SRSecurityPolicy.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. DEPRECATED_MSG_ATTRIBUTE("Using pinned certificates is neither secure nor supported in SocketRocket, "
  26. "and leads to security issues. Please use a proper, trust chain validated certificate.");
  27. /**
  28. Specifies socket security and optional certificate chain validation.
  29. @param enabled Whether or not to validate the SSL certificate chain. If you
  30. are considering using this method because your certificate was not issued by a
  31. recognized certificate authority, consider using `pinningPolicyWithCertificates` instead.
  32. */
  33. - (instancetype)initWithCertificateChainValidationEnabled:(BOOL)enabled
  34. DEPRECATED_MSG_ATTRIBUTE("Disabling certificate chain validation is unsafe. "
  35. "Please use a proper Certificate Authority to issue your TLS certificates.")
  36. NS_DESIGNATED_INITIALIZER;
  37. /**
  38. Updates all the security options for input and output streams, for example you
  39. can set your socket security level here.
  40. @param stream Stream to update the options in.
  41. */
  42. - (void)updateSecurityOptionsInStream:(NSStream *)stream;
  43. /**
  44. Whether or not the specified server trust should be accepted, based on the security policy.
  45. This method should be used when responding to an authentication challenge from
  46. a server. In the default implemenation, no further validation is done here, but
  47. you're free to override it in a subclass. See `SRPinningSecurityPolicy.h` for
  48. an example.
  49. @param serverTrust The X.509 certificate trust of the server.
  50. @param domain The domain of serverTrust.
  51. @return Whether or not to trust the server.
  52. */
  53. - (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust forDomain:(NSString *)domain;
  54. @end
  55. NS_ASSUME_NONNULL_END