NathanaelA / nativescript-websockets

Websockets for NativeScript
83 stars 43 forks source link

Advanced Interface in angular nativescript not working #103

Closed gayatri-kadam closed 2 years ago

gayatri-kadam commented 2 years ago

I have created my sslSocketFactory "socketFactory" and then I pass this as the sslSocketFactory parameter while creating the websocket.

ssl() {
      console.log('SSL function callled***********');
      let socketFactory;
      let sslContext;
      let kmf;
      let ks;
      let inputFileStream;
      let passphrase = Array.from("cybersecureapp");

      kmf = javax.net.ssl.KeyManagerFactory.getInstance("X509"); // does not support SunX509
      ks =  java.security.KeyStore.getInstance("PKCS12");
      sslContext = javax.net.ssl.SSLContext.getInstance("TLSv1.2");
      inputFileStream = Application.android.context.getResources().openRawResource(Application.android.context.getResources()
      .getIdentifier("wcdkeys", "raw", Application.android.context.getPackageName()));
      ssf = javax.net.ssl.SSLSocket;

      ks.load(inputFileStream, passphrase);
      kmf.init(ks, passphrase);

      sslContext.init(kmf.getKeyManagers(), null, null);
      socketFactory = sslContext.getSocketFactory();

    }

this._websocket = new WS(this._host, {protocols: [], timeout: 600, sslSocketFactory: socketFactory }); // advance interface - where we pass sslsocketfactory

The client never connects to the websocket server using advanced interface.

EDIT: I am trying to connect my NS client with OpenSSL server. Following are the things that I get:

  1. Handshake is done successfully.

  2. After handshake, OPEN event of websocket is not triggered. There is no error message. I get this after handshake.

    GET / HTTP/1.1 Connection: Upgrade Host: 172.20.10.3 Origin: https://172.20.10.3:443 Sec-WebSocket-Key: O7m5DLjtKfBU47t17V6xcQ== Sec-WebSocket-Protocol: text Sec-WebSocket-Version: 13 Upgrade: websocket

  3. When I stop the server, the connection closes and the CLOSE event is triggered on the client-side. And after few seconds Client tries to reconnect. But there is no OPEN event triggered at all.

To summarize, on OPEN and MESSAGE events of WS do not get triggered but only CLOSE and ERROR events are triggered.

gayatri-kadam commented 2 years ago

Looks like the OpenSSL server does not support Websocket. I used a secured server developed using nodejs and it worked.