grpc 0.12.0 → 0.13.0.pre1.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (673) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +5707 -22222
  3. data/include/grpc/byte_buffer.h +2 -83
  4. data/include/grpc/census.h +191 -121
  5. data/include/grpc/compression.h +14 -38
  6. data/include/grpc/grpc.h +88 -434
  7. data/include/grpc/grpc_security.h +76 -46
  8. data/include/grpc/grpc_zookeeper.h +1 -1
  9. data/include/grpc/impl/codegen/alloc.h +74 -0
  10. data/include/grpc/impl/codegen/atm.h +92 -0
  11. data/include/grpc/impl/codegen/atm_gcc_atomic.h +72 -0
  12. data/include/grpc/impl/codegen/atm_gcc_sync.h +87 -0
  13. data/include/grpc/impl/codegen/atm_win32.h +125 -0
  14. data/include/grpc/impl/codegen/byte_buffer.h +121 -0
  15. data/include/grpc/impl/codegen/compression_types.h +73 -0
  16. data/include/grpc/impl/codegen/connectivity_state.h +59 -0
  17. data/include/grpc/impl/codegen/grpc_types.h +373 -0
  18. data/include/grpc/impl/codegen/log.h +110 -0
  19. data/include/grpc/impl/codegen/port_platform.h +362 -0
  20. data/include/grpc/impl/codegen/propagation_bits.h +67 -0
  21. data/include/grpc/impl/codegen/slice.h +182 -0
  22. data/include/grpc/impl/codegen/slice_buffer.h +105 -0
  23. data/include/grpc/impl/codegen/status.h +163 -0
  24. data/include/grpc/impl/codegen/sync.h +316 -0
  25. data/include/grpc/impl/codegen/sync_generic.h +55 -0
  26. data/{src/core/census/context.h → include/grpc/impl/codegen/sync_posix.h} +11 -11
  27. data/include/grpc/impl/codegen/sync_win32.h +49 -0
  28. data/include/grpc/impl/codegen/time.h +132 -0
  29. data/include/grpc/status.h +2 -126
  30. data/include/grpc/support/alloc.h +2 -35
  31. data/include/grpc/support/atm.h +2 -55
  32. data/include/grpc/support/atm_gcc_atomic.h +5 -38
  33. data/include/grpc/support/atm_gcc_sync.h +2 -50
  34. data/include/grpc/support/atm_win32.h +2 -88
  35. data/include/grpc/support/avl.h +7 -7
  36. data/include/grpc/support/cmdline.h +15 -13
  37. data/include/grpc/support/cpu.h +5 -3
  38. data/include/grpc/support/histogram.h +23 -20
  39. data/include/grpc/support/host_port.h +5 -3
  40. data/include/grpc/support/log.h +2 -71
  41. data/include/grpc/support/log_win32.h +2 -2
  42. data/include/grpc/support/port_platform.h +2 -319
  43. data/include/grpc/support/slice.h +2 -145
  44. data/include/grpc/support/slice_buffer.h +2 -65
  45. data/include/grpc/support/string_util.h +3 -3
  46. data/include/grpc/support/subprocess.h +8 -6
  47. data/include/grpc/support/sync.h +2 -278
  48. data/include/grpc/support/sync_generic.h +2 -18
  49. data/include/grpc/support/sync_posix.h +2 -10
  50. data/include/grpc/support/sync_win32.h +2 -12
  51. data/include/grpc/support/thd.h +11 -11
  52. data/include/grpc/support/time.h +2 -91
  53. data/include/grpc/support/tls.h +1 -1
  54. data/include/grpc/support/tls_gcc.h +1 -1
  55. data/include/grpc/support/tls_msvc.h +1 -1
  56. data/include/grpc/support/tls_pthread.h +2 -2
  57. data/src/boringssl/err_data.c +1252 -0
  58. data/src/core/census/context.c +492 -8
  59. data/src/core/census/grpc_filter.c +3 -3
  60. data/src/core/census/initialize.c +4 -7
  61. data/src/core/census/operation.c +2 -2
  62. data/src/core/census/placeholders.c +109 -0
  63. data/src/core/census/rpc_metric_id.h +6 -6
  64. data/src/core/census/tracing.c +1 -1
  65. data/src/core/channel/channel_args.c +4 -3
  66. data/src/core/channel/channel_stack.c +1 -1
  67. data/src/core/channel/client_channel.c +18 -14
  68. data/src/core/channel/client_uchannel.c +3 -3
  69. data/src/core/channel/compress_filter.c +8 -8
  70. data/src/core/channel/http_client_filter.c +2 -2
  71. data/src/core/channel/http_server_filter.c +9 -9
  72. data/src/core/channel/subchannel_call_holder.c +12 -10
  73. data/src/core/client_config/lb_policies/pick_first.c +49 -31
  74. data/src/core/client_config/lb_policies/round_robin.c +7 -7
  75. data/src/core/client_config/resolvers/dns_resolver.c +3 -3
  76. data/src/core/client_config/resolvers/sockaddr_resolver.c +5 -5
  77. data/src/core/client_config/subchannel.c +36 -25
  78. data/src/core/compression/algorithm.c +3 -3
  79. data/src/core/httpcli/format_request.c +1 -1
  80. data/src/core/httpcli/httpcli.c +5 -5
  81. data/src/core/httpcli/httpcli_security_connector.c +2 -3
  82. data/src/core/httpcli/parser.c +7 -7
  83. data/src/core/httpcli/parser.h +1 -1
  84. data/src/core/iomgr/closure.c +7 -7
  85. data/src/core/iomgr/closure.h +6 -5
  86. data/src/core/iomgr/exec_ctx.c +12 -8
  87. data/src/core/iomgr/exec_ctx.h +12 -5
  88. data/src/core/iomgr/executor.c +4 -4
  89. data/src/core/iomgr/executor.h +2 -2
  90. data/src/core/iomgr/fd_posix.c +28 -17
  91. data/src/core/iomgr/fd_posix.h +7 -4
  92. data/src/core/iomgr/iocp_windows.c +6 -8
  93. data/src/core/iomgr/pollset_multipoller_with_epoll.c +70 -5
  94. data/src/core/iomgr/pollset_multipoller_with_poll_posix.c +4 -2
  95. data/src/core/iomgr/pollset_posix.c +15 -15
  96. data/src/core/iomgr/pollset_posix.h +4 -2
  97. data/src/core/iomgr/pollset_windows.c +3 -12
  98. data/src/core/iomgr/resolve_address_posix.c +2 -2
  99. data/src/core/iomgr/resolve_address_windows.c +2 -2
  100. data/src/core/iomgr/sockaddr_utils.c +6 -6
  101. data/src/core/iomgr/sockaddr_win32.h +1 -6
  102. data/src/core/iomgr/tcp_client_posix.c +7 -7
  103. data/src/core/iomgr/tcp_client_windows.c +4 -4
  104. data/src/core/iomgr/tcp_posix.c +14 -8
  105. data/src/core/iomgr/tcp_posix.h +7 -1
  106. data/src/core/iomgr/tcp_server.h +40 -20
  107. data/src/core/iomgr/tcp_server_posix.c +106 -49
  108. data/src/core/iomgr/tcp_server_windows.c +98 -49
  109. data/src/core/iomgr/tcp_windows.c +11 -15
  110. data/src/core/iomgr/timer.c +8 -8
  111. data/src/core/iomgr/timer.h +1 -1
  112. data/src/core/iomgr/timer_heap.c +10 -10
  113. data/src/core/iomgr/timer_heap.h +2 -2
  114. data/src/core/iomgr/udp_server.c +2 -12
  115. data/src/core/iomgr/udp_server.h +1 -9
  116. data/src/core/iomgr/workqueue.h +2 -4
  117. data/src/core/iomgr/workqueue_posix.c +3 -3
  118. data/src/core/json/json_reader.c +11 -12
  119. data/src/core/json/json_reader.h +4 -4
  120. data/src/core/json/json_string.c +19 -19
  121. data/src/core/json/json_writer.c +7 -9
  122. data/src/core/profiling/basic_timers.c +1 -1
  123. data/src/core/security/base64.c +9 -9
  124. data/src/core/security/client_auth_filter.c +4 -4
  125. data/src/core/security/credentials.c +5 -5
  126. data/src/core/security/google_default_credentials.c +3 -3
  127. data/src/core/security/handshake.c +6 -5
  128. data/src/core/security/json_token.c +13 -7
  129. data/src/core/security/jwt_verifier.c +3 -2
  130. data/src/core/security/secure_endpoint.c +16 -16
  131. data/src/core/security/security_connector.c +47 -17
  132. data/src/core/security/security_connector.h +5 -5
  133. data/src/core/security/server_auth_filter.c +3 -3
  134. data/src/core/security/server_secure_chttp2.c +30 -31
  135. data/src/core/statistics/census_interface.h +2 -2
  136. data/src/core/statistics/census_rpc_stats.h +3 -3
  137. data/src/core/support/alloc.c +1 -1
  138. data/src/core/support/cpu_posix.c +2 -2
  139. data/src/core/support/env_linux.c +12 -2
  140. data/src/core/support/env_win32.c +15 -7
  141. data/src/core/support/histogram.c +5 -5
  142. data/src/core/support/log_posix.c +1 -1
  143. data/src/core/support/log_win32.c +4 -3
  144. data/src/core/support/murmur_hash.c +11 -11
  145. data/src/core/support/murmur_hash.h +1 -1
  146. data/src/core/support/slice.c +11 -11
  147. data/src/core/support/slice_buffer.c +6 -6
  148. data/src/core/support/stack_lockfree.c +20 -10
  149. data/src/core/support/string.c +15 -15
  150. data/src/core/support/string.h +5 -5
  151. data/src/core/support/string_win32.c +5 -5
  152. data/src/core/support/subprocess_windows.c +141 -0
  153. data/src/core/support/sync.c +4 -4
  154. data/src/core/support/sync_posix.c +2 -2
  155. data/src/core/support/sync_win32.c +10 -5
  156. data/src/core/support/time.c +29 -29
  157. data/src/core/support/time_posix.c +15 -6
  158. data/src/core/support/time_precise.c +2 -2
  159. data/src/core/support/time_win32.c +18 -9
  160. data/src/core/support/tls_pthread.c +1 -1
  161. data/src/core/support/wrap_memcpy.c +53 -0
  162. data/src/core/surface/alarm.c +83 -0
  163. data/src/core/surface/byte_buffer_reader.c +1 -1
  164. data/src/core/surface/call.c +78 -69
  165. data/src/core/surface/call.h +2 -2
  166. data/src/core/surface/call_test_only.h +2 -2
  167. data/src/core/surface/channel.c +9 -9
  168. data/src/core/surface/channel.h +1 -1
  169. data/src/core/surface/channel_connectivity.c +3 -3
  170. data/src/core/surface/channel_create.c +3 -3
  171. data/src/core/surface/channel_ping.c +2 -2
  172. data/src/core/surface/completion_queue.c +11 -12
  173. data/src/core/surface/completion_queue.h +1 -1
  174. data/src/core/surface/init.c +7 -5
  175. data/src/core/surface/lame_client.c +3 -3
  176. data/src/core/surface/secure_channel_create.c +3 -3
  177. data/src/core/surface/server.c +28 -28
  178. data/src/core/surface/server_chttp2.c +8 -8
  179. data/src/core/surface/server_create.c +1 -4
  180. data/src/core/surface/validate_metadata.c +3 -3
  181. data/src/core/surface/version.c +2 -2
  182. data/src/core/transport/byte_stream.c +8 -6
  183. data/src/core/transport/byte_stream.h +6 -5
  184. data/src/core/transport/chttp2/bin_encoder.c +29 -29
  185. data/src/core/transport/chttp2/frame_data.c +29 -26
  186. data/src/core/transport/chttp2/frame_data.h +6 -6
  187. data/src/core/transport/chttp2/frame_goaway.c +30 -30
  188. data/src/core/transport/chttp2/frame_goaway.h +6 -6
  189. data/src/core/transport/chttp2/frame_ping.c +6 -6
  190. data/src/core/transport/chttp2/frame_ping.h +5 -5
  191. data/src/core/transport/chttp2/frame_rst_stream.c +18 -19
  192. data/src/core/transport/chttp2/frame_rst_stream.h +4 -4
  193. data/src/core/transport/chttp2/frame_settings.c +30 -30
  194. data/src/core/transport/chttp2/frame_settings.h +13 -13
  195. data/src/core/transport/chttp2/frame_window_update.c +17 -18
  196. data/src/core/transport/chttp2/frame_window_update.h +5 -7
  197. data/src/core/transport/chttp2/hpack_encoder.c +69 -73
  198. data/src/core/transport/chttp2/hpack_encoder.h +16 -16
  199. data/src/core/transport/chttp2/hpack_parser.c +167 -167
  200. data/src/core/transport/chttp2/hpack_parser.h +16 -16
  201. data/src/core/transport/chttp2/hpack_table.c +13 -13
  202. data/src/core/transport/chttp2/hpack_table.h +11 -11
  203. data/src/core/transport/chttp2/internal.h +97 -86
  204. data/src/core/transport/chttp2/parsing.c +25 -25
  205. data/src/core/transport/chttp2/stream_lists.c +26 -3
  206. data/src/core/transport/chttp2/stream_map.c +13 -14
  207. data/src/core/transport/chttp2/stream_map.h +6 -7
  208. data/src/core/transport/chttp2/timeout_encoding.c +19 -16
  209. data/src/core/transport/chttp2/varint.c +8 -9
  210. data/src/core/transport/chttp2/varint.h +7 -8
  211. data/src/core/transport/chttp2/writing.c +26 -23
  212. data/src/core/transport/chttp2_transport.c +133 -92
  213. data/src/core/transport/connectivity_state.c +6 -6
  214. data/src/core/transport/metadata.c +18 -18
  215. data/src/core/transport/metadata.h +5 -5
  216. data/src/core/transport/static_metadata.c +15 -16
  217. data/src/core/transport/static_metadata.h +5 -5
  218. data/src/core/transport/transport.c +5 -5
  219. data/src/core/transport/transport.h +14 -1
  220. data/src/core/tsi/fake_transport_security.c +7 -7
  221. data/src/core/tsi/ssl_transport_security.c +6 -4
  222. data/src/core/tsi/ssl_types.h +55 -0
  223. data/src/ruby/ext/grpc/extconf.rb +51 -14
  224. data/src/ruby/ext/grpc/rb_byte_buffer.c +3 -1
  225. data/src/ruby/ext/grpc/rb_call.c +6 -3
  226. data/src/ruby/ext/grpc/rb_call_credentials.c +4 -0
  227. data/src/ruby/ext/grpc/rb_channel.c +4 -2
  228. data/src/ruby/ext/grpc/rb_channel_args.c +3 -1
  229. data/src/ruby/ext/grpc/rb_channel_credentials.c +3 -1
  230. data/src/ruby/ext/grpc/rb_completion_queue.c +3 -1
  231. data/src/ruby/ext/grpc/rb_event_thread.c +5 -0
  232. data/src/ruby/ext/grpc/rb_grpc.c +11 -3
  233. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +560 -0
  234. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +843 -0
  235. data/src/ruby/ext/grpc/rb_loader.c +72 -0
  236. data/src/ruby/ext/grpc/rb_loader.h +40 -0
  237. data/src/ruby/ext/grpc/rb_server.c +3 -1
  238. data/src/ruby/ext/grpc/rb_server_credentials.c +4 -2
  239. data/src/ruby/lib/grpc/generic/bidi_call.rb +1 -1
  240. data/src/ruby/lib/grpc/generic/rpc_desc.rb +1 -1
  241. data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
  242. data/src/ruby/lib/grpc/grpc.rb +34 -0
  243. data/src/ruby/lib/grpc/version.rb +1 -1
  244. data/src/ruby/spec/pb/health/checker_spec.rb +1 -1
  245. data/third_party/boringssl/crypto/aes/aes.c +1142 -0
  246. data/third_party/boringssl/crypto/aes/internal.h +87 -0
  247. data/third_party/boringssl/crypto/aes/mode_wrappers.c +108 -0
  248. data/third_party/boringssl/crypto/asn1/a_bitstr.c +255 -0
  249. data/third_party/boringssl/crypto/asn1/a_bool.c +112 -0
  250. data/third_party/boringssl/crypto/asn1/a_bytes.c +317 -0
  251. data/third_party/boringssl/crypto/asn1/a_d2i_fp.c +286 -0
  252. data/third_party/boringssl/crypto/asn1/a_dup.c +103 -0
  253. data/third_party/boringssl/crypto/asn1/a_enum.c +183 -0
  254. data/third_party/boringssl/crypto/asn1/a_gentm.c +255 -0
  255. data/third_party/boringssl/crypto/asn1/a_i2d_fp.c +154 -0
  256. data/third_party/boringssl/crypto/asn1/a_int.c +456 -0
  257. data/third_party/boringssl/crypto/asn1/a_mbstr.c +390 -0
  258. data/third_party/boringssl/crypto/asn1/a_object.c +412 -0
  259. data/third_party/boringssl/crypto/asn1/a_octet.c +70 -0
  260. data/third_party/boringssl/crypto/asn1/a_print.c +119 -0
  261. data/third_party/boringssl/crypto/asn1/a_strnid.c +286 -0
  262. data/third_party/boringssl/crypto/asn1/a_time.c +221 -0
  263. data/third_party/boringssl/crypto/asn1/a_type.c +160 -0
  264. data/third_party/boringssl/crypto/asn1/a_utctm.c +342 -0
  265. data/third_party/boringssl/crypto/asn1/a_utf8.c +210 -0
  266. data/third_party/boringssl/crypto/asn1/asn1_lib.c +510 -0
  267. data/third_party/boringssl/crypto/asn1/asn1_locl.h +73 -0
  268. data/third_party/boringssl/crypto/asn1/asn1_par.c +444 -0
  269. data/third_party/boringssl/crypto/asn1/asn_pack.c +104 -0
  270. data/third_party/boringssl/crypto/asn1/bio_asn1.c +496 -0
  271. data/third_party/boringssl/crypto/asn1/bio_ndef.c +254 -0
  272. data/third_party/boringssl/crypto/asn1/f_enum.c +206 -0
  273. data/third_party/boringssl/crypto/asn1/f_int.c +210 -0
  274. data/third_party/boringssl/crypto/asn1/f_string.c +204 -0
  275. data/third_party/boringssl/crypto/asn1/t_bitst.c +102 -0
  276. data/third_party/boringssl/crypto/asn1/t_pkey.c +112 -0
  277. data/third_party/boringssl/crypto/asn1/tasn_dec.c +1342 -0
  278. data/third_party/boringssl/crypto/asn1/tasn_enc.c +695 -0
  279. data/third_party/boringssl/crypto/asn1/tasn_fre.c +264 -0
  280. data/third_party/boringssl/crypto/asn1/tasn_new.c +398 -0
  281. data/third_party/boringssl/crypto/asn1/tasn_prn.c +642 -0
  282. data/third_party/boringssl/crypto/asn1/tasn_typ.c +137 -0
  283. data/third_party/boringssl/crypto/asn1/tasn_utl.c +266 -0
  284. data/third_party/boringssl/crypto/asn1/x_bignum.c +143 -0
  285. data/third_party/boringssl/crypto/asn1/x_long.c +182 -0
  286. data/third_party/boringssl/crypto/base64/base64.c +478 -0
  287. data/third_party/boringssl/crypto/bio/bio.c +608 -0
  288. data/third_party/boringssl/crypto/bio/bio_mem.c +327 -0
  289. data/third_party/boringssl/crypto/bio/buffer.c +496 -0
  290. data/third_party/boringssl/crypto/bio/connect.c +544 -0
  291. data/third_party/boringssl/crypto/bio/fd.c +270 -0
  292. data/third_party/boringssl/crypto/bio/file.c +349 -0
  293. data/third_party/boringssl/crypto/bio/hexdump.c +192 -0
  294. data/third_party/boringssl/crypto/bio/internal.h +108 -0
  295. data/third_party/boringssl/crypto/bio/pair.c +803 -0
  296. data/third_party/boringssl/crypto/bio/printf.c +119 -0
  297. data/third_party/boringssl/crypto/bio/socket.c +195 -0
  298. data/third_party/boringssl/crypto/bio/socket_helper.c +113 -0
  299. data/third_party/boringssl/crypto/bn/add.c +377 -0
  300. data/third_party/boringssl/crypto/bn/asm/x86_64-gcc.c +599 -0
  301. data/third_party/boringssl/crypto/bn/bn.c +341 -0
  302. data/third_party/boringssl/crypto/bn/bn_asn1.c +93 -0
  303. data/third_party/boringssl/crypto/bn/cmp.c +200 -0
  304. data/third_party/boringssl/crypto/bn/convert.c +597 -0
  305. data/third_party/boringssl/crypto/bn/ctx.c +311 -0
  306. data/third_party/boringssl/crypto/bn/div.c +625 -0
  307. data/third_party/boringssl/crypto/bn/exponentiation.c +1544 -0
  308. data/third_party/boringssl/crypto/bn/gcd.c +711 -0
  309. data/third_party/boringssl/crypto/bn/generic.c +1019 -0
  310. data/third_party/boringssl/crypto/bn/internal.h +294 -0
  311. data/third_party/boringssl/crypto/bn/kronecker.c +175 -0
  312. data/third_party/boringssl/crypto/bn/montgomery.c +561 -0
  313. data/third_party/boringssl/crypto/bn/mul.c +888 -0
  314. data/third_party/boringssl/crypto/bn/prime.c +845 -0
  315. data/third_party/boringssl/crypto/bn/random.c +326 -0
  316. data/third_party/boringssl/crypto/bn/rsaz_exp.c +326 -0
  317. data/third_party/boringssl/crypto/bn/rsaz_exp.h +56 -0
  318. data/third_party/boringssl/crypto/bn/shift.c +299 -0
  319. data/third_party/boringssl/crypto/bn/sqrt.c +505 -0
  320. data/third_party/boringssl/crypto/buf/buf.c +235 -0
  321. data/third_party/boringssl/crypto/bytestring/ber.c +221 -0
  322. data/third_party/boringssl/crypto/bytestring/cbb.c +411 -0
  323. data/third_party/boringssl/crypto/bytestring/cbs.c +415 -0
  324. data/third_party/boringssl/crypto/bytestring/internal.h +46 -0
  325. data/third_party/boringssl/crypto/chacha/chacha_generic.c +140 -0
  326. data/third_party/boringssl/crypto/chacha/chacha_vec.c +323 -0
  327. data/third_party/boringssl/crypto/cipher/aead.c +167 -0
  328. data/third_party/boringssl/crypto/cipher/cipher.c +652 -0
  329. data/third_party/boringssl/crypto/cipher/derive_key.c +154 -0
  330. data/third_party/boringssl/crypto/cipher/e_aes.c +1767 -0
  331. data/third_party/boringssl/crypto/cipher/e_chacha20poly1305.c +311 -0
  332. data/third_party/boringssl/crypto/cipher/e_des.c +207 -0
  333. data/third_party/boringssl/crypto/cipher/e_null.c +85 -0
  334. data/third_party/boringssl/crypto/cipher/e_rc2.c +443 -0
  335. data/third_party/boringssl/crypto/cipher/e_rc4.c +87 -0
  336. data/third_party/boringssl/crypto/cipher/e_ssl3.c +463 -0
  337. data/third_party/boringssl/crypto/cipher/e_tls.c +673 -0
  338. data/third_party/boringssl/crypto/cipher/internal.h +164 -0
  339. data/third_party/boringssl/crypto/cipher/tls_cbc.c +495 -0
  340. data/third_party/boringssl/crypto/cmac/cmac.c +239 -0
  341. data/third_party/boringssl/crypto/conf/conf.c +778 -0
  342. data/third_party/boringssl/crypto/conf/conf_def.h +127 -0
  343. data/third_party/boringssl/crypto/conf/internal.h +31 -0
  344. data/third_party/boringssl/crypto/cpu-arm.c +199 -0
  345. data/third_party/boringssl/crypto/cpu-intel.c +261 -0
  346. data/third_party/boringssl/crypto/crypto.c +140 -0
  347. data/third_party/boringssl/crypto/curve25519/curve25519.c +4897 -0
  348. data/third_party/boringssl/crypto/des/des.c +771 -0
  349. data/third_party/boringssl/crypto/des/internal.h +212 -0
  350. data/third_party/boringssl/crypto/dh/check.c +180 -0
  351. data/third_party/boringssl/crypto/dh/dh.c +463 -0
  352. data/third_party/boringssl/crypto/dh/dh_asn1.c +84 -0
  353. data/third_party/boringssl/crypto/dh/internal.h +80 -0
  354. data/third_party/boringssl/crypto/dh/params.c +301 -0
  355. data/third_party/boringssl/crypto/digest/digest.c +248 -0
  356. data/third_party/boringssl/crypto/digest/digests.c +321 -0
  357. data/third_party/boringssl/crypto/digest/internal.h +112 -0
  358. data/third_party/boringssl/crypto/digest/md32_common.h +322 -0
  359. data/third_party/boringssl/crypto/directory.h +66 -0
  360. data/third_party/boringssl/crypto/directory_posix.c +108 -0
  361. data/third_party/boringssl/crypto/directory_win.c +144 -0
  362. data/third_party/boringssl/crypto/dsa/dsa.c +908 -0
  363. data/third_party/boringssl/crypto/dsa/dsa_asn1.c +150 -0
  364. data/third_party/boringssl/crypto/dsa/internal.h +78 -0
  365. data/third_party/boringssl/crypto/ec/ec.c +889 -0
  366. data/third_party/boringssl/crypto/ec/ec_asn1.c +586 -0
  367. data/third_party/boringssl/crypto/ec/ec_key.c +482 -0
  368. data/third_party/boringssl/crypto/ec/ec_montgomery.c +280 -0
  369. data/third_party/boringssl/crypto/ec/internal.h +318 -0
  370. data/third_party/boringssl/crypto/ec/oct.c +416 -0
  371. data/third_party/boringssl/crypto/ec/p224-64.c +1305 -0
  372. data/third_party/boringssl/crypto/ec/p256-64.c +1878 -0
  373. data/third_party/boringssl/crypto/ec/p256-x86_64-table.h +9548 -0
  374. data/third_party/boringssl/crypto/ec/p256-x86_64.c +596 -0
  375. data/third_party/boringssl/crypto/ec/simple.c +1313 -0
  376. data/third_party/boringssl/crypto/ec/util-64.c +183 -0
  377. data/third_party/boringssl/crypto/ec/wnaf.c +449 -0
  378. data/third_party/boringssl/crypto/ecdh/ecdh.c +153 -0
  379. data/third_party/boringssl/crypto/ecdsa/ecdsa.c +496 -0
  380. data/third_party/boringssl/crypto/ecdsa/ecdsa_asn1.c +240 -0
  381. data/third_party/boringssl/crypto/engine/engine.c +96 -0
  382. data/third_party/boringssl/crypto/err/err.c +756 -0
  383. data/third_party/boringssl/crypto/evp/algorithm.c +153 -0
  384. data/third_party/boringssl/crypto/evp/digestsign.c +159 -0
  385. data/third_party/boringssl/crypto/evp/evp.c +411 -0
  386. data/third_party/boringssl/crypto/evp/evp_asn1.c +179 -0
  387. data/third_party/boringssl/crypto/evp/evp_ctx.c +477 -0
  388. data/third_party/boringssl/crypto/evp/internal.h +278 -0
  389. data/third_party/boringssl/crypto/evp/p_dsa_asn1.c +588 -0
  390. data/third_party/boringssl/crypto/evp/p_ec.c +283 -0
  391. data/third_party/boringssl/crypto/evp/p_ec_asn1.c +562 -0
  392. data/third_party/boringssl/crypto/evp/p_rsa.c +596 -0
  393. data/third_party/boringssl/crypto/evp/p_rsa_asn1.c +737 -0
  394. data/third_party/boringssl/crypto/evp/pbkdf.c +151 -0
  395. data/third_party/boringssl/crypto/evp/sign.c +151 -0
  396. data/third_party/boringssl/crypto/ex_data.c +294 -0
  397. data/third_party/boringssl/crypto/hkdf/hkdf.c +89 -0
  398. data/third_party/boringssl/crypto/hmac/hmac.c +213 -0
  399. data/third_party/boringssl/crypto/internal.h +532 -0
  400. data/third_party/boringssl/crypto/lhash/lhash.c +346 -0
  401. data/third_party/boringssl/crypto/md4/md4.c +225 -0
  402. data/third_party/boringssl/crypto/md5/md5.c +275 -0
  403. data/third_party/boringssl/crypto/mem.c +200 -0
  404. data/third_party/boringssl/crypto/modes/cbc.c +216 -0
  405. data/third_party/boringssl/crypto/modes/cfb.c +231 -0
  406. data/third_party/boringssl/crypto/modes/ctr.c +226 -0
  407. data/third_party/boringssl/crypto/modes/gcm.c +1252 -0
  408. data/third_party/boringssl/crypto/modes/internal.h +370 -0
  409. data/third_party/boringssl/crypto/modes/ofb.c +108 -0
  410. data/third_party/boringssl/crypto/obj/obj.c +664 -0
  411. data/third_party/boringssl/crypto/obj/obj_dat.h +5257 -0
  412. data/third_party/boringssl/crypto/obj/obj_xref.c +124 -0
  413. data/third_party/boringssl/crypto/obj/obj_xref.h +96 -0
  414. data/third_party/boringssl/crypto/pem/pem_all.c +281 -0
  415. data/third_party/boringssl/crypto/pem/pem_info.c +404 -0
  416. data/third_party/boringssl/crypto/pem/pem_lib.c +835 -0
  417. data/third_party/boringssl/crypto/pem/pem_oth.c +89 -0
  418. data/third_party/boringssl/crypto/pem/pem_pk8.c +244 -0
  419. data/third_party/boringssl/crypto/pem/pem_pkey.c +312 -0
  420. data/third_party/boringssl/crypto/pem/pem_x509.c +65 -0
  421. data/third_party/boringssl/crypto/pem/pem_xaux.c +66 -0
  422. data/third_party/boringssl/crypto/pkcs8/internal.h +83 -0
  423. data/third_party/boringssl/crypto/pkcs8/p5_pbe.c +150 -0
  424. data/third_party/boringssl/crypto/pkcs8/p5_pbev2.c +440 -0
  425. data/third_party/boringssl/crypto/pkcs8/p8_pkey.c +85 -0
  426. data/third_party/boringssl/crypto/pkcs8/pkcs8.c +1217 -0
  427. data/third_party/boringssl/crypto/poly1305/poly1305.c +331 -0
  428. data/third_party/boringssl/crypto/poly1305/poly1305_arm.c +301 -0
  429. data/third_party/boringssl/crypto/poly1305/poly1305_vec.c +892 -0
  430. data/third_party/boringssl/crypto/rand/internal.h +32 -0
  431. data/third_party/boringssl/crypto/rand/rand.c +239 -0
  432. data/third_party/boringssl/crypto/rand/urandom.c +223 -0
  433. data/third_party/boringssl/crypto/rand/windows.c +56 -0
  434. data/third_party/boringssl/crypto/rc4/rc4.c +283 -0
  435. data/third_party/boringssl/crypto/refcount_c11.c +67 -0
  436. data/third_party/boringssl/crypto/refcount_lock.c +53 -0
  437. data/third_party/boringssl/crypto/rsa/blinding.c +462 -0
  438. data/third_party/boringssl/crypto/rsa/internal.h +164 -0
  439. data/third_party/boringssl/crypto/rsa/padding.c +711 -0
  440. data/third_party/boringssl/crypto/rsa/rsa.c +808 -0
  441. data/third_party/boringssl/crypto/rsa/rsa_asn1.c +473 -0
  442. data/third_party/boringssl/crypto/rsa/rsa_impl.c +1138 -0
  443. data/third_party/boringssl/crypto/sha/sha1.c +337 -0
  444. data/third_party/boringssl/crypto/sha/sha256.c +327 -0
  445. data/third_party/boringssl/crypto/sha/sha512.c +607 -0
  446. data/third_party/boringssl/crypto/stack/stack.c +386 -0
  447. data/third_party/boringssl/crypto/test/scoped_types.h +137 -0
  448. data/third_party/boringssl/crypto/test/test_util.h +35 -0
  449. data/third_party/boringssl/crypto/thread.c +101 -0
  450. data/third_party/boringssl/crypto/thread_none.c +55 -0
  451. data/third_party/boringssl/crypto/thread_pthread.c +167 -0
  452. data/third_party/boringssl/crypto/thread_win.c +282 -0
  453. data/third_party/boringssl/crypto/time_support.c +212 -0
  454. data/third_party/boringssl/crypto/x509/a_digest.c +97 -0
  455. data/third_party/boringssl/crypto/x509/a_sign.c +136 -0
  456. data/third_party/boringssl/crypto/x509/a_strex.c +564 -0
  457. data/third_party/boringssl/crypto/x509/a_verify.c +133 -0
  458. data/third_party/boringssl/crypto/x509/asn1_gen.c +873 -0
  459. data/third_party/boringssl/crypto/x509/by_dir.c +491 -0
  460. data/third_party/boringssl/crypto/x509/by_file.c +295 -0
  461. data/third_party/boringssl/crypto/x509/charmap.h +15 -0
  462. data/third_party/boringssl/crypto/x509/i2d_pr.c +84 -0
  463. data/third_party/boringssl/crypto/x509/pkcs7.c +353 -0
  464. data/third_party/boringssl/crypto/x509/t_crl.c +129 -0
  465. data/third_party/boringssl/crypto/x509/t_req.c +246 -0
  466. data/third_party/boringssl/crypto/x509/t_x509.c +500 -0
  467. data/third_party/boringssl/crypto/x509/t_x509a.c +109 -0
  468. data/third_party/boringssl/crypto/x509/vpm_int.h +70 -0
  469. data/third_party/boringssl/crypto/x509/x509.c +152 -0
  470. data/third_party/boringssl/crypto/x509/x509_att.c +353 -0
  471. data/third_party/boringssl/crypto/x509/x509_cmp.c +490 -0
  472. data/third_party/boringssl/crypto/x509/x509_d2.c +105 -0
  473. data/third_party/boringssl/crypto/x509/x509_def.c +88 -0
  474. data/third_party/boringssl/crypto/x509/x509_ext.c +206 -0
  475. data/third_party/boringssl/crypto/x509/x509_lu.c +738 -0
  476. data/third_party/boringssl/crypto/x509/x509_obj.c +191 -0
  477. data/third_party/boringssl/crypto/x509/x509_r2x.c +113 -0
  478. data/third_party/boringssl/crypto/x509/x509_req.c +315 -0
  479. data/third_party/boringssl/crypto/x509/x509_set.c +154 -0
  480. data/third_party/boringssl/crypto/x509/x509_trs.c +304 -0
  481. data/third_party/boringssl/crypto/x509/x509_txt.c +209 -0
  482. data/third_party/boringssl/crypto/x509/x509_v3.c +271 -0
  483. data/third_party/boringssl/crypto/x509/x509_vfy.c +2456 -0
  484. data/third_party/boringssl/crypto/x509/x509_vpm.c +672 -0
  485. data/third_party/boringssl/crypto/x509/x509cset.c +172 -0
  486. data/third_party/boringssl/crypto/x509/x509name.c +381 -0
  487. data/third_party/boringssl/crypto/x509/x509rset.c +80 -0
  488. data/third_party/boringssl/crypto/x509/x509spki.c +135 -0
  489. data/third_party/boringssl/crypto/x509/x509type.c +128 -0
  490. data/third_party/boringssl/crypto/x509/x_algor.c +154 -0
  491. data/third_party/boringssl/crypto/x509/x_all.c +547 -0
  492. data/third_party/boringssl/crypto/x509/x_attrib.c +117 -0
  493. data/third_party/boringssl/crypto/x509/x_crl.c +560 -0
  494. data/third_party/boringssl/crypto/x509/x_exten.c +75 -0
  495. data/third_party/boringssl/crypto/x509/x_info.c +95 -0
  496. data/third_party/boringssl/crypto/x509/x_name.c +538 -0
  497. data/third_party/boringssl/crypto/x509/x_pkey.c +100 -0
  498. data/third_party/boringssl/crypto/x509/x_pubkey.c +384 -0
  499. data/third_party/boringssl/crypto/x509/x_req.c +112 -0
  500. data/third_party/boringssl/crypto/x509/x_sig.c +69 -0
  501. data/third_party/boringssl/crypto/x509/x_spki.c +78 -0
  502. data/third_party/boringssl/crypto/x509/x_val.c +69 -0
  503. data/third_party/boringssl/crypto/x509/x_x509.c +227 -0
  504. data/third_party/boringssl/crypto/x509/x_x509a.c +197 -0
  505. data/third_party/boringssl/crypto/x509v3/ext_dat.h +129 -0
  506. data/third_party/boringssl/crypto/x509v3/pcy_cache.c +299 -0
  507. data/third_party/boringssl/crypto/x509v3/pcy_data.c +137 -0
  508. data/third_party/boringssl/crypto/x509v3/pcy_int.h +212 -0
  509. data/third_party/boringssl/crypto/x509v3/pcy_lib.c +165 -0
  510. data/third_party/boringssl/crypto/x509v3/pcy_map.c +133 -0
  511. data/third_party/boringssl/crypto/x509v3/pcy_node.c +197 -0
  512. data/third_party/boringssl/crypto/x509v3/pcy_tree.c +876 -0
  513. data/third_party/boringssl/crypto/x509v3/v3_akey.c +212 -0
  514. data/third_party/boringssl/crypto/x509v3/v3_akeya.c +71 -0
  515. data/third_party/boringssl/crypto/x509v3/v3_alt.c +622 -0
  516. data/third_party/boringssl/crypto/x509v3/v3_bcons.c +126 -0
  517. data/third_party/boringssl/crypto/x509v3/v3_bitst.c +141 -0
  518. data/third_party/boringssl/crypto/x509v3/v3_conf.c +459 -0
  519. data/third_party/boringssl/crypto/x509v3/v3_cpols.c +475 -0
  520. data/third_party/boringssl/crypto/x509v3/v3_crld.c +616 -0
  521. data/third_party/boringssl/crypto/x509v3/v3_enum.c +98 -0
  522. data/third_party/boringssl/crypto/x509v3/v3_extku.c +145 -0
  523. data/third_party/boringssl/crypto/x509v3/v3_genn.c +252 -0
  524. data/third_party/boringssl/crypto/x509v3/v3_ia5.c +117 -0
  525. data/third_party/boringssl/crypto/x509v3/v3_info.c +200 -0
  526. data/third_party/boringssl/crypto/x509v3/v3_int.c +87 -0
  527. data/third_party/boringssl/crypto/x509v3/v3_lib.c +335 -0
  528. data/third_party/boringssl/crypto/x509v3/v3_ncons.c +510 -0
  529. data/third_party/boringssl/crypto/x509v3/v3_pci.c +335 -0
  530. data/third_party/boringssl/crypto/x509v3/v3_pcia.c +56 -0
  531. data/third_party/boringssl/crypto/x509v3/v3_pcons.c +142 -0
  532. data/third_party/boringssl/crypto/x509v3/v3_pku.c +109 -0
  533. data/third_party/boringssl/crypto/x509v3/v3_pmaps.c +156 -0
  534. data/third_party/boringssl/crypto/x509v3/v3_prn.c +207 -0
  535. data/third_party/boringssl/crypto/x509v3/v3_purp.c +805 -0
  536. data/third_party/boringssl/crypto/x509v3/v3_skey.c +148 -0
  537. data/third_party/boringssl/crypto/x509v3/v3_sxnet.c +266 -0
  538. data/third_party/boringssl/crypto/x509v3/v3_utl.c +1322 -0
  539. data/third_party/boringssl/include/openssl/aead.h +346 -0
  540. data/third_party/boringssl/include/openssl/aes.h +158 -0
  541. data/third_party/boringssl/include/openssl/arm_arch.h +127 -0
  542. data/third_party/boringssl/include/openssl/asn1.h +1168 -0
  543. data/third_party/boringssl/include/openssl/asn1_mac.h +75 -0
  544. data/third_party/boringssl/include/openssl/asn1t.h +906 -0
  545. data/third_party/boringssl/include/openssl/base.h +261 -0
  546. data/third_party/boringssl/include/openssl/base64.h +184 -0
  547. data/third_party/boringssl/include/openssl/bio.h +902 -0
  548. data/third_party/boringssl/include/openssl/blowfish.h +93 -0
  549. data/third_party/boringssl/include/openssl/bn.h +885 -0
  550. data/third_party/boringssl/include/openssl/buf.h +118 -0
  551. data/third_party/boringssl/include/openssl/buffer.h +18 -0
  552. data/third_party/boringssl/include/openssl/bytestring.h +360 -0
  553. data/third_party/boringssl/include/openssl/cast.h +96 -0
  554. data/third_party/boringssl/include/openssl/chacha.h +37 -0
  555. data/third_party/boringssl/include/openssl/cipher.h +571 -0
  556. data/third_party/boringssl/include/openssl/cmac.h +76 -0
  557. data/third_party/boringssl/include/openssl/conf.h +145 -0
  558. data/third_party/boringssl/include/openssl/cpu.h +184 -0
  559. data/third_party/boringssl/include/openssl/crypto.h +68 -0
  560. data/third_party/boringssl/include/openssl/curve25519.h +88 -0
  561. data/third_party/boringssl/include/openssl/des.h +177 -0
  562. data/third_party/boringssl/include/openssl/dh.h +238 -0
  563. data/third_party/boringssl/include/openssl/digest.h +258 -0
  564. data/third_party/boringssl/include/openssl/dsa.h +343 -0
  565. data/third_party/boringssl/include/openssl/dtls1.h +16 -0
  566. data/third_party/boringssl/include/openssl/ec.h +355 -0
  567. data/third_party/boringssl/include/openssl/ec_key.h +280 -0
  568. data/third_party/boringssl/include/openssl/ecdh.h +102 -0
  569. data/third_party/boringssl/include/openssl/ecdsa.h +206 -0
  570. data/third_party/boringssl/include/openssl/engine.h +98 -0
  571. data/third_party/boringssl/include/openssl/err.h +487 -0
  572. data/third_party/boringssl/include/openssl/evp.h +750 -0
  573. data/third_party/boringssl/include/openssl/ex_data.h +213 -0
  574. data/third_party/boringssl/include/openssl/hkdf.h +44 -0
  575. data/third_party/boringssl/include/openssl/hmac.h +160 -0
  576. data/third_party/boringssl/include/openssl/lhash.h +192 -0
  577. data/third_party/boringssl/include/openssl/lhash_macros.h +132 -0
  578. data/third_party/boringssl/include/openssl/md4.h +102 -0
  579. data/third_party/boringssl/include/openssl/md5.h +107 -0
  580. data/third_party/boringssl/include/openssl/mem.h +140 -0
  581. data/third_party/boringssl/include/openssl/obj.h +198 -0
  582. data/third_party/boringssl/include/openssl/obj_mac.h +4140 -0
  583. data/third_party/boringssl/include/openssl/objects.h +18 -0
  584. data/third_party/boringssl/include/openssl/opensslfeatures.h +60 -0
  585. data/third_party/boringssl/include/openssl/opensslv.h +18 -0
  586. data/third_party/boringssl/include/openssl/ossl_typ.h +18 -0
  587. data/third_party/boringssl/include/openssl/pem.h +521 -0
  588. data/third_party/boringssl/include/openssl/pkcs12.h +18 -0
  589. data/third_party/boringssl/include/openssl/pkcs7.h +16 -0
  590. data/third_party/boringssl/include/openssl/pkcs8.h +220 -0
  591. data/third_party/boringssl/include/openssl/poly1305.h +51 -0
  592. data/third_party/boringssl/include/openssl/pqueue.h +146 -0
  593. data/third_party/boringssl/include/openssl/rand.h +113 -0
  594. data/third_party/boringssl/include/openssl/rc4.h +90 -0
  595. data/third_party/boringssl/include/openssl/rsa.h +637 -0
  596. data/third_party/boringssl/include/openssl/safestack.h +16 -0
  597. data/third_party/boringssl/include/openssl/sha.h +256 -0
  598. data/third_party/boringssl/include/openssl/srtp.h +18 -0
  599. data/third_party/boringssl/include/openssl/ssl.h +4466 -0
  600. data/third_party/boringssl/include/openssl/ssl3.h +441 -0
  601. data/third_party/boringssl/include/openssl/stack.h +298 -0
  602. data/third_party/boringssl/include/openssl/stack_macros.h +4190 -0
  603. data/third_party/boringssl/include/openssl/thread.h +173 -0
  604. data/third_party/boringssl/include/openssl/time_support.h +90 -0
  605. data/third_party/boringssl/include/openssl/tls1.h +653 -0
  606. data/third_party/boringssl/include/openssl/type_check.h +91 -0
  607. data/third_party/boringssl/include/openssl/x509.h +1258 -0
  608. data/third_party/boringssl/include/openssl/x509_vfy.h +611 -0
  609. data/third_party/boringssl/include/openssl/x509v3.h +798 -0
  610. data/third_party/boringssl/ssl/custom_extensions.c +257 -0
  611. data/third_party/boringssl/ssl/d1_both.c +880 -0
  612. data/third_party/boringssl/ssl/d1_clnt.c +566 -0
  613. data/third_party/boringssl/ssl/d1_lib.c +340 -0
  614. data/third_party/boringssl/ssl/d1_meth.c +130 -0
  615. data/third_party/boringssl/ssl/d1_pkt.c +578 -0
  616. data/third_party/boringssl/ssl/d1_srtp.c +234 -0
  617. data/third_party/boringssl/ssl/d1_srvr.c +485 -0
  618. data/third_party/boringssl/ssl/dtls_record.c +308 -0
  619. data/third_party/boringssl/ssl/internal.h +1276 -0
  620. data/third_party/boringssl/ssl/pqueue/pqueue.c +197 -0
  621. data/third_party/boringssl/ssl/s3_both.c +571 -0
  622. data/third_party/boringssl/ssl/s3_clnt.c +2241 -0
  623. data/third_party/boringssl/ssl/s3_enc.c +494 -0
  624. data/third_party/boringssl/ssl/s3_lib.c +587 -0
  625. data/third_party/boringssl/ssl/s3_meth.c +166 -0
  626. data/third_party/boringssl/ssl/s3_pkt.c +732 -0
  627. data/third_party/boringssl/ssl/s3_srvr.c +2536 -0
  628. data/third_party/boringssl/ssl/ssl_aead_ctx.c +300 -0
  629. data/third_party/boringssl/ssl/ssl_asn1.c +718 -0
  630. data/third_party/boringssl/ssl/ssl_buffer.c +319 -0
  631. data/third_party/boringssl/ssl/ssl_cert.c +539 -0
  632. data/third_party/boringssl/ssl/ssl_cipher.c +2003 -0
  633. data/third_party/boringssl/ssl/ssl_file.c +633 -0
  634. data/third_party/boringssl/ssl/ssl_lib.c +2653 -0
  635. data/third_party/boringssl/ssl/ssl_rsa.c +423 -0
  636. data/third_party/boringssl/ssl/ssl_session.c +764 -0
  637. data/third_party/boringssl/ssl/ssl_stat.c +591 -0
  638. data/third_party/boringssl/ssl/t1_enc.c +708 -0
  639. data/third_party/boringssl/ssl/t1_lib.c +2905 -0
  640. data/third_party/boringssl/ssl/test/async_bio.h +45 -0
  641. data/third_party/boringssl/ssl/test/packeted_bio.h +44 -0
  642. data/third_party/boringssl/ssl/test/scoped_types.h +28 -0
  643. data/third_party/boringssl/ssl/test/test_config.h +108 -0
  644. data/third_party/boringssl/ssl/tls_record.c +342 -0
  645. data/third_party/zlib/adler32.c +179 -0
  646. data/third_party/zlib/compress.c +80 -0
  647. data/third_party/zlib/crc32.c +425 -0
  648. data/third_party/zlib/crc32.h +441 -0
  649. data/third_party/zlib/deflate.c +1967 -0
  650. data/third_party/zlib/deflate.h +346 -0
  651. data/third_party/zlib/gzclose.c +25 -0
  652. data/third_party/zlib/gzguts.h +209 -0
  653. data/third_party/zlib/gzlib.c +634 -0
  654. data/third_party/zlib/gzread.c +594 -0
  655. data/third_party/zlib/gzwrite.c +577 -0
  656. data/third_party/zlib/infback.c +640 -0
  657. data/third_party/zlib/inffast.c +340 -0
  658. data/third_party/zlib/inffast.h +11 -0
  659. data/third_party/zlib/inffixed.h +94 -0
  660. data/third_party/zlib/inflate.c +1512 -0
  661. data/third_party/zlib/inflate.h +122 -0
  662. data/third_party/zlib/inftrees.c +306 -0
  663. data/third_party/zlib/inftrees.h +62 -0
  664. data/third_party/zlib/trees.c +1226 -0
  665. data/third_party/zlib/trees.h +128 -0
  666. data/third_party/zlib/uncompr.c +59 -0
  667. data/third_party/zlib/zconf.h +511 -0
  668. data/third_party/zlib/zlib.h +1768 -0
  669. data/third_party/zlib/zutil.c +324 -0
  670. data/third_party/zlib/zutil.h +253 -0
  671. metadata +492 -25
  672. data/Rakefile +0 -63
  673. data/src/ruby/lib/grpc/grpc.so +0 -0
@@ -0,0 +1,2653 @@
1
+ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
2
+ * All rights reserved.
3
+ *
4
+ * This package is an SSL implementation written
5
+ * by Eric Young (eay@cryptsoft.com).
6
+ * The implementation was written so as to conform with Netscapes SSL.
7
+ *
8
+ * This library is free for commercial and non-commercial use as long as
9
+ * the following conditions are aheared to. The following conditions
10
+ * apply to all code found in this distribution, be it the RC4, RSA,
11
+ * lhash, DES, etc., code; not just the SSL code. The SSL documentation
12
+ * included with this distribution is covered by the same copyright terms
13
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).
14
+ *
15
+ * Copyright remains Eric Young's, and as such any Copyright notices in
16
+ * the code are not to be removed.
17
+ * If this package is used in a product, Eric Young should be given attribution
18
+ * as the author of the parts of the library used.
19
+ * This can be in the form of a textual message at program startup or
20
+ * in documentation (online or textual) provided with the package.
21
+ *
22
+ * Redistribution and use in source and binary forms, with or without
23
+ * modification, are permitted provided that the following conditions
24
+ * are met:
25
+ * 1. Redistributions of source code must retain the copyright
26
+ * notice, this list of conditions and the following disclaimer.
27
+ * 2. Redistributions in binary form must reproduce the above copyright
28
+ * notice, this list of conditions and the following disclaimer in the
29
+ * documentation and/or other materials provided with the distribution.
30
+ * 3. All advertising materials mentioning features or use of this software
31
+ * must display the following acknowledgement:
32
+ * "This product includes cryptographic software written by
33
+ * Eric Young (eay@cryptsoft.com)"
34
+ * The word 'cryptographic' can be left out if the rouines from the library
35
+ * being used are not cryptographic related :-).
36
+ * 4. If you include any Windows specific code (or a derivative thereof) from
37
+ * the apps directory (application code) you must include an acknowledgement:
38
+ * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
39
+ *
40
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50
+ * SUCH DAMAGE.
51
+ *
52
+ * The licence and distribution terms for any publically available version or
53
+ * derivative of this code cannot be changed. i.e. this code cannot simply be
54
+ * copied and put under another distribution licence
55
+ * [including the GNU Public Licence.]
56
+ */
57
+ /* ====================================================================
58
+ * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
59
+ *
60
+ * Redistribution and use in source and binary forms, with or without
61
+ * modification, are permitted provided that the following conditions
62
+ * are met:
63
+ *
64
+ * 1. Redistributions of source code must retain the above copyright
65
+ * notice, this list of conditions and the following disclaimer.
66
+ *
67
+ * 2. Redistributions in binary form must reproduce the above copyright
68
+ * notice, this list of conditions and the following disclaimer in
69
+ * the documentation and/or other materials provided with the
70
+ * distribution.
71
+ *
72
+ * 3. All advertising materials mentioning features or use of this
73
+ * software must display the following acknowledgment:
74
+ * "This product includes software developed by the OpenSSL Project
75
+ * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
76
+ *
77
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
78
+ * endorse or promote products derived from this software without
79
+ * prior written permission. For written permission, please contact
80
+ * openssl-core@openssl.org.
81
+ *
82
+ * 5. Products derived from this software may not be called "OpenSSL"
83
+ * nor may "OpenSSL" appear in their names without prior written
84
+ * permission of the OpenSSL Project.
85
+ *
86
+ * 6. Redistributions of any form whatsoever must retain the following
87
+ * acknowledgment:
88
+ * "This product includes software developed by the OpenSSL Project
89
+ * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
90
+ *
91
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
92
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
93
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
94
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
95
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
96
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
97
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
98
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
99
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
100
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
101
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
102
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
103
+ * ====================================================================
104
+ *
105
+ * This product includes cryptographic software written by Eric Young
106
+ * (eay@cryptsoft.com). This product includes software written by Tim
107
+ * Hudson (tjh@cryptsoft.com).
108
+ *
109
+ */
110
+ /* ====================================================================
111
+ * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
112
+ * ECC cipher suite support in OpenSSL originally developed by
113
+ * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
114
+ */
115
+ /* ====================================================================
116
+ * Copyright 2005 Nokia. All rights reserved.
117
+ *
118
+ * The portions of the attached software ("Contribution") is developed by
119
+ * Nokia Corporation and is licensed pursuant to the OpenSSL open source
120
+ * license.
121
+ *
122
+ * The Contribution, originally written by Mika Kousa and Pasi Eronen of
123
+ * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
124
+ * support (see RFC 4279) to OpenSSL.
125
+ *
126
+ * No patent licenses or other rights except those expressly stated in
127
+ * the OpenSSL open source license shall be deemed granted or received
128
+ * expressly, by implication, estoppel, or otherwise.
129
+ *
130
+ * No assurances are provided by Nokia that the Contribution does not
131
+ * infringe the patent or other intellectual property rights of any third
132
+ * party or that the license provides you with all the necessary rights
133
+ * to make use of the Contribution.
134
+ *
135
+ * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
136
+ * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
137
+ * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
138
+ * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
139
+ * OTHERWISE. */
140
+
141
+ #include <openssl/ssl.h>
142
+
143
+ #include <assert.h>
144
+ #include <stdio.h>
145
+ #include <string.h>
146
+
147
+ #include <openssl/bytestring.h>
148
+ #include <openssl/crypto.h>
149
+ #include <openssl/dh.h>
150
+ #include <openssl/err.h>
151
+ #include <openssl/lhash.h>
152
+ #include <openssl/mem.h>
153
+ #include <openssl/obj.h>
154
+ #include <openssl/rand.h>
155
+ #include <openssl/x509v3.h>
156
+
157
+ #include "internal.h"
158
+ #include "../crypto/internal.h"
159
+
160
+
161
+ /* |SSL_R_UNKNOWN_PROTOCOL| is no longer emitted, but continue to define it
162
+ * to avoid downstream churn. */
163
+ OPENSSL_DECLARE_ERROR_REASON(SSL, UNKNOWN_PROTOCOL)
164
+
165
+ /* Some error codes are special. Ensure the make_errors.go script never
166
+ * regresses this. */
167
+ OPENSSL_COMPILE_ASSERT(SSL_R_TLSV1_ALERT_NO_RENEGOTIATION ==
168
+ SSL_AD_NO_RENEGOTIATION + SSL_AD_REASON_OFFSET,
169
+ ssl_alert_reason_code_mismatch);
170
+
171
+ /* kMaxHandshakeSize is the maximum size, in bytes, of a handshake message. */
172
+ static const size_t kMaxHandshakeSize = (1u << 24) - 1;
173
+
174
+ static CRYPTO_EX_DATA_CLASS g_ex_data_class_ssl =
175
+ CRYPTO_EX_DATA_CLASS_INIT_WITH_APP_DATA;
176
+ static CRYPTO_EX_DATA_CLASS g_ex_data_class_ssl_ctx =
177
+ CRYPTO_EX_DATA_CLASS_INIT_WITH_APP_DATA;
178
+
179
+ int SSL_library_init(void) {
180
+ CRYPTO_library_init();
181
+ return 1;
182
+ }
183
+
184
+ static uint32_t ssl_session_hash(const SSL_SESSION *a) {
185
+ uint32_t hash =
186
+ ((uint32_t)a->session_id[0]) |
187
+ ((uint32_t)a->session_id[1] << 8) |
188
+ ((uint32_t)a->session_id[2] << 16) |
189
+ ((uint32_t)a->session_id[3] << 24);
190
+
191
+ return hash;
192
+ }
193
+
194
+ /* NB: If this function (or indeed the hash function which uses a sort of
195
+ * coarser function than this one) is changed, ensure
196
+ * SSL_CTX_has_matching_session_id() is checked accordingly. It relies on being
197
+ * able to construct an SSL_SESSION that will collide with any existing session
198
+ * with a matching session ID. */
199
+ static int ssl_session_cmp(const SSL_SESSION *a, const SSL_SESSION *b) {
200
+ if (a->ssl_version != b->ssl_version) {
201
+ return 1;
202
+ }
203
+
204
+ if (a->session_id_length != b->session_id_length) {
205
+ return 1;
206
+ }
207
+
208
+ return memcmp(a->session_id, b->session_id, a->session_id_length);
209
+ }
210
+
211
+ SSL_CTX *SSL_CTX_new(const SSL_METHOD *method) {
212
+ SSL_CTX *ret = NULL;
213
+
214
+ if (method == NULL) {
215
+ OPENSSL_PUT_ERROR(SSL, SSL_R_NULL_SSL_METHOD_PASSED);
216
+ return NULL;
217
+ }
218
+
219
+ if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0) {
220
+ OPENSSL_PUT_ERROR(SSL, SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);
221
+ goto err;
222
+ }
223
+
224
+ ret = (SSL_CTX *)OPENSSL_malloc(sizeof(SSL_CTX));
225
+ if (ret == NULL) {
226
+ goto err;
227
+ }
228
+
229
+ memset(ret, 0, sizeof(SSL_CTX));
230
+
231
+ ret->method = method->method;
232
+
233
+ CRYPTO_MUTEX_init(&ret->lock);
234
+
235
+ ret->session_cache_mode = SSL_SESS_CACHE_SERVER;
236
+ ret->session_cache_size = SSL_SESSION_CACHE_MAX_SIZE_DEFAULT;
237
+
238
+ /* We take the system default */
239
+ ret->session_timeout = SSL_DEFAULT_SESSION_TIMEOUT;
240
+
241
+ ret->references = 1;
242
+
243
+ ret->max_cert_list = SSL_MAX_CERT_LIST_DEFAULT;
244
+ ret->verify_mode = SSL_VERIFY_NONE;
245
+ ret->cert = ssl_cert_new();
246
+ if (ret->cert == NULL) {
247
+ goto err;
248
+ }
249
+
250
+ ret->sessions = lh_SSL_SESSION_new(ssl_session_hash, ssl_session_cmp);
251
+ if (ret->sessions == NULL) {
252
+ goto err;
253
+ }
254
+ ret->cert_store = X509_STORE_new();
255
+ if (ret->cert_store == NULL) {
256
+ goto err;
257
+ }
258
+
259
+ ssl_create_cipher_list(ret->method, &ret->cipher_list,
260
+ &ret->cipher_list_by_id, SSL_DEFAULT_CIPHER_LIST);
261
+ if (ret->cipher_list == NULL ||
262
+ sk_SSL_CIPHER_num(ret->cipher_list->ciphers) <= 0) {
263
+ OPENSSL_PUT_ERROR(SSL, SSL_R_LIBRARY_HAS_NO_CIPHERS);
264
+ goto err2;
265
+ }
266
+
267
+ ret->param = X509_VERIFY_PARAM_new();
268
+ if (!ret->param) {
269
+ goto err;
270
+ }
271
+
272
+ ret->client_CA = sk_X509_NAME_new_null();
273
+ if (ret->client_CA == NULL) {
274
+ goto err;
275
+ }
276
+
277
+ CRYPTO_new_ex_data(&ret->ex_data);
278
+
279
+ ret->max_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH;
280
+
281
+ /* Setup RFC4507 ticket keys */
282
+ if (!RAND_bytes(ret->tlsext_tick_key_name, 16) ||
283
+ !RAND_bytes(ret->tlsext_tick_hmac_key, 16) ||
284
+ !RAND_bytes(ret->tlsext_tick_aes_key, 16)) {
285
+ ret->options |= SSL_OP_NO_TICKET;
286
+ }
287
+
288
+ /* Lock the SSL_CTX to the specified version, for compatibility with legacy
289
+ * uses of SSL_METHOD. */
290
+ if (method->version != 0) {
291
+ SSL_CTX_set_max_version(ret, method->version);
292
+ SSL_CTX_set_min_version(ret, method->version);
293
+ }
294
+
295
+ return ret;
296
+
297
+ err:
298
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
299
+ err2:
300
+ SSL_CTX_free(ret);
301
+ return NULL;
302
+ }
303
+
304
+ void SSL_CTX_free(SSL_CTX *ctx) {
305
+ if (ctx == NULL ||
306
+ !CRYPTO_refcount_dec_and_test_zero(&ctx->references)) {
307
+ return;
308
+ }
309
+
310
+ X509_VERIFY_PARAM_free(ctx->param);
311
+
312
+ /* Free internal session cache. However: the remove_cb() may reference the
313
+ * ex_data of SSL_CTX, thus the ex_data store can only be removed after the
314
+ * sessions were flushed. As the ex_data handling routines might also touch
315
+ * the session cache, the most secure solution seems to be: empty (flush) the
316
+ * cache, then free ex_data, then finally free the cache. (See ticket
317
+ * [openssl.org #212].) */
318
+ SSL_CTX_flush_sessions(ctx, 0);
319
+
320
+ CRYPTO_free_ex_data(&g_ex_data_class_ssl_ctx, ctx, &ctx->ex_data);
321
+
322
+ CRYPTO_MUTEX_cleanup(&ctx->lock);
323
+ lh_SSL_SESSION_free(ctx->sessions);
324
+ X509_STORE_free(ctx->cert_store);
325
+ ssl_cipher_preference_list_free(ctx->cipher_list);
326
+ sk_SSL_CIPHER_free(ctx->cipher_list_by_id);
327
+ ssl_cipher_preference_list_free(ctx->cipher_list_tls10);
328
+ ssl_cipher_preference_list_free(ctx->cipher_list_tls11);
329
+ ssl_cert_free(ctx->cert);
330
+ sk_SSL_CUSTOM_EXTENSION_pop_free(ctx->client_custom_extensions,
331
+ SSL_CUSTOM_EXTENSION_free);
332
+ sk_SSL_CUSTOM_EXTENSION_pop_free(ctx->server_custom_extensions,
333
+ SSL_CUSTOM_EXTENSION_free);
334
+ sk_X509_NAME_pop_free(ctx->client_CA, X509_NAME_free);
335
+ sk_SRTP_PROTECTION_PROFILE_free(ctx->srtp_profiles);
336
+ OPENSSL_free(ctx->psk_identity_hint);
337
+ OPENSSL_free(ctx->tlsext_ellipticcurvelist);
338
+ OPENSSL_free(ctx->alpn_client_proto_list);
339
+ OPENSSL_free(ctx->ocsp_response);
340
+ OPENSSL_free(ctx->signed_cert_timestamp_list);
341
+ EVP_PKEY_free(ctx->tlsext_channel_id_private);
342
+
343
+ OPENSSL_free(ctx);
344
+ }
345
+
346
+ SSL *SSL_new(SSL_CTX *ctx) {
347
+ SSL *s;
348
+
349
+ if (ctx == NULL) {
350
+ OPENSSL_PUT_ERROR(SSL, SSL_R_NULL_SSL_CTX);
351
+ return NULL;
352
+ }
353
+ if (ctx->method == NULL) {
354
+ OPENSSL_PUT_ERROR(SSL, SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);
355
+ return NULL;
356
+ }
357
+
358
+ s = (SSL *)OPENSSL_malloc(sizeof(SSL));
359
+ if (s == NULL) {
360
+ goto err;
361
+ }
362
+ memset(s, 0, sizeof(SSL));
363
+
364
+ s->min_version = ctx->min_version;
365
+ s->max_version = ctx->max_version;
366
+
367
+ s->options = ctx->options;
368
+ s->mode = ctx->mode;
369
+ s->max_cert_list = ctx->max_cert_list;
370
+
371
+ s->cert = ssl_cert_dup(ctx->cert);
372
+ if (s->cert == NULL) {
373
+ goto err;
374
+ }
375
+
376
+ s->msg_callback = ctx->msg_callback;
377
+ s->msg_callback_arg = ctx->msg_callback_arg;
378
+ s->verify_mode = ctx->verify_mode;
379
+ s->sid_ctx_length = ctx->sid_ctx_length;
380
+ assert(s->sid_ctx_length <= sizeof s->sid_ctx);
381
+ memcpy(&s->sid_ctx, &ctx->sid_ctx, sizeof(s->sid_ctx));
382
+ s->verify_callback = ctx->default_verify_callback;
383
+
384
+ s->param = X509_VERIFY_PARAM_new();
385
+ if (!s->param) {
386
+ goto err;
387
+ }
388
+ X509_VERIFY_PARAM_inherit(s->param, ctx->param);
389
+ s->quiet_shutdown = ctx->quiet_shutdown;
390
+ s->max_send_fragment = ctx->max_send_fragment;
391
+
392
+ CRYPTO_refcount_inc(&ctx->references);
393
+ s->ctx = ctx;
394
+ CRYPTO_refcount_inc(&ctx->references);
395
+ s->initial_ctx = ctx;
396
+
397
+ if (ctx->tlsext_ellipticcurvelist) {
398
+ s->tlsext_ellipticcurvelist =
399
+ BUF_memdup(ctx->tlsext_ellipticcurvelist,
400
+ ctx->tlsext_ellipticcurvelist_length * 2);
401
+ if (!s->tlsext_ellipticcurvelist) {
402
+ goto err;
403
+ }
404
+ s->tlsext_ellipticcurvelist_length = ctx->tlsext_ellipticcurvelist_length;
405
+ }
406
+
407
+ if (s->ctx->alpn_client_proto_list) {
408
+ s->alpn_client_proto_list = BUF_memdup(s->ctx->alpn_client_proto_list,
409
+ s->ctx->alpn_client_proto_list_len);
410
+ if (s->alpn_client_proto_list == NULL) {
411
+ goto err;
412
+ }
413
+ s->alpn_client_proto_list_len = s->ctx->alpn_client_proto_list_len;
414
+ }
415
+
416
+ s->verify_result = X509_V_OK;
417
+ s->method = ctx->method;
418
+
419
+ if (!s->method->ssl_new(s)) {
420
+ goto err;
421
+ }
422
+ s->enc_method = ssl3_get_enc_method(s->version);
423
+ assert(s->enc_method != NULL);
424
+
425
+ s->rwstate = SSL_NOTHING;
426
+
427
+ CRYPTO_new_ex_data(&s->ex_data);
428
+
429
+ s->psk_identity_hint = NULL;
430
+ if (ctx->psk_identity_hint) {
431
+ s->psk_identity_hint = BUF_strdup(ctx->psk_identity_hint);
432
+ if (s->psk_identity_hint == NULL) {
433
+ goto err;
434
+ }
435
+ }
436
+ s->psk_client_callback = ctx->psk_client_callback;
437
+ s->psk_server_callback = ctx->psk_server_callback;
438
+
439
+ s->tlsext_channel_id_enabled = ctx->tlsext_channel_id_enabled;
440
+ if (ctx->tlsext_channel_id_private) {
441
+ s->tlsext_channel_id_private =
442
+ EVP_PKEY_up_ref(ctx->tlsext_channel_id_private);
443
+ }
444
+
445
+ s->signed_cert_timestamps_enabled = s->ctx->signed_cert_timestamps_enabled;
446
+ s->ocsp_stapling_enabled = s->ctx->ocsp_stapling_enabled;
447
+
448
+ return s;
449
+
450
+ err:
451
+ SSL_free(s);
452
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
453
+
454
+ return NULL;
455
+ }
456
+
457
+ void SSL_free(SSL *ssl) {
458
+ if (ssl == NULL) {
459
+ return;
460
+ }
461
+
462
+ X509_VERIFY_PARAM_free(ssl->param);
463
+
464
+ CRYPTO_free_ex_data(&g_ex_data_class_ssl, ssl, &ssl->ex_data);
465
+
466
+ if (ssl->bbio != NULL) {
467
+ /* If the buffering BIO is in place, pop it off */
468
+ if (ssl->bbio == ssl->wbio) {
469
+ ssl->wbio = BIO_pop(ssl->wbio);
470
+ }
471
+ BIO_free(ssl->bbio);
472
+ ssl->bbio = NULL;
473
+ }
474
+
475
+ int free_wbio = ssl->wbio != ssl->rbio;
476
+ BIO_free_all(ssl->rbio);
477
+ if (free_wbio) {
478
+ BIO_free_all(ssl->wbio);
479
+ }
480
+
481
+ BUF_MEM_free(ssl->init_buf);
482
+
483
+ /* add extra stuff */
484
+ ssl_cipher_preference_list_free(ssl->cipher_list);
485
+ sk_SSL_CIPHER_free(ssl->cipher_list_by_id);
486
+
487
+ ssl_clear_bad_session(ssl);
488
+ SSL_SESSION_free(ssl->session);
489
+
490
+ ssl_clear_cipher_ctx(ssl);
491
+
492
+ ssl_cert_free(ssl->cert);
493
+
494
+ OPENSSL_free(ssl->tlsext_hostname);
495
+ SSL_CTX_free(ssl->initial_ctx);
496
+ OPENSSL_free(ssl->tlsext_ellipticcurvelist);
497
+ OPENSSL_free(ssl->alpn_client_proto_list);
498
+ EVP_PKEY_free(ssl->tlsext_channel_id_private);
499
+ OPENSSL_free(ssl->psk_identity_hint);
500
+ sk_X509_NAME_pop_free(ssl->client_CA, X509_NAME_free);
501
+ OPENSSL_free(ssl->next_proto_negotiated);
502
+ sk_SRTP_PROTECTION_PROFILE_free(ssl->srtp_profiles);
503
+
504
+ if (ssl->method != NULL) {
505
+ ssl->method->ssl_free(ssl);
506
+ }
507
+ SSL_CTX_free(ssl->ctx);
508
+
509
+ OPENSSL_free(ssl);
510
+ }
511
+
512
+ void SSL_set_connect_state(SSL *ssl) {
513
+ ssl->server = 0;
514
+ ssl->shutdown = 0;
515
+ ssl->state = SSL_ST_CONNECT;
516
+ ssl->handshake_func = ssl->method->ssl_connect;
517
+ /* clear the current cipher */
518
+ ssl_clear_cipher_ctx(ssl);
519
+ }
520
+
521
+ void SSL_set_accept_state(SSL *ssl) {
522
+ ssl->server = 1;
523
+ ssl->shutdown = 0;
524
+ ssl->state = SSL_ST_ACCEPT;
525
+ ssl->handshake_func = ssl->method->ssl_accept;
526
+ /* clear the current cipher */
527
+ ssl_clear_cipher_ctx(ssl);
528
+ }
529
+
530
+ void SSL_set_bio(SSL *ssl, BIO *rbio, BIO *wbio) {
531
+ /* If the output buffering BIO is still in place, remove it. */
532
+ if (ssl->bbio != NULL) {
533
+ if (ssl->wbio == ssl->bbio) {
534
+ ssl->wbio = ssl->wbio->next_bio;
535
+ ssl->bbio->next_bio = NULL;
536
+ }
537
+ }
538
+
539
+ if (ssl->rbio != rbio) {
540
+ BIO_free_all(ssl->rbio);
541
+ }
542
+ if (ssl->wbio != wbio && ssl->rbio != ssl->wbio) {
543
+ BIO_free_all(ssl->wbio);
544
+ }
545
+ ssl->rbio = rbio;
546
+ ssl->wbio = wbio;
547
+ }
548
+
549
+ BIO *SSL_get_rbio(const SSL *ssl) { return ssl->rbio; }
550
+
551
+ BIO *SSL_get_wbio(const SSL *ssl) { return ssl->wbio; }
552
+
553
+ int SSL_do_handshake(SSL *ssl) {
554
+ if (ssl->handshake_func == NULL) {
555
+ OPENSSL_PUT_ERROR(SSL, SSL_R_CONNECTION_TYPE_NOT_SET);
556
+ return -1;
557
+ }
558
+
559
+ if (!SSL_in_init(ssl)) {
560
+ return 1;
561
+ }
562
+
563
+ return ssl->handshake_func(ssl);
564
+ }
565
+
566
+ int SSL_connect(SSL *ssl) {
567
+ if (ssl->handshake_func == 0) {
568
+ /* Not properly initialized yet */
569
+ SSL_set_connect_state(ssl);
570
+ }
571
+
572
+ if (ssl->handshake_func != ssl->method->ssl_connect) {
573
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
574
+ return -1;
575
+ }
576
+
577
+ return ssl->handshake_func(ssl);
578
+ }
579
+
580
+ int SSL_accept(SSL *ssl) {
581
+ if (ssl->handshake_func == 0) {
582
+ /* Not properly initialized yet */
583
+ SSL_set_accept_state(ssl);
584
+ }
585
+
586
+ if (ssl->handshake_func != ssl->method->ssl_accept) {
587
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
588
+ return -1;
589
+ }
590
+
591
+ return ssl->handshake_func(ssl);
592
+ }
593
+
594
+ int SSL_read(SSL *ssl, void *buf, int num) {
595
+ if (ssl->handshake_func == 0) {
596
+ OPENSSL_PUT_ERROR(SSL, SSL_R_UNINITIALIZED);
597
+ return -1;
598
+ }
599
+
600
+ if (ssl->shutdown & SSL_RECEIVED_SHUTDOWN) {
601
+ ssl->rwstate = SSL_NOTHING;
602
+ return 0;
603
+ }
604
+
605
+ ERR_clear_system_error();
606
+ return ssl->method->ssl_read_app_data(ssl, buf, num, 0);
607
+ }
608
+
609
+ int SSL_peek(SSL *ssl, void *buf, int num) {
610
+ if (ssl->handshake_func == 0) {
611
+ OPENSSL_PUT_ERROR(SSL, SSL_R_UNINITIALIZED);
612
+ return -1;
613
+ }
614
+
615
+ if (ssl->shutdown & SSL_RECEIVED_SHUTDOWN) {
616
+ return 0;
617
+ }
618
+
619
+ ERR_clear_system_error();
620
+ return ssl->method->ssl_read_app_data(ssl, buf, num, 1);
621
+ }
622
+
623
+ int SSL_write(SSL *ssl, const void *buf, int num) {
624
+ if (ssl->handshake_func == 0) {
625
+ OPENSSL_PUT_ERROR(SSL, SSL_R_UNINITIALIZED);
626
+ return -1;
627
+ }
628
+
629
+ if (ssl->shutdown & SSL_SENT_SHUTDOWN) {
630
+ ssl->rwstate = SSL_NOTHING;
631
+ OPENSSL_PUT_ERROR(SSL, SSL_R_PROTOCOL_IS_SHUTDOWN);
632
+ return -1;
633
+ }
634
+
635
+ ERR_clear_system_error();
636
+ return ssl->method->ssl_write_app_data(ssl, buf, num);
637
+ }
638
+
639
+ int SSL_shutdown(SSL *ssl) {
640
+ /* Note that this function behaves differently from what one might expect.
641
+ * Return values are 0 for no success (yet), 1 for success; but calling it
642
+ * once is usually not enough, even if blocking I/O is used (see
643
+ * ssl3_shutdown). */
644
+
645
+ if (ssl->handshake_func == 0) {
646
+ OPENSSL_PUT_ERROR(SSL, SSL_R_UNINITIALIZED);
647
+ return -1;
648
+ }
649
+
650
+ if (SSL_in_init(ssl)) {
651
+ return 1;
652
+ }
653
+
654
+ /* Do nothing if configured not to send a close_notify. */
655
+ if (ssl->quiet_shutdown) {
656
+ ssl->shutdown = SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN;
657
+ return 1;
658
+ }
659
+
660
+ if (!(ssl->shutdown & SSL_SENT_SHUTDOWN)) {
661
+ ssl->shutdown |= SSL_SENT_SHUTDOWN;
662
+ ssl3_send_alert(ssl, SSL3_AL_WARNING, SSL_AD_CLOSE_NOTIFY);
663
+
664
+ /* our shutdown alert has been sent now, and if it still needs to be
665
+ * written, ssl->s3->alert_dispatch will be true */
666
+ if (ssl->s3->alert_dispatch) {
667
+ return -1; /* return WANT_WRITE */
668
+ }
669
+ } else if (ssl->s3->alert_dispatch) {
670
+ /* resend it if not sent */
671
+ int ret = ssl->method->ssl_dispatch_alert(ssl);
672
+ if (ret == -1) {
673
+ /* we only get to return -1 here the 2nd/Nth invocation, we must have
674
+ * already signalled return 0 upon a previous invoation, return
675
+ * WANT_WRITE */
676
+ return ret;
677
+ }
678
+ } else if (!(ssl->shutdown & SSL_RECEIVED_SHUTDOWN)) {
679
+ /* If we are waiting for a close from our peer, we are closed */
680
+ ssl->method->ssl_read_close_notify(ssl);
681
+ if (!(ssl->shutdown & SSL_RECEIVED_SHUTDOWN)) {
682
+ return -1; /* return WANT_READ */
683
+ }
684
+ }
685
+
686
+ if (ssl->shutdown == (SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN) &&
687
+ !ssl->s3->alert_dispatch) {
688
+ return 1;
689
+ } else {
690
+ return 0;
691
+ }
692
+ }
693
+
694
+ int SSL_get_error(const SSL *ssl, int ret_code) {
695
+ int reason;
696
+ uint32_t err;
697
+ BIO *bio;
698
+
699
+ if (ret_code > 0) {
700
+ return SSL_ERROR_NONE;
701
+ }
702
+
703
+ /* Make things return SSL_ERROR_SYSCALL when doing SSL_do_handshake etc,
704
+ * where we do encode the error */
705
+ err = ERR_peek_error();
706
+ if (err != 0) {
707
+ if (ERR_GET_LIB(err) == ERR_LIB_SYS) {
708
+ return SSL_ERROR_SYSCALL;
709
+ }
710
+ return SSL_ERROR_SSL;
711
+ }
712
+
713
+ if (ret_code == 0) {
714
+ if ((ssl->shutdown & SSL_RECEIVED_SHUTDOWN) &&
715
+ (ssl->s3->warn_alert == SSL_AD_CLOSE_NOTIFY)) {
716
+ /* The socket was cleanly shut down with a close_notify. */
717
+ return SSL_ERROR_ZERO_RETURN;
718
+ }
719
+ /* An EOF was observed which violates the protocol, and the underlying
720
+ * transport does not participate in the error queue. Bubble up to the
721
+ * caller. */
722
+ return SSL_ERROR_SYSCALL;
723
+ }
724
+
725
+ if (SSL_want_session(ssl)) {
726
+ return SSL_ERROR_PENDING_SESSION;
727
+ }
728
+
729
+ if (SSL_want_certificate(ssl)) {
730
+ return SSL_ERROR_PENDING_CERTIFICATE;
731
+ }
732
+
733
+ if (SSL_want_read(ssl)) {
734
+ bio = SSL_get_rbio(ssl);
735
+ if (BIO_should_read(bio)) {
736
+ return SSL_ERROR_WANT_READ;
737
+ }
738
+
739
+ if (BIO_should_write(bio)) {
740
+ /* This one doesn't make too much sense ... We never try to write to the
741
+ * rbio, and an application program where rbio and wbio are separate
742
+ * couldn't even know what it should wait for. However if we ever set
743
+ * s->rwstate incorrectly (so that we have SSL_want_read(s) instead of
744
+ * SSL_want_write(s)) and rbio and wbio *are* the same, this test works
745
+ * around that bug; so it might be safer to keep it. */
746
+ return SSL_ERROR_WANT_WRITE;
747
+ }
748
+
749
+ if (BIO_should_io_special(bio)) {
750
+ reason = BIO_get_retry_reason(bio);
751
+ if (reason == BIO_RR_CONNECT) {
752
+ return SSL_ERROR_WANT_CONNECT;
753
+ }
754
+
755
+ if (reason == BIO_RR_ACCEPT) {
756
+ return SSL_ERROR_WANT_ACCEPT;
757
+ }
758
+
759
+ return SSL_ERROR_SYSCALL; /* unknown */
760
+ }
761
+ }
762
+
763
+ if (SSL_want_write(ssl)) {
764
+ bio = SSL_get_wbio(ssl);
765
+ if (BIO_should_write(bio)) {
766
+ return SSL_ERROR_WANT_WRITE;
767
+ }
768
+
769
+ if (BIO_should_read(bio)) {
770
+ /* See above (SSL_want_read(ssl) with BIO_should_write(bio)) */
771
+ return SSL_ERROR_WANT_READ;
772
+ }
773
+
774
+ if (BIO_should_io_special(bio)) {
775
+ reason = BIO_get_retry_reason(bio);
776
+ if (reason == BIO_RR_CONNECT) {
777
+ return SSL_ERROR_WANT_CONNECT;
778
+ }
779
+
780
+ if (reason == BIO_RR_ACCEPT) {
781
+ return SSL_ERROR_WANT_ACCEPT;
782
+ }
783
+
784
+ return SSL_ERROR_SYSCALL;
785
+ }
786
+ }
787
+
788
+ if (SSL_want_x509_lookup(ssl)) {
789
+ return SSL_ERROR_WANT_X509_LOOKUP;
790
+ }
791
+
792
+ if (SSL_want_channel_id_lookup(ssl)) {
793
+ return SSL_ERROR_WANT_CHANNEL_ID_LOOKUP;
794
+ }
795
+
796
+ if (SSL_want_private_key_operation(ssl)) {
797
+ return SSL_ERROR_WANT_PRIVATE_KEY_OPERATION;
798
+ }
799
+
800
+ return SSL_ERROR_SYSCALL;
801
+ }
802
+
803
+ void SSL_CTX_set_min_version(SSL_CTX *ctx, uint16_t version) {
804
+ ctx->min_version = version;
805
+ }
806
+
807
+ void SSL_CTX_set_max_version(SSL_CTX *ctx, uint16_t version) {
808
+ ctx->max_version = version;
809
+ }
810
+
811
+ void SSL_set_min_version(SSL *ssl, uint16_t version) {
812
+ ssl->min_version = version;
813
+ }
814
+
815
+ void SSL_set_max_version(SSL *ssl, uint16_t version) {
816
+ ssl->max_version = version;
817
+ }
818
+
819
+ uint32_t SSL_CTX_set_options(SSL_CTX *ctx, uint32_t options) {
820
+ ctx->options |= options;
821
+ return ctx->options;
822
+ }
823
+
824
+ uint32_t SSL_CTX_clear_options(SSL_CTX *ctx, uint32_t options) {
825
+ ctx->options &= ~options;
826
+ return ctx->options;
827
+ }
828
+
829
+ uint32_t SSL_CTX_get_options(const SSL_CTX *ctx) { return ctx->options; }
830
+
831
+ uint32_t SSL_set_options(SSL *ssl, uint32_t options) {
832
+ ssl->options |= options;
833
+ return ssl->options;
834
+ }
835
+
836
+ uint32_t SSL_clear_options(SSL *ssl, uint32_t options) {
837
+ ssl->options &= ~options;
838
+ return ssl->options;
839
+ }
840
+
841
+ uint32_t SSL_get_options(const SSL *ssl) { return ssl->options; }
842
+
843
+ uint32_t SSL_CTX_set_mode(SSL_CTX *ctx, uint32_t mode) {
844
+ ctx->mode |= mode;
845
+ return ctx->mode;
846
+ }
847
+
848
+ uint32_t SSL_CTX_clear_mode(SSL_CTX *ctx, uint32_t mode) {
849
+ ctx->mode &= ~mode;
850
+ return ctx->mode;
851
+ }
852
+
853
+ uint32_t SSL_CTX_get_mode(const SSL_CTX *ctx) { return ctx->mode; }
854
+
855
+ uint32_t SSL_set_mode(SSL *ssl, uint32_t mode) {
856
+ ssl->mode |= mode;
857
+ return ssl->mode;
858
+ }
859
+
860
+ uint32_t SSL_clear_mode(SSL *ssl, uint32_t mode) {
861
+ ssl->mode &= ~mode;
862
+ return ssl->mode;
863
+ }
864
+
865
+ uint32_t SSL_get_mode(const SSL *ssl) { return ssl->mode; }
866
+
867
+ X509 *SSL_get_peer_certificate(const SSL *ssl) {
868
+ if (ssl == NULL || ssl->session == NULL || ssl->session->peer == NULL) {
869
+ return NULL;
870
+ }
871
+ return X509_up_ref(ssl->session->peer);
872
+ }
873
+
874
+ STACK_OF(X509) *SSL_get_peer_cert_chain(const SSL *ssl) {
875
+ if (ssl == NULL || ssl->session == NULL) {
876
+ return NULL;
877
+ }
878
+ return ssl->session->cert_chain;
879
+ }
880
+
881
+ int SSL_get_tls_unique(const SSL *ssl, uint8_t *out, size_t *out_len,
882
+ size_t max_out) {
883
+ /* The tls-unique value is the first Finished message in the handshake, which
884
+ * is the client's in a full handshake and the server's for a resumption. See
885
+ * https://tools.ietf.org/html/rfc5929#section-3.1. */
886
+ const uint8_t *finished = ssl->s3->previous_client_finished;
887
+ size_t finished_len = ssl->s3->previous_client_finished_len;
888
+ if (ssl->hit) {
889
+ /* tls-unique is broken for resumed sessions unless EMS is used. */
890
+ if (!ssl->session->extended_master_secret) {
891
+ goto err;
892
+ }
893
+ finished = ssl->s3->previous_server_finished;
894
+ finished_len = ssl->s3->previous_server_finished_len;
895
+ }
896
+
897
+ if (!ssl->s3->initial_handshake_complete ||
898
+ ssl->version < TLS1_VERSION) {
899
+ goto err;
900
+ }
901
+
902
+ *out_len = finished_len;
903
+ if (finished_len > max_out) {
904
+ *out_len = max_out;
905
+ }
906
+
907
+ memcpy(out, finished, *out_len);
908
+ return 1;
909
+
910
+ err:
911
+ *out_len = 0;
912
+ memset(out, 0, max_out);
913
+ return 0;
914
+ }
915
+
916
+ int SSL_CTX_set_session_id_context(SSL_CTX *ctx, const uint8_t *sid_ctx,
917
+ unsigned sid_ctx_len) {
918
+ if (sid_ctx_len > sizeof(ctx->sid_ctx)) {
919
+ OPENSSL_PUT_ERROR(SSL, SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG);
920
+ return 0;
921
+ }
922
+ ctx->sid_ctx_length = sid_ctx_len;
923
+ memcpy(ctx->sid_ctx, sid_ctx, sid_ctx_len);
924
+
925
+ return 1;
926
+ }
927
+
928
+ int SSL_set_session_id_context(SSL *ssl, const uint8_t *sid_ctx,
929
+ unsigned sid_ctx_len) {
930
+ if (sid_ctx_len > SSL_MAX_SID_CTX_LENGTH) {
931
+ OPENSSL_PUT_ERROR(SSL, SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG);
932
+ return 0;
933
+ }
934
+ ssl->sid_ctx_length = sid_ctx_len;
935
+ memcpy(ssl->sid_ctx, sid_ctx, sid_ctx_len);
936
+
937
+ return 1;
938
+ }
939
+
940
+ int SSL_CTX_set_purpose(SSL_CTX *ctx, int purpose) {
941
+ return X509_VERIFY_PARAM_set_purpose(ctx->param, purpose);
942
+ }
943
+
944
+ int SSL_set_purpose(SSL *ssl, int purpose) {
945
+ return X509_VERIFY_PARAM_set_purpose(ssl->param, purpose);
946
+ }
947
+
948
+ int SSL_CTX_set_trust(SSL_CTX *ctx, int trust) {
949
+ return X509_VERIFY_PARAM_set_trust(ctx->param, trust);
950
+ }
951
+
952
+ int SSL_set_trust(SSL *ssl, int trust) {
953
+ return X509_VERIFY_PARAM_set_trust(ssl->param, trust);
954
+ }
955
+
956
+ int SSL_CTX_set1_param(SSL_CTX *ctx, const X509_VERIFY_PARAM *param) {
957
+ return X509_VERIFY_PARAM_set1(ctx->param, param);
958
+ }
959
+
960
+ int SSL_set1_param(SSL *ssl, const X509_VERIFY_PARAM *param) {
961
+ return X509_VERIFY_PARAM_set1(ssl->param, param);
962
+ }
963
+
964
+ void ssl_cipher_preference_list_free(
965
+ struct ssl_cipher_preference_list_st *cipher_list) {
966
+ if (cipher_list == NULL) {
967
+ return;
968
+ }
969
+ sk_SSL_CIPHER_free(cipher_list->ciphers);
970
+ OPENSSL_free(cipher_list->in_group_flags);
971
+ OPENSSL_free(cipher_list);
972
+ }
973
+
974
+ X509_VERIFY_PARAM *SSL_CTX_get0_param(SSL_CTX *ctx) { return ctx->param; }
975
+
976
+ X509_VERIFY_PARAM *SSL_get0_param(SSL *ssl) { return ssl->param; }
977
+
978
+ void SSL_certs_clear(SSL *ssl) { ssl_cert_clear_certs(ssl->cert); }
979
+
980
+ int SSL_get_fd(const SSL *ssl) { return SSL_get_rfd(ssl); }
981
+
982
+ int SSL_get_rfd(const SSL *ssl) {
983
+ int ret = -1;
984
+ BIO *b = BIO_find_type(SSL_get_rbio(ssl), BIO_TYPE_DESCRIPTOR);
985
+ if (b != NULL) {
986
+ BIO_get_fd(b, &ret);
987
+ }
988
+ return ret;
989
+ }
990
+
991
+ int SSL_get_wfd(const SSL *ssl) {
992
+ int ret = -1;
993
+ BIO *b = BIO_find_type(SSL_get_wbio(ssl), BIO_TYPE_DESCRIPTOR);
994
+ if (b != NULL) {
995
+ BIO_get_fd(b, &ret);
996
+ }
997
+ return ret;
998
+ }
999
+
1000
+ int SSL_set_fd(SSL *ssl, int fd) {
1001
+ BIO *bio = BIO_new(BIO_s_fd());
1002
+ if (bio == NULL) {
1003
+ OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB);
1004
+ return 0;
1005
+ }
1006
+ BIO_set_fd(bio, fd, BIO_NOCLOSE);
1007
+ SSL_set_bio(ssl, bio, bio);
1008
+ return 1;
1009
+ }
1010
+
1011
+ int SSL_set_wfd(SSL *ssl, int fd) {
1012
+ if (ssl->rbio == NULL ||
1013
+ BIO_method_type(ssl->rbio) != BIO_TYPE_FD ||
1014
+ BIO_get_fd(ssl->rbio, NULL) != fd) {
1015
+ BIO *bio = BIO_new(BIO_s_fd());
1016
+ if (bio == NULL) {
1017
+ OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB);
1018
+ return 0;
1019
+ }
1020
+ BIO_set_fd(bio, fd, BIO_NOCLOSE);
1021
+ SSL_set_bio(ssl, SSL_get_rbio(ssl), bio);
1022
+ } else {
1023
+ SSL_set_bio(ssl, SSL_get_rbio(ssl), SSL_get_rbio(ssl));
1024
+ }
1025
+
1026
+ return 1;
1027
+ }
1028
+
1029
+ int SSL_set_rfd(SSL *ssl, int fd) {
1030
+ if (ssl->wbio == NULL || BIO_method_type(ssl->wbio) != BIO_TYPE_FD ||
1031
+ BIO_get_fd(ssl->wbio, NULL) != fd) {
1032
+ BIO *bio = BIO_new(BIO_s_fd());
1033
+ if (bio == NULL) {
1034
+ OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB);
1035
+ return 0;
1036
+ }
1037
+ BIO_set_fd(bio, fd, BIO_NOCLOSE);
1038
+ SSL_set_bio(ssl, bio, SSL_get_wbio(ssl));
1039
+ } else {
1040
+ SSL_set_bio(ssl, SSL_get_wbio(ssl), SSL_get_wbio(ssl));
1041
+ }
1042
+ return 1;
1043
+ }
1044
+
1045
+ size_t SSL_get_finished(const SSL *ssl, void *buf, size_t count) {
1046
+ size_t ret = 0;
1047
+
1048
+ if (ssl->s3 != NULL) {
1049
+ ret = ssl->s3->tmp.finish_md_len;
1050
+ if (count > ret) {
1051
+ count = ret;
1052
+ }
1053
+ memcpy(buf, ssl->s3->tmp.finish_md, count);
1054
+ }
1055
+
1056
+ return ret;
1057
+ }
1058
+
1059
+ size_t SSL_get_peer_finished(const SSL *ssl, void *buf, size_t count) {
1060
+ size_t ret = 0;
1061
+
1062
+ if (ssl->s3 != NULL) {
1063
+ ret = ssl->s3->tmp.peer_finish_md_len;
1064
+ if (count > ret) {
1065
+ count = ret;
1066
+ }
1067
+ memcpy(buf, ssl->s3->tmp.peer_finish_md, count);
1068
+ }
1069
+
1070
+ return ret;
1071
+ }
1072
+
1073
+ int SSL_get_verify_mode(const SSL *ssl) { return ssl->verify_mode; }
1074
+
1075
+ int SSL_get_verify_depth(const SSL *ssl) {
1076
+ return X509_VERIFY_PARAM_get_depth(ssl->param);
1077
+ }
1078
+
1079
+ int SSL_get_extms_support(const SSL *ssl) {
1080
+ return ssl->s3->tmp.extended_master_secret == 1;
1081
+ }
1082
+
1083
+ int (*SSL_get_verify_callback(const SSL *ssl))(int, X509_STORE_CTX *) {
1084
+ return ssl->verify_callback;
1085
+ }
1086
+
1087
+ int SSL_CTX_get_verify_mode(const SSL_CTX *ctx) { return ctx->verify_mode; }
1088
+
1089
+ int SSL_CTX_get_verify_depth(const SSL_CTX *ctx) {
1090
+ return X509_VERIFY_PARAM_get_depth(ctx->param);
1091
+ }
1092
+
1093
+ int (*SSL_CTX_get_verify_callback(const SSL_CTX *ctx))(
1094
+ int ok, X509_STORE_CTX *store_ctx) {
1095
+ return ctx->default_verify_callback;
1096
+ }
1097
+
1098
+ void SSL_set_verify(SSL *ssl, int mode,
1099
+ int (*callback)(int ok, X509_STORE_CTX *store_ctx)) {
1100
+ ssl->verify_mode = mode;
1101
+ if (callback != NULL) {
1102
+ ssl->verify_callback = callback;
1103
+ }
1104
+ }
1105
+
1106
+ void SSL_set_verify_depth(SSL *ssl, int depth) {
1107
+ X509_VERIFY_PARAM_set_depth(ssl->param, depth);
1108
+ }
1109
+
1110
+ int SSL_CTX_get_read_ahead(const SSL_CTX *ctx) { return 0; }
1111
+
1112
+ int SSL_get_read_ahead(const SSL *s) { return 0; }
1113
+
1114
+ void SSL_CTX_set_read_ahead(SSL_CTX *ctx, int yes) { }
1115
+
1116
+ void SSL_set_read_ahead(SSL *s, int yes) { }
1117
+
1118
+ int SSL_pending(const SSL *ssl) {
1119
+ if (ssl->s3->rrec.type != SSL3_RT_APPLICATION_DATA) {
1120
+ return 0;
1121
+ }
1122
+ return ssl->s3->rrec.length;
1123
+ }
1124
+
1125
+ /* Fix this so it checks all the valid key/cert options */
1126
+ int SSL_CTX_check_private_key(const SSL_CTX *ctx) {
1127
+ if (ctx->cert->x509 == NULL) {
1128
+ OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CERTIFICATE_ASSIGNED);
1129
+ return 0;
1130
+ }
1131
+
1132
+ if (ctx->cert->privatekey == NULL) {
1133
+ OPENSSL_PUT_ERROR(SSL, SSL_R_NO_PRIVATE_KEY_ASSIGNED);
1134
+ return 0;
1135
+ }
1136
+
1137
+ return X509_check_private_key(ctx->cert->x509, ctx->cert->privatekey);
1138
+ }
1139
+
1140
+ /* Fix this function so that it takes an optional type parameter */
1141
+ int SSL_check_private_key(const SSL *ssl) {
1142
+ if (ssl->cert->x509 == NULL) {
1143
+ OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CERTIFICATE_ASSIGNED);
1144
+ return 0;
1145
+ }
1146
+
1147
+ if (ssl->cert->privatekey == NULL) {
1148
+ OPENSSL_PUT_ERROR(SSL, SSL_R_NO_PRIVATE_KEY_ASSIGNED);
1149
+ return 0;
1150
+ }
1151
+
1152
+ return X509_check_private_key(ssl->cert->x509, ssl->cert->privatekey);
1153
+ }
1154
+
1155
+ long SSL_get_default_timeout(const SSL *ssl) {
1156
+ return SSL_DEFAULT_SESSION_TIMEOUT;
1157
+ }
1158
+
1159
+ int SSL_renegotiate(SSL *ssl) {
1160
+ /* Caller-initiated renegotiation is not supported. */
1161
+ OPENSSL_PUT_ERROR(SSL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1162
+ return 0;
1163
+ }
1164
+
1165
+ int SSL_renegotiate_pending(SSL *ssl) {
1166
+ return SSL_in_init(ssl) && ssl->s3->initial_handshake_complete;
1167
+ }
1168
+
1169
+ size_t SSL_CTX_get_max_cert_list(const SSL_CTX *ctx) {
1170
+ return ctx->max_cert_list;
1171
+ }
1172
+
1173
+ void SSL_CTX_set_max_cert_list(SSL_CTX *ctx, size_t max_cert_list) {
1174
+ if (max_cert_list > kMaxHandshakeSize) {
1175
+ max_cert_list = kMaxHandshakeSize;
1176
+ }
1177
+ ctx->max_cert_list = (uint32_t)max_cert_list;
1178
+ }
1179
+
1180
+ size_t SSL_get_max_cert_list(const SSL *ssl) {
1181
+ return ssl->max_cert_list;
1182
+ }
1183
+
1184
+ void SSL_set_max_cert_list(SSL *ssl, size_t max_cert_list) {
1185
+ if (max_cert_list > kMaxHandshakeSize) {
1186
+ max_cert_list = kMaxHandshakeSize;
1187
+ }
1188
+ ssl->max_cert_list = (uint32_t)max_cert_list;
1189
+ }
1190
+
1191
+ void SSL_CTX_set_max_send_fragment(SSL_CTX *ctx, size_t max_send_fragment) {
1192
+ if (max_send_fragment < 512) {
1193
+ max_send_fragment = 512;
1194
+ }
1195
+ if (max_send_fragment > SSL3_RT_MAX_PLAIN_LENGTH) {
1196
+ max_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH;
1197
+ }
1198
+ ctx->max_send_fragment = (uint16_t)max_send_fragment;
1199
+ }
1200
+
1201
+ void SSL_set_max_send_fragment(SSL *ssl, size_t max_send_fragment) {
1202
+ if (max_send_fragment < 512) {
1203
+ max_send_fragment = 512;
1204
+ }
1205
+ if (max_send_fragment > SSL3_RT_MAX_PLAIN_LENGTH) {
1206
+ max_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH;
1207
+ }
1208
+ ssl->max_send_fragment = (uint16_t)max_send_fragment;
1209
+ }
1210
+
1211
+ int SSL_set_mtu(SSL *ssl, unsigned mtu) {
1212
+ if (!SSL_IS_DTLS(ssl) || mtu < dtls1_min_mtu()) {
1213
+ return 0;
1214
+ }
1215
+ ssl->d1->mtu = mtu;
1216
+ return 1;
1217
+ }
1218
+
1219
+ int SSL_get_secure_renegotiation_support(const SSL *ssl) {
1220
+ return ssl->s3->send_connection_binding;
1221
+ }
1222
+
1223
+ LHASH_OF(SSL_SESSION) *SSL_CTX_sessions(SSL_CTX *ctx) { return ctx->sessions; }
1224
+
1225
+ size_t SSL_CTX_sess_number(const SSL_CTX *ctx) {
1226
+ return lh_SSL_SESSION_num_items(ctx->sessions);
1227
+ }
1228
+
1229
+ unsigned long SSL_CTX_sess_set_cache_size(SSL_CTX *ctx, unsigned long size) {
1230
+ unsigned long ret = ctx->session_cache_size;
1231
+ ctx->session_cache_size = size;
1232
+ return ret;
1233
+ }
1234
+
1235
+ unsigned long SSL_CTX_sess_get_cache_size(const SSL_CTX *ctx) {
1236
+ return ctx->session_cache_size;
1237
+ }
1238
+
1239
+ int SSL_CTX_set_session_cache_mode(SSL_CTX *ctx, int mode) {
1240
+ int ret = ctx->session_cache_mode;
1241
+ ctx->session_cache_mode = mode;
1242
+ return ret;
1243
+ }
1244
+
1245
+ int SSL_CTX_get_session_cache_mode(const SSL_CTX *ctx) {
1246
+ return ctx->session_cache_mode;
1247
+ }
1248
+
1249
+ STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *ssl) {
1250
+ if (ssl == NULL) {
1251
+ return NULL;
1252
+ }
1253
+
1254
+ if (ssl->cipher_list != NULL) {
1255
+ return ssl->cipher_list->ciphers;
1256
+ }
1257
+
1258
+ if (ssl->version >= TLS1_1_VERSION && ssl->ctx != NULL &&
1259
+ ssl->ctx->cipher_list_tls11 != NULL) {
1260
+ return ssl->ctx->cipher_list_tls11->ciphers;
1261
+ }
1262
+
1263
+ if (ssl->version >= TLS1_VERSION && ssl->ctx != NULL &&
1264
+ ssl->ctx->cipher_list_tls10 != NULL) {
1265
+ return ssl->ctx->cipher_list_tls10->ciphers;
1266
+ }
1267
+
1268
+ if (ssl->ctx != NULL && ssl->ctx->cipher_list != NULL) {
1269
+ return ssl->ctx->cipher_list->ciphers;
1270
+ }
1271
+
1272
+ return NULL;
1273
+ }
1274
+
1275
+ /* return a STACK of the ciphers available for the SSL and in order of
1276
+ * algorithm id */
1277
+ STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s) {
1278
+ if (s == NULL) {
1279
+ return NULL;
1280
+ }
1281
+
1282
+ if (s->cipher_list_by_id != NULL) {
1283
+ return s->cipher_list_by_id;
1284
+ }
1285
+
1286
+ if (s->ctx != NULL && s->ctx->cipher_list_by_id != NULL) {
1287
+ return s->ctx->cipher_list_by_id;
1288
+ }
1289
+
1290
+ return NULL;
1291
+ }
1292
+
1293
+ const char *SSL_get_cipher_list(const SSL *ssl, int n) {
1294
+ const SSL_CIPHER *c;
1295
+ STACK_OF(SSL_CIPHER) *sk;
1296
+
1297
+ if (ssl == NULL) {
1298
+ return NULL;
1299
+ }
1300
+
1301
+ sk = SSL_get_ciphers(ssl);
1302
+ if (sk == NULL || n < 0 || (size_t)n >= sk_SSL_CIPHER_num(sk)) {
1303
+ return NULL;
1304
+ }
1305
+
1306
+ c = sk_SSL_CIPHER_value(sk, n);
1307
+ if (c == NULL) {
1308
+ return NULL;
1309
+ }
1310
+
1311
+ return c->name;
1312
+ }
1313
+
1314
+ int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str) {
1315
+ STACK_OF(SSL_CIPHER) *cipher_list = ssl_create_cipher_list(
1316
+ ctx->method, &ctx->cipher_list, &ctx->cipher_list_by_id, str);
1317
+ if (cipher_list == NULL) {
1318
+ return 0;
1319
+ }
1320
+
1321
+ /* |ssl_create_cipher_list| may succeed but return an empty cipher list. */
1322
+ if (sk_SSL_CIPHER_num(cipher_list) == 0) {
1323
+ OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CIPHER_MATCH);
1324
+ return 0;
1325
+ }
1326
+
1327
+ return 1;
1328
+ }
1329
+
1330
+ int SSL_CTX_set_cipher_list_tls10(SSL_CTX *ctx, const char *str) {
1331
+ STACK_OF(SSL_CIPHER) *cipher_list = ssl_create_cipher_list(
1332
+ ctx->method, &ctx->cipher_list_tls10, NULL, str);
1333
+ if (cipher_list == NULL) {
1334
+ return 0;
1335
+ }
1336
+
1337
+ /* |ssl_create_cipher_list| may succeed but return an empty cipher list. */
1338
+ if (sk_SSL_CIPHER_num(cipher_list) == 0) {
1339
+ OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CIPHER_MATCH);
1340
+ return 0;
1341
+ }
1342
+
1343
+ return 1;
1344
+ }
1345
+
1346
+ int SSL_CTX_set_cipher_list_tls11(SSL_CTX *ctx, const char *str) {
1347
+ STACK_OF(SSL_CIPHER) *cipher_list = ssl_create_cipher_list(
1348
+ ctx->method, &ctx->cipher_list_tls11, NULL, str);
1349
+ if (cipher_list == NULL) {
1350
+ return 0;
1351
+ }
1352
+
1353
+ /* |ssl_create_cipher_list| may succeed but return an empty cipher list. */
1354
+ if (sk_SSL_CIPHER_num(cipher_list) == 0) {
1355
+ OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CIPHER_MATCH);
1356
+ return 0;
1357
+ }
1358
+
1359
+ return 1;
1360
+ }
1361
+
1362
+ int SSL_set_cipher_list(SSL *ssl, const char *str) {
1363
+ STACK_OF(SSL_CIPHER) *cipher_list = ssl_create_cipher_list(
1364
+ ssl->ctx->method, &ssl->cipher_list, &ssl->cipher_list_by_id, str);
1365
+ if (cipher_list == NULL) {
1366
+ return 0;
1367
+ }
1368
+
1369
+ /* |ssl_create_cipher_list| may succeed but return an empty cipher list. */
1370
+ if (sk_SSL_CIPHER_num(cipher_list) == 0) {
1371
+ OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CIPHER_MATCH);
1372
+ return 0;
1373
+ }
1374
+
1375
+ return 1;
1376
+ }
1377
+
1378
+ STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s, const CBS *cbs) {
1379
+ CBS cipher_suites = *cbs;
1380
+ const SSL_CIPHER *c;
1381
+ STACK_OF(SSL_CIPHER) *sk;
1382
+
1383
+ if (s->s3) {
1384
+ s->s3->send_connection_binding = 0;
1385
+ }
1386
+
1387
+ if (CBS_len(&cipher_suites) % 2 != 0) {
1388
+ OPENSSL_PUT_ERROR(SSL, SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST);
1389
+ return NULL;
1390
+ }
1391
+
1392
+ sk = sk_SSL_CIPHER_new_null();
1393
+ if (sk == NULL) {
1394
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1395
+ goto err;
1396
+ }
1397
+
1398
+ while (CBS_len(&cipher_suites) > 0) {
1399
+ uint16_t cipher_suite;
1400
+
1401
+ if (!CBS_get_u16(&cipher_suites, &cipher_suite)) {
1402
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1403
+ goto err;
1404
+ }
1405
+
1406
+ /* Check for SCSV. */
1407
+ if (s->s3 && cipher_suite == (SSL3_CK_SCSV & 0xffff)) {
1408
+ /* SCSV is fatal if renegotiating. */
1409
+ if (s->s3->initial_handshake_complete) {
1410
+ OPENSSL_PUT_ERROR(SSL, SSL_R_SCSV_RECEIVED_WHEN_RENEGOTIATING);
1411
+ ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1412
+ goto err;
1413
+ }
1414
+ s->s3->send_connection_binding = 1;
1415
+ continue;
1416
+ }
1417
+
1418
+ /* Check for FALLBACK_SCSV. */
1419
+ if (s->s3 && cipher_suite == (SSL3_CK_FALLBACK_SCSV & 0xffff)) {
1420
+ uint16_t max_version = ssl3_get_max_server_version(s);
1421
+ if (SSL_IS_DTLS(s) ? (uint16_t)s->version > max_version
1422
+ : (uint16_t)s->version < max_version) {
1423
+ OPENSSL_PUT_ERROR(SSL, SSL_R_INAPPROPRIATE_FALLBACK);
1424
+ ssl3_send_alert(s, SSL3_AL_FATAL, SSL3_AD_INAPPROPRIATE_FALLBACK);
1425
+ goto err;
1426
+ }
1427
+ continue;
1428
+ }
1429
+
1430
+ c = SSL_get_cipher_by_value(cipher_suite);
1431
+ if (c != NULL && !sk_SSL_CIPHER_push(sk, c)) {
1432
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1433
+ goto err;
1434
+ }
1435
+ }
1436
+
1437
+ return sk;
1438
+
1439
+ err:
1440
+ sk_SSL_CIPHER_free(sk);
1441
+ return NULL;
1442
+ }
1443
+
1444
+ const char *SSL_get_servername(const SSL *ssl, const int type) {
1445
+ if (type != TLSEXT_NAMETYPE_host_name) {
1446
+ return NULL;
1447
+ }
1448
+
1449
+ /* Historically, |SSL_get_servername| was also the configuration getter
1450
+ * corresponding to |SSL_set_tlsext_host_name|. */
1451
+ if (ssl->tlsext_hostname != NULL) {
1452
+ return ssl->tlsext_hostname;
1453
+ }
1454
+
1455
+ if (ssl->session == NULL) {
1456
+ return NULL;
1457
+ }
1458
+ return ssl->session->tlsext_hostname;
1459
+ }
1460
+
1461
+ int SSL_get_servername_type(const SSL *ssl) {
1462
+ if (ssl->session != NULL && ssl->session->tlsext_hostname != NULL) {
1463
+ return TLSEXT_NAMETYPE_host_name;
1464
+ }
1465
+
1466
+ return -1;
1467
+ }
1468
+
1469
+ void SSL_CTX_enable_signed_cert_timestamps(SSL_CTX *ctx) {
1470
+ ctx->signed_cert_timestamps_enabled = 1;
1471
+ }
1472
+
1473
+ int SSL_enable_signed_cert_timestamps(SSL *ssl) {
1474
+ ssl->signed_cert_timestamps_enabled = 1;
1475
+ return 1;
1476
+ }
1477
+
1478
+ void SSL_CTX_enable_ocsp_stapling(SSL_CTX *ctx) {
1479
+ ctx->ocsp_stapling_enabled = 1;
1480
+ }
1481
+
1482
+ int SSL_enable_ocsp_stapling(SSL *ssl) {
1483
+ ssl->ocsp_stapling_enabled = 1;
1484
+ return 1;
1485
+ }
1486
+
1487
+ void SSL_get0_signed_cert_timestamp_list(const SSL *ssl, const uint8_t **out,
1488
+ size_t *out_len) {
1489
+ SSL_SESSION *session = ssl->session;
1490
+
1491
+ *out_len = 0;
1492
+ *out = NULL;
1493
+ if (ssl->server || !session || !session->tlsext_signed_cert_timestamp_list) {
1494
+ return;
1495
+ }
1496
+
1497
+ *out = session->tlsext_signed_cert_timestamp_list;
1498
+ *out_len = session->tlsext_signed_cert_timestamp_list_length;
1499
+ }
1500
+
1501
+ void SSL_get0_ocsp_response(const SSL *ssl, const uint8_t **out,
1502
+ size_t *out_len) {
1503
+ SSL_SESSION *session = ssl->session;
1504
+
1505
+ *out_len = 0;
1506
+ *out = NULL;
1507
+ if (ssl->server || !session || !session->ocsp_response) {
1508
+ return;
1509
+ }
1510
+ *out = session->ocsp_response;
1511
+ *out_len = session->ocsp_response_length;
1512
+ }
1513
+
1514
+ int SSL_CTX_set_signed_cert_timestamp_list(SSL_CTX *ctx, const uint8_t *list,
1515
+ size_t list_len) {
1516
+ OPENSSL_free(ctx->signed_cert_timestamp_list);
1517
+ ctx->signed_cert_timestamp_list_length = 0;
1518
+
1519
+ ctx->signed_cert_timestamp_list = BUF_memdup(list, list_len);
1520
+ if (ctx->signed_cert_timestamp_list == NULL) {
1521
+ return 0;
1522
+ }
1523
+ ctx->signed_cert_timestamp_list_length = list_len;
1524
+
1525
+ return 1;
1526
+ }
1527
+
1528
+ int SSL_CTX_set_ocsp_response(SSL_CTX *ctx, const uint8_t *response,
1529
+ size_t response_len) {
1530
+ OPENSSL_free(ctx->ocsp_response);
1531
+ ctx->ocsp_response_length = 0;
1532
+
1533
+ ctx->ocsp_response = BUF_memdup(response, response_len);
1534
+ if (ctx->ocsp_response == NULL) {
1535
+ return 0;
1536
+ }
1537
+ ctx->ocsp_response_length = response_len;
1538
+
1539
+ return 1;
1540
+ }
1541
+
1542
+ int SSL_select_next_proto(uint8_t **out, uint8_t *out_len,
1543
+ const uint8_t *server, unsigned server_len,
1544
+ const uint8_t *client, unsigned client_len) {
1545
+ unsigned int i, j;
1546
+ const uint8_t *result;
1547
+ int status = OPENSSL_NPN_UNSUPPORTED;
1548
+
1549
+ /* For each protocol in server preference order, see if we support it. */
1550
+ for (i = 0; i < server_len;) {
1551
+ for (j = 0; j < client_len;) {
1552
+ if (server[i] == client[j] &&
1553
+ memcmp(&server[i + 1], &client[j + 1], server[i]) == 0) {
1554
+ /* We found a match */
1555
+ result = &server[i];
1556
+ status = OPENSSL_NPN_NEGOTIATED;
1557
+ goto found;
1558
+ }
1559
+ j += client[j];
1560
+ j++;
1561
+ }
1562
+ i += server[i];
1563
+ i++;
1564
+ }
1565
+
1566
+ /* There's no overlap between our protocols and the server's list. */
1567
+ result = client;
1568
+ status = OPENSSL_NPN_NO_OVERLAP;
1569
+
1570
+ found:
1571
+ *out = (uint8_t *)result + 1;
1572
+ *out_len = result[0];
1573
+ return status;
1574
+ }
1575
+
1576
+ void SSL_get0_next_proto_negotiated(const SSL *ssl, const uint8_t **out_data,
1577
+ unsigned *out_len) {
1578
+ *out_data = ssl->next_proto_negotiated;
1579
+ if (*out_data == NULL) {
1580
+ *out_len = 0;
1581
+ } else {
1582
+ *out_len = ssl->next_proto_negotiated_len;
1583
+ }
1584
+ }
1585
+
1586
+ void SSL_CTX_set_next_protos_advertised_cb(
1587
+ SSL_CTX *ctx,
1588
+ int (*cb)(SSL *ssl, const uint8_t **out, unsigned *out_len, void *arg),
1589
+ void *arg) {
1590
+ ctx->next_protos_advertised_cb = cb;
1591
+ ctx->next_protos_advertised_cb_arg = arg;
1592
+ }
1593
+
1594
+ void SSL_CTX_set_next_proto_select_cb(
1595
+ SSL_CTX *ctx, int (*cb)(SSL *ssl, uint8_t **out, uint8_t *out_len,
1596
+ const uint8_t *in, unsigned in_len, void *arg),
1597
+ void *arg) {
1598
+ ctx->next_proto_select_cb = cb;
1599
+ ctx->next_proto_select_cb_arg = arg;
1600
+ }
1601
+
1602
+ int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const uint8_t *protos,
1603
+ unsigned protos_len) {
1604
+ OPENSSL_free(ctx->alpn_client_proto_list);
1605
+ ctx->alpn_client_proto_list = BUF_memdup(protos, protos_len);
1606
+ if (!ctx->alpn_client_proto_list) {
1607
+ return 1;
1608
+ }
1609
+ ctx->alpn_client_proto_list_len = protos_len;
1610
+
1611
+ return 0;
1612
+ }
1613
+
1614
+ int SSL_set_alpn_protos(SSL *ssl, const uint8_t *protos, unsigned protos_len) {
1615
+ OPENSSL_free(ssl->alpn_client_proto_list);
1616
+ ssl->alpn_client_proto_list = BUF_memdup(protos, protos_len);
1617
+ if (!ssl->alpn_client_proto_list) {
1618
+ return 1;
1619
+ }
1620
+ ssl->alpn_client_proto_list_len = protos_len;
1621
+
1622
+ return 0;
1623
+ }
1624
+
1625
+ void SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx,
1626
+ int (*cb)(SSL *ssl, const uint8_t **out,
1627
+ uint8_t *out_len, const uint8_t *in,
1628
+ unsigned in_len, void *arg),
1629
+ void *arg) {
1630
+ ctx->alpn_select_cb = cb;
1631
+ ctx->alpn_select_cb_arg = arg;
1632
+ }
1633
+
1634
+ void SSL_get0_alpn_selected(const SSL *ssl, const uint8_t **out_data,
1635
+ unsigned *out_len) {
1636
+ *out_data = NULL;
1637
+ if (ssl->s3) {
1638
+ *out_data = ssl->s3->alpn_selected;
1639
+ }
1640
+ if (*out_data == NULL) {
1641
+ *out_len = 0;
1642
+ } else {
1643
+ *out_len = ssl->s3->alpn_selected_len;
1644
+ }
1645
+ }
1646
+
1647
+ int SSL_export_keying_material(SSL *ssl, uint8_t *out, size_t out_len,
1648
+ const char *label, size_t label_len,
1649
+ const uint8_t *context, size_t context_len,
1650
+ int use_context) {
1651
+ if (ssl->version < TLS1_VERSION) {
1652
+ return 0;
1653
+ }
1654
+
1655
+ return ssl->enc_method->export_keying_material(
1656
+ ssl, out, out_len, label, label_len, context, context_len, use_context);
1657
+ }
1658
+
1659
+ void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx,
1660
+ int (*cb)(X509_STORE_CTX *store_ctx,
1661
+ void *arg),
1662
+ void *arg) {
1663
+ ctx->app_verify_callback = cb;
1664
+ ctx->app_verify_arg = arg;
1665
+ }
1666
+
1667
+ void SSL_CTX_set_verify(SSL_CTX *ctx, int mode,
1668
+ int (*cb)(int, X509_STORE_CTX *)) {
1669
+ ctx->verify_mode = mode;
1670
+ ctx->default_verify_callback = cb;
1671
+ }
1672
+
1673
+ void SSL_CTX_set_verify_depth(SSL_CTX *ctx, int depth) {
1674
+ X509_VERIFY_PARAM_set_depth(ctx->param, depth);
1675
+ }
1676
+
1677
+ void SSL_CTX_set_cert_cb(SSL_CTX *ctx, int (*cb)(SSL *ssl, void *arg),
1678
+ void *arg) {
1679
+ ssl_cert_set_cert_cb(ctx->cert, cb, arg);
1680
+ }
1681
+
1682
+ void SSL_set_cert_cb(SSL *ssl, int (*cb)(SSL *ssl, void *arg), void *arg) {
1683
+ ssl_cert_set_cert_cb(ssl->cert, cb, arg);
1684
+ }
1685
+
1686
+ void ssl_get_compatible_server_ciphers(SSL *s, uint32_t *out_mask_k,
1687
+ uint32_t *out_mask_a) {
1688
+ CERT *c = s->cert;
1689
+ int have_rsa_cert = 0, dh_tmp;
1690
+ uint32_t mask_k, mask_a;
1691
+ int have_ecc_cert = 0, ecdsa_ok;
1692
+ X509 *x;
1693
+
1694
+ dh_tmp = (c->dh_tmp != NULL || c->dh_tmp_cb != NULL);
1695
+
1696
+ if (s->cert->x509 != NULL && ssl_has_private_key(s)) {
1697
+ if (ssl_private_key_type(s) == EVP_PKEY_RSA) {
1698
+ have_rsa_cert = 1;
1699
+ } else if (ssl_private_key_type(s) == EVP_PKEY_EC) {
1700
+ have_ecc_cert = 1;
1701
+ }
1702
+ }
1703
+
1704
+ mask_k = 0;
1705
+ mask_a = 0;
1706
+
1707
+ if (dh_tmp) {
1708
+ mask_k |= SSL_kDHE;
1709
+ }
1710
+ if (have_rsa_cert) {
1711
+ mask_k |= SSL_kRSA;
1712
+ mask_a |= SSL_aRSA;
1713
+ }
1714
+
1715
+ /* An ECC certificate may be usable for ECDSA cipher suites depending on the
1716
+ * key usage extension and on the client's curve preferences. */
1717
+ if (have_ecc_cert) {
1718
+ x = c->x509;
1719
+ /* This call populates extension flags (ex_flags). */
1720
+ X509_check_purpose(x, -1, 0);
1721
+ ecdsa_ok = (x->ex_flags & EXFLAG_KUSAGE)
1722
+ ? (x->ex_kusage & X509v3_KU_DIGITAL_SIGNATURE)
1723
+ : 1;
1724
+ if (!tls1_check_ec_cert(s, x)) {
1725
+ ecdsa_ok = 0;
1726
+ }
1727
+ if (ecdsa_ok) {
1728
+ mask_a |= SSL_aECDSA;
1729
+ }
1730
+ }
1731
+
1732
+ /* If we are considering an ECC cipher suite that uses an ephemeral EC
1733
+ * key, check for a shared curve. */
1734
+ if (tls1_get_shared_curve(s) != NID_undef) {
1735
+ mask_k |= SSL_kECDHE;
1736
+ }
1737
+
1738
+ /* PSK requires a server callback. */
1739
+ if (s->psk_server_callback != NULL) {
1740
+ mask_k |= SSL_kPSK;
1741
+ mask_a |= SSL_aPSK;
1742
+ }
1743
+
1744
+ *out_mask_k = mask_k;
1745
+ *out_mask_a = mask_a;
1746
+ }
1747
+
1748
+ void ssl_update_cache(SSL *ssl, int mode) {
1749
+ SSL_CTX *ctx = ssl->initial_ctx;
1750
+ /* Never cache sessions with empty session IDs. */
1751
+ if (ssl->session->session_id_length == 0 ||
1752
+ (ctx->session_cache_mode & mode) != mode) {
1753
+ return;
1754
+ }
1755
+
1756
+ /* Clients never use the internal session cache. */
1757
+ int use_internal_cache = ssl->server && !(ctx->session_cache_mode &
1758
+ SSL_SESS_CACHE_NO_INTERNAL_STORE);
1759
+
1760
+ /* A client may see new sessions on abbreviated handshakes if the server
1761
+ * decides to renew the ticket. Once the handshake is completed, it should be
1762
+ * inserted into the cache. */
1763
+ if (!ssl->hit || (!ssl->server && ssl->tlsext_ticket_expected)) {
1764
+ if (use_internal_cache) {
1765
+ SSL_CTX_add_session(ctx, ssl->session);
1766
+ }
1767
+ if (ctx->new_session_cb != NULL &&
1768
+ !ctx->new_session_cb(ssl, SSL_SESSION_up_ref(ssl->session))) {
1769
+ /* |new_session_cb|'s return value signals whether it took ownership. */
1770
+ SSL_SESSION_free(ssl->session);
1771
+ }
1772
+ }
1773
+
1774
+ if (use_internal_cache &&
1775
+ !(ctx->session_cache_mode & SSL_SESS_CACHE_NO_AUTO_CLEAR)) {
1776
+ /* Automatically flush the internal session cache every 255 connections. */
1777
+ int flush_cache = 0;
1778
+ CRYPTO_MUTEX_lock_write(&ctx->lock);
1779
+ ctx->handshakes_since_cache_flush++;
1780
+ if (ctx->handshakes_since_cache_flush >= 255) {
1781
+ flush_cache = 1;
1782
+ ctx->handshakes_since_cache_flush = 0;
1783
+ }
1784
+ CRYPTO_MUTEX_unlock(&ctx->lock);
1785
+
1786
+ if (flush_cache) {
1787
+ SSL_CTX_flush_sessions(ctx, (unsigned long)time(NULL));
1788
+ }
1789
+ }
1790
+ }
1791
+
1792
+ static const char *ssl_get_version(int version) {
1793
+ switch (version) {
1794
+ case TLS1_2_VERSION:
1795
+ return "TLSv1.2";
1796
+
1797
+ case TLS1_1_VERSION:
1798
+ return "TLSv1.1";
1799
+
1800
+ case TLS1_VERSION:
1801
+ return "TLSv1";
1802
+
1803
+ case SSL3_VERSION:
1804
+ return "SSLv3";
1805
+
1806
+ case DTLS1_VERSION:
1807
+ return "DTLSv1";
1808
+
1809
+ case DTLS1_2_VERSION:
1810
+ return "DTLSv1.2";
1811
+
1812
+ default:
1813
+ return "unknown";
1814
+ }
1815
+ }
1816
+
1817
+ const char *SSL_get_version(const SSL *ssl) {
1818
+ return ssl_get_version(ssl->version);
1819
+ }
1820
+
1821
+ const char *SSL_SESSION_get_version(const SSL_SESSION *session) {
1822
+ return ssl_get_version(session->ssl_version);
1823
+ }
1824
+
1825
+ const char* SSL_get_curve_name(uint16_t curve_id) {
1826
+ return tls1_ec_curve_id2name(curve_id);
1827
+ }
1828
+
1829
+ void ssl_clear_cipher_ctx(SSL *s) {
1830
+ SSL_AEAD_CTX_free(s->aead_read_ctx);
1831
+ s->aead_read_ctx = NULL;
1832
+ SSL_AEAD_CTX_free(s->aead_write_ctx);
1833
+ s->aead_write_ctx = NULL;
1834
+ }
1835
+
1836
+ X509 *SSL_get_certificate(const SSL *s) {
1837
+ if (s->cert != NULL) {
1838
+ return s->cert->x509;
1839
+ }
1840
+
1841
+ return NULL;
1842
+ }
1843
+
1844
+ EVP_PKEY *SSL_get_privatekey(const SSL *s) {
1845
+ if (s->cert != NULL) {
1846
+ return s->cert->privatekey;
1847
+ }
1848
+
1849
+ return NULL;
1850
+ }
1851
+
1852
+ X509 *SSL_CTX_get0_certificate(const SSL_CTX *ctx) {
1853
+ if (ctx->cert != NULL) {
1854
+ return ctx->cert->x509;
1855
+ }
1856
+
1857
+ return NULL;
1858
+ }
1859
+
1860
+ EVP_PKEY *SSL_CTX_get0_privatekey(const SSL_CTX *ctx) {
1861
+ if (ctx->cert != NULL) {
1862
+ return ctx->cert->privatekey;
1863
+ }
1864
+
1865
+ return NULL;
1866
+ }
1867
+
1868
+ const SSL_CIPHER *SSL_get_current_cipher(const SSL *ssl) {
1869
+ if (ssl->aead_write_ctx == NULL) {
1870
+ return NULL;
1871
+ }
1872
+ return ssl->aead_write_ctx->cipher;
1873
+ }
1874
+
1875
+ const COMP_METHOD *SSL_get_current_compression(SSL *s) { return NULL; }
1876
+
1877
+ const COMP_METHOD *SSL_get_current_expansion(SSL *s) { return NULL; }
1878
+
1879
+ int ssl_init_wbio_buffer(SSL *s, int push) {
1880
+ BIO *bbio;
1881
+
1882
+ if (s->bbio == NULL) {
1883
+ bbio = BIO_new(BIO_f_buffer());
1884
+ if (bbio == NULL) {
1885
+ return 0;
1886
+ }
1887
+ s->bbio = bbio;
1888
+ } else {
1889
+ bbio = s->bbio;
1890
+ if (s->bbio == s->wbio) {
1891
+ s->wbio = BIO_pop(s->wbio);
1892
+ }
1893
+ }
1894
+
1895
+ BIO_reset(bbio);
1896
+ if (!BIO_set_read_buffer_size(bbio, 1)) {
1897
+ OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB);
1898
+ return 0;
1899
+ }
1900
+
1901
+ if (push) {
1902
+ if (s->wbio != bbio) {
1903
+ s->wbio = BIO_push(bbio, s->wbio);
1904
+ }
1905
+ } else {
1906
+ if (s->wbio == bbio) {
1907
+ s->wbio = BIO_pop(bbio);
1908
+ }
1909
+ }
1910
+
1911
+ return 1;
1912
+ }
1913
+
1914
+ void ssl_free_wbio_buffer(SSL *s) {
1915
+ if (s->bbio == NULL) {
1916
+ return;
1917
+ }
1918
+
1919
+ if (s->bbio == s->wbio) {
1920
+ /* remove buffering */
1921
+ s->wbio = BIO_pop(s->wbio);
1922
+ }
1923
+
1924
+ BIO_free(s->bbio);
1925
+ s->bbio = NULL;
1926
+ }
1927
+
1928
+ void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx, int mode) {
1929
+ ctx->quiet_shutdown = (mode != 0);
1930
+ }
1931
+
1932
+ int SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx) {
1933
+ return ctx->quiet_shutdown;
1934
+ }
1935
+
1936
+ void SSL_set_quiet_shutdown(SSL *ssl, int mode) {
1937
+ ssl->quiet_shutdown = (mode != 0);
1938
+ }
1939
+
1940
+ int SSL_get_quiet_shutdown(const SSL *ssl) { return ssl->quiet_shutdown; }
1941
+
1942
+ void SSL_set_shutdown(SSL *ssl, int mode) {
1943
+ /* It is an error to clear any bits that have already been set. (We can't try
1944
+ * to get a second close_notify or send two.) */
1945
+ assert((ssl->shutdown & mode) == ssl->shutdown);
1946
+
1947
+ ssl->shutdown |= mode;
1948
+ }
1949
+
1950
+ int SSL_get_shutdown(const SSL *ssl) { return ssl->shutdown; }
1951
+
1952
+ int SSL_version(const SSL *ssl) { return ssl->version; }
1953
+
1954
+ SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl) { return ssl->ctx; }
1955
+
1956
+ SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx) {
1957
+ if (ssl->ctx == ctx) {
1958
+ return ssl->ctx;
1959
+ }
1960
+
1961
+ if (ctx == NULL) {
1962
+ ctx = ssl->initial_ctx;
1963
+ }
1964
+
1965
+ ssl_cert_free(ssl->cert);
1966
+ ssl->cert = ssl_cert_dup(ctx->cert);
1967
+
1968
+ CRYPTO_refcount_inc(&ctx->references);
1969
+ SSL_CTX_free(ssl->ctx); /* decrement reference count */
1970
+ ssl->ctx = ctx;
1971
+
1972
+ ssl->sid_ctx_length = ctx->sid_ctx_length;
1973
+ assert(ssl->sid_ctx_length <= sizeof(ssl->sid_ctx));
1974
+ memcpy(ssl->sid_ctx, ctx->sid_ctx, sizeof(ssl->sid_ctx));
1975
+
1976
+ return ssl->ctx;
1977
+ }
1978
+
1979
+ int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx) {
1980
+ return X509_STORE_set_default_paths(ctx->cert_store);
1981
+ }
1982
+
1983
+ int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *ca_file,
1984
+ const char *ca_dir) {
1985
+ return X509_STORE_load_locations(ctx->cert_store, ca_file, ca_dir);
1986
+ }
1987
+
1988
+ void SSL_set_info_callback(SSL *ssl,
1989
+ void (*cb)(const SSL *ssl, int type, int value)) {
1990
+ ssl->info_callback = cb;
1991
+ }
1992
+
1993
+ void (*SSL_get_info_callback(const SSL *ssl))(const SSL *ssl, int type,
1994
+ int value) {
1995
+ return ssl->info_callback;
1996
+ }
1997
+
1998
+ int SSL_state(const SSL *ssl) { return ssl->state; }
1999
+
2000
+ void SSL_set_state(SSL *ssl, int state) { }
2001
+
2002
+ void SSL_set_verify_result(SSL *ssl, long result) {
2003
+ ssl->verify_result = result;
2004
+ }
2005
+
2006
+ long SSL_get_verify_result(const SSL *ssl) { return ssl->verify_result; }
2007
+
2008
+ int SSL_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused,
2009
+ CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) {
2010
+ int index;
2011
+ if (!CRYPTO_get_ex_new_index(&g_ex_data_class_ssl, &index, argl, argp,
2012
+ dup_func, free_func)) {
2013
+ return -1;
2014
+ }
2015
+ return index;
2016
+ }
2017
+
2018
+ int SSL_set_ex_data(SSL *ssl, int idx, void *arg) {
2019
+ return CRYPTO_set_ex_data(&ssl->ex_data, idx, arg);
2020
+ }
2021
+
2022
+ void *SSL_get_ex_data(const SSL *ssl, int idx) {
2023
+ return CRYPTO_get_ex_data(&ssl->ex_data, idx);
2024
+ }
2025
+
2026
+ int SSL_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused,
2027
+ CRYPTO_EX_dup *dup_func,
2028
+ CRYPTO_EX_free *free_func) {
2029
+ int index;
2030
+ if (!CRYPTO_get_ex_new_index(&g_ex_data_class_ssl_ctx, &index, argl, argp,
2031
+ dup_func, free_func)) {
2032
+ return -1;
2033
+ }
2034
+ return index;
2035
+ }
2036
+
2037
+ int SSL_CTX_set_ex_data(SSL_CTX *ctx, int idx, void *arg) {
2038
+ return CRYPTO_set_ex_data(&ctx->ex_data, idx, arg);
2039
+ }
2040
+
2041
+ void *SSL_CTX_get_ex_data(const SSL_CTX *ctx, int idx) {
2042
+ return CRYPTO_get_ex_data(&ctx->ex_data, idx);
2043
+ }
2044
+
2045
+ X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *ctx) {
2046
+ return ctx->cert_store;
2047
+ }
2048
+
2049
+ void SSL_CTX_set_cert_store(SSL_CTX *ctx, X509_STORE *store) {
2050
+ X509_STORE_free(ctx->cert_store);
2051
+ ctx->cert_store = store;
2052
+ }
2053
+
2054
+ int SSL_want(const SSL *ssl) { return ssl->rwstate; }
2055
+
2056
+ void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,
2057
+ RSA *(*cb)(SSL *ssl, int is_export,
2058
+ int keylength)) {
2059
+ }
2060
+
2061
+ void SSL_set_tmp_rsa_callback(SSL *ssl, RSA *(*cb)(SSL *ssl, int is_export,
2062
+ int keylength)) {
2063
+ }
2064
+
2065
+ void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,
2066
+ DH *(*callback)(SSL *ssl, int is_export,
2067
+ int keylength)) {
2068
+ ctx->cert->dh_tmp_cb = callback;
2069
+ }
2070
+
2071
+ void SSL_set_tmp_dh_callback(SSL *ssl, DH *(*callback)(SSL *ssl, int is_export,
2072
+ int keylength)) {
2073
+ ssl->cert->dh_tmp_cb = callback;
2074
+ }
2075
+
2076
+ int SSL_CTX_use_psk_identity_hint(SSL_CTX *ctx, const char *identity_hint) {
2077
+ if (identity_hint != NULL && strlen(identity_hint) > PSK_MAX_IDENTITY_LEN) {
2078
+ OPENSSL_PUT_ERROR(SSL, SSL_R_DATA_LENGTH_TOO_LONG);
2079
+ return 0;
2080
+ }
2081
+
2082
+ OPENSSL_free(ctx->psk_identity_hint);
2083
+
2084
+ if (identity_hint != NULL) {
2085
+ ctx->psk_identity_hint = BUF_strdup(identity_hint);
2086
+ if (ctx->psk_identity_hint == NULL) {
2087
+ return 0;
2088
+ }
2089
+ } else {
2090
+ ctx->psk_identity_hint = NULL;
2091
+ }
2092
+
2093
+ return 1;
2094
+ }
2095
+
2096
+ int SSL_use_psk_identity_hint(SSL *ssl, const char *identity_hint) {
2097
+ if (ssl == NULL) {
2098
+ return 0;
2099
+ }
2100
+
2101
+ if (identity_hint != NULL && strlen(identity_hint) > PSK_MAX_IDENTITY_LEN) {
2102
+ OPENSSL_PUT_ERROR(SSL, SSL_R_DATA_LENGTH_TOO_LONG);
2103
+ return 0;
2104
+ }
2105
+
2106
+ /* Clear currently configured hint, if any. */
2107
+ OPENSSL_free(ssl->psk_identity_hint);
2108
+ ssl->psk_identity_hint = NULL;
2109
+
2110
+ if (identity_hint != NULL) {
2111
+ ssl->psk_identity_hint = BUF_strdup(identity_hint);
2112
+ if (ssl->psk_identity_hint == NULL) {
2113
+ return 0;
2114
+ }
2115
+ }
2116
+
2117
+ return 1;
2118
+ }
2119
+
2120
+ const char *SSL_get_psk_identity_hint(const SSL *ssl) {
2121
+ if (ssl == NULL) {
2122
+ return NULL;
2123
+ }
2124
+ return ssl->psk_identity_hint;
2125
+ }
2126
+
2127
+ const char *SSL_get_psk_identity(const SSL *ssl) {
2128
+ if (ssl == NULL || ssl->session == NULL) {
2129
+ return NULL;
2130
+ }
2131
+
2132
+ return ssl->session->psk_identity;
2133
+ }
2134
+
2135
+ void SSL_set_psk_client_callback(
2136
+ SSL *ssl, unsigned (*cb)(SSL *ssl, const char *hint, char *identity,
2137
+ unsigned max_identity_len, uint8_t *psk,
2138
+ unsigned max_psk_len)) {
2139
+ ssl->psk_client_callback = cb;
2140
+ }
2141
+
2142
+ void SSL_CTX_set_psk_client_callback(
2143
+ SSL_CTX *ctx, unsigned (*cb)(SSL *ssl, const char *hint, char *identity,
2144
+ unsigned max_identity_len, uint8_t *psk,
2145
+ unsigned max_psk_len)) {
2146
+ ctx->psk_client_callback = cb;
2147
+ }
2148
+
2149
+ void SSL_set_psk_server_callback(
2150
+ SSL *ssl, unsigned (*cb)(SSL *ssl, const char *identity, uint8_t *psk,
2151
+ unsigned max_psk_len)) {
2152
+ ssl->psk_server_callback = cb;
2153
+ }
2154
+
2155
+ void SSL_CTX_set_psk_server_callback(
2156
+ SSL_CTX *ctx, unsigned (*cb)(SSL *ssl, const char *identity,
2157
+ uint8_t *psk, unsigned max_psk_len)) {
2158
+ ctx->psk_server_callback = cb;
2159
+ }
2160
+
2161
+ void SSL_CTX_set_msg_callback(SSL_CTX *ctx,
2162
+ void (*cb)(int write_p, int version,
2163
+ int content_type, const void *buf,
2164
+ size_t len, SSL *ssl, void *arg)) {
2165
+ ctx->msg_callback = cb;
2166
+ }
2167
+
2168
+ void SSL_CTX_set_msg_callback_arg(SSL_CTX *ctx, void *arg) {
2169
+ ctx->msg_callback_arg = arg;
2170
+ }
2171
+
2172
+ void SSL_set_msg_callback(SSL *ssl,
2173
+ void (*cb)(int write_p, int version, int content_type,
2174
+ const void *buf, size_t len, SSL *ssl,
2175
+ void *arg)) {
2176
+ ssl->msg_callback = cb;
2177
+ }
2178
+
2179
+ void SSL_set_msg_callback_arg(SSL *ssl, void *arg) {
2180
+ ssl->msg_callback_arg = arg;
2181
+ }
2182
+
2183
+ void SSL_CTX_set_keylog_callback(SSL_CTX *ctx,
2184
+ void (*cb)(const SSL *ssl, const char *line)) {
2185
+ ctx->keylog_callback = cb;
2186
+ }
2187
+
2188
+ static int cbb_add_hex(CBB *cbb, const uint8_t *in, size_t in_len) {
2189
+ static const char hextable[] = "0123456789abcdef";
2190
+ uint8_t *out;
2191
+ size_t i;
2192
+
2193
+ if (!CBB_add_space(cbb, &out, in_len * 2)) {
2194
+ return 0;
2195
+ }
2196
+
2197
+ for (i = 0; i < in_len; i++) {
2198
+ *(out++) = (uint8_t)hextable[in[i] >> 4];
2199
+ *(out++) = (uint8_t)hextable[in[i] & 0xf];
2200
+ }
2201
+
2202
+ return 1;
2203
+ }
2204
+
2205
+ int ssl_log_rsa_client_key_exchange(const SSL *ssl,
2206
+ const uint8_t *encrypted_premaster,
2207
+ size_t encrypted_premaster_len,
2208
+ const uint8_t *premaster,
2209
+ size_t premaster_len) {
2210
+ if (ssl->ctx->keylog_callback == NULL) {
2211
+ return 1;
2212
+ }
2213
+
2214
+ if (encrypted_premaster_len < 8) {
2215
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
2216
+ return 0;
2217
+ }
2218
+
2219
+ CBB cbb;
2220
+ uint8_t *out;
2221
+ size_t out_len;
2222
+ if (!CBB_init(&cbb, 4 + 16 + 1 + premaster_len * 2 + 1) ||
2223
+ !CBB_add_bytes(&cbb, (const uint8_t *)"RSA ", 4) ||
2224
+ /* Only the first 8 bytes of the encrypted premaster secret are
2225
+ * logged. */
2226
+ !cbb_add_hex(&cbb, encrypted_premaster, 8) ||
2227
+ !CBB_add_bytes(&cbb, (const uint8_t *)" ", 1) ||
2228
+ !cbb_add_hex(&cbb, premaster, premaster_len) ||
2229
+ !CBB_add_u8(&cbb, 0 /* NUL */) ||
2230
+ !CBB_finish(&cbb, &out, &out_len)) {
2231
+ CBB_cleanup(&cbb);
2232
+ return 0;
2233
+ }
2234
+
2235
+ ssl->ctx->keylog_callback(ssl, (const char *)out);
2236
+ OPENSSL_free(out);
2237
+ return 1;
2238
+ }
2239
+
2240
+ int ssl_log_master_secret(const SSL *ssl, const uint8_t *client_random,
2241
+ size_t client_random_len, const uint8_t *master,
2242
+ size_t master_len) {
2243
+ if (ssl->ctx->keylog_callback == NULL) {
2244
+ return 1;
2245
+ }
2246
+
2247
+ if (client_random_len != 32) {
2248
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
2249
+ return 0;
2250
+ }
2251
+
2252
+ CBB cbb;
2253
+ uint8_t *out;
2254
+ size_t out_len;
2255
+ if (!CBB_init(&cbb, 14 + 64 + 1 + master_len * 2 + 1) ||
2256
+ !CBB_add_bytes(&cbb, (const uint8_t *)"CLIENT_RANDOM ", 14) ||
2257
+ !cbb_add_hex(&cbb, client_random, 32) ||
2258
+ !CBB_add_bytes(&cbb, (const uint8_t *)" ", 1) ||
2259
+ !cbb_add_hex(&cbb, master, master_len) ||
2260
+ !CBB_add_u8(&cbb, 0 /* NUL */) ||
2261
+ !CBB_finish(&cbb, &out, &out_len)) {
2262
+ CBB_cleanup(&cbb);
2263
+ return 0;
2264
+ }
2265
+
2266
+ ssl->ctx->keylog_callback(ssl, (const char *)out);
2267
+ OPENSSL_free(out);
2268
+ return 1;
2269
+ }
2270
+
2271
+ int SSL_is_init_finished(const SSL *ssl) {
2272
+ return ssl->state == SSL_ST_OK;
2273
+ }
2274
+
2275
+ int SSL_in_init(const SSL *ssl) {
2276
+ return (ssl->state & SSL_ST_INIT) != 0;
2277
+ }
2278
+
2279
+ int SSL_in_false_start(const SSL *ssl) {
2280
+ return ssl->s3->tmp.in_false_start;
2281
+ }
2282
+
2283
+ int SSL_cutthrough_complete(const SSL *s) {
2284
+ return SSL_in_false_start(s);
2285
+ }
2286
+
2287
+ void SSL_get_structure_sizes(size_t *ssl_size, size_t *ssl_ctx_size,
2288
+ size_t *ssl_session_size) {
2289
+ *ssl_size = sizeof(SSL);
2290
+ *ssl_ctx_size = sizeof(SSL_CTX);
2291
+ *ssl_session_size = sizeof(SSL_SESSION);
2292
+ }
2293
+
2294
+ int ssl3_can_false_start(const SSL *s) {
2295
+ const SSL_CIPHER *const cipher = SSL_get_current_cipher(s);
2296
+
2297
+ /* False Start only for TLS 1.2 with an ECDHE+AEAD cipher and ALPN or NPN. */
2298
+ return !SSL_IS_DTLS(s) &&
2299
+ SSL_version(s) >= TLS1_2_VERSION &&
2300
+ (s->s3->alpn_selected || s->s3->next_proto_neg_seen) &&
2301
+ cipher != NULL &&
2302
+ cipher->algorithm_mkey == SSL_kECDHE &&
2303
+ cipher->algorithm_mac == SSL_AEAD;
2304
+ }
2305
+
2306
+ const SSL3_ENC_METHOD *ssl3_get_enc_method(uint16_t version) {
2307
+ switch (version) {
2308
+ case SSL3_VERSION:
2309
+ return &SSLv3_enc_data;
2310
+
2311
+ case TLS1_VERSION:
2312
+ return &TLSv1_enc_data;
2313
+
2314
+ case DTLS1_VERSION:
2315
+ case TLS1_1_VERSION:
2316
+ return &TLSv1_1_enc_data;
2317
+
2318
+ case DTLS1_2_VERSION:
2319
+ case TLS1_2_VERSION:
2320
+ return &TLSv1_2_enc_data;
2321
+
2322
+ default:
2323
+ return NULL;
2324
+ }
2325
+ }
2326
+
2327
+ uint16_t ssl3_get_max_server_version(const SSL *s) {
2328
+ uint16_t max_version;
2329
+
2330
+ if (SSL_IS_DTLS(s)) {
2331
+ max_version = (s->max_version != 0) ? s->max_version : DTLS1_2_VERSION;
2332
+ if (!(s->options & SSL_OP_NO_DTLSv1_2) && DTLS1_2_VERSION >= max_version) {
2333
+ return DTLS1_2_VERSION;
2334
+ }
2335
+ if (!(s->options & SSL_OP_NO_DTLSv1) && DTLS1_VERSION >= max_version) {
2336
+ return DTLS1_VERSION;
2337
+ }
2338
+ return 0;
2339
+ }
2340
+
2341
+ max_version = (s->max_version != 0) ? s->max_version : TLS1_2_VERSION;
2342
+ if (!(s->options & SSL_OP_NO_TLSv1_2) && TLS1_2_VERSION <= max_version) {
2343
+ return TLS1_2_VERSION;
2344
+ }
2345
+ if (!(s->options & SSL_OP_NO_TLSv1_1) && TLS1_1_VERSION <= max_version) {
2346
+ return TLS1_1_VERSION;
2347
+ }
2348
+ if (!(s->options & SSL_OP_NO_TLSv1) && TLS1_VERSION <= max_version) {
2349
+ return TLS1_VERSION;
2350
+ }
2351
+ if (!(s->options & SSL_OP_NO_SSLv3) && SSL3_VERSION <= max_version) {
2352
+ return SSL3_VERSION;
2353
+ }
2354
+ return 0;
2355
+ }
2356
+
2357
+ uint16_t ssl3_get_mutual_version(SSL *s, uint16_t client_version) {
2358
+ uint16_t version = 0;
2359
+
2360
+ if (SSL_IS_DTLS(s)) {
2361
+ /* Clamp client_version to max_version. */
2362
+ if (s->max_version != 0 && client_version < s->max_version) {
2363
+ client_version = s->max_version;
2364
+ }
2365
+
2366
+ if (client_version <= DTLS1_2_VERSION && !(s->options & SSL_OP_NO_DTLSv1_2)) {
2367
+ version = DTLS1_2_VERSION;
2368
+ } else if (client_version <= DTLS1_VERSION &&
2369
+ !(s->options & SSL_OP_NO_DTLSv1)) {
2370
+ version = DTLS1_VERSION;
2371
+ }
2372
+
2373
+ /* Check against min_version. */
2374
+ if (version != 0 && s->min_version != 0 && version > s->min_version) {
2375
+ return 0;
2376
+ }
2377
+ return version;
2378
+ } else {
2379
+ /* Clamp client_version to max_version. */
2380
+ if (s->max_version != 0 && client_version > s->max_version) {
2381
+ client_version = s->max_version;
2382
+ }
2383
+
2384
+ if (client_version >= TLS1_2_VERSION && !(s->options & SSL_OP_NO_TLSv1_2)) {
2385
+ version = TLS1_2_VERSION;
2386
+ } else if (client_version >= TLS1_1_VERSION &&
2387
+ !(s->options & SSL_OP_NO_TLSv1_1)) {
2388
+ version = TLS1_1_VERSION;
2389
+ } else if (client_version >= TLS1_VERSION && !(s->options & SSL_OP_NO_TLSv1)) {
2390
+ version = TLS1_VERSION;
2391
+ } else if (client_version >= SSL3_VERSION && !(s->options & SSL_OP_NO_SSLv3)) {
2392
+ version = SSL3_VERSION;
2393
+ }
2394
+
2395
+ /* Check against min_version. */
2396
+ if (version != 0 && s->min_version != 0 && version < s->min_version) {
2397
+ return 0;
2398
+ }
2399
+ return version;
2400
+ }
2401
+ }
2402
+
2403
+ uint16_t ssl3_get_max_client_version(SSL *s) {
2404
+ uint32_t options = s->options;
2405
+ uint16_t version = 0;
2406
+
2407
+ /* OpenSSL's API for controlling versions entails blacklisting individual
2408
+ * protocols. This has two problems. First, on the client, the protocol can
2409
+ * only express a contiguous range of versions. Second, a library consumer
2410
+ * trying to set a maximum version cannot disable protocol versions that get
2411
+ * added in a future version of the library.
2412
+ *
2413
+ * To account for both of these, OpenSSL interprets the client-side bitmask
2414
+ * as a min/max range by picking the lowest contiguous non-empty range of
2415
+ * enabled protocols. Note that this means it is impossible to set a maximum
2416
+ * version of TLS 1.2 in a future-proof way.
2417
+ *
2418
+ * By this scheme, the maximum version is the lowest version V such that V is
2419
+ * enabled and V+1 is disabled or unimplemented. */
2420
+ if (SSL_IS_DTLS(s)) {
2421
+ if (!(options & SSL_OP_NO_DTLSv1_2)) {
2422
+ version = DTLS1_2_VERSION;
2423
+ }
2424
+ if (!(options & SSL_OP_NO_DTLSv1) && (options & SSL_OP_NO_DTLSv1_2)) {
2425
+ version = DTLS1_VERSION;
2426
+ }
2427
+ if (s->max_version != 0 && version < s->max_version) {
2428
+ version = s->max_version;
2429
+ }
2430
+ } else {
2431
+ if (!(options & SSL_OP_NO_TLSv1_2)) {
2432
+ version = TLS1_2_VERSION;
2433
+ }
2434
+ if (!(options & SSL_OP_NO_TLSv1_1) && (options & SSL_OP_NO_TLSv1_2)) {
2435
+ version = TLS1_1_VERSION;
2436
+ }
2437
+ if (!(options & SSL_OP_NO_TLSv1) && (options & SSL_OP_NO_TLSv1_1)) {
2438
+ version = TLS1_VERSION;
2439
+ }
2440
+ if (!(options & SSL_OP_NO_SSLv3) && (options & SSL_OP_NO_TLSv1)) {
2441
+ version = SSL3_VERSION;
2442
+ }
2443
+ if (s->max_version != 0 && version > s->max_version) {
2444
+ version = s->max_version;
2445
+ }
2446
+ }
2447
+
2448
+ return version;
2449
+ }
2450
+
2451
+ int ssl3_is_version_enabled(SSL *s, uint16_t version) {
2452
+ if (SSL_IS_DTLS(s)) {
2453
+ if (s->max_version != 0 && version < s->max_version) {
2454
+ return 0;
2455
+ }
2456
+ if (s->min_version != 0 && version > s->min_version) {
2457
+ return 0;
2458
+ }
2459
+
2460
+ switch (version) {
2461
+ case DTLS1_VERSION:
2462
+ return !(s->options & SSL_OP_NO_DTLSv1);
2463
+
2464
+ case DTLS1_2_VERSION:
2465
+ return !(s->options & SSL_OP_NO_DTLSv1_2);
2466
+
2467
+ default:
2468
+ return 0;
2469
+ }
2470
+ } else {
2471
+ if (s->max_version != 0 && version > s->max_version) {
2472
+ return 0;
2473
+ }
2474
+ if (s->min_version != 0 && version < s->min_version) {
2475
+ return 0;
2476
+ }
2477
+
2478
+ switch (version) {
2479
+ case SSL3_VERSION:
2480
+ return !(s->options & SSL_OP_NO_SSLv3);
2481
+
2482
+ case TLS1_VERSION:
2483
+ return !(s->options & SSL_OP_NO_TLSv1);
2484
+
2485
+ case TLS1_1_VERSION:
2486
+ return !(s->options & SSL_OP_NO_TLSv1_1);
2487
+
2488
+ case TLS1_2_VERSION:
2489
+ return !(s->options & SSL_OP_NO_TLSv1_2);
2490
+
2491
+ default:
2492
+ return 0;
2493
+ }
2494
+ }
2495
+ }
2496
+
2497
+ uint16_t ssl3_version_from_wire(SSL *s, uint16_t wire_version) {
2498
+ if (!SSL_IS_DTLS(s)) {
2499
+ return wire_version;
2500
+ }
2501
+
2502
+ uint16_t tls_version = ~wire_version;
2503
+ uint16_t version = tls_version + 0x0201;
2504
+ /* If either component overflowed, clamp it so comparisons still work. */
2505
+ if ((version >> 8) < (tls_version >> 8)) {
2506
+ version = 0xff00 | (version & 0xff);
2507
+ }
2508
+ if ((version & 0xff) < (tls_version & 0xff)) {
2509
+ version = (version & 0xff00) | 0xff;
2510
+ }
2511
+ /* DTLS 1.0 maps to TLS 1.1, not TLS 1.0. */
2512
+ if (version == TLS1_VERSION) {
2513
+ version = TLS1_1_VERSION;
2514
+ }
2515
+ return version;
2516
+ }
2517
+
2518
+ int SSL_cache_hit(SSL *ssl) { return SSL_session_reused(ssl); }
2519
+
2520
+ int SSL_is_server(SSL *ssl) { return ssl->server; }
2521
+
2522
+ void SSL_CTX_set_select_certificate_cb(
2523
+ SSL_CTX *ctx, int (*cb)(const struct ssl_early_callback_ctx *)) {
2524
+ ctx->select_certificate_cb = cb;
2525
+ }
2526
+
2527
+ void SSL_CTX_set_dos_protection_cb(
2528
+ SSL_CTX *ctx, int (*cb)(const struct ssl_early_callback_ctx *)) {
2529
+ ctx->dos_protection_cb = cb;
2530
+ }
2531
+
2532
+ void SSL_set_renegotiate_mode(SSL *ssl, enum ssl_renegotiate_mode_t mode) {
2533
+ ssl->renegotiate_mode = mode;
2534
+ }
2535
+
2536
+ void SSL_set_reject_peer_renegotiations(SSL *ssl, int reject) {
2537
+ SSL_set_renegotiate_mode(
2538
+ ssl, reject ? ssl_renegotiate_never : ssl_renegotiate_freely);
2539
+ }
2540
+
2541
+ int SSL_get_rc4_state(const SSL *ssl, const RC4_KEY **read_key,
2542
+ const RC4_KEY **write_key) {
2543
+ if (ssl->aead_read_ctx == NULL || ssl->aead_write_ctx == NULL) {
2544
+ return 0;
2545
+ }
2546
+
2547
+ return EVP_AEAD_CTX_get_rc4_state(&ssl->aead_read_ctx->ctx, read_key) &&
2548
+ EVP_AEAD_CTX_get_rc4_state(&ssl->aead_write_ctx->ctx, write_key);
2549
+ }
2550
+
2551
+ int SSL_get_ivs(const SSL *ssl, const uint8_t **out_read_iv,
2552
+ const uint8_t **out_write_iv, size_t *out_iv_len) {
2553
+ if (ssl->aead_read_ctx == NULL || ssl->aead_write_ctx == NULL) {
2554
+ return 0;
2555
+ }
2556
+
2557
+ size_t write_iv_len;
2558
+ if (!EVP_AEAD_CTX_get_iv(&ssl->aead_read_ctx->ctx, out_read_iv, out_iv_len) ||
2559
+ !EVP_AEAD_CTX_get_iv(&ssl->aead_write_ctx->ctx, out_write_iv,
2560
+ &write_iv_len) ||
2561
+ *out_iv_len != write_iv_len) {
2562
+ return 0;
2563
+ }
2564
+
2565
+ return 1;
2566
+ }
2567
+
2568
+ uint8_t SSL_get_server_key_exchange_hash(const SSL *ssl) {
2569
+ return ssl->s3->tmp.server_key_exchange_hash;
2570
+ }
2571
+
2572
+ int SSL_clear(SSL *ssl) {
2573
+ if (ssl->method == NULL) {
2574
+ OPENSSL_PUT_ERROR(SSL, SSL_R_NO_METHOD_SPECIFIED);
2575
+ return 0;
2576
+ }
2577
+
2578
+ if (ssl_clear_bad_session(ssl)) {
2579
+ SSL_SESSION_free(ssl->session);
2580
+ ssl->session = NULL;
2581
+ }
2582
+
2583
+ ssl->hit = 0;
2584
+ ssl->shutdown = 0;
2585
+
2586
+ /* SSL_clear may be called before or after the |ssl| is initialized in either
2587
+ * accept or connect state. In the latter case, SSL_clear should preserve the
2588
+ * half and reset |ssl->state| accordingly. */
2589
+ if (ssl->handshake_func != NULL) {
2590
+ if (ssl->server) {
2591
+ SSL_set_accept_state(ssl);
2592
+ } else {
2593
+ SSL_set_connect_state(ssl);
2594
+ }
2595
+ } else {
2596
+ assert(ssl->state == 0);
2597
+ }
2598
+
2599
+ /* TODO(davidben): Some state on |ssl| is reset both in |SSL_new| and
2600
+ * |SSL_clear| because it is per-connection state rather than configuration
2601
+ * state. Per-connection state should be on |ssl->s3| and |ssl->d1| so it is
2602
+ * naturally reset at the right points between |SSL_new|, |SSL_clear|, and
2603
+ * |ssl3_new|. */
2604
+
2605
+ ssl->rwstate = SSL_NOTHING;
2606
+
2607
+ BUF_MEM_free(ssl->init_buf);
2608
+ ssl->init_buf = NULL;
2609
+
2610
+ ssl_clear_cipher_ctx(ssl);
2611
+
2612
+ OPENSSL_free(ssl->next_proto_negotiated);
2613
+ ssl->next_proto_negotiated = NULL;
2614
+ ssl->next_proto_negotiated_len = 0;
2615
+
2616
+ /* The ssl->d1->mtu is simultaneously configuration (preserved across
2617
+ * clear) and connection-specific state (gets reset).
2618
+ *
2619
+ * TODO(davidben): Avoid this. */
2620
+ unsigned mtu = 0;
2621
+ if (ssl->d1 != NULL) {
2622
+ mtu = ssl->d1->mtu;
2623
+ }
2624
+
2625
+ ssl->method->ssl_free(ssl);
2626
+ if (!ssl->method->ssl_new(ssl)) {
2627
+ return 0;
2628
+ }
2629
+ ssl->enc_method = ssl3_get_enc_method(ssl->version);
2630
+ assert(ssl->enc_method != NULL);
2631
+
2632
+ if (SSL_IS_DTLS(ssl) && (SSL_get_options(ssl) & SSL_OP_NO_QUERY_MTU)) {
2633
+ ssl->d1->mtu = mtu;
2634
+ }
2635
+
2636
+ ssl->client_version = ssl->version;
2637
+
2638
+ return 1;
2639
+ }
2640
+
2641
+ int SSL_CTX_sess_connect(const SSL_CTX *ctx) { return 0; }
2642
+ int SSL_CTX_sess_connect_good(const SSL_CTX *ctx) { return 0; }
2643
+ int SSL_CTX_sess_connect_renegotiate(const SSL_CTX *ctx) { return 0; }
2644
+ int SSL_CTX_sess_accept(const SSL_CTX *ctx) { return 0; }
2645
+ int SSL_CTX_sess_accept_renegotiate(const SSL_CTX *ctx) { return 0; }
2646
+ int SSL_CTX_sess_accept_good(const SSL_CTX *ctx) { return 0; }
2647
+ int SSL_CTX_sess_hits(const SSL_CTX *ctx) { return 0; }
2648
+ int SSL_CTX_sess_cb_hits(const SSL_CTX *ctx) { return 0; }
2649
+ int SSL_CTX_sess_misses(const SSL_CTX *ctx) { return 0; }
2650
+ int SSL_CTX_sess_timeouts(const SSL_CTX *ctx) { return 0; }
2651
+ int SSL_CTX_sess_cache_full(const SSL_CTX *ctx) { return 0; }
2652
+ void ERR_load_SSL_strings(void) {}
2653
+ void SSL_load_error_strings(void) {}