获得网址的Https的SSL证书并且保存到truststore
Posted 年轻人,要努力哟
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获得网址的Https的SSL证书并且保存到truststore相关的知识,希望对你有一定的参考价值。
一、生成PEM文件
这里以邮件发送接口为例https://api.mailgun.net/v3/,首先运行以下命令:
openssl s_client -host api.mailgun.net -port 443 -prexit -showcerts
执行结果如下:
CONNECTED(00000003) depth=1 C = US, O = "thawte, Inc.", CN = thawte SHA256 SSL CA verify error:num=20:unable to get local issuer certificate --- Certificate chain 0 s:/C=US/ST=Texas/L=San Antonio/O=Rackspace US, Inc/OU=Mailgun/CN=*.mailgun.com i:/C=US/O=thawte, Inc./CN=thawte SHA256 SSL CA -----BEGIN CERTIFICATE----- MIIGRjCCBS6gAwIBAgIQcPBE+lQWtps2UTd0ornMgjANBgkqhkiG9w0BAQsFADBD MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMdGhhd3RlLCBJbmMuMR0wGwYDVQQDExR0 aGF3dGUgU0hBMjU2IFNTTCBDQTAeFw0xNjAyMDkwMDAwMDBaFw0xODA0MDgyMzU5 NTlaMHkxCzAJBgNVBAYTAlVTMQ4wDAYDVQQIEwVUZXhhczEUMBIGA1UEBxQLU2Fu IEFudG9uaW8xGjAYBgNVBAoUEVJhY2tzcGFjZSBVUywgSW5jMRAwDgYDVQQLFAdN YWlsZ3VuMRYwFAYDVQQDFA0qLm1haWxndW4uY29tMIIBIjANBgkqhkiG9w0BAQEF AAOCAQ8AMIIBCgKCAQEAyzQJUmOuQsksJ+ypj6ndmfkmFa39aXZKxIsvVSSmGSqU upFO3awNDo4aaGnjjN8OFwHQozthBfNz04RDKgV0E22gyrrOOpCd88mHokJKeV04 TVc93/MQYAVQQ3Ou7b/GafuFcDu1Z5s+YgN1iMEXR4iMczlFsS1SzWZ03WOFeEGn xR31n6wLoOwcBEvD58v4zANntM9Ajwv0UHpd72nzBpwVFQYwY3vQrfK/5E5nbWJf cixs85Ube9L5ID71d49f9XRctPL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Ti1dai Xk8sAiEAqycC8AGehR5pBhWUpGlx3IOXzA2EKda90FLF2Koq9D0wDQYJKoZIhvcN AQELBQADggEBACPqESoobL82TMXdGGbGQoTu03Bk+9lL0uxOSzGP+TJnjrb4b7p4 SvaM/z8XIKmgT3z3BP/wjyTN71BLVbamdLjcfHnNA6AYHE/sv91enmmCExsSN5Yd JWttWO8kk7pa944dOJ1vhPBmd3uGyTX1LuFTPe0++yUJvfv0dwvL/f7VFqM8ZYTO bf9BwQf7OedInr5qQaGHGenOFJStiNalotvmivBnzkrFT8xkK4f3tq73v5iT+Cyl MMLNho6OlLp4YNeUgglcmv2xv+HynkeWZeiIDtLsHceEdiOEP1FlkXT+BWJID2v4 M4CQfAVIzBQ/iNo+Dm9SHcae02JwWSGxeSM= -----END CERTIFICATE----- 1 s:/C=US/O=thawte, Inc./CN=thawte SHA256 SSL CA i:/C=US/O=thawte, Inc./OU=Certification Services Division/OU=(c) 2008 thawte, Inc. - For authorized use only/CN=thawte Primary Root CA - G3 -----BEGIN CERTIFICATE----- MIIEwjCCA6qgAwIBAgIQNjSeGMmcJmm2Vi5s5a1xMjANBgkqhkiG9w0BAQsFADCB rjELMAkGA1UEBhMCVVMxFTATBgNVBAoTDHRoYXd0ZSwgSW5jLjEoMCYGA1UECxMf Q2VydGlmaWNhdGlvbiBTZXJ2aWNlcyBEaXZpc2lvbjE4MDYGA1UECxMvKGMpIDIw MDggdGhhd3RlLCBJbmMuIC0gRm9yIGF1dGhvcml6ZWQgdXNlIG9ubHkxJDAiBgNV BAMTG3RoYXd0ZSBQcmltYXJ5IFJvb3QgQ0EgLSBHMzAeFw0xMzA1MjMwMDAwMDBa Fw0yMzA1MjIyMzU5NTlaMEMxCzAJBgNVBAYTAlVTMRUwEwYDVQQKEwx0aGF3dGUs IEluYy4xHTAbBgNVBAMTFHRoYXd0ZSBTSEEyNTYgU1NMIENBMIIBIjANBgkqhkiG 9w0BAQEFAAOCAQ8AMIIBCgKCAQEAo2Mr1LpdOK6w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2QjfjGUkZW63RHvqbzGa5xTMDh59TP7dQGKCoRPLrZ QW4A54E3k+TaYsYdZ29jtBSG2aZi8A== -----END CERTIFICATE----- --- Server certificate subject=/C=US/ST=Texas/L=San Antonio/O=Rackspace US, Inc/OU=Mailgun/CN=*.mailgun.com issuer=/C=US/O=thawte, Inc./CN=thawte SHA256 SSL CA --- No client certificate CA names sent Peer signing digest: SHA512 Server Temp Key: ECDH, P-256, 256 bits --- SSL handshake has read 3342 bytes and written 434 bytes --- New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES128-GCM-SHA256 Server public key is 2048 bit Secure Renegotiation IS supported Compression: NONE Expansion: NONE No ALPN negotiated SSL-Session: Protocol : TLSv1.2 Cipher : ECDHE-RSA-AES128-GCM-SHA256 Session-ID: E279B2FA33421D0A68D77E6405256671A7E0438D8F61C9A85FB67ABE40B07437 Session-ID-ctx: Master-Key: 9A46CDBA8230B31F0AD744A49AEB97D44346DD26687689C5BF52A1F93BC4F0EFC4A8DFCD1F38DE35FF6007E4823ED0C7 Key-Arg : None PSK identity: None PSK identity hint: None SRP username: None Start Time: 1493541740 Timeout : 300 (sec) Verify return code: 20 (unable to get local issuer certificate) ---
将输出内容保存为pem文件,这里我保存为名为mailgun.pem的文件。
二、将证书导入truststore文件
cp $JAVA_HOME/jre/lib/security/cacerts trustore
本质上keyStore和strustStore文件格式上是一回事,keyStore存的一般是私钥,trustStore存放的是公钥。
导入证书(初始密码是changeit):
keytool -import -alias gca -file mailgun.pem -keystore truststore
导入成功会有提示。GOOD LUCK
三、参考
https://www.cloudera.com/documentation/enterprise/5-8-x/topics/cm_sg_create_key_trust.html
等
以上是关于获得网址的Https的SSL证书并且保存到truststore的主要内容,如果未能解决你的问题,请参考以下文章