StoreSignatureValidationException example

private const SHOPWARE_SIGNATURE_HEADER = 'X-Shopware-Signature';

    public function __construct(private readonly OpenSSLVerifier $openSslVerifier)
    {
    }

    public function __invoke(ResponseInterface $response): ResponseInterface
    {
        $signatureHeaderName = self::SHOPWARE_SIGNATURE_HEADER;
        $header = $response->getHeader($signatureHeaderName);
        if (!isset($header[0])) {
            throw new StoreSignatureValidationException(sprintf('Signature not found in header "%s"', $signatureHeaderName));
        }

        $signature = $header[0];

        if (empty($signature)) {
            throw new StoreSignatureValidationException(sprintf('Signature not found in header "%s"', $signatureHeaderName));
        }

        if (!$this->openSslVerifier->isSystemSupported()) {
            return $response;
        }

        

class StoreSignatureValidationExceptionTest extends TestCase
{
    public function testGetErrorCode(): void
    {
        static::assertSame(
            'FRAMEWORK__STORE_SIGNATURE_INVALID',
            (new StoreSignatureValidationException('reason'))->getErrorCode()
        );
    }

    public function testGetStatusCode(): void
    {
        static::assertSame(
            Response::HTTP_INTERNAL_SERVER_ERROR,
            (new StoreSignatureValidationException('reason'))->getStatusCode()
        );
    }

    

    public function __construct(array $publicKeys)
    {
        foreach ($publicKeys as $publicKey) {
            if (is_readable($publicKey)) {
                $this->publicKeyPath = $publicKey;

                return;
            }
        }

        throw new StoreSignatureValidationException(sprintf('Cannot find readable public key file in %s', implode(',', $publicKeys)));
    }

    public function isSystemSupported(): bool
    {
        return \function_exists('openssl_verify');
    }

    public function isValid(string $message, string $signature): bool
    {
        $errors = [];
        $pubkeyid = $this->getKey();

        
Home | Imprint | This part of the site doesn't use cookies.