t1_trce.c 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532
  1. /*
  2. * Copyright 2012-2017 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (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_locl.h"
  10. #ifndef OPENSSL_NO_SSL_TRACE
  11. /* Packet trace support for OpenSSL */
  12. typedef struct {
  13. int num;
  14. const char *name;
  15. } ssl_trace_tbl;
  16. # define ssl_trace_str(val, tbl) \
  17. do_ssl_trace_str(val, tbl, OSSL_NELEM(tbl))
  18. # define ssl_trace_list(bio, indent, msg, msglen, value, table) \
  19. do_ssl_trace_list(bio, indent, msg, msglen, value, \
  20. table, OSSL_NELEM(table))
  21. static const char *do_ssl_trace_str(int val, ssl_trace_tbl *tbl, size_t ntbl)
  22. {
  23. size_t i;
  24. for (i = 0; i < ntbl; i++, tbl++) {
  25. if (tbl->num == val)
  26. return tbl->name;
  27. }
  28. return "UNKNOWN";
  29. }
  30. static int do_ssl_trace_list(BIO *bio, int indent,
  31. const unsigned char *msg, size_t msglen,
  32. size_t vlen, ssl_trace_tbl *tbl, size_t ntbl)
  33. {
  34. int val;
  35. if (msglen % vlen)
  36. return 0;
  37. while (msglen) {
  38. val = msg[0];
  39. if (vlen == 2)
  40. val = (val << 8) | msg[1];
  41. BIO_indent(bio, indent, 80);
  42. BIO_printf(bio, "%s (%d)\n", do_ssl_trace_str(val, tbl, ntbl), val);
  43. msg += vlen;
  44. msglen -= vlen;
  45. }
  46. return 1;
  47. }
  48. /* Version number */
  49. static ssl_trace_tbl ssl_version_tbl[] = {
  50. {SSL3_VERSION, "SSL 3.0"},
  51. {TLS1_VERSION, "TLS 1.0"},
  52. {TLS1_1_VERSION, "TLS 1.1"},
  53. {TLS1_2_VERSION, "TLS 1.2"},
  54. {TLS1_3_VERSION, "TLS 1.3"},
  55. /* TODO(TLS1.3): Remove this line before release */
  56. {TLS1_3_VERSION_DRAFT, TLS1_3_VERSION_DRAFT_TXT},
  57. {DTLS1_VERSION, "DTLS 1.0"},
  58. {DTLS1_2_VERSION, "DTLS 1.2"},
  59. {DTLS1_BAD_VER, "DTLS 1.0 (bad)"}
  60. };
  61. static 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 */
  68. static 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_HELLO_RETRY_REQUEST, "HelloRetryRequest"},
  76. {SSL3_MT_ENCRYPTED_EXTENSIONS, "EncryptedExtensions"},
  77. {SSL3_MT_CERTIFICATE, "Certificate"},
  78. {SSL3_MT_SERVER_KEY_EXCHANGE, "ServerKeyExchange"},
  79. {SSL3_MT_CERTIFICATE_REQUEST, "CertificateRequest"},
  80. {SSL3_MT_SERVER_DONE, "ServerHelloDone"},
  81. {SSL3_MT_CERTIFICATE_VERIFY, "CertificateVerify"},
  82. {SSL3_MT_CLIENT_KEY_EXCHANGE, "ClientKeyExchange"},
  83. {SSL3_MT_CERTIFICATE_STATUS, "CertificateStatus"},
  84. {SSL3_MT_CLIENT_KEY_EXCHANGE, "ClientKeyExchange"},
  85. {SSL3_MT_FINISHED, "Finished"},
  86. {SSL3_MT_CERTIFICATE_STATUS, "CertificateStatus"},
  87. {SSL3_MT_KEY_UPDATE, "KeyUpdate"},
  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 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. {0x0084, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA"},
  173. {0x0085, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA"},
  174. {0x0086, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA"},
  175. {0x0087, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA"},
  176. {0x0088, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA"},
  177. {0x0089, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA"},
  178. {0x008A, "TLS_PSK_WITH_RC4_128_SHA"},
  179. {0x008B, "TLS_PSK_WITH_3DES_EDE_CBC_SHA"},
  180. {0x008C, "TLS_PSK_WITH_AES_128_CBC_SHA"},
  181. {0x008D, "TLS_PSK_WITH_AES_256_CBC_SHA"},
  182. {0x008E, "TLS_DHE_PSK_WITH_RC4_128_SHA"},
  183. {0x008F, "TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA"},
  184. {0x0090, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA"},
  185. {0x0091, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA"},
  186. {0x0092, "TLS_RSA_PSK_WITH_RC4_128_SHA"},
  187. {0x0093, "TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA"},
  188. {0x0094, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA"},
  189. {0x0095, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA"},
  190. {0x0096, "TLS_RSA_WITH_SEED_CBC_SHA"},
  191. {0x0097, "TLS_DH_DSS_WITH_SEED_CBC_SHA"},
  192. {0x0098, "TLS_DH_RSA_WITH_SEED_CBC_SHA"},
  193. {0x0099, "TLS_DHE_DSS_WITH_SEED_CBC_SHA"},
  194. {0x009A, "TLS_DHE_RSA_WITH_SEED_CBC_SHA"},
  195. {0x009B, "TLS_DH_anon_WITH_SEED_CBC_SHA"},
  196. {0x009C, "TLS_RSA_WITH_AES_128_GCM_SHA256"},
  197. {0x009D, "TLS_RSA_WITH_AES_256_GCM_SHA384"},
  198. {0x009E, "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256"},
  199. {0x009F, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384"},
  200. {0x00A0, "TLS_DH_RSA_WITH_AES_128_GCM_SHA256"},
  201. {0x00A1, "TLS_DH_RSA_WITH_AES_256_GCM_SHA384"},
  202. {0x00A2, "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256"},
  203. {0x00A3, "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384"},
  204. {0x00A4, "TLS_DH_DSS_WITH_AES_128_GCM_SHA256"},
  205. {0x00A5, "TLS_DH_DSS_WITH_AES_256_GCM_SHA384"},
  206. {0x00A6, "TLS_DH_anon_WITH_AES_128_GCM_SHA256"},
  207. {0x00A7, "TLS_DH_anon_WITH_AES_256_GCM_SHA384"},
  208. {0x00A8, "TLS_PSK_WITH_AES_128_GCM_SHA256"},
  209. {0x00A9, "TLS_PSK_WITH_AES_256_GCM_SHA384"},
  210. {0x00AA, "TLS_DHE_PSK_WITH_AES_128_GCM_SHA256"},
  211. {0x00AB, "TLS_DHE_PSK_WITH_AES_256_GCM_SHA384"},
  212. {0x00AC, "TLS_RSA_PSK_WITH_AES_128_GCM_SHA256"},
  213. {0x00AD, "TLS_RSA_PSK_WITH_AES_256_GCM_SHA384"},
  214. {0x00AE, "TLS_PSK_WITH_AES_128_CBC_SHA256"},
  215. {0x00AF, "TLS_PSK_WITH_AES_256_CBC_SHA384"},
  216. {0x00B0, "TLS_PSK_WITH_NULL_SHA256"},
  217. {0x00B1, "TLS_PSK_WITH_NULL_SHA384"},
  218. {0x00B2, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA256"},
  219. {0x00B3, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA384"},
  220. {0x00B4, "TLS_DHE_PSK_WITH_NULL_SHA256"},
  221. {0x00B5, "TLS_DHE_PSK_WITH_NULL_SHA384"},
  222. {0x00B6, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA256"},
  223. {0x00B7, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA384"},
  224. {0x00B8, "TLS_RSA_PSK_WITH_NULL_SHA256"},
  225. {0x00B9, "TLS_RSA_PSK_WITH_NULL_SHA384"},
  226. {0x00BA, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256"},
  227. {0x00BB, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256"},
  228. {0x00BC, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256"},
  229. {0x00BD, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256"},
  230. {0x00BE, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256"},
  231. {0x00BF, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256"},
  232. {0x00C0, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256"},
  233. {0x00C1, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256"},
  234. {0x00C2, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256"},
  235. {0x00C3, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256"},
  236. {0x00C4, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256"},
  237. {0x00C5, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256"},
  238. {0x00FF, "TLS_EMPTY_RENEGOTIATION_INFO_SCSV"},
  239. {0x5600, "TLS_FALLBACK_SCSV"},
  240. {0xC001, "TLS_ECDH_ECDSA_WITH_NULL_SHA"},
  241. {0xC002, "TLS_ECDH_ECDSA_WITH_RC4_128_SHA"},
  242. {0xC003, "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA"},
  243. {0xC004, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA"},
  244. {0xC005, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA"},
  245. {0xC006, "TLS_ECDHE_ECDSA_WITH_NULL_SHA"},
  246. {0xC007, "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA"},
  247. {0xC008, "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA"},
  248. {0xC009, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA"},
  249. {0xC00A, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA"},
  250. {0xC00B, "TLS_ECDH_RSA_WITH_NULL_SHA"},
  251. {0xC00C, "TLS_ECDH_RSA_WITH_RC4_128_SHA"},
  252. {0xC00D, "TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA"},
  253. {0xC00E, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA"},
  254. {0xC00F, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA"},
  255. {0xC010, "TLS_ECDHE_RSA_WITH_NULL_SHA"},
  256. {0xC011, "TLS_ECDHE_RSA_WITH_RC4_128_SHA"},
  257. {0xC012, "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA"},
  258. {0xC013, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA"},
  259. {0xC014, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA"},
  260. {0xC015, "TLS_ECDH_anon_WITH_NULL_SHA"},
  261. {0xC016, "TLS_ECDH_anon_WITH_RC4_128_SHA"},
  262. {0xC017, "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA"},
  263. {0xC018, "TLS_ECDH_anon_WITH_AES_128_CBC_SHA"},
  264. {0xC019, "TLS_ECDH_anon_WITH_AES_256_CBC_SHA"},
  265. {0xC01A, "TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA"},
  266. {0xC01B, "TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA"},
  267. {0xC01C, "TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA"},
  268. {0xC01D, "TLS_SRP_SHA_WITH_AES_128_CBC_SHA"},
  269. {0xC01E, "TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA"},
  270. {0xC01F, "TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA"},
  271. {0xC020, "TLS_SRP_SHA_WITH_AES_256_CBC_SHA"},
  272. {0xC021, "TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA"},
  273. {0xC022, "TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA"},
  274. {0xC023, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256"},
  275. {0xC024, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384"},
  276. {0xC025, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256"},
  277. {0xC026, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384"},
  278. {0xC027, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"},
  279. {0xC028, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384"},
  280. {0xC029, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256"},
  281. {0xC02A, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384"},
  282. {0xC02B, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"},
  283. {0xC02C, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"},
  284. {0xC02D, "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256"},
  285. {0xC02E, "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384"},
  286. {0xC02F, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"},
  287. {0xC030, "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"},
  288. {0xC031, "TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256"},
  289. {0xC032, "TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384"},
  290. {0xC033, "TLS_ECDHE_PSK_WITH_RC4_128_SHA"},
  291. {0xC034, "TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA"},
  292. {0xC035, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA"},
  293. {0xC036, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA"},
  294. {0xC037, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256"},
  295. {0xC038, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384"},
  296. {0xC039, "TLS_ECDHE_PSK_WITH_NULL_SHA"},
  297. {0xC03A, "TLS_ECDHE_PSK_WITH_NULL_SHA256"},
  298. {0xC03B, "TLS_ECDHE_PSK_WITH_NULL_SHA384"},
  299. {0xC03C, "TLS_RSA_WITH_ARIA_128_CBC_SHA256"},
  300. {0xC03D, "TLS_RSA_WITH_ARIA_256_CBC_SHA384"},
  301. {0xC03E, "TLS_DH_DSS_WITH_ARIA_128_CBC_SHA256"},
  302. {0xC03F, "TLS_DH_DSS_WITH_ARIA_256_CBC_SHA384"},
  303. {0xC040, "TLS_DH_RSA_WITH_ARIA_128_CBC_SHA256"},
  304. {0xC041, "TLS_DH_RSA_WITH_ARIA_256_CBC_SHA384"},
  305. {0xC042, "TLS_DHE_DSS_WITH_ARIA_128_CBC_SHA256"},
  306. {0xC043, "TLS_DHE_DSS_WITH_ARIA_256_CBC_SHA384"},
  307. {0xC044, "TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256"},
  308. {0xC045, "TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384"},
  309. {0xC046, "TLS_DH_anon_WITH_ARIA_128_CBC_SHA256"},
  310. {0xC047, "TLS_DH_anon_WITH_ARIA_256_CBC_SHA384"},
  311. {0xC048, "TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256"},
  312. {0xC049, "TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384"},
  313. {0xC04A, "TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256"},
  314. {0xC04B, "TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384"},
  315. {0xC04C, "TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256"},
  316. {0xC04D, "TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384"},
  317. {0xC04E, "TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256"},
  318. {0xC04F, "TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384"},
  319. {0xC050, "TLS_RSA_WITH_ARIA_128_GCM_SHA256"},
  320. {0xC051, "TLS_RSA_WITH_ARIA_256_GCM_SHA384"},
  321. {0xC052, "TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256"},
  322. {0xC053, "TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384"},
  323. {0xC054, "TLS_DH_RSA_WITH_ARIA_128_GCM_SHA256"},
  324. {0xC055, "TLS_DH_RSA_WITH_ARIA_256_GCM_SHA384"},
  325. {0xC056, "TLS_DHE_DSS_WITH_ARIA_128_GCM_SHA256"},
  326. {0xC057, "TLS_DHE_DSS_WITH_ARIA_256_GCM_SHA384"},
  327. {0xC058, "TLS_DH_DSS_WITH_ARIA_128_GCM_SHA256"},
  328. {0xC059, "TLS_DH_DSS_WITH_ARIA_256_GCM_SHA384"},
  329. {0xC05A, "TLS_DH_anon_WITH_ARIA_128_GCM_SHA256"},
  330. {0xC05B, "TLS_DH_anon_WITH_ARIA_256_GCM_SHA384"},
  331. {0xC05C, "TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256"},
  332. {0xC05D, "TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384"},
  333. {0xC05E, "TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256"},
  334. {0xC05F, "TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384"},
  335. {0xC060, "TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256"},
  336. {0xC061, "TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384"},
  337. {0xC062, "TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256"},
  338. {0xC063, "TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384"},
  339. {0xC064, "TLS_PSK_WITH_ARIA_128_CBC_SHA256"},
  340. {0xC065, "TLS_PSK_WITH_ARIA_256_CBC_SHA384"},
  341. {0xC066, "TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256"},
  342. {0xC067, "TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384"},
  343. {0xC068, "TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256"},
  344. {0xC069, "TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384"},
  345. {0xC06A, "TLS_PSK_WITH_ARIA_128_GCM_SHA256"},
  346. {0xC06B, "TLS_PSK_WITH_ARIA_256_GCM_SHA384"},
  347. {0xC06C, "TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256"},
  348. {0xC06D, "TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384"},
  349. {0xC06E, "TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256"},
  350. {0xC06F, "TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384"},
  351. {0xC070, "TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256"},
  352. {0xC071, "TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384"},
  353. {0xC072, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256"},
  354. {0xC073, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384"},
  355. {0xC074, "TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256"},
  356. {0xC075, "TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384"},
  357. {0xC076, "TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256"},
  358. {0xC077, "TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384"},
  359. {0xC078, "TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256"},
  360. {0xC079, "TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384"},
  361. {0xC07A, "TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256"},
  362. {0xC07B, "TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384"},
  363. {0xC07C, "TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256"},
  364. {0xC07D, "TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384"},
  365. {0xC07E, "TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256"},
  366. {0xC07F, "TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384"},
  367. {0xC080, "TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256"},
  368. {0xC081, "TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384"},
  369. {0xC082, "TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256"},
  370. {0xC083, "TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384"},
  371. {0xC084, "TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256"},
  372. {0xC085, "TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384"},
  373. {0xC086, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256"},
  374. {0xC087, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384"},
  375. {0xC088, "TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256"},
  376. {0xC089, "TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384"},
  377. {0xC08A, "TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256"},
  378. {0xC08B, "TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384"},
  379. {0xC08C, "TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256"},
  380. {0xC08D, "TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384"},
  381. {0xC08E, "TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256"},
  382. {0xC08F, "TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384"},
  383. {0xC090, "TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256"},
  384. {0xC091, "TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384"},
  385. {0xC092, "TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256"},
  386. {0xC093, "TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384"},
  387. {0xC094, "TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256"},
  388. {0xC095, "TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384"},
  389. {0xC096, "TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256"},
  390. {0xC097, "TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384"},
  391. {0xC098, "TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256"},
  392. {0xC099, "TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384"},
  393. {0xC09A, "TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256"},
  394. {0xC09B, "TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384"},
  395. {0xC09C, "TLS_RSA_WITH_AES_128_CCM"},
  396. {0xC09D, "TLS_RSA_WITH_AES_256_CCM"},
  397. {0xC09E, "TLS_DHE_RSA_WITH_AES_128_CCM"},
  398. {0xC09F, "TLS_DHE_RSA_WITH_AES_256_CCM"},
  399. {0xC0A0, "TLS_RSA_WITH_AES_128_CCM_8"},
  400. {0xC0A1, "TLS_RSA_WITH_AES_256_CCM_8"},
  401. {0xC0A2, "TLS_DHE_RSA_WITH_AES_128_CCM_8"},
  402. {0xC0A3, "TLS_DHE_RSA_WITH_AES_256_CCM_8"},
  403. {0xC0A4, "TLS_PSK_WITH_AES_128_CCM"},
  404. {0xC0A5, "TLS_PSK_WITH_AES_256_CCM"},
  405. {0xC0A6, "TLS_DHE_PSK_WITH_AES_128_CCM"},
  406. {0xC0A7, "TLS_DHE_PSK_WITH_AES_256_CCM"},
  407. {0xC0A8, "TLS_PSK_WITH_AES_128_CCM_8"},
  408. {0xC0A9, "TLS_PSK_WITH_AES_256_CCM_8"},
  409. {0xC0AA, "TLS_PSK_DHE_WITH_AES_128_CCM_8"},
  410. {0xC0AB, "TLS_PSK_DHE_WITH_AES_256_CCM_8"},
  411. {0xC0AC, "TLS_ECDHE_ECDSA_WITH_AES_128_CCM"},
  412. {0xC0AD, "TLS_ECDHE_ECDSA_WITH_AES_256_CCM"},
  413. {0xC0AE, "TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8"},
  414. {0xC0AF, "TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8"},
  415. {0xCCA8, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256"},
  416. {0xCCA9, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256"},
  417. {0xCCAA, "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256"},
  418. {0xCCAB, "TLS_PSK_WITH_CHACHA20_POLY1305_SHA256"},
  419. {0xCCAC, "TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256"},
  420. {0xCCAD, "TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256"},
  421. {0xCCAE, "TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256"},
  422. {0x1301, "TLS_AES_128_GCM_SHA256"},
  423. {0x1302, "TLS_AES_256_GCM_SHA384"},
  424. {0x1303, "TLS_CHACHA20_POLY1305_SHA256"},
  425. {0x1304, "TLS_AES_128_CCM_SHA256"},
  426. {0x1305, "TLS_AES_128_CCM_8_SHA256"},
  427. {0xFEFE, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"},
  428. {0xFEFF, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA"},
  429. };
  430. /* Compression methods */
  431. static ssl_trace_tbl ssl_comp_tbl[] = {
  432. {0x0000, "No Compression"},
  433. {0x0001, "Zlib Compression"}
  434. };
  435. /* Extensions */
  436. static ssl_trace_tbl ssl_exts_tbl[] = {
  437. {TLSEXT_TYPE_server_name, "server_name"},
  438. {TLSEXT_TYPE_max_fragment_length, "max_fragment_length"},
  439. {TLSEXT_TYPE_client_certificate_url, "client_certificate_url"},
  440. {TLSEXT_TYPE_trusted_ca_keys, "trusted_ca_keys"},
  441. {TLSEXT_TYPE_truncated_hmac, "truncated_hmac"},
  442. {TLSEXT_TYPE_status_request, "status_request"},
  443. {TLSEXT_TYPE_user_mapping, "user_mapping"},
  444. {TLSEXT_TYPE_client_authz, "client_authz"},
  445. {TLSEXT_TYPE_server_authz, "server_authz"},
  446. {TLSEXT_TYPE_cert_type, "cert_type"},
  447. {TLSEXT_TYPE_key_share, "key_share"},
  448. {TLSEXT_TYPE_psk, "psk"},
  449. {TLSEXT_TYPE_psk_kex_modes, "psk_key_exchange_modes"},
  450. {TLSEXT_TYPE_supported_groups, "supported_groups"},
  451. {TLSEXT_TYPE_ec_point_formats, "ec_point_formats"},
  452. {TLSEXT_TYPE_srp, "srp"},
  453. {TLSEXT_TYPE_signature_algorithms, "signature_algorithms"},
  454. {TLSEXT_TYPE_use_srtp, "use_srtp"},
  455. {TLSEXT_TYPE_session_ticket, "session_ticket"},
  456. {TLSEXT_TYPE_supported_versions, "supported_versions"},
  457. {TLSEXT_TYPE_renegotiate, "renegotiate"},
  458. # ifndef OPENSSL_NO_NEXTPROTONEG
  459. {TLSEXT_TYPE_next_proto_neg, "next_proto_neg"},
  460. # endif
  461. {TLSEXT_TYPE_application_layer_protocol_negotiation,
  462. "application_layer_protocol_negotiation"},
  463. {TLSEXT_TYPE_signed_certificate_timestamp, "signed_certificate_timestamps"},
  464. {TLSEXT_TYPE_padding, "padding"},
  465. {TLSEXT_TYPE_encrypt_then_mac, "encrypt_then_mac"},
  466. {TLSEXT_TYPE_extended_master_secret, "extended_master_secret"},
  467. {TLSEXT_TYPE_early_data, "early_data"}
  468. };
  469. static ssl_trace_tbl ssl_groups_tbl[] = {
  470. {1, "sect163k1 (K-163)"},
  471. {2, "sect163r1"},
  472. {3, "sect163r2 (B-163)"},
  473. {4, "sect193r1"},
  474. {5, "sect193r2"},
  475. {6, "sect233k1 (K-233)"},
  476. {7, "sect233r1 (B-233)"},
  477. {8, "sect239k1"},
  478. {9, "sect283k1 (K-283)"},
  479. {10, "sect283r1 (B-283)"},
  480. {11, "sect409k1 (K-409)"},
  481. {12, "sect409r1 (B-409)"},
  482. {13, "sect571k1 (K-571)"},
  483. {14, "sect571r1 (B-571)"},
  484. {15, "secp160k1"},
  485. {16, "secp160r1"},
  486. {17, "secp160r2"},
  487. {18, "secp192k1"},
  488. {19, "secp192r1 (P-192)"},
  489. {20, "secp224k1"},
  490. {21, "secp224r1 (P-224)"},
  491. {22, "secp256k1"},
  492. {23, "secp256r1 (P-256)"},
  493. {24, "secp384r1 (P-384)"},
  494. {25, "secp521r1 (P-521)"},
  495. {26, "brainpoolP256r1"},
  496. {27, "brainpoolP384r1"},
  497. {28, "brainpoolP512r1"},
  498. {29, "ecdh_x25519"},
  499. {256, "ffdhe2048"},
  500. {257, "ffdhe3072"},
  501. {258, "ffdhe4096"},
  502. {259, "ffdhe6144"},
  503. {260, "ffdhe8192"},
  504. {0xFF01, "arbitrary_explicit_prime_curves"},
  505. {0xFF02, "arbitrary_explicit_char2_curves"}
  506. };
  507. static ssl_trace_tbl ssl_point_tbl[] = {
  508. {0, "uncompressed"},
  509. {1, "ansiX962_compressed_prime"},
  510. {2, "ansiX962_compressed_char2"}
  511. };
  512. static ssl_trace_tbl ssl_sigalg_tbl[] = {
  513. {TLSEXT_SIGALG_ecdsa_secp256r1_sha256, "ecdsa_secp256r1_sha256"},
  514. {TLSEXT_SIGALG_ecdsa_secp384r1_sha384, "ecdsa_secp384r1_sha384"},
  515. {TLSEXT_SIGALG_ecdsa_secp521r1_sha512, "ecdsa_secp521r1_sha512"},
  516. {TLSEXT_SIGALG_ecdsa_sha224, "ecdsa_sha224"},
  517. {TLSEXT_SIGALG_ed25519, "ed25519"},
  518. {TLSEXT_SIGALG_ecdsa_sha1, "ecdsa_sha1"},
  519. {TLSEXT_SIGALG_rsa_pss_sha256, "rsa_pss_sha256"},
  520. {TLSEXT_SIGALG_rsa_pss_sha384, "rsa_pss_sha384"},
  521. {TLSEXT_SIGALG_rsa_pss_sha512, "rsa_pss_sha512"},
  522. {TLSEXT_SIGALG_rsa_pkcs1_sha256, "rsa_pkcs1_sha256"},
  523. {TLSEXT_SIGALG_rsa_pkcs1_sha384, "rsa_pkcs1_sha384"},
  524. {TLSEXT_SIGALG_rsa_pkcs1_sha512, "rsa_pkcs1_sha512"},
  525. {TLSEXT_SIGALG_rsa_pkcs1_sha224, "rsa_pkcs1_sha224"},
  526. {TLSEXT_SIGALG_rsa_pkcs1_sha1, "rsa_pkcs1_sha1"},
  527. {TLSEXT_SIGALG_dsa_sha256, "dsa_sha256"},
  528. {TLSEXT_SIGALG_dsa_sha384, "dsa_sha384"},
  529. {TLSEXT_SIGALG_dsa_sha512, "dsa_sha512"},
  530. {TLSEXT_SIGALG_dsa_sha224, "dsa_sha224"},
  531. {TLSEXT_SIGALG_dsa_sha1, "dsa_sha1"},
  532. {TLSEXT_SIGALG_gostr34102012_256_gostr34112012_256, "gost2012_256"},
  533. {TLSEXT_SIGALG_gostr34102012_512_gostr34112012_512, "gost2012_512"},
  534. {TLSEXT_SIGALG_gostr34102001_gostr3411, "gost2001_gost94"},
  535. };
  536. static ssl_trace_tbl ssl_ctype_tbl[] = {
  537. {1, "rsa_sign"},
  538. {2, "dss_sign"},
  539. {3, "rsa_fixed_dh"},
  540. {4, "dss_fixed_dh"},
  541. {5, "rsa_ephemeral_dh"},
  542. {6, "dss_ephemeral_dh"},
  543. {20, "fortezza_dms"},
  544. {64, "ecdsa_sign"},
  545. {65, "rsa_fixed_ecdh"},
  546. {66, "ecdsa_fixed_ecdh"}
  547. };
  548. static ssl_trace_tbl ssl_psk_kex_modes_tbl[] = {
  549. {TLSEXT_KEX_MODE_KE, "psk_ke"},
  550. {TLSEXT_KEX_MODE_KE_DHE, "psk_dhe_ke"}
  551. };
  552. static ssl_trace_tbl ssl_key_update_tbl[] = {
  553. {SSL_KEY_UPDATE_NOT_REQUESTED, "update_not_requested"},
  554. {SSL_KEY_UPDATE_REQUESTED, "update_requested"}
  555. };
  556. static void ssl_print_hex(BIO *bio, int indent, const char *name,
  557. const unsigned char *msg, size_t msglen)
  558. {
  559. size_t i;
  560. BIO_indent(bio, indent, 80);
  561. BIO_printf(bio, "%s (len=%d): ", name, (int)msglen);
  562. for (i = 0; i < msglen; i++)
  563. BIO_printf(bio, "%02X", msg[i]);
  564. BIO_puts(bio, "\n");
  565. }
  566. static int ssl_print_hexbuf(BIO *bio, int indent,
  567. const char *name, size_t nlen,
  568. const unsigned char **pmsg, size_t *pmsglen)
  569. {
  570. size_t blen;
  571. const unsigned char *p = *pmsg;
  572. if (*pmsglen < nlen)
  573. return 0;
  574. blen = p[0];
  575. if (nlen > 1)
  576. blen = (blen << 8) | p[1];
  577. if (*pmsglen < nlen + blen)
  578. return 0;
  579. p += nlen;
  580. ssl_print_hex(bio, indent, name, p, blen);
  581. *pmsg += blen + nlen;
  582. *pmsglen -= blen + nlen;
  583. return 1;
  584. }
  585. static int ssl_print_version(BIO *bio, int indent, const char *name,
  586. const unsigned char **pmsg, size_t *pmsglen,
  587. unsigned int *version)
  588. {
  589. int vers;
  590. if (*pmsglen < 2)
  591. return 0;
  592. vers = ((*pmsg)[0] << 8) | (*pmsg)[1];
  593. if (version != NULL) {
  594. /* TODO(TLS1.3): Remove the draft conditional here before release */
  595. *version = (vers == TLS1_3_VERSION_DRAFT) ? TLS1_3_VERSION : vers;
  596. }
  597. BIO_indent(bio, indent, 80);
  598. BIO_printf(bio, "%s=0x%x (%s)\n",
  599. name, vers, ssl_trace_str(vers, ssl_version_tbl));
  600. *pmsg += 2;
  601. *pmsglen -= 2;
  602. return 1;
  603. }
  604. static int ssl_print_random(BIO *bio, int indent,
  605. const unsigned char **pmsg, size_t *pmsglen)
  606. {
  607. unsigned int tm;
  608. const unsigned char *p = *pmsg;
  609. if (*pmsglen < 32)
  610. return 0;
  611. tm = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
  612. p += 4;
  613. BIO_indent(bio, indent, 80);
  614. BIO_puts(bio, "Random:\n");
  615. BIO_indent(bio, indent + 2, 80);
  616. BIO_printf(bio, "gmt_unix_time=0x%08X\n", tm);
  617. ssl_print_hex(bio, indent + 2, "random_bytes", p, 28);
  618. *pmsg += 32;
  619. *pmsglen -= 32;
  620. return 1;
  621. }
  622. static int ssl_print_signature(BIO *bio, int indent, SSL *s,
  623. const unsigned char **pmsg, size_t *pmsglen)
  624. {
  625. if (*pmsglen < 2)
  626. return 0;
  627. if (SSL_USE_SIGALGS(s)) {
  628. const unsigned char *p = *pmsg;
  629. unsigned int sigalg = (p[0] << 8) | p[1];
  630. BIO_indent(bio, indent, 80);
  631. BIO_printf(bio, "Signature Algorithm: %s (0x%04x)\n",
  632. ssl_trace_str(sigalg, ssl_sigalg_tbl), sigalg);
  633. *pmsg += 2;
  634. *pmsglen -= 2;
  635. }
  636. return ssl_print_hexbuf(bio, indent, "Signature", 2, pmsg, pmsglen);
  637. }
  638. static int ssl_print_extension(BIO *bio, int indent, int server,
  639. unsigned char mt, int extype,
  640. const unsigned char *ext, size_t extlen)
  641. {
  642. size_t xlen, share_len;
  643. unsigned int sigalg;
  644. uint32_t max_early_data;
  645. BIO_indent(bio, indent, 80);
  646. BIO_printf(bio, "extension_type=%s(%d), length=%d\n",
  647. ssl_trace_str(extype, ssl_exts_tbl), extype, (int)extlen);
  648. switch (extype) {
  649. case TLSEXT_TYPE_ec_point_formats:
  650. if (extlen < 1)
  651. return 0;
  652. xlen = ext[0];
  653. if (extlen != xlen + 1)
  654. return 0;
  655. return ssl_trace_list(bio, indent + 2, ext + 1, xlen, 1, ssl_point_tbl);
  656. case TLSEXT_TYPE_supported_groups:
  657. if (extlen < 2)
  658. return 0;
  659. xlen = (ext[0] << 8) | ext[1];
  660. if (extlen != xlen + 2)
  661. return 0;
  662. return ssl_trace_list(bio, indent + 2, ext + 2, xlen, 2, ssl_groups_tbl);
  663. case TLSEXT_TYPE_application_layer_protocol_negotiation:
  664. if (extlen < 2)
  665. return 0;
  666. xlen = (ext[0] << 8) | ext[1];
  667. if (extlen != xlen + 2)
  668. return 0;
  669. ext += 2;
  670. while (xlen > 0) {
  671. size_t plen = *ext++;
  672. if (plen > xlen + 1)
  673. return 0;
  674. BIO_indent(bio, indent + 2, 80);
  675. BIO_write(bio, ext, plen);
  676. BIO_puts(bio, "\n");
  677. ext += plen;
  678. xlen -= plen + 1;
  679. }
  680. return 1;
  681. case TLSEXT_TYPE_signature_algorithms:
  682. if (extlen < 2)
  683. return 0;
  684. xlen = (ext[0] << 8) | ext[1];
  685. if (extlen != xlen + 2)
  686. return 0;
  687. if (xlen & 1)
  688. return 0;
  689. ext += 2;
  690. while (xlen > 0) {
  691. BIO_indent(bio, indent + 2, 80);
  692. sigalg = (ext[0] << 8) | ext[1];
  693. BIO_printf(bio, "%s (0x%04x)\n",
  694. ssl_trace_str(sigalg, ssl_sigalg_tbl), sigalg);
  695. xlen -= 2;
  696. ext += 2;
  697. }
  698. break;
  699. case TLSEXT_TYPE_renegotiate:
  700. if (extlen < 1)
  701. return 0;
  702. xlen = ext[0];
  703. if (xlen + 1 != extlen)
  704. return 0;
  705. ext++;
  706. if (xlen) {
  707. if (server) {
  708. if (xlen & 1)
  709. return 0;
  710. xlen >>= 1;
  711. }
  712. ssl_print_hex(bio, indent + 4, "client_verify_data", ext, xlen);
  713. if (server) {
  714. ext += xlen;
  715. ssl_print_hex(bio, indent + 4, "server_verify_data", ext, xlen);
  716. }
  717. } else {
  718. BIO_indent(bio, indent + 4, 80);
  719. BIO_puts(bio, "<EMPTY>\n");
  720. }
  721. break;
  722. case TLSEXT_TYPE_heartbeat:
  723. return 0;
  724. case TLSEXT_TYPE_session_ticket:
  725. if (extlen != 0)
  726. ssl_print_hex(bio, indent + 4, "ticket", ext, extlen);
  727. break;
  728. case TLSEXT_TYPE_key_share:
  729. if (mt == SSL3_MT_HELLO_RETRY_REQUEST) {
  730. int group_id;
  731. if (extlen != 2)
  732. return 0;
  733. group_id = (ext[0] << 8) | ext[1];
  734. BIO_indent(bio, indent + 4, 80);
  735. BIO_printf(bio, "NamedGroup: %s (%d)\n",
  736. ssl_trace_str(group_id, ssl_groups_tbl), group_id);
  737. break;
  738. }
  739. if (extlen < 2)
  740. return 0;
  741. if (server) {
  742. xlen = extlen;
  743. } else {
  744. xlen = (ext[0] << 8) | ext[1];
  745. if (extlen != xlen + 2)
  746. return 0;
  747. ext += 2;
  748. }
  749. for (; xlen > 0; ext += share_len, xlen -= share_len) {
  750. int group_id;
  751. if (xlen < 4)
  752. return 0;
  753. group_id = (ext[0] << 8) | ext[1];
  754. share_len = (ext[2] << 8) | ext[3];
  755. ext += 4;
  756. xlen -= 4;
  757. if (xlen < share_len)
  758. return 0;
  759. BIO_indent(bio, indent + 4, 80);
  760. BIO_printf(bio, "NamedGroup: %s (%d)\n",
  761. ssl_trace_str(group_id, ssl_groups_tbl), group_id);
  762. ssl_print_hex(bio, indent + 4, "key_exchange: ", ext, share_len);
  763. }
  764. break;
  765. case TLSEXT_TYPE_supported_versions:
  766. if (extlen < 1)
  767. return 0;
  768. xlen = ext[0];
  769. if (extlen != xlen + 1)
  770. return 0;
  771. return ssl_trace_list(bio, indent + 2, ext + 1, xlen, 2,
  772. ssl_version_tbl);
  773. case TLSEXT_TYPE_psk_kex_modes:
  774. if (extlen < 1)
  775. return 0;
  776. xlen = ext[0];
  777. if (extlen != xlen + 1)
  778. return 0;
  779. return ssl_trace_list(bio, indent + 2, ext + 1, xlen, 1,
  780. ssl_psk_kex_modes_tbl);
  781. case TLSEXT_TYPE_early_data:
  782. if (mt != SSL3_MT_NEWSESSION_TICKET)
  783. break;
  784. if (extlen != 4)
  785. return 0;
  786. max_early_data = (ext[0] << 24) | (ext[1] << 16) | (ext[2] << 8)
  787. | ext[3];
  788. BIO_indent(bio, indent + 2, 80);
  789. BIO_printf(bio, "max_early_data=%u\n", max_early_data);
  790. break;
  791. default:
  792. BIO_dump_indent(bio, (const char *)ext, extlen, indent + 2);
  793. }
  794. return 1;
  795. }
  796. static int ssl_print_extensions(BIO *bio, int indent, int server,
  797. unsigned char mt, const unsigned char **msgin,
  798. size_t *msginlen)
  799. {
  800. size_t extslen, msglen = *msginlen;
  801. const unsigned char *msg = *msgin;
  802. BIO_indent(bio, indent, 80);
  803. if (msglen == 0) {
  804. BIO_puts(bio, "No Extensions\n");
  805. return 1;
  806. }
  807. extslen = (msg[0] << 8) | msg[1];
  808. if (extslen != msglen - 2)
  809. return 0;
  810. msg += 2;
  811. msglen = extslen;
  812. BIO_printf(bio, "extensions, length = %d\n", (int)msglen);
  813. while (msglen > 0) {
  814. int extype;
  815. size_t extlen;
  816. if (msglen < 4)
  817. return 0;
  818. extype = (msg[0] << 8) | msg[1];
  819. extlen = (msg[2] << 8) | msg[3];
  820. if (msglen < extlen + 4)
  821. return 0;
  822. msg += 4;
  823. if (!ssl_print_extension(bio, indent + 2, server, mt, extype, msg,
  824. extlen))
  825. return 0;
  826. msg += extlen;
  827. msglen -= extlen + 4;
  828. }
  829. *msgin = msg;
  830. *msginlen = msglen;
  831. return 1;
  832. }
  833. static int ssl_print_client_hello(BIO *bio, SSL *ssl, int indent,
  834. const unsigned char *msg, size_t msglen)
  835. {
  836. size_t len;
  837. unsigned int cs;
  838. if (!ssl_print_version(bio, indent, "client_version", &msg, &msglen, NULL))
  839. return 0;
  840. if (!ssl_print_random(bio, indent, &msg, &msglen))
  841. return 0;
  842. if (!ssl_print_hexbuf(bio, indent, "session_id", 1, &msg, &msglen))
  843. return 0;
  844. if (SSL_IS_DTLS(ssl)) {
  845. if (!ssl_print_hexbuf(bio, indent, "cookie", 1, &msg, &msglen))
  846. return 0;
  847. }
  848. if (msglen < 2)
  849. return 0;
  850. len = (msg[0] << 8) | msg[1];
  851. msg += 2;
  852. msglen -= 2;
  853. BIO_indent(bio, indent, 80);
  854. BIO_printf(bio, "cipher_suites (len=%d)\n", (int)len);
  855. if (msglen < len || len & 1)
  856. return 0;
  857. while (len > 0) {
  858. cs = (msg[0] << 8) | msg[1];
  859. BIO_indent(bio, indent + 2, 80);
  860. BIO_printf(bio, "{0x%02X, 0x%02X} %s\n",
  861. msg[0], msg[1], ssl_trace_str(cs, ssl_ciphers_tbl));
  862. msg += 2;
  863. msglen -= 2;
  864. len -= 2;
  865. }
  866. if (msglen < 1)
  867. return 0;
  868. len = msg[0];
  869. msg++;
  870. msglen--;
  871. if (msglen < len)
  872. return 0;
  873. BIO_indent(bio, indent, 80);
  874. BIO_printf(bio, "compression_methods (len=%d)\n", (int)len);
  875. while (len > 0) {
  876. BIO_indent(bio, indent + 2, 80);
  877. BIO_printf(bio, "%s (0x%02X)\n",
  878. ssl_trace_str(msg[0], ssl_comp_tbl), msg[0]);
  879. msg++;
  880. msglen--;
  881. len--;
  882. }
  883. if (!ssl_print_extensions(bio, indent, 0, SSL3_MT_CLIENT_HELLO, &msg,
  884. &msglen))
  885. return 0;
  886. return 1;
  887. }
  888. static int dtls_print_hello_vfyrequest(BIO *bio, int indent,
  889. const unsigned char *msg, size_t msglen)
  890. {
  891. if (!ssl_print_version(bio, indent, "server_version", &msg, &msglen, NULL))
  892. return 0;
  893. if (!ssl_print_hexbuf(bio, indent, "cookie", 1, &msg, &msglen))
  894. return 0;
  895. return 1;
  896. }
  897. static int ssl_print_server_hello(BIO *bio, int indent,
  898. const unsigned char *msg, size_t msglen)
  899. {
  900. unsigned int cs;
  901. unsigned int vers;
  902. if (!ssl_print_version(bio, indent, "server_version", &msg, &msglen, &vers))
  903. return 0;
  904. if (!ssl_print_random(bio, indent, &msg, &msglen))
  905. return 0;
  906. if (vers != TLS1_3_VERSION
  907. && !ssl_print_hexbuf(bio, indent, "session_id", 1, &msg, &msglen))
  908. return 0;
  909. if (msglen < 2)
  910. return 0;
  911. cs = (msg[0] << 8) | msg[1];
  912. BIO_indent(bio, indent, 80);
  913. BIO_printf(bio, "cipher_suite {0x%02X, 0x%02X} %s\n",
  914. msg[0], msg[1], ssl_trace_str(cs, ssl_ciphers_tbl));
  915. msg += 2;
  916. msglen -= 2;
  917. if (vers != TLS1_3_VERSION) {
  918. if (msglen < 1)
  919. return 0;
  920. BIO_indent(bio, indent, 80);
  921. BIO_printf(bio, "compression_method: %s (0x%02X)\n",
  922. ssl_trace_str(msg[0], ssl_comp_tbl), msg[0]);
  923. msg++;
  924. msglen--;
  925. }
  926. if (!ssl_print_extensions(bio, indent, 1, SSL3_MT_SERVER_HELLO, &msg,
  927. &msglen))
  928. return 0;
  929. return 1;
  930. }
  931. static int ssl_print_hello_retry_request(BIO *bio, int indent,
  932. const unsigned char *msg,
  933. size_t msglen)
  934. {
  935. unsigned int cs;
  936. if (!ssl_print_version(bio, indent, "server_version", &msg, &msglen, NULL))
  937. return 0;
  938. cs = (msg[0] << 8) | msg[1];
  939. BIO_indent(bio, indent, 80);
  940. BIO_printf(bio, "cipher_suite {0x%02X, 0x%02X} %s\n",
  941. msg[0], msg[1], ssl_trace_str(cs, ssl_ciphers_tbl));
  942. msg += 2;
  943. msglen -= 2;
  944. if (!ssl_print_extensions(bio, indent, 1, SSL3_MT_HELLO_RETRY_REQUEST, &msg,
  945. &msglen))
  946. return 0;
  947. return 1;
  948. }
  949. static int ssl_get_keyex(const char **pname, SSL *ssl)
  950. {
  951. unsigned long alg_k = ssl->s3->tmp.new_cipher->algorithm_mkey;
  952. if (alg_k & SSL_kRSA) {
  953. *pname = "rsa";
  954. return SSL_kRSA;
  955. }
  956. if (alg_k & SSL_kDHE) {
  957. *pname = "DHE";
  958. return SSL_kDHE;
  959. }
  960. if (alg_k & SSL_kECDHE) {
  961. *pname = "ECDHE";
  962. return SSL_kECDHE;
  963. }
  964. if (alg_k & SSL_kPSK) {
  965. *pname = "PSK";
  966. return SSL_kPSK;
  967. }
  968. if (alg_k & SSL_kRSAPSK) {
  969. *pname = "RSAPSK";
  970. return SSL_kRSAPSK;
  971. }
  972. if (alg_k & SSL_kDHEPSK) {
  973. *pname = "DHEPSK";
  974. return SSL_kDHEPSK;
  975. }
  976. if (alg_k & SSL_kECDHEPSK) {
  977. *pname = "ECDHEPSK";
  978. return SSL_kECDHEPSK;
  979. }
  980. if (alg_k & SSL_kSRP) {
  981. *pname = "SRP";
  982. return SSL_kSRP;
  983. }
  984. if (alg_k & SSL_kGOST) {
  985. *pname = "GOST";
  986. return SSL_kGOST;
  987. }
  988. *pname = "UNKNOWN";
  989. return 0;
  990. }
  991. static int ssl_print_client_keyex(BIO *bio, int indent, SSL *ssl,
  992. const unsigned char *msg, size_t msglen)
  993. {
  994. const char *algname;
  995. int id = ssl_get_keyex(&algname, ssl);
  996. BIO_indent(bio, indent, 80);
  997. BIO_printf(bio, "KeyExchangeAlgorithm=%s\n", algname);
  998. if (id & SSL_PSK) {
  999. if (!ssl_print_hexbuf(bio, indent + 2,
  1000. "psk_identity", 2, &msg, &msglen))
  1001. return 0;
  1002. }
  1003. switch (id) {
  1004. case SSL_kRSA:
  1005. case SSL_kRSAPSK:
  1006. if (TLS1_get_version(ssl) == SSL3_VERSION) {
  1007. ssl_print_hex(bio, indent + 2,
  1008. "EncyptedPreMasterSecret", msg, msglen);
  1009. } else {
  1010. if (!ssl_print_hexbuf(bio, indent + 2,
  1011. "EncyptedPreMasterSecret", 2, &msg, &msglen))
  1012. return 0;
  1013. }
  1014. break;
  1015. case SSL_kDHE:
  1016. case SSL_kDHEPSK:
  1017. if (!ssl_print_hexbuf(bio, indent + 2, "dh_Yc", 2, &msg, &msglen))
  1018. return 0;
  1019. break;
  1020. case SSL_kECDHE:
  1021. case SSL_kECDHEPSK:
  1022. if (!ssl_print_hexbuf(bio, indent + 2, "ecdh_Yc", 1, &msg, &msglen))
  1023. return 0;
  1024. break;
  1025. }
  1026. return !msglen;
  1027. }
  1028. static int ssl_print_server_keyex(BIO *bio, int indent, SSL *ssl,
  1029. const unsigned char *msg, size_t msglen)
  1030. {
  1031. const char *algname;
  1032. int id = ssl_get_keyex(&algname, ssl);
  1033. BIO_indent(bio, indent, 80);
  1034. BIO_printf(bio, "KeyExchangeAlgorithm=%s\n", algname);
  1035. if (id & SSL_PSK) {
  1036. if (!ssl_print_hexbuf(bio, indent + 2,
  1037. "psk_identity_hint", 2, &msg, &msglen))
  1038. return 0;
  1039. }
  1040. switch (id) {
  1041. case SSL_kRSA:
  1042. if (!ssl_print_hexbuf(bio, indent + 2, "rsa_modulus", 2, &msg, &msglen))
  1043. return 0;
  1044. if (!ssl_print_hexbuf(bio, indent + 2, "rsa_exponent", 2,
  1045. &msg, &msglen))
  1046. return 0;
  1047. break;
  1048. case SSL_kDHE:
  1049. case SSL_kDHEPSK:
  1050. if (!ssl_print_hexbuf(bio, indent + 2, "dh_p", 2, &msg, &msglen))
  1051. return 0;
  1052. if (!ssl_print_hexbuf(bio, indent + 2, "dh_g", 2, &msg, &msglen))
  1053. return 0;
  1054. if (!ssl_print_hexbuf(bio, indent + 2, "dh_Ys", 2, &msg, &msglen))
  1055. return 0;
  1056. break;
  1057. # ifndef OPENSSL_NO_EC
  1058. case SSL_kECDHE:
  1059. case SSL_kECDHEPSK:
  1060. if (msglen < 1)
  1061. return 0;
  1062. BIO_indent(bio, indent + 2, 80);
  1063. if (msg[0] == EXPLICIT_PRIME_CURVE_TYPE)
  1064. BIO_puts(bio, "explicit_prime\n");
  1065. else if (msg[0] == EXPLICIT_CHAR2_CURVE_TYPE)
  1066. BIO_puts(bio, "explicit_char2\n");
  1067. else if (msg[0] == NAMED_CURVE_TYPE) {
  1068. int curve;
  1069. if (msglen < 3)
  1070. return 0;
  1071. curve = (msg[1] << 8) | msg[2];
  1072. BIO_printf(bio, "named_curve: %s (%d)\n",
  1073. ssl_trace_str(curve, ssl_groups_tbl), curve);
  1074. msg += 3;
  1075. msglen -= 3;
  1076. if (!ssl_print_hexbuf(bio, indent + 2, "point", 1, &msg, &msglen))
  1077. return 0;
  1078. } else {
  1079. BIO_printf(bio, "UNKNOWN CURVE PARAMETER TYPE %d\n", msg[0]);
  1080. return 0;
  1081. }
  1082. break;
  1083. # endif
  1084. case SSL_kPSK:
  1085. case SSL_kRSAPSK:
  1086. break;
  1087. }
  1088. if (!(id & SSL_PSK))
  1089. ssl_print_signature(bio, indent, ssl, &msg, &msglen);
  1090. return !msglen;
  1091. }
  1092. static int ssl_print_certificate(BIO *bio, int indent,
  1093. const unsigned char **pmsg, size_t *pmsglen)
  1094. {
  1095. size_t msglen = *pmsglen;
  1096. size_t clen;
  1097. X509 *x;
  1098. const unsigned char *p = *pmsg, *q;
  1099. if (msglen < 3)
  1100. return 0;
  1101. clen = (p[0] << 16) | (p[1] << 8) | p[2];
  1102. if (msglen < clen + 3)
  1103. return 0;
  1104. q = p + 3;
  1105. BIO_indent(bio, indent, 80);
  1106. BIO_printf(bio, "ASN.1Cert, length=%d", (int)clen);
  1107. x = d2i_X509(NULL, &q, clen);
  1108. if (!x)
  1109. BIO_puts(bio, "<UNPARSEABLE CERTIFICATE>\n");
  1110. else {
  1111. BIO_puts(bio, "\n------details-----\n");
  1112. X509_print_ex(bio, x, XN_FLAG_ONELINE, 0);
  1113. PEM_write_bio_X509(bio, x);
  1114. /* Print certificate stuff */
  1115. BIO_puts(bio, "------------------\n");
  1116. X509_free(x);
  1117. }
  1118. if (q != p + 3 + clen) {
  1119. BIO_puts(bio, "<TRAILING GARBAGE AFTER CERTIFICATE>\n");
  1120. }
  1121. *pmsg += clen + 3;
  1122. *pmsglen -= clen + 3;
  1123. return 1;
  1124. }
  1125. static int ssl_print_certificates(BIO *bio, SSL *s, int server, int indent,
  1126. const unsigned char *msg, size_t msglen)
  1127. {
  1128. size_t clen;
  1129. if (SSL_IS_TLS13(s)
  1130. && !ssl_print_hexbuf(bio, indent, "context", 1, &msg, &msglen))
  1131. return 0;
  1132. if (msglen < 3)
  1133. return 0;
  1134. clen = (msg[0] << 16) | (msg[1] << 8) | msg[2];
  1135. if (msglen != clen + 3)
  1136. return 0;
  1137. msg += 3;
  1138. BIO_indent(bio, indent, 80);
  1139. BIO_printf(bio, "certificate_list, length=%d\n", (int)clen);
  1140. while (clen > 0) {
  1141. if (!ssl_print_certificate(bio, indent + 2, &msg, &clen))
  1142. return 0;
  1143. if (!ssl_print_extensions(bio, indent + 2, server, SSL3_MT_CERTIFICATE,
  1144. &msg, &clen))
  1145. return 0;
  1146. }
  1147. return 1;
  1148. }
  1149. static int ssl_print_cert_request(BIO *bio, int indent, SSL *s,
  1150. const unsigned char *msg, size_t msglen)
  1151. {
  1152. size_t xlen;
  1153. unsigned int sigalg;
  1154. if (SSL_IS_TLS13(s)) {
  1155. if (!ssl_print_hexbuf(bio, indent, "request_context", 1, &msg, &msglen))
  1156. return 0;
  1157. } else {
  1158. if (msglen < 1)
  1159. return 0;
  1160. xlen = msg[0];
  1161. if (msglen < xlen + 1)
  1162. return 0;
  1163. msg++;
  1164. BIO_indent(bio, indent, 80);
  1165. BIO_printf(bio, "certificate_types (len=%d)\n", (int)xlen);
  1166. if (!ssl_trace_list(bio, indent + 2, msg, xlen, 1, ssl_ctype_tbl))
  1167. return 0;
  1168. msg += xlen;
  1169. msglen -= xlen + 1;
  1170. }
  1171. if (SSL_USE_SIGALGS(s)) {
  1172. if (msglen < 2)
  1173. return 0;
  1174. xlen = (msg[0] << 8) | msg[1];
  1175. if (msglen < xlen + 2 || (xlen & 1))
  1176. return 0;
  1177. msg += 2;
  1178. msglen -= xlen + 2;
  1179. BIO_indent(bio, indent, 80);
  1180. BIO_printf(bio, "signature_algorithms (len=%d)\n", (int)xlen);
  1181. while (xlen > 0) {
  1182. BIO_indent(bio, indent + 2, 80);
  1183. sigalg = (msg[0] << 8) | msg[1];
  1184. BIO_printf(bio, "%s (0x%04x)\n",
  1185. ssl_trace_str(sigalg, ssl_sigalg_tbl), sigalg);
  1186. xlen -= 2;
  1187. msg += 2;
  1188. }
  1189. msg += xlen;
  1190. }
  1191. xlen = (msg[0] << 8) | msg[1];
  1192. BIO_indent(bio, indent, 80);
  1193. if (msglen < xlen + 2)
  1194. return 0;
  1195. msg += 2;
  1196. msglen -= 2 + xlen;
  1197. BIO_printf(bio, "certificate_authorities (len=%d)\n", (int)xlen);
  1198. while (xlen > 0) {
  1199. size_t dlen;
  1200. X509_NAME *nm;
  1201. const unsigned char *p;
  1202. if (xlen < 2)
  1203. return 0;
  1204. dlen = (msg[0] << 8) | msg[1];
  1205. if (xlen < dlen + 2)
  1206. return 0;
  1207. msg += 2;
  1208. BIO_indent(bio, indent + 2, 80);
  1209. BIO_printf(bio, "DistinguishedName (len=%d): ", (int)dlen);
  1210. p = msg;
  1211. nm = d2i_X509_NAME(NULL, &p, dlen);
  1212. if (!nm) {
  1213. BIO_puts(bio, "<UNPARSEABLE DN>\n");
  1214. } else {
  1215. X509_NAME_print_ex(bio, nm, 0, XN_FLAG_ONELINE);
  1216. BIO_puts(bio, "\n");
  1217. X509_NAME_free(nm);
  1218. }
  1219. xlen -= dlen + 2;
  1220. msg += dlen;
  1221. }
  1222. if (SSL_IS_TLS13(s)) {
  1223. if (!ssl_print_hexbuf(bio, indent, "request_extensions", 2,
  1224. &msg, &msglen))
  1225. return 0;
  1226. }
  1227. return msglen == 0;
  1228. }
  1229. static int ssl_print_ticket(BIO *bio, int indent, SSL *s,
  1230. const unsigned char *msg, size_t msglen)
  1231. {
  1232. unsigned int tick_life;
  1233. if (msglen == 0) {
  1234. BIO_indent(bio, indent + 2, 80);
  1235. BIO_puts(bio, "No Ticket\n");
  1236. return 1;
  1237. }
  1238. if (msglen < 4)
  1239. return 0;
  1240. tick_life = (msg[0] << 24) | (msg[1] << 16) | (msg[2] << 8) | msg[3];
  1241. msglen -= 4;
  1242. msg += 4;
  1243. BIO_indent(bio, indent + 2, 80);
  1244. BIO_printf(bio, "ticket_lifetime_hint=%u\n", tick_life);
  1245. if (SSL_IS_TLS13(s)) {
  1246. unsigned int ticket_age_add;
  1247. if (msglen < 4)
  1248. return 0;
  1249. ticket_age_add = (msg[0] << 24) | (msg[1] << 16) | (msg[2] << 8)
  1250. | msg[3];
  1251. msglen -= 4;
  1252. msg += 4;
  1253. BIO_indent(bio, indent + 2, 80);
  1254. BIO_printf(bio, "ticket_age_add=%u\n", ticket_age_add);
  1255. if (!ssl_print_hexbuf(bio, indent + 2, "ticket_nonce", 1, &msg,
  1256. &msglen))
  1257. return 0;
  1258. }
  1259. if (!ssl_print_hexbuf(bio, indent + 2, "ticket", 2, &msg, &msglen))
  1260. return 0;
  1261. if (SSL_IS_TLS13(s) && !ssl_print_extensions(bio, indent + 2, 0,
  1262. SSL3_MT_NEWSESSION_TICKET,
  1263. &msg, &msglen))
  1264. return 0;
  1265. if (msglen)
  1266. return 0;
  1267. return 1;
  1268. }
  1269. static int ssl_print_handshake(BIO *bio, SSL *ssl, int server,
  1270. const unsigned char *msg, size_t msglen,
  1271. int indent)
  1272. {
  1273. size_t hlen;
  1274. unsigned char htype;
  1275. if (msglen < 4)
  1276. return 0;
  1277. htype = msg[0];
  1278. hlen = (msg[1] << 16) | (msg[2] << 8) | msg[3];
  1279. BIO_indent(bio, indent, 80);
  1280. BIO_printf(bio, "%s, Length=%d\n",
  1281. ssl_trace_str(htype, ssl_handshake_tbl), (int)hlen);
  1282. msg += 4;
  1283. msglen -= 4;
  1284. if (SSL_IS_DTLS(ssl)) {
  1285. if (msglen < 8)
  1286. return 0;
  1287. BIO_indent(bio, indent, 80);
  1288. BIO_printf(bio, "message_seq=%d, fragment_offset=%d, "
  1289. "fragment_length=%d\n",
  1290. (msg[0] << 8) | msg[1],
  1291. (msg[2] << 16) | (msg[3] << 8) | msg[4],
  1292. (msg[5] << 16) | (msg[6] << 8) | msg[7]);
  1293. msg += 8;
  1294. msglen -= 8;
  1295. }
  1296. if (msglen < hlen)
  1297. return 0;
  1298. switch (htype) {
  1299. case SSL3_MT_CLIENT_HELLO:
  1300. if (!ssl_print_client_hello(bio, ssl, indent + 2, msg, msglen))
  1301. return 0;
  1302. break;
  1303. case DTLS1_MT_HELLO_VERIFY_REQUEST:
  1304. if (!dtls_print_hello_vfyrequest(bio, indent + 2, msg, msglen))
  1305. return 0;
  1306. break;
  1307. case SSL3_MT_SERVER_HELLO:
  1308. if (!ssl_print_server_hello(bio, indent + 2, msg, msglen))
  1309. return 0;
  1310. break;
  1311. case SSL3_MT_SERVER_KEY_EXCHANGE:
  1312. if (!ssl_print_server_keyex(bio, indent + 2, ssl, msg, msglen))
  1313. return 0;
  1314. break;
  1315. case SSL3_MT_CLIENT_KEY_EXCHANGE:
  1316. if (!ssl_print_client_keyex(bio, indent + 2, ssl, msg, msglen))
  1317. return 0;
  1318. break;
  1319. case SSL3_MT_CERTIFICATE:
  1320. if (!ssl_print_certificates(bio, ssl, server, indent + 2, msg, msglen))
  1321. return 0;
  1322. break;
  1323. case SSL3_MT_CERTIFICATE_VERIFY:
  1324. if (!ssl_print_signature(bio, indent + 2, ssl, &msg, &msglen))
  1325. return 0;
  1326. break;
  1327. case SSL3_MT_CERTIFICATE_REQUEST:
  1328. if (!ssl_print_cert_request(bio, indent + 2, ssl, msg, msglen))
  1329. return 0;
  1330. break;
  1331. case SSL3_MT_FINISHED:
  1332. ssl_print_hex(bio, indent + 2, "verify_data", msg, msglen);
  1333. break;
  1334. case SSL3_MT_SERVER_DONE:
  1335. if (msglen != 0)
  1336. ssl_print_hex(bio, indent + 2, "unexpected value", msg, msglen);
  1337. break;
  1338. case SSL3_MT_NEWSESSION_TICKET:
  1339. if (!ssl_print_ticket(bio, indent + 2, ssl, msg, msglen))
  1340. return 0;
  1341. break;
  1342. case SSL3_MT_HELLO_RETRY_REQUEST:
  1343. if (!ssl_print_hello_retry_request(bio, indent + 2, msg, msglen))
  1344. return 0;
  1345. break;
  1346. case SSL3_MT_ENCRYPTED_EXTENSIONS:
  1347. if (!ssl_print_extensions(bio, indent + 2, 1,
  1348. SSL3_MT_ENCRYPTED_EXTENSIONS, &msg, &msglen))
  1349. return 0;
  1350. break;
  1351. case SSL3_MT_KEY_UPDATE:
  1352. if (msglen != 1) {
  1353. ssl_print_hex(bio, indent + 2, "unexpected value", msg, msglen);
  1354. return 0;
  1355. }
  1356. if (!ssl_trace_list(bio, indent + 2, msg, msglen, 1,
  1357. ssl_key_update_tbl))
  1358. return 0;
  1359. break;
  1360. default:
  1361. BIO_indent(bio, indent + 2, 80);
  1362. BIO_puts(bio, "Unsupported, hex dump follows:\n");
  1363. BIO_dump_indent(bio, (const char *)msg, msglen, indent + 4);
  1364. }
  1365. return 1;
  1366. }
  1367. void SSL_trace(int write_p, int version, int content_type,
  1368. const void *buf, size_t msglen, SSL *ssl, void *arg)
  1369. {
  1370. const unsigned char *msg = buf;
  1371. BIO *bio = arg;
  1372. switch (content_type) {
  1373. case SSL3_RT_HEADER:
  1374. {
  1375. int hvers = msg[1] << 8 | msg[2];
  1376. BIO_puts(bio, write_p ? "Sent" : "Received");
  1377. BIO_printf(bio, " Record\nHeader:\n Version = %s (0x%x)\n",
  1378. ssl_trace_str(hvers, ssl_version_tbl), hvers);
  1379. if (SSL_IS_DTLS(ssl)) {
  1380. BIO_printf(bio,
  1381. " epoch=%d, sequence_number=%04x%04x%04x\n",
  1382. (msg[3] << 8 | msg[4]),
  1383. (msg[5] << 8 | msg[6]),
  1384. (msg[7] << 8 | msg[8]), (msg[9] << 8 | msg[10]));
  1385. }
  1386. BIO_printf(bio, " Content Type = %s (%d)\n Length = %d",
  1387. ssl_trace_str(msg[0], ssl_content_tbl), msg[0],
  1388. msg[msglen - 2] << 8 | msg[msglen - 1]);
  1389. }
  1390. break;
  1391. case SSL3_RT_INNER_CONTENT_TYPE:
  1392. BIO_printf(bio, " Inner Content Type = %s (%d)",
  1393. ssl_trace_str(msg[0], ssl_content_tbl), msg[0]);
  1394. break;
  1395. case SSL3_RT_HANDSHAKE:
  1396. if (!ssl_print_handshake(bio, ssl, ssl->server ? write_p : !write_p,
  1397. msg, msglen, 4))
  1398. BIO_printf(bio, "Message length parse error!\n");
  1399. break;
  1400. case SSL3_RT_CHANGE_CIPHER_SPEC:
  1401. if (msglen == 1 && msg[0] == 1)
  1402. BIO_puts(bio, " change_cipher_spec (1)\n");
  1403. else
  1404. ssl_print_hex(bio, 4, "unknown value", msg, msglen);
  1405. break;
  1406. case SSL3_RT_ALERT:
  1407. if (msglen != 2)
  1408. BIO_puts(bio, " Illegal Alert Length\n");
  1409. else {
  1410. BIO_printf(bio, " Level=%s(%d), description=%s(%d)\n",
  1411. SSL_alert_type_string_long(msg[0] << 8),
  1412. msg[0], SSL_alert_desc_string_long(msg[1]), msg[1]);
  1413. }
  1414. }
  1415. BIO_puts(bio, "\n");
  1416. }
  1417. #endif