Securing WebSocket using wss and HTTPS/TLS (Tech Tip #50)

50th tip on this blog, yaay!

Tech Tip #49 explained how to secure WebSockets using username/password and Servlet Security mechanisms. This Tech Tip will explain how to secure WebSockets using HTTPS/TLS on WildFly.

Lets get started!

  1. Create a new keystore:

    Used “websocket” as the convenience password.
  2. Download WildFly 8.1, unzip, and copy “websocket.keystore” file in standalone/configuration directory.
  3. Start WildFly as
  4. Connect to it using jboss-cli as:
  5. Add a new security realm as:

    And configure it:
  6. Add a new HTTPS listener as:
  7. A simple sample to show TLS-based security for WebSocket is available at Clone the workspace and change directory to “websocket/endpoint-wss”. The sample’s deployment descriptor has:

    This ensures that any request coming to this application will be auto-directed to an HTTPS URL.
  8. Deploy the sample by giving the command:

Now accessing http://localhost:8080/endpoint-wss redirects to https://localhost:8080/endpoint-wss. The browsers may complain about self-signed certificate. For example, Chrome shows the following warning:


And Safari shows the following warning:


In either case, click on “Proceed to localhost” or “Continue” to proceed further. And then a secure WebSocket connection is established.

Another relevant point to understand is that a non-secure WebSocket connection cannot be made from an https-protected page. For example the following code in our sample:

will throw the following exception in Chrome Developer Tools:


Be Sociable, Share!
  • Tweet

2 thoughts on “Securing WebSocket using wss and HTTPS/TLS (Tech Tip #50)

  1. I replied to another post on your blog and hope you don’t feel I am hounding you. I am a coach with a First Lego League team. This is a competition using Lego Mindstorm robots. As part of the competition we present an idea about a solution to a real life problem. To finalize our presentation we need feedback from a mod developer but I am having difficulty reaching anyone. We simply need to know if there already exists any mods using command keys to move the character and/or a mod that makes different sounds when the characters turns right or left. If there is not such a mod, how much time/cost would it take for a proficient mod developer to make such a mod? We would really appreciate any input you can offer. When I mentioned to the boys on our team that I had messaged you, they were very excited because many of them have watched your videos on YouTube. If you are not able to help us, can you point us in the right direction? Thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *

1 × eight =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">