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

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2023/12/3 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 websocket wss_使用wss和HTTPS / TLS保护WebSocket的安全 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

websocket wss

這個(gè)博客的第50條提示,是的!

技術(shù)提示#49說(shuō)明了如何使用用戶名/密碼和Servlet安全機(jī)制保護(hù)WebSocket的安全。 本技術(shù)提示將說(shuō)明如何在WildFly上使用HTTPS / TLS保護(hù)WebSockets。

讓我們開(kāi)始吧!

  • 創(chuàng)建一個(gè)新的密鑰庫(kù): 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”文件復(fù)制到standalone/configuration目錄standalone/configuration目錄中。
  • 以以下方式啟動(dòng)WildFly: ./bin/standalone.sh
  • 使用jboss-cli連接到它: ./bin/jboss-cli.sh -c
  • 將新的安全領(lǐng)域添加為: [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偵聽(tīng)器添加為: [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獲得一個(gè)簡(jiǎn)單的示例,以顯示基于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>

    這樣可以確保任何傳入此應(yīng)用程序的請(qǐng)求都將自動(dòng)定向到HTTPS URL。

  • 通過(guò)提供以下命令來(lái)部署示例: mvn wildfly:deploy
  • 現(xiàn)在訪問(wèn)http:// localhost:8080 / endpoint-wss重定向到https:// localhost:8080 / endpoint-wss 。 瀏覽器可能會(huì)抱怨自簽名證書(shū)。 例如,Chrome顯示以下警告:

    Safari顯示以下警告:

    無(wú)論哪種情況,都單擊“繼續(xù)到本地主機(jī)”或“繼續(xù)”以繼續(xù)進(jìn)行。 然后,建立安全的WebSocket連接。

    要理解的另一個(gè)相關(guān)要點(diǎn)是,不能從受https保護(hù)的頁(yè)面建立不安全的WebSocket連接。 例如我們示例中的以下代碼:

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

    將在Chrome開(kāi)發(fā)者工具中引發(fā)以下異常:

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

    請(qǐng)享用!

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

    websocket wss

    總結(jié)

    以上是生活随笔為你收集整理的websocket wss_使用wss和HTTPS / TLS保护WebSocket的安全的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。