nativescript-websockets icon indicating copy to clipboard operation
nativescript-websockets copied to clipboard

sslSocketFactory Parameter in Android

Open Dennis-kw-yiu opened this issue 6 years ago • 5 comments

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.

Dennis-kw-yiu avatar Nov 10 '18 06:11 Dennis-kw-yiu

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...

NathanaelA avatar Nov 13 '18 16:11 NathanaelA

May I know how to setup the sslSocketFactory?

Dennis-kw-yiu avatar Nov 21 '18 16:11 Dennis-kw-yiu

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.

sido420 avatar Dec 19 '20 04:12 sido420

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".

gayatri-kadam avatar Mar 22 '22 05:03 gayatri-kadam

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....

NathanaelA avatar Mar 22 '22 18:03 NathanaelA