Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class DataTaskDelegate : NSUrlSessionDataDelegate
{
NSUrlSessionHandler This { get; set; }
public DataTaskDelegate(NSUrlSessionHandler that)
{
this.This = that;
}
public override void DidReceiveChallenge(NSUrlSession session, NSUrlSessionTask task, NSUrlAuthenticationChallenge challenge, Action<NSUrlSessionAuthChallengeDisposition, NSUrlCredential> completionHandler)
{
if (This.certVerification == CertificateVerification.Normal ||
challenge.ProtectionSpace == null ||
challenge.ProtectionSpace.AuthenticationMethod != "NSURLAuthenticationMethodServerTrust") {
// XXX: This throws ArgumentNullException, but according to Apple
// Docs, this is how you indicate you want default result: "For
// other challenges, the ones that you don't care about, call the
// completion handler block with the
// NSURLSessionAuthChallengePerformDefaultHandling disposition and
// a NULL credential."
// https://developer.apple.com/library/ios/technotes/tn2232/_index.html#//apple_ref/doc/uid/DTS40012884-CH1-SECNSURLSESSION
completionHandler(NSUrlSessionAuthChallengeDisposition.PerformDefaultHandling, null);
}
Console.WriteLine("Performing INSECURE request to {0}", task.CurrentRequest.Url.AbsoluteString);
completionHandler(NSUrlSessionAuthChallengeDisposition.UseCredential, NSUrlCredential.FromTrust(new SecTrust(IntPtr.Zero)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment