Fleck: Error in Secure Websocket
Hello,
i need your help, i’m using your console app sample to test secure WebSockets (wss) i did changes to your code as below:
console cs: var server = new WebSocketServer(“wss://127.0.0.1:2080”); server.Certificate = new X509Certificate2(@“[path]\beaweb.cert.pfx”, “password”);
client.html: window.ws = new wsImpl(‘wss://127.0.0.1:2080/’);
i have used openssl to generate my certificate:
-
openssl req -x509 -days 1460 -newkey rsa:2048 -keyout beaweb.key.pem -out beaweb.cert.pem pwd: [password]
-
openssl pkcs12 -export -in beaweb.cert.pem -inkey beaweb.key.pem -out beaweb.cert.pfx pwd: [password]
-
openssl pkcs12 -in beaweb.cert.pfx -clcerts -nokeys -out beaweb.cert.public.pem pwd: [password]
when i tried to run your sample after this i got the below exception:
2/6/2018 3:55:40 PM [Info] Server started at wss://127.0.0.1:2080 (actual port 2080)
2/6/2018 3:55:40 PM [Debug] Using default TLS 1.0 security protocol.
2/6/2018 3:55:55 PM [Debug] Client connected from 127.0.0.1:10953
2/6/2018 3:55:55 PM [Debug] Authenticating Secure Connection
2/6/2018 3:55:55 PM [Warn] Failed to Authenticate System.AggregateException: One or more errors occurred. —> System.IO.IOException: Authentication failed because the remote party has closed the transport stream.
at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result)
at System.Net.Security.SslStream.EndAuthenticateAsServer(IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization)
— End of inner exception stack trace —
—> (Inner Exception #0) System.IO.IOException: Authentication failed because the remote party has closed the transport stream.
at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result)
at System.Net.Security.SslStream.EndAuthenticateAsServer(IAsyncResult asyncResult)
at System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization)<—
i need to know if i missed something, i need your help because i built mvc web application communicating to client hardware like camera, fingerprint and passport reader using your library, it’s working fine when i running my site as http, but it faild when i switch to https!
thank you
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 17
Everyone seems to have a different way of generating these certificates & 99% never seem to work. So here goes with how I get it to work…
This will create an ssl certificate using
test.comto test secure WebSockets in your local environment.Install
Win32 OpenSSL v1.1.0gfrom https://slproweb.com/products/Win32OpenSSL.htmlSave below as
openssl.cnftoC:\OpenSSL-Win32\open cmd
run:
cd "c:\OpenSSL-Win32\bin"run:
set OPENSSL_CONF=c:\OpenSSL-Win32\openssl.cnfrun:
openssl req -x509 -newkey rsa:4096 -sha256 -nodes -keyout test.key -out test.crt -subj "/CN=test.com" -days 3650Import “test.crt” into certificate store:
certlm.msctest.crtjust created (will be in C:\OpenSSL-Win32\bin)Export this certificate from the store:
test.p7b& save it inC:\OpenSSL-Win32\bin\test.comcertificate that’s currently in cert storerun:
openssl pkcs7 -in test.p7b -inform DER -out result.pem -print_certsrun:
openssl pkcs12 -export -inkey test.key -in result.pem -name test.com -out final_result.pfxImport “final_result.pfx” into the certificate store:
final_result.pfxfile to run the installerRepeat above import steps 1 to 7 again, but this time in step 6, place the certificate in the “Web Hosting” certificate store (so that IIS can see the certificate when binding to https)
Export this certificate from the store (to use in the socket server app):
test.comcertificatetest.com.pfx(save it to C:\ or the location where your “socket server app” will reference it, see below)X509Certificate2 certificate = new X509Certificate2("C:\\test.com.pfx", "password");Add
test.comto host file along with local pc ipCreate IIS website & add bindings to test.com for both http & https (and select the test.com certificate in the https bindings)
Visit https://test.com/your-socket-client.htm (in Chrome/Edge, click advanced > proceed when prompted for ssl warning)
Socket client should now connect successfully over wss using
wss://test.com:xxxx