我提到我到目前为止所尝试的内容,我开始提出问题:
我的应用程序中没有证书,我只使用SHA256密钥,互联网上的大多数答案都需要应用程序中的物理证书才能将其加载到密钥库中,我没有.
我收到以下错误:
javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
Run Code Online (Sandbox Code Playgroud)
1)TrustKit它需要编译SDK 24及以上,但我有23个和许多支持库与SDK 23同步所以我无法更改所有这些,它可能会在某个时候崩溃我的应用程序.
2)CWAC-NetSecurity我在我的代码中实现了这个,没有使用Android N安全设置,我也遵循git页面上给出的指令,但是不能将sslSocketfactory传递给Volley,它有OkHTTP的例子.所以它也给出了上述错误.
我用OKHttp的CertificatePinner尝试了这个,它也不适用于我.同样的错误.我也尝试将hostNameVerifier和sslSocketFactory传递给HttpsUrlConnection但是同样的错误.
JsonObjectRequestSolaire jsonRequest = new JsonObjectRequestSolaire(method, URL, object, headers, responseListener, errorListener);
RetryPolicy policy = new DefaultRetryPolicy(TIMEOUT, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
jsonRequest.setRetryPolicy(policy);
jsonRequest.setShouldCache(false);
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.certificatePinner(new CertificatePinner.Builder()
.add("my_domain", "sha256/shaKey")//example.com
.add("my_domain", "sha256/shaKey")//also tried *.example.com
.build())
.build();
//HttpsURLConnection.setDefaultHostnameVerifier(okHttpClient.hostnameVerifier());
//HttpsURLConnection.setDefaultSSLSocketFactory(okHttpClient.sslSocketFactory());
RequestQueue requestQueue = Volley.newRequestQueue(activity.getApplicationContext(), new HurlStack(null, okHttpClient.sslSocketFactory()));
requestQueue.add(jsonRequest);
Run Code Online (Sandbox Code Playgroud)
通过使用trustKit我们的iOS人员实现,它正在为他工作.
提前致谢.
请在这里分享您的宝贵意见,以便我能理解这个SSL固定概念.
android android-volley okhttp3 certificate-pinning public-key-pinning
我正在我们的 android 应用程序中实现 SSL 固定。我通过将 2 个证书(当前和备份)嵌入到应用程序中来将它们固定在客户端。
现在,我希望有一种机制来更新这些证书,而无需推出应用程序升级,以防证书过期或私钥被泄露。我该如何实施?
我看到的一种可能的解决方案是通过应用程序通知。我可以使用新证书广播通知并将它们存储在客户端中。这种方法有什么问题还是有更好的方法?
我想使用 SSL Pinning 来保护我的应用程序免受中间人 (mitm) 攻击。
\n默认情况下,可以使用 Charles 或 mitmproxy 等代理来拦截流量,并使用自签名证书对其进行解密。
经过广泛的研究,我发现了几种选择:
\n添加NSPinnedDomains > MY_DOMAIN > NSPinnedLeafIdentities到Info.plist
\nApple 文档:身份锁定
\nGuardsquare:利用基于 Info.plist 的证书锁定
\n优点:简单
\n缺点:一旦更新证书/私钥(通常在几个月后),应用程序将变得无法使用
添加NSPinnedDomains > MY_DOMAIN > NSPinnedCAIdentities到Info.plist
\nApple 文档:与上面相同
\n优点:简单。叶证书续订不会失败,因为根 CA 已被固定(过期日期几十年后)
\n缺点:似乎多余,因为大多数根 CA 已包含在操作系统中
检查代码中的证书URLSessionDelegate> SecTrustEvaluateWithError(或 Alamofire 包装器)
\nRay Wenderlich:使用 SSL Pinning 防止 iOS 中的中间人攻击\n
\nApple 文档:处理身份验证质询
\nMedium 文章:有关 SSL Pinning 您需要了解的所有信息
\n中型文章:使用 …
这是我的 alamofire 经理,我如何在其上添加公钥固定?请帮助我,我不知道如何在我的代码中做到这一点,如果可能的话,我需要逐步解释如何使用具有所有请求的 AFManager
class AFManager : NSObject{
///without headers (post)
//used this to registration
class func requestPOSTURL(_ strURL : String, params : [String :
AnyObject]?, success:@escaping (JSON) -> Void, failure:@escaping (Error) -> Void){
URLCache.shared.removeAllCachedResponses()
Alamofire.request(strURL, method: .post, parameters: params, encoding: URLEncoding.httpBody).responseJSON { (responseObject) -> Void in
//print(responseObject)
if responseObject.result.isSuccess {
let resJson = JSON(responseObject.result.value!)
success(resJson)
}
if responseObject.result.isFailure {
let error : Error = responseObject.result.error!
failure(error)
}
}
}
///// response string (post)
//used this in login // used …Run Code Online (Sandbox Code Playgroud) 我需要从证书中获取公钥
我已经找到了一种在 iOS 12+ 和 iOS 10.3+ 上执行此操作的方法,但是如何在 iOS 10.0+ 上执行此操作?
func publicKey(for certificate: SecCertificate) -> SecKey? {
if #available(iOS 12.0, *) {
return SecCertificateCopyKey(certificate)
} else if #available(iOS 10.3, *) {
return SecCertificateCopyPublicKey(certificate)
} else {
// ???
return nil
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将 SSL 公钥固定集成到 Alamofire swift 5 中,但我发现ServerTrustPolicyManager它已被弃用。请帮助我融入。谢谢。