SRSecurityPolicy.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // Copyright (c) 2016-present, Facebook, Inc.
  3. // All rights reserved.
  4. //
  5. // This source code is licensed under the BSD-style license found in the
  6. // LICENSE file in the root directory of this source tree. An additional grant
  7. // of patent rights can be found in the PATENTS file in the same directory.
  8. //
  9. #import <Foundation/Foundation.h>
  10. #import <Security/Security.h>
  11. NS_ASSUME_NONNULL_BEGIN
  12. @interface SRSecurityPolicy : NSObject
  13. /**
  14. A default `SRSecurityPolicy` implementation specifies socket security and
  15. validates the certificate chain.
  16. Use a subclass of `SRSecurityPolicy` for more fine grained customization.
  17. */
  18. + (instancetype)defaultPolicy;
  19. /**
  20. Specifies socket security and provider certificate pinning, disregarding certificate
  21. chain validation.
  22. @param pinnedCertificates Array of `SecCertificateRef` SSL certificates to use for validation.
  23. */
  24. + (instancetype)pinnningPolicyWithCertificates:(NSArray *)pinnedCertificates;
  25. /**
  26. Specifies socket security and optional certificate chain validation.
  27. @param enabled Whether or not to validate the SSL certificate chain. If you
  28. are considering using this method because your certificate was not issued by a
  29. recognized certificate authority, consider using `pinningPolicyWithCertificates` instead.
  30. */
  31. - (instancetype)initWithCertificateChainValidationEnabled:(BOOL)enabled NS_DESIGNATED_INITIALIZER;
  32. /**
  33. Updates all the security options for input and output streams, for example you
  34. can set your socket security level here.
  35. @param stream Stream to update the options in.
  36. */
  37. - (void)updateSecurityOptionsInStream:(NSStream *)stream;
  38. /**
  39. Whether or not the specified server trust should be accepted, based on the security policy.
  40. This method should be used when responding to an authentication challenge from
  41. a server. In the default implemenation, no further validation is done here, but
  42. you're free to override it in a subclass. See `SRPinningSecurityPolicy.h` for
  43. an example.
  44. @param serverTrust The X.509 certificate trust of the server.
  45. @param domain The domain of serverTrust.
  46. @return Whether or not to trust the server.
  47. */
  48. - (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust forDomain:(NSString *)domain;
  49. @end
  50. NS_ASSUME_NONNULL_END