NathanaelA / nativescript-websockets

Websockets for NativeScript
83 stars 43 forks source link

sslSocketFactory Parameter in Android #60

Open Dennis-kw-yiu opened 5 years ago

Dennis-kw-yiu commented 5 years ago

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.

NathanaelA commented 5 years ago

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

Dennis-kw-yiu commented 5 years ago

May I know how to setup the sslSocketFactory?

sido420 commented 3 years ago

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.

gayatri-kadam commented 2 years ago

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

NathanaelA commented 2 years ago

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