最近我在实施SSL的项目上工作 .
SSL证书每年到期一次 . 在我更新服务器上的证书后,它在android中抛出异常 .
06-13 11:20:27.709: D/allenj(30076): javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
在查看项目代码后,我看到有一个bks文件,所以,这是否意味着每年必须更新一次bks文件,我还必须将应用程序重新上传到Google Play .
问题是应对SSL证书更新的标准方法是什么?谢谢你的帮助 .
代码提取
nnable Register_runnable = new Runnable(){
@Override
public void run() {
EditText emailText = (EditText) findViewById(R.id.editText1regist);
EditText pwText = (EditText) findViewById(R.id.editText2registpw);
String end = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
try {
KeyStore keyStore = KeyStore.getInstance("BKS");
InputStream in =
getResources().openRawResource(R.raw.ballooncardbks);
keyStore.load(in, "".toCharArray());
TrustManagerFactory tmf =
TrustManagerFactory.getInstance("X509");
tmf.init(keyStore);
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, tmf.getTrustManagers(), null);
String actionUrl = "https://app.ballooncard.com/api/client/register/format/json";
URL url = new URL(actionUrl);
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
// con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setRequestMethod("POST");
con.setSSLSocketFactory(context.getSocketFactory());
con.setRequestProperty("Connection", "Keep-Alive");
con.setRequestProperty("Charset", "UTF-8");
con.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
1 回答
看起来应用程序正在使用“证书固定”,这意味着证书已经硬编码到应用程序中,并且已经指示应用程序仅接受该证书而不接受其他证书 .
这会增加安全性,但需要在证书过期(理想情况下)之前更新应用程序 . 您可以按照我在此处创建的帖子中的说明操作:
https://stackoverflow.com/a/24007536/276949
从您的证书生成一个新的
.bks
文件 . 完成此操作后,覆盖旧的.bks
文件,您的应用应通过SSL成功连接 .