t1_trce.c 62 KB

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