在Android上使用Volley网络库进行SSL固定

编程入门 行业动态 更新时间:2024-10-15 08:20:25
本文介绍了在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固定

本文发布于:2023-11-26 14:03:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634077.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网络   Android   Volley   SSL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!