nativescript-websockets
nativescript-websockets copied to clipboard
sslSocketFactory Parameter in Android
Hi All,
I am new to websocket. I need to connect to a websocket in an android device via wss://. However, I cannot do so, exception is shown as below:
javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
I saw that I may need to supply the sslSocketFactory. However, I have no idea how to set the parameter. Is there any genius can help or any other approach can solve my problem? Thank you in advance.
This error normally occurs if you are using WSS and using a self signed certificate. If you are using a self signed cert; then you do have to setup your own sslSocketFactory...
May I know how to setup the sslSocketFactory?
Any updates on this? An example would be truly appreciated.
In my case, its not a self-signed certificate. And, this ZeroSSL certificate works fine from Chrome.
Any updates here? I have set up my own sslSocketFactory and passed it as a parameter while creating the WS but it never connects to the server and throws an error. Is there a sample code for reference? The one in this repository does not demonstrate "Advanced Interface".
Basically you need to follow any of the tutorials that you would do in Java to setup for self signed cert and how to initialize a SSLSocketFactory for it... And then you pass the sslSocketFactor as the options.sslSocketFactory
value when you create a new WebSocket...
const WS = require("@master.technology/websockets");
// Do whatever is needed to configure and create a new sslSocketFactory for your certificate
let mySocket = new WS(URL, {sslSocketFactory: mySslSocketFactory});
// use mySocket....