1
0

appletls.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  1. #include "hssl.h"
  2. #ifdef WITH_APPLETLS
  3. /* Disclaimer: excerpted from curl */
  4. #include <Security/Security.h>
  5. /* For some reason, when building for iOS, the omnibus header above does
  6. * not include SecureTransport.h as of iOS SDK 5.1. */
  7. #include <Security/SecureTransport.h>
  8. #include <CoreFoundation/CoreFoundation.h>
  9. #include <CommonCrypto/CommonDigest.h>
  10. #include "hsocket.h"
  11. /* The Security framework has changed greatly between iOS and different macOS
  12. versions, and we will try to support as many of them as we can (back to
  13. Leopard and iOS 5) by using macros and weak-linking.
  14. In general, you want to build this using the most recent OS SDK, since some
  15. features require curl to be built against the latest SDK. TLS 1.1 and 1.2
  16. support, for instance, require the macOS 10.8 SDK or later. TLS 1.3
  17. requires the macOS 10.13 or iOS 11 SDK or later. */
  18. #if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
  19. #if MAC_OS_X_VERSION_MAX_ALLOWED < 1050
  20. #error "The Secure Transport back-end requires Leopard or later."
  21. #endif /* MAC_OS_X_VERSION_MAX_ALLOWED < 1050 */
  22. #define CURL_BUILD_IOS 0
  23. #define CURL_BUILD_IOS_7 0
  24. #define CURL_BUILD_IOS_9 0
  25. #define CURL_BUILD_IOS_11 0
  26. #define CURL_BUILD_IOS_13 0
  27. #define CURL_BUILD_MAC 1
  28. /* This is the maximum API level we are allowed to use when building: */
  29. #define CURL_BUILD_MAC_10_5 MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
  30. #define CURL_BUILD_MAC_10_6 MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
  31. #define CURL_BUILD_MAC_10_7 MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
  32. #define CURL_BUILD_MAC_10_8 MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
  33. #define CURL_BUILD_MAC_10_9 MAC_OS_X_VERSION_MAX_ALLOWED >= 1090
  34. #define CURL_BUILD_MAC_10_11 MAC_OS_X_VERSION_MAX_ALLOWED >= 101100
  35. #define CURL_BUILD_MAC_10_13 MAC_OS_X_VERSION_MAX_ALLOWED >= 101300
  36. #define CURL_BUILD_MAC_10_15 MAC_OS_X_VERSION_MAX_ALLOWED >= 101500
  37. /* These macros mean "the following code is present to allow runtime backward
  38. compatibility with at least this cat or earlier":
  39. (You set this at build-time using the compiler command line option
  40. "-mmacosx-version-min.") */
  41. #define CURL_SUPPORT_MAC_10_5 MAC_OS_X_VERSION_MIN_REQUIRED <= 1050
  42. #define CURL_SUPPORT_MAC_10_6 MAC_OS_X_VERSION_MIN_REQUIRED <= 1060
  43. #define CURL_SUPPORT_MAC_10_7 MAC_OS_X_VERSION_MIN_REQUIRED <= 1070
  44. #define CURL_SUPPORT_MAC_10_8 MAC_OS_X_VERSION_MIN_REQUIRED <= 1080
  45. #define CURL_SUPPORT_MAC_10_9 MAC_OS_X_VERSION_MIN_REQUIRED <= 1090
  46. #elif TARGET_OS_EMBEDDED || TARGET_OS_IPHONE
  47. #define CURL_BUILD_IOS 1
  48. #define CURL_BUILD_IOS_7 __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
  49. #define CURL_BUILD_IOS_9 __IPHONE_OS_VERSION_MAX_ALLOWED >= 90000
  50. #define CURL_BUILD_IOS_11 __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
  51. #define CURL_BUILD_IOS_13 __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
  52. #define CURL_BUILD_MAC 0
  53. #define CURL_BUILD_MAC_10_5 0
  54. #define CURL_BUILD_MAC_10_6 0
  55. #define CURL_BUILD_MAC_10_7 0
  56. #define CURL_BUILD_MAC_10_8 0
  57. #define CURL_BUILD_MAC_10_9 0
  58. #define CURL_BUILD_MAC_10_11 0
  59. #define CURL_BUILD_MAC_10_13 0
  60. #define CURL_BUILD_MAC_10_15 0
  61. #define CURL_SUPPORT_MAC_10_5 0
  62. #define CURL_SUPPORT_MAC_10_6 0
  63. #define CURL_SUPPORT_MAC_10_7 0
  64. #define CURL_SUPPORT_MAC_10_8 0
  65. #define CURL_SUPPORT_MAC_10_9 0
  66. #else
  67. #error "The Secure Transport back-end requires iOS or macOS."
  68. #endif /* (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE)) */
  69. #if !defined(__MAC_10_8)
  70. static const SSLProtocol kTLSProtocol11 = (SSLProtocol)7;
  71. static const SSLProtocol kTLSProtocol12 = (SSLProtocol)8;
  72. #endif
  73. #if !defined(__MAC_10_13)
  74. static const SSLProtocol kTLSProtocol13 = (SSLProtocol)10;
  75. #endif
  76. static inline const char* SSLProtocolToString(SSLProtocol proto) {
  77. switch(proto) {
  78. case kSSLProtocol2: return "SSLv2";
  79. case kSSLProtocol3: return "SSLv3";
  80. case kTLSProtocol1: return "TLSv1";
  81. case kTLSProtocol11: return "TLSv1.1";
  82. case kTLSProtocol12: return "TLSv1.2";
  83. case kTLSProtocol13: return "TLSv1.3";
  84. default: return "Unknown";
  85. }
  86. }
  87. struct st_cipher {
  88. const char *name; /* Cipher suite IANA name. It starts with "TLS_" prefix */
  89. const char *alias_name; /* Alias name is the same as OpenSSL cipher name */
  90. SSLCipherSuite num; /* Cipher suite code/number defined in IANA registry */
  91. bool weak; /* Flag to mark cipher as weak based on previous implementation
  92. of Secure Transport back-end by CURL */
  93. };
  94. /* Macro to initialize st_cipher data structure: stringify id to name, cipher
  95. number/id, 'weak' suite flag
  96. */
  97. #define CIPHER_DEF(num, alias, weak) \
  98. { #num, alias, num, weak }
  99. /*
  100. Macro to initialize st_cipher data structure with name, code (IANA cipher
  101. number/id value), and 'weak' suite flag. The first 28 cipher suite numbers
  102. have the same IANA code for both SSL and TLS standards: numbers 0x0000 to
  103. 0x001B. They have different names though. The first 4 letters of the cipher
  104. suite name are the protocol name: "SSL_" or "TLS_", rest of the IANA name is
  105. the same for both SSL and TLS cipher suite name.
  106. The second part of the problem is that macOS/iOS SDKs don't define all TLS
  107. codes but only 12 of them. The SDK defines all SSL codes though, i.e. SSL_NUM
  108. constant is always defined for those 28 ciphers while TLS_NUM is defined only
  109. for 12 of the first 28 ciphers. Those 12 TLS cipher codes match to
  110. corresponding SSL enum value and represent the same cipher suite. Therefore
  111. we'll use the SSL enum value for those cipher suites because it is defined
  112. for all 28 of them.
  113. We make internal data consistent and based on TLS names, i.e. all st_cipher
  114. item names start with the "TLS_" prefix.
  115. Summarizing all the above, those 28 first ciphers are presented in our table
  116. with both TLS and SSL names. Their cipher numbers are assigned based on the
  117. SDK enum value for the SSL cipher, which matches to IANA TLS number.
  118. */
  119. #define CIPHER_DEF_SSLTLS(num_wo_prefix, alias, weak) \
  120. { "TLS_" #num_wo_prefix, alias, SSL_##num_wo_prefix, weak }
  121. /*
  122. Cipher suites were marked as weak based on the following:
  123. RC4 encryption - rfc7465, the document contains a list of deprecated ciphers.
  124. Marked in the code below as weak.
  125. RC2 encryption - many mentions, was found vulnerable to a relatively easy
  126. attack https://link.springer.com/chapter/10.1007%2F3-540-69710-1_14
  127. Marked in the code below as weak.
  128. DES and IDEA encryption - rfc5469, has a list of deprecated ciphers.
  129. Marked in the code below as weak.
  130. Anonymous Diffie-Hellman authentication and anonymous elliptic curve
  131. Diffie-Hellman - vulnerable to a man-in-the-middle attack. Deprecated by
  132. RFC 4346 aka TLS 1.1 (section A.5, page 60)
  133. Null bulk encryption suites - not encrypted communication
  134. Export ciphers, i.e. ciphers with restrictions to be used outside the US for
  135. software exported to some countries, they were excluded from TLS 1.1
  136. version. More precisely, they were noted as ciphers which MUST NOT be
  137. negotiated in RFC 4346 aka TLS 1.1 (section A.5, pages 60 and 61).
  138. All of those filters were considered weak because they contain a weak
  139. algorithm like DES, RC2 or RC4, and already considered weak by other
  140. criteria.
  141. 3DES - NIST deprecated it and is going to retire it by 2023
  142. https://csrc.nist.gov/News/2017/Update-to-Current-Use-and-Deprecation-of-TDEA
  143. OpenSSL https://www.openssl.org/blog/blog/2016/08/24/sweet32/ also
  144. deprecated those ciphers. Some other libraries also consider it
  145. vulnerable or at least not strong enough.
  146. CBC ciphers are vulnerable with SSL3.0 and TLS1.0:
  147. https://www.cisco.com/c/en/us/support/docs/security/email-security-appliance
  148. /118518-technote-esa-00.html
  149. We don't take care of this issue because it is resolved by later TLS
  150. versions and for us, it requires more complicated checks, we need to
  151. check a protocol version also. Vulnerability doesn't look very critical
  152. and we do not filter out those cipher suites.
  153. */
  154. #define CIPHER_WEAK_NOT_ENCRYPTED TRUE
  155. #define CIPHER_WEAK_RC_ENCRYPTION TRUE
  156. #define CIPHER_WEAK_DES_ENCRYPTION TRUE
  157. #define CIPHER_WEAK_IDEA_ENCRYPTION TRUE
  158. #define CIPHER_WEAK_ANON_AUTH TRUE
  159. #define CIPHER_WEAK_3DES_ENCRYPTION TRUE
  160. #define CIPHER_STRONG_ENOUGH FALSE
  161. /* Please do not change the order of the first ciphers available for SSL.
  162. Do not insert and do not delete any of them. Code below
  163. depends on their order and continuity.
  164. If you add a new cipher, please maintain order by number, i.e.
  165. insert in between existing items to appropriate place based on
  166. cipher suite IANA number
  167. */
  168. const static struct st_cipher ciphertable[] = {
  169. /* SSL version 3.0 and initial TLS 1.0 cipher suites.
  170. Defined since SDK 10.2.8 */
  171. CIPHER_DEF_SSLTLS(NULL_WITH_NULL_NULL, /* 0x0000 */
  172. NULL,
  173. CIPHER_WEAK_NOT_ENCRYPTED),
  174. CIPHER_DEF_SSLTLS(RSA_WITH_NULL_MD5, /* 0x0001 */
  175. "NULL-MD5",
  176. CIPHER_WEAK_NOT_ENCRYPTED),
  177. CIPHER_DEF_SSLTLS(RSA_WITH_NULL_SHA, /* 0x0002 */
  178. "NULL-SHA",
  179. CIPHER_WEAK_NOT_ENCRYPTED),
  180. CIPHER_DEF_SSLTLS(RSA_EXPORT_WITH_RC4_40_MD5, /* 0x0003 */
  181. "EXP-RC4-MD5",
  182. CIPHER_WEAK_RC_ENCRYPTION),
  183. CIPHER_DEF_SSLTLS(RSA_WITH_RC4_128_MD5, /* 0x0004 */
  184. "RC4-MD5",
  185. CIPHER_WEAK_RC_ENCRYPTION),
  186. CIPHER_DEF_SSLTLS(RSA_WITH_RC4_128_SHA, /* 0x0005 */
  187. "RC4-SHA",
  188. CIPHER_WEAK_RC_ENCRYPTION),
  189. CIPHER_DEF_SSLTLS(RSA_EXPORT_WITH_RC2_CBC_40_MD5, /* 0x0006 */
  190. "EXP-RC2-CBC-MD5",
  191. CIPHER_WEAK_RC_ENCRYPTION),
  192. CIPHER_DEF_SSLTLS(RSA_WITH_IDEA_CBC_SHA, /* 0x0007 */
  193. "IDEA-CBC-SHA",
  194. CIPHER_WEAK_IDEA_ENCRYPTION),
  195. CIPHER_DEF_SSLTLS(RSA_EXPORT_WITH_DES40_CBC_SHA, /* 0x0008 */
  196. "EXP-DES-CBC-SHA",
  197. CIPHER_WEAK_DES_ENCRYPTION),
  198. CIPHER_DEF_SSLTLS(RSA_WITH_DES_CBC_SHA, /* 0x0009 */
  199. "DES-CBC-SHA",
  200. CIPHER_WEAK_DES_ENCRYPTION),
  201. CIPHER_DEF_SSLTLS(RSA_WITH_3DES_EDE_CBC_SHA, /* 0x000A */
  202. "DES-CBC3-SHA",
  203. CIPHER_WEAK_3DES_ENCRYPTION),
  204. CIPHER_DEF_SSLTLS(DH_DSS_EXPORT_WITH_DES40_CBC_SHA, /* 0x000B */
  205. "EXP-DH-DSS-DES-CBC-SHA",
  206. CIPHER_WEAK_DES_ENCRYPTION),
  207. CIPHER_DEF_SSLTLS(DH_DSS_WITH_DES_CBC_SHA, /* 0x000C */
  208. "DH-DSS-DES-CBC-SHA",
  209. CIPHER_WEAK_DES_ENCRYPTION),
  210. CIPHER_DEF_SSLTLS(DH_DSS_WITH_3DES_EDE_CBC_SHA, /* 0x000D */
  211. "DH-DSS-DES-CBC3-SHA",
  212. CIPHER_WEAK_3DES_ENCRYPTION),
  213. CIPHER_DEF_SSLTLS(DH_RSA_EXPORT_WITH_DES40_CBC_SHA, /* 0x000E */
  214. "EXP-DH-RSA-DES-CBC-SHA",
  215. CIPHER_WEAK_DES_ENCRYPTION),
  216. CIPHER_DEF_SSLTLS(DH_RSA_WITH_DES_CBC_SHA, /* 0x000F */
  217. "DH-RSA-DES-CBC-SHA",
  218. CIPHER_WEAK_DES_ENCRYPTION),
  219. CIPHER_DEF_SSLTLS(DH_RSA_WITH_3DES_EDE_CBC_SHA, /* 0x0010 */
  220. "DH-RSA-DES-CBC3-SHA",
  221. CIPHER_WEAK_3DES_ENCRYPTION),
  222. CIPHER_DEF_SSLTLS(DHE_DSS_EXPORT_WITH_DES40_CBC_SHA, /* 0x0011 */
  223. "EXP-EDH-DSS-DES-CBC-SHA",
  224. CIPHER_WEAK_DES_ENCRYPTION),
  225. CIPHER_DEF_SSLTLS(DHE_DSS_WITH_DES_CBC_SHA, /* 0x0012 */
  226. "EDH-DSS-CBC-SHA",
  227. CIPHER_WEAK_DES_ENCRYPTION),
  228. CIPHER_DEF_SSLTLS(DHE_DSS_WITH_3DES_EDE_CBC_SHA, /* 0x0013 */
  229. "DHE-DSS-DES-CBC3-SHA",
  230. CIPHER_WEAK_3DES_ENCRYPTION),
  231. CIPHER_DEF_SSLTLS(DHE_RSA_EXPORT_WITH_DES40_CBC_SHA, /* 0x0014 */
  232. "EXP-EDH-RSA-DES-CBC-SHA",
  233. CIPHER_WEAK_DES_ENCRYPTION),
  234. CIPHER_DEF_SSLTLS(DHE_RSA_WITH_DES_CBC_SHA, /* 0x0015 */
  235. "EDH-RSA-DES-CBC-SHA",
  236. CIPHER_WEAK_DES_ENCRYPTION),
  237. CIPHER_DEF_SSLTLS(DHE_RSA_WITH_3DES_EDE_CBC_SHA, /* 0x0016 */
  238. "DHE-RSA-DES-CBC3-SHA",
  239. CIPHER_WEAK_3DES_ENCRYPTION),
  240. CIPHER_DEF_SSLTLS(DH_anon_EXPORT_WITH_RC4_40_MD5, /* 0x0017 */
  241. "EXP-ADH-RC4-MD5",
  242. CIPHER_WEAK_ANON_AUTH),
  243. CIPHER_DEF_SSLTLS(DH_anon_WITH_RC4_128_MD5, /* 0x0018 */
  244. "ADH-RC4-MD5",
  245. CIPHER_WEAK_ANON_AUTH),
  246. CIPHER_DEF_SSLTLS(DH_anon_EXPORT_WITH_DES40_CBC_SHA, /* 0x0019 */
  247. "EXP-ADH-DES-CBC-SHA",
  248. CIPHER_WEAK_ANON_AUTH),
  249. CIPHER_DEF_SSLTLS(DH_anon_WITH_DES_CBC_SHA, /* 0x001A */
  250. "ADH-DES-CBC-SHA",
  251. CIPHER_WEAK_ANON_AUTH),
  252. CIPHER_DEF_SSLTLS(DH_anon_WITH_3DES_EDE_CBC_SHA, /* 0x001B */
  253. "ADH-DES-CBC3-SHA",
  254. CIPHER_WEAK_3DES_ENCRYPTION),
  255. CIPHER_DEF(SSL_FORTEZZA_DMS_WITH_NULL_SHA, /* 0x001C */
  256. NULL,
  257. CIPHER_WEAK_NOT_ENCRYPTED),
  258. CIPHER_DEF(SSL_FORTEZZA_DMS_WITH_FORTEZZA_CBC_SHA, /* 0x001D */
  259. NULL,
  260. CIPHER_STRONG_ENOUGH),
  261. #if CURL_BUILD_MAC_10_9 || CURL_BUILD_IOS_7
  262. /* RFC 4785 - Pre-Shared Key (PSK) Ciphersuites with NULL Encryption */
  263. CIPHER_DEF(TLS_PSK_WITH_NULL_SHA, /* 0x002C */
  264. "PSK-NULL-SHA",
  265. CIPHER_WEAK_NOT_ENCRYPTED),
  266. CIPHER_DEF(TLS_DHE_PSK_WITH_NULL_SHA, /* 0x002D */
  267. "DHE-PSK-NULL-SHA",
  268. CIPHER_WEAK_NOT_ENCRYPTED),
  269. CIPHER_DEF(TLS_RSA_PSK_WITH_NULL_SHA, /* 0x002E */
  270. "RSA-PSK-NULL-SHA",
  271. CIPHER_WEAK_NOT_ENCRYPTED),
  272. #endif /* CURL_BUILD_MAC_10_9 || CURL_BUILD_IOS_7 */
  273. /* TLS addenda using AES, per RFC 3268. Defined since SDK 10.4u */
  274. CIPHER_DEF(TLS_RSA_WITH_AES_128_CBC_SHA, /* 0x002F */
  275. "AES128-SHA",
  276. CIPHER_STRONG_ENOUGH),
  277. CIPHER_DEF(TLS_DH_DSS_WITH_AES_128_CBC_SHA, /* 0x0030 */
  278. "DH-DSS-AES128-SHA",
  279. CIPHER_STRONG_ENOUGH),
  280. CIPHER_DEF(TLS_DH_RSA_WITH_AES_128_CBC_SHA, /* 0x0031 */
  281. "DH-RSA-AES128-SHA",
  282. CIPHER_STRONG_ENOUGH),
  283. CIPHER_DEF(TLS_DHE_DSS_WITH_AES_128_CBC_SHA, /* 0x0032 */
  284. "DHE-DSS-AES128-SHA",
  285. CIPHER_STRONG_ENOUGH),
  286. CIPHER_DEF(TLS_DHE_RSA_WITH_AES_128_CBC_SHA, /* 0x0033 */
  287. "DHE-RSA-AES128-SHA",
  288. CIPHER_STRONG_ENOUGH),
  289. CIPHER_DEF(TLS_DH_anon_WITH_AES_128_CBC_SHA, /* 0x0034 */
  290. "ADH-AES128-SHA",
  291. CIPHER_WEAK_ANON_AUTH),
  292. CIPHER_DEF(TLS_RSA_WITH_AES_256_CBC_SHA, /* 0x0035 */
  293. "AES256-SHA",
  294. CIPHER_STRONG_ENOUGH),
  295. CIPHER_DEF(TLS_DH_DSS_WITH_AES_256_CBC_SHA, /* 0x0036 */
  296. "DH-DSS-AES256-SHA",
  297. CIPHER_STRONG_ENOUGH),
  298. CIPHER_DEF(TLS_DH_RSA_WITH_AES_256_CBC_SHA, /* 0x0037 */
  299. "DH-RSA-AES256-SHA",
  300. CIPHER_STRONG_ENOUGH),
  301. CIPHER_DEF(TLS_DHE_DSS_WITH_AES_256_CBC_SHA, /* 0x0038 */
  302. "DHE-DSS-AES256-SHA",
  303. CIPHER_STRONG_ENOUGH),
  304. CIPHER_DEF(TLS_DHE_RSA_WITH_AES_256_CBC_SHA, /* 0x0039 */
  305. "DHE-RSA-AES256-SHA",
  306. CIPHER_STRONG_ENOUGH),
  307. CIPHER_DEF(TLS_DH_anon_WITH_AES_256_CBC_SHA, /* 0x003A */
  308. "ADH-AES256-SHA",
  309. CIPHER_WEAK_ANON_AUTH),
  310. #if CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS
  311. /* TLS 1.2 addenda, RFC 5246 */
  312. /* Server provided RSA certificate for key exchange. */
  313. CIPHER_DEF(TLS_RSA_WITH_NULL_SHA256, /* 0x003B */
  314. "NULL-SHA256",
  315. CIPHER_WEAK_NOT_ENCRYPTED),
  316. CIPHER_DEF(TLS_RSA_WITH_AES_128_CBC_SHA256, /* 0x003C */
  317. "AES128-SHA256",
  318. CIPHER_STRONG_ENOUGH),
  319. CIPHER_DEF(TLS_RSA_WITH_AES_256_CBC_SHA256, /* 0x003D */
  320. "AES256-SHA256",
  321. CIPHER_STRONG_ENOUGH),
  322. /* Server-authenticated (and optionally client-authenticated)
  323. Diffie-Hellman. */
  324. CIPHER_DEF(TLS_DH_DSS_WITH_AES_128_CBC_SHA256, /* 0x003E */
  325. "DH-DSS-AES128-SHA256",
  326. CIPHER_STRONG_ENOUGH),
  327. CIPHER_DEF(TLS_DH_RSA_WITH_AES_128_CBC_SHA256, /* 0x003F */
  328. "DH-RSA-AES128-SHA256",
  329. CIPHER_STRONG_ENOUGH),
  330. CIPHER_DEF(TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, /* 0x0040 */
  331. "DHE-DSS-AES128-SHA256",
  332. CIPHER_STRONG_ENOUGH),
  333. /* TLS 1.2 addenda, RFC 5246 */
  334. CIPHER_DEF(TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, /* 0x0067 */
  335. "DHE-RSA-AES128-SHA256",
  336. CIPHER_STRONG_ENOUGH),
  337. CIPHER_DEF(TLS_DH_DSS_WITH_AES_256_CBC_SHA256, /* 0x0068 */
  338. "DH-DSS-AES256-SHA256",
  339. CIPHER_STRONG_ENOUGH),
  340. CIPHER_DEF(TLS_DH_RSA_WITH_AES_256_CBC_SHA256, /* 0x0069 */
  341. "DH-RSA-AES256-SHA256",
  342. CIPHER_STRONG_ENOUGH),
  343. CIPHER_DEF(TLS_DHE_DSS_WITH_AES_256_CBC_SHA256, /* 0x006A */
  344. "DHE-DSS-AES256-SHA256",
  345. CIPHER_STRONG_ENOUGH),
  346. CIPHER_DEF(TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, /* 0x006B */
  347. "DHE-RSA-AES256-SHA256",
  348. CIPHER_STRONG_ENOUGH),
  349. CIPHER_DEF(TLS_DH_anon_WITH_AES_128_CBC_SHA256, /* 0x006C */
  350. "ADH-AES128-SHA256",
  351. CIPHER_WEAK_ANON_AUTH),
  352. CIPHER_DEF(TLS_DH_anon_WITH_AES_256_CBC_SHA256, /* 0x006D */
  353. "ADH-AES256-SHA256",
  354. CIPHER_WEAK_ANON_AUTH),
  355. #endif /* CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS */
  356. #if CURL_BUILD_MAC_10_9 || CURL_BUILD_IOS_7
  357. /* Addendum from RFC 4279, TLS PSK */
  358. CIPHER_DEF(TLS_PSK_WITH_RC4_128_SHA, /* 0x008A */
  359. "PSK-RC4-SHA",
  360. CIPHER_WEAK_RC_ENCRYPTION),
  361. CIPHER_DEF(TLS_PSK_WITH_3DES_EDE_CBC_SHA, /* 0x008B */
  362. "PSK-3DES-EDE-CBC-SHA",
  363. CIPHER_WEAK_3DES_ENCRYPTION),
  364. CIPHER_DEF(TLS_PSK_WITH_AES_128_CBC_SHA, /* 0x008C */
  365. "PSK-AES128-CBC-SHA",
  366. CIPHER_STRONG_ENOUGH),
  367. CIPHER_DEF(TLS_PSK_WITH_AES_256_CBC_SHA, /* 0x008D */
  368. "PSK-AES256-CBC-SHA",
  369. CIPHER_STRONG_ENOUGH),
  370. CIPHER_DEF(TLS_DHE_PSK_WITH_RC4_128_SHA, /* 0x008E */
  371. "DHE-PSK-RC4-SHA",
  372. CIPHER_WEAK_RC_ENCRYPTION),
  373. CIPHER_DEF(TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA, /* 0x008F */
  374. "DHE-PSK-3DES-EDE-CBC-SHA",
  375. CIPHER_WEAK_3DES_ENCRYPTION),
  376. CIPHER_DEF(TLS_DHE_PSK_WITH_AES_128_CBC_SHA, /* 0x0090 */
  377. "DHE-PSK-AES128-CBC-SHA",
  378. CIPHER_STRONG_ENOUGH),
  379. CIPHER_DEF(TLS_DHE_PSK_WITH_AES_256_CBC_SHA, /* 0x0091 */
  380. "DHE-PSK-AES256-CBC-SHA",
  381. CIPHER_STRONG_ENOUGH),
  382. CIPHER_DEF(TLS_RSA_PSK_WITH_RC4_128_SHA, /* 0x0092 */
  383. "RSA-PSK-RC4-SHA",
  384. CIPHER_WEAK_RC_ENCRYPTION),
  385. CIPHER_DEF(TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA, /* 0x0093 */
  386. "RSA-PSK-3DES-EDE-CBC-SHA",
  387. CIPHER_WEAK_3DES_ENCRYPTION),
  388. CIPHER_DEF(TLS_RSA_PSK_WITH_AES_128_CBC_SHA, /* 0x0094 */
  389. "RSA-PSK-AES128-CBC-SHA",
  390. CIPHER_STRONG_ENOUGH),
  391. CIPHER_DEF(TLS_RSA_PSK_WITH_AES_256_CBC_SHA, /* 0x0095 */
  392. "RSA-PSK-AES256-CBC-SHA",
  393. CIPHER_STRONG_ENOUGH),
  394. #endif /* CURL_BUILD_MAC_10_9 || CURL_BUILD_IOS_7 */
  395. #if CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS
  396. /* Addenda from rfc 5288 AES Galois Counter Mode (GCM) Cipher Suites
  397. for TLS. */
  398. CIPHER_DEF(TLS_RSA_WITH_AES_128_GCM_SHA256, /* 0x009C */
  399. "AES128-GCM-SHA256",
  400. CIPHER_STRONG_ENOUGH),
  401. CIPHER_DEF(TLS_RSA_WITH_AES_256_GCM_SHA384, /* 0x009D */
  402. "AES256-GCM-SHA384",
  403. CIPHER_STRONG_ENOUGH),
  404. CIPHER_DEF(TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, /* 0x009E */
  405. "DHE-RSA-AES128-GCM-SHA256",
  406. CIPHER_STRONG_ENOUGH),
  407. CIPHER_DEF(TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, /* 0x009F */
  408. "DHE-RSA-AES256-GCM-SHA384",
  409. CIPHER_STRONG_ENOUGH),
  410. CIPHER_DEF(TLS_DH_RSA_WITH_AES_128_GCM_SHA256, /* 0x00A0 */
  411. "DH-RSA-AES128-GCM-SHA256",
  412. CIPHER_STRONG_ENOUGH),
  413. CIPHER_DEF(TLS_DH_RSA_WITH_AES_256_GCM_SHA384, /* 0x00A1 */
  414. "DH-RSA-AES256-GCM-SHA384",
  415. CIPHER_STRONG_ENOUGH),
  416. CIPHER_DEF(TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, /* 0x00A2 */
  417. "DHE-DSS-AES128-GCM-SHA256",
  418. CIPHER_STRONG_ENOUGH),
  419. CIPHER_DEF(TLS_DHE_DSS_WITH_AES_256_GCM_SHA384, /* 0x00A3 */
  420. "DHE-DSS-AES256-GCM-SHA384",
  421. CIPHER_STRONG_ENOUGH),
  422. CIPHER_DEF(TLS_DH_DSS_WITH_AES_128_GCM_SHA256, /* 0x00A4 */
  423. "DH-DSS-AES128-GCM-SHA256",
  424. CIPHER_STRONG_ENOUGH),
  425. CIPHER_DEF(TLS_DH_DSS_WITH_AES_256_GCM_SHA384, /* 0x00A5 */
  426. "DH-DSS-AES256-GCM-SHA384",
  427. CIPHER_STRONG_ENOUGH),
  428. CIPHER_DEF(TLS_DH_anon_WITH_AES_128_GCM_SHA256, /* 0x00A6 */
  429. "ADH-AES128-GCM-SHA256",
  430. CIPHER_WEAK_ANON_AUTH),
  431. CIPHER_DEF(TLS_DH_anon_WITH_AES_256_GCM_SHA384, /* 0x00A7 */
  432. "ADH-AES256-GCM-SHA384",
  433. CIPHER_WEAK_ANON_AUTH),
  434. #endif /* CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS */
  435. #if CURL_BUILD_MAC_10_9 || CURL_BUILD_IOS_7
  436. /* RFC 5487 - PSK with SHA-256/384 and AES GCM */
  437. CIPHER_DEF(TLS_PSK_WITH_AES_128_GCM_SHA256, /* 0x00A8 */
  438. "PSK-AES128-GCM-SHA256",
  439. CIPHER_STRONG_ENOUGH),
  440. CIPHER_DEF(TLS_PSK_WITH_AES_256_GCM_SHA384, /* 0x00A9 */
  441. "PSK-AES256-GCM-SHA384",
  442. CIPHER_STRONG_ENOUGH),
  443. CIPHER_DEF(TLS_DHE_PSK_WITH_AES_128_GCM_SHA256, /* 0x00AA */
  444. "DHE-PSK-AES128-GCM-SHA256",
  445. CIPHER_STRONG_ENOUGH),
  446. CIPHER_DEF(TLS_DHE_PSK_WITH_AES_256_GCM_SHA384, /* 0x00AB */
  447. "DHE-PSK-AES256-GCM-SHA384",
  448. CIPHER_STRONG_ENOUGH),
  449. CIPHER_DEF(TLS_RSA_PSK_WITH_AES_128_GCM_SHA256, /* 0x00AC */
  450. "RSA-PSK-AES128-GCM-SHA256",
  451. CIPHER_STRONG_ENOUGH),
  452. CIPHER_DEF(TLS_RSA_PSK_WITH_AES_256_GCM_SHA384, /* 0x00AD */
  453. "RSA-PSK-AES256-GCM-SHA384",
  454. CIPHER_STRONG_ENOUGH),
  455. CIPHER_DEF(TLS_PSK_WITH_AES_128_CBC_SHA256, /* 0x00AE */
  456. "PSK-AES128-CBC-SHA256",
  457. CIPHER_STRONG_ENOUGH),
  458. CIPHER_DEF(TLS_PSK_WITH_AES_256_CBC_SHA384, /* 0x00AF */
  459. "PSK-AES256-CBC-SHA384",
  460. CIPHER_STRONG_ENOUGH),
  461. CIPHER_DEF(TLS_PSK_WITH_NULL_SHA256, /* 0x00B0 */
  462. "PSK-NULL-SHA256",
  463. CIPHER_WEAK_NOT_ENCRYPTED),
  464. CIPHER_DEF(TLS_PSK_WITH_NULL_SHA384, /* 0x00B1 */
  465. "PSK-NULL-SHA384",
  466. CIPHER_WEAK_NOT_ENCRYPTED),
  467. CIPHER_DEF(TLS_DHE_PSK_WITH_AES_128_CBC_SHA256, /* 0x00B2 */
  468. "DHE-PSK-AES128-CBC-SHA256",
  469. CIPHER_STRONG_ENOUGH),
  470. CIPHER_DEF(TLS_DHE_PSK_WITH_AES_256_CBC_SHA384, /* 0x00B3 */
  471. "DHE-PSK-AES256-CBC-SHA384",
  472. CIPHER_STRONG_ENOUGH),
  473. CIPHER_DEF(TLS_DHE_PSK_WITH_NULL_SHA256, /* 0x00B4 */
  474. "DHE-PSK-NULL-SHA256",
  475. CIPHER_WEAK_NOT_ENCRYPTED),
  476. CIPHER_DEF(TLS_DHE_PSK_WITH_NULL_SHA384, /* 0x00B5 */
  477. "DHE-PSK-NULL-SHA384",
  478. CIPHER_WEAK_NOT_ENCRYPTED),
  479. CIPHER_DEF(TLS_RSA_PSK_WITH_AES_128_CBC_SHA256, /* 0x00B6 */
  480. "RSA-PSK-AES128-CBC-SHA256",
  481. CIPHER_STRONG_ENOUGH),
  482. CIPHER_DEF(TLS_RSA_PSK_WITH_AES_256_CBC_SHA384, /* 0x00B7 */
  483. "RSA-PSK-AES256-CBC-SHA384",
  484. CIPHER_STRONG_ENOUGH),
  485. CIPHER_DEF(TLS_RSA_PSK_WITH_NULL_SHA256, /* 0x00B8 */
  486. "RSA-PSK-NULL-SHA256",
  487. CIPHER_WEAK_NOT_ENCRYPTED),
  488. CIPHER_DEF(TLS_RSA_PSK_WITH_NULL_SHA384, /* 0x00B9 */
  489. "RSA-PSK-NULL-SHA384",
  490. CIPHER_WEAK_NOT_ENCRYPTED),
  491. #endif /* CURL_BUILD_MAC_10_9 || CURL_BUILD_IOS_7 */
  492. /* RFC 5746 - Secure Renegotiation. This is not a real suite,
  493. it is a response to initiate negotiation again */
  494. CIPHER_DEF(TLS_EMPTY_RENEGOTIATION_INFO_SCSV, /* 0x00FF */
  495. NULL,
  496. CIPHER_STRONG_ENOUGH),
  497. #if CURL_BUILD_MAC_10_13 || CURL_BUILD_IOS_11
  498. /* TLS 1.3 standard cipher suites for ChaCha20+Poly1305.
  499. Note: TLS 1.3 ciphersuites do not specify the key exchange
  500. algorithm -- they only specify the symmetric ciphers.
  501. Cipher alias name matches to OpenSSL cipher name, and for
  502. TLS 1.3 ciphers */
  503. CIPHER_DEF(TLS_AES_128_GCM_SHA256, /* 0x1301 */
  504. NULL, /* The OpenSSL cipher name matches to the IANA name */
  505. CIPHER_STRONG_ENOUGH),
  506. CIPHER_DEF(TLS_AES_256_GCM_SHA384, /* 0x1302 */
  507. NULL, /* The OpenSSL cipher name matches to the IANA name */
  508. CIPHER_STRONG_ENOUGH),
  509. CIPHER_DEF(TLS_CHACHA20_POLY1305_SHA256, /* 0x1303 */
  510. NULL, /* The OpenSSL cipher name matches to the IANA name */
  511. CIPHER_STRONG_ENOUGH),
  512. CIPHER_DEF(TLS_AES_128_CCM_SHA256, /* 0x1304 */
  513. NULL, /* The OpenSSL cipher name matches to the IANA name */
  514. CIPHER_STRONG_ENOUGH),
  515. CIPHER_DEF(TLS_AES_128_CCM_8_SHA256, /* 0x1305 */
  516. NULL, /* The OpenSSL cipher name matches to the IANA name */
  517. CIPHER_STRONG_ENOUGH),
  518. #endif /* CURL_BUILD_MAC_10_13 || CURL_BUILD_IOS_11 */
  519. #if CURL_BUILD_MAC_10_6 || CURL_BUILD_IOS
  520. /* ECDSA addenda, RFC 4492 */
  521. CIPHER_DEF(TLS_ECDH_ECDSA_WITH_NULL_SHA, /* 0xC001 */
  522. "ECDH-ECDSA-NULL-SHA",
  523. CIPHER_WEAK_NOT_ENCRYPTED),
  524. CIPHER_DEF(TLS_ECDH_ECDSA_WITH_RC4_128_SHA, /* 0xC002 */
  525. "ECDH-ECDSA-RC4-SHA",
  526. CIPHER_WEAK_RC_ENCRYPTION),
  527. CIPHER_DEF(TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, /* 0xC003 */
  528. "ECDH-ECDSA-DES-CBC3-SHA",
  529. CIPHER_STRONG_ENOUGH),
  530. CIPHER_DEF(TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, /* 0xC004 */
  531. "ECDH-ECDSA-AES128-SHA",
  532. CIPHER_STRONG_ENOUGH),
  533. CIPHER_DEF(TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, /* 0xC005 */
  534. "ECDH-ECDSA-AES256-SHA",
  535. CIPHER_STRONG_ENOUGH),
  536. CIPHER_DEF(TLS_ECDHE_ECDSA_WITH_NULL_SHA, /* 0xC006 */
  537. "ECDHE-ECDSA-NULL-SHA",
  538. CIPHER_WEAK_NOT_ENCRYPTED),
  539. CIPHER_DEF(TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, /* 0xC007 */
  540. "ECDHE-ECDSA-RC4-SHA",
  541. CIPHER_WEAK_RC_ENCRYPTION),
  542. CIPHER_DEF(TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, /* 0xC008 */
  543. "ECDHE-ECDSA-DES-CBC3-SHA",
  544. CIPHER_WEAK_3DES_ENCRYPTION),
  545. CIPHER_DEF(TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, /* 0xC009 */
  546. "ECDHE-ECDSA-AES128-SHA",
  547. CIPHER_STRONG_ENOUGH),
  548. CIPHER_DEF(TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, /* 0xC00A */
  549. "ECDHE-ECDSA-AES256-SHA",
  550. CIPHER_STRONG_ENOUGH),
  551. CIPHER_DEF(TLS_ECDH_RSA_WITH_NULL_SHA, /* 0xC00B */
  552. "ECDH-RSA-NULL-SHA",
  553. CIPHER_WEAK_NOT_ENCRYPTED),
  554. CIPHER_DEF(TLS_ECDH_RSA_WITH_RC4_128_SHA, /* 0xC00C */
  555. "ECDH-RSA-RC4-SHA",
  556. CIPHER_WEAK_RC_ENCRYPTION),
  557. CIPHER_DEF(TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, /* 0xC00D */
  558. "ECDH-RSA-DES-CBC3-SHA",
  559. CIPHER_WEAK_3DES_ENCRYPTION),
  560. CIPHER_DEF(TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, /* 0xC00E */
  561. "ECDH-RSA-AES128-SHA",
  562. CIPHER_STRONG_ENOUGH),
  563. CIPHER_DEF(TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, /* 0xC00F */
  564. "ECDH-RSA-AES256-SHA",
  565. CIPHER_STRONG_ENOUGH),
  566. CIPHER_DEF(TLS_ECDHE_RSA_WITH_NULL_SHA, /* 0xC010 */
  567. "ECDHE-RSA-NULL-SHA",
  568. CIPHER_WEAK_NOT_ENCRYPTED),
  569. CIPHER_DEF(TLS_ECDHE_RSA_WITH_RC4_128_SHA, /* 0xC011 */
  570. "ECDHE-RSA-RC4-SHA",
  571. CIPHER_WEAK_RC_ENCRYPTION),
  572. CIPHER_DEF(TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, /* 0xC012 */
  573. "ECDHE-RSA-DES-CBC3-SHA",
  574. CIPHER_WEAK_3DES_ENCRYPTION),
  575. CIPHER_DEF(TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, /* 0xC013 */
  576. "ECDHE-RSA-AES128-SHA",
  577. CIPHER_STRONG_ENOUGH),
  578. CIPHER_DEF(TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, /* 0xC014 */
  579. "ECDHE-RSA-AES256-SHA",
  580. CIPHER_STRONG_ENOUGH),
  581. CIPHER_DEF(TLS_ECDH_anon_WITH_NULL_SHA, /* 0xC015 */
  582. "AECDH-NULL-SHA",
  583. CIPHER_WEAK_ANON_AUTH),
  584. CIPHER_DEF(TLS_ECDH_anon_WITH_RC4_128_SHA, /* 0xC016 */
  585. "AECDH-RC4-SHA",
  586. CIPHER_WEAK_ANON_AUTH),
  587. CIPHER_DEF(TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA, /* 0xC017 */
  588. "AECDH-DES-CBC3-SHA",
  589. CIPHER_WEAK_3DES_ENCRYPTION),
  590. CIPHER_DEF(TLS_ECDH_anon_WITH_AES_128_CBC_SHA, /* 0xC018 */
  591. "AECDH-AES128-SHA",
  592. CIPHER_WEAK_ANON_AUTH),
  593. CIPHER_DEF(TLS_ECDH_anon_WITH_AES_256_CBC_SHA, /* 0xC019 */
  594. "AECDH-AES256-SHA",
  595. CIPHER_WEAK_ANON_AUTH),
  596. #endif /* CURL_BUILD_MAC_10_6 || CURL_BUILD_IOS */
  597. #if CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS
  598. /* Addenda from rfc 5289 Elliptic Curve Cipher Suites with
  599. HMAC SHA-256/384. */
  600. CIPHER_DEF(TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, /* 0xC023 */
  601. "ECDHE-ECDSA-AES128-SHA256",
  602. CIPHER_STRONG_ENOUGH),
  603. CIPHER_DEF(TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, /* 0xC024 */
  604. "ECDHE-ECDSA-AES256-SHA384",
  605. CIPHER_STRONG_ENOUGH),
  606. CIPHER_DEF(TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, /* 0xC025 */
  607. "ECDH-ECDSA-AES128-SHA256",
  608. CIPHER_STRONG_ENOUGH),
  609. CIPHER_DEF(TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, /* 0xC026 */
  610. "ECDH-ECDSA-AES256-SHA384",
  611. CIPHER_STRONG_ENOUGH),
  612. CIPHER_DEF(TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, /* 0xC027 */
  613. "ECDHE-RSA-AES128-SHA256",
  614. CIPHER_STRONG_ENOUGH),
  615. CIPHER_DEF(TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, /* 0xC028 */
  616. "ECDHE-RSA-AES256-SHA384",
  617. CIPHER_STRONG_ENOUGH),
  618. CIPHER_DEF(TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, /* 0xC029 */
  619. "ECDH-RSA-AES128-SHA256",
  620. CIPHER_STRONG_ENOUGH),
  621. CIPHER_DEF(TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, /* 0xC02A */
  622. "ECDH-RSA-AES256-SHA384",
  623. CIPHER_STRONG_ENOUGH),
  624. /* Addenda from rfc 5289 Elliptic Curve Cipher Suites with
  625. SHA-256/384 and AES Galois Counter Mode (GCM) */
  626. CIPHER_DEF(TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, /* 0xC02B */
  627. "ECDHE-ECDSA-AES128-GCM-SHA256",
  628. CIPHER_STRONG_ENOUGH),
  629. CIPHER_DEF(TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, /* 0xC02C */
  630. "ECDHE-ECDSA-AES256-GCM-SHA384",
  631. CIPHER_STRONG_ENOUGH),
  632. CIPHER_DEF(TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, /* 0xC02D */
  633. "ECDH-ECDSA-AES128-GCM-SHA256",
  634. CIPHER_STRONG_ENOUGH),
  635. CIPHER_DEF(TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, /* 0xC02E */
  636. "ECDH-ECDSA-AES256-GCM-SHA384",
  637. CIPHER_STRONG_ENOUGH),
  638. CIPHER_DEF(TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, /* 0xC02F */
  639. "ECDHE-RSA-AES128-GCM-SHA256",
  640. CIPHER_STRONG_ENOUGH),
  641. CIPHER_DEF(TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, /* 0xC030 */
  642. "ECDHE-RSA-AES256-GCM-SHA384",
  643. CIPHER_STRONG_ENOUGH),
  644. CIPHER_DEF(TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, /* 0xC031 */
  645. "ECDH-RSA-AES128-GCM-SHA256",
  646. CIPHER_STRONG_ENOUGH),
  647. CIPHER_DEF(TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, /* 0xC032 */
  648. "ECDH-RSA-AES256-GCM-SHA384",
  649. CIPHER_STRONG_ENOUGH),
  650. #endif /* CURL_BUILD_MAC_10_8 || CURL_BUILD_IOS */
  651. #if CURL_BUILD_MAC_10_15 || CURL_BUILD_IOS_13
  652. /* ECDHE_PSK Cipher Suites for Transport Layer Security (TLS), RFC 5489 */
  653. CIPHER_DEF(TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA, /* 0xC035 */
  654. "ECDHE-PSK-AES128-CBC-SHA",
  655. CIPHER_STRONG_ENOUGH),
  656. CIPHER_DEF(TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA, /* 0xC036 */
  657. "ECDHE-PSK-AES256-CBC-SHA",
  658. CIPHER_STRONG_ENOUGH),
  659. #endif /* CURL_BUILD_MAC_10_15 || CURL_BUILD_IOS_13 */
  660. #if CURL_BUILD_MAC_10_13 || CURL_BUILD_IOS_11
  661. /* Addenda from rfc 7905 ChaCha20-Poly1305 Cipher Suites for
  662. Transport Layer Security (TLS). */
  663. CIPHER_DEF(TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, /* 0xCCA8 */
  664. "ECDHE-RSA-CHACHA20-POLY1305",
  665. CIPHER_STRONG_ENOUGH),
  666. CIPHER_DEF(TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, /* 0xCCA9 */
  667. "ECDHE-ECDSA-CHACHA20-POLY1305",
  668. CIPHER_STRONG_ENOUGH),
  669. #endif /* CURL_BUILD_MAC_10_13 || CURL_BUILD_IOS_11 */
  670. #if CURL_BUILD_MAC_10_15 || CURL_BUILD_IOS_13
  671. /* ChaCha20-Poly1305 Cipher Suites for Transport Layer Security (TLS),
  672. RFC 7905 */
  673. CIPHER_DEF(TLS_PSK_WITH_CHACHA20_POLY1305_SHA256, /* 0xCCAB */
  674. "PSK-CHACHA20-POLY1305",
  675. CIPHER_STRONG_ENOUGH),
  676. #endif /* CURL_BUILD_MAC_10_15 || CURL_BUILD_IOS_13 */
  677. /* Tags for SSL 2 cipher kinds which are not specified for SSL 3.
  678. Defined since SDK 10.2.8 */
  679. CIPHER_DEF(SSL_RSA_WITH_RC2_CBC_MD5, /* 0xFF80 */
  680. NULL,
  681. CIPHER_WEAK_RC_ENCRYPTION),
  682. CIPHER_DEF(SSL_RSA_WITH_IDEA_CBC_MD5, /* 0xFF81 */
  683. NULL,
  684. CIPHER_WEAK_IDEA_ENCRYPTION),
  685. CIPHER_DEF(SSL_RSA_WITH_DES_CBC_MD5, /* 0xFF82 */
  686. NULL,
  687. CIPHER_WEAK_DES_ENCRYPTION),
  688. CIPHER_DEF(SSL_RSA_WITH_3DES_EDE_CBC_MD5, /* 0xFF83 */
  689. NULL,
  690. CIPHER_WEAK_3DES_ENCRYPTION),
  691. };
  692. #define NUM_OF_CIPHERS sizeof(ciphertable)/sizeof(ciphertable[0])
  693. static const char* SSLCipherSuiteToString(SSLCipherSuite cipher)
  694. {
  695. /* The first ciphers in the ciphertable are continuos. Here we do small
  696. optimization and instead of loop directly get SSL name by cipher number.
  697. */
  698. if(cipher <= SSL_FORTEZZA_DMS_WITH_FORTEZZA_CBC_SHA) {
  699. return ciphertable[cipher].name;
  700. }
  701. /* Iterate through the rest of the ciphers */
  702. for(size_t i = SSL_FORTEZZA_DMS_WITH_FORTEZZA_CBC_SHA + 1;
  703. i < NUM_OF_CIPHERS;
  704. ++i) {
  705. if(ciphertable[i].num == cipher) {
  706. return ciphertable[i].name;
  707. }
  708. }
  709. return ciphertable[SSL_NULL_WITH_NULL_NULL].name;
  710. }
  711. static bool is_cipher_suite_strong(SSLCipherSuite suite_num)
  712. {
  713. for(size_t i = 0; i < NUM_OF_CIPHERS; ++i) {
  714. if(ciphertable[i].num == suite_num) {
  715. return !ciphertable[i].weak;
  716. }
  717. }
  718. /* If the cipher is not in our list, assume it is a new one
  719. and therefore strong. Previous implementation was the same,
  720. if cipher suite is not in the list, it was considered strong enough */
  721. return true;
  722. }
  723. const char* hssl_backend() {
  724. return "appletls";
  725. }
  726. typedef struct appletls_ctx {
  727. SecIdentityRef cert;
  728. hssl_ctx_init_param_t* param;
  729. } appletls_ctx_t;
  730. hssl_ctx_t hssl_ctx_init(hssl_ctx_init_param_t* param) {
  731. appletls_ctx_t* ctx = (appletls_ctx_t*)malloc(sizeof(appletls_ctx_t));
  732. if (ctx == NULL) return NULL;
  733. ctx->cert = NULL;
  734. ctx->param = param;
  735. g_ssl_ctx = ctx;
  736. return ctx;
  737. }
  738. void hssl_ctx_cleanup(hssl_ctx_t ssl_ctx) {
  739. if (ssl_ctx == NULL) return;
  740. appletls_ctx_t* ctx = (appletls_ctx_t*)ssl_ctx;
  741. if (ctx->cert) {
  742. CFRelease(ctx->cert);
  743. ctx->cert = NULL;
  744. }
  745. free(ctx);
  746. }
  747. typedef struct appletls_s {
  748. SSLContextRef session;
  749. appletls_ctx_t* ctx;
  750. int fd;
  751. } appletls_t;
  752. hssl_t hssl_new(hssl_ctx_t ssl_ctx, int fd) {
  753. if (ssl_ctx == NULL) return NULL;
  754. appletls_t* appletls = (appletls_t*)malloc(sizeof(appletls_t));
  755. if (appletls == NULL) return NULL;
  756. appletls->session = NULL;
  757. appletls->ctx = (appletls_ctx_t*)ssl_ctx;
  758. appletls->fd = fd;
  759. return (hssl_t)appletls;
  760. }
  761. static OSStatus SocketRead(SSLConnectionRef conn, void* data, size_t* len) {
  762. // printf("SocketRead(%d)\n", (int)*len);
  763. appletls_t* appletls = (appletls_t*)conn;
  764. uint8_t* buffer = (uint8_t*)data;
  765. size_t remain = *len;
  766. *len = 0;
  767. int fd = appletls->fd;
  768. // int timeout = 1000;
  769. // struct timeval tv = { timeout / 1000, (timeout % 1000) * 1000 };
  770. // fd_set readfds;
  771. while (remain) {
  772. /*
  773. FD_ZERO(&readfds);
  774. FD_SET(fd, &readfds);
  775. int nselect = select(fd + 1, &readfds, 0, 0, &tv);
  776. printf("nselect=%d\n", nselect);
  777. if (nselect < 0) {
  778. return errSSLClosedAbort;
  779. }
  780. if (nselect == 0) {
  781. return errSSLWouldBlock;
  782. }
  783. */
  784. // printf("read(%d)\n", (int)remain);
  785. // NOTE: avoid blocking
  786. if (remain < 16) {
  787. so_rcvtimeo(fd, 1000);
  788. }
  789. ssize_t nread = read(fd, buffer, remain);
  790. // printf("nread=%d errno=%d\n", (int)nread, (int)errno);
  791. if (nread == 0) return errSSLClosedGraceful;
  792. if (nread < 0) {
  793. switch (errno) {
  794. case ENOENT: return errSSLClosedGraceful;
  795. case ECONNRESET:return errSSLClosedAbort;
  796. case EAGAIN: return errSSLWouldBlock;
  797. default: return errSSLClosedAbort;
  798. }
  799. }
  800. *len += nread;
  801. remain -= nread;
  802. buffer += nread;
  803. }
  804. return noErr;
  805. }
  806. static OSStatus SocketWrite(SSLConnectionRef conn, const void* data, size_t* len) {
  807. // printf("SocketWrite(%d)\n", (int)*len);
  808. appletls_t* appletls = (appletls_t*)conn;
  809. uint8_t* buffer = (uint8_t*)data;
  810. size_t remain = *len;
  811. *len = 0;
  812. int fd = appletls->fd;
  813. while (remain) {
  814. if (remain < 16) {
  815. so_sndtimeo(fd, 1000);
  816. }
  817. // printf("write(%d)\n", (int)remain);
  818. ssize_t nwrite = write(fd, buffer, remain);
  819. // printf("nwrite=%d errno=%d\n", (int)nwrite, (int)errno);
  820. if (nwrite <= 0) {
  821. switch (errno) {
  822. case EAGAIN: return errSSLWouldBlock;
  823. default: return errSSLClosedAbort;
  824. }
  825. }
  826. remain -= nwrite;
  827. buffer += nwrite;
  828. *len += nwrite;
  829. }
  830. return noErr;
  831. }
  832. static int hssl_init(hssl_t ssl, int endpoint) {
  833. if (ssl == NULL) return HSSL_ERROR;
  834. appletls_t* appletls = (appletls_t*)ssl;
  835. OSStatus ret = noErr;
  836. if (appletls->session == NULL) {
  837. #if defined(__MAC_10_8)
  838. appletls->session = SSLCreateContext(NULL, endpoint == HSSL_SERVER ? kSSLServerSide : kSSLClientSide, kSSLStreamType);
  839. #else
  840. SSLNewContext(endpoint == HSSL_SERVER, &(appletls->session));
  841. #endif
  842. }
  843. if (appletls->session == NULL) {
  844. fprintf(stderr, "SSLCreateContext failed!\n");
  845. return HSSL_ERROR;
  846. }
  847. ret = SSLSetProtocolVersionEnabled(appletls->session, kSSLProtocolAll, true);
  848. if (ret != noErr) {
  849. fprintf(stderr, "SSLSetProtocolVersionEnabled failed!\n");
  850. return HSSL_ERROR;
  851. }
  852. bool verify_peer = false;
  853. if (appletls->ctx->param && appletls->ctx->param->verify_peer) {
  854. verify_peer = true;
  855. }
  856. #if defined(__MAC_10_8)
  857. ret = SSLSetSessionOption(appletls->session, kSSLSessionOptionBreakOnServerAuth, !verify_peer);
  858. #else
  859. ret = SSLSetEnableCertVerify(appletls->session, verify_peer);
  860. #endif
  861. if (ret != noErr) {
  862. fprintf(stderr, "SSLSetEnableCertVerify failed!\n");
  863. return HSSL_ERROR;
  864. }
  865. if (appletls->ctx->cert) {
  866. CFArrayRef certs = CFArrayCreate(NULL, (const void**)&appletls->ctx->cert, 1, NULL);
  867. if (!certs) {
  868. fprintf(stderr, "CFArrayCreate failed!\n");
  869. return HSSL_ERROR;
  870. }
  871. ret = SSLSetCertificate(appletls->session, certs);
  872. CFRelease(certs);
  873. if (ret != noErr) {
  874. fprintf(stderr, "SSLSetCertificate failed!\n");
  875. return HSSL_ERROR;
  876. }
  877. }
  878. size_t all_ciphers_count = 0, allowed_ciphers_count = 0;
  879. SSLCipherSuite *all_ciphers = NULL, *allowed_ciphers = NULL;
  880. ret = SSLGetNumberSupportedCiphers(appletls->session, &all_ciphers_count);
  881. if (ret != noErr) {
  882. fprintf(stderr, "SSLGetNumberSupportedCiphers failed!\n");
  883. goto error;
  884. }
  885. all_ciphers = (SSLCipherSuite*)malloc(all_ciphers_count * sizeof(SSLCipherSuite));
  886. allowed_ciphers = (SSLCipherSuite*)malloc(all_ciphers_count * sizeof(SSLCipherSuite));
  887. if (all_ciphers == NULL || allowed_ciphers == NULL) {
  888. fprintf(stderr, "malloc failed!\n");
  889. goto error;
  890. }
  891. ret = SSLGetSupportedCiphers(appletls->session, all_ciphers, &all_ciphers_count);
  892. if (ret != noErr) {
  893. fprintf(stderr, "SSLGetSupportedCiphers failed!\n");
  894. goto error;
  895. }
  896. for (size_t i = 0; i < all_ciphers_count; ++i) {
  897. if (is_cipher_suite_strong(all_ciphers[i])) {
  898. allowed_ciphers[allowed_ciphers_count++] = all_ciphers[i];
  899. }
  900. }
  901. ret = SSLSetEnabledCiphers(appletls->session, allowed_ciphers, allowed_ciphers_count);
  902. if (ret != noErr) {
  903. fprintf(stderr, "SSLSetEnabledCiphers failed!\n");
  904. goto error;
  905. }
  906. if (all_ciphers) {
  907. free(all_ciphers);
  908. all_ciphers = NULL;
  909. }
  910. if (allowed_ciphers) {
  911. free(allowed_ciphers);
  912. allowed_ciphers = NULL;
  913. }
  914. ret = SSLSetIOFuncs(appletls->session, SocketRead, SocketWrite);
  915. if (ret != noErr) {
  916. fprintf(stderr, "SSLSetIOFuncs failed!\n");
  917. return HSSL_ERROR;
  918. }
  919. ret = SSLSetConnection(appletls->session, appletls);
  920. if (ret != noErr) {
  921. fprintf(stderr, "SSLSetConnection failed!\n");
  922. return HSSL_ERROR;
  923. }
  924. /*
  925. char session_id[64] = {0};
  926. int session_id_len = snprintf(session_id, sizeof(session_id), "libhv:appletls:%p", appletls->session);
  927. ret = SSLSetPeerID(appletls->session, session_id, session_id_len);
  928. if (ret != noErr) {
  929. fprintf(stderr, "SSLSetPeerID failed!\n");
  930. return HSSL_ERROR;
  931. }
  932. */
  933. return HSSL_OK;
  934. error:
  935. if (all_ciphers) {
  936. free(all_ciphers);
  937. }
  938. if (allowed_ciphers) {
  939. free(allowed_ciphers);
  940. }
  941. return HSSL_ERROR;
  942. }
  943. void hssl_free(hssl_t ssl) {
  944. if (ssl == NULL) return;
  945. appletls_t* appletls = (appletls_t*)ssl;
  946. if (appletls->session) {
  947. #if defined(__MAC_10_8)
  948. CFRelease(appletls->session);
  949. #else
  950. SSLDisposeContext(appletls->session);
  951. #endif
  952. appletls->session = NULL;
  953. }
  954. free(appletls);
  955. }
  956. static int hssl_handshake(hssl_t ssl) {
  957. if (ssl == NULL) return HSSL_ERROR;
  958. appletls_t* appletls = (appletls_t*)ssl;
  959. OSStatus ret = SSLHandshake(appletls->session);
  960. // printf("SSLHandshake retval=%d\n", (int)ret);
  961. switch(ret) {
  962. case noErr:
  963. break;
  964. case errSSLWouldBlock:
  965. return HSSL_WANT_READ;
  966. case errSSLPeerAuthCompleted: /* peer cert is valid, or was ignored if verification disabled */
  967. return hssl_handshake(ssl);
  968. case errSSLBadConfiguration:
  969. return HSSL_WANT_READ;
  970. default:
  971. return HSSL_ERROR;
  972. }
  973. /*
  974. SSLProtocol protocol = kSSLProtocolUnknown;
  975. SSLGetNegotiatedProtocolVersion(appletls->session, &protocol);
  976. SSLCipherSuite cipher = SSL_NO_SUCH_CIPHERSUITE;
  977. SSLGetNegotiatedCipher(appletls->session, &cipher);
  978. printf("* %s connection using %s\n", SSLProtocolToString(protocol), SSLCipherSuiteToString(cipher));
  979. */
  980. return HSSL_OK;
  981. }
  982. int hssl_accept(hssl_t ssl) {
  983. if (ssl == NULL) return HSSL_ERROR;
  984. appletls_t* appletls = (appletls_t*)ssl;
  985. if (appletls->session == NULL) {
  986. hssl_init(ssl, HSSL_SERVER);
  987. }
  988. return hssl_handshake(ssl);
  989. }
  990. int hssl_connect(hssl_t ssl) {
  991. if (ssl == NULL) return HSSL_ERROR;
  992. appletls_t* appletls = (appletls_t*)ssl;
  993. if (appletls->session == NULL) {
  994. hssl_init(ssl, HSSL_CLIENT);
  995. }
  996. return hssl_handshake(ssl);
  997. }
  998. int hssl_read(hssl_t ssl, void* buf, int len) {
  999. if (ssl == NULL) return HSSL_ERROR;
  1000. appletls_t* appletls = (appletls_t*)ssl;
  1001. size_t processed = 0;
  1002. // printf("SSLRead(%d)\n", len);
  1003. OSStatus ret = SSLRead(appletls->session, buf, len, &processed);
  1004. // printf("SSLRead retval=%d processed=%d\n", (int)ret, (int)processed);
  1005. switch (ret) {
  1006. case noErr:
  1007. return processed;
  1008. case errSSLWouldBlock:
  1009. return processed ? processed : HSSL_WOULD_BLOCK;
  1010. case errSSLClosedGraceful:
  1011. case errSSLClosedNoNotify:
  1012. return 0;
  1013. default:
  1014. return HSSL_ERROR;
  1015. }
  1016. }
  1017. int hssl_write(hssl_t ssl, const void* buf, int len) {
  1018. if (ssl == NULL) return HSSL_ERROR;
  1019. appletls_t* appletls = (appletls_t*)ssl;
  1020. size_t processed = 0;
  1021. // printf("SSLWrite(%d)\n", len);
  1022. OSStatus ret = SSLWrite(appletls->session, buf, len, &processed);
  1023. // printf("SSLWrite retval=%d processed=%d\n", (int)ret, (int)processed);
  1024. switch (ret) {
  1025. case noErr:
  1026. return processed;
  1027. case errSSLWouldBlock:
  1028. return processed ? processed : HSSL_WOULD_BLOCK;
  1029. case errSSLClosedGraceful:
  1030. case errSSLClosedNoNotify:
  1031. return 0;
  1032. default:
  1033. return HSSL_ERROR;
  1034. }
  1035. }
  1036. int hssl_close(hssl_t ssl) {
  1037. if (ssl == NULL) return HSSL_ERROR;
  1038. appletls_t* appletls = (appletls_t*)ssl;
  1039. SSLClose(appletls->session);
  1040. return 0;
  1041. }
  1042. int hssl_set_sni_hostname(hssl_t ssl, const char* hostname) {
  1043. if (ssl == NULL) return HSSL_ERROR;
  1044. appletls_t* appletls = (appletls_t*)ssl;
  1045. if (appletls->session == NULL) {
  1046. hssl_init(ssl, HSSL_CLIENT);
  1047. }
  1048. SSLSetPeerDomainName(appletls->session, hostname, strlen(hostname));
  1049. return 0;
  1050. }
  1051. #endif // WITH_APPLETLS