awesome-grpc-that-works 0.12.2 → 0.14.0.dev

Sign up to get free protection for your applications and to get access to all the features.
Files changed (724) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/Makefile +5783 -22121
  4. data/include/grpc/byte_buffer.h +2 -83
  5. data/include/grpc/census.h +173 -121
  6. data/include/grpc/compression.h +14 -38
  7. data/include/grpc/grpc.h +85 -434
  8. data/include/grpc/grpc_security.h +76 -46
  9. data/include/grpc/grpc_zookeeper.h +1 -1
  10. data/include/grpc/impl/codegen/alloc.h +74 -0
  11. data/include/grpc/impl/codegen/atm.h +92 -0
  12. data/include/grpc/impl/codegen/atm_gcc_atomic.h +72 -0
  13. data/include/grpc/impl/codegen/atm_gcc_sync.h +87 -0
  14. data/include/grpc/impl/codegen/atm_win32.h +125 -0
  15. data/include/grpc/impl/codegen/byte_buffer.h +121 -0
  16. data/include/grpc/impl/codegen/compression_types.h +73 -0
  17. data/include/grpc/impl/codegen/connectivity_state.h +59 -0
  18. data/include/grpc/impl/codegen/grpc_types.h +378 -0
  19. data/include/grpc/impl/codegen/log.h +110 -0
  20. data/include/grpc/impl/codegen/port_platform.h +370 -0
  21. data/include/grpc/impl/codegen/propagation_bits.h +67 -0
  22. data/include/grpc/impl/codegen/slice.h +182 -0
  23. data/include/grpc/impl/codegen/slice_buffer.h +105 -0
  24. data/include/grpc/impl/codegen/status.h +163 -0
  25. data/include/grpc/impl/codegen/sync.h +316 -0
  26. data/include/grpc/impl/codegen/sync_generic.h +55 -0
  27. data/{src/core/census/context.h → include/grpc/impl/codegen/sync_posix.h} +11 -11
  28. data/include/grpc/impl/codegen/sync_win32.h +49 -0
  29. data/include/grpc/impl/codegen/time.h +130 -0
  30. data/include/grpc/status.h +2 -126
  31. data/include/grpc/support/alloc.h +2 -35
  32. data/include/grpc/support/atm.h +2 -55
  33. data/include/grpc/support/atm_gcc_atomic.h +5 -38
  34. data/include/grpc/support/atm_gcc_sync.h +2 -50
  35. data/include/grpc/support/atm_win32.h +2 -88
  36. data/include/grpc/support/avl.h +10 -9
  37. data/include/grpc/support/cmdline.h +15 -13
  38. data/include/grpc/support/cpu.h +5 -3
  39. data/include/grpc/support/histogram.h +23 -20
  40. data/include/grpc/support/host_port.h +5 -3
  41. data/include/grpc/support/log.h +2 -71
  42. data/include/grpc/support/log_win32.h +2 -2
  43. data/include/grpc/support/port_platform.h +2 -319
  44. data/include/grpc/support/slice.h +2 -145
  45. data/include/grpc/support/slice_buffer.h +2 -65
  46. data/include/grpc/support/string_util.h +3 -3
  47. data/include/grpc/support/subprocess.h +8 -6
  48. data/include/grpc/support/sync.h +2 -278
  49. data/include/grpc/support/sync_generic.h +2 -18
  50. data/include/grpc/support/sync_posix.h +2 -10
  51. data/include/grpc/support/sync_win32.h +2 -12
  52. data/include/grpc/support/thd.h +11 -11
  53. data/include/grpc/support/time.h +2 -91
  54. data/include/grpc/support/tls.h +1 -1
  55. data/include/grpc/support/tls_gcc.h +1 -1
  56. data/include/grpc/support/tls_msvc.h +1 -1
  57. data/include/grpc/support/tls_pthread.h +2 -2
  58. data/include/grpc/support/useful.h +3 -1
  59. data/src/boringssl/err_data.c +1252 -0
  60. data/src/core/census/context.c +471 -8
  61. data/src/core/census/grpc_filter.c +5 -5
  62. data/src/core/census/initialize.c +4 -7
  63. data/src/core/census/mlog.c +600 -0
  64. data/src/core/census/mlog.h +95 -0
  65. data/src/core/census/operation.c +2 -2
  66. data/src/core/census/placeholders.c +109 -0
  67. data/src/core/census/rpc_metric_id.h +6 -6
  68. data/src/core/census/tracing.c +1 -1
  69. data/src/core/channel/channel_args.c +71 -9
  70. data/src/core/channel/channel_args.h +7 -1
  71. data/src/core/channel/channel_stack.c +1 -1
  72. data/src/core/channel/client_channel.c +33 -30
  73. data/src/core/channel/client_uchannel.c +3 -3
  74. data/src/core/channel/compress_filter.c +8 -8
  75. data/src/core/channel/http_client_filter.c +4 -4
  76. data/src/core/channel/http_server_filter.c +11 -11
  77. data/src/core/channel/subchannel_call_holder.c +11 -11
  78. data/src/core/client_config/connector.c +3 -2
  79. data/src/core/client_config/connector.h +2 -2
  80. data/src/core/client_config/lb_policies/load_balancer_api.c +163 -0
  81. data/src/core/client_config/lb_policies/load_balancer_api.h +85 -0
  82. data/src/core/client_config/lb_policies/pick_first.c +57 -40
  83. data/src/core/client_config/lb_policies/round_robin.c +14 -15
  84. data/src/core/client_config/lb_policy.c +3 -3
  85. data/src/core/client_config/lb_policy.h +3 -2
  86. data/src/core/client_config/resolvers/dns_resolver.c +3 -3
  87. data/src/core/client_config/resolvers/sockaddr_resolver.c +5 -5
  88. data/src/core/client_config/subchannel.c +84 -39
  89. data/src/core/client_config/subchannel.h +15 -6
  90. data/src/core/client_config/subchannel_index.c +261 -0
  91. data/src/core/client_config/subchannel_index.h +77 -0
  92. data/src/core/compression/{algorithm.c → compression_algorithm.c} +3 -3
  93. data/src/core/httpcli/format_request.c +1 -1
  94. data/src/core/httpcli/httpcli.c +18 -16
  95. data/src/core/httpcli/httpcli.h +3 -2
  96. data/src/core/httpcli/httpcli_security_connector.c +9 -10
  97. data/src/core/httpcli/parser.c +7 -7
  98. data/src/core/httpcli/parser.h +1 -1
  99. data/src/core/iomgr/closure.c +7 -7
  100. data/src/core/iomgr/closure.h +6 -5
  101. data/src/core/iomgr/exec_ctx.c +12 -8
  102. data/src/core/iomgr/exec_ctx.h +12 -5
  103. data/src/core/iomgr/executor.c +4 -4
  104. data/src/core/iomgr/executor.h +2 -2
  105. data/src/core/iomgr/fd_posix.c +32 -19
  106. data/src/core/iomgr/fd_posix.h +7 -4
  107. data/src/core/iomgr/iocp_windows.c +7 -9
  108. data/src/core/iomgr/iomgr.c +2 -2
  109. data/src/core/iomgr/pollset.h +9 -10
  110. data/src/core/iomgr/pollset_multipoller_with_epoll.c +71 -5
  111. data/src/core/iomgr/pollset_multipoller_with_poll_posix.c +9 -5
  112. data/src/core/iomgr/pollset_posix.c +44 -49
  113. data/src/core/iomgr/pollset_posix.h +14 -8
  114. data/src/core/iomgr/pollset_set.h +3 -9
  115. data/src/core/iomgr/pollset_set_posix.c +23 -3
  116. data/src/core/iomgr/pollset_set_posix.h +2 -18
  117. data/src/core/iomgr/pollset_set_windows.c +3 -3
  118. data/src/core/iomgr/pollset_set_windows.h +2 -2
  119. data/src/core/iomgr/pollset_windows.c +29 -37
  120. data/src/core/iomgr/pollset_windows.h +1 -5
  121. data/src/core/iomgr/resolve_address_posix.c +2 -2
  122. data/src/core/iomgr/resolve_address_windows.c +2 -2
  123. data/src/core/iomgr/sockaddr_utils.c +6 -6
  124. data/src/core/iomgr/sockaddr_win32.h +1 -6
  125. data/src/core/iomgr/tcp_client_posix.c +14 -12
  126. data/src/core/iomgr/tcp_client_windows.c +4 -4
  127. data/src/core/iomgr/tcp_posix.c +18 -10
  128. data/src/core/iomgr/tcp_posix.h +7 -1
  129. data/src/core/iomgr/tcp_server.h +40 -20
  130. data/src/core/iomgr/tcp_server_posix.c +106 -49
  131. data/src/core/iomgr/tcp_server_windows.c +98 -49
  132. data/src/core/iomgr/tcp_windows.c +11 -15
  133. data/src/core/iomgr/timer.c +10 -11
  134. data/src/core/iomgr/timer.h +22 -2
  135. data/src/core/iomgr/timer_heap.c +10 -10
  136. data/src/core/iomgr/timer_heap.h +2 -2
  137. data/src/core/iomgr/udp_server.c +7 -16
  138. data/src/core/iomgr/udp_server.h +2 -9
  139. data/src/core/iomgr/workqueue.h +2 -4
  140. data/src/core/iomgr/workqueue_posix.c +4 -3
  141. data/src/core/iomgr/workqueue_posix.h +3 -1
  142. data/src/core/json/json_reader.c +11 -12
  143. data/src/core/json/json_reader.h +4 -4
  144. data/src/core/json/json_string.c +19 -19
  145. data/src/core/json/json_writer.c +7 -9
  146. data/src/core/profiling/basic_timers.c +1 -1
  147. data/src/core/proto/grpc/lb/v0/load_balancer.pb.c +119 -0
  148. data/src/core/proto/grpc/lb/v0/load_balancer.pb.h +182 -0
  149. data/src/core/security/{base64.c → b64.c} +10 -10
  150. data/src/core/security/{base64.h → b64.h} +1 -1
  151. data/src/core/security/client_auth_filter.c +4 -5
  152. data/src/core/security/credentials.c +17 -10
  153. data/src/core/security/credentials.h +3 -3
  154. data/src/core/security/google_default_credentials.c +27 -22
  155. data/src/core/security/handshake.c +21 -12
  156. data/src/core/security/handshake.h +2 -1
  157. data/src/core/security/json_token.c +14 -8
  158. data/src/core/security/jwt_verifier.c +4 -3
  159. data/src/core/security/secure_endpoint.c +16 -16
  160. data/src/core/security/security_connector.c +131 -81
  161. data/src/core/security/security_connector.h +47 -27
  162. data/src/core/security/security_context.c +8 -3
  163. data/src/core/security/server_auth_filter.c +5 -5
  164. data/src/core/security/server_secure_chttp2.c +36 -37
  165. data/src/core/statistics/census_interface.h +2 -2
  166. data/src/core/statistics/census_rpc_stats.h +3 -3
  167. data/src/core/support/alloc.c +1 -1
  168. data/src/core/support/avl.c +2 -2
  169. data/src/core/support/cpu_posix.c +2 -2
  170. data/src/core/support/env_linux.c +28 -1
  171. data/src/core/support/env_win32.c +15 -7
  172. data/src/core/support/histogram.c +5 -5
  173. data/src/core/support/{file.c → load_file.c} +2 -2
  174. data/src/core/support/{file.h → load_file.h} +4 -12
  175. data/src/core/support/log_posix.c +1 -1
  176. data/src/core/support/log_win32.c +4 -3
  177. data/src/core/support/murmur_hash.c +11 -11
  178. data/src/core/support/murmur_hash.h +1 -1
  179. data/src/core/support/slice.c +11 -11
  180. data/src/core/support/slice_buffer.c +6 -6
  181. data/src/core/support/stack_lockfree.c +20 -10
  182. data/src/core/support/string.c +15 -15
  183. data/src/core/support/string.h +5 -5
  184. data/src/core/support/string_win32.c +5 -5
  185. data/src/core/support/subprocess_windows.c +141 -0
  186. data/src/core/support/sync.c +4 -4
  187. data/src/core/support/sync_posix.c +2 -2
  188. data/src/core/support/sync_win32.c +10 -5
  189. data/src/core/support/time.c +29 -29
  190. data/src/core/support/time_posix.c +15 -6
  191. data/src/core/support/time_precise.c +2 -2
  192. data/src/core/support/time_win32.c +18 -9
  193. data/src/core/support/tls_pthread.c +1 -1
  194. data/src/core/support/tmpfile.h +55 -0
  195. data/src/core/support/{file_posix.c → tmpfile_posix.c} +2 -2
  196. data/src/core/support/{file_win32.c → tmpfile_win32.c} +2 -2
  197. data/src/core/support/wrap_memcpy.c +53 -0
  198. data/src/core/surface/alarm.c +84 -0
  199. data/src/core/surface/byte_buffer_reader.c +1 -1
  200. data/src/core/surface/call.c +175 -116
  201. data/src/core/surface/call.h +2 -2
  202. data/src/core/surface/call_test_only.h +2 -2
  203. data/src/core/surface/channel.c +9 -9
  204. data/src/core/surface/channel.h +1 -1
  205. data/src/core/surface/channel_connectivity.c +3 -3
  206. data/src/core/surface/channel_create.c +4 -4
  207. data/src/core/surface/channel_ping.c +2 -2
  208. data/src/core/surface/completion_queue.c +84 -53
  209. data/src/core/surface/completion_queue.h +1 -1
  210. data/src/core/surface/init.c +11 -5
  211. data/src/core/surface/lame_client.c +2 -3
  212. data/src/core/surface/secure_channel_create.c +9 -10
  213. data/src/core/surface/server.c +30 -30
  214. data/src/core/surface/server_chttp2.c +8 -8
  215. data/src/core/surface/server_create.c +1 -4
  216. data/src/core/surface/validate_metadata.c +4 -4
  217. data/src/core/surface/version.c +2 -2
  218. data/src/core/transport/byte_stream.c +8 -6
  219. data/src/core/transport/byte_stream.h +6 -5
  220. data/src/core/transport/chttp2/bin_encoder.c +29 -29
  221. data/src/core/transport/chttp2/frame_data.c +29 -26
  222. data/src/core/transport/chttp2/frame_data.h +6 -6
  223. data/src/core/transport/chttp2/frame_goaway.c +30 -30
  224. data/src/core/transport/chttp2/frame_goaway.h +6 -6
  225. data/src/core/transport/chttp2/frame_ping.c +6 -6
  226. data/src/core/transport/chttp2/frame_ping.h +5 -5
  227. data/src/core/transport/chttp2/frame_rst_stream.c +18 -19
  228. data/src/core/transport/chttp2/frame_rst_stream.h +4 -4
  229. data/src/core/transport/chttp2/frame_settings.c +30 -30
  230. data/src/core/transport/chttp2/frame_settings.h +13 -13
  231. data/src/core/transport/chttp2/frame_window_update.c +17 -18
  232. data/src/core/transport/chttp2/frame_window_update.h +5 -7
  233. data/src/core/transport/chttp2/hpack_encoder.c +69 -73
  234. data/src/core/transport/chttp2/hpack_encoder.h +16 -16
  235. data/src/core/transport/chttp2/hpack_parser.c +167 -167
  236. data/src/core/transport/chttp2/hpack_parser.h +16 -16
  237. data/src/core/transport/chttp2/hpack_table.c +13 -13
  238. data/src/core/transport/chttp2/hpack_table.h +11 -11
  239. data/src/core/transport/chttp2/internal.h +103 -87
  240. data/src/core/transport/chttp2/parsing.c +25 -25
  241. data/src/core/transport/chttp2/stream_lists.c +38 -1
  242. data/src/core/transport/chttp2/stream_map.c +13 -14
  243. data/src/core/transport/chttp2/stream_map.h +6 -7
  244. data/src/core/transport/chttp2/timeout_encoding.c +19 -16
  245. data/src/core/transport/chttp2/varint.c +8 -9
  246. data/src/core/transport/chttp2/varint.h +7 -8
  247. data/src/core/transport/chttp2/writing.c +25 -22
  248. data/src/core/transport/chttp2_transport.c +147 -100
  249. data/src/core/transport/connectivity_state.c +6 -6
  250. data/src/core/transport/metadata.c +18 -18
  251. data/src/core/transport/metadata.h +5 -5
  252. data/src/core/transport/static_metadata.c +32 -33
  253. data/src/core/transport/static_metadata.h +8 -8
  254. data/src/core/transport/transport.c +6 -5
  255. data/src/core/transport/transport.h +17 -1
  256. data/src/core/tsi/fake_transport_security.c +7 -7
  257. data/src/core/tsi/ssl_transport_security.c +6 -4
  258. data/src/core/{iomgr/timer_internal.h → tsi/ssl_types.h} +19 -25
  259. data/src/ruby/ext/grpc/extconf.rb +52 -14
  260. data/src/ruby/ext/grpc/rb_byte_buffer.c +3 -1
  261. data/src/ruby/ext/grpc/rb_call.c +7 -3
  262. data/src/ruby/ext/grpc/rb_call_credentials.c +4 -0
  263. data/src/ruby/ext/grpc/rb_channel.c +4 -2
  264. data/src/ruby/ext/grpc/rb_channel_args.c +3 -1
  265. data/src/ruby/ext/grpc/rb_channel_credentials.c +3 -1
  266. data/src/ruby/ext/grpc/rb_completion_queue.c +3 -1
  267. data/src/ruby/ext/grpc/rb_event_thread.c +5 -0
  268. data/src/ruby/ext/grpc/rb_grpc.c +28 -19
  269. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +562 -0
  270. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +846 -0
  271. data/src/ruby/ext/grpc/rb_loader.c +72 -0
  272. data/src/ruby/ext/grpc/rb_loader.h +40 -0
  273. data/src/ruby/ext/grpc/rb_server.c +3 -1
  274. data/src/ruby/ext/grpc/rb_server_credentials.c +4 -2
  275. data/src/ruby/lib/grpc/core/time_consts.rb +2 -2
  276. data/src/ruby/lib/grpc/errors.rb +2 -2
  277. data/src/ruby/lib/grpc/generic/bidi_call.rb +1 -1
  278. data/src/ruby/lib/grpc/generic/rpc_desc.rb +1 -1
  279. data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
  280. data/src/ruby/lib/grpc/grpc.rb +34 -0
  281. data/src/ruby/lib/grpc/version.rb +1 -1
  282. data/src/ruby/pb/README.md +2 -2
  283. data/src/ruby/pb/generate_proto_ruby.sh +2 -2
  284. data/src/ruby/pb/grpc/health/checker.rb +11 -11
  285. data/src/ruby/pb/grpc/health/v1/health.rb +28 -0
  286. data/src/ruby/pb/grpc/health/{v1alpha → v1}/health_services.rb +4 -4
  287. data/src/ruby/spec/client_server_spec.rb +2 -1
  288. data/src/ruby/spec/pb/health/checker_spec.rb +23 -37
  289. data/third_party/boringssl/crypto/aes/aes.c +1142 -0
  290. data/third_party/boringssl/crypto/aes/internal.h +87 -0
  291. data/third_party/boringssl/crypto/aes/mode_wrappers.c +108 -0
  292. data/third_party/boringssl/crypto/asn1/a_bitstr.c +255 -0
  293. data/third_party/boringssl/crypto/asn1/a_bool.c +112 -0
  294. data/third_party/boringssl/crypto/asn1/a_bytes.c +317 -0
  295. data/third_party/boringssl/crypto/asn1/a_d2i_fp.c +286 -0
  296. data/third_party/boringssl/crypto/asn1/a_dup.c +103 -0
  297. data/third_party/boringssl/crypto/asn1/a_enum.c +183 -0
  298. data/third_party/boringssl/crypto/asn1/a_gentm.c +255 -0
  299. data/third_party/boringssl/crypto/asn1/a_i2d_fp.c +154 -0
  300. data/third_party/boringssl/crypto/asn1/a_int.c +456 -0
  301. data/third_party/boringssl/crypto/asn1/a_mbstr.c +390 -0
  302. data/third_party/boringssl/crypto/asn1/a_object.c +412 -0
  303. data/third_party/boringssl/crypto/asn1/a_octet.c +70 -0
  304. data/third_party/boringssl/crypto/asn1/a_print.c +119 -0
  305. data/third_party/boringssl/crypto/asn1/a_strnid.c +286 -0
  306. data/third_party/boringssl/crypto/asn1/a_time.c +221 -0
  307. data/third_party/boringssl/crypto/asn1/a_type.c +160 -0
  308. data/third_party/boringssl/crypto/asn1/a_utctm.c +342 -0
  309. data/third_party/boringssl/crypto/asn1/a_utf8.c +210 -0
  310. data/third_party/boringssl/crypto/asn1/asn1_lib.c +510 -0
  311. data/third_party/boringssl/crypto/asn1/asn1_locl.h +73 -0
  312. data/third_party/boringssl/crypto/asn1/asn1_par.c +444 -0
  313. data/third_party/boringssl/crypto/asn1/asn_pack.c +104 -0
  314. data/third_party/boringssl/crypto/asn1/bio_asn1.c +496 -0
  315. data/third_party/boringssl/crypto/asn1/bio_ndef.c +254 -0
  316. data/third_party/boringssl/crypto/asn1/f_enum.c +206 -0
  317. data/third_party/boringssl/crypto/asn1/f_int.c +210 -0
  318. data/third_party/boringssl/crypto/asn1/f_string.c +204 -0
  319. data/third_party/boringssl/crypto/asn1/t_bitst.c +102 -0
  320. data/third_party/boringssl/crypto/asn1/t_pkey.c +112 -0
  321. data/third_party/boringssl/crypto/asn1/tasn_dec.c +1342 -0
  322. data/third_party/boringssl/crypto/asn1/tasn_enc.c +695 -0
  323. data/third_party/boringssl/crypto/asn1/tasn_fre.c +264 -0
  324. data/third_party/boringssl/crypto/asn1/tasn_new.c +398 -0
  325. data/third_party/boringssl/crypto/asn1/tasn_prn.c +642 -0
  326. data/third_party/boringssl/crypto/asn1/tasn_typ.c +137 -0
  327. data/third_party/boringssl/crypto/asn1/tasn_utl.c +266 -0
  328. data/third_party/boringssl/crypto/asn1/x_bignum.c +143 -0
  329. data/third_party/boringssl/crypto/asn1/x_long.c +182 -0
  330. data/third_party/boringssl/crypto/base64/base64.c +478 -0
  331. data/third_party/boringssl/crypto/bio/bio.c +608 -0
  332. data/third_party/boringssl/crypto/bio/bio_mem.c +327 -0
  333. data/third_party/boringssl/crypto/bio/buffer.c +496 -0
  334. data/third_party/boringssl/crypto/bio/connect.c +544 -0
  335. data/third_party/boringssl/crypto/bio/fd.c +270 -0
  336. data/third_party/boringssl/crypto/bio/file.c +349 -0
  337. data/third_party/boringssl/crypto/bio/hexdump.c +192 -0
  338. data/third_party/boringssl/crypto/bio/internal.h +108 -0
  339. data/third_party/boringssl/crypto/bio/pair.c +803 -0
  340. data/third_party/boringssl/crypto/bio/printf.c +119 -0
  341. data/third_party/boringssl/crypto/bio/socket.c +195 -0
  342. data/third_party/boringssl/crypto/bio/socket_helper.c +113 -0
  343. data/third_party/boringssl/crypto/bn/add.c +377 -0
  344. data/third_party/boringssl/crypto/bn/asm/x86_64-gcc.c +599 -0
  345. data/third_party/boringssl/crypto/bn/bn.c +341 -0
  346. data/third_party/boringssl/crypto/bn/bn_asn1.c +93 -0
  347. data/third_party/boringssl/crypto/bn/cmp.c +200 -0
  348. data/third_party/boringssl/crypto/bn/convert.c +597 -0
  349. data/third_party/boringssl/crypto/bn/ctx.c +311 -0
  350. data/third_party/boringssl/crypto/bn/div.c +625 -0
  351. data/third_party/boringssl/crypto/bn/exponentiation.c +1544 -0
  352. data/third_party/boringssl/crypto/bn/gcd.c +711 -0
  353. data/third_party/boringssl/crypto/bn/generic.c +1019 -0
  354. data/third_party/boringssl/crypto/bn/internal.h +294 -0
  355. data/third_party/boringssl/crypto/bn/kronecker.c +175 -0
  356. data/third_party/boringssl/crypto/bn/montgomery.c +561 -0
  357. data/third_party/boringssl/crypto/bn/mul.c +888 -0
  358. data/third_party/boringssl/crypto/bn/prime.c +845 -0
  359. data/third_party/boringssl/crypto/bn/random.c +326 -0
  360. data/third_party/boringssl/crypto/bn/rsaz_exp.c +326 -0
  361. data/third_party/boringssl/crypto/bn/rsaz_exp.h +56 -0
  362. data/third_party/boringssl/crypto/bn/shift.c +299 -0
  363. data/third_party/boringssl/crypto/bn/sqrt.c +505 -0
  364. data/third_party/boringssl/crypto/buf/buf.c +235 -0
  365. data/third_party/boringssl/crypto/bytestring/ber.c +221 -0
  366. data/third_party/boringssl/crypto/bytestring/cbb.c +411 -0
  367. data/third_party/boringssl/crypto/bytestring/cbs.c +415 -0
  368. data/third_party/boringssl/crypto/bytestring/internal.h +46 -0
  369. data/third_party/boringssl/crypto/chacha/chacha_generic.c +140 -0
  370. data/third_party/boringssl/crypto/chacha/chacha_vec.c +323 -0
  371. data/third_party/boringssl/crypto/cipher/aead.c +167 -0
  372. data/third_party/boringssl/crypto/cipher/cipher.c +652 -0
  373. data/third_party/boringssl/crypto/cipher/derive_key.c +154 -0
  374. data/third_party/boringssl/crypto/cipher/e_aes.c +1767 -0
  375. data/third_party/boringssl/crypto/cipher/e_chacha20poly1305.c +311 -0
  376. data/third_party/boringssl/crypto/cipher/e_des.c +207 -0
  377. data/third_party/boringssl/crypto/cipher/e_null.c +85 -0
  378. data/third_party/boringssl/crypto/cipher/e_rc2.c +443 -0
  379. data/third_party/boringssl/crypto/cipher/e_rc4.c +87 -0
  380. data/third_party/boringssl/crypto/cipher/e_ssl3.c +463 -0
  381. data/third_party/boringssl/crypto/cipher/e_tls.c +673 -0
  382. data/third_party/boringssl/crypto/cipher/internal.h +164 -0
  383. data/third_party/boringssl/crypto/cipher/tls_cbc.c +495 -0
  384. data/third_party/boringssl/crypto/cmac/cmac.c +239 -0
  385. data/third_party/boringssl/crypto/conf/conf.c +778 -0
  386. data/third_party/boringssl/crypto/conf/conf_def.h +127 -0
  387. data/third_party/boringssl/crypto/conf/internal.h +31 -0
  388. data/third_party/boringssl/crypto/cpu-arm.c +199 -0
  389. data/third_party/boringssl/crypto/cpu-intel.c +261 -0
  390. data/third_party/boringssl/crypto/crypto.c +140 -0
  391. data/third_party/boringssl/crypto/curve25519/curve25519.c +4897 -0
  392. data/third_party/boringssl/crypto/des/des.c +771 -0
  393. data/third_party/boringssl/crypto/des/internal.h +212 -0
  394. data/third_party/boringssl/crypto/dh/check.c +180 -0
  395. data/third_party/boringssl/crypto/dh/dh.c +463 -0
  396. data/third_party/boringssl/crypto/dh/dh_asn1.c +84 -0
  397. data/third_party/boringssl/crypto/dh/internal.h +80 -0
  398. data/third_party/boringssl/crypto/dh/params.c +301 -0
  399. data/third_party/boringssl/crypto/digest/digest.c +248 -0
  400. data/third_party/boringssl/crypto/digest/digests.c +321 -0
  401. data/third_party/boringssl/crypto/digest/internal.h +112 -0
  402. data/third_party/boringssl/crypto/digest/md32_common.h +322 -0
  403. data/third_party/boringssl/crypto/directory.h +66 -0
  404. data/third_party/boringssl/crypto/directory_posix.c +108 -0
  405. data/third_party/boringssl/crypto/directory_win.c +144 -0
  406. data/third_party/boringssl/crypto/dsa/dsa.c +908 -0
  407. data/third_party/boringssl/crypto/dsa/dsa_asn1.c +150 -0
  408. data/third_party/boringssl/crypto/dsa/internal.h +78 -0
  409. data/third_party/boringssl/crypto/ec/ec.c +889 -0
  410. data/third_party/boringssl/crypto/ec/ec_asn1.c +586 -0
  411. data/third_party/boringssl/crypto/ec/ec_key.c +482 -0
  412. data/third_party/boringssl/crypto/ec/ec_montgomery.c +280 -0
  413. data/third_party/boringssl/crypto/ec/internal.h +318 -0
  414. data/third_party/boringssl/crypto/ec/oct.c +416 -0
  415. data/third_party/boringssl/crypto/ec/p224-64.c +1305 -0
  416. data/third_party/boringssl/crypto/ec/p256-64.c +1878 -0
  417. data/third_party/boringssl/crypto/ec/p256-x86_64-table.h +9548 -0
  418. data/third_party/boringssl/crypto/ec/p256-x86_64.c +596 -0
  419. data/third_party/boringssl/crypto/ec/simple.c +1313 -0
  420. data/third_party/boringssl/crypto/ec/util-64.c +183 -0
  421. data/third_party/boringssl/crypto/ec/wnaf.c +449 -0
  422. data/third_party/boringssl/crypto/ecdh/ecdh.c +153 -0
  423. data/third_party/boringssl/crypto/ecdsa/ecdsa.c +496 -0
  424. data/third_party/boringssl/crypto/ecdsa/ecdsa_asn1.c +240 -0
  425. data/third_party/boringssl/crypto/engine/engine.c +96 -0
  426. data/third_party/boringssl/crypto/err/err.c +756 -0
  427. data/third_party/boringssl/crypto/evp/algorithm.c +153 -0
  428. data/third_party/boringssl/crypto/evp/digestsign.c +159 -0
  429. data/third_party/boringssl/crypto/evp/evp.c +411 -0
  430. data/third_party/boringssl/crypto/evp/evp_asn1.c +179 -0
  431. data/third_party/boringssl/crypto/evp/evp_ctx.c +477 -0
  432. data/third_party/boringssl/crypto/evp/internal.h +278 -0
  433. data/third_party/boringssl/crypto/evp/p_dsa_asn1.c +588 -0
  434. data/third_party/boringssl/crypto/evp/p_ec.c +283 -0
  435. data/third_party/boringssl/crypto/evp/p_ec_asn1.c +562 -0
  436. data/third_party/boringssl/crypto/evp/p_rsa.c +596 -0
  437. data/third_party/boringssl/crypto/evp/p_rsa_asn1.c +737 -0
  438. data/third_party/boringssl/crypto/evp/pbkdf.c +151 -0
  439. data/third_party/boringssl/crypto/evp/sign.c +151 -0
  440. data/third_party/boringssl/crypto/ex_data.c +294 -0
  441. data/third_party/boringssl/crypto/hkdf/hkdf.c +89 -0
  442. data/third_party/boringssl/crypto/hmac/hmac.c +213 -0
  443. data/third_party/boringssl/crypto/internal.h +532 -0
  444. data/third_party/boringssl/crypto/lhash/lhash.c +346 -0
  445. data/third_party/boringssl/crypto/md4/md4.c +225 -0
  446. data/third_party/boringssl/crypto/md5/md5.c +275 -0
  447. data/third_party/boringssl/crypto/mem.c +200 -0
  448. data/third_party/boringssl/crypto/modes/cbc.c +216 -0
  449. data/third_party/boringssl/crypto/modes/cfb.c +231 -0
  450. data/third_party/boringssl/crypto/modes/ctr.c +226 -0
  451. data/third_party/boringssl/crypto/modes/gcm.c +1252 -0
  452. data/third_party/boringssl/crypto/modes/internal.h +370 -0
  453. data/third_party/boringssl/crypto/modes/ofb.c +108 -0
  454. data/third_party/boringssl/crypto/obj/obj.c +664 -0
  455. data/third_party/boringssl/crypto/obj/obj_dat.h +5257 -0
  456. data/third_party/boringssl/crypto/obj/obj_xref.c +124 -0
  457. data/third_party/boringssl/crypto/obj/obj_xref.h +96 -0
  458. data/third_party/boringssl/crypto/pem/pem_all.c +281 -0
  459. data/third_party/boringssl/crypto/pem/pem_info.c +404 -0
  460. data/third_party/boringssl/crypto/pem/pem_lib.c +835 -0
  461. data/third_party/boringssl/crypto/pem/pem_oth.c +89 -0
  462. data/third_party/boringssl/crypto/pem/pem_pk8.c +244 -0
  463. data/third_party/boringssl/crypto/pem/pem_pkey.c +312 -0
  464. data/third_party/boringssl/crypto/pem/pem_x509.c +65 -0
  465. data/third_party/boringssl/crypto/pem/pem_xaux.c +66 -0
  466. data/third_party/boringssl/crypto/pkcs8/internal.h +83 -0
  467. data/third_party/boringssl/crypto/pkcs8/p5_pbe.c +150 -0
  468. data/third_party/boringssl/crypto/pkcs8/p5_pbev2.c +440 -0
  469. data/third_party/boringssl/crypto/pkcs8/p8_pkey.c +85 -0
  470. data/third_party/boringssl/crypto/pkcs8/pkcs8.c +1217 -0
  471. data/third_party/boringssl/crypto/poly1305/poly1305.c +331 -0
  472. data/third_party/boringssl/crypto/poly1305/poly1305_arm.c +301 -0
  473. data/third_party/boringssl/crypto/poly1305/poly1305_vec.c +892 -0
  474. data/third_party/boringssl/crypto/rand/internal.h +32 -0
  475. data/third_party/boringssl/crypto/rand/rand.c +239 -0
  476. data/third_party/boringssl/crypto/rand/urandom.c +223 -0
  477. data/third_party/boringssl/crypto/rand/windows.c +56 -0
  478. data/third_party/boringssl/crypto/rc4/rc4.c +283 -0
  479. data/third_party/boringssl/crypto/refcount_c11.c +67 -0
  480. data/third_party/boringssl/crypto/refcount_lock.c +53 -0
  481. data/third_party/boringssl/crypto/rsa/blinding.c +462 -0
  482. data/third_party/boringssl/crypto/rsa/internal.h +164 -0
  483. data/third_party/boringssl/crypto/rsa/padding.c +711 -0
  484. data/third_party/boringssl/crypto/rsa/rsa.c +808 -0
  485. data/third_party/boringssl/crypto/rsa/rsa_asn1.c +473 -0
  486. data/third_party/boringssl/crypto/rsa/rsa_impl.c +1138 -0
  487. data/third_party/boringssl/crypto/sha/sha1.c +337 -0
  488. data/third_party/boringssl/crypto/sha/sha256.c +327 -0
  489. data/third_party/boringssl/crypto/sha/sha512.c +607 -0
  490. data/third_party/boringssl/crypto/stack/stack.c +386 -0
  491. data/third_party/boringssl/crypto/test/scoped_types.h +137 -0
  492. data/third_party/boringssl/crypto/test/test_util.h +35 -0
  493. data/third_party/boringssl/crypto/thread.c +101 -0
  494. data/third_party/boringssl/crypto/thread_none.c +55 -0
  495. data/third_party/boringssl/crypto/thread_pthread.c +167 -0
  496. data/third_party/boringssl/crypto/thread_win.c +282 -0
  497. data/third_party/boringssl/crypto/time_support.c +212 -0
  498. data/third_party/boringssl/crypto/x509/a_digest.c +97 -0
  499. data/third_party/boringssl/crypto/x509/a_sign.c +136 -0
  500. data/third_party/boringssl/crypto/x509/a_strex.c +564 -0
  501. data/third_party/boringssl/crypto/x509/a_verify.c +133 -0
  502. data/third_party/boringssl/crypto/x509/asn1_gen.c +873 -0
  503. data/third_party/boringssl/crypto/x509/by_dir.c +491 -0
  504. data/third_party/boringssl/crypto/x509/by_file.c +295 -0
  505. data/third_party/boringssl/crypto/x509/charmap.h +15 -0
  506. data/third_party/boringssl/crypto/x509/i2d_pr.c +84 -0
  507. data/third_party/boringssl/crypto/x509/pkcs7.c +353 -0
  508. data/third_party/boringssl/crypto/x509/t_crl.c +129 -0
  509. data/third_party/boringssl/crypto/x509/t_req.c +246 -0
  510. data/third_party/boringssl/crypto/x509/t_x509.c +500 -0
  511. data/third_party/boringssl/crypto/x509/t_x509a.c +109 -0
  512. data/third_party/boringssl/crypto/x509/vpm_int.h +70 -0
  513. data/third_party/boringssl/crypto/x509/x509.c +152 -0
  514. data/third_party/boringssl/crypto/x509/x509_att.c +353 -0
  515. data/third_party/boringssl/crypto/x509/x509_cmp.c +490 -0
  516. data/third_party/boringssl/crypto/x509/x509_d2.c +105 -0
  517. data/third_party/boringssl/crypto/x509/x509_def.c +88 -0
  518. data/third_party/boringssl/crypto/x509/x509_ext.c +206 -0
  519. data/third_party/boringssl/crypto/x509/x509_lu.c +738 -0
  520. data/third_party/boringssl/crypto/x509/x509_obj.c +191 -0
  521. data/third_party/boringssl/crypto/x509/x509_r2x.c +113 -0
  522. data/third_party/boringssl/crypto/x509/x509_req.c +315 -0
  523. data/third_party/boringssl/crypto/x509/x509_set.c +154 -0
  524. data/third_party/boringssl/crypto/x509/x509_trs.c +304 -0
  525. data/third_party/boringssl/crypto/x509/x509_txt.c +209 -0
  526. data/third_party/boringssl/crypto/x509/x509_v3.c +271 -0
  527. data/third_party/boringssl/crypto/x509/x509_vfy.c +2456 -0
  528. data/third_party/boringssl/crypto/x509/x509_vpm.c +672 -0
  529. data/third_party/boringssl/crypto/x509/x509cset.c +172 -0
  530. data/third_party/boringssl/crypto/x509/x509name.c +381 -0
  531. data/third_party/boringssl/crypto/x509/x509rset.c +80 -0
  532. data/third_party/boringssl/crypto/x509/x509spki.c +135 -0
  533. data/third_party/boringssl/crypto/x509/x509type.c +128 -0
  534. data/third_party/boringssl/crypto/x509/x_algor.c +154 -0
  535. data/third_party/boringssl/crypto/x509/x_all.c +547 -0
  536. data/third_party/boringssl/crypto/x509/x_attrib.c +117 -0
  537. data/third_party/boringssl/crypto/x509/x_crl.c +560 -0
  538. data/third_party/boringssl/crypto/x509/x_exten.c +75 -0
  539. data/third_party/boringssl/crypto/x509/x_info.c +95 -0
  540. data/third_party/boringssl/crypto/x509/x_name.c +538 -0
  541. data/third_party/boringssl/crypto/x509/x_pkey.c +100 -0
  542. data/third_party/boringssl/crypto/x509/x_pubkey.c +384 -0
  543. data/third_party/boringssl/crypto/x509/x_req.c +112 -0
  544. data/third_party/boringssl/crypto/x509/x_sig.c +69 -0
  545. data/third_party/boringssl/crypto/x509/x_spki.c +78 -0
  546. data/third_party/boringssl/crypto/x509/x_val.c +69 -0
  547. data/third_party/boringssl/crypto/x509/x_x509.c +227 -0
  548. data/third_party/boringssl/crypto/x509/x_x509a.c +197 -0
  549. data/third_party/boringssl/crypto/x509v3/ext_dat.h +129 -0
  550. data/third_party/boringssl/crypto/x509v3/pcy_cache.c +299 -0
  551. data/third_party/boringssl/crypto/x509v3/pcy_data.c +137 -0
  552. data/third_party/boringssl/crypto/x509v3/pcy_int.h +212 -0
  553. data/third_party/boringssl/crypto/x509v3/pcy_lib.c +165 -0
  554. data/third_party/boringssl/crypto/x509v3/pcy_map.c +133 -0
  555. data/third_party/boringssl/crypto/x509v3/pcy_node.c +197 -0
  556. data/third_party/boringssl/crypto/x509v3/pcy_tree.c +876 -0
  557. data/third_party/boringssl/crypto/x509v3/v3_akey.c +212 -0
  558. data/third_party/boringssl/crypto/x509v3/v3_akeya.c +71 -0
  559. data/third_party/boringssl/crypto/x509v3/v3_alt.c +622 -0
  560. data/third_party/boringssl/crypto/x509v3/v3_bcons.c +126 -0
  561. data/third_party/boringssl/crypto/x509v3/v3_bitst.c +141 -0
  562. data/third_party/boringssl/crypto/x509v3/v3_conf.c +459 -0
  563. data/third_party/boringssl/crypto/x509v3/v3_cpols.c +475 -0
  564. data/third_party/boringssl/crypto/x509v3/v3_crld.c +616 -0
  565. data/third_party/boringssl/crypto/x509v3/v3_enum.c +98 -0
  566. data/third_party/boringssl/crypto/x509v3/v3_extku.c +145 -0
  567. data/third_party/boringssl/crypto/x509v3/v3_genn.c +252 -0
  568. data/third_party/boringssl/crypto/x509v3/v3_ia5.c +117 -0
  569. data/third_party/boringssl/crypto/x509v3/v3_info.c +200 -0
  570. data/third_party/boringssl/crypto/x509v3/v3_int.c +87 -0
  571. data/third_party/boringssl/crypto/x509v3/v3_lib.c +335 -0
  572. data/third_party/boringssl/crypto/x509v3/v3_ncons.c +510 -0
  573. data/third_party/boringssl/crypto/x509v3/v3_pci.c +335 -0
  574. data/third_party/boringssl/crypto/x509v3/v3_pcia.c +56 -0
  575. data/third_party/boringssl/crypto/x509v3/v3_pcons.c +142 -0
  576. data/third_party/boringssl/crypto/x509v3/v3_pku.c +109 -0
  577. data/third_party/boringssl/crypto/x509v3/v3_pmaps.c +156 -0
  578. data/third_party/boringssl/crypto/x509v3/v3_prn.c +207 -0
  579. data/third_party/boringssl/crypto/x509v3/v3_purp.c +805 -0
  580. data/third_party/boringssl/crypto/x509v3/v3_skey.c +148 -0
  581. data/third_party/boringssl/crypto/x509v3/v3_sxnet.c +266 -0
  582. data/third_party/boringssl/crypto/x509v3/v3_utl.c +1322 -0
  583. data/third_party/boringssl/include/openssl/aead.h +346 -0
  584. data/third_party/boringssl/include/openssl/aes.h +158 -0
  585. data/third_party/boringssl/include/openssl/arm_arch.h +127 -0
  586. data/third_party/boringssl/include/openssl/asn1.h +1168 -0
  587. data/third_party/boringssl/include/openssl/asn1_mac.h +75 -0
  588. data/third_party/boringssl/include/openssl/asn1t.h +906 -0
  589. data/third_party/boringssl/include/openssl/base.h +261 -0
  590. data/third_party/boringssl/include/openssl/base64.h +184 -0
  591. data/third_party/boringssl/include/openssl/bio.h +902 -0
  592. data/third_party/boringssl/include/openssl/blowfish.h +93 -0
  593. data/third_party/boringssl/include/openssl/bn.h +885 -0
  594. data/third_party/boringssl/include/openssl/buf.h +118 -0
  595. data/third_party/boringssl/include/openssl/buffer.h +18 -0
  596. data/third_party/boringssl/include/openssl/bytestring.h +360 -0
  597. data/third_party/boringssl/include/openssl/cast.h +96 -0
  598. data/third_party/boringssl/include/openssl/chacha.h +37 -0
  599. data/third_party/boringssl/include/openssl/cipher.h +571 -0
  600. data/third_party/boringssl/include/openssl/cmac.h +76 -0
  601. data/third_party/boringssl/include/openssl/conf.h +145 -0
  602. data/third_party/boringssl/include/openssl/cpu.h +184 -0
  603. data/third_party/boringssl/include/openssl/crypto.h +68 -0
  604. data/third_party/boringssl/include/openssl/curve25519.h +88 -0
  605. data/third_party/boringssl/include/openssl/des.h +177 -0
  606. data/third_party/boringssl/include/openssl/dh.h +238 -0
  607. data/third_party/boringssl/include/openssl/digest.h +258 -0
  608. data/third_party/boringssl/include/openssl/dsa.h +343 -0
  609. data/third_party/boringssl/include/openssl/dtls1.h +16 -0
  610. data/third_party/boringssl/include/openssl/ec.h +355 -0
  611. data/third_party/boringssl/include/openssl/ec_key.h +280 -0
  612. data/third_party/boringssl/include/openssl/ecdh.h +102 -0
  613. data/third_party/boringssl/include/openssl/ecdsa.h +206 -0
  614. data/third_party/boringssl/include/openssl/engine.h +98 -0
  615. data/third_party/boringssl/include/openssl/err.h +487 -0
  616. data/third_party/boringssl/include/openssl/evp.h +750 -0
  617. data/third_party/boringssl/include/openssl/ex_data.h +213 -0
  618. data/third_party/boringssl/include/openssl/hkdf.h +44 -0
  619. data/third_party/boringssl/include/openssl/hmac.h +160 -0
  620. data/third_party/boringssl/include/openssl/lhash.h +192 -0
  621. data/third_party/boringssl/include/openssl/lhash_macros.h +132 -0
  622. data/third_party/boringssl/include/openssl/md4.h +102 -0
  623. data/third_party/boringssl/include/openssl/md5.h +107 -0
  624. data/third_party/boringssl/include/openssl/mem.h +140 -0
  625. data/third_party/boringssl/include/openssl/obj.h +198 -0
  626. data/third_party/boringssl/include/openssl/obj_mac.h +4140 -0
  627. data/third_party/boringssl/include/openssl/objects.h +18 -0
  628. data/third_party/boringssl/include/openssl/opensslfeatures.h +60 -0
  629. data/third_party/boringssl/include/openssl/opensslv.h +18 -0
  630. data/third_party/boringssl/include/openssl/ossl_typ.h +18 -0
  631. data/third_party/boringssl/include/openssl/pem.h +521 -0
  632. data/third_party/boringssl/include/openssl/pkcs12.h +18 -0
  633. data/third_party/boringssl/include/openssl/pkcs7.h +16 -0
  634. data/third_party/boringssl/include/openssl/pkcs8.h +220 -0
  635. data/third_party/boringssl/include/openssl/poly1305.h +51 -0
  636. data/third_party/boringssl/include/openssl/pqueue.h +146 -0
  637. data/third_party/boringssl/include/openssl/rand.h +113 -0
  638. data/third_party/boringssl/include/openssl/rc4.h +90 -0
  639. data/third_party/boringssl/include/openssl/rsa.h +637 -0
  640. data/third_party/boringssl/include/openssl/safestack.h +16 -0
  641. data/third_party/boringssl/include/openssl/sha.h +256 -0
  642. data/third_party/boringssl/include/openssl/srtp.h +18 -0
  643. data/third_party/boringssl/include/openssl/ssl.h +4466 -0
  644. data/third_party/boringssl/include/openssl/ssl3.h +441 -0
  645. data/third_party/boringssl/include/openssl/stack.h +298 -0
  646. data/third_party/boringssl/include/openssl/stack_macros.h +4190 -0
  647. data/third_party/boringssl/include/openssl/thread.h +173 -0
  648. data/third_party/boringssl/include/openssl/time_support.h +90 -0
  649. data/third_party/boringssl/include/openssl/tls1.h +653 -0
  650. data/third_party/boringssl/include/openssl/type_check.h +91 -0
  651. data/third_party/boringssl/include/openssl/x509.h +1258 -0
  652. data/third_party/boringssl/include/openssl/x509_vfy.h +611 -0
  653. data/third_party/boringssl/include/openssl/x509v3.h +798 -0
  654. data/third_party/boringssl/ssl/custom_extensions.c +257 -0
  655. data/third_party/boringssl/ssl/d1_both.c +880 -0
  656. data/third_party/boringssl/ssl/d1_clnt.c +566 -0
  657. data/third_party/boringssl/ssl/d1_lib.c +340 -0
  658. data/third_party/boringssl/ssl/d1_meth.c +130 -0
  659. data/third_party/boringssl/ssl/d1_pkt.c +578 -0
  660. data/third_party/boringssl/ssl/d1_srtp.c +234 -0
  661. data/third_party/boringssl/ssl/d1_srvr.c +485 -0
  662. data/third_party/boringssl/ssl/dtls_record.c +308 -0
  663. data/third_party/boringssl/ssl/internal.h +1276 -0
  664. data/third_party/boringssl/ssl/pqueue/pqueue.c +197 -0
  665. data/third_party/boringssl/ssl/s3_both.c +571 -0
  666. data/third_party/boringssl/ssl/s3_clnt.c +2241 -0
  667. data/third_party/boringssl/ssl/s3_enc.c +494 -0
  668. data/third_party/boringssl/ssl/s3_lib.c +587 -0
  669. data/third_party/boringssl/ssl/s3_meth.c +166 -0
  670. data/third_party/boringssl/ssl/s3_pkt.c +732 -0
  671. data/third_party/boringssl/ssl/s3_srvr.c +2536 -0
  672. data/third_party/boringssl/ssl/ssl_aead_ctx.c +300 -0
  673. data/third_party/boringssl/ssl/ssl_asn1.c +718 -0
  674. data/third_party/boringssl/ssl/ssl_buffer.c +319 -0
  675. data/third_party/boringssl/ssl/ssl_cert.c +539 -0
  676. data/third_party/boringssl/ssl/ssl_cipher.c +2003 -0
  677. data/third_party/boringssl/ssl/ssl_file.c +633 -0
  678. data/third_party/boringssl/ssl/ssl_lib.c +2653 -0
  679. data/third_party/boringssl/ssl/ssl_rsa.c +423 -0
  680. data/third_party/boringssl/ssl/ssl_session.c +764 -0
  681. data/third_party/boringssl/ssl/ssl_stat.c +591 -0
  682. data/third_party/boringssl/ssl/t1_enc.c +708 -0
  683. data/third_party/boringssl/ssl/t1_lib.c +2905 -0
  684. data/third_party/boringssl/ssl/test/async_bio.h +45 -0
  685. data/third_party/boringssl/ssl/test/packeted_bio.h +44 -0
  686. data/third_party/boringssl/ssl/test/scoped_types.h +28 -0
  687. data/third_party/boringssl/ssl/test/test_config.h +108 -0
  688. data/third_party/boringssl/ssl/tls_record.c +342 -0
  689. data/third_party/nanopb/pb.h +547 -0
  690. data/third_party/nanopb/pb_common.c +97 -0
  691. data/third_party/nanopb/pb_common.h +42 -0
  692. data/third_party/nanopb/pb_decode.c +1319 -0
  693. data/third_party/nanopb/pb_decode.h +149 -0
  694. data/third_party/nanopb/pb_encode.c +690 -0
  695. data/third_party/nanopb/pb_encode.h +154 -0
  696. data/third_party/zlib/adler32.c +179 -0
  697. data/third_party/zlib/compress.c +80 -0
  698. data/third_party/zlib/crc32.c +425 -0
  699. data/third_party/zlib/crc32.h +441 -0
  700. data/third_party/zlib/deflate.c +1967 -0
  701. data/third_party/zlib/deflate.h +346 -0
  702. data/third_party/zlib/gzclose.c +25 -0
  703. data/third_party/zlib/gzguts.h +209 -0
  704. data/third_party/zlib/gzlib.c +634 -0
  705. data/third_party/zlib/gzread.c +594 -0
  706. data/third_party/zlib/gzwrite.c +577 -0
  707. data/third_party/zlib/infback.c +640 -0
  708. data/third_party/zlib/inffast.c +340 -0
  709. data/third_party/zlib/inffast.h +11 -0
  710. data/third_party/zlib/inffixed.h +94 -0
  711. data/third_party/zlib/inflate.c +1512 -0
  712. data/third_party/zlib/inflate.h +122 -0
  713. data/third_party/zlib/inftrees.c +306 -0
  714. data/third_party/zlib/inftrees.h +62 -0
  715. data/third_party/zlib/trees.c +1226 -0
  716. data/third_party/zlib/trees.h +128 -0
  717. data/third_party/zlib/uncompr.c +59 -0
  718. data/third_party/zlib/zconf.h +511 -0
  719. data/third_party/zlib/zlib.h +1768 -0
  720. data/third_party/zlib/zutil.c +324 -0
  721. data/third_party/zlib/zutil.h +253 -0
  722. metadata +504 -20
  723. data/Rakefile +0 -63
  724. data/src/ruby/pb/grpc/health/v1alpha/health.rb +0 -29
@@ -0,0 +1,2241 @@
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
+ *
113
+ * Portions of the attached software ("Contribution") are developed by
114
+ * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
115
+ *
116
+ * The Contribution is licensed pursuant to the OpenSSL open source
117
+ * license provided above.
118
+ *
119
+ * ECC cipher suite support in OpenSSL originally written by
120
+ * Vipul Gupta and Sumit Gupta of Sun Microsystems Laboratories.
121
+ *
122
+ */
123
+ /* ====================================================================
124
+ * Copyright 2005 Nokia. All rights reserved.
125
+ *
126
+ * The portions of the attached software ("Contribution") is developed by
127
+ * Nokia Corporation and is licensed pursuant to the OpenSSL open source
128
+ * license.
129
+ *
130
+ * The Contribution, originally written by Mika Kousa and Pasi Eronen of
131
+ * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
132
+ * support (see RFC 4279) to OpenSSL.
133
+ *
134
+ * No patent licenses or other rights except those expressly stated in
135
+ * the OpenSSL open source license shall be deemed granted or received
136
+ * expressly, by implication, estoppel, or otherwise.
137
+ *
138
+ * No assurances are provided by Nokia that the Contribution does not
139
+ * infringe the patent or other intellectual property rights of any third
140
+ * party or that the license provides you with all the necessary rights
141
+ * to make use of the Contribution.
142
+ *
143
+ * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
144
+ * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
145
+ * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
146
+ * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
147
+ * OTHERWISE.
148
+ */
149
+
150
+ #include <openssl/ssl.h>
151
+
152
+ #include <assert.h>
153
+ #include <stdio.h>
154
+ #include <string.h>
155
+
156
+ #include <openssl/bn.h>
157
+ #include <openssl/buf.h>
158
+ #include <openssl/bytestring.h>
159
+ #include <openssl/dh.h>
160
+ #include <openssl/ec_key.h>
161
+ #include <openssl/ecdsa.h>
162
+ #include <openssl/err.h>
163
+ #include <openssl/evp.h>
164
+ #include <openssl/md5.h>
165
+ #include <openssl/mem.h>
166
+ #include <openssl/obj.h>
167
+ #include <openssl/rand.h>
168
+ #include <openssl/x509.h>
169
+ #include <openssl/x509v3.h>
170
+
171
+ #include "internal.h"
172
+ #include "../crypto/dh/internal.h"
173
+
174
+
175
+ int ssl3_connect(SSL *s) {
176
+ BUF_MEM *buf = NULL;
177
+ void (*cb)(const SSL *ssl, int type, int value) = NULL;
178
+ int ret = -1;
179
+ int new_state, state, skip = 0;
180
+
181
+ assert(s->handshake_func == ssl3_connect);
182
+ assert(!s->server);
183
+ assert(!SSL_IS_DTLS(s));
184
+
185
+ ERR_clear_error();
186
+ ERR_clear_system_error();
187
+
188
+ if (s->info_callback != NULL) {
189
+ cb = s->info_callback;
190
+ } else if (s->ctx->info_callback != NULL) {
191
+ cb = s->ctx->info_callback;
192
+ }
193
+
194
+ s->in_handshake++;
195
+
196
+ for (;;) {
197
+ state = s->state;
198
+
199
+ switch (s->state) {
200
+ case SSL_ST_CONNECT:
201
+ if (cb != NULL) {
202
+ cb(s, SSL_CB_HANDSHAKE_START, 1);
203
+ }
204
+
205
+ if (s->init_buf == NULL) {
206
+ buf = BUF_MEM_new();
207
+ if (buf == NULL ||
208
+ !BUF_MEM_grow(buf, SSL3_RT_MAX_PLAIN_LENGTH)) {
209
+ ret = -1;
210
+ goto end;
211
+ }
212
+
213
+ s->init_buf = buf;
214
+ buf = NULL;
215
+ }
216
+
217
+ if (!ssl_init_wbio_buffer(s, 0)) {
218
+ ret = -1;
219
+ goto end;
220
+ }
221
+
222
+ /* don't push the buffering BIO quite yet */
223
+
224
+ if (!ssl3_init_handshake_buffer(s)) {
225
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
226
+ ret = -1;
227
+ goto end;
228
+ }
229
+
230
+ s->state = SSL3_ST_CW_CLNT_HELLO_A;
231
+ s->init_num = 0;
232
+ break;
233
+
234
+ case SSL3_ST_CW_CLNT_HELLO_A:
235
+ case SSL3_ST_CW_CLNT_HELLO_B:
236
+ s->shutdown = 0;
237
+ ret = ssl3_send_client_hello(s);
238
+ if (ret <= 0) {
239
+ goto end;
240
+ }
241
+ s->state = SSL3_ST_CR_SRVR_HELLO_A;
242
+ s->init_num = 0;
243
+
244
+ /* turn on buffering for the next lot of output */
245
+ if (s->bbio != s->wbio) {
246
+ s->wbio = BIO_push(s->bbio, s->wbio);
247
+ }
248
+
249
+ break;
250
+
251
+ case SSL3_ST_CR_SRVR_HELLO_A:
252
+ case SSL3_ST_CR_SRVR_HELLO_B:
253
+ ret = ssl3_get_server_hello(s);
254
+ if (ret <= 0) {
255
+ goto end;
256
+ }
257
+
258
+ if (s->hit) {
259
+ s->state = SSL3_ST_CR_CHANGE;
260
+ if (s->tlsext_ticket_expected) {
261
+ /* receive renewed session ticket */
262
+ s->state = SSL3_ST_CR_SESSION_TICKET_A;
263
+ }
264
+ } else {
265
+ s->state = SSL3_ST_CR_CERT_A;
266
+ }
267
+ s->init_num = 0;
268
+ break;
269
+
270
+ case SSL3_ST_CR_CERT_A:
271
+ case SSL3_ST_CR_CERT_B:
272
+ if (ssl_cipher_has_server_public_key(s->s3->tmp.new_cipher)) {
273
+ ret = ssl3_get_server_certificate(s);
274
+ if (ret <= 0) {
275
+ goto end;
276
+ }
277
+ if (s->s3->tmp.certificate_status_expected) {
278
+ s->state = SSL3_ST_CR_CERT_STATUS_A;
279
+ } else {
280
+ s->state = SSL3_ST_VERIFY_SERVER_CERT;
281
+ }
282
+ } else {
283
+ skip = 1;
284
+ s->state = SSL3_ST_CR_KEY_EXCH_A;
285
+ }
286
+ s->init_num = 0;
287
+ break;
288
+
289
+ case SSL3_ST_VERIFY_SERVER_CERT:
290
+ ret = ssl3_verify_server_cert(s);
291
+ if (ret <= 0) {
292
+ goto end;
293
+ }
294
+
295
+ s->state = SSL3_ST_CR_KEY_EXCH_A;
296
+ s->init_num = 0;
297
+ break;
298
+
299
+ case SSL3_ST_CR_KEY_EXCH_A:
300
+ case SSL3_ST_CR_KEY_EXCH_B:
301
+ ret = ssl3_get_server_key_exchange(s);
302
+ if (ret <= 0) {
303
+ goto end;
304
+ }
305
+ s->state = SSL3_ST_CR_CERT_REQ_A;
306
+ s->init_num = 0;
307
+ break;
308
+
309
+ case SSL3_ST_CR_CERT_REQ_A:
310
+ case SSL3_ST_CR_CERT_REQ_B:
311
+ ret = ssl3_get_certificate_request(s);
312
+ if (ret <= 0) {
313
+ goto end;
314
+ }
315
+ s->state = SSL3_ST_CR_SRVR_DONE_A;
316
+ s->init_num = 0;
317
+ break;
318
+
319
+ case SSL3_ST_CR_SRVR_DONE_A:
320
+ case SSL3_ST_CR_SRVR_DONE_B:
321
+ ret = ssl3_get_server_done(s);
322
+ if (ret <= 0) {
323
+ goto end;
324
+ }
325
+ if (s->s3->tmp.cert_req) {
326
+ s->state = SSL3_ST_CW_CERT_A;
327
+ } else {
328
+ s->state = SSL3_ST_CW_KEY_EXCH_A;
329
+ }
330
+ s->init_num = 0;
331
+
332
+ break;
333
+
334
+ case SSL3_ST_CW_CERT_A:
335
+ case SSL3_ST_CW_CERT_B:
336
+ case SSL3_ST_CW_CERT_C:
337
+ case SSL3_ST_CW_CERT_D:
338
+ ret = ssl3_send_client_certificate(s);
339
+ if (ret <= 0) {
340
+ goto end;
341
+ }
342
+ s->state = SSL3_ST_CW_KEY_EXCH_A;
343
+ s->init_num = 0;
344
+ break;
345
+
346
+ case SSL3_ST_CW_KEY_EXCH_A:
347
+ case SSL3_ST_CW_KEY_EXCH_B:
348
+ ret = ssl3_send_client_key_exchange(s);
349
+ if (ret <= 0) {
350
+ goto end;
351
+ }
352
+ /* For TLS, cert_req is set to 2, so a cert chain
353
+ * of nothing is sent, but no verify packet is sent */
354
+ if (s->s3->tmp.cert_req == 1) {
355
+ s->state = SSL3_ST_CW_CERT_VRFY_A;
356
+ } else {
357
+ s->state = SSL3_ST_CW_CHANGE_A;
358
+ }
359
+
360
+ s->init_num = 0;
361
+ break;
362
+
363
+ case SSL3_ST_CW_CERT_VRFY_A:
364
+ case SSL3_ST_CW_CERT_VRFY_B:
365
+ case SSL3_ST_CW_CERT_VRFY_C:
366
+ ret = ssl3_send_cert_verify(s);
367
+ if (ret <= 0) {
368
+ goto end;
369
+ }
370
+ s->state = SSL3_ST_CW_CHANGE_A;
371
+ s->init_num = 0;
372
+ break;
373
+
374
+ case SSL3_ST_CW_CHANGE_A:
375
+ case SSL3_ST_CW_CHANGE_B:
376
+ ret = ssl3_send_change_cipher_spec(s, SSL3_ST_CW_CHANGE_A,
377
+ SSL3_ST_CW_CHANGE_B);
378
+ if (ret <= 0) {
379
+ goto end;
380
+ }
381
+
382
+ s->state = SSL3_ST_CW_FINISHED_A;
383
+ if (s->s3->tlsext_channel_id_valid) {
384
+ s->state = SSL3_ST_CW_CHANNEL_ID_A;
385
+ }
386
+ if (s->s3->next_proto_neg_seen) {
387
+ s->state = SSL3_ST_CW_NEXT_PROTO_A;
388
+ }
389
+ s->init_num = 0;
390
+
391
+ s->session->cipher = s->s3->tmp.new_cipher;
392
+ if (!s->enc_method->setup_key_block(s) ||
393
+ !s->enc_method->change_cipher_state(
394
+ s, SSL3_CHANGE_CIPHER_CLIENT_WRITE)) {
395
+ ret = -1;
396
+ goto end;
397
+ }
398
+
399
+ break;
400
+
401
+ case SSL3_ST_CW_NEXT_PROTO_A:
402
+ case SSL3_ST_CW_NEXT_PROTO_B:
403
+ ret = ssl3_send_next_proto(s);
404
+ if (ret <= 0) {
405
+ goto end;
406
+ }
407
+
408
+ if (s->s3->tlsext_channel_id_valid) {
409
+ s->state = SSL3_ST_CW_CHANNEL_ID_A;
410
+ } else {
411
+ s->state = SSL3_ST_CW_FINISHED_A;
412
+ }
413
+ break;
414
+
415
+ case SSL3_ST_CW_CHANNEL_ID_A:
416
+ case SSL3_ST_CW_CHANNEL_ID_B:
417
+ ret = ssl3_send_channel_id(s);
418
+ if (ret <= 0) {
419
+ goto end;
420
+ }
421
+ s->state = SSL3_ST_CW_FINISHED_A;
422
+ break;
423
+
424
+ case SSL3_ST_CW_FINISHED_A:
425
+ case SSL3_ST_CW_FINISHED_B:
426
+ ret =
427
+ ssl3_send_finished(s, SSL3_ST_CW_FINISHED_A, SSL3_ST_CW_FINISHED_B,
428
+ s->enc_method->client_finished_label,
429
+ s->enc_method->client_finished_label_len);
430
+ if (ret <= 0) {
431
+ goto end;
432
+ }
433
+ s->state = SSL3_ST_CW_FLUSH;
434
+
435
+ if (s->hit) {
436
+ s->s3->tmp.next_state = SSL_ST_OK;
437
+ } else {
438
+ /* This is a non-resumption handshake. If it involves ChannelID, then
439
+ * record the handshake hashes at this point in the session so that
440
+ * any resumption of this session with ChannelID can sign those
441
+ * hashes. */
442
+ ret = tls1_record_handshake_hashes_for_channel_id(s);
443
+ if (ret <= 0) {
444
+ goto end;
445
+ }
446
+ if ((SSL_get_mode(s) & SSL_MODE_ENABLE_FALSE_START) &&
447
+ ssl3_can_false_start(s) &&
448
+ /* No False Start on renegotiation (would complicate the state
449
+ * machine). */
450
+ !s->s3->initial_handshake_complete) {
451
+ s->s3->tmp.next_state = SSL3_ST_FALSE_START;
452
+ } else {
453
+ /* Allow NewSessionTicket if ticket expected */
454
+ if (s->tlsext_ticket_expected) {
455
+ s->s3->tmp.next_state = SSL3_ST_CR_SESSION_TICKET_A;
456
+ } else {
457
+ s->s3->tmp.next_state = SSL3_ST_CR_CHANGE;
458
+ }
459
+ }
460
+ }
461
+ s->init_num = 0;
462
+ break;
463
+
464
+ case SSL3_ST_CR_SESSION_TICKET_A:
465
+ case SSL3_ST_CR_SESSION_TICKET_B:
466
+ ret = ssl3_get_new_session_ticket(s);
467
+ if (ret <= 0) {
468
+ goto end;
469
+ }
470
+ s->state = SSL3_ST_CR_CHANGE;
471
+ s->init_num = 0;
472
+ break;
473
+
474
+ case SSL3_ST_CR_CERT_STATUS_A:
475
+ case SSL3_ST_CR_CERT_STATUS_B:
476
+ ret = ssl3_get_cert_status(s);
477
+ if (ret <= 0) {
478
+ goto end;
479
+ }
480
+ s->state = SSL3_ST_VERIFY_SERVER_CERT;
481
+ s->init_num = 0;
482
+ break;
483
+
484
+ case SSL3_ST_CR_CHANGE:
485
+ ret = s->method->ssl_read_change_cipher_spec(s);
486
+ if (ret <= 0) {
487
+ goto end;
488
+ }
489
+
490
+ if (!ssl3_do_change_cipher_spec(s)) {
491
+ ret = -1;
492
+ goto end;
493
+ }
494
+ s->state = SSL3_ST_CR_FINISHED_A;
495
+ break;
496
+
497
+ case SSL3_ST_CR_FINISHED_A:
498
+ case SSL3_ST_CR_FINISHED_B:
499
+ ret =
500
+ ssl3_get_finished(s, SSL3_ST_CR_FINISHED_A, SSL3_ST_CR_FINISHED_B);
501
+ if (ret <= 0) {
502
+ goto end;
503
+ }
504
+
505
+ if (s->hit) {
506
+ s->state = SSL3_ST_CW_CHANGE_A;
507
+ } else {
508
+ s->state = SSL_ST_OK;
509
+ }
510
+ s->init_num = 0;
511
+ break;
512
+
513
+ case SSL3_ST_CW_FLUSH:
514
+ s->rwstate = SSL_WRITING;
515
+ if (BIO_flush(s->wbio) <= 0) {
516
+ ret = -1;
517
+ goto end;
518
+ }
519
+ s->rwstate = SSL_NOTHING;
520
+ s->state = s->s3->tmp.next_state;
521
+ break;
522
+
523
+ case SSL3_ST_FALSE_START:
524
+ /* Allow NewSessionTicket if ticket expected */
525
+ if (s->tlsext_ticket_expected) {
526
+ s->state = SSL3_ST_CR_SESSION_TICKET_A;
527
+ } else {
528
+ s->state = SSL3_ST_CR_CHANGE;
529
+ }
530
+ s->s3->tmp.in_false_start = 1;
531
+
532
+ ssl_free_wbio_buffer(s);
533
+ ret = 1;
534
+ goto end;
535
+
536
+ case SSL_ST_OK:
537
+ /* clean a few things up */
538
+ ssl3_cleanup_key_block(s);
539
+
540
+ BUF_MEM_free(s->init_buf);
541
+ s->init_buf = NULL;
542
+
543
+ /* Remove write buffering now. */
544
+ ssl_free_wbio_buffer(s);
545
+
546
+ const int is_initial_handshake = !s->s3->initial_handshake_complete;
547
+
548
+ s->init_num = 0;
549
+ s->s3->tmp.in_false_start = 0;
550
+ s->s3->initial_handshake_complete = 1;
551
+
552
+ if (is_initial_handshake) {
553
+ /* Renegotiations do not participate in session resumption. */
554
+ ssl_update_cache(s, SSL_SESS_CACHE_CLIENT);
555
+ }
556
+
557
+ ret = 1;
558
+ /* s->server=0; */
559
+
560
+ if (cb != NULL) {
561
+ cb(s, SSL_CB_HANDSHAKE_DONE, 1);
562
+ }
563
+
564
+ goto end;
565
+
566
+ default:
567
+ OPENSSL_PUT_ERROR(SSL, SSL_R_UNKNOWN_STATE);
568
+ ret = -1;
569
+ goto end;
570
+ }
571
+
572
+ if (!s->s3->tmp.reuse_message && !skip) {
573
+ if (cb != NULL && s->state != state) {
574
+ new_state = s->state;
575
+ s->state = state;
576
+ cb(s, SSL_CB_CONNECT_LOOP, 1);
577
+ s->state = new_state;
578
+ }
579
+ }
580
+ skip = 0;
581
+ }
582
+
583
+ end:
584
+ s->in_handshake--;
585
+ BUF_MEM_free(buf);
586
+ if (cb != NULL) {
587
+ cb(s, SSL_CB_CONNECT_EXIT, ret);
588
+ }
589
+ return ret;
590
+ }
591
+
592
+ static int ssl3_write_client_cipher_list(SSL *ssl, CBB *out) {
593
+ /* Prepare disabled cipher masks. */
594
+ ssl_set_client_disabled(ssl);
595
+
596
+ CBB child;
597
+ if (!CBB_add_u16_length_prefixed(out, &child)) {
598
+ return 0;
599
+ }
600
+
601
+ STACK_OF(SSL_CIPHER) *ciphers = SSL_get_ciphers(ssl);
602
+
603
+ int any_enabled = 0;
604
+ size_t i;
605
+ for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) {
606
+ const SSL_CIPHER *cipher = sk_SSL_CIPHER_value(ciphers, i);
607
+ /* Skip disabled ciphers */
608
+ if ((cipher->algorithm_mkey & ssl->cert->mask_k) ||
609
+ (cipher->algorithm_auth & ssl->cert->mask_a)) {
610
+ continue;
611
+ }
612
+ if (SSL_CIPHER_get_min_version(cipher) >
613
+ ssl3_version_from_wire(ssl, ssl->client_version)) {
614
+ continue;
615
+ }
616
+ any_enabled = 1;
617
+ if (!CBB_add_u16(&child, ssl_cipher_get_value(cipher))) {
618
+ return 0;
619
+ }
620
+ }
621
+
622
+ /* If all ciphers were disabled, return the error to the caller. */
623
+ if (!any_enabled) {
624
+ OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CIPHERS_AVAILABLE);
625
+ return 0;
626
+ }
627
+
628
+ /* For SSLv3, the SCSV is added. Otherwise the renegotiation extension is
629
+ * added. */
630
+ if (ssl->client_version == SSL3_VERSION &&
631
+ !ssl->s3->initial_handshake_complete) {
632
+ if (!CBB_add_u16(&child, SSL3_CK_SCSV & 0xffff)) {
633
+ return 0;
634
+ }
635
+ /* The renegotiation extension is required to be at index zero. */
636
+ ssl->s3->tmp.extensions.sent |= (1u << 0);
637
+ }
638
+
639
+ if ((ssl->mode & SSL_MODE_SEND_FALLBACK_SCSV) &&
640
+ !CBB_add_u16(&child, SSL3_CK_FALLBACK_SCSV & 0xffff)) {
641
+ return 0;
642
+ }
643
+
644
+ return CBB_flush(out);
645
+ }
646
+
647
+ int ssl3_send_client_hello(SSL *ssl) {
648
+ if (ssl->state == SSL3_ST_CW_CLNT_HELLO_B) {
649
+ return ssl_do_write(ssl);
650
+ }
651
+
652
+ /* In DTLS, reset the handshake buffer each time a new ClientHello is
653
+ * assembled. We may send multiple if we receive HelloVerifyRequest. */
654
+ if (SSL_IS_DTLS(ssl) && !ssl3_init_handshake_buffer(ssl)) {
655
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
656
+ return -1;
657
+ }
658
+
659
+ CBB cbb;
660
+ CBB_zero(&cbb);
661
+
662
+ assert(ssl->state == SSL3_ST_CW_CLNT_HELLO_A);
663
+ if (!ssl->s3->have_version) {
664
+ uint16_t max_version = ssl3_get_max_client_version(ssl);
665
+ /* Disabling all versions is silly: return an error. */
666
+ if (max_version == 0) {
667
+ OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_SSL_VERSION);
668
+ goto err;
669
+ }
670
+
671
+ ssl->version = max_version;
672
+ /* Only set |ssl->client_version| on the initial handshake. Renegotiations,
673
+ * although locked to a version, reuse the value. When using the plain RSA
674
+ * key exchange, the ClientHello version is checked in the premaster secret.
675
+ * Some servers fail when this value changes. */
676
+ ssl->client_version = max_version;
677
+ }
678
+
679
+ /* If the configured session has expired or was created at a version higher
680
+ * than our maximum version, drop it. */
681
+ if (ssl->session != NULL &&
682
+ (ssl->session->session_id_length == 0 || ssl->session->not_resumable ||
683
+ ssl->session->timeout < (long)(time(NULL) - ssl->session->time) ||
684
+ (!SSL_IS_DTLS(ssl) && ssl->session->ssl_version > ssl->version) ||
685
+ (SSL_IS_DTLS(ssl) && ssl->session->ssl_version < ssl->version))) {
686
+ SSL_set_session(ssl, NULL);
687
+ }
688
+
689
+ /* If resending the ClientHello in DTLS after a HelloVerifyRequest, don't
690
+ * renegerate the client_random. The random must be reused. */
691
+ if ((!SSL_IS_DTLS(ssl) || !ssl->d1->send_cookie) &&
692
+ !ssl_fill_hello_random(ssl->s3->client_random,
693
+ sizeof(ssl->s3->client_random), 0 /* client */)) {
694
+ goto err;
695
+ }
696
+
697
+ /* Renegotiations do not participate in session resumption. */
698
+ int has_session = ssl->session != NULL &&
699
+ !ssl->s3->initial_handshake_complete;
700
+
701
+ CBB child;
702
+ if (!CBB_init_fixed(&cbb, ssl_handshake_start(ssl),
703
+ ssl->init_buf->max - SSL_HM_HEADER_LENGTH(ssl)) ||
704
+ !CBB_add_u16(&cbb, ssl->client_version) ||
705
+ !CBB_add_bytes(&cbb, ssl->s3->client_random, SSL3_RANDOM_SIZE) ||
706
+ !CBB_add_u8_length_prefixed(&cbb, &child) ||
707
+ (has_session &&
708
+ !CBB_add_bytes(&child, ssl->session->session_id,
709
+ ssl->session->session_id_length))) {
710
+ goto err;
711
+ }
712
+
713
+ if (SSL_IS_DTLS(ssl)) {
714
+ if (!CBB_add_u8_length_prefixed(&cbb, &child) ||
715
+ !CBB_add_bytes(&child, ssl->d1->cookie, ssl->d1->cookie_len)) {
716
+ goto err;
717
+ }
718
+ }
719
+
720
+ size_t length;
721
+ if (!ssl3_write_client_cipher_list(ssl, &cbb) ||
722
+ !CBB_add_u8(&cbb, 1 /* one compression method */) ||
723
+ !CBB_add_u8(&cbb, 0 /* null compression */) ||
724
+ !ssl_add_clienthello_tlsext(ssl, &cbb,
725
+ CBB_len(&cbb) + SSL_HM_HEADER_LENGTH(ssl)) ||
726
+ !CBB_finish(&cbb, NULL, &length) ||
727
+ !ssl_set_handshake_header(ssl, SSL3_MT_CLIENT_HELLO, length)) {
728
+ goto err;
729
+ }
730
+
731
+ ssl->state = SSL3_ST_CW_CLNT_HELLO_B;
732
+ return ssl_do_write(ssl);
733
+
734
+ err:
735
+ CBB_cleanup(&cbb);
736
+ return -1;
737
+ }
738
+
739
+ int ssl3_get_server_hello(SSL *s) {
740
+ STACK_OF(SSL_CIPHER) *sk;
741
+ const SSL_CIPHER *c;
742
+ CERT *ct = s->cert;
743
+ int al = SSL_AD_INTERNAL_ERROR, ok;
744
+ long n;
745
+ CBS server_hello, server_random, session_id;
746
+ uint16_t server_version, cipher_suite;
747
+ uint8_t compression_method;
748
+
749
+ n = s->method->ssl_get_message(s, SSL3_ST_CR_SRVR_HELLO_A,
750
+ SSL3_ST_CR_SRVR_HELLO_B, SSL3_MT_SERVER_HELLO,
751
+ 20000, /* ?? */
752
+ ssl_hash_message, &ok);
753
+
754
+ if (!ok) {
755
+ uint32_t err = ERR_peek_error();
756
+ if (ERR_GET_LIB(err) == ERR_LIB_SSL &&
757
+ ERR_GET_REASON(err) == SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE) {
758
+ /* Add a dedicated error code to the queue for a handshake_failure alert
759
+ * in response to ClientHello. This matches NSS's client behavior and
760
+ * gives a better error on a (probable) failure to negotiate initial
761
+ * parameters. Note: this error code comes after the original one.
762
+ *
763
+ * See https://crbug.com/446505. */
764
+ OPENSSL_PUT_ERROR(SSL, SSL_R_HANDSHAKE_FAILURE_ON_CLIENT_HELLO);
765
+ }
766
+ return n;
767
+ }
768
+
769
+ CBS_init(&server_hello, s->init_msg, n);
770
+
771
+ if (!CBS_get_u16(&server_hello, &server_version) ||
772
+ !CBS_get_bytes(&server_hello, &server_random, SSL3_RANDOM_SIZE) ||
773
+ !CBS_get_u8_length_prefixed(&server_hello, &session_id) ||
774
+ CBS_len(&session_id) > SSL3_SESSION_ID_SIZE ||
775
+ !CBS_get_u16(&server_hello, &cipher_suite) ||
776
+ !CBS_get_u8(&server_hello, &compression_method)) {
777
+ al = SSL_AD_DECODE_ERROR;
778
+ OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
779
+ goto f_err;
780
+ }
781
+
782
+ assert(s->s3->have_version == s->s3->initial_handshake_complete);
783
+ if (!s->s3->have_version) {
784
+ if (!ssl3_is_version_enabled(s, server_version)) {
785
+ OPENSSL_PUT_ERROR(SSL, SSL_R_UNSUPPORTED_PROTOCOL);
786
+ s->version = server_version;
787
+ /* Mark the version as fixed so the record-layer version is not clamped
788
+ * to TLS 1.0. */
789
+ s->s3->have_version = 1;
790
+ al = SSL_AD_PROTOCOL_VERSION;
791
+ goto f_err;
792
+ }
793
+ s->version = server_version;
794
+ s->enc_method = ssl3_get_enc_method(server_version);
795
+ assert(s->enc_method != NULL);
796
+ /* At this point, the connection's version is known and s->version is
797
+ * fixed. Begin enforcing the record-layer version. */
798
+ s->s3->have_version = 1;
799
+ } else if (server_version != s->version) {
800
+ OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_SSL_VERSION);
801
+ al = SSL_AD_PROTOCOL_VERSION;
802
+ goto f_err;
803
+ }
804
+
805
+ /* Copy over the server random. */
806
+ memcpy(s->s3->server_random, CBS_data(&server_random), SSL3_RANDOM_SIZE);
807
+
808
+ assert(s->session == NULL || s->session->session_id_length > 0);
809
+ if (!s->s3->initial_handshake_complete && s->session != NULL &&
810
+ CBS_mem_equal(&session_id, s->session->session_id,
811
+ s->session->session_id_length)) {
812
+ if (s->sid_ctx_length != s->session->sid_ctx_length ||
813
+ memcmp(s->session->sid_ctx, s->sid_ctx, s->sid_ctx_length)) {
814
+ /* actually a client application bug */
815
+ al = SSL_AD_ILLEGAL_PARAMETER;
816
+ OPENSSL_PUT_ERROR(SSL,
817
+ SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT);
818
+ goto f_err;
819
+ }
820
+ s->hit = 1;
821
+ } else {
822
+ /* The session wasn't resumed. Create a fresh SSL_SESSION to
823
+ * fill out. */
824
+ s->hit = 0;
825
+ if (!ssl_get_new_session(s, 0 /* client */)) {
826
+ goto f_err;
827
+ }
828
+ /* Note: session_id could be empty. */
829
+ s->session->session_id_length = CBS_len(&session_id);
830
+ memcpy(s->session->session_id, CBS_data(&session_id), CBS_len(&session_id));
831
+ }
832
+
833
+ c = SSL_get_cipher_by_value(cipher_suite);
834
+ if (c == NULL) {
835
+ /* unknown cipher */
836
+ al = SSL_AD_ILLEGAL_PARAMETER;
837
+ OPENSSL_PUT_ERROR(SSL, SSL_R_UNKNOWN_CIPHER_RETURNED);
838
+ goto f_err;
839
+ }
840
+ /* If the cipher is disabled then we didn't sent it in the ClientHello, so if
841
+ * the server selected it, it's an error. */
842
+ if ((c->algorithm_mkey & ct->mask_k) ||
843
+ (c->algorithm_auth & ct->mask_a) ||
844
+ SSL_CIPHER_get_min_version(c) > ssl3_version_from_wire(s, s->version)) {
845
+ al = SSL_AD_ILLEGAL_PARAMETER;
846
+ OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CIPHER_RETURNED);
847
+ goto f_err;
848
+ }
849
+
850
+ sk = ssl_get_ciphers_by_id(s);
851
+ if (!sk_SSL_CIPHER_find(sk, NULL, c)) {
852
+ /* we did not say we would use this cipher */
853
+ al = SSL_AD_ILLEGAL_PARAMETER;
854
+ OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CIPHER_RETURNED);
855
+ goto f_err;
856
+ }
857
+
858
+ if (s->hit) {
859
+ if (s->session->cipher != c) {
860
+ al = SSL_AD_ILLEGAL_PARAMETER;
861
+ OPENSSL_PUT_ERROR(SSL, SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED);
862
+ goto f_err;
863
+ }
864
+ if (s->session->ssl_version != s->version) {
865
+ al = SSL_AD_ILLEGAL_PARAMETER;
866
+ OPENSSL_PUT_ERROR(SSL, SSL_R_OLD_SESSION_VERSION_NOT_RETURNED);
867
+ goto f_err;
868
+ }
869
+ }
870
+ s->s3->tmp.new_cipher = c;
871
+
872
+ /* Now that the cipher is known, initialize the handshake hash. */
873
+ if (!ssl3_init_handshake_hash(s)) {
874
+ goto f_err;
875
+ }
876
+
877
+ /* If doing a full handshake with TLS 1.2, the server may request a client
878
+ * certificate which requires hashing the handshake transcript under a
879
+ * different hash. Otherwise, the handshake buffer may be released. */
880
+ if (!SSL_USE_SIGALGS(s) || s->hit) {
881
+ ssl3_free_handshake_buffer(s);
882
+ }
883
+
884
+ /* Only the NULL compression algorithm is supported. */
885
+ if (compression_method != 0) {
886
+ al = SSL_AD_ILLEGAL_PARAMETER;
887
+ OPENSSL_PUT_ERROR(SSL, SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM);
888
+ goto f_err;
889
+ }
890
+
891
+ /* TLS extensions */
892
+ if (!ssl_parse_serverhello_tlsext(s, &server_hello)) {
893
+ OPENSSL_PUT_ERROR(SSL, SSL_R_PARSE_TLSEXT);
894
+ goto err;
895
+ }
896
+
897
+ /* There should be nothing left over in the record. */
898
+ if (CBS_len(&server_hello) != 0) {
899
+ /* wrong packet length */
900
+ al = SSL_AD_DECODE_ERROR;
901
+ OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_PACKET_LENGTH);
902
+ goto f_err;
903
+ }
904
+
905
+ if (s->hit &&
906
+ s->s3->tmp.extended_master_secret != s->session->extended_master_secret) {
907
+ al = SSL_AD_HANDSHAKE_FAILURE;
908
+ if (s->session->extended_master_secret) {
909
+ OPENSSL_PUT_ERROR(SSL, SSL_R_RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION);
910
+ } else {
911
+ OPENSSL_PUT_ERROR(SSL, SSL_R_RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION);
912
+ }
913
+ goto f_err;
914
+ }
915
+
916
+ return 1;
917
+
918
+ f_err:
919
+ ssl3_send_alert(s, SSL3_AL_FATAL, al);
920
+ err:
921
+ return -1;
922
+ }
923
+
924
+ /* ssl3_check_leaf_certificate returns one if |leaf| is a suitable leaf server
925
+ * certificate for |ssl|. Otherwise, it returns zero and pushes an error on the
926
+ * error queue. */
927
+ static int ssl3_check_leaf_certificate(SSL *ssl, X509 *leaf) {
928
+ int ret = 0;
929
+ EVP_PKEY *pkey = X509_get_pubkey(leaf);
930
+ if (pkey == NULL) {
931
+ goto err;
932
+ }
933
+
934
+ /* Check the certificate's type matches the cipher. */
935
+ const SSL_CIPHER *cipher = ssl->s3->tmp.new_cipher;
936
+ int expected_type = ssl_cipher_get_key_type(cipher);
937
+ assert(expected_type != EVP_PKEY_NONE);
938
+ if (pkey->type != expected_type) {
939
+ OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CERTIFICATE_TYPE);
940
+ goto err;
941
+ }
942
+
943
+ if (cipher->algorithm_auth & SSL_aECDSA) {
944
+ /* TODO(davidben): This behavior is preserved from upstream. Should key
945
+ * usages be checked in other cases as well? */
946
+ /* This call populates the ex_flags field correctly */
947
+ X509_check_purpose(leaf, -1, 0);
948
+ if ((leaf->ex_flags & EXFLAG_KUSAGE) &&
949
+ !(leaf->ex_kusage & X509v3_KU_DIGITAL_SIGNATURE)) {
950
+ OPENSSL_PUT_ERROR(SSL, SSL_R_ECC_CERT_NOT_FOR_SIGNING);
951
+ goto err;
952
+ }
953
+
954
+ if (!tls1_check_ec_cert(ssl, leaf)) {
955
+ OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_ECC_CERT);
956
+ goto err;
957
+ }
958
+ }
959
+
960
+ ret = 1;
961
+
962
+ err:
963
+ EVP_PKEY_free(pkey);
964
+ return ret;
965
+ }
966
+
967
+ int ssl3_get_server_certificate(SSL *s) {
968
+ int al, ok, ret = -1;
969
+ unsigned long n;
970
+ X509 *x = NULL;
971
+ STACK_OF(X509) *sk = NULL;
972
+ EVP_PKEY *pkey = NULL;
973
+ CBS cbs, certificate_list;
974
+ const uint8_t *data;
975
+
976
+ n = s->method->ssl_get_message(s, SSL3_ST_CR_CERT_A, SSL3_ST_CR_CERT_B,
977
+ SSL3_MT_CERTIFICATE, (long)s->max_cert_list,
978
+ ssl_hash_message, &ok);
979
+
980
+ if (!ok) {
981
+ return n;
982
+ }
983
+
984
+ CBS_init(&cbs, s->init_msg, n);
985
+
986
+ sk = sk_X509_new_null();
987
+ if (sk == NULL) {
988
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
989
+ goto err;
990
+ }
991
+
992
+ if (!CBS_get_u24_length_prefixed(&cbs, &certificate_list) ||
993
+ CBS_len(&certificate_list) == 0 ||
994
+ CBS_len(&cbs) != 0) {
995
+ al = SSL_AD_DECODE_ERROR;
996
+ OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
997
+ goto f_err;
998
+ }
999
+
1000
+ while (CBS_len(&certificate_list) > 0) {
1001
+ CBS certificate;
1002
+ if (!CBS_get_u24_length_prefixed(&certificate_list, &certificate)) {
1003
+ al = SSL_AD_DECODE_ERROR;
1004
+ OPENSSL_PUT_ERROR(SSL, SSL_R_CERT_LENGTH_MISMATCH);
1005
+ goto f_err;
1006
+ }
1007
+ /* A u24 length cannot overflow a long. */
1008
+ data = CBS_data(&certificate);
1009
+ x = d2i_X509(NULL, &data, (long)CBS_len(&certificate));
1010
+ if (x == NULL) {
1011
+ al = SSL_AD_BAD_CERTIFICATE;
1012
+ OPENSSL_PUT_ERROR(SSL, ERR_R_ASN1_LIB);
1013
+ goto f_err;
1014
+ }
1015
+ if (data != CBS_data(&certificate) + CBS_len(&certificate)) {
1016
+ al = SSL_AD_DECODE_ERROR;
1017
+ OPENSSL_PUT_ERROR(SSL, SSL_R_CERT_LENGTH_MISMATCH);
1018
+ goto f_err;
1019
+ }
1020
+ if (!sk_X509_push(sk, x)) {
1021
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1022
+ goto err;
1023
+ }
1024
+ x = NULL;
1025
+ }
1026
+
1027
+ X509 *leaf = sk_X509_value(sk, 0);
1028
+ if (!ssl3_check_leaf_certificate(s, leaf)) {
1029
+ al = SSL_AD_ILLEGAL_PARAMETER;
1030
+ goto f_err;
1031
+ }
1032
+
1033
+ /* NOTE: Unlike the server half, the client's copy of |cert_chain| includes
1034
+ * the leaf. */
1035
+ sk_X509_pop_free(s->session->cert_chain, X509_free);
1036
+ s->session->cert_chain = sk;
1037
+ sk = NULL;
1038
+
1039
+ X509_free(s->session->peer);
1040
+ s->session->peer = X509_up_ref(leaf);
1041
+
1042
+ s->session->verify_result = s->verify_result;
1043
+
1044
+ ret = 1;
1045
+
1046
+ if (0) {
1047
+ f_err:
1048
+ ssl3_send_alert(s, SSL3_AL_FATAL, al);
1049
+ }
1050
+
1051
+ err:
1052
+ EVP_PKEY_free(pkey);
1053
+ X509_free(x);
1054
+ sk_X509_pop_free(sk, X509_free);
1055
+ return ret;
1056
+ }
1057
+
1058
+ int ssl3_get_server_key_exchange(SSL *s) {
1059
+ EVP_MD_CTX md_ctx;
1060
+ int al, ok;
1061
+ long n, alg_k, alg_a;
1062
+ EVP_PKEY *pkey = NULL;
1063
+ const EVP_MD *md = NULL;
1064
+ RSA *rsa = NULL;
1065
+ DH *dh = NULL;
1066
+ EC_KEY *ecdh = NULL;
1067
+ BN_CTX *bn_ctx = NULL;
1068
+ EC_POINT *srvr_ecpoint = NULL;
1069
+ CBS server_key_exchange, server_key_exchange_orig, parameter;
1070
+
1071
+ /* use same message size as in ssl3_get_certificate_request() as
1072
+ * ServerKeyExchange message may be skipped */
1073
+ n = s->method->ssl_get_message(s, SSL3_ST_CR_KEY_EXCH_A,
1074
+ SSL3_ST_CR_KEY_EXCH_B, -1, s->max_cert_list,
1075
+ ssl_hash_message, &ok);
1076
+ if (!ok) {
1077
+ return n;
1078
+ }
1079
+
1080
+ if (s->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE) {
1081
+ if (ssl_cipher_requires_server_key_exchange(s->s3->tmp.new_cipher)) {
1082
+ OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_MESSAGE);
1083
+ ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
1084
+ return -1;
1085
+ }
1086
+
1087
+ /* In plain PSK ciphersuite, ServerKeyExchange may be omitted to send no
1088
+ * identity hint. */
1089
+ if (s->s3->tmp.new_cipher->algorithm_auth & SSL_aPSK) {
1090
+ /* TODO(davidben): This should be reset in one place with the rest of the
1091
+ * handshake state. */
1092
+ OPENSSL_free(s->s3->tmp.peer_psk_identity_hint);
1093
+ s->s3->tmp.peer_psk_identity_hint = NULL;
1094
+ }
1095
+ s->s3->tmp.reuse_message = 1;
1096
+ return 1;
1097
+ }
1098
+
1099
+ /* Retain a copy of the original CBS to compute the signature over. */
1100
+ CBS_init(&server_key_exchange, s->init_msg, n);
1101
+ server_key_exchange_orig = server_key_exchange;
1102
+
1103
+ alg_k = s->s3->tmp.new_cipher->algorithm_mkey;
1104
+ alg_a = s->s3->tmp.new_cipher->algorithm_auth;
1105
+ EVP_MD_CTX_init(&md_ctx);
1106
+
1107
+ if (alg_a & SSL_aPSK) {
1108
+ CBS psk_identity_hint;
1109
+
1110
+ /* Each of the PSK key exchanges begins with a psk_identity_hint. */
1111
+ if (!CBS_get_u16_length_prefixed(&server_key_exchange,
1112
+ &psk_identity_hint)) {
1113
+ al = SSL_AD_DECODE_ERROR;
1114
+ OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
1115
+ goto f_err;
1116
+ }
1117
+
1118
+ /* Store PSK identity hint for later use, hint is used in
1119
+ * ssl3_send_client_key_exchange. Assume that the maximum length of a PSK
1120
+ * identity hint can be as long as the maximum length of a PSK identity.
1121
+ * Also do not allow NULL characters; identities are saved as C strings.
1122
+ *
1123
+ * TODO(davidben): Should invalid hints be ignored? It's a hint rather than
1124
+ * a specific identity. */
1125
+ if (CBS_len(&psk_identity_hint) > PSK_MAX_IDENTITY_LEN ||
1126
+ CBS_contains_zero_byte(&psk_identity_hint)) {
1127
+ al = SSL_AD_HANDSHAKE_FAILURE;
1128
+ OPENSSL_PUT_ERROR(SSL, SSL_R_DATA_LENGTH_TOO_LONG);
1129
+ goto f_err;
1130
+ }
1131
+
1132
+ /* Save the identity hint as a C string. */
1133
+ if (!CBS_strdup(&psk_identity_hint, &s->s3->tmp.peer_psk_identity_hint)) {
1134
+ al = SSL_AD_INTERNAL_ERROR;
1135
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1136
+ goto f_err;
1137
+ }
1138
+ }
1139
+
1140
+ if (alg_k & SSL_kDHE) {
1141
+ CBS dh_p, dh_g, dh_Ys;
1142
+
1143
+ if (!CBS_get_u16_length_prefixed(&server_key_exchange, &dh_p) ||
1144
+ CBS_len(&dh_p) == 0 ||
1145
+ !CBS_get_u16_length_prefixed(&server_key_exchange, &dh_g) ||
1146
+ CBS_len(&dh_g) == 0 ||
1147
+ !CBS_get_u16_length_prefixed(&server_key_exchange, &dh_Ys) ||
1148
+ CBS_len(&dh_Ys) == 0) {
1149
+ al = SSL_AD_DECODE_ERROR;
1150
+ OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
1151
+ goto f_err;
1152
+ }
1153
+
1154
+ dh = DH_new();
1155
+ if (dh == NULL) {
1156
+ OPENSSL_PUT_ERROR(SSL, ERR_R_DH_LIB);
1157
+ goto err;
1158
+ }
1159
+
1160
+ if ((dh->p = BN_bin2bn(CBS_data(&dh_p), CBS_len(&dh_p), NULL)) == NULL ||
1161
+ (dh->g = BN_bin2bn(CBS_data(&dh_g), CBS_len(&dh_g), NULL)) == NULL ||
1162
+ (dh->pub_key = BN_bin2bn(CBS_data(&dh_Ys), CBS_len(&dh_Ys), NULL)) ==
1163
+ NULL) {
1164
+ OPENSSL_PUT_ERROR(SSL, ERR_R_BN_LIB);
1165
+ goto err;
1166
+ }
1167
+
1168
+ s->session->key_exchange_info = DH_num_bits(dh);
1169
+ if (s->session->key_exchange_info < 1024) {
1170
+ OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_DH_P_LENGTH);
1171
+ goto err;
1172
+ }
1173
+ if (s->session->key_exchange_info > 4096) {
1174
+ /* Overly large DHE groups are prohibitively expensive, so enforce a limit
1175
+ * to prevent a server from causing us to perform too expensive of a
1176
+ * computation. */
1177
+ OPENSSL_PUT_ERROR(SSL, SSL_R_DH_P_TOO_LONG);
1178
+ goto err;
1179
+ }
1180
+ DH_free(s->s3->tmp.peer_dh_tmp);
1181
+ s->s3->tmp.peer_dh_tmp = dh;
1182
+ dh = NULL;
1183
+ } else if (alg_k & SSL_kECDHE) {
1184
+ uint16_t curve_id;
1185
+ int curve_nid = 0;
1186
+ const EC_GROUP *group;
1187
+ CBS point;
1188
+
1189
+ /* Extract elliptic curve parameters and the server's ephemeral ECDH public
1190
+ * key. Check curve is one of our preferences, if not server has sent an
1191
+ * invalid curve. */
1192
+ if (!tls1_check_curve(s, &server_key_exchange, &curve_id)) {
1193
+ al = SSL_AD_DECODE_ERROR;
1194
+ OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CURVE);
1195
+ goto f_err;
1196
+ }
1197
+
1198
+ curve_nid = tls1_ec_curve_id2nid(curve_id);
1199
+ if (curve_nid == 0) {
1200
+ al = SSL_AD_INTERNAL_ERROR;
1201
+ OPENSSL_PUT_ERROR(SSL, SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS);
1202
+ goto f_err;
1203
+ }
1204
+
1205
+ ecdh = EC_KEY_new_by_curve_name(curve_nid);
1206
+ s->session->key_exchange_info = curve_id;
1207
+ if (ecdh == NULL) {
1208
+ OPENSSL_PUT_ERROR(SSL, ERR_R_EC_LIB);
1209
+ goto err;
1210
+ }
1211
+
1212
+ group = EC_KEY_get0_group(ecdh);
1213
+
1214
+ /* Next, get the encoded ECPoint */
1215
+ if (!CBS_get_u8_length_prefixed(&server_key_exchange, &point)) {
1216
+ al = SSL_AD_DECODE_ERROR;
1217
+ OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
1218
+ goto f_err;
1219
+ }
1220
+
1221
+ if (((srvr_ecpoint = EC_POINT_new(group)) == NULL) ||
1222
+ ((bn_ctx = BN_CTX_new()) == NULL)) {
1223
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1224
+ goto err;
1225
+ }
1226
+
1227
+ if (!EC_POINT_oct2point(group, srvr_ecpoint, CBS_data(&point),
1228
+ CBS_len(&point), bn_ctx)) {
1229
+ al = SSL_AD_DECODE_ERROR;
1230
+ OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_ECPOINT);
1231
+ goto f_err;
1232
+ }
1233
+ EC_KEY_set_public_key(ecdh, srvr_ecpoint);
1234
+ EC_KEY_free(s->s3->tmp.peer_ecdh_tmp);
1235
+ s->s3->tmp.peer_ecdh_tmp = ecdh;
1236
+ ecdh = NULL;
1237
+ BN_CTX_free(bn_ctx);
1238
+ bn_ctx = NULL;
1239
+ EC_POINT_free(srvr_ecpoint);
1240
+ srvr_ecpoint = NULL;
1241
+ } else if (!(alg_k & SSL_kPSK)) {
1242
+ al = SSL_AD_UNEXPECTED_MESSAGE;
1243
+ OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_MESSAGE);
1244
+ goto f_err;
1245
+ }
1246
+
1247
+ /* At this point, |server_key_exchange| contains the signature, if any, while
1248
+ * |server_key_exchange_orig| contains the entire message. From that, derive
1249
+ * a CBS containing just the parameter. */
1250
+ CBS_init(&parameter, CBS_data(&server_key_exchange_orig),
1251
+ CBS_len(&server_key_exchange_orig) - CBS_len(&server_key_exchange));
1252
+
1253
+ /* ServerKeyExchange should be signed by the server's public key. */
1254
+ if (ssl_cipher_has_server_public_key(s->s3->tmp.new_cipher)) {
1255
+ pkey = X509_get_pubkey(s->session->peer);
1256
+ if (pkey == NULL) {
1257
+ goto err;
1258
+ }
1259
+
1260
+ if (SSL_USE_SIGALGS(s)) {
1261
+ uint8_t hash, signature;
1262
+ if (!CBS_get_u8(&server_key_exchange, &hash) ||
1263
+ !CBS_get_u8(&server_key_exchange, &signature)) {
1264
+ al = SSL_AD_DECODE_ERROR;
1265
+ OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
1266
+ goto f_err;
1267
+ }
1268
+ if (!tls12_check_peer_sigalg(s, &md, &al, hash, signature, pkey)) {
1269
+ goto f_err;
1270
+ }
1271
+ s->s3->tmp.server_key_exchange_hash = hash;
1272
+ } else if (pkey->type == EVP_PKEY_RSA) {
1273
+ md = EVP_md5_sha1();
1274
+ } else {
1275
+ md = EVP_sha1();
1276
+ }
1277
+
1278
+ /* The last field in |server_key_exchange| is the signature. */
1279
+ CBS signature;
1280
+ if (!CBS_get_u16_length_prefixed(&server_key_exchange, &signature) ||
1281
+ CBS_len(&server_key_exchange) != 0) {
1282
+ al = SSL_AD_DECODE_ERROR;
1283
+ OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
1284
+ goto f_err;
1285
+ }
1286
+
1287
+ if (!EVP_DigestVerifyInit(&md_ctx, NULL, md, NULL, pkey) ||
1288
+ !EVP_DigestVerifyUpdate(&md_ctx, s->s3->client_random,
1289
+ SSL3_RANDOM_SIZE) ||
1290
+ !EVP_DigestVerifyUpdate(&md_ctx, s->s3->server_random,
1291
+ SSL3_RANDOM_SIZE) ||
1292
+ !EVP_DigestVerifyUpdate(&md_ctx, CBS_data(&parameter),
1293
+ CBS_len(&parameter)) ||
1294
+ !EVP_DigestVerifyFinal(&md_ctx, CBS_data(&signature),
1295
+ CBS_len(&signature))) {
1296
+ /* bad signature */
1297
+ al = SSL_AD_DECRYPT_ERROR;
1298
+ OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_SIGNATURE);
1299
+ goto f_err;
1300
+ }
1301
+ } else {
1302
+ /* PSK ciphers are the only supported certificate-less ciphers. */
1303
+ assert(alg_a == SSL_aPSK);
1304
+
1305
+ if (CBS_len(&server_key_exchange) > 0) {
1306
+ al = SSL_AD_DECODE_ERROR;
1307
+ OPENSSL_PUT_ERROR(SSL, SSL_R_EXTRA_DATA_IN_MESSAGE);
1308
+ goto f_err;
1309
+ }
1310
+ }
1311
+ EVP_PKEY_free(pkey);
1312
+ EVP_MD_CTX_cleanup(&md_ctx);
1313
+ return 1;
1314
+
1315
+ f_err:
1316
+ ssl3_send_alert(s, SSL3_AL_FATAL, al);
1317
+ err:
1318
+ EVP_PKEY_free(pkey);
1319
+ RSA_free(rsa);
1320
+ DH_free(dh);
1321
+ BN_CTX_free(bn_ctx);
1322
+ EC_POINT_free(srvr_ecpoint);
1323
+ EC_KEY_free(ecdh);
1324
+ EVP_MD_CTX_cleanup(&md_ctx);
1325
+ return -1;
1326
+ }
1327
+
1328
+ static int ca_dn_cmp(const X509_NAME **a, const X509_NAME **b) {
1329
+ return X509_NAME_cmp(*a, *b);
1330
+ }
1331
+
1332
+ int ssl3_get_certificate_request(SSL *s) {
1333
+ int ok, ret = 0;
1334
+ unsigned long n;
1335
+ X509_NAME *xn = NULL;
1336
+ STACK_OF(X509_NAME) *ca_sk = NULL;
1337
+ CBS cbs;
1338
+ CBS certificate_types;
1339
+ CBS certificate_authorities;
1340
+ const uint8_t *data;
1341
+
1342
+ n = s->method->ssl_get_message(s, SSL3_ST_CR_CERT_REQ_A,
1343
+ SSL3_ST_CR_CERT_REQ_B, -1, s->max_cert_list,
1344
+ ssl_hash_message, &ok);
1345
+
1346
+ if (!ok) {
1347
+ return n;
1348
+ }
1349
+
1350
+ s->s3->tmp.cert_req = 0;
1351
+
1352
+ if (s->s3->tmp.message_type == SSL3_MT_SERVER_DONE) {
1353
+ s->s3->tmp.reuse_message = 1;
1354
+ /* If we get here we don't need the handshake buffer as we won't be doing
1355
+ * client auth. */
1356
+ ssl3_free_handshake_buffer(s);
1357
+ return 1;
1358
+ }
1359
+
1360
+ if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_REQUEST) {
1361
+ ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
1362
+ OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_MESSAGE_TYPE);
1363
+ goto err;
1364
+ }
1365
+
1366
+ CBS_init(&cbs, s->init_msg, n);
1367
+
1368
+ ca_sk = sk_X509_NAME_new(ca_dn_cmp);
1369
+ if (ca_sk == NULL) {
1370
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1371
+ goto err;
1372
+ }
1373
+
1374
+ /* get the certificate types */
1375
+ if (!CBS_get_u8_length_prefixed(&cbs, &certificate_types)) {
1376
+ ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1377
+ OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
1378
+ goto err;
1379
+ }
1380
+
1381
+ if (!CBS_stow(&certificate_types, &s->s3->tmp.certificate_types,
1382
+ &s->s3->tmp.num_certificate_types)) {
1383
+ ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
1384
+ goto err;
1385
+ }
1386
+
1387
+ if (SSL_USE_SIGALGS(s)) {
1388
+ CBS supported_signature_algorithms;
1389
+ if (!CBS_get_u16_length_prefixed(&cbs, &supported_signature_algorithms) ||
1390
+ !tls1_parse_peer_sigalgs(s, &supported_signature_algorithms)) {
1391
+ ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1392
+ OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
1393
+ goto err;
1394
+ }
1395
+ }
1396
+
1397
+ /* get the CA RDNs */
1398
+ if (!CBS_get_u16_length_prefixed(&cbs, &certificate_authorities)) {
1399
+ ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1400
+ OPENSSL_PUT_ERROR(SSL, SSL_R_LENGTH_MISMATCH);
1401
+ goto err;
1402
+ }
1403
+
1404
+ while (CBS_len(&certificate_authorities) > 0) {
1405
+ CBS distinguished_name;
1406
+ if (!CBS_get_u16_length_prefixed(&certificate_authorities,
1407
+ &distinguished_name)) {
1408
+ ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1409
+ OPENSSL_PUT_ERROR(SSL, SSL_R_CA_DN_TOO_LONG);
1410
+ goto err;
1411
+ }
1412
+
1413
+ data = CBS_data(&distinguished_name);
1414
+
1415
+ /* A u16 length cannot overflow a long. */
1416
+ xn = d2i_X509_NAME(NULL, &data, (long)CBS_len(&distinguished_name));
1417
+ if (xn == NULL) {
1418
+ ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1419
+ OPENSSL_PUT_ERROR(SSL, ERR_R_ASN1_LIB);
1420
+ goto err;
1421
+ }
1422
+
1423
+ if (!CBS_skip(&distinguished_name, data - CBS_data(&distinguished_name))) {
1424
+ ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1425
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1426
+ goto err;
1427
+ }
1428
+
1429
+ if (CBS_len(&distinguished_name) != 0) {
1430
+ ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1431
+ OPENSSL_PUT_ERROR(SSL, SSL_R_CA_DN_LENGTH_MISMATCH);
1432
+ goto err;
1433
+ }
1434
+
1435
+ if (!sk_X509_NAME_push(ca_sk, xn)) {
1436
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1437
+ goto err;
1438
+ }
1439
+ }
1440
+
1441
+ /* we should setup a certificate to return.... */
1442
+ s->s3->tmp.cert_req = 1;
1443
+ sk_X509_NAME_pop_free(s->s3->tmp.ca_names, X509_NAME_free);
1444
+ s->s3->tmp.ca_names = ca_sk;
1445
+ ca_sk = NULL;
1446
+
1447
+ ret = 1;
1448
+
1449
+ err:
1450
+ sk_X509_NAME_pop_free(ca_sk, X509_NAME_free);
1451
+ return ret;
1452
+ }
1453
+
1454
+ int ssl3_get_new_session_ticket(SSL *s) {
1455
+ int ok, al;
1456
+ long n = s->method->ssl_get_message(
1457
+ s, SSL3_ST_CR_SESSION_TICKET_A, SSL3_ST_CR_SESSION_TICKET_B,
1458
+ SSL3_MT_NEWSESSION_TICKET, 16384, ssl_hash_message, &ok);
1459
+
1460
+ if (!ok) {
1461
+ return n;
1462
+ }
1463
+
1464
+ CBS new_session_ticket, ticket;
1465
+ uint32_t ticket_lifetime_hint;
1466
+ CBS_init(&new_session_ticket, s->init_msg, n);
1467
+ if (!CBS_get_u32(&new_session_ticket, &ticket_lifetime_hint) ||
1468
+ !CBS_get_u16_length_prefixed(&new_session_ticket, &ticket) ||
1469
+ CBS_len(&new_session_ticket) != 0) {
1470
+ al = SSL_AD_DECODE_ERROR;
1471
+ OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
1472
+ goto f_err;
1473
+ }
1474
+
1475
+ if (CBS_len(&ticket) == 0) {
1476
+ /* RFC 5077 allows a server to change its mind and send no ticket after
1477
+ * negotiating the extension. The value of |tlsext_ticket_expected| is
1478
+ * checked in |ssl_update_cache| so is cleared here to avoid an unnecessary
1479
+ * update. */
1480
+ s->tlsext_ticket_expected = 0;
1481
+ return 1;
1482
+ }
1483
+
1484
+ if (s->hit) {
1485
+ /* The server is sending a new ticket for an existing session. Sessions are
1486
+ * immutable once established, so duplicate all but the ticket of the
1487
+ * existing session. */
1488
+ uint8_t *bytes;
1489
+ size_t bytes_len;
1490
+ if (!SSL_SESSION_to_bytes_for_ticket(s->session, &bytes, &bytes_len)) {
1491
+ goto err;
1492
+ }
1493
+ SSL_SESSION *new_session = SSL_SESSION_from_bytes(bytes, bytes_len);
1494
+ OPENSSL_free(bytes);
1495
+ if (new_session == NULL) {
1496
+ /* This should never happen. */
1497
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1498
+ goto err;
1499
+ }
1500
+
1501
+ SSL_SESSION_free(s->session);
1502
+ s->session = new_session;
1503
+ }
1504
+
1505
+ if (!CBS_stow(&ticket, &s->session->tlsext_tick,
1506
+ &s->session->tlsext_ticklen)) {
1507
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1508
+ goto err;
1509
+ }
1510
+ s->session->tlsext_tick_lifetime_hint = ticket_lifetime_hint;
1511
+
1512
+ /* Generate a session ID for this session based on the session ticket. We use
1513
+ * the session ID mechanism for detecting ticket resumption. This also fits in
1514
+ * with assumptions elsewhere in OpenSSL.*/
1515
+ if (!EVP_Digest(CBS_data(&ticket), CBS_len(&ticket), s->session->session_id,
1516
+ &s->session->session_id_length, EVP_sha256(), NULL)) {
1517
+ goto err;
1518
+ }
1519
+
1520
+ return 1;
1521
+
1522
+ f_err:
1523
+ ssl3_send_alert(s, SSL3_AL_FATAL, al);
1524
+ err:
1525
+ return -1;
1526
+ }
1527
+
1528
+ int ssl3_get_cert_status(SSL *s) {
1529
+ int ok, al;
1530
+ long n;
1531
+ CBS certificate_status, ocsp_response;
1532
+ uint8_t status_type;
1533
+
1534
+ n = s->method->ssl_get_message(
1535
+ s, SSL3_ST_CR_CERT_STATUS_A, SSL3_ST_CR_CERT_STATUS_B,
1536
+ -1, 16384, ssl_hash_message, &ok);
1537
+
1538
+ if (!ok) {
1539
+ return n;
1540
+ }
1541
+
1542
+ if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_STATUS) {
1543
+ /* A server may send status_request in ServerHello and then change
1544
+ * its mind about sending CertificateStatus. */
1545
+ s->s3->tmp.reuse_message = 1;
1546
+ return 1;
1547
+ }
1548
+
1549
+ CBS_init(&certificate_status, s->init_msg, n);
1550
+ if (!CBS_get_u8(&certificate_status, &status_type) ||
1551
+ status_type != TLSEXT_STATUSTYPE_ocsp ||
1552
+ !CBS_get_u24_length_prefixed(&certificate_status, &ocsp_response) ||
1553
+ CBS_len(&ocsp_response) == 0 ||
1554
+ CBS_len(&certificate_status) != 0) {
1555
+ al = SSL_AD_DECODE_ERROR;
1556
+ OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
1557
+ goto f_err;
1558
+ }
1559
+
1560
+ if (!CBS_stow(&ocsp_response, &s->session->ocsp_response,
1561
+ &s->session->ocsp_response_length)) {
1562
+ al = SSL_AD_INTERNAL_ERROR;
1563
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1564
+ goto f_err;
1565
+ }
1566
+ return 1;
1567
+
1568
+ f_err:
1569
+ ssl3_send_alert(s, SSL3_AL_FATAL, al);
1570
+ return -1;
1571
+ }
1572
+
1573
+ int ssl3_get_server_done(SSL *s) {
1574
+ int ok;
1575
+ long n;
1576
+
1577
+ n = s->method->ssl_get_message(s, SSL3_ST_CR_SRVR_DONE_A,
1578
+ SSL3_ST_CR_SRVR_DONE_B, SSL3_MT_SERVER_DONE,
1579
+ 30, /* should be very small, like 0 :-) */
1580
+ ssl_hash_message, &ok);
1581
+
1582
+ if (!ok) {
1583
+ return n;
1584
+ }
1585
+
1586
+ if (n > 0) {
1587
+ /* should contain no data */
1588
+ ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1589
+ OPENSSL_PUT_ERROR(SSL, SSL_R_LENGTH_MISMATCH);
1590
+ return -1;
1591
+ }
1592
+
1593
+ return 1;
1594
+ }
1595
+
1596
+ OPENSSL_COMPILE_ASSERT(sizeof(size_t) >= sizeof(unsigned),
1597
+ SIZE_T_IS_SMALLER_THAN_UNSIGNED);
1598
+
1599
+ int ssl3_send_client_key_exchange(SSL *s) {
1600
+ uint8_t *p;
1601
+ int n = 0;
1602
+ uint32_t alg_k;
1603
+ uint32_t alg_a;
1604
+ uint8_t *q;
1605
+ EVP_PKEY *pkey = NULL;
1606
+ EC_KEY *clnt_ecdh = NULL;
1607
+ const EC_POINT *srvr_ecpoint = NULL;
1608
+ EVP_PKEY *srvr_pub_pkey = NULL;
1609
+ uint8_t *encodedPoint = NULL;
1610
+ int encoded_pt_len = 0;
1611
+ BN_CTX *bn_ctx = NULL;
1612
+ unsigned int psk_len = 0;
1613
+ uint8_t psk[PSK_MAX_PSK_LEN];
1614
+ uint8_t *pms = NULL;
1615
+ size_t pms_len = 0;
1616
+
1617
+ if (s->state == SSL3_ST_CW_KEY_EXCH_A) {
1618
+ p = ssl_handshake_start(s);
1619
+
1620
+ alg_k = s->s3->tmp.new_cipher->algorithm_mkey;
1621
+ alg_a = s->s3->tmp.new_cipher->algorithm_auth;
1622
+
1623
+ /* If using a PSK key exchange, prepare the pre-shared key. */
1624
+ if (alg_a & SSL_aPSK) {
1625
+ char identity[PSK_MAX_IDENTITY_LEN + 1];
1626
+ size_t identity_len;
1627
+
1628
+ if (s->psk_client_callback == NULL) {
1629
+ OPENSSL_PUT_ERROR(SSL, SSL_R_PSK_NO_CLIENT_CB);
1630
+ goto err;
1631
+ }
1632
+
1633
+ memset(identity, 0, sizeof(identity));
1634
+ psk_len =
1635
+ s->psk_client_callback(s, s->s3->tmp.peer_psk_identity_hint, identity,
1636
+ sizeof(identity), psk, sizeof(psk));
1637
+ if (psk_len > PSK_MAX_PSK_LEN) {
1638
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1639
+ goto err;
1640
+ } else if (psk_len == 0) {
1641
+ OPENSSL_PUT_ERROR(SSL, SSL_R_PSK_IDENTITY_NOT_FOUND);
1642
+ ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1643
+ goto err;
1644
+ }
1645
+
1646
+ identity_len = OPENSSL_strnlen(identity, sizeof(identity));
1647
+ if (identity_len > PSK_MAX_IDENTITY_LEN) {
1648
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1649
+ goto err;
1650
+ }
1651
+
1652
+ OPENSSL_free(s->session->psk_identity);
1653
+ s->session->psk_identity = BUF_strdup(identity);
1654
+ if (s->session->psk_identity == NULL) {
1655
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1656
+ goto err;
1657
+ }
1658
+
1659
+ /* Write out psk_identity. */
1660
+ s2n(identity_len, p);
1661
+ memcpy(p, identity, identity_len);
1662
+ p += identity_len;
1663
+ n = 2 + identity_len;
1664
+ }
1665
+
1666
+ /* Depending on the key exchange method, compute |pms| and |pms_len|. */
1667
+ if (alg_k & SSL_kRSA) {
1668
+ size_t enc_pms_len;
1669
+
1670
+ pms_len = SSL_MAX_MASTER_KEY_LENGTH;
1671
+ pms = OPENSSL_malloc(pms_len);
1672
+ if (pms == NULL) {
1673
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1674
+ goto err;
1675
+ }
1676
+
1677
+ pkey = X509_get_pubkey(s->session->peer);
1678
+ if (pkey == NULL) {
1679
+ goto err;
1680
+ }
1681
+
1682
+ RSA *rsa = EVP_PKEY_get0_RSA(pkey);
1683
+ if (rsa == NULL) {
1684
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1685
+ EVP_PKEY_free(pkey);
1686
+ goto err;
1687
+ }
1688
+
1689
+ s->session->key_exchange_info = EVP_PKEY_bits(pkey);
1690
+ EVP_PKEY_free(pkey);
1691
+
1692
+ pms[0] = s->client_version >> 8;
1693
+ pms[1] = s->client_version & 0xff;
1694
+ if (!RAND_bytes(&pms[2], SSL_MAX_MASTER_KEY_LENGTH - 2)) {
1695
+ goto err;
1696
+ }
1697
+
1698
+ s->session->master_key_length = SSL_MAX_MASTER_KEY_LENGTH;
1699
+
1700
+ q = p;
1701
+ /* In TLS and beyond, reserve space for the length prefix. */
1702
+ if (s->version > SSL3_VERSION) {
1703
+ p += 2;
1704
+ n += 2;
1705
+ }
1706
+ if (!RSA_encrypt(rsa, &enc_pms_len, p, RSA_size(rsa), pms, pms_len,
1707
+ RSA_PKCS1_PADDING)) {
1708
+ OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_RSA_ENCRYPT);
1709
+ goto err;
1710
+ }
1711
+ n += enc_pms_len;
1712
+
1713
+ /* Log the premaster secret, if logging is enabled. */
1714
+ if (!ssl_log_rsa_client_key_exchange(s, p, enc_pms_len, pms, pms_len)) {
1715
+ goto err;
1716
+ }
1717
+
1718
+ /* Fill in the length prefix. */
1719
+ if (s->version > SSL3_VERSION) {
1720
+ s2n(enc_pms_len, q);
1721
+ }
1722
+ } else if (alg_k & SSL_kDHE) {
1723
+ DH *dh_srvr, *dh_clnt;
1724
+ int dh_len;
1725
+ size_t pub_len;
1726
+
1727
+ if (s->s3->tmp.peer_dh_tmp == NULL) {
1728
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1729
+ goto err;
1730
+ }
1731
+ dh_srvr = s->s3->tmp.peer_dh_tmp;
1732
+
1733
+ /* generate a new random key */
1734
+ dh_clnt = DHparams_dup(dh_srvr);
1735
+ if (dh_clnt == NULL) {
1736
+ OPENSSL_PUT_ERROR(SSL, ERR_R_DH_LIB);
1737
+ goto err;
1738
+ }
1739
+ if (!DH_generate_key(dh_clnt)) {
1740
+ OPENSSL_PUT_ERROR(SSL, ERR_R_DH_LIB);
1741
+ DH_free(dh_clnt);
1742
+ goto err;
1743
+ }
1744
+
1745
+ pms_len = DH_size(dh_clnt);
1746
+ pms = OPENSSL_malloc(pms_len);
1747
+ if (pms == NULL) {
1748
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1749
+ DH_free(dh_clnt);
1750
+ goto err;
1751
+ }
1752
+
1753
+ dh_len = DH_compute_key(pms, dh_srvr->pub_key, dh_clnt);
1754
+ if (dh_len <= 0) {
1755
+ OPENSSL_PUT_ERROR(SSL, ERR_R_DH_LIB);
1756
+ DH_free(dh_clnt);
1757
+ goto err;
1758
+ }
1759
+ pms_len = dh_len;
1760
+
1761
+ /* send off the data */
1762
+ pub_len = BN_num_bytes(dh_clnt->pub_key);
1763
+ s2n(pub_len, p);
1764
+ BN_bn2bin(dh_clnt->pub_key, p);
1765
+ n += 2 + pub_len;
1766
+
1767
+ DH_free(dh_clnt);
1768
+ } else if (alg_k & SSL_kECDHE) {
1769
+ const EC_GROUP *srvr_group = NULL;
1770
+ EC_KEY *tkey;
1771
+ int ecdh_len;
1772
+
1773
+ if (s->s3->tmp.peer_ecdh_tmp == NULL) {
1774
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1775
+ goto err;
1776
+ }
1777
+
1778
+ tkey = s->s3->tmp.peer_ecdh_tmp;
1779
+
1780
+ srvr_group = EC_KEY_get0_group(tkey);
1781
+ srvr_ecpoint = EC_KEY_get0_public_key(tkey);
1782
+ if (srvr_group == NULL || srvr_ecpoint == NULL) {
1783
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1784
+ goto err;
1785
+ }
1786
+
1787
+ clnt_ecdh = EC_KEY_new();
1788
+ if (clnt_ecdh == NULL) {
1789
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1790
+ goto err;
1791
+ }
1792
+
1793
+ if (!EC_KEY_set_group(clnt_ecdh, srvr_group)) {
1794
+ OPENSSL_PUT_ERROR(SSL, ERR_R_EC_LIB);
1795
+ goto err;
1796
+ }
1797
+
1798
+ /* Generate a new ECDH key pair */
1799
+ if (!EC_KEY_generate_key(clnt_ecdh)) {
1800
+ OPENSSL_PUT_ERROR(SSL, ERR_R_ECDH_LIB);
1801
+ goto err;
1802
+ }
1803
+
1804
+ unsigned field_size = EC_GROUP_get_degree(srvr_group);
1805
+ if (field_size == 0) {
1806
+ OPENSSL_PUT_ERROR(SSL, ERR_R_ECDH_LIB);
1807
+ goto err;
1808
+ }
1809
+
1810
+ pms_len = (field_size + 7) / 8;
1811
+ pms = OPENSSL_malloc(pms_len);
1812
+ if (pms == NULL) {
1813
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1814
+ goto err;
1815
+ }
1816
+
1817
+ ecdh_len = ECDH_compute_key(pms, pms_len, srvr_ecpoint, clnt_ecdh, NULL);
1818
+ if (ecdh_len <= 0) {
1819
+ OPENSSL_PUT_ERROR(SSL, ERR_R_ECDH_LIB);
1820
+ goto err;
1821
+ }
1822
+ pms_len = ecdh_len;
1823
+
1824
+ /* First check the size of encoding and allocate memory accordingly. */
1825
+ encoded_pt_len =
1826
+ EC_POINT_point2oct(srvr_group, EC_KEY_get0_public_key(clnt_ecdh),
1827
+ POINT_CONVERSION_UNCOMPRESSED, NULL, 0, NULL);
1828
+
1829
+ encodedPoint =
1830
+ (uint8_t *)OPENSSL_malloc(encoded_pt_len * sizeof(uint8_t));
1831
+ bn_ctx = BN_CTX_new();
1832
+ if (encodedPoint == NULL || bn_ctx == NULL) {
1833
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1834
+ goto err;
1835
+ }
1836
+
1837
+ /* Encode the public key */
1838
+ encoded_pt_len = EC_POINT_point2oct(
1839
+ srvr_group, EC_KEY_get0_public_key(clnt_ecdh),
1840
+ POINT_CONVERSION_UNCOMPRESSED, encodedPoint, encoded_pt_len, bn_ctx);
1841
+
1842
+ *p = encoded_pt_len; /* length of encoded point */
1843
+ /* Encoded point will be copied here */
1844
+ p += 1;
1845
+ n += 1;
1846
+ /* copy the point */
1847
+ memcpy(p, encodedPoint, encoded_pt_len);
1848
+ /* increment n to account for length field */
1849
+ n += encoded_pt_len;
1850
+
1851
+ /* Free allocated memory */
1852
+ BN_CTX_free(bn_ctx);
1853
+ bn_ctx = NULL;
1854
+ OPENSSL_free(encodedPoint);
1855
+ encodedPoint = NULL;
1856
+ EC_KEY_free(clnt_ecdh);
1857
+ clnt_ecdh = NULL;
1858
+ EVP_PKEY_free(srvr_pub_pkey);
1859
+ srvr_pub_pkey = NULL;
1860
+ } else if (alg_k & SSL_kPSK) {
1861
+ /* For plain PSK, other_secret is a block of 0s with the same length as
1862
+ * the pre-shared key. */
1863
+ pms_len = psk_len;
1864
+ pms = OPENSSL_malloc(pms_len);
1865
+ if (pms == NULL) {
1866
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1867
+ goto err;
1868
+ }
1869
+ memset(pms, 0, pms_len);
1870
+ } else {
1871
+ ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1872
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1873
+ goto err;
1874
+ }
1875
+
1876
+ /* For a PSK cipher suite, other_secret is combined with the pre-shared
1877
+ * key. */
1878
+ if (alg_a & SSL_aPSK) {
1879
+ CBB cbb, child;
1880
+ uint8_t *new_pms;
1881
+ size_t new_pms_len;
1882
+
1883
+ CBB_zero(&cbb);
1884
+ if (!CBB_init(&cbb, 2 + psk_len + 2 + pms_len) ||
1885
+ !CBB_add_u16_length_prefixed(&cbb, &child) ||
1886
+ !CBB_add_bytes(&child, pms, pms_len) ||
1887
+ !CBB_add_u16_length_prefixed(&cbb, &child) ||
1888
+ !CBB_add_bytes(&child, psk, psk_len) ||
1889
+ !CBB_finish(&cbb, &new_pms, &new_pms_len)) {
1890
+ CBB_cleanup(&cbb);
1891
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1892
+ goto err;
1893
+ }
1894
+ OPENSSL_cleanse(pms, pms_len);
1895
+ OPENSSL_free(pms);
1896
+ pms = new_pms;
1897
+ pms_len = new_pms_len;
1898
+ }
1899
+
1900
+ /* The message must be added to the finished hash before calculating the
1901
+ * master secret. */
1902
+ if (!ssl_set_handshake_header(s, SSL3_MT_CLIENT_KEY_EXCHANGE, n)) {
1903
+ goto err;
1904
+ }
1905
+ s->state = SSL3_ST_CW_KEY_EXCH_B;
1906
+
1907
+ s->session->master_key_length = s->enc_method->generate_master_secret(
1908
+ s, s->session->master_key, pms, pms_len);
1909
+ if (s->session->master_key_length == 0) {
1910
+ goto err;
1911
+ }
1912
+ s->session->extended_master_secret = s->s3->tmp.extended_master_secret;
1913
+ OPENSSL_cleanse(pms, pms_len);
1914
+ OPENSSL_free(pms);
1915
+ }
1916
+
1917
+ /* SSL3_ST_CW_KEY_EXCH_B */
1918
+ return s->method->do_write(s);
1919
+
1920
+ err:
1921
+ BN_CTX_free(bn_ctx);
1922
+ OPENSSL_free(encodedPoint);
1923
+ EC_KEY_free(clnt_ecdh);
1924
+ EVP_PKEY_free(srvr_pub_pkey);
1925
+ if (pms) {
1926
+ OPENSSL_cleanse(pms, pms_len);
1927
+ OPENSSL_free(pms);
1928
+ }
1929
+ return -1;
1930
+ }
1931
+
1932
+ int ssl3_send_cert_verify(SSL *s) {
1933
+ if (s->state == SSL3_ST_CW_CERT_VRFY_A ||
1934
+ s->state == SSL3_ST_CW_CERT_VRFY_B) {
1935
+ enum ssl_private_key_result_t sign_result;
1936
+ uint8_t *p = ssl_handshake_start(s);
1937
+ size_t signature_length = 0;
1938
+ unsigned long n = 0;
1939
+ assert(ssl_has_private_key(s));
1940
+
1941
+ if (s->state == SSL3_ST_CW_CERT_VRFY_A) {
1942
+ uint8_t *buf = (uint8_t *)s->init_buf->data;
1943
+ const EVP_MD *md = NULL;
1944
+ uint8_t digest[EVP_MAX_MD_SIZE];
1945
+ size_t digest_length;
1946
+
1947
+ /* Write out the digest type if need be. */
1948
+ if (SSL_USE_SIGALGS(s)) {
1949
+ md = tls1_choose_signing_digest(s);
1950
+ if (!tls12_get_sigandhash(s, p, md)) {
1951
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1952
+ return -1;
1953
+ }
1954
+ p += 2;
1955
+ n += 2;
1956
+ }
1957
+
1958
+ /* Compute the digest. */
1959
+ const int pkey_type = ssl_private_key_type(s);
1960
+ if (!ssl3_cert_verify_hash(s, digest, &digest_length, &md, pkey_type)) {
1961
+ return -1;
1962
+ }
1963
+
1964
+ /* The handshake buffer is no longer necessary. */
1965
+ ssl3_free_handshake_buffer(s);
1966
+
1967
+ /* Sign the digest. */
1968
+ signature_length = ssl_private_key_max_signature_len(s);
1969
+ if (p + 2 + signature_length > buf + SSL3_RT_MAX_PLAIN_LENGTH) {
1970
+ OPENSSL_PUT_ERROR(SSL, SSL_R_DATA_LENGTH_TOO_LONG);
1971
+ return -1;
1972
+ }
1973
+
1974
+ s->rwstate = SSL_PRIVATE_KEY_OPERATION;
1975
+ sign_result = ssl_private_key_sign(s, &p[2], &signature_length,
1976
+ signature_length, md, digest,
1977
+ digest_length);
1978
+ } else {
1979
+ if (SSL_USE_SIGALGS(s)) {
1980
+ /* The digest has already been selected and written. */
1981
+ p += 2;
1982
+ n += 2;
1983
+ }
1984
+ signature_length = ssl_private_key_max_signature_len(s);
1985
+ s->rwstate = SSL_PRIVATE_KEY_OPERATION;
1986
+ sign_result = ssl_private_key_sign_complete(s, &p[2], &signature_length,
1987
+ signature_length);
1988
+ }
1989
+
1990
+ if (sign_result == ssl_private_key_retry) {
1991
+ s->state = SSL3_ST_CW_CERT_VRFY_B;
1992
+ return -1;
1993
+ }
1994
+ s->rwstate = SSL_NOTHING;
1995
+ if (sign_result != ssl_private_key_success) {
1996
+ return -1;
1997
+ }
1998
+
1999
+ s2n(signature_length, p);
2000
+ n += signature_length + 2;
2001
+ if (!ssl_set_handshake_header(s, SSL3_MT_CERTIFICATE_VERIFY, n)) {
2002
+ return -1;
2003
+ }
2004
+ s->state = SSL3_ST_CW_CERT_VRFY_C;
2005
+ }
2006
+
2007
+ return ssl_do_write(s);
2008
+ }
2009
+
2010
+ /* ssl3_has_client_certificate returns true if a client certificate is
2011
+ * configured. */
2012
+ static int ssl3_has_client_certificate(SSL *ssl) {
2013
+ return ssl->cert && ssl->cert->x509 && ssl_has_private_key(ssl);
2014
+ }
2015
+
2016
+ int ssl3_send_client_certificate(SSL *s) {
2017
+ X509 *x509 = NULL;
2018
+ EVP_PKEY *pkey = NULL;
2019
+ int i;
2020
+
2021
+ if (s->state == SSL3_ST_CW_CERT_A) {
2022
+ /* Let cert callback update client certificates if required */
2023
+ if (s->cert->cert_cb) {
2024
+ i = s->cert->cert_cb(s, s->cert->cert_cb_arg);
2025
+ if (i < 0) {
2026
+ s->rwstate = SSL_X509_LOOKUP;
2027
+ return -1;
2028
+ }
2029
+ if (i == 0) {
2030
+ ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
2031
+ return 0;
2032
+ }
2033
+ s->rwstate = SSL_NOTHING;
2034
+ }
2035
+
2036
+ if (ssl3_has_client_certificate(s)) {
2037
+ s->state = SSL3_ST_CW_CERT_C;
2038
+ } else {
2039
+ s->state = SSL3_ST_CW_CERT_B;
2040
+ }
2041
+ }
2042
+
2043
+ /* We need to get a client cert */
2044
+ if (s->state == SSL3_ST_CW_CERT_B) {
2045
+ /* If we get an error, we need to:
2046
+ * ssl->rwstate=SSL_X509_LOOKUP; return(-1);
2047
+ * We then get retried later */
2048
+ i = ssl_do_client_cert_cb(s, &x509, &pkey);
2049
+ if (i < 0) {
2050
+ s->rwstate = SSL_X509_LOOKUP;
2051
+ return -1;
2052
+ }
2053
+ s->rwstate = SSL_NOTHING;
2054
+ if (i == 1 && pkey != NULL && x509 != NULL) {
2055
+ s->state = SSL3_ST_CW_CERT_B;
2056
+ if (!SSL_use_certificate(s, x509) || !SSL_use_PrivateKey(s, pkey)) {
2057
+ i = 0;
2058
+ }
2059
+ } else if (i == 1) {
2060
+ i = 0;
2061
+ OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_DATA_RETURNED_BY_CALLBACK);
2062
+ }
2063
+
2064
+ X509_free(x509);
2065
+ EVP_PKEY_free(pkey);
2066
+ if (i && !ssl3_has_client_certificate(s)) {
2067
+ i = 0;
2068
+ }
2069
+ if (i == 0) {
2070
+ if (s->version == SSL3_VERSION) {
2071
+ s->s3->tmp.cert_req = 0;
2072
+ ssl3_send_alert(s, SSL3_AL_WARNING, SSL_AD_NO_CERTIFICATE);
2073
+ return 1;
2074
+ } else {
2075
+ s->s3->tmp.cert_req = 2;
2076
+ /* There is no client certificate, so the handshake buffer may be
2077
+ * released. */
2078
+ ssl3_free_handshake_buffer(s);
2079
+ }
2080
+ }
2081
+
2082
+ /* Ok, we have a cert */
2083
+ s->state = SSL3_ST_CW_CERT_C;
2084
+ }
2085
+
2086
+ if (s->state == SSL3_ST_CW_CERT_C) {
2087
+ if (s->s3->tmp.cert_req == 2) {
2088
+ /* Send an empty Certificate message. */
2089
+ uint8_t *p = ssl_handshake_start(s);
2090
+ l2n3(0, p);
2091
+ if (!ssl_set_handshake_header(s, SSL3_MT_CERTIFICATE, 3)) {
2092
+ return -1;
2093
+ }
2094
+ } else if (!ssl3_output_cert_chain(s)) {
2095
+ return -1;
2096
+ }
2097
+ s->state = SSL3_ST_CW_CERT_D;
2098
+ }
2099
+
2100
+ /* SSL3_ST_CW_CERT_D */
2101
+ return ssl_do_write(s);
2102
+ }
2103
+
2104
+ int ssl3_send_next_proto(SSL *ssl) {
2105
+ if (ssl->state == SSL3_ST_CW_NEXT_PROTO_B) {
2106
+ return ssl_do_write(ssl);
2107
+ }
2108
+
2109
+ assert(ssl->state == SSL3_ST_CW_NEXT_PROTO_A);
2110
+
2111
+ static const uint8_t kZero[32] = {0};
2112
+ size_t padding_len = 32 - ((ssl->next_proto_negotiated_len + 2) % 32);
2113
+
2114
+ CBB cbb, child;
2115
+ size_t length;
2116
+ CBB_zero(&cbb);
2117
+ if (!CBB_init_fixed(&cbb, ssl_handshake_start(ssl),
2118
+ ssl->init_buf->max - SSL_HM_HEADER_LENGTH(ssl)) ||
2119
+ !CBB_add_u8_length_prefixed(&cbb, &child) ||
2120
+ !CBB_add_bytes(&child, ssl->next_proto_negotiated,
2121
+ ssl->next_proto_negotiated_len) ||
2122
+ !CBB_add_u8_length_prefixed(&cbb, &child) ||
2123
+ !CBB_add_bytes(&child, kZero, padding_len) ||
2124
+ !CBB_finish(&cbb, NULL, &length) ||
2125
+ !ssl_set_handshake_header(ssl, SSL3_MT_NEXT_PROTO, length)) {
2126
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
2127
+ CBB_cleanup(&cbb);
2128
+ return -1;
2129
+ }
2130
+
2131
+ ssl->state = SSL3_ST_CW_NEXT_PROTO_B;
2132
+ return ssl_do_write(ssl);
2133
+ }
2134
+
2135
+ static int write_32_byte_big_endian(CBB *out, const BIGNUM *in) {
2136
+ uint8_t *ptr;
2137
+ return CBB_add_space(out, &ptr, 32) &&
2138
+ BN_bn2bin_padded(ptr, 32, in);
2139
+ }
2140
+
2141
+ int ssl3_send_channel_id(SSL *ssl) {
2142
+ if (ssl->state == SSL3_ST_CW_CHANNEL_ID_B) {
2143
+ return ssl_do_write(ssl);
2144
+ }
2145
+
2146
+ assert(ssl->state == SSL3_ST_CW_CHANNEL_ID_A);
2147
+
2148
+ if (ssl->tlsext_channel_id_private == NULL &&
2149
+ ssl->ctx->channel_id_cb != NULL) {
2150
+ EVP_PKEY *key = NULL;
2151
+ ssl->ctx->channel_id_cb(ssl, &key);
2152
+ if (key != NULL &&
2153
+ !SSL_set1_tls_channel_id(ssl, key)) {
2154
+ EVP_PKEY_free(key);
2155
+ return -1;
2156
+ }
2157
+ EVP_PKEY_free(key);
2158
+ }
2159
+
2160
+ if (ssl->tlsext_channel_id_private == NULL) {
2161
+ ssl->rwstate = SSL_CHANNEL_ID_LOOKUP;
2162
+ return -1;
2163
+ }
2164
+ ssl->rwstate = SSL_NOTHING;
2165
+
2166
+ EC_KEY *ec_key = EVP_PKEY_get0_EC_KEY(ssl->tlsext_channel_id_private);
2167
+ if (ec_key == NULL) {
2168
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
2169
+ return -1;
2170
+ }
2171
+
2172
+ int ret = -1;
2173
+ BIGNUM *x = BN_new();
2174
+ BIGNUM *y = BN_new();
2175
+ ECDSA_SIG *sig = NULL;
2176
+ if (x == NULL || y == NULL ||
2177
+ !EC_POINT_get_affine_coordinates_GFp(EC_KEY_get0_group(ec_key),
2178
+ EC_KEY_get0_public_key(ec_key),
2179
+ x, y, NULL)) {
2180
+ goto err;
2181
+ }
2182
+
2183
+ uint8_t digest[EVP_MAX_MD_SIZE];
2184
+ size_t digest_len;
2185
+ if (!tls1_channel_id_hash(ssl, digest, &digest_len)) {
2186
+ goto err;
2187
+ }
2188
+
2189
+ sig = ECDSA_do_sign(digest, digest_len, ec_key);
2190
+ if (sig == NULL) {
2191
+ goto err;
2192
+ }
2193
+
2194
+ CBB cbb, child;
2195
+ size_t length;
2196
+ CBB_zero(&cbb);
2197
+ if (!CBB_init_fixed(&cbb, ssl_handshake_start(ssl),
2198
+ ssl->init_buf->max - SSL_HM_HEADER_LENGTH(ssl)) ||
2199
+ !CBB_add_u16(&cbb, TLSEXT_TYPE_channel_id) ||
2200
+ !CBB_add_u16_length_prefixed(&cbb, &child) ||
2201
+ !write_32_byte_big_endian(&child, x) ||
2202
+ !write_32_byte_big_endian(&child, y) ||
2203
+ !write_32_byte_big_endian(&child, sig->r) ||
2204
+ !write_32_byte_big_endian(&child, sig->s) ||
2205
+ !CBB_finish(&cbb, NULL, &length) ||
2206
+ !ssl_set_handshake_header(ssl, SSL3_MT_ENCRYPTED_EXTENSIONS, length)) {
2207
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
2208
+ CBB_cleanup(&cbb);
2209
+ goto err;
2210
+ }
2211
+
2212
+ ssl->state = SSL3_ST_CW_CHANNEL_ID_B;
2213
+ ret = ssl_do_write(ssl);
2214
+
2215
+ err:
2216
+ BN_free(x);
2217
+ BN_free(y);
2218
+ ECDSA_SIG_free(sig);
2219
+ return ret;
2220
+ }
2221
+
2222
+ int ssl_do_client_cert_cb(SSL *ssl, X509 **out_x509, EVP_PKEY **out_pkey) {
2223
+ if (ssl->ctx->client_cert_cb == NULL) {
2224
+ return 0;
2225
+ }
2226
+ return ssl->ctx->client_cert_cb(ssl, out_x509, out_pkey);
2227
+ }
2228
+
2229
+ int ssl3_verify_server_cert(SSL *s) {
2230
+ int ret = ssl_verify_cert_chain(s, s->session->cert_chain);
2231
+ if (s->verify_mode != SSL_VERIFY_NONE && ret <= 0) {
2232
+ int al = ssl_verify_alarm_type(s->verify_result);
2233
+ ssl3_send_alert(s, SSL3_AL_FATAL, al);
2234
+ OPENSSL_PUT_ERROR(SSL, SSL_R_CERTIFICATE_VERIFY_FAILED);
2235
+ } else {
2236
+ ret = 1;
2237
+ ERR_clear_error(); /* but we keep s->verify_result */
2238
+ }
2239
+
2240
+ return ret;
2241
+ }