在 Jetty 中创建由自签名 CA 证书签名的 SSL 证书

在 Jetty 中创建由自签名 CA 证书签名的 SSL 证书

我正在尝试配置一个使用自签名 CA 证书签名的证书jetty-distribution-9.3.1.v20150714运行的后端,以进行 SSL 固定。Java 1.8.0_45-b14

下列的苹果指南,我创建了一个自签名 CA 证书,然后基于该 CA 证书创建了一个证书。

结果是ServerCertificate.p12带有服务器证书、私钥和root.cer文件的文件,将用于固定。

$ keytool -list -keystore keystore.p12 -storetype pkcs12 
server, Jul 27, 2015, PrivateKeyEntry, 
Certificate fingerprint (SHA1): AA:BB:CC.........11:22:33

我之前曾使用过由受信任 CA 签名的证书,因此后端应该正确配置了 SSL。移动应用程序的固定框架已使用不同的自签名网站进行了测试,效果很好。

但是应用程序无法通过该密钥库连接到我的后端:Trust anchor for certification path not found.

我感觉密钥库中缺少 CA 证书,因此我尝试添加它keytool -import -alias root -keystore keystore.p12 -storetype pkcs12 -trustcacerts -file root.crt(.crt 是 base64 可读证书文件),但没有帮助。

# after adding root.crt

$ keytool -list -keystore keystore.p12 -storetype pkcs12 
server, Jul 27, 2015, PrivateKeyEntry, 
Certificate fingerprint (SHA1): AA:BB:CC.........11:22:33
root, Jul 27, 2015, trustedCertEntry, 
Certificate fingerprint (SHA1): FF:DD:EE.........33:22:11

$ openssl s_client -connect example.com:443
CONNECTED(00000003)
depth=1 CN = Product CA, C = AU
verify error:num=19:self signed certificate in certificate chain
---
Certificate chain
 0 s:/CN=Product/C=AU
   i:/CN=Product CA/C=AU
 1 s:/CN=Product CA/C=AU
   i:/CN=Product CA/C=AU
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIDADCCAei..................................
.............................................
..........BASE64.STUFF.......................
.............................................
................................eTVowuY+erkaf
+sIO4w==
-----END CERTIFICATE-----
subject=/CN=Product/C=AU
issuer=/CN=Product CA/C=AU
---
No client certificate CA names sent
Peer signing digest: SHA512
Server Temp Key: DH, 2048 bits
---
SSL handshake has read 2732 bytes and written 636 bytes
---
New, TLSv1/SSLv3, Cipher is DHE-RSA-AES256-GCM-SHA384
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : DHE-RSA-AES256-GCM-SHA384
    Session-ID: 55B6.........................2B4
    Session-ID-ctx: 
    Master-Key: 1C.............................................................................30AF
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    Start Time: 1497776932
    Timeout   : 300 (sec)
    Verify return code: 19 (self signed certificate in certificate chain)
---
closed

有趣的是,curl https://example.com --cacert server.cer效果很好......(没有--cacert则不行)

知道配置有什么问题吗?

相关内容