原文 http://www.tuicool.com/articles/goto?id=JR3mmy
50th tip on this blog, yaay!
Tech Tip #49explained 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!
-
Create a new keystore:
keytool -genkey -alias websocket -keyalg RSA -keystore websocket.keystore -validity 10950 Enter keystore password: Re-enter new password: What is your first and last name? [Unknown]: Arun Gupta What is the name of your organizational unit? [Unknown]: JBoss Middleware What is the name of your organization? [Unknown]: Red Hat What is the name of your City or Locality? [Unknown]: San Jose What is the name of your State or Province? [Unknown]: CA What is the two-letter country code for this unit? [Unknown]: US Is CN=Arun Gupta, OU=JBoss Middleware, O=Red Hat, L=San Jose, ST=CA, C=US correct? [no]: yes Enter key password for <websocket> (RETURN if same as keystore password): Re-enter new password:
Used “websocket” as the convenience password.
- Download WildFly 8.1 , unzip, and copy “websocket.keystore” file in
standalone/configuration
directory. - Start WildFly as
./bin/standalone.sh
- Connect to it using jboss-cli as:
./bin/jboss-cli.sh -c
-
Add a new security realm as:
[standalone@localhost:9990 /] /core-service=management/security-realm=WebSocketRealm:add() {"outcome" => "success"}
And configure it:
[standalone@localhost:9990 /] /core-service=management/security-realm=WebSocketRealm/server-identity=ssl:add(keystore-path=websocket.keystore, keystore-relative-to=jboss.server.config.dir, keystore-password=websocket) { "outcome" => "success", "response-headers" => { "operation-requires-reload" => true, "process-state" => "reload-required" } }
- Add a new HTTPS listener as:
[standalone@localhost:9990 /] /subsystem=undertow/server=default-server/https-listener=https:add(socket-binding=https, security-realm=WebSocketRealm) { "outcome" => "success", "response-headers" => {"process-state" => "reload-required"} }
- A simple sample to show TLS-based security for WebSocket is available at github.com/javaee-samples/javaee7-samples/tree/master/websocket/endpoint-wss
. Clone the workspace and change directory to “websocket/endpoint-wss”. The sample’s deployment descriptor has:
<security-constraint> <web-resource-collection> <web-resource-name>Secure WebSocket</web-resource-name> <url-pattern>/*</url-pattern> </web-resource-collection> <user-data-constraint> <transport-guarantee>CONFIDENTIAL</transport-guarantee> </user-data-constraint> </security-constraint>
This ensures that any request coming to this application will be auto-directed to an HTTPS URL.
- Deploy the sample by giving the command:
mvn wildfly:deploy
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:
new WebSocket("ws://localhost:8080/endpoint-wss/websocket");
will throw the following exception in Chrome Developer Tools:
[blocked] The page at 'https://localhost:8443/endpoint-wss/index.jsp' was loaded over HTTPS, but ran insecure content from 'ws://localhost:8080/endpoint-wss/websocket': this content should also be loaded over HTTPS. Uncaught SecurityError: Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.
Enjoy!
相关推荐
- **技术编辑团队**:包括 Arun Nadar、Kapil Hemnani 和 Monica John 等在内的技术编辑团队确保了书中内容的专业性和准确性。 #### 本书核心知识点概览 基于上述信息,我们可以总结出本书将涵盖的关键知识点: 1....
ML教程-由Dr.-Arun-Chauhan- 该存储库包含ML的所有教程代码
Author: Arun Gupta, Geertjan Wielenga, John Brock Length: 176 pages Edition: 1 Language: English Publisher: McGraw-Hill Osborne Media Publication Date: 2014-03-25 ISBN-10: 0071823093 ISBN-13: ...
Added examples.0.9.2.1b- Fixed a bug when send a mail and the first line disappear (thanks to Arun)- Now, you could do MySMTP.MsgTo := ‘a@doma.com; b@domb.com;c@domc.com‘; the spaces before/after ...
CVE-2020-35682 SD-91948:CVE-2020-35682:在ServiceDesk Plus中进行SAML登录期间,身份验证绕过漏洞。 (如)。 如果目标ServiceDesk Plus(<...┌─[✗]─[felli0t@damnlab]─[~/POCs/CVE-2020-35682] └──╼
#FEWD 课程 - Arun Sood ##Week 2:布局 ###Day 2: ##第 3 周:高级布局 ###Day 2: ##第 4 周:编程简介 ###Day 2: ##第 5 周:JavaScript 继续 ###第一天: ###Day 2: ##第 6 周:回顾 ###Day 1: ###...
《多生物特征识别手册》是一本关于多生物特征识别技术的经典书籍,由Arun Ross、Karthis Nandakumar以及Anil K. Jain三位在计算机科学领域的专家共同编写。本书主要探讨了多生物特征识别系统的各个方面,特别是不同...
【标题】"chetty-arun.github.io:chettyarun.in 的投资组合"指的是一个个人投资组合网站,它被托管在GitHub Pages上。这个网站可能是由Arun Chetty创建的,用于展示他的专业技能、项目经历和个人成就。GitHub Pages...
■■ Learn the fundamentals of Minecraft Forge and other tools, such as Eclipse ■■ Start out by building and testing a simple chat message mod ■■ Build cool mods that make things explode on ...
fab packages.go-install -H [user]@[host] 而且您的工作时间不到15秒。 假设您要在Macbook Pro上启动ssh隧道代理服务, 您需要做的就是运行 invoke patches.proxy 1 6666 [user]@[host] Wi-Fi --r
### 振动模拟在MATLAB与ANSYS中的应用 #### 一、绪论与系统表示 本书《振动模拟在MATLAB与ANSYS中的应用》(出版日期:2000年9月21日;ISBN-10:1584882050;ISBN-13:978-1584882053)旨在为初学者或不常使用动力...
使用Gatsby CLI创建一个新站点,并指定此项目gatsby new project-name https://github.com/LekoArts/gatsby-starter-portfolio-cara 开始开发。 导航到新站点的目录并启动。 cd project-namegatsby develop 打开...
rcnn代码具有综合图像语言线索的短语定位和视觉关系检测 pl-clc包含我们的实现,它比最初的 arXiv 提交有几个实现改进。 如果您发现此代码对您的研究有用,请考虑引用: @inproceedings{plummerPLCLC2017, Author = ...
PS-XT编码分配 一个前端应用程序,它将...$ git https://github.com/arun-maddheshia/ps-xt-coding-assignment.git [your-project-name] $ cd [your-project-name] # set up `origin` $ git remote set-url origin [yo
ARun2.1.8.0是一款注册表查看工具,其RAR压缩包文件名提示了该软件的版本信息,即2.1.8.0。在Windows操作系统中,注册表是一个至关重要的数据库,它存储了系统和应用程序的配置设置。这款工具可能是为了帮助用户更加...
Vue.js样板此样板建立在Vue CLI 3.0的顶部。 这提供了有助于编写灵活且模块化的大型Vue.js样板的体系结构。该样板建立在Vue CLI 3.0的顶部。 这提供了一种有助于使用Vue.js编写灵活的模块化大规模应用程序的体系结构...
从内容摘录中我们可以看出,文件列出了多个与石油和天然气行业相关的分析师的联系信息,其中包括负责不同子领域的分析师,如Arun Jayaram、Michael Glick、Sean C Meakim、Phil Gresh、Jeremy Tonet和Christopher ...