ql_ssl.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. /*================================================================
  2. Copyright (c) 2021, Quectel Wireless Solutions Co., Ltd. All rights reserved.
  3. Quectel Wireless Solutions Proprietary and Confidential.
  4. =================================================================*/
  5. #ifndef QL_SSL_H
  6. #define QL_SSL_H
  7. #if 1//defined(CONFIG_QUEC_PROJECT_FEATURE_SSL)
  8. #define QL_MAX_CA_CERT_CNT 10
  9. #define QUEC_MAX_CA_CERTEX_INDEX_NUM 6
  10. #define QUEC_SSL_CA_CERTEX_INDEX_MIN 0
  11. #define QUEC_SSL_CA_CERTEX_INDEX_MAX (QUEC_MAX_CA_CERTEX_INDEX_NUM - 1)
  12. #define QL_SSL_NEGOTIATE_TIME_DEF 300
  13. #define QL_SSL_TLS_RSA_WITH_NULL_MD5 0x0001 /**< Weak! */
  14. #define QL_SSL_TLS_RSA_WITH_NULL_SHA 0x0002 /**< Weak! */
  15. #define QL_SSL_TLS_RSA_WITH_RC4_128_MD5 0x0004
  16. #define QL_SSL_TLS_RSA_WITH_RC4_128_SHA 0x0005
  17. #define QL_SSL_TLS_RSA_WITH_DES_CBC_SHA 0x0009 /**< Weak! Not in TLS 1.2 */
  18. #define QL_SSL_TLS_RSA_WITH_3DES_EDE_CBC_SHA 0x000A
  19. #define QL_SSL_TLS_DHE_RSA_WITH_DES_CBC_SHA 0x0015 /**< Weak! Not in TLS 1.2 */
  20. #define QL_SSL_TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA 0x0016
  21. #define QL_SSL_TLS_PSK_WITH_NULL_SHA 0x002C /**< Weak! */
  22. #define QL_SSL_TLS_DHE_PSK_WITH_NULL_SHA 0x002D /**< Weak! */
  23. #define QL_SSL_TLS_RSA_PSK_WITH_NULL_SHA 0x002E /**< Weak! */
  24. #define QL_SSL_TLS_RSA_WITH_AES_128_CBC_SHA 0x002F
  25. #define QL_SSL_TLS_DHE_RSA_WITH_AES_128_CBC_SHA 0x0033
  26. #define QL_SSL_TLS_RSA_WITH_AES_256_CBC_SHA 0x0035
  27. #define QL_SSL_TLS_DHE_RSA_WITH_AES_256_CBC_SHA 0x0039
  28. #define QL_SSL_TLS_RSA_WITH_NULL_SHA256 0x003B /**< Weak! */
  29. #define QL_SSL_TLS_RSA_WITH_AES_128_CBC_SHA256 0x003C /**< TLS 1.2 */
  30. #define QL_SSL_TLS_RSA_WITH_AES_256_CBC_SHA256 0x003D /**< TLS 1.2 */
  31. #define QL_SSL_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA 0x0041
  32. #define QL_SSL_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA 0x0045
  33. #define QL_SSL_TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 0x0067 /**< TLS 1.2 */
  34. #define QL_SSL_TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 0x006B /**< TLS 1.2 */
  35. #define QL_SSL_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA 0x0084
  36. #define QL_SSL_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA 0x0088
  37. #define QL_SSL_TLS_PSK_WITH_RC4_128_SHA 0x008A
  38. #define QL_SSL_TLS_PSK_WITH_3DES_EDE_CBC_SHA 0x008B
  39. #define QL_SSL_TLS_PSK_WITH_AES_128_CBC_SHA 0x008C
  40. #define QL_SSL_TLS_PSK_WITH_AES_256_CBC_SHA 0x008D
  41. #define QL_SSL_TLS_DHE_PSK_WITH_RC4_128_SHA 0x008E
  42. #define QL_SSL_TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA 0x008F
  43. #define QL_SSL_TLS_DHE_PSK_WITH_AES_128_CBC_SHA 0x0090
  44. #define QL_SSL_TLS_DHE_PSK_WITH_AES_256_CBC_SHA 0x0091
  45. #define QL_SSL_TLS_RSA_PSK_WITH_RC4_128_SHA 0x0092
  46. #define QL_SSL_TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA 0x0093
  47. #define QL_SSL_TLS_RSA_PSK_WITH_AES_128_CBC_SHA 0x0094
  48. #define QL_SSL_TLS_RSA_PSK_WITH_AES_256_CBC_SHA 0x0095
  49. #define QL_SSL_TLS_RSA_WITH_AES_128_GCM_SHA256 0x009C /**< TLS 1.2 */
  50. #define QL_SSL_TLS_RSA_WITH_AES_256_GCM_SHA384 0x009D /**< TLS 1.2 */
  51. #define QL_SSL_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 0x009E /**< TLS 1.2 */
  52. #define QL_SSL_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 0x009F /**< TLS 1.2 */
  53. #define QL_SSL_TLS_PSK_WITH_AES_128_GCM_SHA256 0x00A8 /**< TLS 1.2 */
  54. #define QL_SSL_TLS_PSK_WITH_AES_256_GCM_SHA384 0x00A9 /**< TLS 1.2 */
  55. #define QL_SSL_TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 0x00AA /**< TLS 1.2 */
  56. #define QL_SSL_TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 0x00AB /**< TLS 1.2 */
  57. #define QL_SSL_TLS_RSA_PSK_WITH_AES_128_GCM_SHA256 0x00AC /**< TLS 1.2 */
  58. #define QL_SSL_TLS_RSA_PSK_WITH_AES_256_GCM_SHA384 0x00AD /**< TLS 1.2 */
  59. #define QL_SSL_TLS_PSK_WITH_AES_128_CBC_SHA256 0x00AE
  60. #define QL_SSL_TLS_PSK_WITH_AES_256_CBC_SHA384 0x00AF
  61. #define QL_SSL_TLS_PSK_WITH_NULL_SHA256 0x00B0 /**< Weak! */
  62. #define QL_SSL_TLS_PSK_WITH_NULL_SHA384 0x00B1 /**< Weak! */
  63. #define QL_SSL_TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 0x00B2
  64. #define QL_SSL_TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 0x00B3
  65. #define QL_SSL_TLS_DHE_PSK_WITH_NULL_SHA256 0x00B4 /**< Weak! */
  66. #define QL_SSL_TLS_DHE_PSK_WITH_NULL_SHA384 0x00B5 /**< Weak! */
  67. #define QL_SSL_TLS_RSA_PSK_WITH_AES_128_CBC_SHA256 0x00B6
  68. #define QL_SSL_TLS_RSA_PSK_WITH_AES_256_CBC_SHA384 0x00B7
  69. #define QL_SSL_TLS_RSA_PSK_WITH_NULL_SHA256 0x00B8 /**< Weak! */
  70. #define QL_SSL_TLS_RSA_PSK_WITH_NULL_SHA384 0x00B9 /**< Weak! */
  71. #define QL_SSL_TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 0x00BA /**< TLS 1.2 */
  72. #define QL_SSL_TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 0x00BE /**< TLS 1.2 */
  73. #define QL_SSL_TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 0x00C0 /**< TLS 1.2 */
  74. #define QL_SSL_TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 0x00C4 /**< TLS 1.2 */
  75. #define QL_SSL_TLS_ECDH_ECDSA_WITH_NULL_SHA 0xC001 /**< Weak! */
  76. #define QL_SSL_TLS_ECDH_ECDSA_WITH_RC4_128_SHA 0xC002 /**< Not in SSL3! */
  77. #define QL_SSL_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA 0xC003 /**< Not in SSL3! */
  78. #define QL_SSL_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA 0xC004 /**< Not in SSL3! */
  79. #define QL_SSL_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA 0xC005 /**< Not in SSL3! */
  80. #define QL_SSL_TLS_ECDHE_ECDSA_WITH_NULL_SHA 0xC006 /**< Weak! */
  81. #define QL_SSL_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA 0xC007 /**< Not in SSL3! */
  82. #define QL_SSL_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA 0xC008 /**< Not in SSL3! */
  83. #define QL_SSL_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA 0xC009 /**< Not in SSL3! */
  84. #define QL_SSL_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA 0xC00A /**< Not in SSL3! */
  85. #define QL_SSL_TLS_ECDH_RSA_WITH_NULL_SHA 0xC00B /**< Weak! */
  86. #define QL_SSL_TLS_ECDH_RSA_WITH_RC4_128_SHA 0xC00C /**< Not in SSL3! */
  87. #define QL_SSL_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA 0xC00D /**< Not in SSL3! */
  88. #define QL_SSL_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA 0xC00E /**< Not in SSL3! */
  89. #define QL_SSL_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA 0xC00F /**< Not in SSL3! */
  90. #define QL_SSL_TLS_ECDHE_RSA_WITH_NULL_SHA 0xC010 /**< Weak! */
  91. #define QL_SSL_TLS_ECDHE_RSA_WITH_RC4_128_SHA 0xC011 /**< Not in SSL3! */
  92. #define QL_SSL_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA 0xC012 /**< Not in SSL3! */
  93. #define QL_SSL_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA 0xC013 /**< Not in SSL3! */
  94. #define QL_SSL_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA 0xC014 /**< Not in SSL3! */
  95. #define QL_SSL_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 0xC023 /**< TLS 1.2 */
  96. #define QL_SSL_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 0xC024 /**< TLS 1.2 */
  97. #define QL_SSL_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 0xC025 /**< TLS 1.2 */
  98. #define QL_SSL_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 0xC026 /**< TLS 1.2 */
  99. #define QL_SSL_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 0xC027 /**< TLS 1.2 */
  100. #define QL_SSL_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 0xC028 /**< TLS 1.2 */
  101. #define QL_SSL_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 0xC029 /**< TLS 1.2 */
  102. #define QL_SSL_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 0xC02A /**< TLS 1.2 */
  103. #define QL_SSL_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 0xC02B /**< TLS 1.2 */
  104. #define QL_SSL_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 0xC02C /**< TLS 1.2 */
  105. #define QL_SSL_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 0xC02D /**< TLS 1.2 */
  106. #define QL_SSL_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 0xC02E /**< TLS 1.2 */
  107. #define QL_SSL_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 0xC02F /**< TLS 1.2 */
  108. #define QL_SSL_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 0xC030 /**< TLS 1.2 */
  109. #define QL_SSL_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 0xC031 /**< TLS 1.2 */
  110. #define QL_SSL_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 0xC032 /**< TLS 1.2 */
  111. #define QL_SSL_TLS_ECDHE_PSK_WITH_RC4_128_SHA 0xC033 /**< Not in SSL3! */
  112. #define QL_SSL_TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA 0xC034 /**< Not in SSL3! */
  113. #define QL_SSL_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA 0xC035 /**< Not in SSL3! */
  114. #define QL_SSL_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA 0xC036 /**< Not in SSL3! */
  115. #define QL_SSL_TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 0xC037 /**< Not in SSL3! */
  116. #define QL_SSL_TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 0xC038 /**< Not in SSL3! */
  117. #define QL_SSL_TLS_ECDHE_PSK_WITH_NULL_SHA 0xC039 /**< Weak! No SSL3! */
  118. #define QL_SSL_TLS_ECDHE_PSK_WITH_NULL_SHA256 0xC03A /**< Weak! No SSL3! */
  119. #define QL_SSL_TLS_ECDHE_PSK_WITH_NULL_SHA384 0xC03B /**< Weak! No SSL3! */
  120. #define QL_SSL_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 0xC072 /**< Not in SSL3! */
  121. #define QL_SSL_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 0xC073 /**< Not in SSL3! */
  122. #define QL_SSL_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 0xC074 /**< Not in SSL3! */
  123. #define QL_SSL_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 0xC075 /**< Not in SSL3! */
  124. #define QL_SSL_TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xC076 /**< Not in SSL3! */
  125. #define QL_SSL_TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 0xC077 /**< Not in SSL3! */
  126. #define QL_SSL_TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 0xC078 /**< Not in SSL3! */
  127. #define QL_SSL_TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 0xC079 /**< Not in SSL3! */
  128. #define QL_SSL_TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 0xC07A /**< TLS 1.2 */
  129. #define QL_SSL_TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 0xC07B /**< TLS 1.2 */
  130. #define QL_SSL_TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 0xC07C /**< TLS 1.2 */
  131. #define QL_SSL_TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 0xC07D /**< TLS 1.2 */
  132. #define QL_SSL_TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 0xC086 /**< TLS 1.2 */
  133. #define QL_SSL_TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 0xC087 /**< TLS 1.2 */
  134. #define QL_SSL_TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 0xC088 /**< TLS 1.2 */
  135. #define QL_SSL_TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 0xC089 /**< TLS 1.2 */
  136. #define QL_SSL_TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 0xC08A /**< TLS 1.2 */
  137. #define QL_SSL_TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 0xC08B /**< TLS 1.2 */
  138. #define QL_SSL_TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 0xC08C /**< TLS 1.2 */
  139. #define QL_SSL_TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 0xC08D /**< TLS 1.2 */
  140. #define QL_SSL_TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 0xC08E /**< TLS 1.2 */
  141. #define QL_SSL_TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384 0xC08F /**< TLS 1.2 */
  142. #define QL_SSL_TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256 0xC090 /**< TLS 1.2 */
  143. #define QL_SSL_TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384 0xC091 /**< TLS 1.2 */
  144. #define QL_SSL_TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256 0xC092 /**< TLS 1.2 */
  145. #define QL_SSL_TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384 0xC093 /**< TLS 1.2 */
  146. #define QL_SSL_TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 0xC094
  147. #define QL_SSL_TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384 0xC095
  148. #define QL_SSL_TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 0xC096
  149. #define QL_SSL_TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 0xC097
  150. #define QL_SSL_TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 0xC098
  151. #define QL_SSL_TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 0xC099
  152. #define QL_SSL_TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 0xC09A /**< Not in SSL3! */
  153. #define QL_SSL_TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 0xC09B /**< Not in SSL3! */
  154. #define QL_SSL_TLS_RSA_WITH_AES_128_CCM 0xC09C /**< TLS 1.2 */
  155. #define QL_SSL_TLS_RSA_WITH_AES_256_CCM 0xC09D /**< TLS 1.2 */
  156. #define QL_SSL_TLS_DHE_RSA_WITH_AES_128_CCM 0xC09E /**< TLS 1.2 */
  157. #define QL_SSL_TLS_DHE_RSA_WITH_AES_256_CCM 0xC09F /**< TLS 1.2 */
  158. #define QL_SSL_TLS_RSA_WITH_AES_128_CCM_8 0xC0A0 /**< TLS 1.2 */
  159. #define QL_SSL_TLS_RSA_WITH_AES_256_CCM_8 0xC0A1 /**< TLS 1.2 */
  160. #define QL_SSL_TLS_DHE_RSA_WITH_AES_128_CCM_8 0xC0A2 /**< TLS 1.2 */
  161. #define QL_SSL_TLS_DHE_RSA_WITH_AES_256_CCM_8 0xC0A3 /**< TLS 1.2 */
  162. #define QL_SSL_TLS_PSK_WITH_AES_128_CCM 0xC0A4 /**< TLS 1.2 */
  163. #define QL_SSL_TLS_PSK_WITH_AES_256_CCM 0xC0A5 /**< TLS 1.2 */
  164. #define QL_SSL_TLS_DHE_PSK_WITH_AES_128_CCM 0xC0A6 /**< TLS 1.2 */
  165. #define QL_SSL_TLS_DHE_PSK_WITH_AES_256_CCM 0xC0A7 /**< TLS 1.2 */
  166. #define QL_SSL_TLS_PSK_WITH_AES_128_CCM_8 0xC0A8 /**< TLS 1.2 */
  167. #define QL_SSL_TLS_PSK_WITH_AES_256_CCM_8 0xC0A9 /**< TLS 1.2 */
  168. #define QL_SSL_TLS_DHE_PSK_WITH_AES_128_CCM_8 0xC0AA /**< TLS 1.2 */
  169. #define QL_SSL_TLS_DHE_PSK_WITH_AES_256_CCM_8 0xC0AB /**< TLS 1.2 */
  170. /* The last two are named with PSK_DHE in the RFC, which looks like a typo */
  171. #define QL_SSL_TLS_ECDHE_ECDSA_WITH_AES_128_CCM 0xC0AC /**< TLS 1.2 */
  172. #define QL_SSL_TLS_ECDHE_ECDSA_WITH_AES_256_CCM 0xC0AD /**< TLS 1.2 */
  173. #define QL_SSL_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 0xC0AE /**< TLS 1.2 */
  174. #define QL_SSL_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 0xC0AF /**< TLS 1.2 */
  175. #define QL_SSL_TLS_ECJPAKE_WITH_AES_128_CCM_8 0xC0FF /**< experimental */
  176. #define QL_SSL_TLS_CURL_SUPPORT
  177. #define QL_SSL_TLS_SESSION_CACHE_FEATURE
  178. #ifdef CONFIG_QUEC_PROJECT_FEATURE_SSL
  179. //#define QL_SSL_DTLS_FEATURE
  180. //#define QL_SSL_PSK_FEATURE
  181. //#define QL_SSL_RENEGOTIATION_FEATURE
  182. #endif
  183. #ifdef QL_SSL_PSK_FEATURE
  184. #define QL_SSL_PSK_IDENTITY_LENGTH_MAX 255
  185. #define QL_SSL_PSK_KEY_LENGTH_MAX 255
  186. #endif
  187. #define ql_ssl_handshark(ssl_ctx_ptr) ql_ssl_handshake(ssl_ctx_ptr)
  188. #define ql_ssl_handshark_finished(ssl_ctx_ptr) ql_ssl_handshake_finished(ssl_ctx_ptr)
  189. typedef enum
  190. {
  191. QL_SSL_VERSION_0 = 0, /**< SSL protocol ver. 3.0. */
  192. QL_SSL_VERSION_1, /**< TLS protocol ver. 1.0 (SSL 3.1). */
  193. QL_SSL_VERSION_2, /**< TLS protocol ver. 1.1 (SSL 3.2). */
  194. QL_SSL_VERSION_3,
  195. //QL_SSL_VERSION_4,
  196. QL_SSL_VERSION_ALL
  197. } ql_ssl_version_type_e;
  198. typedef enum
  199. {
  200. QL_SSL_VERIFY_NULL = 0x0000,
  201. QL_SSL_VERIFY_SERVER = 0x0001,
  202. QL_SSL_VERIFY_CLIENT_SERVER = 0x0002,
  203. #ifdef QL_SSL_PSK_FEATURE
  204. QL_SSL_VERIFY_PSK = 0x0003,
  205. #endif
  206. } ql_ssl_authmode_e;
  207. typedef enum{
  208. QL_SSL_TLS_PROTOCOL = 0,
  209. QL_SSL_DTLS_PROTOCOL = 1,
  210. }ql_ssl_transport_type_e;
  211. typedef enum{
  212. QL_SSL_CLIENT_CERT_FILE = 0,
  213. QL_SSL_CLIENT_CERT_BUFFER = 1,
  214. }ql_ssl_client_cert_type_e;
  215. #ifdef QL_SSL_DTLS_FEATURE
  216. typedef enum
  217. {
  218. QL_SSL_VER_DTLS10 = 0, /**< DTLS protocol ver. 1.0. > */
  219. QL_SSL_VER_DTLS12 = 1, /**< DTLS protocal ver. 1.2. > */
  220. } ql_ssl_dtls_version_enum;
  221. #endif
  222. #ifdef QL_SSL_RENEGOTIATION_FEATURE
  223. typedef enum{
  224. QL_SSL_RENEGOTIATION_DISABLED = 0,
  225. QL_SSL_RENEGOTIATION_ENABLED = 1,
  226. }ql_ssl_renegotiation_type_e;
  227. #endif
  228. typedef int ql_ssl_context;
  229. typedef void(*ql_ssl_handshake_timeout_cb)(ql_ssl_context *ssl_ctx, void *arg);
  230. /* Number of certificate checking items */
  231. #define QL_SSL_TLS_CERT_ITEM_NUM 20
  232. #ifdef QL_SSL_TLS_SESSION_CACHE_FEATURE
  233. #include "mbedtls/ssl.h"
  234. typedef struct
  235. {
  236. uint8_t session_cache_enable;
  237. ip_addr_t remote_ip;
  238. uint16_t remote_port;
  239. uint8_t hostname_temp[256]; // save session hostname when qsslopen
  240. uint8_t session_hostname[256]; // real hostname coresponding to session cache
  241. mbedtls_ssl_session ssl_session;
  242. }ql_ssl_session;
  243. #endif
  244. typedef struct{
  245. int ssl_version;
  246. int transport; //0: TLS 1: DTLS
  247. int *ciphersuites;
  248. int auth_mode;
  249. int sni_enable;
  250. char *ca_cert_path[QL_MAX_CA_CERT_CNT];
  251. char *own_cert_path;
  252. char *own_key_path;
  253. char *own_key_pwd;
  254. char *ca_cert_buffer[QL_MAX_CA_CERT_CNT];
  255. int ssl_negotiate_timeout;
  256. ql_ssl_handshake_timeout_cb negotiate_timeout_cb;
  257. void *negotiate_timeout_cb_arg;
  258. int ignore_invalid_certsign;
  259. uint32_t ignore_certitem;
  260. int ignore_multi_certchain_verify;
  261. bool client_cert_type;
  262. #ifdef QL_SSL_TLS_SESSION_CACHE_FEATURE
  263. ql_ssl_session ssl_session_cache;
  264. #endif
  265. #ifdef QL_SSL_DTLS_FEATURE
  266. int dtls_version;
  267. #endif
  268. #ifdef QL_SSL_PSK_FEATURE
  269. char *psk_identity;
  270. char *psk_key;
  271. #endif
  272. #ifdef QL_SSL_RENEGOTIATION_FEATURE
  273. int renegotiation;
  274. #endif
  275. }ql_ssl_config;
  276. typedef enum{
  277. QL_SSL_CONF_VERSION = 1,
  278. QL_SSL_CONF_TRANSPORT = 2,
  279. QL_SSL_CONF_CIPHERSUITE = 3,
  280. QL_SSL_CONF_AUTHMODE = 4,
  281. QL_SSL_CONF_CACERT = 5,
  282. QL_SSL_CONF_OWNCERT = 6,
  283. QL_SSL_CONF_SNI = 7,
  284. QL_SSL_CONF_HS_TIMEOUT = 8,
  285. QL_SSL_CONF_IGNORE_LOCALTM = 9,
  286. QL_SSL_CONF_HS_TIMEOUT_FUNC= 10,
  287. QL_SSL_CONF_IGNORE_INVALID_CERT_SIGN = 11,
  288. QL_SSL_CONF_IGNORE_CERT_ITEM = 12,
  289. QL_SSL_CONF_IGNORE_MULTI_CERTCHAIN_VERIFY = 13,
  290. #ifdef QL_SSL_TLS_SESSION_CACHE_FEATURE
  291. QL_SSL_CONF_SESSION_CACHE = 14,
  292. #endif
  293. QL_SSL_CONF_CACERT_BUFFER = 15,
  294. QL_SSL_CONF_OWNCERT_BUFFER = 16,
  295. #ifdef QL_SSL_DTLS_FEATURE
  296. QL_SSL_CONF_DTLSVERSION = 17,
  297. #endif
  298. #ifdef QL_SSL_PSK_FEATURE
  299. QL_SSL_CONF_PSK_IDENTITY = 18,
  300. QL_SSL_CONF_PSK_KEY = 19,
  301. #endif
  302. #ifdef QL_SSL_RENEGOTIATION_FEATURE
  303. QL_SSL_CONF_RENEGOTIATION = 20,
  304. #endif
  305. }ql_ssl_config_type_e;
  306. typedef enum{
  307. QL_SSL_SUCCESS = 0,
  308. QL_SSL_ERROR_UNKOWN = -1,
  309. QL_SSL_ERROR_WOUNDBLOCK = -2,
  310. QL_SSL_ERROR_INVALID_PARAM = -3,
  311. QL_SSL_ERROR_OUT_OF_MEM = -4,
  312. QL_SSL_ERROR_NOT_SUPPORT = -5,
  313. QL_SSL_ERROR_HS_FAILURE = -6,
  314. QL_SSL_ERROR_DECRYPT_FAILURE = -7,
  315. QL_SSL_ERROR_ENCRYPT_FAILURE = -8,
  316. QL_SSL_ERROR_HS_INPROGRESS = -9,
  317. QL_SSL_ERROR_BAD_REQUEST = -10,
  318. QL_SSL_ERROR_WANT_READ = -11,
  319. QL_SSL_ERROR_WANT_WRITE = -12,
  320. QL_SSL_ERROR_SOCKET_RESET = -13,
  321. }ql_ssl_error_code_e;
  322. /*****************************************************************
  323. * Function: ql_ssl_conf_init
  324. *
  325. * Description: 初始化ssl上下文配置项的结构信息
  326. *
  327. * Parameters:
  328. * conf [in] ssl上下文配置项结构体指针.
  329. *
  330. * Return:
  331. * 0 成功
  332. * other 错误码
  333. *
  334. *****************************************************************/
  335. int ql_ssl_conf_init(ql_ssl_config *conf);
  336. /*****************************************************************
  337. * Function: ql_ssl_conf_set
  338. *
  339. * Description: 设置ssl上下文配置项中的配置参数
  340. *
  341. * Parameters:
  342. * conf [in] ssl上下文配置项结构体指针.
  343. * type [in] ssl上下文配置项的参数处理类型
  344. *
  345. * Return:
  346. * 0 成功
  347. * other 错误码
  348. *
  349. *****************************************************************/
  350. int ql_ssl_conf_set(ql_ssl_config *conf, int type, ...);
  351. /*****************************************************************
  352. * Function: ql_ssl_conf_get
  353. *
  354. * Description: 获取已设置的ssl上下文配置项的配置参数
  355. *
  356. * Parameters:
  357. * conf [in] ssl上下文配置项结构体指针.
  358. * type [in] ssl上下文中配置参数处理类型
  359. *
  360. * Return:
  361. * 0 成功
  362. * other 错误码
  363. *
  364. *****************************************************************/
  365. int ql_ssl_conf_get(ql_ssl_config *conf, int type, ...);
  366. /*****************************************************************
  367. * Function: ql_ssl_conf_set_by_id
  368. *
  369. * Description: 通过ssl上下文id号,设置该id对应的ssl上下文配置项的配置参数
  370. *
  371. * Parameters:
  372. * ctx_id [in] ssl上下文id号.
  373. * type [in] ssl上下文中配置参数处理类型
  374. *
  375. * Return:
  376. * 0 成功
  377. * other 错误码
  378. *
  379. *****************************************************************/
  380. int ql_ssl_conf_set_by_id(int ctx_id, int type, ...);
  381. /*****************************************************************
  382. * Function: ql_ssl_conf_get_by_id
  383. *
  384. * Description: 通过ssl上下文id号,获取该id设置的ssl上下文配置项的配置参数
  385. *
  386. * Parameters:
  387. * ctx_id [in] ssl上下文id号.
  388. * type [in] ssl上下文中配置参数处理类型
  389. *
  390. * Return:
  391. * 0 成功
  392. * other 错误码
  393. *
  394. *****************************************************************/
  395. int ql_ssl_conf_get_by_id(int ctx_id, int type, ...);
  396. /*****************************************************************
  397. * Function: ql_ssl_conf_free
  398. *
  399. * Description: 释放ssl上下文配置项结构体的内存块
  400. *
  401. * Parameters:
  402. * conf [in] ssl上下文配置项结构体指针.
  403. *
  404. * Return:
  405. * 0 成功
  406. * other 错误码
  407. *
  408. *****************************************************************/
  409. int ql_ssl_conf_free(ql_ssl_config *conf);
  410. /*****************************************************************
  411. * Function: ql_ssl_new
  412. *
  413. * Description: 初始化ssl上下文结构
  414. *
  415. * Parameters:
  416. * ssl [in] ssl上下文结构体指针.
  417. *
  418. * Return:
  419. * 0 成功
  420. * other 错误码
  421. *
  422. *****************************************************************/
  423. int ql_ssl_new(ql_ssl_context *ssl);
  424. /*****************************************************************
  425. * Function: ql_ssl_setup
  426. *
  427. * Description: 通过conf配置ssl上下文,ssl上下文信息确定ssl连接的属性
  428. *
  429. * Parameters:
  430. * ssl [in] ssl上下文结构体指针.
  431. * conf [in] ssl上下文配置项结构体指针.
  432. *
  433. * Return:
  434. * 0 成功
  435. * other 错误码
  436. *
  437. *****************************************************************/
  438. int ql_ssl_setup(ql_ssl_context *ssl, ql_ssl_config *conf);
  439. /*****************************************************************
  440. * Function: ql_ssl_set_socket_fd
  441. *
  442. * Description: 关联当前ssl上下文与指定的套接字描述符,以及设置mbed bio的读写函数
  443. *
  444. * Parameters:
  445. * ssl [in] ssl上下文结构体指针.
  446. * sock_fd [in] socket套接字描述符.
  447. *
  448. * Return:
  449. * 0 成功
  450. * other 错误码
  451. *
  452. *****************************************************************/
  453. int ql_ssl_set_socket_fd(ql_ssl_context *ssl, int sock_fd);
  454. /*****************************************************************
  455. * Function: ql_ssl_set_hostname
  456. *
  457. * Description:
  458. * 1. 设置远端主机名用以检查接收到的服务器证书,在调用ql_ssl_setup函数后才调用本函数。
  459. * 2. 保存远端主机名用以判断会话恢复。
  460. *
  461. * Parameters:
  462. * ssl [in] ssl上下文结构体指针.
  463. * hostname [in] 远端IP地址或域名地址
  464. *
  465. * Return:
  466. * 0 成功
  467. * other 错误码
  468. *
  469. *****************************************************************/
  470. int ql_ssl_set_hostname(ql_ssl_context *ssl, const char *hostname);
  471. /*****************************************************************
  472. * Function: ql_ssl_handshake
  473. *
  474. * Description: ssl握手通信,通过ssl上下文确定ssl建立连接属性
  475. *
  476. * Parameters:
  477. * ssl [in] ssl上下文结构体指针.
  478. *
  479. * Return:
  480. * 0 成功
  481. * other 错误码
  482. *
  483. *****************************************************************/
  484. int ql_ssl_handshake(ql_ssl_context *ssl);
  485. /*****************************************************************
  486. * Function: ql_ssl_close_notify
  487. *
  488. * Description: 通知ssl连接对端连接正在关闭
  489. *
  490. * Parameters:
  491. * ssl [in] ssl上下文结构体指针.
  492. *
  493. * Return:
  494. * 0 成功
  495. * other 错误码
  496. *
  497. *****************************************************************/
  498. int ql_ssl_close_notify(ql_ssl_context *ssl);
  499. /*****************************************************************
  500. * Function: ql_ssl_get_bytes_avail
  501. *
  502. * Description: 返回可读取的数据字节数
  503. *
  504. * Parameters:
  505. * ssl [in] ssl上下文结构体指针.
  506. *
  507. * Return:
  508. * 返回读缓冲区中有多少字节可用
  509. *
  510. *****************************************************************/
  511. int ql_ssl_get_bytes_avail(ql_ssl_context *ssl);
  512. /*****************************************************************
  513. * Function: ql_ssl_read
  514. *
  515. * Description: 从缓冲区中读取len字节的数据
  516. *
  517. * Parameters:
  518. * ssl [in] ssl上下文结构体指针.
  519. * buf [in] 读buf缓冲区指针.
  520. * len [in] 待读取数据长度.
  521. *
  522. * Return:
  523. * 大于等于0 返回当前已从缓冲区成功读取的数据字节数
  524. * other 错误码
  525. *
  526. *****************************************************************/
  527. int ql_ssl_read(ql_ssl_context *ssl, unsigned char *buf, size_t len);
  528. /*****************************************************************
  529. * Function: ql_ssl_write
  530. *
  531. * Description: 向缓冲区中写入len字节的数据
  532. *
  533. * Parameters:
  534. * ssl [in] ssl上下文结构体指针.
  535. * buf [in] 保存数据buf缓冲区指针.
  536. * len [in] 待发送的数据长度.
  537. *
  538. * Return:
  539. * 大于等于0 返回当前已从缓冲区成功写入的数据字节数
  540. * other 错误码
  541. *
  542. *****************************************************************/
  543. int ql_ssl_write(ql_ssl_context *ssl, const unsigned char *buf, size_t len);
  544. /*****************************************************************
  545. * Function: ql_ssl_free
  546. *
  547. * Description: 释放ssl上下文,以及ssl上下文所占用的内存块
  548. *
  549. * Parameters:
  550. * ssl [in] ssl上下文结构体指针.
  551. *
  552. * Return:
  553. * 0 成功
  554. * other 错误码
  555. *
  556. *****************************************************************/
  557. int ql_ssl_free(ql_ssl_context *ssl);
  558. /*****************************************************************
  559. * Function: ql_ssl_handshake_finished
  560. *
  561. * Description: ssl握手通信结束,更改ssl上下文状态为HANDSHAKE_OVER
  562. *
  563. * Parameters:
  564. * ssl [in] ssl上下文结构体指针.
  565. *
  566. * Return:
  567. * 0 成功
  568. * other 错误码
  569. *
  570. *****************************************************************/
  571. int ql_ssl_handshake_finished(ql_ssl_context *ssl);
  572. /*****************************************************************
  573. * Function: ql_ssl_ciphersuit_is_valid
  574. *
  575. * Description: 判断所指定的SSL密码组是否支持
  576. *
  577. * Parameters:
  578. * cs_id [in] SSL加密套件的数值id
  579. *
  580. * Return:
  581. * 0 成功
  582. * other 错误码
  583. *
  584. *****************************************************************/
  585. int ql_ssl_ciphersuit_is_valid(int cs_id);
  586. #endif
  587. #endif