我正在尝试使用MonoTouch将客户端证书用于SSL连接.似乎有几个例子使用objective-c来做到这一点,我正在寻找的解决方案可能与此处回答的解决方案类似,但在MonoTouch(C#)中.
我在MonoTouch中使用NSUrlConnection类,并重写了NSUrlConnectionDelegate类以响应身份验证挑战.
我已经能够从文件加载证书,但我无法找到证书的有用表示来响应身份验证质询.
public override void ReceivedAuthenticationChallenge(NSUrlConnection connection, NSUrlAuthenticationChallenge challenge)
{
if (string.Equals(challenge.ProtectionSpace.AuthenticationMethod, "NSURLAuthenticationMethodClientCertificate", StringComparison.OrdinalIgnoreCase)) {
string password = "<password_signed_certificate>";
byte[] data = File.ReadAllBytes("<path_of_file_in_ios_sandboxed_filesystem_pkcs>");
NSDictionary opt = NSDictionary.FromObjectsAndKeys(new object[]{password}, new object[]{"passphrase"});
NSDictionary[] items;
SecStatusCode stat = SecImportExport.ImportPkcs12(data, opt, out items); // Uses MonoTouch.Security namespace
MonoTouch.Security.SecTrust trust = (MonoTouch.Security.SecTrust)items[0]["trust"];
// Everything to this point works, and I can inspect the trust object that all the expected certificate properties (IssuerName etc.) are correct
IntPtr secTrustRef = trust // ????? How …Run Code Online (Sandbox Code Playgroud)