2022-10-26 00:02:55 +02:00
|
|
|
<?php
|
|
|
|
|
2022-11-04 22:02:44 +01:00
|
|
|
/**
|
2022-11-04 22:45:47 +01:00
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* https://www.d3data.de
|
2022-11-04 22:02:44 +01:00
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
2022-11-04 22:45:47 +01:00
|
|
|
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
|
|
|
* @link https://www.oxidmodule.com
|
2022-11-04 22:02:44 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-10-26 00:02:55 +02:00
|
|
|
namespace D3\Webauthn\Application\Model;
|
|
|
|
|
2022-10-28 00:45:32 +02:00
|
|
|
use OxidEsales\Eshop\Core\Registry;
|
|
|
|
|
2022-10-26 00:02:55 +02:00
|
|
|
class WebauthnErrors
|
|
|
|
{
|
2022-11-01 23:42:25 +01:00
|
|
|
public const INVALIDSTATE = 'invalidstateerror';
|
|
|
|
public const NOTALLWED = 'notallowederror';
|
|
|
|
public const ABORT = 'aborterror';
|
|
|
|
public const CONSTRAINT = 'constrainterror';
|
|
|
|
public const NOTSUPPORTED = 'notsupporederror';
|
|
|
|
public const UNKNOWN = 'unknownerror';
|
|
|
|
public const NOPUBKEYSUPPORT = 'd3nopublickeycredentialsupportederror';
|
2022-11-09 11:19:53 +01:00
|
|
|
public const UNSECURECONNECTION = 'D3_WEBAUTHN_ERR_UNSECURECONNECTION';
|
2022-10-28 00:45:32 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $msg
|
2022-11-01 23:42:25 +01:00
|
|
|
* @param null $type
|
|
|
|
* @return string
|
2022-10-28 00:45:32 +02:00
|
|
|
*/
|
2022-11-01 23:42:25 +01:00
|
|
|
public function translateError($msg, $type = null): string
|
2022-10-26 00:02:55 +02:00
|
|
|
{
|
2022-10-28 00:45:32 +02:00
|
|
|
$lang = Registry::getLang();
|
2022-11-01 23:42:25 +01:00
|
|
|
$type = $type ? '_'.$type : null;
|
2022-10-28 00:45:32 +02:00
|
|
|
|
|
|
|
switch ($this->getErrIdFromMessage($msg)) {
|
|
|
|
case self::INVALIDSTATE:
|
2022-11-01 23:42:25 +01:00
|
|
|
return $lang->translateString('D3_WEBAUTHN_ERR_INVALIDSTATE'.$type, null, true);
|
2022-10-28 00:45:32 +02:00
|
|
|
case self::NOTALLWED:
|
|
|
|
return $lang->translateString('D3_WEBAUTHN_ERR_NOTALLOWED', null, true);
|
|
|
|
case self::ABORT:
|
|
|
|
return $lang->translateString('D3_WEBAUTHN_ERR_ABORT', null, true);
|
|
|
|
case self::CONSTRAINT:
|
|
|
|
return $lang->translateString('D3_WEBAUTHN_ERR_CONSTRAINT', null, true);
|
|
|
|
case self::NOTSUPPORTED:
|
|
|
|
return $lang->translateString('D3_WEBAUTHN_ERR_NOTSUPPORTED', null, true);
|
|
|
|
case self::UNKNOWN:
|
|
|
|
return $lang->translateString('D3_WEBAUTHN_ERR_UNKNOWN', null, true);
|
|
|
|
case self::NOPUBKEYSUPPORT:
|
|
|
|
return $lang->translateString('D3_WEBAUTHN_ERR_NOPUBKEYSUPPORT', null, true);
|
2022-10-26 00:02:55 +02:00
|
|
|
}
|
|
|
|
|
2022-11-09 11:19:53 +01:00
|
|
|
switch ($msg) {
|
|
|
|
case self::UNSECURECONNECTION:
|
|
|
|
return $lang->translateString($msg);
|
|
|
|
}
|
|
|
|
|
2022-11-01 23:42:25 +01:00
|
|
|
return $lang->translateString('D3_WEBAUTHN_ERR_TECHNICALERROR', null, true);
|
2022-10-26 00:02:55 +02:00
|
|
|
}
|
2022-10-28 00:45:32 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $msg
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getErrIdFromMessage(string $msg): string
|
|
|
|
{
|
2022-11-09 11:19:53 +01:00
|
|
|
if (is_int(strpos($msg, ':'))) {
|
|
|
|
return trim( strtolower( substr( $msg, 0, strpos( $msg, ':' ) ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return trim(strtolower($msg));
|
2022-10-28 00:45:32 +02:00
|
|
|
}
|
2022-10-26 00:02:55 +02:00
|
|
|
}
|