日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用wss和HTTPS / TLS保护WebSocket的安全

發布時間:2023/12/3 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用wss和HTTPS / TLS保护WebSocket的安全 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

是這個博客的第50條提示,是的!

技術提示#49說明了如何使用用戶名/密碼和Servlet安全機制保護WebSocket的安全。 本技術提示將說明如何在WildFly上使用HTTPS / TLS保護WebSocket。

讓我們開始吧!

  • 創建一個新的密鑰庫: 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]: yesEnter key password for <websocket>(RETURN if same as keystore password): Re-enter new password:

    使用“ websocket”作為便捷密碼。

  • 下載WildFly 8.1 ,解壓縮,然后將“ websocket.keystore”文件復制到standalone/configuration目錄standalone/configuration目錄中。
  • 以以下方式啟動WildFly: ./bin/standalone.sh
  • 使用jboss-cli連接至它: ./bin/jboss-cli.sh -c
  • 將新的安全領域添加為: [standalone@localhost:9990 /] /core-service=management/security-realm=WebSocketRealm:add() {"outcome" => "success"}

    并配置它:

    [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"} }
  • 將新的HTTPS偵聽器添加為: [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"} }
  • 可以從github.com/javaee-samples/javaee7-samples/tree/master/websocket/endpoint-wss獲得一個簡單的示例,以顯示基于TLS的WebSocket安全性。 克隆工作空間并將目錄更改為“ websocket / endpoint-wss”。 該示例的部署描述符具有: <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>

    這樣可以確保任何傳入此應用程序的請求都將自動定向到HTTPS URL。

  • 通過提供以下命令來部署樣本: mvn wildfly:deploy
  • 現在訪問http:// localhost:8080 / endpoint-wss重定向到https:// localhost:8080 / endpoint-wss 。 瀏覽器可能會抱怨自簽名證書。 例如,Chrome顯示以下警告:

    Safari顯示以下警告:

    在任何一種情況下,請單擊“繼續到本地主機”或“繼續”以繼續進行。 然后,建立安全的WebSocket連接。

    要理解的另一個相關要點是,不能從受https保護的頁面建立不安全的WebSocket連接。 例如我們示例中的以下代碼:

    new WebSocket("ws://localhost:8080/endpoint-wss/websocket");

    將在Chrome開發者工具中引發以下異常:

    [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.

    請享用!

    翻譯自: https://www.javacodegeeks.com/2014/10/securing-websocket-using-wss-and-httpstls.html

    總結

    以上是生活随笔為你收集整理的使用wss和HTTPS / TLS保护WebSocket的安全的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。