Re: [問題] Android 7.0 https無法連線的問題

作者: joycece (joycece)   2017-03-15 10:40:17
糗了 我的程式裡面本來就有加了 不知道是否還有其他線索可指點一下
感謝~
public int init() throws InterruptedException {
KeyStore ks;
try {
ks = KeyStore.getInstance("BKS");
String pkres;
pkres = GlbArgs.getString("SslKey");
ks.load(GlbArgs.getRes().openRawResource(GlbArgs.getResId(pkres)),
"000000".toCharArray());
TrustManagerFactory tmf = TrustManagerFactory
.getInstance(KeyManagerFactory.getDefaultAlgorithm());
tmf.init(ks);
SSLContext ctx = SSLContext.getInstance("TLS");
//SSLContext ctx = SSLContext.getDefault();
ctx.init(null, tmf.getTrustManagers(), null);
SSLSocketFactory sslFact = ctx.getSocketFactory();
mSock = (SSLSocket) sslFact.createSocket();
mSock.setEnabledCipherSuites(mSock.getSupportedCipherSuites());
String[] s={"TLSv1.2"};
mSock .setEnabledProtocols(s);
} catch (IOException | NoSuchAlgorithmException
| CertificateException | KeyStoreException | KeyManagementException e) {
e.printStackTrace();
return ERR_TCPSSL_INIT;
}
return ERR_OK;
}
※ 引述《benedict76 (ben)》之銘言:
: 我有遇過Android m可以但是在N不行,
: 後來發現N把RC4 cipher suites disable,
: 結果我連的server要的cipher suite預設都被
: 關掉,所以在我連線的時候,在sslsocket
: 哪邊setenabledciphersuites,傳
: getsupportedciphersuites()進去,後來就成
: 功連線,您可以試試看。
: ※ 引述《joycece (joycece)》之銘言:
: : 我也遇上了類似的問題
: : 在Android 5 & 6的 手機上可以正常SSL連線(TLS1.2)
: : 但在Android 7.1.1的手機就發生以下錯誤
: : javax.net.ssl.SSLHandshakeException:
: : java.security.cert.CertPathValidatorException:
: : Trust anchor for certification path not found.
: : 想請問是否能夠給個方向怎樣去修正或避免這個問題發生?
: : 謝謝
:
作者: benedict76 (ben)   2017-03-15 10:56:00
您這是用自己的certificate嗎?不知道是不是要用networkconfigure 來做
作者: hh81tw (J)   2017-04-08 09:04:00
是不是少了https://developer.android.com/training/articles/security-config.html#manifest

Links booklink

Contact Us: admin [ a t ] ucptt.com