TSKTrustKitConfig.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. TSKTrustKitConfig.h
  3. TrustKit
  4. Copyright 2017 The TrustKit Project Authors
  5. Licensed under the MIT license, see associated LICENSE file for terms.
  6. See AUTHORS file for the list of project authors.
  7. */
  8. #if __has_feature(modules)
  9. @import Foundation;
  10. #else
  11. #import <Foundation/Foundation.h>
  12. #endif
  13. /**
  14. The version of TrustKit, such as "1.4.0".
  15. */
  16. FOUNDATION_EXPORT NSString * const TrustKitVersion;
  17. #pragma mark Configuration Keys
  18. /**
  19. A global, App-wide configuration key that can be set in the pinning policy.
  20. */
  21. typedef NSString *TSKGlobalConfigurationKey;
  22. /**
  23. A domain-specific configuration key (to defined for a domain under the `kTSKPinnedDomains`
  24. key) that can be set in the pinning policy.
  25. */
  26. typedef NSString *TSKDomainConfigurationKey;
  27. #pragma mark Global Configuration Keys - Required
  28. /**
  29. A boolean. If set to `YES`, TrustKit will perform method swizzling on the App's
  30. `NSURLConnection` and `NSURLSession` delegates in order to automatically add SSL pinning
  31. validation to the App's connections. This option can only be used if TrustKit is
  32. initialized in singleton mode; default value is `NO`.
  33. Swizzling allows enabling pinning within an App without having to find and modify each
  34. and every instance of `NSURLConnection` or `NSURLSession` delegates.
  35. However, it should only be enabled for simple Apps, as it may not work properly in several
  36. scenarios including:
  37. * Apps with complex connection delegates, for example to handle client authentication
  38. via certificates or basic authentication.
  39. * Apps where method swizzling of the connection delegates is already performed by another
  40. module or library (such as Analytics SDKs).
  41. * Apps that do no use `NSURLSession` or `NSURLConnection` for their connections.
  42. In such scenarios or if the developer wants a tigher control on the App's networking
  43. behavior, `kTSKSwizzleNetworkDelegates` should be set to `NO`; the developer should then
  44. manually add pinning validation to the App's authentication handlers.
  45. See the `TSKPinningValidator` class for instructions on how to do so.
  46. */
  47. FOUNDATION_EXPORT const TSKGlobalConfigurationKey kTSKSwizzleNetworkDelegates;
  48. /**
  49. A dictionary with domains (such as _www.domain.com_) as keys and dictionaries as values.
  50. Each entry should contain domain-specific settings for performing pinning validation when
  51. connecting to the domain, including for example the domain's public key hashes. A list of
  52. all domain-specific keys is available in the "Domain-specific Keys" sections.
  53. */
  54. FOUNDATION_EXPORT const TSKGlobalConfigurationKey kTSKPinnedDomains;
  55. #pragma mark Global Configuration Keys - Optional
  56. /**
  57. A boolean. If set to `YES`, pinning validation will be skipped if the server's certificate
  58. chain terminates at a user-defined trust anchor (such as a root CA that isn't part of OS X's
  59. default trust store) and no pin failure reports will be sent; default value is `YES`.
  60. This is useful for allowing SSL connections through corporate proxies or firewalls. See
  61. "How does key pinning interact with local proxies and filters?" within the Chromium security
  62. FAQ at https://www.chromium.org/Home/chromium-security/security-faq for more information.
  63. Only available on macOS.
  64. */
  65. FOUNDATION_EXPORT const TSKGlobalConfigurationKey kTSKIgnorePinningForUserDefinedTrustAnchors NS_AVAILABLE_MAC(10_9);
  66. #pragma mark Domain-Specific Configuration Keys - Required
  67. /**
  68. An array of SSL pins, where each pin is the base64-encoded SHA-256 hash of a certificate's
  69. Subject Public Key Info.
  70. TrustKit will verify that at least one of the specified pins is found in the server's
  71. evaluated certificate chain.
  72. */
  73. FOUNDATION_EXPORT const TSKDomainConfigurationKey kTSKPublicKeyHashes;
  74. /**
  75. DEPRECATED since 1.6.0: this configuration key is no longer needed.
  76. An array of `TSKSupportedAlgorithm` constants to specify the public key algorithms for the
  77. keys to be pinned.
  78. TrustKit requires this information in order to compute SSL pins when validating a server's
  79. certificate chain, because the `Security` framework does not provide APIs to extract the
  80. key's algorithm from an SSL certificate. To minimize the performance impact of Trustkit,
  81. only one algorithm should be enabled.
  82. */
  83. FOUNDATION_EXPORT const TSKDomainConfigurationKey kTSKPublicKeyAlgorithms __deprecated_msg("Starting with TrustKit 1.6.0, key algorithms no longer need to be specified; remove TSKPublicKeyAlgorithms from your configuration.");
  84. #pragma mark Domain-Specific Configuration Keys - Optional
  85. /**
  86. A boolean. If set to `NO`, TrustKit will not block SSL connections that caused a pin or
  87. certificate validation error; default value is `YES`.
  88. When a pinning failure occurs, pin failure reports will always be sent to the configured
  89. report URIs regardless of the value of `kTSKEnforcePinning`.
  90. */
  91. FOUNDATION_EXPORT const TSKDomainConfigurationKey kTSKEnforcePinning;
  92. /**
  93. A boolean. If set to `YES`, also pin all the subdomains of the specified domain; default
  94. value is `NO`.
  95. */
  96. FOUNDATION_EXPORT const TSKDomainConfigurationKey kTSKIncludeSubdomains;
  97. /**
  98. A boolean. If set to `YES`, TrustKit will not pin this specific domain if `kTSKIncludeSubdomains`
  99. was set for this domain's parent domain.
  100. This allows excluding specific subdomains from a pinning policy that was applied to a
  101. parent domain.
  102. */
  103. FOUNDATION_EXPORT const TSKDomainConfigurationKey kTSKExcludeSubdomainFromParentPolicy;
  104. /**
  105. An array of URLs to which pin validation failures should be reported.
  106. To minimize the performance impact of sending reports on each validation failure, the reports
  107. are uploaded using the background transfer service and are also rate-limited to one per day
  108. and per type of failure. For HTTPS report URLs, the HTTPS connections will ignore the SSL
  109. pinning policy and use the default certificate validation mechanisms, in order to maximize
  110. the chance of the reports reaching the server. The format of the reports is similar to the
  111. one described in RFC 7469 for the HPKP specification:
  112. {
  113. "app-bundle-id": "com.datatheorem.testtrustkit2",
  114. "app-version": "1",
  115. "app-vendor-id": "599F9C00-92DC-4B5C-9464-7971F01F8370",
  116. "app-platform": "IOS",
  117. "app-platform-version": "10.2.0",
  118. "trustkit-version": "1.3.1",
  119. "hostname": "www.datatheorem.com",
  120. "port": 0,
  121. "noted-hostname": "datatheorem.com",
  122. "include-subdomains": true,
  123. "enforce-pinning": true,
  124. "validated-certificate-chain": [
  125. pem1, ... pemN
  126. ],
  127. "known-pins": [
  128. "pin-sha256=\"d6qzRu9zOECb90Uez27xWltNsj0e1Md7GkYYkVoZWmM=\"",
  129. "pin-sha256=\"E9CZ9INDbd+2eRQozYqqbQ2yXLVKB9+xcprMF+44U1g=\""
  130. ],
  131. "validation-result":1
  132. }
  133. */
  134. FOUNDATION_EXPORT const TSKDomainConfigurationKey kTSKReportUris;
  135. /**
  136. A boolean. If set to `YES`, the default report URL for sending pin failure reports will
  137. be disabled; default value is `NO`.
  138. By default, pin failure reports are sent to a report server hosted by Data Theorem, for
  139. detecting potential CA compromises and man-in-the-middle attacks, as well as providing a
  140. free dashboard for developers; email info@datatheorem.com if you'd like a dashboard for
  141. your App. Only pin failure reports are sent, which contain the App's bundle ID, the IDFV,
  142. and the server's hostname and certificate chain that failed validation.
  143. */
  144. FOUNDATION_EXPORT const TSKDomainConfigurationKey kTSKDisableDefaultReportUri;
  145. /**
  146. A string containing the date, in yyyy-MM-dd format, on which the domain's configured SSL
  147. pins expire, thus disabling pinning validation. If the key is not set, then the pins do
  148. not expire.
  149. Expiration helps prevent connectivity issues in Apps which do not get updates to their
  150. pin set, such as when the user disables App updates.
  151. */
  152. FOUNDATION_EXPORT const TSKDomainConfigurationKey kTSKExpirationDate;
  153. #pragma mark DEPRECATED - Supported Public Key Algorithm Keys
  154. /**
  155. DEPRECATED since 1.6.0: this configuration key is no longer needed.
  156. A public key algorithm supported by TrustKit for generating the SSL pin for a certificate.
  157. */
  158. typedef NSString *TSKSupportedAlgorithm __deprecated_msg("Starting with TrustKit 1.6.0, key algorithms no longer need to be specified; remove TSKSupportedAlgorithm from your configuration.");
  159. /**
  160. RSA 2048.
  161. */
  162. FOUNDATION_EXPORT const TSKSupportedAlgorithm kTSKAlgorithmRsa2048 __deprecated_msg("Starting with TrustKit 1.6.0, key algorithms no longer need to be specified; remove TSKPublicKeyAlgorithms from your configuration.");
  163. /**
  164. RSA 4096.
  165. */
  166. FOUNDATION_EXPORT const TSKSupportedAlgorithm kTSKAlgorithmRsa4096 __deprecated_msg("Starting with TrustKit 1.6.0, key algorithms no longer need to be specified; remove TSKPublicKeyAlgorithms from your configuration.");
  167. /**
  168. ECDSA with secp256r1 curve.
  169. */
  170. FOUNDATION_EXPORT const TSKSupportedAlgorithm kTSKAlgorithmEcDsaSecp256r1 __deprecated_msg("Starting with TrustKit 1.6.0, key algorithms no longer need to be specified; remove TSKPublicKeyAlgorithms from your configuration.");
  171. /**
  172. ECDSA with secp384r1 curve.
  173. */
  174. FOUNDATION_EXPORT const TSKSupportedAlgorithm kTSKAlgorithmEcDsaSecp384r1 __deprecated_msg("Starting with TrustKit 1.6.0, key algorithms no longer need to be specified; remove TSKPublicKeyAlgorithms from your configuration.");