System.ComponentModel.Win32Exception: An unknown error occurred while processing the certificate
Hello everyone. I am trying to make a secure WebSocket Server. I have generated an X509Certificate via the command given below:
makecert.exe -r -pe -n "CN=localhost" -sky exchange -sv server.pvk server.cer
pvk2pfx.exe -pvk server.pvk -spc server.cer -pfx server.pfx -pi <password>
But when I try to connect from the client to the server, I get the following error in the server logs.
4/26/2021 1:40:53 PM|Error|<>c__DisplayClass71_0.<receiveRequest>b__0:0|Authentication failed, see inner exception.
4/26/2021 1:40:53 PM|Debug|<>c__DisplayClass71_0.<receiveRequest>b__0:0|System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception. ---> System.ComponentModel.Win32Exception: An unknown error occurred while processing the certificate
--- End of inner exception stack trace ---
at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, ExceptionDispatchInfo exception)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.Security.SslStream.AuthenticateAsServer(SslServerAuthenticationOptions sslServerAuthenticationOptions)
at System.Net.Security.SslStream.AuthenticateAsServer(X509Certificate serverCertificate, Boolean clientCertificateRequired, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation)
at WebSocketSharp.Net.WebSockets.TcpListenerWebSocketContext..ctor(TcpClient tcpClient, String protocol, Boolean secure, ServerSslConfiguration sslConfig, Logger log)
at WebSocketSharp.Server.WebSocketServer.<>c__DisplayClass71_0.<receiveRequest>b__0(Object state)
How do I generate the X509Certificate for WSS correctly?
Also I tried the following way:
./openssl.exe req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -subj "/C=US/ST=Test/L=Test/O=Test/OU=Org/CN=localhost"
and
./openssl.exe pkcs12 -inkey key.pem -in cert.pem -export -out server.pfx
It didn't work either.
Also didn't work:
./openssl.exe req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes -keyout server.key -out server.crt -subj "/CN=localhost" -addext "subjectAltName=IP:0.0.0.0,IP:127.0.0.1"
./openssl.exe pkcs12 -inkey server.key -in server.crt -export -out server.pfx
You have to add DNS Name to subjectAltName like subjectAltName=DNS:example.com,IP:192.168.1.3
192.168.1.3 is the IP address of the PC running the C # app Please rewrite example.com to suit your environment.
I entered 192.168.1.3 when accessing WebsocketServer, but it worked.
I solved it with this🎉
shall i use localhost instead of example.com (dns)