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 配置
... <tls> <key-stores> <key-store name="applicationKS"> <credential-reference clear-text="password"/> <implementation type="JKS"/> <file path="application.keystore" relative-to="jboss.server.config.dir"/> </key-store> </key-stores> <key-managers> <key-manager name="applicationKM" key-store="applicationKS" generate-self-signed-certificate-host="localhost"> <credential-reference clear-text="password"/> </key-manager> </key-managers> <server-ssl-contexts> <server-ssl-context name="applicationSSC" key-manager="applicationKM"/> </server-ssl-contexts> </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
向浏览器显示的证书示例
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
- 如果指纹匹配,如示例中,您可以继续进入该页面。
为应用程序启用 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
提示时输入所需信息。
使用
--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
注意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
向导提示输入示例
Please provide required pieces of information to enable SSL: Certificate info: Key-store file name (default default-server.keystore): exampleKeystore.pkcs12 Password (blank generated): secret What is your first and last name? [Unknown]: localhost What is the name of your organizational unit? [Unknown]: What is the name of your organization? [Unknown]: What is the name of your City or Locality? [Unknown]: What is the name of your State or Province? [Unknown]: What is the two-letter country code for this unit? [Unknown]: Is CN=localhost, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown correct y/n [y]?y Validity (in days, blank default): 365 Alias (blank generated): localhost Enable SSL Mutual Authentication y/n (blank n):n //For one way SSL/TLS enter blank or n here SSL options: keystore file: exampleKeystore.pkcs12 distinguished name: CN=localhost, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown password: secret validity: 365 alias: localhost Server keystore file exampleKeystore.pkcs12, certificate file exampleKeystore.pem and exampleKeystore.csr file will be generated in server configuration directory. Do you confirm y/n :y
输入
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
验证
如果您使用了自签名证书,浏览器会显示一个警告,表示服务器出示的证书未知。
检查证书,并验证浏览器中显示的指纹是否与密钥存储中的证书的指纹匹配。您可以使用以下命令查看生成的证书:
语法
/subsystem=elytron/key-store=<server_keystore_name>:read-alias(alias=<alias>)
Example
/subsystem=elytron/key-store=key-store-4cba6678-c464-4dcc-90ff-9295312ac395:read-alias(alias="localhost")
您可以从向导的输出中获取密钥存储名称,例如 "key-store 为 key-store-4cba6678-c464-4dcc-90ff-9295312ac395"。
输出示例
... "sha-1-digest" => "48:e3:6f:16:d1:af:4b:31:8f:9b:0b:7f:33:94:58:af:69:85:c 0:ea", "sha-256-digest" => "8f:3e:6b:b5:56:e0:d1:97:81:bc:f1:8d:c8:66:75:06:db:7d :4d:b6:b1:d3:34:dd:f5:6c:85:ca:c7:2b:5b:c7", ...
现在,在 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>)
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=<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>")
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=<keystore_name>:store()
Example
/subsystem=elytron/key-store=exampleKeyStore:store()
配置引用
key-store
的key-manager
。语法
/subsystem=elytron/key-manager=<key-manager_name>:add(key-store=<key-store_name>,credential-reference=<credential_reference>)
Example
/subsystem=elytron/key-manager=exampleKeyManager:add(key-store=exampleKeyStore,credential-reference={clear-text=secret})
重要红帽没有指定 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>)
Example
/subsystem=elytron/server-ssl-context=examplehttpsSSC:add(key-manager=exampleKeyManager, protocols=["TLSv1.2"])
重要您需要确定您要支持的 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>)
Example
/subsystem=undertow/server=default-server/https-listener=https:write-attribute(name=ssl-context, value=examplehttpsSSC)
重新加载服务器。
reload
验证
如果您使用了自签名证书,浏览器会显示一个警告,表示服务器出示的证书未知。
检查证书,并验证浏览器中显示的指纹是否与密钥存储中的证书的指纹匹配。您可以使用以下命令查看生成的证书:
语法
/subsystem=elytron/key-store=<server_keystore_name>:read-alias(alias=<alias>)
Example
/subsystem=elytron/key-store=exampleKeyStore:read-alias(alias=localhost)
输出示例
... "sha-1-digest" => "cc:f1:82:59:c7:0d:f6:91:bc:3e:69:0a:38:fb:48:be:ec:7f:d 4:bd", "sha-256-digest" => "c0:f3:f9:8b:3c:f1:72:17:64:54:35:a6:bb:82:7e:51:b0:78 :30:cb:68:ef:04:0e:f5:2b:9d:62:ca:a7:f6:35", ...
现在,在 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
服务器使用以下输出重新加载:
... Server reloaded. SSL disabled for default-server
您可以使用以下流程之一为在 JBoss EAP 上部署的应用程序启用 SSL/TLS:
- 使用自动 生成的自签名证书为应用程序启用 SSL/TLS :仅在开发或测试环境中使用此流程。此流程可帮助您快速为应用程序启用 SSL/TLS,而无需进行任何配置。
- 使用向导为 JBoss EAP 上部署的应用程序启用单向 SSL/TLS :使用此流程使用基于 CLI 的向导来快速设置 SSL/TLS。Elytron 根据您的向导的输入创建所需资源。
- 使用子系统命令为应用程序启用单向 SSL/TLS :使用此方法配置所需资源以手动启用 SSL/TLS。手动配置资源可让您更好地控制服务器配置。