[英]How to sign custom Soap Header?
I've added a custom soap header <MyApp:FOO>
element to the <soap:Header>
element and the requirments states that i must sign this element , how would one do that? 我在
<soap:Header>
元素中添加了一个自定义的肥皂标头<MyApp:FOO>
元素,并且要求指出我必须对此元素进行签名,该怎么做? <MyApp:FOO>
contains a number of things (username, preferences, etc) that identifies a user on higher level. <MyApp:FOO>
包含许多东西(用户名,首选项等),这些东西标识更高级别的用户。 I've succesfully used a policy file and now a policyClass with CertificateAssertions and SoapFilters to sign wsu:Timestamp, wsu:action, wsu:MessageId etc. But now the <MyApp:FOO>
element needs to signed aswell. 我已经成功使用了策略文件,现在使用带有CertificateAssertions和SoapFilters的policyClass来签名wsu:Timestamp,wsu:action,wsu:MessageId等。但是现在
<MyApp:FOO>
元素也需要签名。
What i've understood this far is that the element that needs to be signed must be indentified with a wsu:Id attribute and then transformed using xml-exc-c14n. 到目前为止,我已经了解到,必须使用wsu:Id属性来标识需要签名的元素,然后使用xml-exc-c14n对其进行转换。
So, how do I specify that the soap header should be signed aswell? 那么,如何指定soap标头也要签名? This is the current class that i use for signing my message.
这是我用来签名消息的当前类。
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));
}
}
My current version of SecureMessage seems to do the trick.. 我当前的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);
}
Including supplementary articles from MSDN 包括来自MSDN的补充文章
How to: Add an Id Attribute to a SOAP Header 如何:将Id属性添加到SOAP标头
How to: Digitally Sign a Custom SOAP Header 如何:对自定义SOAP标头进行数字签名
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.