MonoTouch를 사용하여 SSL 연결에 클라이언트 인증서를 사용하려고합니다. objective-c를 사용하여이 작업을 수행하는 몇 가지 예제가있는 것으로 보입니다. 내가 찾고있는 솔루션은 아마도 비슷할 것이라고 here하지만 MonoTouch (C#)에서 대답했습니다.Monotouch로 HTTPS 클라이언트 인증서
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 do I bridge this gap
// NSUrlConnection does not utilise MonoTouch security namespace
NSUrlCredential cred = new NSUrlCredential(secTrustRef, true);
challenge.Sender.UseCredentials(cred, challenge);
}
}
일부 노트 :
- 나는 목표 - C 솔루션을 보았다하지만 난 MonoTouch (C#을)에 필요한 단계에 해당 세트를 발견하지 않았습니다.
- httpWebRequest.ClientCertificates (컬렉션)의 모노 터치 구현이 '구현되지 않은 예외'를 throw하므로 HttpWebRequest를 사용할 수 없습니다.
- Mono.Security.X509 및 System.Security.Cryptography.X509Certificates 네임 스페이스를 사용하여 인증서를 성공적으로 열려고 시도했지만 다시 클래스 인스턴스를 사용하여 인증 요청에 응답 할 수 없습니다. IntPtr만을 받아들이는 NSUrlCredential 객체를 생성합니다.
- this도 참조하십시오.
NSUrlSession을 사용하여이 작업을 수행하는 방법에 대한 아이디어가 있습니까? – nhenrique