src/MessageValidator.php
public function validate(Message $message)
    {
        if (self::isLambdaStyle($message)) {
            $message = self::convertLambdaMessage($message);
        }

        // Get the certificate.
        $this->validateUrl($message['SigningCertURL']);
        $certificate = call_user_func($this->certClient, $message['SigningCertURL']);
        if ($certificate === false) {
            throw new InvalidSnsMessageException(
                "Cannot get the certificate from \"{$message['SigningCertURL']}\"."
            );
        }

        // Extract the public key.
        $key = openssl_get_publickey($certificate);
        if (!$key) {
            throw new InvalidSnsMessageException(
                'Cannot get the public key from the certificate.'
            );
        }

        // Verify the signature of the message.
        $content = $this->getStringToSign($message);
        $signature = base64_decode($message['Signature']);
        if (openssl_verify($content, $signature, $key, OPENSSL_ALGO_SHA1) != 1) {
            throw new InvalidSnsMessageException(
                'The message signature is invalid.'
            );
        }
    }
public function validate(Message $message)
    {
        if (self::isLambdaStyle($message)) {
            $message = self::convertLambdaMessage($message);
        }

        // Get the certificate.
        $this->validateUrl($message['SigningCertURL']);
        $certificate = call_user_func($this->certClient, $message['SigningCertURL']);
        if ($certificate === false) {
            throw new InvalidSnsMessageException(
                "Cannot get the certificate from \"{$message['SigningCertURL']}\"."
            );
        }

        // Extract the public key.
        $key = openssl_get_publickey($certificate);
        if (!$key) {
            throw new InvalidSnsMessageException(
                'Cannot get the public key from the certificate.'
            );
        }

        // Verify the signature of the message.
        $content = $this->getStringToSign($message);
        $signature = base64_decode($message['Signature']);
        if (openssl_verify($content, $signature, $key, OPENSSL_ALGO_SHA1) != 1) {
            throw new InvalidSnsMessageException(
                'The message signature is invalid.'
            );
        }
    }
public function validate ( Message $ message ) { if ( self :: isLambdaStyle ( $ message ) ) { $ message = self :: convertLambdaMessage ( $ message ) ; } // Get the certificate. $ this -> validateUrl ( $ message [ 'SigningCertURL' ] ) ; $ certificate = call_user_func ( $ this -> certClient , $ message [ 'SigningCertURL' ] ) ; if ( $ certificate === false ) { throw new InvalidSnsMessageException ( "Cannot get the certificate from \"{$message['SigningCertURL']}\"." ) ; } // Extract the public key. $ key = openssl_get_publickey ( $ certificate ) ; if ( ! $ key ) { throw new InvalidSnsMessageException ( 'Cannot get the public key from the certificate.' ) ; } // Verify the signature of the message. $ content = $ this -> getStringToSign ( $ message ) ; $ signature = base64_decode ( $ message [ 'Signature' ] ) ; if ( openssl_verify ( $ content , $ signature , $ key , OPENSSL_ALGO_SHA1 ) != 1 ) { throw new InvalidSnsMessageException ( 'The message signature is invalid.' ) ; } }
Validates a message from SNS to ensure that it was delivered by AWS.

@param Message $message Message to validate.

@throws InvalidSnsMessageException If the cert cannot be retrieved or its
source verified, or the message
signature is invalid.
Validates a message from SNS to ensure that it was delivered by AWS .