mkuklis / phonegap-websocket

Websocket PhoneGap plugin for Android
203 stars 78 forks source link

WSS support #17

Closed rgillan closed 10 years ago

rgillan commented 10 years ago

Support for WSS, with a preference to selecting either WS or WSS by the prefix in the URL parameter

mkuklis commented 10 years ago

@rgillan I think I will have to wait with this until some cases in https://github.com/TooTallNate/Java-WebSocket/ are done. In particular I would like to get this merged first: https://github.com/TooTallNate/Java-WebSocket/issues/155

rgillan commented 10 years ago

Michal,

This is the one to watch: https://github.com/TooTallNate/Java-WebSocket/pull/205

This was tested a couple of weeks ago and hopefully will make it in soon. We are still trying to get to the bottom of the larger packet size failing.

/r

On 19/09/2013, at 6:27 AM, Michal Kuklis notifications@github.com wrote:

@rgillan I think I will have to wait with this until some cases in https://github.com/TooTallNate/Java-WebSocket/ are done. In particular I would like to get this merged first: TooTallNate/Java-WebSocket#155

— Reply to this email directly or view it on GitHub.

mkuklis commented 10 years ago

Thank you for point this one to me Rob.

On 9/18/13 6:11 PM, Rob Gillan wrote:

Michal,

This is the one to watch: https://github.com/TooTallNate/Java-WebSocket/pull/205

This was tested a couple of weeks ago and hopefully will make it in soon. We are still trying to get to the bottom of the larger packet size failing.

/r

On 19/09/2013, at 6:27 AM, Michal Kuklis notifications@github.com wrote:

@rgillan I think I will have to wait with this until some cases in https://github.com/TooTallNate/Java-WebSocket/ are done. In particular I would like to get this merged first: TooTallNate/Java-WebSocket#155

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHub https://github.com/mkuklis/phonegap-websocket/issues/17#issuecomment-24703760.

aburtnett commented 10 years ago

First off, thank you for this great plugin which has allowed me to connect to both ws:// and wss:// websockets in Android 4.0 and above. I haven't tested anything lower. I was able to get WSS working by modifying the CordovaClient constructor by adding this code:

//We must use a secure socket for a wss:// URI
if (serverURI.getScheme().equals("wss")) {
  try {
    SSLContext sslContext = null;
    sslContext = SSLContext.getInstance( "TLS" );
    sslContext.init( null, null, null ); // will use java's default key and trust store which is sufficient unless you deal with self-signed certificates
    SSLSocketFactory factory = sslContext.getSocketFactory();// (SSLSocketFactory) SSLSocketFactory.getDefault();
    this.setSocket(factory.createSocket());
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}

Is this a reasonable solution to the problem of connecting to WSS? What would the preferred approach be to get wss:// working?

Thanks, Andy

MayurChandra commented 10 years ago

@aburtnett I tried your code, but I am getting setSocket is undefined error. Where is it defined? Thanks

MayurChandra commented 10 years ago

@aburtnett I am not able to get wss working using SSL certificates so am intrigued how you managed it on Android. Any help?

mkuklis commented 10 years ago

@aburtnett thank you for your snippet. It will be helpful to add WSS support. The recent version of Java-Websocket has changed so I will have to take another look at it. I plan to add the WSS support by the end of this week. I will probably use part of your code. Thanks again!

aburtnett commented 10 years ago

Do you have the latest java_websocket.jar? The WebSocketClient.setSocket() method was only added a few days ago in this commit:

https://github.com/TooTallNate/Java-WebSocket/commit/60425255a37b1ee95260ed54b6d13925c05d8225#diff-1d71083456e5001270f1e266bf262b1f

Andy

mkuklis commented 10 years ago

@aburtnett yes I believe the current jar https://github.com/mkuklis/phonegap-websocket/tree/master/libs includes that already.

MayurChandra commented 10 years ago

@mkuklis is it possible to update the old websocket code to work with wss? I am using Phonegap v2.5 and have loads of other plugins that work with that version. If I upgrade to PG3 then my other plugins would stop working. I trust your excellent WS plugin and would love to use it with Phonegap 2.5 with wss support. Any help? Thanks.

@aburtnett Thanks, I have not updated my Phonegap!

MayurChandra commented 10 years ago

@mkuklis Please can you update the old 2.xx version of your WS plugin to use latest jar? Would be so useful! Thanks.

MayurChandra commented 10 years ago

@aburtnett @mkuklis Just tried the latest jar with 2.5 of Phonegap and it works with SSL Certificates on v2.2 of Android. Tried it on v4.3 and v4.1.2 of Android. The changes @aburtnett made, works well. Thank you both!

mkuklis commented 10 years ago

@rgillan I just pushed a little change based on the @aburtnett's snippet which adds wss support (only known providers - not self sign). If you could give it a try and report back if it works for you that would be great.

rgillan commented 10 years ago

Michal,

This is now working, thanks so much. We are using a signed certificate btw.

Cheers Rob

mkuklis commented 10 years ago

@rgillan cool thanks for letting me know.