本文介绍了在Android上使用Volley网络库进行SSL固定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在排球网络库中使用SSL固定.有什么方法可以通过volley实现SSL固定吗?凌空提供此支持以提高安全性吗?
I want to use SSL Pinning in volley network library. Is there any way to implement SSL pinning with volley? Does volley provide this support for security improvements?
推荐答案我只是按以下说明实施了它: blog.ostorlab.co/2016/05/ssl-pinning-in-android-networking.html
I just implemented it like described here: blog.ostorlab.co/2016/05/ssl-pinning-in-android-networking.html
以下是截击实施所需的代码:
Here is the needed code for a volley-implementation:
CertificateFactory cf = CertificateFactory.getInstance("X.509"); // Generate the certificate using the certificate file under res/raw/cert.cer InputStream caInput = new BufferedInputStream(getResources().openRawResource(R.raw.cert)); Certificate ca = cf.generateCertificate(caInput); caInput.close(); // Create a KeyStore containing our trusted CAs String keyStoreType = KeyStore.getDefaultType(); KeyStore trusted = KeyStore.getInstance(keyStoreType); trusted.load(null, null); trusted.setCertificateEntry("ca", ca); // Create a TrustManager that trusts the CAs in our KeyStore String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm(); TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm); tmf.init(trusted); // Create an SSLContext that uses our TrustManager SSLContext context = SSLContext.getInstance("TLS"); context.init(null, tmf.getTrustManagers(), null); SSLSocketFactory sf = context.getSocketFactory(); mRequestQueue = Volley.newRequestQueue(mCtx.getApplicationContext(), new HurlStack(null, sf));似乎可以正常工作!
更多推荐
在Android上使用Volley网络库进行SSL固定
发布评论