【问题标题】:How to sign custom Soap Header?如何签署自定义肥皂标题?
【发布时间】:2010-09-14 05:22:25
【问题描述】:

我在<soap:Header> 元素中添加了一个自定义soap 标头<MyApp:FOO> 元素,并且要求我必须签署这个元素,如何做到这一点? <MyApp:FOO> 包含许多可以识别更高级别用户的内容(用户名、首选项等)。 我已经成功地使用了一个策略文件,现在是一个带有 CertificateAssertions 和 SoapFilters 的 policyClass 来签署 wsu:Timestamp、wsu:action、wsu:MessageId 等。但是现在<MyApp:FOO> 元素也需要签名。

到目前为止我所理解的是,需要签名的元素必须使用 wsu:Id 属性进行标识,然后使用 xml-exc-c14n 进行转换。

那么,如何指定soap 标头也应签名? 这是我用于签署消息的当前类。

internal class FOOClientOutFilter: SendSecurityFilter
{
X509SecurityToken clientToken;

public FOOClientOutFilter(SSEKCertificateAssertion parentAssertion)
: base(parentAssertion.ServiceActor, true)
{
// Get the client security token.
clientToken = X509TokenProvider.CreateToken(StoreLocation.CurrentUser, StoreName.My, "CN=TestClientCert");

// Get the server security token.
serverToken = X509TokenProvider.CreateToken(StoreLocation.LocalMachine, StoreName.My, "CN=TestServerCert");
}

public override void SecureMessage(SoapEnvelope envelope, Security security)
{
// Sign the SOAP message with the client's security token.
security.Tokens.Add(clientToken);

security.Elements.Add(new MessageSignature(clientToken));
}
}

【问题讨论】:

    标签: c# web-services wse3.0 x509securitytokenmanager


    【解决方案1】:

    我当前版本的 SecureMessage 似乎可以解决问题..

        public override void SecureMessage(SoapEnvelope envelope, Security security)
        {
            //EncryptedData data = new EncryptedData(userToken);
            SignatureReference ssekSignature = new SignatureReference();
            MessageSignature signature = new MessageSignature(clientToken);
            // encrypt custom headers
    
            for (int index = 0; index < envelope.Header.ChildNodes.Count; index++)
            {
                XmlElement child =
                  envelope.Header.ChildNodes[index] as XmlElement;
    
                // find all FOO headers
                if (child != null && child.Name == "FOO")
                {
                    string id = Guid.NewGuid().ToString();
                    child.SetAttribute("Id", "http://docs.oasis-" +
                          "open.org/wss/2004/01/oasis-200401-" +
                          "wss-wssecurity-utility-1.0.xsd", id);
                    signature.AddReference(new SignatureReference("#" + id));
                }
            }
    
            // Sign the SOAP message with the client's security token.
            security.Tokens.Add(clientToken);
    
            security.Elements.Add(signature);
        }
    

    【讨论】:

      【解决方案2】:
      猜你喜欢
      • 1970-01-01
      • 2010-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多