I have a Windows service (running LocalSystem) that is a self-service OWIN service (SignalR) and must be accessible via SSL.
I can configure SSL binding on my local development machine just fine - and I can access my service through SSL on the same computer. However, when I switch to another machine and try to run the following command, I get an error message:
Command:
netsh http add sslcert ipport=0.0.0.0:9389 appid={...guid here...} certhash=...cert hash here...
Error:
SSL Certificate Error, Error: 1312
The specified login session does not exist. It may already be completed.
The certificate that I use is a fully signed certificate (not a development certificate) and works in my local dev block. That's what I'm doing:
The Windows service starts and registers my certificate using the following code:
var store = new X509Store(StoreName.Root, StoreLocation.LocalMachine); store.Open(OpenFlags.ReadWrite); var path = AppDomain.CurrentDomain.BaseDirectory; var cert = new X509Certificate2(path + @"\mycert.cer"); var existingCert = store.Certificates.Find(X509FindType.FindByThumbprint, cert.Thumbprint, false); if (existingCert.Count == 0) store.Add(cert); store.Close();
Then I try to bind the certificate to port 9389 using netsh and the following code:
var process = new Process { StartInfo = new ProcessStartInfo { WindowStyle = ProcessWindowStyle.Hidden, FileName = "cmd.exe", Arguments = "/c netsh http add sslcert ipport=0.0.0.0:9389 appid={12345678-db90-4b66-8b01-88f7af2e36bf} certhash=" + cert.thumbprint } }; process.Start();
The code above successfully installs the certificate in the certificate folder "Local machine - certificates \ Trusted root certification authorities \ Certificates", but the netsh command does not start with the error described above. If I take the netsh command and run it on the command line as an administrator in this field, it will also give the same error - so I don't think this is a problem with the code ...
I have to imagine that this can be done - many other applications create self-service services and host them on top of ssl - but I can't get this to work at all ... who has any suggestions? Perhaps software alternatives to netsh?