1.2. 为在 JBoss EAP 上部署的应用程序启用单向 SSL/TLS
为 JBoss EAP 上部署的应用启用单向 SSL/TLS,因此 Web 浏览器等应用与客户端之间的通信是安全的。
要为在 JBoss EAP 上部署的应用程序启用单向 SSL/TLS,您可以使用以下步骤:
- 使用自动 生成的自签名证书为应用程序启用 SSL/TLS :仅在开发或测试环境中使用此流程。此流程可帮助您快速为应用程序启用 SSL/TLS,而无需进行任何配置。
- 使用向导为 JBoss EAP 上部署的应用程序启用单向 SSL/TLS :使用此流程使用基于 CLI 的向导来快速设置 SSL/TLS。Elytron 根据您的向导的输入创建所需资源。
- 使用子系统命令为应用程序启用单向 SSL/TLS :使用此方法配置所需资源以手动启用 SSL/TLS。手动配置资源可让您更好地控制服务器配置。
此外,您可以使用 安全命令禁用 SSL/TLS 的步骤,为 JBoss EAP 上部署的应用程序禁用 SSL/TLS。
1.2.1. Elytron 中的默认 SSL 上下文 复制链接链接已复制到粘贴板!
为了帮助开发人员为应用程序快速设置单向 SSL/TLS,elytron 子系统包含启用单向 SSL/TLS 所需的资源,默认准备在开发或测试环境中使用。
默认提供以下资源:
-
名为
applicationKS的key-store。 -
key-manager,名为applicationKM,引用key-store。 -
名为
applicationSSC的server-ssl-context,引用key-manager。
默认 TLS 配置
默认 key-manager applicationKM 包含一个 generate-self-signed-certificate-host 属性,值为 localhost。generate-self-signed-certificate-host 属性表示当使用此 key-manager 获取服务器证书时,如果支持其 key-store 的文件不存在,则 key-manager 应该自动生成自签名证书,并将 localhost 用作 通用名称。生成的自签名证书存储在支持 key-store 的文件中。
由于安装服务器时支持默认 key-store 的文件,只需向服务器发送 https 请求会生成自签名证书,并为应用程序启用单向 SSL/TLS。如需更多信息,请参阅使用自动生成的自签名证书为应用程序启用 SSL/TLS。
1.2.2. 使用自动生成的自签名证书为应用程序启用 SSL/TLS 复制链接链接已复制到粘贴板!
当服务器第一次收到 HTTPS 请求时,JBoss EAP 会自动生成自签名证书。elytron 子系统还包含可在开发或测试环境中使用的 key-store、key-manager 和 server-ssl-context 资源。因此,当 JBoss EAP 生成自签名证书后,应用程序就会使用证书进行保护。
不要在生产环境中使用自签名证书。仅使用证书颁发机构(CA)签名的证书。
先决条件
- JBoss EAP 正在运行。
流程
导航到端口
8443上的服务器 URL,例如 https://localhost:8443。JBoss EAP 在收到此请求时生成自签名证书。有关此证书的详情,您可以查看服务器日志。
浏览器会将连接标记为不安全,因为生成的证书是自签名的。
验证
将显示的证书 JBoss EAP 与浏览器与服务器日志中的证书进行比较。
服务器日志示例
17:50:24,086 WARN [org.wildfly.extension.elytron] (default task-1) WFLYELY01085: Generated self-signed certificate at /home/user1/Downloads/wildflies/wildfly-27.0.1.Final/standalone/configuration/application.keystore. Please note that self-signed certificates are not secure and should only be used for testing purposes. Do not use this self-signed certificate in production. SHA-1 fingerprint of the generated key is 11:2f:e7:8c:18:b7:2c:c1:b0:5a:ad:ea:83:e0:32:59:ba:73:91:e2 SHA-256 fingerprint of the generated key is b2:a4:ed:b0:5c:c2:a1:4c:ca:39:03:e8:3a:11:e4:c5:c4:81:9d:46:97:7c:e6:6f:0c:45:f6:5d:64:3f:0d:64
17:50:24,086 WARN [org.wildfly.extension.elytron] (default task-1) WFLYELY01085: Generated self-signed certificate at /home/user1/Downloads/wildflies/wildfly-27.0.1.Final/standalone/configuration/application.keystore. Please note that self-signed certificates are not secure and should only be used for testing purposes. Do not use this self-signed certificate in production. SHA-1 fingerprint of the generated key is 11:2f:e7:8c:18:b7:2c:c1:b0:5a:ad:ea:83:e0:32:59:ba:73:91:e2 SHA-256 fingerprint of the generated key is b2:a4:ed:b0:5c:c2:a1:4c:ca:39:03:e8:3a:11:e4:c5:c4:81:9d:46:97:7c:e6:6f:0c:45:f6:5d:64:3f:0d:64Copy to Clipboard Copied! Toggle word wrap Toggle overflow 向浏览器显示的证书示例
SHA-256 Fingerprint B2 A4 ED B0 5C C2 A1 4C CA 39 03 E8 3A 11 E4 C5 C4 81 9D 46 97 7C E6 6F 0C 45 F6 5D 64 3F 0D 64 SHA-1 Fingerprint 11 2F E7 8C 18 B7 2C C1 B0 5A AD EA 83 E0 32 59 BA 73 91 E2
SHA-256 Fingerprint B2 A4 ED B0 5C C2 A1 4C CA 39 03 E8 3A 11 E4 C5 C4 81 9D 46 97 7C E6 6F 0C 45 F6 5D 64 3F 0D 64 SHA-1 Fingerprint 11 2F E7 8C 18 B7 2C C1 B0 5A AD EA 83 E0 32 59 BA 73 91 E2Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 如果指纹匹配,如示例中,您可以继续进入该页面。
为应用程序启用 SSL/TLS。
1.2.3. 使用向导为 JBoss EAP 上部署的应用程序启用单向 SSL/TLS 复制链接链接已复制到粘贴板!
Elytron 提供了一个向导来快速设置 SSL/TLS。您可以使用包含证书的现有密钥存储,或者使用向导生成的密钥存储和自签名证书来启用 SSL/TLS。您还可以使用 --lets-encrypt 选项从 Let 的 Encrypt 证书颁发机构获取和使用证书。有关 Let's Encrypt 的详情,请查看 Let 的加密文档。
使用向导生成的自签名证书来启用 SSL/TLS,仅用于测试和开发目的。对于生产环境,始终使用证书颁发机构(CA)签名证书。
不要在生产环境中使用自签名证书。仅使用证书颁发机构(CA)签名的证书。
向导配置为应用程序启用 SSL/TLS 所需的以下资源:
-
key-store -
key-manager -
server-ssl-context -
然后,
server-ssl-context应用到 Undertowhttps-listener。
Elytron 将每个资源命名为 resource-type-UUID。例如,key-store-9e35a3be-62bb-4fff-afc2-2d8d141b82bc。通用唯一标识符(UUID)有助于避免资源的名称冲突。
先决条件
- JBoss EAP 正在运行。
流程
在管理 CLI 中输入以下命令来启动向导来为应用程序配置单向 SSL/TLS:
语法
security enable-ssl-http-server --interactive
security enable-ssl-http-server --interactiveCopy to Clipboard Copied! Toggle word wrap Toggle overflow 提示时输入所需信息。
使用
--lets-encrypt选项从 Let 的 Encrypt 证书颁发机构获取和使用证书。如果
server-ssl-context已存在,向导会退出,并显示以下信息:An SSL server context already exists on the HTTPS listener, use --override-ssl-context option to overwrite the existing SSL context
An SSL server context already exists on the HTTPS listener, use --override-ssl-context option to overwrite the existing SSL contextCopy to Clipboard Copied! Toggle word wrap Toggle overflow 注意elytron子系统默认包含一个已配置的server-ssl-context资源。因此,您必须在全新安装后第一次启动向导时使用--override-ssl-context选项。如需更多信息,请参阅 Elytron 中的默认 SSL 上下文。
如果您覆盖现有的
server-ssl-context,Elytron 将使用向导创建的server-ssl-context来启用 SSL。注意要启用单向 SSL/TLS,请在提示启用 SSL 相互身份验证时输入
n或 blank。设置 mutual 身份验证可启用双向 SSL/TLS。启动向导示例
security enable-ssl-http-server --interactive --override-ssl-context
security enable-ssl-http-server --interactive --override-ssl-contextCopy to Clipboard Copied! Toggle word wrap Toggle overflow 向导提示输入示例
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 输入
y后,服务器会使用以下输出重新载入:Server reloaded. SSL enabled for default-server ssl-context is ssl-context-4cba6678-c464-4dcc-90ff-9295312ac395 key-manager is key-manager-4cba6678-c464-4dcc-90ff-9295312ac395 key-store is key-store-4cba6678-c464-4dcc-90ff-9295312ac395
Server reloaded. SSL enabled for default-server ssl-context is ssl-context-4cba6678-c464-4dcc-90ff-9295312ac395 key-manager is key-manager-4cba6678-c464-4dcc-90ff-9295312ac395 key-store is key-store-4cba6678-c464-4dcc-90ff-9295312ac395Copy to Clipboard Copied! Toggle word wrap Toggle overflow
验证
如果您使用了自签名证书,浏览器会显示一个警告,表示服务器出示的证书未知。
检查证书,并验证浏览器中显示的指纹是否与密钥存储中的证书的指纹匹配。您可以使用以下命令查看生成的证书:
语法
/subsystem=elytron/key-store=<server_keystore_name>:read-alias(alias=<alias>)
/subsystem=elytron/key-store=<server_keystore_name>:read-alias(alias=<alias>)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
/subsystem=elytron/key-store=key-store-4cba6678-c464-4dcc-90ff-9295312ac395:read-alias(alias="localhost")
/subsystem=elytron/key-store=key-store-4cba6678-c464-4dcc-90ff-9295312ac395:read-alias(alias="localhost")Copy to Clipboard Copied! Toggle word wrap Toggle overflow 您可以从向导的输出中获取密钥存储名称,例如 "key-store 为 key-store-4cba6678-c464-4dcc-90ff-9295312ac395"。
输出示例
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
现在,在 JBoss EAP 上部署的应用程序启用了 SSL/TLS。
1.2.4. 使用 subsystem 命令为应用程序启用单向 SSL/TLS 复制链接链接已复制到粘贴板!
使用 elytron 子系统命令,使用 SSL/TLS 保护在 JBoss EAP 上部署的应用。
出于测试和开发目的,您可以使用自签名证书。您可以使用包含证书的现有密钥存储,或者在创建 key-store 资源时使用 Elytron 生成的密钥存储。对于生产环境,始终使用证书颁发机构(CA)签名证书。
不要在生产环境中使用自签名证书。仅使用证书颁发机构(CA)签名的证书。
先决条件
- JBoss EAP 正在运行。
流程
配置密钥存储以存储证书。
您可以提供到现有密钥存储的路径,例如,包含 CA 签名证书的路径,或者提供要创建的密钥存储的路径。
/subsystem=elytron/key-store=<keystore_name>:add(path=<path_to_keystore>, credential-reference=<credential_reference>, type=<keystore_type>)
/subsystem=elytron/key-store=<keystore_name>:add(path=<path_to_keystore>, credential-reference=<credential_reference>, type=<keystore_type>)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
/subsystem=elytron/key-store=exampleKeyStore:add(path=exampleserver.keystore.pkcs12, relative-to=jboss.server.config.dir,credential-reference={clear-text=secret},type=PKCS12)/subsystem=elytron/key-store=exampleKeyStore:add(path=exampleserver.keystore.pkcs12, relative-to=jboss.server.config.dir,credential-reference={clear-text=secret},type=PKCS12)Copy to Clipboard Copied! Toggle word wrap Toggle overflow 如果密钥存储不包含任何证书,或者您使用上面的步骤来创建密钥存储,则必须生成证书并将证书存储在文件中。
在密钥存储中生成密钥对。
语法
/subsystem=elytron/key-store=<keystore_name>:generate-key-pair(alias=<keystore_alias>,algorithm=<algorithm>,key-size=<key_size>,validity=<validity_in_days>,credential-reference=<credential_reference>,distinguished-name="<distinguished_name>")
/subsystem=elytron/key-store=<keystore_name>:generate-key-pair(alias=<keystore_alias>,algorithm=<algorithm>,key-size=<key_size>,validity=<validity_in_days>,credential-reference=<credential_reference>,distinguished-name="<distinguished_name>")Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
/subsystem=elytron/key-store=exampleKeyStore:generate-key-pair(alias=localhost,algorithm=RSA,key-size=2048,validity=365,credential-reference={clear-text=secret},distinguished-name="CN=localhost")/subsystem=elytron/key-store=exampleKeyStore:generate-key-pair(alias=localhost,algorithm=RSA,key-size=2048,validity=365,credential-reference={clear-text=secret},distinguished-name="CN=localhost")Copy to Clipboard Copied! Toggle word wrap Toggle overflow 将证书存储在文件中。
语法
/subsystem=elytron/key-store=<keystore_name>:store()
/subsystem=elytron/key-store=<keystore_name>:store()Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
/subsystem=elytron/key-store=exampleKeyStore:store()
/subsystem=elytron/key-store=exampleKeyStore:store()Copy to Clipboard Copied! Toggle word wrap Toggle overflow
配置引用
key-store的key-manager。语法
/subsystem=elytron/key-manager=<key-manager_name>:add(key-store=<key-store_name>,credential-reference=<credential_reference>)
/subsystem=elytron/key-manager=<key-manager_name>:add(key-store=<key-store_name>,credential-reference=<credential_reference>)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
/subsystem=elytron/key-manager=exampleKeyManager:add(key-store=exampleKeyStore,credential-reference={clear-text=secret})/subsystem=elytron/key-manager=exampleKeyManager:add(key-store=exampleKeyStore,credential-reference={clear-text=secret})Copy to Clipboard Copied! Toggle word wrap Toggle overflow 重要红帽没有指定 algorithm 属性,因为
elytron子系统使用KeyManagerFactory.getDefaultAlgorithm ()来默认确定算法。但是,您可以指定 algorithm 属性。要指定 algorithm 属性,您需要知道您使用的 Java Development Kit (JDK)提供哪些密钥管理器算法。例如,使用 Java 安全套接字扩展(SunJSSE)的 JDK 提供了 PKIX 和 SunX509 算法。
在命令中,您可以指定 SunX509 作为
key-manager算法属性。配置引用
key-manager的server-ssl-context。语法
/subsystem=elytron/server-ssl-context=<server-ssl-context_name>:add(key-manager=<key-manager_name>, protocols=<list_of_protocols>)
/subsystem=elytron/server-ssl-context=<server-ssl-context_name>:add(key-manager=<key-manager_name>, protocols=<list_of_protocols>)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
/subsystem=elytron/server-ssl-context=examplehttpsSSC:add(key-manager=exampleKeyManager, protocols=["TLSv1.2"])
/subsystem=elytron/server-ssl-context=examplehttpsSSC:add(key-manager=exampleKeyManager, protocols=["TLSv1.2"])Copy to Clipboard Copied! Toggle word wrap Toggle overflow 重要您需要确定您要支持的 SSL/TLS 协议。示例命令使用 TLSv1.2。
-
对于 TLSv1.2 及更早版本,请使用
cipher-suite-filter参数指定允许哪些密码套件。 -
对于 TLSv1.3,使用
cipher-suite-names参数指定允许哪些密码套件。TLSv1.3 默认禁用。如果您没有使用 protocol 属性指定协议,或者指定的集合包含 TLSv1.3,请配置cipher-suite-names启用 TLSv1.3。
使用
use-cipher-suites-order参数来遵循服务器密码套件顺序。use-cipher-suites-order属性默认设置为true。这与旧的 security 子系统行为不同,它默认为遵循客户端密码套件顺序。-
对于 TLSv1.2 及更早版本,请使用
更新 Undertow,以使用配置的
server-ssl-context。语法
/subsystem=undertow/server=default-server/https-listener=https:write-attribute(name=ssl-context, value=<server-ssl-context_name>)
/subsystem=undertow/server=default-server/https-listener=https:write-attribute(name=ssl-context, value=<server-ssl-context_name>)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
/subsystem=undertow/server=default-server/https-listener=https:write-attribute(name=ssl-context, value=examplehttpsSSC)
/subsystem=undertow/server=default-server/https-listener=https:write-attribute(name=ssl-context, value=examplehttpsSSC)Copy to Clipboard Copied! Toggle word wrap Toggle overflow 重新加载服务器。
reload
reloadCopy to Clipboard Copied! Toggle word wrap Toggle overflow
验证
如果您使用了自签名证书,浏览器会显示一个警告,表示服务器出示的证书未知。
检查证书,并验证浏览器中显示的指纹是否与密钥存储中的证书的指纹匹配。您可以使用以下命令查看生成的证书:
语法
/subsystem=elytron/key-store=<server_keystore_name>:read-alias(alias=<alias>)
/subsystem=elytron/key-store=<server_keystore_name>:read-alias(alias=<alias>)Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
/subsystem=elytron/key-store=exampleKeyStore:read-alias(alias=localhost)
/subsystem=elytron/key-store=exampleKeyStore:read-alias(alias=localhost)Copy to Clipboard Copied! Toggle word wrap Toggle overflow 输出示例
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
现在,在 JBoss EAP 上部署的应用程序启用了 SSL/TLS。
1.2.5. 使用 security 命令为应用程序禁用 SSL/TLS 复制链接链接已复制到粘贴板!
使用 security 命令为 JBoss EAP 上部署的应用程序禁用 SSL/TLS。使用 命令禁用 SSL/TLS 不会删除 Elytron 资源。命令仅将服务器的 ssl-context 设置为其默认值 applicationSSC。
先决条件
- JBoss EAP 正在运行。
流程
在管理 CLI 中使用
security disable-ssl-http-server命令。security disable-ssl-http-server
security disable-ssl-http-serverCopy to Clipboard Copied! Toggle word wrap Toggle overflow 服务器使用以下输出重新加载:
... Server reloaded. SSL disabled for default-server
... Server reloaded. SSL disabled for default-serverCopy to Clipboard Copied! Toggle word wrap Toggle overflow
您可以使用以下流程之一为在 JBoss EAP 上部署的应用程序启用 SSL/TLS:
- 使用自动 生成的自签名证书为应用程序启用 SSL/TLS :仅在开发或测试环境中使用此流程。此流程可帮助您快速为应用程序启用 SSL/TLS,而无需进行任何配置。
- 使用向导为 JBoss EAP 上部署的应用程序启用单向 SSL/TLS :使用此流程使用基于 CLI 的向导来快速设置 SSL/TLS。Elytron 根据您的向导的输入创建所需资源。
- 使用子系统命令为应用程序启用单向 SSL/TLS :使用此方法配置所需资源以手动启用 SSL/TLS。手动配置资源可让您更好地控制服务器配置。