WCF客户端标志肥皂消息与智能卡

时间:2014-07-10 08:30:23

标签: c# web-services wcf soap sign

我有使用CustomBinding签署soap请求的表单应用程序和服务引用(只需要签署soap body)。如果我尝试用包含私钥的签名请求pfx wcf客户端成功签署Basic256Sha256Rsa15。

以下成功案例:

private CustomBinding GetCustomHttpBinding()
        {
            CustomBinding binding = new CustomBinding();
            // Open and Close = 20s 
            binding.OpenTimeout = new TimeSpan(0, 0, 20);
            binding.CloseTimeout = new TimeSpan(0, 0, 20);
            // Send and Receive = 300s
            binding.SendTimeout = new TimeSpan(0, 5, 0);
            binding.ReceiveTimeout = new TimeSpan(0, 5, 0);
            // ++ Setting security binding ++
            var param = new X509SecurityTokenParameters();
            param.X509ReferenceStyle = X509KeyIdentifierClauseType.IssuerSerial;
            param.ReferenceStyle = SecurityTokenReferenceStyle.Internal;
            param.InclusionMode = SecurityTokenInclusionMode.AlwaysToRecipient;
            param.RequireDerivedKeys = false;

            var userNameToken = new UserNameSecurityTokenParameters();
            userNameToken.InclusionMode = SecurityTokenInclusionMode.AlwaysToRecipient;

            var securityElement = new AsymmetricSecurityBindingElement();

            securityElement.EnableUnsecuredResponse = true;
            securityElement.IncludeTimestamp = true;
            securityElement.RecipientTokenParameters = new X509SecurityTokenParameters(X509KeyIdentifierClauseType.IssuerSerial, SecurityTokenInclusionMode.Never);
            securityElement.InitiatorTokenParameters = new X509SecurityTokenParameters(X509KeyIdentifierClauseType.IssuerSerial, SecurityTokenInclusionMode.AlwaysToRecipient);
            securityElement.DefaultAlgorithmSuite = SecurityAlgorithmSuite.Basic256Sha256Rsa15;
            securityElement.SecurityHeaderLayout = SecurityHeaderLayout.Strict;
            securityElement.SetKeyDerivation(false);
            securityElement.EndpointSupportingTokenParameters.Signed.Add(param);
            //securityElement.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt;
            securityElement.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurityProfile10;
            binding.Elements.Add(securityElement);


            // ++ Setting message encoding binding ++
            var encodingElement = new TextMessageEncodingBindingElement();
            encodingElement.MessageVersion = MessageVersion.Soap12;
            encodingElement.WriteEncoding = Encoding.UTF8;
            //encodingElement.MaxReadPoolSize = 50000000;
            //encodingElement.MaxWritePoolSize = 50000000;
            encodingElement.ReaderQuotas.MaxArrayLength = 50000000;
            encodingElement.ReaderQuotas.MaxStringContentLength = 50000000;

            binding.Elements.Add(encodingElement);

            // ++ Setting https transport binding ++
            var httpsElement = new HttpsTransportBindingElement();
            // Messagge buffer size
            httpsElement.MaxBufferSize = 50000000;
            httpsElement.MaxReceivedMessageSize = 50000000;
            httpsElement.MaxBufferPoolSize = 50000000;
            httpsElement.RequireClientCertificate = true;

            // Others
            httpsElement.UseDefaultWebProxy = true;
            binding.Elements.Add(httpsElement);

            return binding;
        }

Service Sertificate设置为

client.ClientCredentials.ClientCertificate.Certificate=cert;// From pfx file
client.ClientCredentials.ServiceCertificate.DefaultCertificate =serverCert;//from server certificate

我尝试用我公司的智能卡签名,这是ACS38智能卡。如果我使用DefaultAlgotihmSuite Basic128或Basic128Rsa15,那么smartCard证书会成功签署body元素。我更改algorihmsuite Basic256Sha256Rsa15的要求然后我得到KeySet不存在。在此智能卡中有私钥,但WCF无法访问该私钥。

有没有办法在SmartCard上使用Sha256Rsa签署Soap Body?

0 个答案:

没有答案