【发布时间】:2015-11-16 05:06:34
【问题描述】:
我是安卓新手。 这个问题已经被问过很多次了,但我已经回答了这里几乎所有的问题。
我正在尝试在 Node.Js 服务器(使用 express)和 Android 上的 Volley 上使用自签名证书。
使用:http://blog.applegrew.com/2015/04/using-pinned-self-signed-ssl-certificate-with-android-volley/
我无法使用http://ogrelab.ikratko.com/using-android-volley-with-self-signed-certificate/,因为我的应用程序中有太多代码需要更改。
这就是错误。
javax.net.ssl.SSLHandshakeException:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚。
我的 volleysingelton 代码:
private SSLSocketFactory newSslSocketFactory() {
try {
// Get an instance of the Bouncy Castle KeyStore format
KeyStore trusted = KeyStore.getInstance("BKS");
// Get the raw resource, which contains the keystore with
// your trusted certificates (root and any intermediate certs)
InputStream in = mCtx.getResources().openRawResource(R.raw.evennewer);
try {
// Initialize the keystore with the provided trusted certificates
// Provide the password of the keystore
trusted.load(in, KEYSTORE_PASSWORD);
} finally {
in.close();
}
String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
tmf.init(trusted);
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, tmf.getTrustManagers(), null);
SSLSocketFactory sf = context.getSocketFactory();
return sf;
} catch (Exception e) {
throw new AssertionError(e);
}
}
我的 Node.Js 代码:
var config = {
key: fs.readFileSync('./ssl/newkey.key'),
cert: fs.readFileSync('./ssl/newcert.crt')
};
var port = 443;
var server = https.createServer(config, app).listen(port, function(){
console.log("Express server listening on port " + port);
});
并且 openssl 调试返回:
验证返回码:18(自签名证书)
【问题讨论】:
标签: android node.js ssl https android-volley