security - .NET 4.0 client certificate validation error -
I have the following code
on factory = new ChannelFactory & LT; InewsClient & gt; (); Factory Credential Client Certificate Certificate = GetCertificate (); Factory Endpoint Address = new endpoint ("https://blabla.com/myservice/"); Var Binding = New Basic HTBiding (Basic HTPCEERMD.transport); Binding. Security. Transportation Client Credential Type = HTTP Client Credential Type certificate; Factory.indpoint Binding = bond; Var channel = factory. Cutlet (); Channel.GetNews (); It works in .NET 3.5, but not in .NET4.0. Bizarre huh? The certificate I'm using is not valid on the local machine (no series). In 3.5, the validity of the client certificate is irrelevant to SSL installation, but when migrating to 4.0, the certificate is valid before using it for SSL (I can see the errors in the CAPI2 event log). Resulting in an ugly SecurityNegotiationException ...
Stack trace:
System.ServiceModel.Security.SecurityNegotiationException: Safe with rights' pep.uat.dialectpayments SSL / TLS The channel could not be installed .com '. --- & gt; System.Net.WebException: The request was canceled: SSL / TLS secure channel can not be made System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply timed System.Net.HttpWebRequest.GetResponse () (TimeSpan on ) --- at the inner exception stack trace --- end server stack trace: at System.ServiceModel.Channels.RequestChannel.Request on System.ServiceModel.Channels (message, Taimspen timeout). System Processor Module Channel. HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply (Taimspen timeout) .HttpChannelUtilities.ProcessGetResponseWebException (WebException webException, HttpWebRequest request, HttpAbortReason abortReason) finished System.ServiceModel.Dispatcher.RequestChannelBinder.Request (message, time TimeSpan on) System.ServiceModel.Channels .ServiceChannel.Call on (String Action, Boolean Oneway, ProxyOperationRuntime Operation, Object [] These, [] Exclusions, TimeSpan Timeout Object System). ServiceModel.Channel. ServiceCranel Proxy Invoksewa (Aimut column message Vidhicol, Proksiopreshnrentimenn operation) restore .ServiceModel.Channels.ServiceChannelProxy.Invoke (IMessage message) exception [0] on the system: the system. time. Remoting. Proxies Real Proxy Handle on ReutersNews Message System (IMs ReConz, IMess's RatMG) From time to time. Approval. Proxies Real Proxy Private Invok (in MessageData & amp; msgData, Int32 type) at ConsoleApplication2kProgramkINewsClientkGet () on ConsoleApplication2.Program.Main (String [] args) D: \ Dev \ ConsoleApplication2 \ Program.cs: line 44 In our security architecture, certs are valid against a LDAP directory on the server, so there is no need to know the whole range of the client.
The question is, how can I disable this new behavior?
OK, I will provide my own answer here ...
In essence: It seems that you can not use a non-permanent CSP with .NET 4 for X509. To wit. . (Ie non-consecutive)
var certificate = new X509Certificate2 (: its CSP a KeyContainerName it must be to work I GetCertificate (was the) method @ "C: \ public.cer"); Var rsa = RSA.Create (); Rsa.FromXmlString ("& lt; RSakeyValue & gt; ...... & lt; / RSakeyValue & gt;"); certificate. Privatized = RSA; Return certificate;
Changing it takes my sample work to 3.5 and 4.0: (Setting KeyContainerName will create a physical entry in your crypto folders)
var Certificate = new X509Certificate2 (@ "C: \ public.cer"); CSPParameters parameter = new CSPParameters {KeyContainerName = "KeyContainer"}; Var RSA = New RSACRPPS service provider (parameter); Rsa.FromXmlString ("& lt; RSakeyValue & gt; ...... & lt; / RSakeyValue & gt;"); certificate. Privatized = RSA; Return certificate; For simplicity, I was trying to export the private key in .pfx file, but could not use the first approach in .NET 4.0, but could use .NET 3.5. Somwhow, private key is not exportable in .NET 4.0. It helped me fix it. However, it would be good to know what has changed between 3.5 and 4.0.
Comments
Post a Comment