2

要素にカスタム SOAP ヘッダー<MyApp:FOO>要素を追加しました<soap:Header>が、要件には、この要素に署名する必要があると記載されています。 <MyApp:FOO>より高いレベルでユーザーを識別する多くのもの (ユーザー名、設定など) が含まれています。私はポリシー ファイルを正常に使用し、wsu:Timestamp、wsu:action、wsu:MessageId などに署名するために CertificateAssertions と SoapFilters を含む policyClass を使用しました。ただし、<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));
}
}
4

2 に答える 2

3

私の現在のバージョンの 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);
    }
于 2008-09-30T10:29:55.783 に答える
1

MSDN の補足記事を含む

方法: Id 属性を SOAP ヘッダーに追加する

方法: カスタム SOAP ヘッダーにデジタル署名する

于 2009-01-12T13:11:22.733 に答える