I am using C#/WCF. I have a web service which shall be invoked by the client. This is the service definition:
<service behaviorConfiguration="WCFInterface.CommonBehavior" name="WCFInterface.Content">
<endpoint address="" binding="ws2007HttpBinding" bindingConfiguration="wsHttpUserName"
contract="ABB.fTunes.WCFInterface.IContent">
<identity>
<dns value="fTunesTestServer" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
And this is the binding:
<ws2007HttpBinding>
<binding name="wsHttpUserName">
<security mode="Message">
<message clientCredentialType="UserName"/>
</security>
</binding>
</ws2007HttpBinding>
If I understand this correctly, the messages sent from server to client are encrypted with a certificate. Currently I am still working with developer certificates. I created a root certificate, a certificate revokation list and a key on the server.
I am installing the client with Windows Installer and I have a custom install action to install the certificates.
The following code shows how the certificates are added to the store
Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ClientCertificates.MyRoot.cer");
byte[] buffer = new byte[((int)(manifestResourceStream.Length - 1L)) + 1];
manifestResourceStream.Read(buffer, 0, (int)manifestResourceStream.Length);
manifestResourceStream.Close();
var cert = new X509Certificate2(buffer);
var store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadWrite);
store.Add(cert);
store.Close();
/*
// The CRL is also needed, no idea why
manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ClientCertificates.MyRoot.crl");
buffer = new byte[((int)(manifestResourceStream.Length - 1L)) + 1];
manifestResourceStream.Read(buffer, 0, (int)manifestResourceStream.Length);
manifestResourceStream.Close();
cert = new X509Certificate2(buffer);
store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadWrite);
store.Add(cert);
store.Close();
*/
// This is the key
manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ClientCertificates.MyTestServer.cer");
buffer = new byte[((int)(manifestResourceStream.Length - 1L)) + 1];
manifestResourceStream.Read(buffer, 0, (int)manifestResourceStream.Length);
manifestResourceStream.Close();
cert = new X509Certificate2(buffer);
store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadWrite);
store.Add(cert);
store.Close();
I have now two behaviors:
Installing the certificates work, but when I call the web service I get a SecurityNegotiationException
.
When I add the Certificate Revocation List manually, the communication with the server works.
When I try to do it programmatically (see code above) it does not work. I get a "Could not find requested object" exception.
I tried to use different stores but with no success.
I have two questions: a) Why do I need the CRL on the client? b) If I need it, how can I install it programmatically? Where is my mistake above?
Thanks for your help, Kay