我目前正在构建一个应该处理Alexa语音意图的Web服务。我必须通过检查签名来验证我从Alexa获得的HTTP请求,如in the documentation所述。
我在Perl中编写此代码。
亚马逊为我提供了SignatureCertChainUrl
(其中包含证书)和签名,如下所示:
signature: KUm7g9saS4la2pwCPJHuk0ZOtNAPKnqE8qprp58rz1x9Em1DDp2mNdL56iiC7weGw3hzaN6lCmqjWL3zxtAC7HXmbDPdpYE5ZQJzVDCorAvAgb0VQTVMiRi2xcoNm+6KcQZe2/aFJgAxaDaJ3qID9EVPmhJMlHhFxD+/4Ip5O860Pk9GPTq1lC7gKGw5VmUinXZk/RCUnevnhL4TGfZYgEs4bI5QgHtdzlQdy+P6cfRqpuQrLEeFjHF13OA1uf/W5MjgF9dKjV0cCM3fAcBbz8O9itZbt1pC7LIJsDLYxQMcW7af98GdTv2dlnx3kb9JPERsTSni+rDKoukxgxQGcA==
-----BEGIN CERTIFICATE-----
MIIF5jCCBM6gAwIBAgIQQPlwU5w/zc7VB5NZu84xNzANBgkqhkiG9w0BAQsFADB+
MQswCQYDVQQGEwJVUzEdMBsGA1UEChMUU3ltYW50ZWMgQ29ycG9yYXRpb24xHzAd
BgNVBAsTFlN5bWFudGVjIFRydXN0IE5ldHdvcmsxLzAtBgNVBAMTJlN5bWFudGVj
IENsYXNzIDMgU2VjdXJlIFNlcnZlciBDQSAtIEc0MB4XDTE3MTAwMzAwMDAwMFoX
DTE4MDcwMzIzNTk1OVowbTELMAkGA1UEBhMCVVMxEzARBgNVBAgMCldhc2hpbmd0
b24xEDAOBgNVBAcMB1NlYXR0bGUxGTAXBgNVBAoMEEFtYXpvbi5jb20sIEluYy4x
HDAaBgNVBAMME2VjaG8tYXBpLmFtYXpvbi5jb20wggEiMA0GCSqGSIb3DQEBAQUA
A4IBDwAwggEKAoIBAQCQ9PvhGTQogVCnaeqkuUDiEnK4Tbm6hLEg7jrHGfpNWra4
lCoMz6TjIzqTZvavll7r393k8FlD+en5wL0TCUC/PuyZyc+42Q1dAs2XfbvED1W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QBVSK/eHiXgSgW7ZTaoteNTCLD0IX4eRnh8OsN4wUmSGiaqdZpwOdgyA8nTY
Kvi4Os7X1g8RvmurFPW9QaAiY4nxug9vKWNmLT+sjHLF+8fk1A/yO0+MKcc=
-----END CERTIFICATE-----
我使用以下代码来解码和提取公钥,因为我在名为$ primary_cert的变量中拥有证书的第一部分。
my $decoded_cert2 = Crypt::OpenSSL::X509->new_from_string( $primary_cert );
my $pub_key = Crypt::OpenSSL::RSA->new_public_key($decoded_cert2->pubkey());
但是我似乎仍然坚持这些步骤:
Perl代码应该如何执行最后的步骤?我使用以下perl模块:
use CGI qw(:all);
use JSON qw( decode_json );
use Switch;
use Crypt::X509;
use MIME::Base64 qw(decode_base64);
use Crypt::OpenSSL::X509;
use Crypt::OpenSSL::RSA;
use Crypt::OpenSSL::VerifyX509;
use Try::Tiny;