Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I do functions shown in SSLClientExample in JavaScript? #1080

Closed
jpaulm opened this issue Oct 8, 2020 · 11 comments
Closed

How do I do functions shown in SSLClientExample in JavaScript? #1080

jpaulm opened this issue Oct 8, 2020 · 11 comments
Labels

Comments

@jpaulm
Copy link

jpaulm commented Oct 8, 2020

Looking at SSLClientExample, I see the main line has key management code, etc., which is almost the same as that shown in SSLServerExample... so my questions are:

a) does this code need to be in both places, and

b) if it needs to be in the client, how do I do that in JavaScript (my client is JavaScript invoked by HTML)?

Thanks! Apologies as this is probably a dumb question!

@marci4
Copy link
Collaborator

marci4 commented Oct 10, 2020

Hey @jpaulm,

the code in the SSLClientExample is necessary, if you use a self signed certificate and you want to trust this.

The self signed certificate is saved in the keystore and most of the code is just to get the sslcontext for that self signed certificate.

If you are connecting to a trusted certificate, you can do it without all that code. Just pass wss://address:port as url and you are good to go.

For the server it is a bit more difficult since the server will need the private key of your certificate.
There are a few ways to get this done, see https://github.com/TooTallNate/Java-WebSocket/wiki/Getting-a-SSLContext-from-different-sources for more.

For the javascript client, it also depends on your certificate. If you use a trusted certificate, you can simple connect to the server with wss://address:port.
If you are using a self signed certificate, you have to trust it e.g. by adding the certificate to your trusted certificates or open the websocket url with https:// instead (https://address:port). The browser will report an error for the certificate but you are able to trust it in this dialog as well.

Best regards,
Marcel

@jpaulm
Copy link
Author

jpaulm commented Oct 10, 2020

That's a great help - thanks, Marcel! Looks like one option is colon after the double slash - I haven't run into that before! I can't even find a definition for it using Google...?

@marci4
Copy link
Collaborator

marci4 commented Oct 11, 2020

I think markdown did screw with me. I edited my post

Sorry

@jpaulm
Copy link
Author

jpaulm commented Oct 11, 2020

Many thanks, Marcel! I don't know much about trusted and/or self-signed certificates, so I had better do some reading! I followed some "recipes", but they are not much use if I don't really know what I'm doing! The weird thing is that I did find a reference to
//:192.168.0.1 while Googling, but I don't know if it was a typo!

Thanks, and regards

@jpaulm
Copy link
Author

jpaulm commented Oct 12, 2020

Sorry to bother you - but I just need a direction! I am trying to test wss: in my JavaScript/HTML client, and it just dies on the chatclient.send! No error message or anything! I know it reached the "send", but I have no idea what state it is in after that! So I am just wondering if you could point me at a debugging tool, error test, listener, or whatever, so that I could resume testing...! I am completely stuck at this point! I know very little about JS, but my test case with ws: does work! It is only the wss: case that gives me trouble!

Many thanks in advance!

@PhilipRoman
Copy link
Collaborator

@jpaulm Try using the developer console (Ctrl+Shift+i) and check the console for any errors or warnings.

@jpaulm
Copy link
Author

jpaulm commented Oct 12, 2020

Fantastic! That's excellent - thanks so much, Philip!

@jpaulm
Copy link
Author

jpaulm commented Dec 9, 2020

@marci4 Came across your Oct. 10 comment: "If you are using a self signed certificate, you have to trust it e.g. by adding the certificate to your trusted certificates or open the websocket url with https:// instead (https://address:port). The browser will report an error for the certificate but you are able to trust it in this dialog as well."

Just figured out how to do this, and it gave me a message of 404 Websocket Upgrade Failure , so I guess i will try the first alternative...

Just to verify: I can do this with JavaScript clients, right? Very little info out on the 'net... Thanks!

@ItsHarper
Copy link
Contributor

@jpaulm Note that 404 Websocket Upgrade Failure is the error you'll get if you try to connect to a WebSocket server by typing its address into your browser. You have to make the connection using the WebSocket JavaScript API for browsers (or a library for whatever your client platform is).

@marci4
Copy link
Collaborator

marci4 commented Dec 9, 2020

@jpaulm that is expected but the only way to trust the self signed certificate I know (without flags or adding it to the os certificate store)

@jpaulm
Copy link
Author

jpaulm commented Dec 9, 2020

Thanks for your prompt answers, @noahandrews and @marci4 ! I managed to get my certificate trusted, so things seem to be working... with Chrome, but not with Firefox, though - I seem to remember reading that somewhere that Firefox is different, but I'm not sure how or why (it gives a message of "An established connection was aborted by the software in your host machine" and crashes!)...?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants