AuthURLSessionTaskDelegate.h 2.3 KB

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