检查 canAuthenticateAgainstProtectionSpace 中的公钥
我被要求根据 canAuthenticateAgainstProtectionSpace
中的已知值检查公钥(NSURLConnection
)
这就是我到目前为止所拥有的:
- (BOOL)connection:(NSURLConnection *)connection
canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
SecKeyRef publicKey = SecTrustCopyPublicKey([protectionSpace serverTrust]);
NSLog(@"%@",SecTrustCopyPublicKey([protectionSpace serverTrust]));
return YES;
}
How can I Compare the public key against已知值?
NSLog 生成:
,这并不是很有用。
I have been asked to check the public key against a known value in canAuthenticateAgainstProtectionSpace
( a delegate callback of NSURLConnection
)
This is what I have so far:
- (BOOL)connection:(NSURLConnection *)connection
canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
SecKeyRef publicKey = SecTrustCopyPublicKey([protectionSpace serverTrust]);
NSLog(@"%@",SecTrustCopyPublicKey([protectionSpace serverTrust]));
return YES;
}
How can I compare the public key against a known value?
The NSLog produces: <SecKeyRef: 0x687c000>
which isn't vary useful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果有人关心的话,解决方案是使用捆绑包中保存的证书逐字节检查证书。
Incase anyone cares, the solution was to check the certificatie byte for byte with a certificate saved on the bundle.
请注意,SecCertificateCopyData 以“DER”形式(可区分编码规则)返回证书。因此,您需要以这种形式将证书合并到您的应用程序中,而不是作为 pem 或任何格式。要使用 openssl 将证书转换为 DER,请使用以下命令: openssl x509 -in server.crt -out server.der -outform DER
Note that SecCertificateCopyData returns the certificate in it's "DER" form, Distinguished Encoding Rules. So you need to incorporate the certificate in your App in that form, and not as a pem or whatever format. To convert a certificate to DER with openssl use the command: openssl x509 -in server.crt -out server.der -outform DER