remove support for newest TOTP and QR libraries (they are not <= PHP 7.0 compatible)

This commit is contained in:
Daniel Seifert 2018-10-22 08:56:14 +02:00
parent 2dde73ee61
commit 96057b594a
2 changed files with 15 additions and 39 deletions

View File

@ -2,7 +2,6 @@
"name": "d3/totp", "name": "d3/totp",
"description": "Two-factor authentication for OXID eSales shop", "description": "Two-factor authentication for OXID eSales shop",
"type": "oxideshop-module", "type": "oxideshop-module",
"version": "0.1",
"keywords": [ "keywords": [
"oxid", "oxid",
"modules", "modules",
@ -34,8 +33,8 @@
"require": { "require": {
"php": ">=5.6", "php": ">=5.6",
"oxid-esales/oxideshop-metapackage-ce": "~6.0.3 || ~6.1.0", "oxid-esales/oxideshop-metapackage-ce": "~6.0.3 || ~6.1.0",
"spomky-labs/otphp": "^8.3 || ^9.0", "spomky-labs/otphp": "^8.3",
"bacon/bacon-qr-code": "^1.0 || ^2.0" "bacon/bacon-qr-code": "^1.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

View File

@ -15,9 +15,7 @@
namespace D3\Totp\Application\Model; namespace D3\Totp\Application\Model;
use BaconQrCode\Renderer\Image\SvgImageBackEnd; use BaconQrCode\Renderer\Image\Svg;
use BaconQrCode\Renderer\ImageRenderer;
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
use BaconQrCode\Writer; use BaconQrCode\Writer;
use D3\ModCfg\Application\Model\d3database; use D3\ModCfg\Application\Model\d3database;
use D3\Totp\Application\Model\Exceptions\d3totp_wrongOtpException; use D3\Totp\Application\Model\Exceptions\d3totp_wrongOtpException;
@ -92,7 +90,6 @@ class d3totp extends BaseModel
} }
/** /**
* @param $userId
* @return bool * @return bool
*/ */
public function UserUseTotp() public function UserUseTotp()
@ -102,7 +99,6 @@ class d3totp extends BaseModel
} }
/** /**
* @param $userId
* @return string * @return string
*/ */
public function getSavedSecret() public function getSavedSecret()
@ -128,7 +124,6 @@ class d3totp extends BaseModel
{ {
if (false == $this->totp) { if (false == $this->totp) {
if ($this->getTotpLibVersion() == 8) { // version 0.8 (< PHP 7.1)
$this->totp = oxNew( $this->totp = oxNew(
TOTP::class, TOTP::class,
$this->getUser()->getFieldData('oxusername') $this->getUser()->getFieldData('oxusername')
@ -138,29 +133,12 @@ class d3totp extends BaseModel
? $seed ? $seed
: $this->getSavedSecret() : $this->getSavedSecret()
); );
} else { // version 0.9 (>= PHP 7.1)
$this->totp = TOTP::create($seed ? $seed : $this->getSavedSecret());
$this->totp->setLabel($this->getUser()->getFieldData('oxusername')
? $this->getUser()->getFieldData('oxusername')
: ''
);
}
$this->totp->setIssuer(Registry::getConfig()->getActiveShop()->getFieldData('oxname')); $this->totp->setIssuer(Registry::getConfig()->getActiveShop()->getFieldData('oxname'));
} }
return $this->totp; return $this->totp;
} }
/**
* @return int
*/
public function getTotpLibVersion()
{
return method_exists(TOTP::class, 'create') ?
9 :
8;
}
/** /**
* @return string * @return string
*/ */
@ -174,11 +152,10 @@ class d3totp extends BaseModel
*/ */
public function getQrCodeElement() public function getQrCodeElement()
{ {
/** @var ImageRenderer $renderer */ $renderer = oxNew(Svg::class);
$renderer = oxNew(ImageRenderer::class, $renderer->setHeight(200);
oxNew(RendererStyle::class, 200), $renderer->setWidth(200);
oxNew(SvgImageBackEnd::class)
);
/** @var Writer $writer */ /** @var Writer $writer */
$writer = oxNew(Writer::class, $renderer); $writer = oxNew(Writer::class, $renderer);
return $writer->writeString($this->getTotp()->getProvisioningUri()); return $writer->writeString($this->getTotp()->getProvisioningUri());