亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我在程序中調用 https URL 時遇到握手失敗

我在程序中調用 https URL 時遇到握手失敗

夢里花落0921 2023-10-13 09:52:53
請查看完整日志trustStore is: /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/security/jssecacertstrustStore type is : jkstrustStore provider is : init truststoreadding as trusted cert:  Subject: CN=m3_external_ca_test  Issuer:  CN=m3_external_ca_test  Algorithm: RSA; Serial number: 0x1  Valid from Tue Jun 12 01:57:02 IST 2018 until Fri Jun 09 01:57:02 IST 2028adding as trusted cert:  Subject: CN=ecw-test.mtn.co.ug, C=UG  Issuer:  CN=m3_external_ca_test  Algorithm: RSA; Serial number: 0x-2afddf7d2f077bc9  Valid from Tue Jun 12 13:21:39 IST 2018 until Thu Jun 11 13:21:39 IST 2020adding as trusted cert:  Subject: [email protected], CN=test.xpwallet.com, OU=ARED, O=ARED, L=RW, ST=RW, C=RW  Issuer:  CN=m3_external_ca_test  Algorithm: RSA; Serial number: 0xb165b0b05e8fed1  Valid from Mon Sep 09 13:58:16 IST 2019 until Wed Sep 08 13:58:16 IST 2021keyStore is : /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/security/jssecacertskeyStore type is : jkskeyStore provider is : init keystoreinit keymanager of type SunX509trigger seeding of SecureRandomdone seeding SecureRandomAllow unsafe renegotiation: falseAllow legacy hello messages: trueIs initial handshake: trueIs secure renegotiation: falsemain, setSoTimeout(0) called%% No cached client session*** ClientHello, TLSv1.2RandomCookie:  GMT: 1553995999 bytes = { 68, 80, 88, 59, 21, 219, 212, 92, 98, 185, 156, 181, 51, 80, 35, 252, 156, 223, 223, 151, 72, 252, 100, 85, 35, 44, 134, 21 }
查看完整描述

3 回答

?
ABOUTYOU

TA貢獻1812條經驗 獲得超5個贊

你應該嘗試像這樣構建客戶端


    // Creating SSLContextBuilder object

    SSLContextBuilder SSLBuilder = SSLContexts.custom();


    // Loading the Keystore file

    File file = new File("mykeystore.jks");

    SSLBuilder = SSLBuilder.loadTrustMaterial(file, "changeit".toCharArray());


    // Building the SSLContext usiong the build() method

    SSLContext sslcontext = SSLBuilder.build();


    // Creating SSLConnectionSocketFactory object

    SSLConnectionSocketFactory sslConSocFactory = new SSLConnectionSocketFactory(sslcontext,

            new NoopHostnameVerifier());


    // Creating HttpClientBuilder

    HttpClientBuilder clientbuilder = HttpClients.custom();


    // Setting the SSLConnectionSocketFactory

    clientbuilder = clientbuilder.setSSLSocketFactory(sslConSocFactory);


    // Building the CloseableHttpClient

    CloseableHttpClient httpclient = clientbuilder.build();


查看完整回答
反對 回復 2023-10-13
?
阿晨1998

TA貢獻2037條經驗 獲得超6個贊

您的客戶端沒有按照服務器(肯定)請求且顯然需要的方式發送客戶端證書。


請注意,您的信任庫沒有任何問題,更改您的信任庫或信任管理器完全無關且無用。那些認為所有 SSL/TLS 問題都缺乏驗證(信任)服務器證書的人就像那些認為如果發動機已從汽車上拆下,只要放一些汽油(或汽油/香精),它仍然會運行良好的人/etc 取決于國家)在水箱中。


從你的調試日志:


*** CertificateRequest

Cert Types: RSA, DSS, ECDSA

Supported Signature Algorithms: SHA256withRSA, SHA256withDSA, SHA256withECDSA, SHA384withRSA, Unknown (hash:0x5, signature:0x2), SHA384withECDSA, SHA512withRSA, Unknown (hash:0x6, signature:0x2), SHA512withECDSA, SHA1withRSA, SHA1withDSA, SHA1withECDSA

Cert Authorities:

<CN=m3_external_ca_test>

服務器請求客戶端證書,又名客戶端身份驗證(認證),又名雙向身份驗證或相互身份驗證。


Warning: no suitable certificate found - continuing without client authentication

*** Certificate chain

<Empty>

***

...

*** ECDHClientKeyExchange


[Raw read]: length = 2

0000: 02 28                                              .(

main, READ: TLSv1.2 Alert, length = 2

main, RECV TLSv1.2 ALERT:  fatal, handshake_failure

您沒有提供一份(以及證明擁有的相關簽名)。服務器中止握手,通常可能有多種原因,但此時唯一可能的原因是您沒有提供所請求的證書(和簽名)。


返回頂部附近:


keyStore is : /Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre/lib/security/jssecacerts

keyStore type is : jks

keyStore provider is : 

init keystore

init keymanager of type SunX509

請注意,本節沒有說類似的內容,就像可用的客戶端證書一樣:


found key for : <alias>

chain [0] = [ <usually dozens of lines of data> ]

<usually chain[1], maybe chain[2] and more depending>

有兩種截然不同的證書:一種是識別您(或您的設備等)并且您希望其他人信任的證書,您必須擁有 privatekey ;另一種是識別您信任的其他人的證書,您應該擁有該私鑰永遠沒有私鑰。對于客戶端身份驗證,您需要第一種,但您沒有。(補充說明:一般來說,對于您自己的證書,您還需要一個或有時多個“鏈”或“中間”證書,但在這種情況下,調試日志清楚地表明您正在使用不使用的虛擬/測試 CA鏈證書。)


要么是您或其他人準備jssecacerts錯誤,要么是使用錯誤的文件,因為它旨在包含您信任的其他人的證書,即 CA,Java 稱之為信任庫(盡管它仍然是密鑰庫格式),并且不是您自己的證書,這是真正的密鑰庫。第三個證書被列為受信任,帶有[email protected],看起來它可能是客戶端證書,但由于您沒有私鑰,所以不能這樣使用。修復該文件,或者如果您在不同的文件中擁有帶有密鑰的客戶端證書(這將是一個很好且常用的方法),請改用該不同的文件。


查看完整回答
反對 回復 2023-10-13
?
RISEBY

TA貢獻1856條經驗 獲得超5個贊

我們通常使用 TrustStore 來信任第 3 方服務器通信。在通過 HTTPS 協議進行客戶端和服務器通信時,后者始終查找其密鑰庫并將其呈現the public key and certificate給前者。之后,客戶端查找associated certificate in the truststore.?如果調用服務器共享的證書或證書頒發機構不存在于客戶端信任存儲中(默認情況下,Java 始終將信任存儲捆綁為 cacerts 并將其保留在 $JAVA_HOME/jre/lib/security 路徑中),則會SSLHandshakeException發生這種情況。要解決該問題,您必須添加信任存儲。

可以使用以下命令列出默認受信任的證書頒發機構

keytool?-list?-keystore?cacerts

您可以使用以下命令添加信任存儲:

keytool?-import?-trustcacerts?-alias?certAlias?-file?certFile?-keystore?trustStoreFile

默認情況下,trustStoreFile 位置為 $JAVA_HOME/jre/lib/security/cacerts。


查看完整回答
反對 回復 2023-10-13
  • 3 回答
  • 0 關注
  • 206 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號