问题描述
我对这整个WebSocket和SSL证书都不熟悉。
I am a little new to this whole WebSocket and SSL certificate.
所以我在Android端创建了自己的WebSocket服务器,网站就是客户端。我能够使用常规WebSocket (ws://)
但不安全的WebSocket (wss://)
由于它需要SSL证书。
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.
我的问题是如何获得SSL证书?根据我的阅读,SSL证书基于域。我需要它为localhost。我需要这样的地址:
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
我如何获得可与 localhost
一起使用的SSL证书? 。
How can I go about getting a SSL certificate that will work with localhost
.
感谢您的时间!
============= =========编辑=====================
====================== EDIT =====================
我的原因这样做:
我的Android应用程序中有一个蓝牙服务,它将从连接的健康蓝牙设备(如体重秤和血压机)获取数据。我已经实现了这部分,我想获取这些数据并将其传递给网站。 WebSocket似乎更容易,因为用户将打开我的应用程序,当他们自己的重量时,它会自动填充网站上的字段,其重量来自体重秤。我希望我明白这一点。
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.
为此,我需要一种方法将体重或血压值从Java(Android)传递到WebView中加载的网站。所以我认为WebSocket是最简单的方法。
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
谢谢!!!
推荐答案
我们遇到了类似的问题,我们的解决方案是将子域注册到我们的域之一,A记录为127.0.0.1并获得该域的证书。
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 - >记录到127.0.0.1
- 为local.example.com请求的SSL证书
我担心这个答案对你来说太晚了,但是对于其他人来说这可能会有所帮助。
I'm afraid this answer is too late for you however, it can be helpful for others finding this article.
这篇关于使用HTTPS localhost SSL证书保护WebSocket(WSS)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!