gpt4 book ai didi

iphone - 在 canAuthenticateAgainstProtectionSpace 中检查公钥

转载 作者:可可西里 更新时间:2023-11-01 06:23:54 24 4
gpt4 key购买 nike

有人要求我根据 canAuthenticateAgainstProtectionSpace 中的已知值检查公钥( NSURLConnection 的委托(delegate)回调)

这是我目前所拥有的:

- (BOOL)connection:(NSURLConnection *)connection 
canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
SecKeyRef publicKey = SecTrustCopyPublicKey([protectionSpace serverTrust]);

NSLog(@"%@",SecTrustCopyPublicKey([protectionSpace serverTrust]));
return YES;
}

如何将公钥与已知值进行比较?

NSLog 产生:<SecKeyRef: 0x687c000>这没什么用。

最佳答案

如果有人关心,解决方案是使用保存在 bundle 中的证书逐字节检查证书。

- (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace 
{
SecTrustRef trust = [protectionSpace serverTrust];

SecCertificateRef certificate = SecTrustGetCertificateAtIndex(trust, 0);

NSData* ServerCertificateData = (NSData*) SecCertificateCopyData(certificate);

// Check if the certificate returned from the server is identical to the saved certificate in
// the main bundle
BOOL areCertificatesEqual = ([ServerCertificateData
isEqualToData:[MyClass getCertificate]]);

[ServerCertificateData release];

if (!areCertificatesEqual)
{
NSLog(@"Bad Certificate, canceling request");
[connection cancel];
}

// If the certificates are not equal we should not talk to the server;
return areCertificatesEqual;
}

关于iphone - 在 canAuthenticateAgainstProtectionSpace 中检查公钥,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5675808/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com