-
-
Save therealjohn/10069333 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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