简体   繁体   中英

Secure WebSocket (WSS) with HTTPS localhost SSL certificate?

I am a little new to this whole WebSocket and SSL certificate.

So I have created my own WebSocket server on Android side and the website is the client. I was able to make it work with regular WebSocket (ws://) but not secure WebSocket (wss://) due to the fact that it requires SSL certificate.

My question is how can I get a SSL certificate? From what I've read, SSL certificate is based on a domain. I need it for localhost. I need it for something like this address:

wss://localhost:8080/ws/main

How can I go about getting a SSL certificate that will work with localhost .

Thank you for your time!

====================== EDIT =====================

Reason why I am doing this: I have a Bluetooth service in my Android application that will be getting data from connected health bluetooth devices like Weight Scale and Blood Pressure machine. I have this part implemented already and I want to take this data and pass it to a website. WebSocket seemed easier because the user will have my application open and when they do their weight, it would automatically fill the field on the website with the weight from the Weight Scale. I hope I am making this clear.

To do this, I need to have a way to pass the weight or blood pressure values from Java (Android) to the website that loads within a WebView. So I thought WebSocket would the easiest way.

Please tell me if you think there is an easier way.

Also, I've already tried self-signed certificate and I get the following error:

I/X509Util: Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

OR

Exception=javax.net.ssl.SSLException: Error occured in delegated task:javax.net.ssl.SSLException: Not trusted server certificate

Thank you!!!

We faced a similar problem, our solution was to register a subdomain to one of our domains with an A record to 127.0.0.1 and get a certificate for that domain.

  • local.example.com -> A record to 127.0.0.1
  • SSL certificate requested for local.example.com

I'm afraid this answer is too late for you however, it can be helpful for others finding this article.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM