- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在这里看到了一些问题,但没有一个对我有帮助。人们主要解决重新生成服务器证书的问题:What is the reason of kSecTrustResultRecoverableTrustFailure?
假设我需要使用自签名证书与服务器建立 https 连接。我没有来自服务器的任何内部数据,例如它的私钥。例如服务器是 https://www.pcwebshop.co.uk/
据我所知,我可以将客户端证书捆绑到应用程序中并将其用于验证。我是否可以在没有来自服务器的任何内部数据的情况下获得有效的客户端证书?
我在这里搜索了一个教程 http://www.indelible.org/ink/trusted-ssl-certificates
这是我获取客户端证书的方式
openssl s_client \
-showcerts -connect "${HOST}:443" </dev/null 2>/dev/null | \
openssl x509 -outform DER >"../resources/${HOST}.der"
这是代码(几乎没有变化):
- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];
}
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
if ([self shouldTrustProtectionSpace:challenge.protectionSpace]) {
[challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]
forAuthenticationChallenge:challenge];
} else {
[challenge.sender performDefaultHandlingForAuthenticationChallenge:challenge];
}
}
- (BOOL)shouldTrustProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
// load up the bundled certificate
NSString *certPath = [[NSBundle mainBundle] pathForResource:protectionSpace.host ofType:@"der"];
if (certPath == nil)
return NO;
OSStatus status;
NSData *certData = [[NSData alloc] initWithContentsOfFile:certPath];
CFDataRef certDataRef = (__bridge_retained CFDataRef)certData;
SecCertificateRef cert = SecCertificateCreateWithData(NULL, certDataRef);
// establish a chain of trust anchored on our bundled certificate
CFArrayRef certArrayRef = CFArrayCreate(NULL, (void *)&cert, 1, NULL);
SecTrustRef serverTrust = protectionSpace.serverTrust;
status = SecTrustSetAnchorCertificates(serverTrust, certArrayRef);
// status == 0
// verify that trust
SecTrustResultType trustResult;
status = SecTrustEvaluate(serverTrust, &trustResult);
// status == 0
CFRelease(certArrayRef);
CFRelease(cert);
CFRelease(certDataRef);
return trustResult == kSecTrustResultUnspecified;
}
trustResult 始终是 kSecTrustResultRecoverableTrustFailure。
我做错了什么?谢谢。
更新:好的,我发现原因是“服务器的证书与 URL 不匹配”。
是否可以通过忽略服务器证书的 URL(主机名)从客户端解决问题?
最佳答案
Suppose I need to make a https connection to server with self-signed certificate. I don't have any internal data from the server such as its private keys.
在这种情况下,您需要一个安全多样化策略。 Gutmann 在他的书中对此进行了详细介绍 Engineering Security .
简而言之:在您第一次遇到证书时明智地验证它。您仍然可以使用大多数传统的 PKI/PKIX 测试。一旦证书通过所有测试(“受信任的根路径”除外),您就可以将其称为“受信任”。这种策略称为首次使用时信任或 TOFU。
在后续的连接中,你不再需要TOFU,因为你已经遇到了证书或公钥。在随后的连接中,您确保证书或公钥是连续的(即不变),IP 来自与之前遇到的相同区域等。如果证书发生变化,那么请确保它是因为自签名即将过期.警惕意外变化。
Here's the code (almost unchanged):
...
trustResult == trustResult == kSecTrustResultUnspecified
对于 kSecTrustResultUnspecified
,请参阅 Technical Q&A QA1360 .本质上,这是一个可恢复的错误。问答说提示用户。 Gutmann(和我)建议使用如上所述的安全多元化策略。
您需要让用户脱离循环,因为他们总是会做出让他们尽快通过消息框的决定。不管他们回答对还是错都没有关系 - 他们想看跳舞的兔子。
此外,安全多样化策略甚至适用于kSecTrustResultProceed
。考虑:两者 Diginotar和 Trustwave破坏了 PKI{X},Cocoa/CocoaTouch 非常乐意返回 kSecTrustResultProceed
。这并不是 Cocoa/CocoaTouch 的错——PKI{X} 存在架构缺陷。
Is it possible to fix the issue from the client side by ignoring the URL (hostname) of the server's certificate?
这种做法违背了 PKI{X} 的目的。如果您愿意接受任何主机、任何公钥或任何签名,为什么还要首先使用 PKI{X}? PKI{X} 中 X509 的全部要点是使用受信任的第三方签名(在本例中为自签名)将实体或主机绑定(bind)到公钥。
如果您不关心绑定(bind),只需使用匿名 Diffie-Hellman 并结束安全剧院。
关于ios - 使用 NSURLConnection 使用自签名证书连接到 https 时的 kSecTrustResultRecoverableTrustFailure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24229926/
我得到了这个printHashKey函数,它运行良好。 fun printHashKey() { try { val info : PackageInfo = packageM
如何使用正确的签名 key 为我的 Android 应用包签名? 最佳答案 我尝试在此处和 this question 中使用多个答案, 但不知何故我收到了这个错误,因为我的 android/app/
我的 gradle 文件中有这个: android { signingConfigs { mySigningConfig { keyAlias 'the
请至少选择一个签名版本以在 Android Studio 2.3 中使用 现在在 Android Studio 中生成一个签名的 APK 时,它显示了两个选项(复选框),即 1. V1(Jar 签名)
我想表示一些标量值(例如整数或字符串)通过它的实际值或一些 NA 值,然后存储它们在集合中(例如列表)。目的是处理缺失值。 为此,我实现了一个签名 module type Scalar = sig
为什么这不完全有效? sum :: (Num a, Num b) => a -> b -> c sum a b = a + b 当然,错误消息与签名有关,但我仍然不明白原因。 Couldn't mat
谢谢帮助,我的问题是关于从下面的代码中收到的 ax 值? mov al,22h mov cl,0fdh imul cl 真机结果:ff9a 我的预期:00:9a(通过二进制相乘) 第一个数字是 22h
我有一个注释: import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.
我从对物体的思考中得出了一个术语。当我们扩展一个类时,扩展类将具有与父类相同的签名,因此术语 IS-A 来自...示例 class Foo{ } class Foo2 extends Foo{ } c
我需要在有符号整数和它们作为字节序列的内部表示之间进行转换。在 C 中,我使用的函数如下: unsigned char hibyte(unsigned short i) {return i>>8;}
我正在尝试使用给定的 RSA 参数对一些数据进行签名。 我给出了模数、指数、D、DP、DQ、P、Q 和 InverseQ。什么库或方法最容易使用来计算此签名。在 C# 中,一旦您提供参数,它们就会有一
这些签名之间有什么区别? T * f(T & identifier); T & f(T & identifier); T f(T & identifier); void f(T * identifie
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: Where and why do I have to put the “template” and “typ
我有一个签名,我需要在签名旁边添加图片。但我不确定 css 的确切程度和内容。目前它显示在文字下方,我应该把图片放在哪里?在相同的 tr 或 td 中?
查看 LinkedHashMap 的 JDK 源代码,我注意到这个类被声明为: public class LinkedHashMap extends HashMap im
背景:我继承了一个基于 linux 的嵌入式系统,其中包含一个 SMTP 代理和一些我不得不忍受的古怪限制。它位于 SMTP 客户端和服务器之间。当 SMTP 客户端连接时,代理会打开与服务器的连接,
这是 C++17 形式的规则 ([basic.lval]/8),但它在其他标准中看起来很相似(在 C++98 中是“lvalue”而不是“glvalue”): 8 If a program attem
我有一个注释: import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.
我即将开展一个项目,希望使用电子签名板使用 C# 捕获客户的签名、在设备上显示文本等。 现在,在我开始做进一步的研究之前,我想向你们征求一些意见/建议,我应该使用哪些设备.. 我现在的要求非常笼统:我
呢喃自己在心中开始扩张地盘,仿佛制式地广播了三次。 漾起的涟绮,用谈不上精腻的手段。 拒绝天亮,却又贪恋着贪恋多情的日光。 川流不息的画面是他们,而我的落幕停在右脚,它渴望着下台,而我只剩自言
我是一名优秀的程序员,十分优秀!