簡體   English   中英

如何禁用用於驗證消息簽名的x509證書的驗證?

[英]How do I disable validation of the x509 certificate used to validate a message signature?

我有一個客戶端,該客戶端調用簽名其響應消息的API。 簽名驗證設置需要特殊的綁定,如下所示:

public class SignatureBinding : Binding
{
    public override BindingElementCollection CreateBindingElements()
    {
        var signingElement = new AsymmetricSecurityBindingElement
        {
            AllowInsecureTransport = false,
            RecipientTokenParameters = new X509SecurityTokenParameters(X509KeyIdentifierClauseType.IssuerSerial, SecurityTokenInclusionMode.Never),
            InitiatorTokenParameters = new X509SecurityTokenParameters(X509KeyIdentifierClauseType.IssuerSerial, SecurityTokenInclusionMode.AlwaysToRecipient),
            DefaultAlgorithmSuite = SecurityAlgorithmSuite.Basic256,
            SecurityHeaderLayout = SecurityHeaderLayout.Strict,
            MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt,
            MessageSecurityVersion = MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10,
            AllowSerializedSigningTokenOnReply = true
        };
        signingElement.SetKeyDerivation(false);

        return new BindingElementCollection
        {
            signingElement,
            new HttpsTransportBindingElement()
        };
    }
}

並且在ClientCredentials行為中:

public class CredentialsBehavior : ClientCredentials 
{
    public CredentialsBehavior()
    {
        base.ServiceCertificate.DefaultCertificate = store.FindBySerialNumber(signatureCertSN);
    }

    //Code omitted
}

我已經確認,從普通計算機上運行上述代碼可以正常工作。 消息已發送,服務器制作了響應並對其進行簽名,然后返回,客戶端驗證了簽名,一切都很好。

但是,從目標服務器運行時會出現故障,由於防火牆,該服務器無法訪問CRL服務 通過通道發送消息時,ServiceModel調用返回錯誤。 該錯誤與包含用於驗證簽名的公鑰的證書有關。 錯誤是:

X.509證書CN = somecert.somedomain.com,OU = CE_Operations,O =“ MyCompany,Inc。”,L =城市,S =州,C =美國鏈建立失敗。 使用的證書具有無法驗證的信任鏈。 替換證書或更改certificateValidationMode。 吊銷服務器處於脫機狀態,因此吊銷功能無法檢查吊銷。

該服務器存在於無法訪問CRL的域中,因此我在此答案的幫助下禁用了檢查:

ServicePointManager.ServerCertificateValidationCallback += ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
ServicePointManager.CheckCertificateRevocationList = false;

但是,錯誤仍然存​​在。 我猜想ServerCertificateValidationCallback僅針對服務器證書觸發,並且此證書是不同的。

如何說服服務模型允許使用此證書,而無需檢查CRL或執行其他驗證過程?

將certificateValidationMode設置為None以忽略證書驗證X509CertificateValidationMode

這是一種行為,因此,如果要以編程方式進行操作,則應將其作為新行為綁定到服務:

ServiceHost host = new ServiceHost(typeof(Service));
ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(IService), new WebHttpBinding(), "http://...");

var endpointClientbehavior = new ClientCredentials();
endpointClientbehavior.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;

endpoint.Behaviors.Add(endpointClientbehavior);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM