- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 Tomcat v10.0.x 中使用 HSM 中的 key 来使用 TLS。
tl; dr:请参阅下面的答案以及所有步骤。剩余部分留在下面以允许搜索算法找到它。
我想知道的是,a:(事物的宏伟计划)应该可行,并且 b:(细节)我在 server.xml 连接器中错过了什么?
<Connector port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
<Connector
protocol="org.apache.coyote.http11.Http11NioProtocol"
port="8443"
SSLEnabled="true"
scheme="https"
secure="true"
clientAuth="false"
>
<SSLHostConfig>
protocols="TLSv1.2"
>
<Certificate
type="RSA"
certificateKeystoreType="PKCS11"
certificateKeystoreFile=""
certificateKeystoreProvider="SunPKCS11-CryptoServer"
certificateKeystorePassword="123456"
/>
</SSLHostConfig>
</Connector>
当 Tomcat 启动时,我得到各种 NullPointerExceptions(取决于连接器中的内容)。例子:
27-Oct-2021 10:03:42.669 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["https-openssl-nio-443"]
27-Oct-2021 10:03:42.869 WARNING [main] org.apache.tomcat.util.net.openssl.OpenSSLContext.init Error initializing SSL context
java.lang.NullPointerException: Cannot read the array length because "src" is null
和
27-Oct-2021 15:16:20.406 WARNING [main] org.apache.tomcat.util.net.openssl.OpenSSLContext.init Error initializing SSL context
java.lang.NullPointerException
at java.base/java.util.Base64$Encoder.encode(Base64.java:289)
at java.base/java.util.Base64$Encoder.encodeToString(Base64.java:343)
at org.apache.tomcat.util.net.openssl.OpenSSLContext.addCertificate(OpenSSLContext.java:408)
at org.apache.tomcat.util.net.openssl.OpenSSLContext.init(OpenSSLContext.java:250)
底层 HSM 已正确配置,并且在插槽 0 中具有可用的 key /证书。SunPKCS11-CryptoServer 确实适用于 key 工具。当我启动 tomcat 时,HSM 日志文件中填充了我希望看到的信息。
curl -k -v --tlsv1.2 https://127.0.0.1:8080/
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* error:1408F10B:SSL routines:ssl3_get_record:wrong version number
* stopped the pause stream!
* Closing connection 0
curl: (35) error:1408F10B:SSL routines:ssl3_get_record:wrong version number
和
curl -k -v --tlsv1.2 https://127.0.0.1:8443
* Rebuilt URL to: https://127.0.0.1:8443/
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to 127.0.0.1:8443
* stopped the pause stream!
* Closing connection 0
curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to 127.0.0.1:8443
在日志中,我得到“在方法名称中发现无效字符”和十六进制值:
27-Oct-2021 15:22:58.552 INFO [http-nio-8080-exec-1] org.apache.coyote.http11.Http11Processor.service Error parsing HTTP request header
Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Invalid character found in method name [0x..0x..0x.. ...]. HTTP method names must be tokens
尝试使用 nio 和 nio2。
sslImplementationName="org.apache.tomcat.util.net.jsse.JSSEImplementation"
现在,Tomcat 无一异常(exception)地启动了。但是,当我尝试 curl 时:
curl -k -v --tlsv1.2 https://127.0.0.1:8443
* Rebuilt URL to: https://127.0.0.1:8443/
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS alert, Server hello (2):
* error:14094438:SSL routines:ssl3_read_bytes:tlsv1 alert internal error
* stopped the pause stream!
* Closing connection 0
curl: (35) error:14094438:SSL routines:ssl3_read_bytes:tlsv1 alert internal error
curl -k -v --tlsv1.3 https://127.0.0.1:8443
* Rebuilt URL to: https://127.0.0.1:8443/
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS Unknown, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, Unknown (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS Unknown, Unknown (21):
* TLSv1.3 (IN), TLS alert, Server hello (2):
* error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure
* stopped the pause stream!
* Closing connection 0
curl: (35) error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure
Tomcat 日志没有显示任何内容,有趣的是,HSM 日志文件没有显示任何新数据。我希望看到对 HSM 的调用是 DH key 协议(protocol)的一部分。
An error occurred during a connection to 127.0.0.1:8443. SSL peer was unable to negotiate an acceptable set of security parameters.
Error code: SSL_ERROR_HANDSHAKE_FAILURE_ALERT
并且, openssl s_client -connect localhost:8443,以防万一。这看起来像是可以协商的配置错误;虽然我可以确定问题,但我不确定在哪里需要进行哪些更改。
---
No client certificate CA names sent
Server Temp Key: X25519, 253 bits
---
SSL handshake has read 1324 bytes and written 307 bytes
Verification error: self signed certificate
---
New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384
Server public key is 3096 bit
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
Early data was not sent
Verify return code: 18 (self signed certificate)
---
我通过添加在 Tomcat 实例中启用了 ssl:handshake
set "JAVA_OPTS=%JAVA_OPTS% -Djavax.net.debug=ssl:handshake"
到 {安装}\bin\catalina.bat。
javax.net.ssl|DEBUG|17|https-jsse-nio-8443-exec-1|2021-10-28 16:22:21.925 \
PDT|CertificateMessage.java:262|Produced server Certificate handshake message (
"Certificates": [
"certificate" : {
"version" : "v3",
"serial number" : "00 EB 48 4B 73 73 35 C6 D8",
"signature algorithm": "SHA256withRSA",
"issuer" : "CN=localhost, OU=SysEng, O=UInc, L=Ca, S=Ca, C=US",
"not before" : "2021-10-28 16:20:07.000 PDT",
"not after" : "2022-01-26 15:20:07.000 PST",
"subject" : "CN=localhost, OU=SysEng, O=UInc, L=Ca, S=Ca, C=US",
"subject public key" : "RSA",
"extensions" : [
{
ObjectId: 2.5.29.14 Criticality=false
SubjectKeyIdentifier [
KeyIdentifier [
0000: 91 84 8C 3A 49 C6 2E E4 95 D2 8F 84 97 34 2C 4E ...:I........4,N
0010: F2 B9 D2 D0 ....
]
]
}
]}
]
)
javax.net.ssl|ERROR|17|https-jsse-nio-8443-exec-1|2021-10-28 16:22:21.945 \
PDT|TransportContext.java:316|Fatal (INTERNAL_ERROR): Unsupported signature \
algorithm: rsa_pss_rsae_sha256 (
"throwable" : {
java.security.InvalidKeyException: RSA key must be at least 512 bytes
at jdk.crypto.cryptoki/sun.security.pkcs11.P11PSSSignature.checkKeySize(P11PSSSignature.java:352)
at jdk.crypto.cryptoki/sun.security.pkcs11.P11PSSSignature.engineInitSign(P11PSSSignature.java:480)
F:\Tomcat\apache-tomcat-10.0.12\bin>cxitool dev=3001@127.0.0.1 LogonPass=USR_0000,ask Group=* ListKeys
idx algo size type group name spec
--------------------------------------------------------------------------------------
1 RSA 3072 prv SLOT_0000 6
2 X509 0 cert SLOT_0000 7
跟进最优秀的 dave_thompson 的最新评论,我重新生成了 key ,因为我无法弄清楚为什么 3072 位 key 在 openssl 输出中报告 3096。我生成了一个 4096 位 key (
并修复了证书 -dname 中的问题),然后它就起作用了。
最佳答案
Utimaco CryptoServer 的步骤:
将 HSM 配置为使用 PKCS11 R2 或 R3,具体取决于固件版本。可以让 R2 和 R3 配置“实时”并在 server.xml 文件中选择一个。
name = CryptoServerR2
description = SunPKCS11 provider offload to CryptoServer PKCS11 R2 library
library = {path_to}\cs_pkcs11_R2.dll
# library = {path_to}\cs_pkcs11_R3.dll
# Set slotListIndex to the slot (SLOT_xxxx), where SLOT_0003 would be 3
slotListIndex = 0
attributes(*,*,CKK_EC) = {
CKA_DERIVE = true
}
attributes(generate,*,CKK_GENERIC_SECRET) = {
CKA_SENSITIVE = false
CKA_EXTRACTABLE = true
}
{path_to} 将根据您用于安装工具的安装程序版本而改变。
somepath> keytool -genkey -keyalg RSA -keysize 4096 -keystore NONE -storetype PKCS11 \
-storepass {passphrase} -providername SunPKCS11-CryptoServerR2 -alias tomcat_demo \
-dname "CN=localhost,OU=SysEng,O=UInc,L=Locality,S=StateOrProvince,C=Country"
此时,Java 被配置为通过安全提供程序列表使用 PKCS11 库。
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"/>
<Connector
protocol="org.apache.coyote.http11.Http11NioProtocol"
sslImplementationName="org.apache.tomcat.util.net.jsse.JSSEImplementation"
port="8443"
SSLEnabled="true"
maxThreads="150"
scheme="https"
secure="true"
clientAuth="false"
>
<SSLHostConfig
protocols="TLSv1.2"
ciphers="TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA,
TLS_RSA_WITH_AES_128_CBC_SHA,
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
TLS_RSA_WITH_AES_128_CBC_SHA256,
TLS_RSA_WITH_AES_128_GCM_SHA256,
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
TLS_RSA_WITH_AES_256_CBC_SHA,
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
TLS_RSA_WITH_AES_256_CBC_SHA256,
TLS_RSA_WITH_AES_256_GCM_SHA384,
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"
>
<Certificate
type="RSA"
certificateKeystoreType="PKCS11"
certificateKeystoreFile=""
certificateKeystoreProvider="SunPKCS11-CryptoServerR2"
certificateKeystorePassword="{passphrase}"
certificateKeyAlias="tomcat_demo"
/>
</SSLHostConfig>
</Connector>
使用 startup.bat 脚本启动 Tomcat 并观察输出中的异常。
curl -k -v --tlsv1.2 https://localhost:8443
关于ssl - Tomcat 10 使用 HSM 作为 TLS 的 PKCS11 keyStore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69746244/
常用的 PKCS 标准有什么用:PKCS#7、PKCS#10 和 PKCS#12? 最佳答案 PKCS#7 允许您使用 X.509 证书对通用数据进行签名和加密。 PKCS#7 格式也可用于存储一个或
我想知道当使用 AES-128-CBC 时,openssl 如何处理可被 8 个字节整除的消息。 openssl 如何检测到没有要删除的填充(PKCS#5/PKCS#7)?特别是当消息以 ASCII
我正在阅读 PKCS 11 文档,但我无法清楚地理解 key 的 CKA_SENSITIVE 属性是什么意思。 更常见的是:我在哪里可以阅读属性描述? 最佳答案 引自 PKCS#11 spec v2.
我想寻求有关使用 cryptography.hazmat.primitives.padding.PKCS7 的帮助Python 类。 解密后,我得到字符串45394700000019770808080
我知道 PKCS#7 = 证书 + 可选原始数据 + PKCS#1 格式的签名 我需要从 PKCS#7 签名中提取 PKCS#1 如何在 C# 中执行此操作。我可以用充气城堡来做这个吗,这是我的实现I
我希望能够使用带有 aws golang SDK 的 AWS SNS 发送 iOS APNS 推送通知。我按照以下说明创建了一个 p12 文件:https://support-aws.s3.amazo
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 2年前关闭。 Improve this questi
我正在开发一个移动应用程序,它必须验证它收到的一些签名。我拥有我需要的一切——输入数据、公钥和签名。但有一个问题。我使用方法 SHA256withRSA 进行签名验证,其中包含以下几行代码来验证签名:
我有一个 PKCS#5 加密的 PKCS#8 RSA 私钥存储在一个磁盘文件中(最初由 SSLPlus 生成,大约在 1997 年),例如: -----BEGIN ENCRYPTED PRIVATE
是否可以将 PKCS#8 编码的 RSA 私钥转换为 PKCS#1?我知道这可以通过 openssl 轻松完成,但是可以用 Java 完成吗? 最佳答案 使用 BouncyCaSTLe 1.50 Pr
我正在为 Android 实现 Jscep。最初,我尝试了 Jscep for java,效果很好。现在在 Android 中,我使用 SpongyCaSTLe 而不是 BouncyCaSTLe。现在
我正在尝试在 SafeNet HSM 中生成一个 RSA key 对。我为私钥和公钥复制了 PKCS11 中指定的示例模板。当我生成 key 对时,一切正常。但是,当我为私钥指定以下属性值时,C_Ge
密码学在信息安全中扮演着至关重要的角色。为了保护敏感信息、数字身份和网络通信的安全性,密码设备(如硬件安全模块HSM)与应用程序之间的安全通信和互操作性变得至关重要。PKCS#11(Public-K
这玩意折腾了一天,有个老外的代码,公钥用了PKCS#1,私钥用了PKCS#8。调用了不同的API,而我的全是生成的PKCS#8,后面查阅了大量资料和长时间调试程序,才发现了问题,在此记录下。 用Ope
PKCS#12是一种将私钥与其对应的 X.509 证书合并为标准化的单一文件格式的便捷方式。然而,该规范于 1999 年由 RSALabs 发布,并且仅使用 RC4、RC2 和 TripleDES 进
我正在尝试使用 PKCS#7 进行签名和验证签名。我正在阅读《beginning cryptography with java》这本书。我已经编写了示例代码来签名和验证。当我尝试附加签名并将其写入文件
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 4年前关闭。 Improve this qu
使用java加密、签名、解密、验证签名需要遵循哪些步骤? 使用 PKCS#7 算法, java keystore 有什么用?关于 PKCS#7。 最佳答案 第 1 步 使用 keytool 实用程序生
我在 iPhone 上使用这个 OpenSSL 代码生成一个 PKCS#12 文件,给定证书/私钥的一些数据。我能够验证此 PKCS#12 在 OpenSSL 上是否可解析,因为当我在代码中检查它时它
我实际上正在研究一个应该从 PKCS7 mime 加密消息中提取 RecipientInfo 的函数。我想这样做的原因是,我想获取邮件加密的所有邮件地址(或至少是 keyids/指纹)。 嗯 - 我尝
我是一名优秀的程序员,十分优秀!