Hello,

This API is not presently exposed in MonoTouch but you can see how to
use it in [1]. That's the code that both MonoTouch and MonoMac use to
verify the X.509 certificates when doing SSL/TLS connections.

Sebastien

[1] 
https://github.com/mono/mono/blob/master/mcs/class/System/System.Security.Cryptography.X509Certificates/OSX509Certificates.cs#L44

On Wed, Jul 18, 2012 at 1:22 PM, pwijegunawardena
<pwijegunaward...@bloommg.com> wrote:
> I'm essentially trying to do what is outlined in this article (Listing 2-6:
> Obtaining a Policy Object and Evaluating Trust) in MonoTouch. I have a X509
> Certificate and I'm trying to import it and evaluate its trust.
>
> developer.apple.com/library/ios/#documentation/Security/Conceptual/CertKeyTrustProgGuide/iPhone_Tasks/iPhone_Tasks.html#//apple_ref/doc/uid/TP40001358-CH208-DontLinkElementID_9
>
> I can't seem to find the corresponding MonoTouch implementation of OSStatus
> or SecTrustEvaluate.
>
> Any help is much appreciated. I also copied and pasted the objective-C code
> below.
>
> Thanks much.
>
> Push W.
>
> -- Objective-C Code:
>
>     NSString *thePath = [[NSBundle mainBundle]
>
>                           pathForResource:@"Romeo Montegue" ofType:@"cer"];
>
>     NSData *certData = [[NSData alloc]
>
>                          initWithContentsOfFile:thePath];
>
>     CFDataRef myCertData = (CFDataRef)certData;                 // 1
>
>
>
>     SecCertificateRef myCert;
>
>     myCert = SecCertificateCreateWithData(NULL, myCertData);    // 2
>
>
>
>     SecPolicyRef myPolicy = SecPolicyCreateBasicX509();         // 3
>
>
>
>     SecCertificateRef certArray[1] = { myCert };
>
>     CFArrayRef myCerts = CFArrayCreate(
>
>                                        NULL, (void *)certArray,
>
>                                        1, NULL);
>
>     SecTrustRef myTrust;
>
>     OSStatus status = SecTrustCreateWithCertificates(
>
>                                                     myCerts,
>
>                                                     myPolicy,
>
>                                                     &myTrust);  // 4
>
>
>
>     SecTrustResultType trustResult;
>
>     if (status == noErr) {
>
>         status = SecTrustEvaluate(myTrust, &trustResult);       // 5
>
>     }
>
> ...                                                             // 6
>
>     if (trustResult == kSecTrustResultRecoverableTrustFailure) {
>
>         ...;
>
>     }
>
> ...
>
>     if (myPolicy)
>
>         CFRelease(myPolicy);
>
>
>
>
>
> --
> View this message in context: 
> http://monotouch.2284126.n4.nabble.com/Obtaining-a-Policy-Object-and-Evaluating-Trust-in-MonoTouch-tp4656046.html
> Sent from the MonoTouch mailing list archive at Nabble.com.
> _______________________________________________
> MonoTouch mailing list
> MonoTouch@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/monotouch
_______________________________________________
MonoTouch mailing list
MonoTouch@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to