AuthURLSessionTaskDelegate.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // AuthURLSessionTaskDelegate.h
  3. // TunneledWebRequest
  4. //
  5. /*
  6. Licensed under Creative Commons Zero (CC0).
  7. https://creativecommons.org/publicdomain/zero/1.0/
  8. */
  9. // NOTE: this file is shared by TunneledWebRequest and TunneledWebView
  10. #import <Foundation/Foundation.h>
  11. NS_ASSUME_NONNULL_BEGIN
  12. /*
  13. * AuthURLSessionTaskDelegate implements URLSession:task:didReceiveChallenge:completionHandler:
  14. * of the NSURLSessionTaskDelegate protocol.
  15. *
  16. * The main motivation of AuthURLSessionTaskDelegate is to ensure that OCSP requests are not
  17. * sent in plaintext outside of the tunnel.
  18. *
  19. * If the policy object for checking the revocation of certificates is created with
  20. * SecPolicyCreateRevocation(kSecRevocationOCSPMethod | ...), and network access is allowed
  21. * (the kSecRevocationNetworkAccessDisabled flag is not provided), a plaintext OCSP request over
  22. * HTTP is triggered when SecTrustEvaluate() is called. This request does not respect NSURLProtocol
  23. * subclassing.
  24. *
  25. * The solution is to inspect each X.509 certificate for the Online Certificate Status Protocol
  26. * (1.3.6.1.5.5.7.48.1) Authority Information Access Method, which contains the locations (URLs) of
  27. * the OCSP servers; then OCSP requests are then made to these servers through the local HTTP proxy.
  28. *
  29. * Note: The OCSP Authority Information Access Method is found in the Certificate Authority
  30. * Information Access (1.3.6.1.5.5.7.1.1) X.509v3 extension --
  31. * https://tools.ietf.org/html/rfc2459#section-4.2.2.1.
  32. */
  33. @interface AuthURLSessionTaskDelegate : NSObject <NSURLSessionDelegate>
  34. /*
  35. * Logger for errors.
  36. */
  37. @property (nonatomic, strong) void (^logger)(NSString*);
  38. /*
  39. * Local HTTP proxy port.
  40. *
  41. * OCSP request URL is constructed as:
  42. * http://127.0.0.1:<HTTP proxy port>/tunneled/<URL encoded OCSP request>
  43. */
  44. @property (atomic, assign) NSInteger localHTTPProxyPort;
  45. - (id)initWithLogger:(void (^)(NSString*))logger andLocalHTTPProxyPort:(NSInteger)port;
  46. - (void)URLSession:(NSURLSession *)session
  47. task:(NSURLSessionTask *)task
  48. didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
  49. completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential *))completionHandler;
  50. @end
  51. NS_ASSUME_NONNULL_END