我使用以下步骤创建一个新的Java密钥库,其中包含一对私有/公共密钥,供Java(内部)服务器使用TLS.请注意证书是自签名的:
1)使用AES256生成密钥
openssl genrsa -aes256 -out server.key 1024
Run Code Online (Sandbox Code Playgroud)
2)为CA生成证书请求
openssl req -x509 -sha256 -new -key server.key -out server.csr
Run Code Online (Sandbox Code Playgroud)
3)生成自签名到期时间10年
openssl x509 -sha256 -days 3652 -in server.csr -signkey server.key -out selfsigned.crt
Run Code Online (Sandbox Code Playgroud)
4)使用像KeyStoreExplorer这样的程序在新的JKS中导入对(私钥和自签名证书)
这有效,但我想在不使用GUI的情况下实现最后一步.
我知道如何仅导入自签名证书:
// create the keystore and import the public key. THIS WILL NOT IMPORT THE PRIVATE KEY SO THE KEYSTORE CAN'T BE USED ON THE SERVER TO MAKE THE TLS CONNECTION
/usr/java/jdk1.6.0_45/bin/keytool -import -alias myservercert -file server.crt -keystore mykeystore.jks
Run Code Online (Sandbox Code Playgroud)
所以问题是:我如何创建Java KeyStore并使用公钥和私钥导入证书而不使用GUI?
我正在尝试与trackobot.com建立连接以接收一些JSON数据.服务器仅允许通过HTTPS/SSL进行连接.这是代码:
java.lang.System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");
URL url = new URL("https://trackobot.com/profile/history.json?username=USER&token=TOCKEN");
InputStream is = url.openStream();
JsonParser parser = Json.createParser(is);
Run Code Online (Sandbox Code Playgroud)
openSteam抛出javax.net.ssl.SSLHandshakeException:收到致命警报:handshake_failure
我阅读了几篇与类似问题相关的帖子,但没有一个建议有帮助.相应的证书在我的信任库中.当我尝试连接到例如google.com时,没有错误.所以,问题似乎是在我试图连接的服务器的握手特定中.
我使用-Djavax.net.debug = ssl运行我的代码返回:
keyStore is :
keyStore type is : jks
keyStore provider is :
init keystore
init keymanager of type SunX509
trustStore is: /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre/lib/security/cacerts
trustStore type is : jks
trustStore provider is :
init truststore
[Here I removed hundreds of „adding as trusted cert“:… lines]
trigger seeding of SecureRandom
done seeding SecureRandom
Ignoring unavailable cipher suite: TLS_DHE_DSS_WITH_AES_256_GCM_SHA384
Ignoring unavailable cipher suite: …Run Code Online (Sandbox Code Playgroud)