ComponentSpace Saml 2.0从哪里获取密钥来加密断言

时间:2012-09-05 00:01:36

标签: public-key-encryption saml-2.0

当我运行以下代码(使用ComponentSpace Saml 2.0 lib)时,Fiddler向我显示SAMLRequest的值是加密的,如<input type="hidden" name="SAMLRequest" value="PHNhbWxwOkF1dGhu....">这是非常期望的行为。该代码实现了SSO SAML 2.0 POST个人资料的第一步。请注意,代码中没有指定任何证书密钥来进行任何加密,所以我想知道ComponentSpace lib如何决定选择哪一个?

   var authnRequest = new AuthnRequest
        {
            Destination = @"https://idpserver/...",
            Issuer = new Issuer(@"https://sp/..."),
            ForceAuthn = false,
            NameIDPolicy = new NameIDPolicy(null, null, true), 
            ProtocolBinding = SAMLIdentifiers.BindingURIs.HTTPPost,
            AssertionConsumerServiceURL = @"https://sp/..."
        };

        var relayState = RelayStateCache.Add(new RelayState(@"https://sp/...", null));

        ServiceProvider.SendAuthnRequestByHTTPPost(
            new HttpResponseWrapper(_context.Response), 
            @"https://idpserver/...", 
            authnRequest.ToXml(), 
            relayState);

所有维基百科都说“ SAMLRequest参数的值是base64编码”。没有关于密钥用于编码的信息。

2 个答案:

答案 0 :(得分:1)

很抱歉误解了你的问题。您的示例代码构造并发送了authn请求。听起来你在询问SAML响应中包含的SAML断言。

身份提供商使用服务提供商的公钥加密SAML断言。服务提供者将使用其私钥解密断言。

如果您想查看此示例,请查看AssertionExample项目,该项目演示加密/解密SAML断言。

您提供的链接上的步骤2描述了SP通过HTTP / POST向IdP发送AuthnRequest。发送AuthnRequest时不涉及XML加密。 XML使用deflate和base-64进行编码,但不加密。当您调用ServiceProvider.SendAuthnRequestByHTTPPost时,将为您完成此编码。

答案 1 :(得分:0)

签署authn请求是可选的。

要在签署请求之前,在调用ServiceProvider.SendAuthnRequestByHTTPPost之前,您需要执行以下操作:

// Serialize to XML
XmlElement authnRequestElement = authnRequest.ToXml();

// Sign the authn request
SAMLMessageSignature.Generate(authnRequestElement, x509Certificate.PrivateKey, x509Certificate);

// Send the authn request to the IdP
ServiceProvider.SendAuthnRequestByHTTPPost(..., authnRequestElement, ...);

您始终使用私钥进行签名,收件人将使用您的公钥/证书验证签名。