perl - 如何在 Perl 中验证 SAML 断言?

标签 perl saml

我需要验证此类 SAML 断言:

<saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ID="Assertion-uuide824d44-0134-14b1-8e70-f85c710cb043" IssueInstant="2011-12-05T13:55:47Z" Version="2.0">
    <saml:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">MPS</saml:Issuer>
        <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="uuide824d48-0134-18fe-b37b-f85c710cb043">
        <ds:SignedInfo>
            <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></ds:CanonicalizationMethod>
            <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"></ds:SignatureMethod>
            <ds:Reference URI="#Assertion-uuide824d44-0134-14b1-8e70-f85c710cb043">
                <ds:Transforms>
                    <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"></ds:Transform>
                    <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
                        <xc14n:InclusiveNamespaces xmlns:xc14n="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="xs saml xsi"></xc14n:InclusiveNamespaces>
                    </ds:Transform>
                </ds:Transforms>
                <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod>
                <ds:DigestValue>p02xKMDUYCR5xpppYUOQgsGBR5c=</ds:DigestValue>
            </ds:Reference>
        </ds:SignedInfo>
        <ds:SignatureValue>R9YHo8TK/wYkGkTP3QrnnM8U6TKf9vu+ElpRjDPgpg4O88oARZSb9OhlVn2sXJGEaQ5i0ORrofbKwOI+D/jFgz3Hz/g/h4yt2aqIFxLpOTFb448bDvFsHHWAoWc0DUPYf1AjW7Peu1ICSCdR3EaVLqtgdsUsVWoA7oXbWyAyVLM=</ds:SignatureValue>
        <ds:KeyInfo>
            <ds:KeyValue>
                <ds:RSAKeyValue>
                    <ds:Modulus>iZ0D1X6rk8+ZwNBTVZt7C85m421a8A52Ksjw40t+jNvbLYDp/W66AMMYD7rB5qgniZ5K1p9W8ivM9WbPxc2u/60tFPg0e/Q/r/fxegW1K1umnay+5MaUvN3p4XUCRrfg79OvurvXQ7GZa1/wOp5vBIdXzg6i9CVAqL29JGi6GYU=</ds:Modulus>
                    <ds:Exponent>AQAB</ds:Exponent>
                </ds:RSAKeyValue>
            </ds:KeyValue>
        </ds:KeyInfo>
    </ds:Signature>
    <saml:Subject>
        <saml:NameID Format="urn:ibm:names:ITFIM:5.1:accessmanager">J006068</saml:NameID>
        <saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer"></saml:SubjectConfirmation>
    </saml:Subject>
    <saml:Conditions NotBefore="2011-12-05T13:45:47Z" NotOnOrAfter="2011-12-05T14:05:47Z">
        <saml:AudienceRestriction>
            <saml:AttributeValue xsi:type="xs:string">1030</saml>

我在 CPAN 上没有找到可以将 SAML 作为参数并验证它的库。

有人可以帮助我如何实现我的目标吗?

最佳答案

好吧,迟到总比不到好……如何使用它……

当您说“验证”时,我不确定您的意思是“检查断言”还是“验证签名”。

my $assertion = Net::SAML2::Protocol::Assertion->new_from_xml( 
   xml => decode_base64($saml_response)
);

然后您只需检查通过访问器创建的 Assertion 对象的有效性。我假设您了解 SAML 语义。

要验证签名,您需要访问私钥:

my $sig = Net::SAML2::XML::Sig->new( { key =>'/private.key' } );
$sig->verify( $xml );

请参阅 XML::Sig perldoc 了解 key 来源(x509、证书)的变化。

请注意,Net::SAML2 不涵盖加密的 SAML 断言 (),但您没有询问这一点。

关于perl - 如何在 Perl 中验证 SAML 断言?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8387452/

相关文章:

arrays - 向 CSV 文件添加新行时可以使用数组元素吗?

c# - 验证来自 OneLogin 的 Saml 响应

java - 登录 ADFS 时出现错误 - System.FormatException : Index (zero based) must be greater than or equal to zero and less than the size

spring security 在类路径中找不到元数据文件

linux - Shibboleth ACS URL 与 http 和 https 不匹配

Perl: elsif, Python: elif, C/CPP/Java: else if

perl - 无法使用perl中的引用内部函数打印值

spring-security - 慢跑。 ADFS 上的错误 MSIS7074

regex - 为什么将此语句视为字符串而不是其结果?

perl - 我可以通过访问器本地化 Moose 属性中的哈希引用吗?