t1_trce.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791
  1. /*
  2. * Copyright 2012-2023 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include "ssl_local.h"
  10. #ifndef OPENSSL_NO_SSL_TRACE
  11. /* Packet trace support for OpenSSL */
  12. #include "internal/nelem.h"
  13. typedef struct {
  14. int num;
  15. const char *name;
  16. } ssl_trace_tbl;
  17. # define ssl_trace_str(val, tbl) \
  18. do_ssl_trace_str(val, tbl, OSSL_NELEM(tbl))
  19. # define ssl_trace_list(bio, indent, msg, msglen, value, table) \
  20. do_ssl_trace_list(bio, indent, msg, msglen, value, \
  21. table, OSSL_NELEM(table))
  22. static const char *do_ssl_trace_str(int val, const ssl_trace_tbl *tbl,
  23. size_t ntbl)
  24. {
  25. size_t i;
  26. for (i = 0; i < ntbl; i++, tbl++) {
  27. if (tbl->num == val)
  28. return tbl->name;
  29. }
  30. return "UNKNOWN";
  31. }
  32. static int do_ssl_trace_list(BIO *bio, int indent,
  33. const unsigned char *msg, size_t msglen,
  34. size_t vlen, const ssl_trace_tbl *tbl, size_t ntbl)
  35. {
  36. int val;
  37. if (msglen % vlen)
  38. return 0;
  39. while (msglen) {
  40. val = msg[0];
  41. if (vlen == 2)
  42. val = (val << 8) | msg[1];
  43. BIO_indent(bio, indent, 80);
  44. BIO_printf(bio, "%s (%d)\n", do_ssl_trace_str(val, tbl, ntbl), val);
  45. msg += vlen;
  46. msglen -= vlen;
  47. }
  48. return 1;
  49. }
  50. /* Version number */
  51. static const ssl_trace_tbl ssl_version_tbl[] = {
  52. {SSL3_VERSION, "SSL 3.0"},
  53. {TLS1_VERSION, "TLS 1.0"},
  54. {TLS1_1_VERSION, "TLS 1.1"},
  55. {TLS1_2_VERSION, "TLS 1.2"},
  56. {TLS1_3_VERSION, "TLS 1.3"},
  57. {DTLS1_VERSION, "DTLS 1.0"},
  58. {DTLS1_2_VERSION, "DTLS 1.2"},
  59. {DTLS1_BAD_VER, "DTLS 1.0 (bad)"}
  60. };
  61. static const ssl_trace_tbl ssl_content_tbl[] = {
  62. {SSL3_RT_CHANGE_CIPHER_SPEC, "ChangeCipherSpec"},
  63. {SSL3_RT_ALERT, "Alert"},
  64. {SSL3_RT_HANDSHAKE, "Handshake"},
  65. {SSL3_RT_APPLICATION_DATA, "ApplicationData"},
  66. };
  67. /* Handshake types, sorted by ascending id */
  68. static const ssl_trace_tbl ssl_handshake_tbl[] = {
  69. {SSL3_MT_HELLO_REQUEST, "HelloRequest"},
  70. {SSL3_MT_CLIENT_HELLO, "ClientHello"},
  71. {SSL3_MT_SERVER_HELLO, "ServerHello"},
  72. {DTLS1_MT_HELLO_VERIFY_REQUEST, "HelloVerifyRequest"},
  73. {SSL3_MT_NEWSESSION_TICKET, "NewSessionTicket"},
  74. {SSL3_MT_END_OF_EARLY_DATA, "EndOfEarlyData"},
  75. {SSL3_MT_ENCRYPTED_EXTENSIONS, "EncryptedExtensions"},
  76. {SSL3_MT_CERTIFICATE, "Certificate"},
  77. {SSL3_MT_SERVER_KEY_EXCHANGE, "ServerKeyExchange"},
  78. {SSL3_MT_CERTIFICATE_REQUEST, "CertificateRequest"},
  79. {SSL3_MT_SERVER_DONE, "ServerHelloDone"},
  80. {SSL3_MT_CERTIFICATE_VERIFY, "CertificateVerify"},
  81. {SSL3_MT_CLIENT_KEY_EXCHANGE, "ClientKeyExchange"},
  82. {SSL3_MT_FINISHED, "Finished"},
  83. {SSL3_MT_CERTIFICATE_URL, "CertificateUrl"},
  84. {SSL3_MT_CERTIFICATE_STATUS, "CertificateStatus"},
  85. {SSL3_MT_SUPPLEMENTAL_DATA, "SupplementalData"},
  86. {SSL3_MT_KEY_UPDATE, "KeyUpdate"},
  87. {SSL3_MT_COMPRESSED_CERTIFICATE, "CompressedCertificate"},
  88. # ifndef OPENSSL_NO_NEXTPROTONEG
  89. {SSL3_MT_NEXT_PROTO, "NextProto"},
  90. # endif
  91. {SSL3_MT_MESSAGE_HASH, "MessageHash"}
  92. };
  93. /* Cipher suites */
  94. static const ssl_trace_tbl ssl_ciphers_tbl[] = {
  95. {0x0000, "TLS_NULL_WITH_NULL_NULL"},
  96. {0x0001, "TLS_RSA_WITH_NULL_MD5"},
  97. {0x0002, "TLS_RSA_WITH_NULL_SHA"},
  98. {0x0003, "TLS_RSA_EXPORT_WITH_RC4_40_MD5"},
  99. {0x0004, "TLS_RSA_WITH_RC4_128_MD5"},
  100. {0x0005, "TLS_RSA_WITH_RC4_128_SHA"},
  101. {0x0006, "TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5"},
  102. {0x0007, "TLS_RSA_WITH_IDEA_CBC_SHA"},
  103. {0x0008, "TLS_RSA_EXPORT_WITH_DES40_CBC_SHA"},
  104. {0x0009, "TLS_RSA_WITH_DES_CBC_SHA"},
  105. {0x000A, "TLS_RSA_WITH_3DES_EDE_CBC_SHA"},
  106. {0x000B, "TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA"},
  107. {0x000C, "TLS_DH_DSS_WITH_DES_CBC_SHA"},
  108. {0x000D, "TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA"},
  109. {0x000E, "TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA"},
  110. {0x000F, "TLS_DH_RSA_WITH_DES_CBC_SHA"},
  111. {0x0010, "TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA"},
  112. {0x0011, "TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA"},
  113. {0x0012, "TLS_DHE_DSS_WITH_DES_CBC_SHA"},
  114. {0x0013, "TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA"},
  115. {0x0014, "TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA"},
  116. {0x0015, "TLS_DHE_RSA_WITH_DES_CBC_SHA"},
  117. {0x0016, "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA"},
  118. {0x0017, "TLS_DH_anon_EXPORT_WITH_RC4_40_MD5"},
  119. {0x0018, "TLS_DH_anon_WITH_RC4_128_MD5"},
  120. {0x0019, "TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA"},
  121. {0x001A, "TLS_DH_anon_WITH_DES_CBC_SHA"},
  122. {0x001B, "TLS_DH_anon_WITH_3DES_EDE_CBC_SHA"},
  123. {0x001D, "SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA"},
  124. {0x001E, "SSL_FORTEZZA_KEA_WITH_RC4_128_SHA"},
  125. {0x001F, "TLS_KRB5_WITH_3DES_EDE_CBC_SHA"},
  126. {0x0020, "TLS_KRB5_WITH_RC4_128_SHA"},
  127. {0x0021, "TLS_KRB5_WITH_IDEA_CBC_SHA"},
  128. {0x0022, "TLS_KRB5_WITH_DES_CBC_MD5"},
  129. {0x0023, "TLS_KRB5_WITH_3DES_EDE_CBC_MD5"},
  130. {0x0024, "TLS_KRB5_WITH_RC4_128_MD5"},
  131. {0x0025, "TLS_KRB5_WITH_IDEA_CBC_MD5"},
  132. {0x0026, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA"},
  133. {0x0027, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA"},
  134. {0x0028, "TLS_KRB5_EXPORT_WITH_RC4_40_SHA"},
  135. {0x0029, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5"},
  136. {0x002A, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5"},
  137. {0x002B, "TLS_KRB5_EXPORT_WITH_RC4_40_MD5"},
  138. {0x002C, "TLS_PSK_WITH_NULL_SHA"},
  139. {0x002D, "TLS_DHE_PSK_WITH_NULL_SHA"},
  140. {0x002E, "TLS_RSA_PSK_WITH_NULL_SHA"},
  141. {0x002F, "TLS_RSA_WITH_AES_128_CBC_SHA"},
  142. {0x0030, "TLS_DH_DSS_WITH_AES_128_CBC_SHA"},
  143. {0x0031, "TLS_DH_RSA_WITH_AES_128_CBC_SHA"},
  144. {0x0032, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA"},
  145. {0x0033, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA"},
  146. {0x0034, "TLS_DH_anon_WITH_AES_128_CBC_SHA"},
  147. {0x0035, "TLS_RSA_WITH_AES_256_CBC_SHA"},
  148. {0x0036, "TLS_DH_DSS_WITH_AES_256_CBC_SHA"},
  149. {0x0037, "TLS_DH_RSA_WITH_AES_256_CBC_SHA"},
  150. {0x0038, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA"},
  151. {0x0039, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA"},
  152. {0x003A, "TLS_DH_anon_WITH_AES_256_CBC_SHA"},
  153. {0x003B, "TLS_RSA_WITH_NULL_SHA256"},
  154. {0x003C, "TLS_RSA_WITH_AES_128_CBC_SHA256"},
  155. {0x003D, "TLS_RSA_WITH_AES_256_CBC_SHA256"},
  156. {0x003E, "TLS_DH_DSS_WITH_AES_128_CBC_SHA256"},
  157. {0x003F, "TLS_DH_RSA_WITH_AES_128_CBC_SHA256"},
  158. {0x0040, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256"},
  159. {0x0041, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA"},
  160. {0x0042, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA"},
  161. {0x0043, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA"},
  162. {0x0044, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA"},
  163. {0x0045, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA"},
  164. {0x0046, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA"},
  165. {0x0067, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256"},
  166. {0x0068, "TLS_DH_DSS_WITH_AES_256_CBC_SHA256"},
  167. {0x0069, "TLS_DH_RSA_WITH_AES_256_CBC_SHA256"},
  168. {0x006A, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256"},
  169. {0x006B, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256"},
  170. {0x006C, "TLS_DH_anon_WITH_AES_128_CBC_SHA256"},
  171. {0x006D, "TLS_DH_anon_WITH_AES_256_CBC_SHA256"},
  172. {0x0081, "TLS_GOSTR341001_WITH_28147_CNT_IMIT"},
  173. {0x0083, "TLS_GOSTR341001_WITH_NULL_GOSTR3411"},
  174. {0x0084, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA"},
  175. {0x0085, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA"},
  176. {0x0086, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA"},
  177. {0x0087, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA"},
  178. {0x0088, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA"},
  179. {0x0089, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA"},
  180. {0x008A, "TLS_PSK_WITH_RC4_128_SHA"},
  181. {0x008B, "TLS_PSK_WITH_3DES_EDE_CBC_SHA"},
  182. {0x008C, "TLS_PSK_WITH_AES_128_CBC_SHA"},
  183. {0x008D, "TLS_PSK_WITH_AES_256_CBC_SHA"},
  184. {0x008E, "TLS_DHE_PSK_WITH_RC4_128_SHA"},
  185. {0x008F, "TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA"},
  186. {0x0090, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA"},
  187. {0x0091, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA"},
  188. {0x0092, "TLS_RSA_PSK_WITH_RC4_128_SHA"},
  189. {0x0093, "TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA"},
  190. {0x0094, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA"},
  191. {0x0095, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA"},
  192. {0x0096, "TLS_RSA_WITH_SEED_CBC_SHA"},
  193. {0x0097, "TLS_DH_DSS_WITH_SEED_CBC_SHA"},
  194. {0x0098, "TLS_DH_RSA_WITH_SEED_CBC_SHA"},
  195. {0x0099, "TLS_DHE_DSS_WITH_SEED_CBC_SHA"},
  196. {0x009A, "TLS_DHE_RSA_WITH_SEED_CBC_SHA"},
  197. {0x009B, "TLS_DH_anon_WITH_SEED_CBC_SHA"},
  198. {0x009C, "TLS_RSA_WITH_AES_128_GCM_SHA256"},
  199. {0x009D, "TLS_RSA_WITH_AES_256_GCM_SHA384"},
  200. {0x009E, "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256"},
  201. {0x009F, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384"},
  202. {0x00A0, "TLS_DH_RSA_WITH_AES_128_GCM_SHA256"},
  203. {0x00A1, "TLS_DH_RSA_WITH_AES_256_GCM_SHA384"},
  204. {0x00A2, "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256"},
  205. {0x00A3, "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384"},
  206. {0x00A4, "TLS_DH_DSS_WITH_AES_128_GCM_SHA256"},
  207. {0x00A5, "TLS_DH_DSS_WITH_AES_256_GCM_SHA384"},
  208. {0x00A6, "TLS_DH_anon_WITH_AES_128_GCM_SHA256"},
  209. {0x00A7, "TLS_DH_anon_WITH_AES_256_GCM_SHA384"},
  210. {0x00A8, "TLS_PSK_WITH_AES_128_GCM_SHA256"},
  211. {0x00A9, "TLS_PSK_WITH_AES_256_GCM_SHA384"},
  212. {0x00AA, "TLS_DHE_PSK_WITH_AES_128_GCM_SHA256"},
  213. {0x00AB, "TLS_DHE_PSK_WITH_AES_256_GCM_SHA384"},
  214. {0x00AC, "TLS_RSA_PSK_WITH_AES_128_GCM_SHA256"},
  215. {0x00AD, "TLS_RSA_PSK_WITH_AES_256_GCM_SHA384"},
  216. {0x00AE, "TLS_PSK_WITH_AES_128_CBC_SHA256"},
  217. {0x00AF, "TLS_PSK_WITH_AES_256_CBC_SHA384"},
  218. {0x00B0, "TLS_PSK_WITH_NULL_SHA256"},
  219. {0x00B1, "TLS_PSK_WITH_NULL_SHA384"},
  220. {0x00B2, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA256"},
  221. {0x00B3, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA384"},
  222. {0x00B4, "TLS_DHE_PSK_WITH_NULL_SHA256"},
  223. {0x00B5, "TLS_DHE_PSK_WITH_NULL_SHA384"},
  224. {0x00B6, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA256"},
  225. {0x00B7, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA384"},
  226. {0x00B8, "TLS_RSA_PSK_WITH_NULL_SHA256"},
  227. {0x00B9, "TLS_RSA_PSK_WITH_NULL_SHA384"},
  228. {0x00BA, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256"},
  229. {0x00BB, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256"},
  230. {0x00BC, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256"},
  231. {0x00BD, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256"},
  232. {0x00BE, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256"},
  233. {0x00BF, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256"},
  234. {0x00C0, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256"},
  235. {0x00C1, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256"},
  236. {0x00C2, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256"},
  237. {0x00C3, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256"},
  238. {0x00C4, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256"},
  239. {0x00C5, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256"},
  240. {0x00FF, "TLS_EMPTY_RENEGOTIATION_INFO_SCSV"},
  241. {0x5600, "TLS_FALLBACK_SCSV"},
  242. {0xC001, "TLS_ECDH_ECDSA_WITH_NULL_SHA"},
  243. {0xC002, "TLS_ECDH_ECDSA_WITH_RC4_128_SHA"},
  244. {0xC003, "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA"},
  245. {0xC004, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA"},
  246. {0xC005, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA"},
  247. {0xC006, "TLS_ECDHE_ECDSA_WITH_NULL_SHA"},
  248. {0xC007, "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA"},
  249. {0xC008, "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA"},
  250. {0xC009, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA"},
  251. {0xC00A, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA"},
  252. {0xC00B, "TLS_ECDH_RSA_WITH_NULL_SHA"},
  253. {0xC00C, "TLS_ECDH_RSA_WITH_RC4_128_SHA"},
  254. {0xC00D, "TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA"},
  255. {0xC00E, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA"},
  256. {0xC00F, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA"},
  257. {0xC010, "TLS_ECDHE_RSA_WITH_NULL_SHA"},
  258. {0xC011, "TLS_ECDHE_RSA_WITH_RC4_128_SHA"},
  259. {0xC012, "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA"},
  260. {0xC013, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA"},
  261. {0xC014, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA"},
  262. {0xC015, "TLS_ECDH_anon_WITH_NULL_SHA"},
  263. {0xC016, "TLS_ECDH_anon_WITH_RC4_128_SHA"},
  264. {0xC017, "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA"},
  265. {0xC018, "TLS_ECDH_anon_WITH_AES_128_CBC_SHA"},
  266. {0xC019, "TLS_ECDH_anon_WITH_AES_256_CBC_SHA"},
  267. {0xC01A, "TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA"},
  268. {0xC01B, "TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA"},
  269. {0xC01C, "TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA"},
  270. {0xC01D, "TLS_SRP_SHA_WITH_AES_128_CBC_SHA"},
  271. {0xC01E, "TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA"},
  272. {0xC01F, "TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA"},
  273. {0xC020, "TLS_SRP_SHA_WITH_AES_256_CBC_SHA"},
  274. {0xC021, "TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA"},
  275. {0xC022, "TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA"},
  276. {0xC023, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256"},
  277. {0xC024, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384"},
  278. {0xC025, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256"},
  279. {0xC026, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384"},
  280. {0xC027, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"},
  281. {0xC028, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384"},
  282. {0xC029, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256"},
  283. {0xC02A, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384"},
  284. {0xC02B, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"},
  285. {0xC02C, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"},
  286. {0xC02D, "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256"},
  287. {0xC02E, "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384"},
  288. {0xC02F, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"},
  289. {0xC030, "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"},
  290. {0xC031, "TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256"},
  291. {0xC032, "TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384"},
  292. {0xC033, "TLS_ECDHE_PSK_WITH_RC4_128_SHA"},
  293. {0xC034, "TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA"},
  294. {0xC035, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA"},
  295. {0xC036, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA"},
  296. {0xC037, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256"},
  297. {0xC038, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384"},
  298. {0xC039, "TLS_ECDHE_PSK_WITH_NULL_SHA"},
  299. {0xC03A, "TLS_ECDHE_PSK_WITH_NULL_SHA256"},
  300. {0xC03B, "TLS_ECDHE_PSK_WITH_NULL_SHA384"},
  301. {0xC03C, "TLS_RSA_WITH_ARIA_128_CBC_SHA256"},
  302. {0xC03D, "TLS_RSA_WITH_ARIA_256_CBC_SHA384"},
  303. {0xC03E, "TLS_DH_DSS_WITH_ARIA_128_CBC_SHA256"},
  304. {0xC03F, "TLS_DH_DSS_WITH_ARIA_256_CBC_SHA384"},
  305. {0xC040, "TLS_DH_RSA_WITH_ARIA_128_CBC_SHA256"},
  306. {0xC041, "TLS_DH_RSA_WITH_ARIA_256_CBC_SHA384"},
  307. {0xC042, "TLS_DHE_DSS_WITH_ARIA_128_CBC_SHA256"},
  308. {0xC043, "TLS_DHE_DSS_WITH_ARIA_256_CBC_SHA384"},
  309. {0xC044, "TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256"},
  310. {0xC045, "TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384"},
  311. {0xC046, "TLS_DH_anon_WITH_ARIA_128_CBC_SHA256"},
  312. {0xC047, "TLS_DH_anon_WITH_ARIA_256_CBC_SHA384"},
  313. {0xC048, "TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256"},
  314. {0xC049, "TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384"},
  315. {0xC04A, "TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256"},
  316. {0xC04B, "TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384"},
  317. {0xC04C, "TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256"},
  318. {0xC04D, "TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384"},
  319. {0xC04E, "TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256"},
  320. {0xC04F, "TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384"},
  321. {0xC050, "TLS_RSA_WITH_ARIA_128_GCM_SHA256"},
  322. {0xC051, "TLS_RSA_WITH_ARIA_256_GCM_SHA384"},
  323. {0xC052, "TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256"},
  324. {0xC053, "TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384"},
  325. {0xC054, "TLS_DH_RSA_WITH_ARIA_128_GCM_SHA256"},
  326. {0xC055, "TLS_DH_RSA_WITH_ARIA_256_GCM_SHA384"},
  327. {0xC056, "TLS_DHE_DSS_WITH_ARIA_128_GCM_SHA256"},
  328. {0xC057, "TLS_DHE_DSS_WITH_ARIA_256_GCM_SHA384"},
  329. {0xC058, "TLS_DH_DSS_WITH_ARIA_128_GCM_SHA256"},
  330. {0xC059, "TLS_DH_DSS_WITH_ARIA_256_GCM_SHA384"},
  331. {0xC05A, "TLS_DH_anon_WITH_ARIA_128_GCM_SHA256"},
  332. {0xC05B, "TLS_DH_anon_WITH_ARIA_256_GCM_SHA384"},
  333. {0xC05C, "TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256"},
  334. {0xC05D, "TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384"},
  335. {0xC05E, "TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256"},
  336. {0xC05F, "TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384"},
  337. {0xC060, "TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256"},
  338. {0xC061, "TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384"},
  339. {0xC062, "TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256"},
  340. {0xC063, "TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384"},
  341. {0xC064, "TLS_PSK_WITH_ARIA_128_CBC_SHA256"},
  342. {0xC065, "TLS_PSK_WITH_ARIA_256_CBC_SHA384"},
  343. {0xC066, "TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256"},
  344. {0xC067, "TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384"},
  345. {0xC068, "TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256"},
  346. {0xC069, "TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384"},
  347. {0xC06A, "TLS_PSK_WITH_ARIA_128_GCM_SHA256"},
  348. {0xC06B, "TLS_PSK_WITH_ARIA_256_GCM_SHA384"},
  349. {0xC06C, "TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256"},
  350. {0xC06D, "TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384"},
  351. {0xC06E, "TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256"},
  352. {0xC06F, "TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384"},
  353. {0xC070, "TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256"},
  354. {0xC071, "TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384"},
  355. {0xC072, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256"},
  356. {0xC073, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384"},
  357. {0xC074, "TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256"},
  358. {0xC075, "TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384"},
  359. {0xC076, "TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256"},
  360. {0xC077, "TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384"},
  361. {0xC078, "TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256"},
  362. {0xC079, "TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384"},
  363. {0xC07A, "TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256"},
  364. {0xC07B, "TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384"},
  365. {0xC07C, "TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256"},
  366. {0xC07D, "TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384"},
  367. {0xC07E, "TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256"},
  368. {0xC07F, "TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384"},
  369. {0xC080, "TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256"},
  370. {0xC081, "TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384"},
  371. {0xC082, "TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256"},
  372. {0xC083, "TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384"},
  373. {0xC084, "TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256"},
  374. {0xC085, "TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384"},
  375. {0xC086, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256"},
  376. {0xC087, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384"},
  377. {0xC088, "TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256"},
  378. {0xC089, "TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384"},
  379. {0xC08A, "TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256"},
  380. {0xC08B, "TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384"},
  381. {0xC08C, "TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256"},
  382. {0xC08D, "TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384"},
  383. {0xC08E, "TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256"},
  384. {0xC08F, "TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384"},
  385. {0xC090, "TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256"},
  386. {0xC091, "TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384"},
  387. {0xC092, "TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256"},
  388. {0xC093, "TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384"},
  389. {0xC094, "TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256"},
  390. {0xC095, "TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384"},
  391. {0xC096, "TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256"},
  392. {0xC097, "TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384"},
  393. {0xC098, "TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256"},
  394. {0xC099, "TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384"},
  395. {0xC09A, "TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256"},
  396. {0xC09B, "TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384"},
  397. {0xC09C, "TLS_RSA_WITH_AES_128_CCM"},
  398. {0xC09D, "TLS_RSA_WITH_AES_256_CCM"},
  399. {0xC09E, "TLS_DHE_RSA_WITH_AES_128_CCM"},
  400. {0xC09F, "TLS_DHE_RSA_WITH_AES_256_CCM"},
  401. {0xC0A0, "TLS_RSA_WITH_AES_128_CCM_8"},
  402. {0xC0A1, "TLS_RSA_WITH_AES_256_CCM_8"},
  403. {0xC0A2, "TLS_DHE_RSA_WITH_AES_128_CCM_8"},
  404. {0xC0A3, "TLS_DHE_RSA_WITH_AES_256_CCM_8"},
  405. {0xC0A4, "TLS_PSK_WITH_AES_128_CCM"},
  406. {0xC0A5, "TLS_PSK_WITH_AES_256_CCM"},
  407. {0xC0A6, "TLS_DHE_PSK_WITH_AES_128_CCM"},
  408. {0xC0A7, "TLS_DHE_PSK_WITH_AES_256_CCM"},
  409. {0xC0A8, "TLS_PSK_WITH_AES_128_CCM_8"},
  410. {0xC0A9, "TLS_PSK_WITH_AES_256_CCM_8"},
  411. {0xC0AA, "TLS_PSK_DHE_WITH_AES_128_CCM_8"},
  412. {0xC0AB, "TLS_PSK_DHE_WITH_AES_256_CCM_8"},
  413. {0xC0AC, "TLS_ECDHE_ECDSA_WITH_AES_128_CCM"},
  414. {0xC0AD, "TLS_ECDHE_ECDSA_WITH_AES_256_CCM"},
  415. {0xC0AE, "TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8"},
  416. {0xC0AF, "TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8"},
  417. {0xC102, "IANA-GOST2012-GOST8912-GOST8912"},
  418. {0xCCA8, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256"},
  419. {0xCCA9, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256"},
  420. {0xCCAA, "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256"},
  421. {0xCCAB, "TLS_PSK_WITH_CHACHA20_POLY1305_SHA256"},
  422. {0xCCAC, "TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256"},
  423. {0xCCAD, "TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256"},
  424. {0xCCAE, "TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256"},
  425. {0x1301, "TLS_AES_128_GCM_SHA256"},
  426. {0x1302, "TLS_AES_256_GCM_SHA384"},
  427. {0x1303, "TLS_CHACHA20_POLY1305_SHA256"},
  428. {0x1304, "TLS_AES_128_CCM_SHA256"},
  429. {0x1305, "TLS_AES_128_CCM_8_SHA256"},
  430. {0xFEFE, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"},
  431. {0xFEFF, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA"},
  432. {0xFF85, "LEGACY-GOST2012-GOST8912-GOST8912"},
  433. {0xFF87, "GOST2012-NULL-GOST12"},
  434. {0xC100, "GOST2012-KUZNYECHIK-KUZNYECHIKOMAC"},
  435. {0xC101, "GOST2012-MAGMA-MAGMAOMAC"},
  436. {0xC102, "GOST2012-GOST8912-IANA"},
  437. };
  438. /* Compression methods */
  439. static const ssl_trace_tbl ssl_comp_tbl[] = {
  440. {0x0000, "No Compression"},
  441. {0x0001, "Zlib Compression"}
  442. };
  443. /* Extensions sorted by ascending id */
  444. static const ssl_trace_tbl ssl_exts_tbl[] = {
  445. {TLSEXT_TYPE_server_name, "server_name"},
  446. {TLSEXT_TYPE_max_fragment_length, "max_fragment_length"},
  447. {TLSEXT_TYPE_client_certificate_url, "client_certificate_url"},
  448. {TLSEXT_TYPE_trusted_ca_keys, "trusted_ca_keys"},
  449. {TLSEXT_TYPE_truncated_hmac, "truncated_hmac"},
  450. {TLSEXT_TYPE_status_request, "status_request"},
  451. {TLSEXT_TYPE_user_mapping, "user_mapping"},
  452. {TLSEXT_TYPE_client_authz, "client_authz"},
  453. {TLSEXT_TYPE_server_authz, "server_authz"},
  454. {TLSEXT_TYPE_cert_type, "cert_type"},
  455. {TLSEXT_TYPE_supported_groups, "supported_groups"},
  456. {TLSEXT_TYPE_ec_point_formats, "ec_point_formats"},
  457. {TLSEXT_TYPE_srp, "srp"},
  458. {TLSEXT_TYPE_signature_algorithms, "signature_algorithms"},
  459. {TLSEXT_TYPE_use_srtp, "use_srtp"},
  460. {TLSEXT_TYPE_application_layer_protocol_negotiation,
  461. "application_layer_protocol_negotiation"},
  462. {TLSEXT_TYPE_signed_certificate_timestamp, "signed_certificate_timestamps"},
  463. {TLSEXT_TYPE_client_cert_type, "client_cert_type"},
  464. {TLSEXT_TYPE_server_cert_type, "server_cert_type"},
  465. {TLSEXT_TYPE_padding, "padding"},
  466. {TLSEXT_TYPE_encrypt_then_mac, "encrypt_then_mac"},
  467. {TLSEXT_TYPE_extended_master_secret, "extended_master_secret"},
  468. {TLSEXT_TYPE_compress_certificate, "compress_certificate"},
  469. {TLSEXT_TYPE_session_ticket, "session_ticket"},
  470. {TLSEXT_TYPE_psk, "psk"},
  471. {TLSEXT_TYPE_early_data, "early_data"},
  472. {TLSEXT_TYPE_supported_versions, "supported_versions"},
  473. {TLSEXT_TYPE_cookie, "cookie_ext"},
  474. {TLSEXT_TYPE_psk_kex_modes, "psk_key_exchange_modes"},
  475. {TLSEXT_TYPE_certificate_authorities, "certificate_authorities"},
  476. {TLSEXT_TYPE_post_handshake_auth, "post_handshake_auth"},
  477. {TLSEXT_TYPE_signature_algorithms_cert, "signature_algorithms_cert"},
  478. {TLSEXT_TYPE_key_share, "key_share"},
  479. {TLSEXT_TYPE_renegotiate, "renegotiate"},
  480. # ifndef OPENSSL_NO_NEXTPROTONEG
  481. {TLSEXT_TYPE_next_proto_neg, "next_proto_neg"},
  482. # endif
  483. };
  484. static const ssl_trace_tbl ssl_groups_tbl[] = {
  485. {1, "sect163k1 (K-163)"},
  486. {2, "sect163r1"},
  487. {3, "sect163r2 (B-163)"},
  488. {4, "sect193r1"},
  489. {5, "sect193r2"},
  490. {6, "sect233k1 (K-233)"},
  491. {7, "sect233r1 (B-233)"},
  492. {8, "sect239k1"},
  493. {9, "sect283k1 (K-283)"},
  494. {10, "sect283r1 (B-283)"},
  495. {11, "sect409k1 (K-409)"},
  496. {12, "sect409r1 (B-409)"},
  497. {13, "sect571k1 (K-571)"},
  498. {14, "sect571r1 (B-571)"},
  499. {15, "secp160k1"},
  500. {16, "secp160r1"},
  501. {17, "secp160r2"},
  502. {18, "secp192k1"},
  503. {19, "secp192r1 (P-192)"},
  504. {20, "secp224k1"},
  505. {21, "secp224r1 (P-224)"},
  506. {22, "secp256k1"},
  507. {23, "secp256r1 (P-256)"},
  508. {24, "secp384r1 (P-384)"},
  509. {25, "secp521r1 (P-521)"},
  510. {26, "brainpoolP256r1"},
  511. {27, "brainpoolP384r1"},
  512. {28, "brainpoolP512r1"},
  513. {29, "ecdh_x25519"},
  514. {30, "ecdh_x448"},
  515. {31, "brainpoolP256r1tls13"},
  516. {32, "brainpoolP384r1tls13"},
  517. {33, "brainpoolP512r1tls13"},
  518. {34, "GC256A"},
  519. {35, "GC256B"},
  520. {36, "GC256C"},
  521. {37, "GC256D"},
  522. {38, "GC512A"},
  523. {39, "GC512B"},
  524. {40, "GC512C"},
  525. {256, "ffdhe2048"},
  526. {257, "ffdhe3072"},
  527. {258, "ffdhe4096"},
  528. {259, "ffdhe6144"},
  529. {260, "ffdhe8192"},
  530. {25497, "X25519Kyber768Draft00"},
  531. {25498, "SecP256r1Kyber768Draft00"},
  532. {0xFF01, "arbitrary_explicit_prime_curves"},
  533. {0xFF02, "arbitrary_explicit_char2_curves"}
  534. };
  535. static const ssl_trace_tbl ssl_point_tbl[] = {
  536. {0, "uncompressed"},
  537. {1, "ansiX962_compressed_prime"},
  538. {2, "ansiX962_compressed_char2"}
  539. };
  540. static const ssl_trace_tbl ssl_mfl_tbl[] = {
  541. {0, "disabled"},
  542. {1, "max_fragment_length := 2^9 (512 bytes)"},
  543. {2, "max_fragment_length := 2^10 (1024 bytes)"},
  544. {3, "max_fragment_length := 2^11 (2048 bytes)"},
  545. {4, "max_fragment_length := 2^12 (4096 bytes)"}
  546. };
  547. static const ssl_trace_tbl ssl_sigalg_tbl[] = {
  548. {TLSEXT_SIGALG_ecdsa_secp256r1_sha256, "ecdsa_secp256r1_sha256"},
  549. {TLSEXT_SIGALG_ecdsa_secp384r1_sha384, "ecdsa_secp384r1_sha384"},
  550. {TLSEXT_SIGALG_ecdsa_secp521r1_sha512, "ecdsa_secp521r1_sha512"},
  551. {TLSEXT_SIGALG_ecdsa_sha224, "ecdsa_sha224"},
  552. {TLSEXT_SIGALG_ed25519, "ed25519"},
  553. {TLSEXT_SIGALG_ed448, "ed448"},
  554. {TLSEXT_SIGALG_ecdsa_sha1, "ecdsa_sha1"},
  555. {TLSEXT_SIGALG_rsa_pss_rsae_sha256, "rsa_pss_rsae_sha256"},
  556. {TLSEXT_SIGALG_rsa_pss_rsae_sha384, "rsa_pss_rsae_sha384"},
  557. {TLSEXT_SIGALG_rsa_pss_rsae_sha512, "rsa_pss_rsae_sha512"},
  558. {TLSEXT_SIGALG_rsa_pss_pss_sha256, "rsa_pss_pss_sha256"},
  559. {TLSEXT_SIGALG_rsa_pss_pss_sha384, "rsa_pss_pss_sha384"},
  560. {TLSEXT_SIGALG_rsa_pss_pss_sha512, "rsa_pss_pss_sha512"},
  561. {TLSEXT_SIGALG_rsa_pkcs1_sha256, "rsa_pkcs1_sha256"},
  562. {TLSEXT_SIGALG_rsa_pkcs1_sha384, "rsa_pkcs1_sha384"},
  563. {TLSEXT_SIGALG_rsa_pkcs1_sha512, "rsa_pkcs1_sha512"},
  564. {TLSEXT_SIGALG_rsa_pkcs1_sha224, "rsa_pkcs1_sha224"},
  565. {TLSEXT_SIGALG_rsa_pkcs1_sha1, "rsa_pkcs1_sha1"},
  566. {TLSEXT_SIGALG_dsa_sha256, "dsa_sha256"},
  567. {TLSEXT_SIGALG_dsa_sha384, "dsa_sha384"},
  568. {TLSEXT_SIGALG_dsa_sha512, "dsa_sha512"},
  569. {TLSEXT_SIGALG_dsa_sha224, "dsa_sha224"},
  570. {TLSEXT_SIGALG_dsa_sha1, "dsa_sha1"},
  571. {TLSEXT_SIGALG_gostr34102012_256_intrinsic, "gost2012_256"},
  572. {TLSEXT_SIGALG_gostr34102012_512_intrinsic, "gost2012_512"},
  573. {TLSEXT_SIGALG_gostr34102012_256_gostr34112012_256, "gost2012_256"},
  574. {TLSEXT_SIGALG_gostr34102012_512_gostr34112012_512, "gost2012_512"},
  575. {TLSEXT_SIGALG_gostr34102001_gostr3411, "gost2001_gost94"},
  576. {TLSEXT_SIGALG_ecdsa_brainpoolP256r1_sha256, "ecdsa_brainpoolP256r1_sha256"},
  577. {TLSEXT_SIGALG_ecdsa_brainpoolP384r1_sha384, "ecdsa_brainpoolP384r1_sha384"},
  578. {TLSEXT_SIGALG_ecdsa_brainpoolP512r1_sha512, "ecdsa_brainpoolP512r1_sha512"},
  579. };
  580. static const ssl_trace_tbl ssl_ctype_tbl[] = {
  581. {1, "rsa_sign"},
  582. {2, "dss_sign"},
  583. {3, "rsa_fixed_dh"},
  584. {4, "dss_fixed_dh"},
  585. {5, "rsa_ephemeral_dh"},
  586. {6, "dss_ephemeral_dh"},
  587. {20, "fortezza_dms"},
  588. {64, "ecdsa_sign"},
  589. {65, "rsa_fixed_ecdh"},
  590. {66, "ecdsa_fixed_ecdh"},
  591. {67, "gost_sign256"},
  592. {68, "gost_sign512"},
  593. };
  594. static const ssl_trace_tbl ssl_psk_kex_modes_tbl[] = {
  595. {TLSEXT_KEX_MODE_KE, "psk_ke"},
  596. {TLSEXT_KEX_MODE_KE_DHE, "psk_dhe_ke"}
  597. };
  598. static const ssl_trace_tbl ssl_key_update_tbl[] = {
  599. {SSL_KEY_UPDATE_NOT_REQUESTED, "update_not_requested"},
  600. {SSL_KEY_UPDATE_REQUESTED, "update_requested"}
  601. };
  602. static const ssl_trace_tbl ssl_comp_cert_tbl[] = {
  603. {TLSEXT_comp_cert_none, "none"},
  604. {TLSEXT_comp_cert_zlib, "zlib"},
  605. {TLSEXT_comp_cert_brotli, "brotli"},
  606. {TLSEXT_comp_cert_zstd, "zstd"}
  607. };
  608. /*
  609. * "pgp" and "1609dot2" are defined in RFC7250,
  610. * although OpenSSL doesn't support them, it can
  611. * at least report them in traces
  612. */
  613. static const ssl_trace_tbl ssl_cert_type_tbl[] = {
  614. {TLSEXT_cert_type_x509, "x509"},
  615. {TLSEXT_cert_type_pgp, "pgp"},
  616. {TLSEXT_cert_type_rpk, "rpk"},
  617. {TLSEXT_cert_type_1609dot2, "1609dot2"}
  618. };
  619. static void ssl_print_hex(BIO *bio, int indent, const char *name,
  620. const unsigned char *msg, size_t msglen)
  621. {
  622. size_t i;
  623. BIO_indent(bio, indent, 80);
  624. BIO_printf(bio, "%s (len=%d): ", name, (int)msglen);
  625. for (i = 0; i < msglen; i++)
  626. BIO_printf(bio, "%02X", msg[i]);
  627. BIO_puts(bio, "\n");
  628. }
  629. static int ssl_print_hexbuf(BIO *bio, int indent, const char *name, size_t nlen,
  630. const unsigned char **pmsg, size_t *pmsglen)
  631. {
  632. size_t blen;
  633. const unsigned char *p = *pmsg;
  634. if (*pmsglen < nlen)
  635. return 0;
  636. blen = p[0];
  637. if (nlen > 1)
  638. blen = (blen << 8) | p[1];
  639. if (*pmsglen < nlen + blen)
  640. return 0;
  641. p += nlen;
  642. ssl_print_hex(bio, indent, name, p, blen);
  643. *pmsg += blen + nlen;
  644. *pmsglen -= blen + nlen;
  645. return 1;
  646. }
  647. static int ssl_print_version(BIO *bio, int indent, const char *name,
  648. const unsigned char **pmsg, size_t *pmsglen,
  649. unsigned int *version)
  650. {
  651. int vers;
  652. if (*pmsglen < 2)
  653. return 0;
  654. vers = ((*pmsg)[0] << 8) | (*pmsg)[1];
  655. if (version != NULL)
  656. *version = vers;
  657. BIO_indent(bio, indent, 80);
  658. BIO_printf(bio, "%s=0x%x (%s)\n",
  659. name, vers, ssl_trace_str(vers, ssl_version_tbl));
  660. *pmsg += 2;
  661. *pmsglen -= 2;
  662. return 1;
  663. }
  664. static int ssl_print_random(BIO *bio, int indent,
  665. const unsigned char **pmsg, size_t *pmsglen)
  666. {
  667. unsigned int tm;
  668. const unsigned char *p = *pmsg;
  669. if (*pmsglen < 32)
  670. return 0;
  671. tm = ((unsigned int)p[0] << 24)
  672. | ((unsigned int)p[1] << 16)
  673. | ((unsigned int)p[2] << 8)
  674. | (unsigned int)p[3];
  675. p += 4;
  676. BIO_indent(bio, indent, 80);
  677. BIO_puts(bio, "Random:\n");
  678. BIO_indent(bio, indent + 2, 80);
  679. BIO_printf(bio, "gmt_unix_time=0x%08X\n", tm);
  680. ssl_print_hex(bio, indent + 2, "random_bytes", p, 28);
  681. *pmsg += 32;
  682. *pmsglen -= 32;
  683. return 1;
  684. }
  685. static int ssl_print_signature(BIO *bio, int indent, const SSL_CONNECTION *sc,
  686. const unsigned char **pmsg, size_t *pmsglen)
  687. {
  688. if (*pmsglen < 2)
  689. return 0;
  690. if (SSL_USE_SIGALGS(sc)) {
  691. const unsigned char *p = *pmsg;
  692. unsigned int sigalg = (p[0] << 8) | p[1];
  693. BIO_indent(bio, indent, 80);
  694. BIO_printf(bio, "Signature Algorithm: %s (0x%04x)\n",
  695. ssl_trace_str(sigalg, ssl_sigalg_tbl), sigalg);
  696. *pmsg += 2;
  697. *pmsglen -= 2;
  698. }
  699. return ssl_print_hexbuf(bio, indent, "Signature", 2, pmsg, pmsglen);
  700. }
  701. static int ssl_print_extension(BIO *bio, int indent, int server,
  702. unsigned char mt, int extype,
  703. const unsigned char *ext, size_t extlen)
  704. {
  705. size_t xlen, share_len;
  706. unsigned int sigalg;
  707. uint32_t max_early_data;
  708. BIO_indent(bio, indent, 80);
  709. BIO_printf(bio, "extension_type=%s(%d), length=%d\n",
  710. ssl_trace_str(extype, ssl_exts_tbl), extype, (int)extlen);
  711. switch (extype) {
  712. case TLSEXT_TYPE_compress_certificate:
  713. if (extlen < 1)
  714. return 0;
  715. xlen = ext[0];
  716. if (extlen != xlen + 1)
  717. return 0;
  718. return ssl_trace_list(bio, indent + 2, ext + 1, xlen, 2, ssl_comp_cert_tbl);
  719. case TLSEXT_TYPE_max_fragment_length:
  720. if (extlen < 1)
  721. return 0;
  722. xlen = extlen;
  723. return ssl_trace_list(bio, indent + 2, ext, xlen, 1, ssl_mfl_tbl);
  724. case TLSEXT_TYPE_ec_point_formats:
  725. if (extlen < 1)
  726. return 0;
  727. xlen = ext[0];
  728. if (extlen != xlen + 1)
  729. return 0;
  730. return ssl_trace_list(bio, indent + 2, ext + 1, xlen, 1, ssl_point_tbl);
  731. case TLSEXT_TYPE_supported_groups:
  732. if (extlen < 2)
  733. return 0;
  734. xlen = (ext[0] << 8) | ext[1];
  735. if (extlen != xlen + 2)
  736. return 0;
  737. return ssl_trace_list(bio, indent + 2, ext + 2, xlen, 2, ssl_groups_tbl);
  738. case TLSEXT_TYPE_application_layer_protocol_negotiation:
  739. if (extlen < 2)
  740. return 0;
  741. xlen = (ext[0] << 8) | ext[1];
  742. if (extlen != xlen + 2)
  743. return 0;
  744. ext += 2;
  745. while (xlen > 0) {
  746. size_t plen = *ext++;
  747. if (plen + 1 > xlen)
  748. return 0;
  749. BIO_indent(bio, indent + 2, 80);
  750. BIO_write(bio, ext, plen);
  751. BIO_puts(bio, "\n");
  752. ext += plen;
  753. xlen -= plen + 1;
  754. }
  755. return 1;
  756. case TLSEXT_TYPE_signature_algorithms:
  757. if (extlen < 2)
  758. return 0;
  759. xlen = (ext[0] << 8) | ext[1];
  760. if (extlen != xlen + 2)
  761. return 0;
  762. if (xlen & 1)
  763. return 0;
  764. ext += 2;
  765. while (xlen > 0) {
  766. BIO_indent(bio, indent + 2, 80);
  767. sigalg = (ext[0] << 8) | ext[1];
  768. BIO_printf(bio, "%s (0x%04x)\n",
  769. ssl_trace_str(sigalg, ssl_sigalg_tbl), sigalg);
  770. xlen -= 2;
  771. ext += 2;
  772. }
  773. break;
  774. case TLSEXT_TYPE_renegotiate:
  775. if (extlen < 1)
  776. return 0;
  777. xlen = ext[0];
  778. if (xlen + 1 != extlen)
  779. return 0;
  780. ext++;
  781. if (xlen) {
  782. if (server) {
  783. if (xlen & 1)
  784. return 0;
  785. xlen >>= 1;
  786. }
  787. ssl_print_hex(bio, indent + 4, "client_verify_data", ext, xlen);
  788. if (server) {
  789. ext += xlen;
  790. ssl_print_hex(bio, indent + 4, "server_verify_data", ext, xlen);
  791. }
  792. } else {
  793. BIO_indent(bio, indent + 4, 80);
  794. BIO_puts(bio, "<EMPTY>\n");
  795. }
  796. break;
  797. case TLSEXT_TYPE_session_ticket:
  798. if (extlen != 0)
  799. ssl_print_hex(bio, indent + 4, "ticket", ext, extlen);
  800. break;
  801. case TLSEXT_TYPE_key_share:
  802. if (server && extlen == 2) {
  803. int group_id;
  804. /* We assume this is an HRR, otherwise this is an invalid key_share */
  805. group_id = (ext[0] << 8) | ext[1];
  806. BIO_indent(bio, indent + 4, 80);
  807. BIO_printf(bio, "NamedGroup: %s (%d)\n",
  808. ssl_trace_str(group_id, ssl_groups_tbl), group_id);
  809. break;
  810. }
  811. if (extlen < 2)
  812. return 0;
  813. if (server) {
  814. xlen = extlen;
  815. } else {
  816. xlen = (ext[0] << 8) | ext[1];
  817. if (extlen != xlen + 2)
  818. return 0;
  819. ext += 2;
  820. }
  821. for (; xlen > 0; ext += share_len, xlen -= share_len) {
  822. int group_id;
  823. if (xlen < 4)
  824. return 0;
  825. group_id = (ext[0] << 8) | ext[1];
  826. share_len = (ext[2] << 8) | ext[3];
  827. ext += 4;
  828. xlen -= 4;
  829. if (xlen < share_len)
  830. return 0;
  831. BIO_indent(bio, indent + 4, 80);
  832. BIO_printf(bio, "NamedGroup: %s (%d)\n",
  833. ssl_trace_str(group_id, ssl_groups_tbl), group_id);
  834. ssl_print_hex(bio, indent + 4, "key_exchange: ", ext, share_len);
  835. }
  836. break;
  837. case TLSEXT_TYPE_supported_versions:
  838. if (server) {
  839. int version;
  840. if (extlen != 2)
  841. return 0;
  842. version = (ext[0] << 8) | ext[1];
  843. BIO_indent(bio, indent + 4, 80);
  844. BIO_printf(bio, "%s (%d)\n",
  845. ssl_trace_str(version, ssl_version_tbl), version);
  846. break;
  847. }
  848. if (extlen < 1)
  849. return 0;
  850. xlen = ext[0];
  851. if (extlen != xlen + 1)
  852. return 0;
  853. return ssl_trace_list(bio, indent + 2, ext + 1, xlen, 2,
  854. ssl_version_tbl);
  855. case TLSEXT_TYPE_psk_kex_modes:
  856. if (extlen < 1)
  857. return 0;
  858. xlen = ext[0];
  859. if (extlen != xlen + 1)
  860. return 0;
  861. return ssl_trace_list(bio, indent + 2, ext + 1, xlen, 1,
  862. ssl_psk_kex_modes_tbl);
  863. case TLSEXT_TYPE_early_data:
  864. if (mt != SSL3_MT_NEWSESSION_TICKET)
  865. break;
  866. if (extlen != 4)
  867. return 0;
  868. max_early_data = ((unsigned int)ext[0] << 24)
  869. | ((unsigned int)ext[1] << 16)
  870. | ((unsigned int)ext[2] << 8)
  871. | (unsigned int)ext[3];
  872. BIO_indent(bio, indent + 2, 80);
  873. BIO_printf(bio, "max_early_data=%u\n", (unsigned int)max_early_data);
  874. break;
  875. case TLSEXT_TYPE_server_cert_type:
  876. case TLSEXT_TYPE_client_cert_type:
  877. if (server) {
  878. if (extlen != 1)
  879. return 0;
  880. return ssl_trace_list(bio, indent + 2, ext, 1, 1, ssl_cert_type_tbl);
  881. }
  882. if (extlen < 1)
  883. return 0;
  884. xlen = ext[0];
  885. if (extlen != xlen + 1)
  886. return 0;
  887. return ssl_trace_list(bio, indent + 2, ext + 1, xlen, 1, ssl_cert_type_tbl);
  888. default:
  889. BIO_dump_indent(bio, (const char *)ext, extlen, indent + 2);
  890. }
  891. return 1;
  892. }
  893. static int ssl_print_extensions(BIO *bio, int indent, int server,
  894. unsigned char mt, const unsigned char **msgin,
  895. size_t *msginlen)
  896. {
  897. size_t extslen, msglen = *msginlen;
  898. const unsigned char *msg = *msgin;
  899. BIO_indent(bio, indent, 80);
  900. if (msglen == 0) {
  901. BIO_puts(bio, "No extensions\n");
  902. return 1;
  903. }
  904. if (msglen < 2)
  905. return 0;
  906. extslen = (msg[0] << 8) | msg[1];
  907. msglen -= 2;
  908. msg += 2;
  909. if (extslen == 0) {
  910. BIO_puts(bio, "No extensions\n");
  911. *msgin = msg;
  912. *msginlen = msglen;
  913. return 1;
  914. }
  915. if (extslen > msglen)
  916. return 0;
  917. BIO_printf(bio, "extensions, length = %d\n", (int)extslen);
  918. msglen -= extslen;
  919. while (extslen > 0) {
  920. int extype;
  921. size_t extlen;
  922. if (extslen < 4)
  923. return 0;
  924. extype = (msg[0] << 8) | msg[1];
  925. extlen = (msg[2] << 8) | msg[3];
  926. if (extslen < extlen + 4) {
  927. BIO_printf(bio, "extensions, extype = %d, extlen = %d\n", extype,
  928. (int)extlen);
  929. BIO_dump_indent(bio, (const char *)msg, extslen, indent + 2);
  930. return 0;
  931. }
  932. msg += 4;
  933. if (!ssl_print_extension(bio, indent + 2, server, mt, extype, msg,
  934. extlen))
  935. return 0;
  936. msg += extlen;
  937. extslen -= extlen + 4;
  938. }
  939. *msgin = msg;
  940. *msginlen = msglen;
  941. return 1;
  942. }
  943. static int ssl_print_client_hello(BIO *bio, const SSL_CONNECTION *sc, int indent,
  944. const unsigned char *msg, size_t msglen)
  945. {
  946. size_t len;
  947. unsigned int cs;
  948. if (!ssl_print_version(bio, indent, "client_version", &msg, &msglen, NULL))
  949. return 0;
  950. if (!ssl_print_random(bio, indent, &msg, &msglen))
  951. return 0;
  952. if (!ssl_print_hexbuf(bio, indent, "session_id", 1, &msg, &msglen))
  953. return 0;
  954. if (SSL_CONNECTION_IS_DTLS(sc)) {
  955. if (!ssl_print_hexbuf(bio, indent, "cookie", 1, &msg, &msglen))
  956. return 0;
  957. }
  958. if (msglen < 2)
  959. return 0;
  960. len = (msg[0] << 8) | msg[1];
  961. msg += 2;
  962. msglen -= 2;
  963. BIO_indent(bio, indent, 80);
  964. BIO_printf(bio, "cipher_suites (len=%d)\n", (int)len);
  965. if (msglen < len || len & 1)
  966. return 0;
  967. while (len > 0) {
  968. cs = (msg[0] << 8) | msg[1];
  969. BIO_indent(bio, indent + 2, 80);
  970. BIO_printf(bio, "{0x%02X, 0x%02X} %s\n",
  971. msg[0], msg[1], ssl_trace_str(cs, ssl_ciphers_tbl));
  972. msg += 2;
  973. msglen -= 2;
  974. len -= 2;
  975. }
  976. if (msglen < 1)
  977. return 0;
  978. len = msg[0];
  979. msg++;
  980. msglen--;
  981. if (msglen < len)
  982. return 0;
  983. BIO_indent(bio, indent, 80);
  984. BIO_printf(bio, "compression_methods (len=%d)\n", (int)len);
  985. while (len > 0) {
  986. BIO_indent(bio, indent + 2, 80);
  987. BIO_printf(bio, "%s (0x%02X)\n",
  988. ssl_trace_str(msg[0], ssl_comp_tbl), msg[0]);
  989. msg++;
  990. msglen--;
  991. len--;
  992. }
  993. if (!ssl_print_extensions(bio, indent, 0, SSL3_MT_CLIENT_HELLO, &msg,
  994. &msglen))
  995. return 0;
  996. return 1;
  997. }
  998. static int dtls_print_hello_vfyrequest(BIO *bio, int indent,
  999. const unsigned char *msg, size_t msglen)
  1000. {
  1001. if (!ssl_print_version(bio, indent, "server_version", &msg, &msglen, NULL))
  1002. return 0;
  1003. if (!ssl_print_hexbuf(bio, indent, "cookie", 1, &msg, &msglen))
  1004. return 0;
  1005. return 1;
  1006. }
  1007. static int ssl_print_server_hello(BIO *bio, int indent,
  1008. const unsigned char *msg, size_t msglen)
  1009. {
  1010. unsigned int cs;
  1011. unsigned int vers;
  1012. if (!ssl_print_version(bio, indent, "server_version", &msg, &msglen, &vers))
  1013. return 0;
  1014. if (!ssl_print_random(bio, indent, &msg, &msglen))
  1015. return 0;
  1016. if (vers != TLS1_3_VERSION
  1017. && !ssl_print_hexbuf(bio, indent, "session_id", 1, &msg, &msglen))
  1018. return 0;
  1019. if (msglen < 2)
  1020. return 0;
  1021. cs = (msg[0] << 8) | msg[1];
  1022. BIO_indent(bio, indent, 80);
  1023. BIO_printf(bio, "cipher_suite {0x%02X, 0x%02X} %s\n",
  1024. msg[0], msg[1], ssl_trace_str(cs, ssl_ciphers_tbl));
  1025. msg += 2;
  1026. msglen -= 2;
  1027. if (vers != TLS1_3_VERSION) {
  1028. if (msglen < 1)
  1029. return 0;
  1030. BIO_indent(bio, indent, 80);
  1031. BIO_printf(bio, "compression_method: %s (0x%02X)\n",
  1032. ssl_trace_str(msg[0], ssl_comp_tbl), msg[0]);
  1033. msg++;
  1034. msglen--;
  1035. }
  1036. if (!ssl_print_extensions(bio, indent, 1, SSL3_MT_SERVER_HELLO, &msg,
  1037. &msglen))
  1038. return 0;
  1039. return 1;
  1040. }
  1041. static int ssl_get_keyex(const char **pname, const SSL_CONNECTION *sc)
  1042. {
  1043. unsigned long alg_k = sc->s3.tmp.new_cipher->algorithm_mkey;
  1044. if (alg_k & SSL_kRSA) {
  1045. *pname = "rsa";
  1046. return SSL_kRSA;
  1047. }
  1048. if (alg_k & SSL_kDHE) {
  1049. *pname = "DHE";
  1050. return SSL_kDHE;
  1051. }
  1052. if (alg_k & SSL_kECDHE) {
  1053. *pname = "ECDHE";
  1054. return SSL_kECDHE;
  1055. }
  1056. if (alg_k & SSL_kPSK) {
  1057. *pname = "PSK";
  1058. return SSL_kPSK;
  1059. }
  1060. if (alg_k & SSL_kRSAPSK) {
  1061. *pname = "RSAPSK";
  1062. return SSL_kRSAPSK;
  1063. }
  1064. if (alg_k & SSL_kDHEPSK) {
  1065. *pname = "DHEPSK";
  1066. return SSL_kDHEPSK;
  1067. }
  1068. if (alg_k & SSL_kECDHEPSK) {
  1069. *pname = "ECDHEPSK";
  1070. return SSL_kECDHEPSK;
  1071. }
  1072. if (alg_k & SSL_kSRP) {
  1073. *pname = "SRP";
  1074. return SSL_kSRP;
  1075. }
  1076. if (alg_k & SSL_kGOST) {
  1077. *pname = "GOST";
  1078. return SSL_kGOST;
  1079. }
  1080. if (alg_k & SSL_kGOST18) {
  1081. *pname = "GOST18";
  1082. return SSL_kGOST18;
  1083. }
  1084. *pname = "UNKNOWN";
  1085. return 0;
  1086. }
  1087. static int ssl_print_client_keyex(BIO *bio, int indent, const SSL_CONNECTION *sc,
  1088. const unsigned char *msg, size_t msglen)
  1089. {
  1090. const char *algname;
  1091. int id = ssl_get_keyex(&algname, sc);
  1092. BIO_indent(bio, indent, 80);
  1093. BIO_printf(bio, "KeyExchangeAlgorithm=%s\n", algname);
  1094. if (id & SSL_PSK) {
  1095. if (!ssl_print_hexbuf(bio, indent + 2,
  1096. "psk_identity", 2, &msg, &msglen))
  1097. return 0;
  1098. }
  1099. switch (id) {
  1100. case SSL_kRSA:
  1101. case SSL_kRSAPSK:
  1102. if (TLS1_get_version(SSL_CONNECTION_GET_SSL(sc)) == SSL3_VERSION) {
  1103. ssl_print_hex(bio, indent + 2,
  1104. "EncryptedPreMasterSecret", msg, msglen);
  1105. } else {
  1106. if (!ssl_print_hexbuf(bio, indent + 2,
  1107. "EncryptedPreMasterSecret", 2, &msg, &msglen))
  1108. return 0;
  1109. }
  1110. break;
  1111. case SSL_kDHE:
  1112. case SSL_kDHEPSK:
  1113. if (!ssl_print_hexbuf(bio, indent + 2, "dh_Yc", 2, &msg, &msglen))
  1114. return 0;
  1115. break;
  1116. case SSL_kECDHE:
  1117. case SSL_kECDHEPSK:
  1118. if (!ssl_print_hexbuf(bio, indent + 2, "ecdh_Yc", 1, &msg, &msglen))
  1119. return 0;
  1120. break;
  1121. case SSL_kGOST:
  1122. ssl_print_hex(bio, indent + 2, "GostKeyTransportBlob", msg, msglen);
  1123. msglen = 0;
  1124. break;
  1125. case SSL_kGOST18:
  1126. ssl_print_hex(bio, indent + 2,
  1127. "GOST-wrapped PreMasterSecret", msg, msglen);
  1128. msglen = 0;
  1129. break;
  1130. }
  1131. return !msglen;
  1132. }
  1133. static int ssl_print_server_keyex(BIO *bio, int indent, const SSL_CONNECTION *sc,
  1134. const unsigned char *msg, size_t msglen)
  1135. {
  1136. const char *algname;
  1137. int id = ssl_get_keyex(&algname, sc);
  1138. BIO_indent(bio, indent, 80);
  1139. BIO_printf(bio, "KeyExchangeAlgorithm=%s\n", algname);
  1140. if (id & SSL_PSK) {
  1141. if (!ssl_print_hexbuf(bio, indent + 2,
  1142. "psk_identity_hint", 2, &msg, &msglen))
  1143. return 0;
  1144. }
  1145. switch (id) {
  1146. case SSL_kRSA:
  1147. if (!ssl_print_hexbuf(bio, indent + 2, "rsa_modulus", 2, &msg, &msglen))
  1148. return 0;
  1149. if (!ssl_print_hexbuf(bio, indent + 2, "rsa_exponent", 2,
  1150. &msg, &msglen))
  1151. return 0;
  1152. break;
  1153. case SSL_kDHE:
  1154. case SSL_kDHEPSK:
  1155. if (!ssl_print_hexbuf(bio, indent + 2, "dh_p", 2, &msg, &msglen))
  1156. return 0;
  1157. if (!ssl_print_hexbuf(bio, indent + 2, "dh_g", 2, &msg, &msglen))
  1158. return 0;
  1159. if (!ssl_print_hexbuf(bio, indent + 2, "dh_Ys", 2, &msg, &msglen))
  1160. return 0;
  1161. break;
  1162. case SSL_kECDHE:
  1163. case SSL_kECDHEPSK:
  1164. if (msglen < 1)
  1165. return 0;
  1166. BIO_indent(bio, indent + 2, 80);
  1167. if (msg[0] == EXPLICIT_PRIME_CURVE_TYPE)
  1168. BIO_puts(bio, "explicit_prime\n");
  1169. else if (msg[0] == EXPLICIT_CHAR2_CURVE_TYPE)
  1170. BIO_puts(bio, "explicit_char2\n");
  1171. else if (msg[0] == NAMED_CURVE_TYPE) {
  1172. int curve;
  1173. if (msglen < 3)
  1174. return 0;
  1175. curve = (msg[1] << 8) | msg[2];
  1176. BIO_printf(bio, "named_curve: %s (%d)\n",
  1177. ssl_trace_str(curve, ssl_groups_tbl), curve);
  1178. msg += 3;
  1179. msglen -= 3;
  1180. if (!ssl_print_hexbuf(bio, indent + 2, "point", 1, &msg, &msglen))
  1181. return 0;
  1182. } else {
  1183. BIO_printf(bio, "UNKNOWN CURVE PARAMETER TYPE %d\n", msg[0]);
  1184. return 0;
  1185. }
  1186. break;
  1187. case SSL_kPSK:
  1188. case SSL_kRSAPSK:
  1189. break;
  1190. }
  1191. if (!(id & SSL_PSK))
  1192. ssl_print_signature(bio, indent, sc, &msg, &msglen);
  1193. return !msglen;
  1194. }
  1195. static int ssl_print_certificate(BIO *bio, const SSL_CONNECTION *sc, int indent,
  1196. const unsigned char **pmsg, size_t *pmsglen)
  1197. {
  1198. size_t msglen = *pmsglen;
  1199. size_t clen;
  1200. X509 *x;
  1201. const unsigned char *p = *pmsg, *q;
  1202. SSL_CTX *ctx = SSL_CONNECTION_GET_CTX(sc);
  1203. if (msglen < 3)
  1204. return 0;
  1205. clen = (p[0] << 16) | (p[1] << 8) | p[2];
  1206. if (msglen < clen + 3)
  1207. return 0;
  1208. q = p + 3;
  1209. BIO_indent(bio, indent, 80);
  1210. BIO_printf(bio, "ASN.1Cert, length=%d", (int)clen);
  1211. x = X509_new_ex(ctx->libctx, ctx->propq);
  1212. if (x != NULL && d2i_X509(&x, &q, clen) == NULL) {
  1213. X509_free(x);
  1214. x = NULL;
  1215. }
  1216. if (x == NULL)
  1217. BIO_puts(bio, "<UNPARSEABLE CERTIFICATE>\n");
  1218. else {
  1219. BIO_puts(bio, "\n------details-----\n");
  1220. X509_print_ex(bio, x, XN_FLAG_ONELINE, 0);
  1221. PEM_write_bio_X509(bio, x);
  1222. /* Print certificate stuff */
  1223. BIO_puts(bio, "------------------\n");
  1224. X509_free(x);
  1225. }
  1226. if (q != p + 3 + clen) {
  1227. BIO_puts(bio, "<TRAILING GARBAGE AFTER CERTIFICATE>\n");
  1228. }
  1229. *pmsg += clen + 3;
  1230. *pmsglen -= clen + 3;
  1231. return 1;
  1232. }
  1233. static int ssl_print_raw_public_key(BIO *bio, const SSL *ssl, int server,
  1234. int indent, const unsigned char **pmsg,
  1235. size_t *pmsglen)
  1236. {
  1237. EVP_PKEY *pkey;
  1238. size_t clen;
  1239. const unsigned char *msg = *pmsg;
  1240. size_t msglen = *pmsglen;
  1241. if (msglen < 3)
  1242. return 0;
  1243. clen = (msg[0] << 16) | (msg[1] << 8) | msg[2];
  1244. if (msglen < clen + 3)
  1245. return 0;
  1246. msg += 3;
  1247. BIO_indent(bio, indent, 80);
  1248. BIO_printf(bio, "raw_public_key, length=%d\n", (int)clen);
  1249. pkey = d2i_PUBKEY_ex(NULL, &msg, clen, ssl->ctx->libctx, ssl->ctx->propq);
  1250. if (pkey == NULL)
  1251. return 0;
  1252. EVP_PKEY_print_public(bio, pkey, indent + 2, NULL);
  1253. EVP_PKEY_free(pkey);
  1254. *pmsg += clen + 3;
  1255. *pmsglen -= clen + 3;
  1256. return 1;
  1257. }
  1258. static int ssl_print_certificates(BIO *bio, const SSL_CONNECTION *sc, int server,
  1259. int indent, const unsigned char *msg,
  1260. size_t msglen)
  1261. {
  1262. size_t clen;
  1263. if (SSL_CONNECTION_IS_TLS13(sc)
  1264. && !ssl_print_hexbuf(bio, indent, "context", 1, &msg, &msglen))
  1265. return 0;
  1266. if (msglen < 3)
  1267. return 0;
  1268. clen = (msg[0] << 16) | (msg[1] << 8) | msg[2];
  1269. if (msglen != clen + 3)
  1270. return 0;
  1271. msg += 3;
  1272. if ((server && sc->ext.server_cert_type == TLSEXT_cert_type_rpk)
  1273. || (!server && sc->ext.client_cert_type == TLSEXT_cert_type_rpk)) {
  1274. if (!ssl_print_raw_public_key(bio, &sc->ssl, server, indent, &msg, &clen))
  1275. return 0;
  1276. if (SSL_CONNECTION_IS_TLS13(sc)
  1277. && !ssl_print_extensions(bio, indent + 2, server,
  1278. SSL3_MT_CERTIFICATE, &msg, &clen))
  1279. return 0;
  1280. return 1;
  1281. }
  1282. BIO_indent(bio, indent, 80);
  1283. BIO_printf(bio, "certificate_list, length=%d\n", (int)clen);
  1284. while (clen > 0) {
  1285. if (!ssl_print_certificate(bio, sc, indent + 2, &msg, &clen))
  1286. return 0;
  1287. if (SSL_CONNECTION_IS_TLS13(sc)
  1288. && !ssl_print_extensions(bio, indent + 2, server,
  1289. SSL3_MT_CERTIFICATE, &msg, &clen))
  1290. return 0;
  1291. }
  1292. return 1;
  1293. }
  1294. static int ssl_print_compressed_certificates(BIO *bio, const SSL_CONNECTION *sc,
  1295. int server, int indent,
  1296. const unsigned char *msg,
  1297. size_t msglen)
  1298. {
  1299. size_t uclen;
  1300. size_t clen;
  1301. unsigned int alg;
  1302. int ret = 1;
  1303. #ifndef OPENSSL_NO_COMP_ALG
  1304. COMP_METHOD *method;
  1305. COMP_CTX *comp = NULL;
  1306. unsigned char* ucdata = NULL;
  1307. #endif
  1308. if (msglen < 8)
  1309. return 0;
  1310. alg = (msg[0] << 8) | msg[1];
  1311. uclen = (msg[2] << 16) | (msg[3] << 8) | msg[4];
  1312. clen = (msg[5] << 16) | (msg[6] << 8) | msg[7];
  1313. if (msglen != clen + 8)
  1314. return 0;
  1315. msg += 8;
  1316. BIO_indent(bio, indent, 80);
  1317. BIO_printf(bio, "Compression type=%s (0x%04x)\n", ssl_trace_str(alg, ssl_comp_cert_tbl), alg);
  1318. BIO_indent(bio, indent, 80);
  1319. BIO_printf(bio, "Uncompressed length=%d\n", (int)uclen);
  1320. BIO_indent(bio, indent, 80);
  1321. if (clen > 0)
  1322. BIO_printf(bio, "Compressed length=%d, Ratio=%f:1\n", (int)clen, (float)uclen / (float)clen);
  1323. else
  1324. BIO_printf(bio, "Compressed length=%d, Ratio=unknown\n", (int)clen);
  1325. BIO_dump_indent(bio, (const char *)msg, clen, indent);
  1326. #ifndef OPENSSL_NO_COMP_ALG
  1327. if (!ossl_comp_has_alg(alg))
  1328. return 0;
  1329. /* Check against certificate maximum size (coverity) */
  1330. if (uclen == 0 || uclen > 0xFFFFFF || (ucdata = OPENSSL_malloc(uclen)) == NULL)
  1331. return 0;
  1332. switch (alg) {
  1333. case TLSEXT_comp_cert_zlib:
  1334. method = COMP_zlib();
  1335. break;
  1336. case TLSEXT_comp_cert_brotli:
  1337. method = COMP_brotli_oneshot();
  1338. break;
  1339. case TLSEXT_comp_cert_zstd:
  1340. method = COMP_zstd_oneshot();
  1341. break;
  1342. default:
  1343. goto err;
  1344. }
  1345. if ((comp = COMP_CTX_new(method)) == NULL
  1346. || COMP_expand_block(comp, ucdata, uclen, (unsigned char*)msg, clen) != (int)uclen)
  1347. goto err;
  1348. ret = ssl_print_certificates(bio, sc, server, indent, ucdata, uclen);
  1349. err:
  1350. COMP_CTX_free(comp);
  1351. OPENSSL_free(ucdata);
  1352. #endif
  1353. return ret;
  1354. }
  1355. static int ssl_print_cert_request(BIO *bio, int indent, const SSL_CONNECTION *sc,
  1356. const unsigned char *msg, size_t msglen)
  1357. {
  1358. size_t xlen;
  1359. unsigned int sigalg;
  1360. if (SSL_CONNECTION_IS_TLS13(sc)) {
  1361. if (!ssl_print_hexbuf(bio, indent, "request_context", 1, &msg, &msglen))
  1362. return 0;
  1363. if (!ssl_print_extensions(bio, indent, 1,
  1364. SSL3_MT_CERTIFICATE_REQUEST, &msg, &msglen))
  1365. return 0;
  1366. return 1;
  1367. } else {
  1368. if (msglen < 1)
  1369. return 0;
  1370. xlen = msg[0];
  1371. if (msglen < xlen + 1)
  1372. return 0;
  1373. msg++;
  1374. BIO_indent(bio, indent, 80);
  1375. BIO_printf(bio, "certificate_types (len=%d)\n", (int)xlen);
  1376. if (!ssl_trace_list(bio, indent + 2, msg, xlen, 1, ssl_ctype_tbl))
  1377. return 0;
  1378. msg += xlen;
  1379. msglen -= xlen + 1;
  1380. }
  1381. if (SSL_USE_SIGALGS(sc)) {
  1382. if (msglen < 2)
  1383. return 0;
  1384. xlen = (msg[0] << 8) | msg[1];
  1385. if (msglen < xlen + 2 || (xlen & 1))
  1386. return 0;
  1387. msg += 2;
  1388. msglen -= xlen + 2;
  1389. BIO_indent(bio, indent, 80);
  1390. BIO_printf(bio, "signature_algorithms (len=%d)\n", (int)xlen);
  1391. while (xlen > 0) {
  1392. BIO_indent(bio, indent + 2, 80);
  1393. sigalg = (msg[0] << 8) | msg[1];
  1394. BIO_printf(bio, "%s (0x%04x)\n",
  1395. ssl_trace_str(sigalg, ssl_sigalg_tbl), sigalg);
  1396. xlen -= 2;
  1397. msg += 2;
  1398. }
  1399. msg += xlen;
  1400. }
  1401. if (msglen < 2)
  1402. return 0;
  1403. xlen = (msg[0] << 8) | msg[1];
  1404. BIO_indent(bio, indent, 80);
  1405. if (msglen < xlen + 2)
  1406. return 0;
  1407. msg += 2;
  1408. msglen -= 2 + xlen;
  1409. BIO_printf(bio, "certificate_authorities (len=%d)\n", (int)xlen);
  1410. while (xlen > 0) {
  1411. size_t dlen;
  1412. X509_NAME *nm;
  1413. const unsigned char *p;
  1414. if (xlen < 2)
  1415. return 0;
  1416. dlen = (msg[0] << 8) | msg[1];
  1417. if (xlen < dlen + 2)
  1418. return 0;
  1419. msg += 2;
  1420. BIO_indent(bio, indent + 2, 80);
  1421. BIO_printf(bio, "DistinguishedName (len=%d): ", (int)dlen);
  1422. p = msg;
  1423. nm = d2i_X509_NAME(NULL, &p, dlen);
  1424. if (!nm) {
  1425. BIO_puts(bio, "<UNPARSEABLE DN>\n");
  1426. } else {
  1427. X509_NAME_print_ex(bio, nm, 0, XN_FLAG_ONELINE);
  1428. BIO_puts(bio, "\n");
  1429. X509_NAME_free(nm);
  1430. }
  1431. xlen -= dlen + 2;
  1432. msg += dlen;
  1433. }
  1434. if (SSL_CONNECTION_IS_TLS13(sc)) {
  1435. if (!ssl_print_hexbuf(bio, indent, "request_extensions", 2,
  1436. &msg, &msglen))
  1437. return 0;
  1438. }
  1439. return msglen == 0;
  1440. }
  1441. static int ssl_print_ticket(BIO *bio, int indent, const SSL_CONNECTION *sc,
  1442. const unsigned char *msg, size_t msglen)
  1443. {
  1444. unsigned int tick_life;
  1445. if (msglen == 0) {
  1446. BIO_indent(bio, indent + 2, 80);
  1447. BIO_puts(bio, "No Ticket\n");
  1448. return 1;
  1449. }
  1450. if (msglen < 4)
  1451. return 0;
  1452. tick_life = ((unsigned int)msg[0] << 24)
  1453. | ((unsigned int)msg[1] << 16)
  1454. | ((unsigned int)msg[2] << 8)
  1455. | (unsigned int)msg[3];
  1456. msglen -= 4;
  1457. msg += 4;
  1458. BIO_indent(bio, indent + 2, 80);
  1459. BIO_printf(bio, "ticket_lifetime_hint=%u\n", tick_life);
  1460. if (SSL_CONNECTION_IS_TLS13(sc)) {
  1461. unsigned int ticket_age_add;
  1462. if (msglen < 4)
  1463. return 0;
  1464. ticket_age_add =
  1465. ((unsigned int)msg[0] << 24)
  1466. | ((unsigned int)msg[1] << 16)
  1467. | ((unsigned int)msg[2] << 8)
  1468. | (unsigned int)msg[3];
  1469. msglen -= 4;
  1470. msg += 4;
  1471. BIO_indent(bio, indent + 2, 80);
  1472. BIO_printf(bio, "ticket_age_add=%u\n", ticket_age_add);
  1473. if (!ssl_print_hexbuf(bio, indent + 2, "ticket_nonce", 1, &msg,
  1474. &msglen))
  1475. return 0;
  1476. }
  1477. if (!ssl_print_hexbuf(bio, indent + 2, "ticket", 2, &msg, &msglen))
  1478. return 0;
  1479. if (SSL_CONNECTION_IS_TLS13(sc)
  1480. && !ssl_print_extensions(bio, indent + 2, 0,
  1481. SSL3_MT_NEWSESSION_TICKET, &msg, &msglen))
  1482. return 0;
  1483. if (msglen)
  1484. return 0;
  1485. return 1;
  1486. }
  1487. static int ssl_print_handshake(BIO *bio, const SSL_CONNECTION *sc, int server,
  1488. const unsigned char *msg, size_t msglen,
  1489. int indent)
  1490. {
  1491. size_t hlen;
  1492. unsigned char htype;
  1493. if (msglen < 4)
  1494. return 0;
  1495. htype = msg[0];
  1496. hlen = (msg[1] << 16) | (msg[2] << 8) | msg[3];
  1497. BIO_indent(bio, indent, 80);
  1498. BIO_printf(bio, "%s, Length=%d\n",
  1499. ssl_trace_str(htype, ssl_handshake_tbl), (int)hlen);
  1500. msg += 4;
  1501. msglen -= 4;
  1502. if (SSL_CONNECTION_IS_DTLS(sc)) {
  1503. if (msglen < 8)
  1504. return 0;
  1505. BIO_indent(bio, indent, 80);
  1506. BIO_printf(bio, "message_seq=%d, fragment_offset=%d, "
  1507. "fragment_length=%d\n",
  1508. (msg[0] << 8) | msg[1],
  1509. (msg[2] << 16) | (msg[3] << 8) | msg[4],
  1510. (msg[5] << 16) | (msg[6] << 8) | msg[7]);
  1511. msg += 8;
  1512. msglen -= 8;
  1513. }
  1514. if (msglen < hlen)
  1515. return 0;
  1516. switch (htype) {
  1517. case SSL3_MT_CLIENT_HELLO:
  1518. if (!ssl_print_client_hello(bio, sc, indent + 2, msg, msglen))
  1519. return 0;
  1520. break;
  1521. case DTLS1_MT_HELLO_VERIFY_REQUEST:
  1522. if (!dtls_print_hello_vfyrequest(bio, indent + 2, msg, msglen))
  1523. return 0;
  1524. break;
  1525. case SSL3_MT_SERVER_HELLO:
  1526. if (!ssl_print_server_hello(bio, indent + 2, msg, msglen))
  1527. return 0;
  1528. break;
  1529. case SSL3_MT_SERVER_KEY_EXCHANGE:
  1530. if (!ssl_print_server_keyex(bio, indent + 2, sc, msg, msglen))
  1531. return 0;
  1532. break;
  1533. case SSL3_MT_CLIENT_KEY_EXCHANGE:
  1534. if (!ssl_print_client_keyex(bio, indent + 2, sc, msg, msglen))
  1535. return 0;
  1536. break;
  1537. case SSL3_MT_CERTIFICATE:
  1538. if (!ssl_print_certificates(bio, sc, server, indent + 2, msg, msglen))
  1539. return 0;
  1540. break;
  1541. case SSL3_MT_COMPRESSED_CERTIFICATE:
  1542. if (!ssl_print_compressed_certificates(bio, sc, server, indent + 2, msg, msglen))
  1543. return 0;
  1544. break;
  1545. case SSL3_MT_CERTIFICATE_VERIFY:
  1546. if (!ssl_print_signature(bio, indent + 2, sc, &msg, &msglen))
  1547. return 0;
  1548. break;
  1549. case SSL3_MT_CERTIFICATE_REQUEST:
  1550. if (!ssl_print_cert_request(bio, indent + 2, sc, msg, msglen))
  1551. return 0;
  1552. break;
  1553. case SSL3_MT_FINISHED:
  1554. ssl_print_hex(bio, indent + 2, "verify_data", msg, msglen);
  1555. break;
  1556. case SSL3_MT_SERVER_DONE:
  1557. if (msglen != 0)
  1558. ssl_print_hex(bio, indent + 2, "unexpected value", msg, msglen);
  1559. break;
  1560. case SSL3_MT_NEWSESSION_TICKET:
  1561. if (!ssl_print_ticket(bio, indent + 2, sc, msg, msglen))
  1562. return 0;
  1563. break;
  1564. case SSL3_MT_ENCRYPTED_EXTENSIONS:
  1565. if (!ssl_print_extensions(bio, indent + 2, 1,
  1566. SSL3_MT_ENCRYPTED_EXTENSIONS, &msg, &msglen))
  1567. return 0;
  1568. break;
  1569. case SSL3_MT_KEY_UPDATE:
  1570. if (msglen != 1) {
  1571. ssl_print_hex(bio, indent + 2, "unexpected value", msg, msglen);
  1572. return 0;
  1573. }
  1574. if (!ssl_trace_list(bio, indent + 2, msg, msglen, 1,
  1575. ssl_key_update_tbl))
  1576. return 0;
  1577. break;
  1578. default:
  1579. BIO_indent(bio, indent + 2, 80);
  1580. BIO_puts(bio, "Unsupported, hex dump follows:\n");
  1581. BIO_dump_indent(bio, (const char *)msg, msglen, indent + 4);
  1582. }
  1583. return 1;
  1584. }
  1585. void SSL_trace(int write_p, int version, int content_type,
  1586. const void *buf, size_t msglen, SSL *ssl, void *arg)
  1587. {
  1588. const unsigned char *msg = buf;
  1589. BIO *bio = arg;
  1590. SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL(ssl);
  1591. #ifndef OPENSSL_NO_QUIC
  1592. QUIC_CONNECTION *qc = QUIC_CONNECTION_FROM_SSL(ssl);
  1593. if (qc != NULL) {
  1594. if (ossl_quic_trace(write_p, version, content_type, buf, msglen, ssl,
  1595. arg))
  1596. return;
  1597. /*
  1598. * Otherwise ossl_quic_trace didn't handle this content_type so we
  1599. * fallback to standard TLS handling
  1600. */
  1601. }
  1602. #endif
  1603. if (sc == NULL)
  1604. return;
  1605. switch (content_type) {
  1606. case SSL3_RT_HEADER:
  1607. {
  1608. int hvers;
  1609. /* avoid overlapping with length at the end of buffer */
  1610. if (msglen < (size_t)(SSL_CONNECTION_IS_DTLS(sc) ?
  1611. DTLS1_RT_HEADER_LENGTH : SSL3_RT_HEADER_LENGTH)) {
  1612. BIO_puts(bio, write_p ? "Sent" : "Received");
  1613. ssl_print_hex(bio, 0, " too short message", msg, msglen);
  1614. break;
  1615. }
  1616. hvers = msg[1] << 8 | msg[2];
  1617. BIO_puts(bio, write_p ? "Sent" : "Received");
  1618. BIO_printf(bio, " TLS Record\nHeader:\n Version = %s (0x%x)\n",
  1619. ssl_trace_str(hvers, ssl_version_tbl), hvers);
  1620. if (SSL_CONNECTION_IS_DTLS(sc)) {
  1621. BIO_printf(bio,
  1622. " epoch=%d, sequence_number=%04x%04x%04x\n",
  1623. (msg[3] << 8 | msg[4]),
  1624. (msg[5] << 8 | msg[6]),
  1625. (msg[7] << 8 | msg[8]), (msg[9] << 8 | msg[10]));
  1626. }
  1627. BIO_printf(bio, " Content Type = %s (%d)\n Length = %d",
  1628. ssl_trace_str(msg[0], ssl_content_tbl), msg[0],
  1629. msg[msglen - 2] << 8 | msg[msglen - 1]);
  1630. }
  1631. break;
  1632. case SSL3_RT_INNER_CONTENT_TYPE:
  1633. BIO_printf(bio, " Inner Content Type = %s (%d)",
  1634. ssl_trace_str(msg[0], ssl_content_tbl), msg[0]);
  1635. break;
  1636. case SSL3_RT_HANDSHAKE:
  1637. if (!ssl_print_handshake(bio, sc, sc->server ? write_p : !write_p,
  1638. msg, msglen, 4))
  1639. BIO_printf(bio, "Message length parse error!\n");
  1640. break;
  1641. case SSL3_RT_CHANGE_CIPHER_SPEC:
  1642. if (msglen == 1 && msg[0] == 1)
  1643. BIO_puts(bio, " change_cipher_spec (1)\n");
  1644. else
  1645. ssl_print_hex(bio, 4, "unknown value", msg, msglen);
  1646. break;
  1647. case SSL3_RT_ALERT:
  1648. if (msglen != 2)
  1649. BIO_puts(bio, " Illegal Alert Length\n");
  1650. else {
  1651. BIO_printf(bio, " Level=%s(%d), description=%s(%d)\n",
  1652. SSL_alert_type_string_long(msg[0] << 8),
  1653. msg[0], SSL_alert_desc_string_long(msg[1]), msg[1]);
  1654. }
  1655. }
  1656. BIO_puts(bio, "\n");
  1657. }
  1658. #endif