wearefair-grpc 1.3.1.pre.a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1161) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +1 -0
  3. data/Makefile +19484 -0
  4. data/etc/roots.pem +5288 -0
  5. data/include/grpc/byte_buffer.h +102 -0
  6. data/include/grpc/byte_buffer_reader.h +39 -0
  7. data/include/grpc/census.h +484 -0
  8. data/include/grpc/compression.h +85 -0
  9. data/include/grpc/grpc.h +509 -0
  10. data/include/grpc/grpc_cronet.h +51 -0
  11. data/include/grpc/grpc_posix.h +81 -0
  12. data/include/grpc/grpc_security.h +390 -0
  13. data/include/grpc/grpc_security_constants.h +114 -0
  14. data/include/grpc/impl/codegen/atm.h +100 -0
  15. data/include/grpc/impl/codegen/atm_gcc_atomic.h +97 -0
  16. data/include/grpc/impl/codegen/atm_gcc_sync.h +97 -0
  17. data/include/grpc/impl/codegen/atm_windows.h +140 -0
  18. data/include/grpc/impl/codegen/byte_buffer_reader.h +57 -0
  19. data/include/grpc/impl/codegen/compression_types.h +122 -0
  20. data/include/grpc/impl/codegen/connectivity_state.h +61 -0
  21. data/include/grpc/impl/codegen/exec_ctx_fwd.h +41 -0
  22. data/include/grpc/impl/codegen/gpr_slice.h +84 -0
  23. data/include/grpc/impl/codegen/gpr_types.h +75 -0
  24. data/include/grpc/impl/codegen/grpc_types.h +550 -0
  25. data/include/grpc/impl/codegen/port_platform.h +421 -0
  26. data/include/grpc/impl/codegen/propagation_bits.h +67 -0
  27. data/include/grpc/impl/codegen/slice.h +157 -0
  28. data/include/grpc/impl/codegen/status.h +163 -0
  29. data/include/grpc/impl/codegen/sync.h +75 -0
  30. data/include/grpc/impl/codegen/sync_generic.h +55 -0
  31. data/include/grpc/impl/codegen/sync_posix.h +47 -0
  32. data/include/grpc/impl/codegen/sync_windows.h +49 -0
  33. data/include/grpc/load_reporting.h +63 -0
  34. data/include/grpc/module.modulemap +13 -0
  35. data/include/grpc/slice.h +168 -0
  36. data/include/grpc/slice_buffer.h +94 -0
  37. data/include/grpc/status.h +39 -0
  38. data/include/grpc/support/alloc.h +82 -0
  39. data/include/grpc/support/atm.h +39 -0
  40. data/include/grpc/support/atm_gcc_atomic.h +39 -0
  41. data/include/grpc/support/atm_gcc_sync.h +39 -0
  42. data/include/grpc/support/atm_windows.h +39 -0
  43. data/include/grpc/support/avl.h +97 -0
  44. data/include/grpc/support/cmdline.h +103 -0
  45. data/include/grpc/support/cpu.h +59 -0
  46. data/include/grpc/support/histogram.h +79 -0
  47. data/include/grpc/support/host_port.h +66 -0
  48. data/include/grpc/support/log.h +118 -0
  49. data/include/grpc/support/log_windows.h +53 -0
  50. data/include/grpc/support/port_platform.h +39 -0
  51. data/include/grpc/support/string_util.h +64 -0
  52. data/include/grpc/support/subprocess.h +59 -0
  53. data/include/grpc/support/sync.h +295 -0
  54. data/include/grpc/support/sync_generic.h +39 -0
  55. data/include/grpc/support/sync_posix.h +39 -0
  56. data/include/grpc/support/sync_windows.h +39 -0
  57. data/include/grpc/support/thd.h +91 -0
  58. data/include/grpc/support/time.h +105 -0
  59. data/include/grpc/support/tls.h +77 -0
  60. data/include/grpc/support/tls_gcc.h +100 -0
  61. data/include/grpc/support/tls_msvc.h +56 -0
  62. data/include/grpc/support/tls_pthread.h +60 -0
  63. data/include/grpc/support/useful.h +80 -0
  64. data/src/boringssl/err_data.c +1270 -0
  65. data/src/core/ext/census/aggregation.h +66 -0
  66. data/src/core/ext/census/base_resources.c +71 -0
  67. data/src/core/ext/census/base_resources.h +39 -0
  68. data/src/core/ext/census/census_interface.h +76 -0
  69. data/src/core/ext/census/census_rpc_stats.h +101 -0
  70. data/src/core/ext/census/context.c +509 -0
  71. data/src/core/ext/census/gen/census.pb.c +176 -0
  72. data/src/core/ext/census/gen/census.pb.h +295 -0
  73. data/src/core/ext/census/gen/trace_context.pb.c +54 -0
  74. data/src/core/ext/census/gen/trace_context.pb.h +93 -0
  75. data/src/core/ext/census/grpc_context.c +53 -0
  76. data/src/core/ext/census/grpc_filter.c +213 -0
  77. data/src/core/ext/census/grpc_filter.h +44 -0
  78. data/src/core/ext/census/grpc_plugin.c +85 -0
  79. data/src/core/ext/census/initialize.c +66 -0
  80. data/src/core/ext/census/mlog.c +600 -0
  81. data/src/core/ext/census/mlog.h +95 -0
  82. data/src/core/ext/census/operation.c +63 -0
  83. data/src/core/ext/census/placeholders.c +64 -0
  84. data/src/core/ext/census/resource.c +312 -0
  85. data/src/core/ext/census/resource.h +63 -0
  86. data/src/core/ext/census/rpc_metric_id.h +51 -0
  87. data/src/core/ext/census/trace_context.c +86 -0
  88. data/src/core/ext/census/trace_context.h +71 -0
  89. data/src/core/ext/census/trace_label.h +61 -0
  90. data/src/core/ext/census/trace_propagation.h +63 -0
  91. data/src/core/ext/census/trace_status.h +45 -0
  92. data/src/core/ext/census/trace_string.h +50 -0
  93. data/src/core/ext/census/tracing.c +71 -0
  94. data/src/core/ext/census/tracing.h +124 -0
  95. data/src/core/ext/filters/client_channel/channel_connectivity.c +226 -0
  96. data/src/core/ext/filters/client_channel/client_channel.c +1410 -0
  97. data/src/core/ext/filters/client_channel/client_channel.h +64 -0
  98. data/src/core/ext/filters/client_channel/client_channel_factory.c +87 -0
  99. data/src/core/ext/filters/client_channel/client_channel_factory.h +92 -0
  100. data/src/core/ext/filters/client_channel/client_channel_plugin.c +106 -0
  101. data/src/core/ext/filters/client_channel/connector.c +55 -0
  102. data/src/core/ext/filters/client_channel/connector.h +88 -0
  103. data/src/core/ext/filters/client_channel/http_connect_handshaker.c +389 -0
  104. data/src/core/ext/filters/client_channel/http_connect_handshaker.h +49 -0
  105. data/src/core/ext/filters/client_channel/http_proxy.c +125 -0
  106. data/src/core/ext/filters/client_channel/http_proxy.h +39 -0
  107. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c +1419 -0
  108. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h +44 -0
  109. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +57 -0
  110. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.c +107 -0
  111. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c +249 -0
  112. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +105 -0
  113. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +88 -0
  114. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +158 -0
  115. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +476 -0
  116. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +795 -0
  117. data/src/core/ext/filters/client_channel/lb_policy.c +167 -0
  118. data/src/core/ext/filters/client_channel/lb_policy.h +209 -0
  119. data/src/core/ext/filters/client_channel/lb_policy_factory.c +163 -0
  120. data/src/core/ext/filters/client_channel/lb_policy_factory.h +134 -0
  121. data/src/core/ext/filters/client_channel/lb_policy_registry.c +85 -0
  122. data/src/core/ext/filters/client_channel/lb_policy_registry.h +55 -0
  123. data/src/core/ext/filters/client_channel/parse_address.c +170 -0
  124. data/src/core/ext/filters/client_channel/parse_address.h +54 -0
  125. data/src/core/ext/filters/client_channel/proxy_mapper.c +63 -0
  126. data/src/core/ext/filters/client_channel/proxy_mapper.h +89 -0
  127. data/src/core/ext/filters/client_channel/proxy_mapper_registry.c +139 -0
  128. data/src/core/ext/filters/client_channel/proxy_mapper_registry.h +59 -0
  129. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +350 -0
  130. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +66 -0
  131. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.c +319 -0
  132. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +289 -0
  133. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +64 -0
  134. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.c +325 -0
  135. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.c +234 -0
  136. data/src/core/ext/filters/client_channel/resolver.c +88 -0
  137. data/src/core/ext/filters/client_channel/resolver.h +101 -0
  138. data/src/core/ext/filters/client_channel/resolver_factory.c +56 -0
  139. data/src/core/ext/filters/client_channel/resolver_factory.h +85 -0
  140. data/src/core/ext/filters/client_channel/resolver_registry.c +174 -0
  141. data/src/core/ext/filters/client_channel/resolver_registry.h +84 -0
  142. data/src/core/ext/filters/client_channel/retry_throttle.c +210 -0
  143. data/src/core/ext/filters/client_channel/retry_throttle.h +65 -0
  144. data/src/core/ext/filters/client_channel/subchannel.c +835 -0
  145. data/src/core/ext/filters/client_channel/subchannel.h +203 -0
  146. data/src/core/ext/filters/client_channel/subchannel_index.c +262 -0
  147. data/src/core/ext/filters/client_channel/subchannel_index.h +77 -0
  148. data/src/core/ext/filters/client_channel/uri_parser.c +315 -0
  149. data/src/core/ext/filters/client_channel/uri_parser.h +65 -0
  150. data/src/core/ext/filters/load_reporting/load_reporting.c +106 -0
  151. data/src/core/ext/filters/load_reporting/load_reporting.h +73 -0
  152. data/src/core/ext/filters/load_reporting/load_reporting_filter.c +218 -0
  153. data/src/core/ext/filters/load_reporting/load_reporting_filter.h +42 -0
  154. data/src/core/ext/filters/max_age/max_age_filter.c +439 -0
  155. data/src/core/ext/filters/max_age/max_age_filter.h +39 -0
  156. data/src/core/ext/transport/chttp2/alpn/alpn.c +56 -0
  157. data/src/core/ext/transport/chttp2/alpn/alpn.h +49 -0
  158. data/src/core/ext/transport/chttp2/client/chttp2_connector.c +221 -0
  159. data/src/core/ext/transport/chttp2/client/chttp2_connector.h +41 -0
  160. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +121 -0
  161. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c +95 -0
  162. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +239 -0
  163. data/src/core/ext/transport/chttp2/server/chttp2_server.c +304 -0
  164. data/src/core/ext/transport/chttp2/server/chttp2_server.h +47 -0
  165. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +59 -0
  166. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c +90 -0
  167. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +101 -0
  168. data/src/core/ext/transport/chttp2/transport/bin_decoder.c +236 -0
  169. data/src/core/ext/transport/chttp2/transport/bin_decoder.h +67 -0
  170. data/src/core/ext/transport/chttp2/transport/bin_encoder.c +241 -0
  171. data/src/core/ext/transport/chttp2/transport/bin_encoder.h +54 -0
  172. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +43 -0
  173. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +2847 -0
  174. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +53 -0
  175. data/src/core/ext/transport/chttp2/transport/frame.h +61 -0
  176. data/src/core/ext/transport/chttp2/transport/frame_data.c +287 -0
  177. data/src/core/ext/transport/chttp2/transport/frame_data.h +104 -0
  178. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +198 -0
  179. data/src/core/ext/transport/chttp2/transport/frame_goaway.h +78 -0
  180. data/src/core/ext/transport/chttp2/transport/frame_ping.c +145 -0
  181. data/src/core/ext/transport/chttp2/transport/frame_ping.h +59 -0
  182. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +125 -0
  183. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +58 -0
  184. data/src/core/ext/transport/chttp2/transport/frame_settings.c +239 -0
  185. data/src/core/ext/transport/chttp2/transport/frame_settings.h +76 -0
  186. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +134 -0
  187. data/src/core/ext/transport/chttp2/transport/frame_window_update.h +57 -0
  188. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +661 -0
  189. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +107 -0
  190. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +1734 -0
  191. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +129 -0
  192. data/src/core/ext/transport/chttp2/transport/hpack_table.c +383 -0
  193. data/src/core/ext/transport/chttp2/transport/hpack_table.h +112 -0
  194. data/src/core/ext/transport/chttp2/transport/http2_settings.c +75 -0
  195. data/src/core/ext/transport/chttp2/transport/http2_settings.h +74 -0
  196. data/src/core/ext/transport/chttp2/transport/huffsyms.c +105 -0
  197. data/src/core/ext/transport/chttp2/transport/huffsyms.h +48 -0
  198. data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +88 -0
  199. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +63 -0
  200. data/src/core/ext/transport/chttp2/transport/internal.h +852 -0
  201. data/src/core/ext/transport/chttp2/transport/parsing.c +825 -0
  202. data/src/core/ext/transport/chttp2/transport/stream_lists.c +194 -0
  203. data/src/core/ext/transport/chttp2/transport/stream_map.c +176 -0
  204. data/src/core/ext/transport/chttp2/transport/stream_map.h +83 -0
  205. data/src/core/ext/transport/chttp2/transport/varint.c +65 -0
  206. data/src/core/ext/transport/chttp2/transport/varint.h +75 -0
  207. data/src/core/ext/transport/chttp2/transport/writing.c +429 -0
  208. data/src/core/lib/channel/channel_args.c +355 -0
  209. data/src/core/lib/channel/channel_args.h +126 -0
  210. data/src/core/lib/channel/channel_stack.c +291 -0
  211. data/src/core/lib/channel/channel_stack.h +319 -0
  212. data/src/core/lib/channel/channel_stack_builder.c +284 -0
  213. data/src/core/lib/channel/channel_stack_builder.h +170 -0
  214. data/src/core/lib/channel/compress_filter.c +353 -0
  215. data/src/core/lib/channel/compress_filter.h +67 -0
  216. data/src/core/lib/channel/connected_channel.c +188 -0
  217. data/src/core/lib/channel/connected_channel.h +48 -0
  218. data/src/core/lib/channel/context.h +64 -0
  219. data/src/core/lib/channel/deadline_filter.c +348 -0
  220. data/src/core/lib/channel/deadline_filter.h +102 -0
  221. data/src/core/lib/channel/handshaker.c +281 -0
  222. data/src/core/lib/channel/handshaker.h +182 -0
  223. data/src/core/lib/channel/handshaker_factory.c +54 -0
  224. data/src/core/lib/channel/handshaker_factory.h +66 -0
  225. data/src/core/lib/channel/handshaker_registry.c +113 -0
  226. data/src/core/lib/channel/handshaker_registry.h +63 -0
  227. data/src/core/lib/channel/http_client_filter.c +601 -0
  228. data/src/core/lib/channel/http_client_filter.h +47 -0
  229. data/src/core/lib/channel/http_server_filter.c +445 -0
  230. data/src/core/lib/channel/http_server_filter.h +42 -0
  231. data/src/core/lib/channel/message_size_filter.c +270 -0
  232. data/src/core/lib/channel/message_size_filter.h +39 -0
  233. data/src/core/lib/compression/algorithm_metadata.h +53 -0
  234. data/src/core/lib/compression/compression.c +198 -0
  235. data/src/core/lib/compression/message_compress.c +204 -0
  236. data/src/core/lib/compression/message_compress.h +54 -0
  237. data/src/core/lib/debug/trace.c +140 -0
  238. data/src/core/lib/debug/trace.h +43 -0
  239. data/src/core/lib/http/format_request.c +135 -0
  240. data/src/core/lib/http/format_request.h +47 -0
  241. data/src/core/lib/http/httpcli.c +336 -0
  242. data/src/core/lib/http/httpcli.h +141 -0
  243. data/src/core/lib/http/httpcli_security_connector.c +199 -0
  244. data/src/core/lib/http/parser.c +379 -0
  245. data/src/core/lib/http/parser.h +126 -0
  246. data/src/core/lib/iomgr/closure.c +168 -0
  247. data/src/core/lib/iomgr/closure.h +153 -0
  248. data/src/core/lib/iomgr/combiner.c +460 -0
  249. data/src/core/lib/iomgr/combiner.h +83 -0
  250. data/src/core/lib/iomgr/endpoint.c +78 -0
  251. data/src/core/lib/iomgr/endpoint.h +117 -0
  252. data/src/core/lib/iomgr/endpoint_pair.h +47 -0
  253. data/src/core/lib/iomgr/endpoint_pair_posix.c +87 -0
  254. data/src/core/lib/iomgr/endpoint_pair_uv.c +53 -0
  255. data/src/core/lib/iomgr/endpoint_pair_windows.c +101 -0
  256. data/src/core/lib/iomgr/error.c +793 -0
  257. data/src/core/lib/iomgr/error.h +218 -0
  258. data/src/core/lib/iomgr/error_internal.h +75 -0
  259. data/src/core/lib/iomgr/ev_epoll_linux.c +1965 -0
  260. data/src/core/lib/iomgr/ev_epoll_linux.h +48 -0
  261. data/src/core/lib/iomgr/ev_poll_posix.c +1593 -0
  262. data/src/core/lib/iomgr/ev_poll_posix.h +42 -0
  263. data/src/core/lib/iomgr/ev_posix.c +287 -0
  264. data/src/core/lib/iomgr/ev_posix.h +189 -0
  265. data/src/core/lib/iomgr/exec_ctx.c +117 -0
  266. data/src/core/lib/iomgr/exec_ctx.h +117 -0
  267. data/src/core/lib/iomgr/executor.c +170 -0
  268. data/src/core/lib/iomgr/executor.h +51 -0
  269. data/src/core/lib/iomgr/iocp_windows.c +168 -0
  270. data/src/core/lib/iomgr/iocp_windows.h +55 -0
  271. data/src/core/lib/iomgr/iomgr.c +183 -0
  272. data/src/core/lib/iomgr/iomgr.h +47 -0
  273. data/src/core/lib/iomgr/iomgr_internal.h +58 -0
  274. data/src/core/lib/iomgr/iomgr_posix.c +56 -0
  275. data/src/core/lib/iomgr/iomgr_posix.h +39 -0
  276. data/src/core/lib/iomgr/iomgr_uv.c +49 -0
  277. data/src/core/lib/iomgr/iomgr_windows.c +76 -0
  278. data/src/core/lib/iomgr/load_file.c +92 -0
  279. data/src/core/lib/iomgr/load_file.h +56 -0
  280. data/src/core/lib/iomgr/lockfree_event.c +238 -0
  281. data/src/core/lib/iomgr/lockfree_event.h +54 -0
  282. data/src/core/lib/iomgr/network_status_tracker.c +48 -0
  283. data/src/core/lib/iomgr/network_status_tracker.h +45 -0
  284. data/src/core/lib/iomgr/polling_entity.c +104 -0
  285. data/src/core/lib/iomgr/polling_entity.h +81 -0
  286. data/src/core/lib/iomgr/pollset.h +97 -0
  287. data/src/core/lib/iomgr/pollset_set.h +62 -0
  288. data/src/core/lib/iomgr/pollset_set_uv.c +63 -0
  289. data/src/core/lib/iomgr/pollset_set_windows.c +64 -0
  290. data/src/core/lib/iomgr/pollset_set_windows.h +39 -0
  291. data/src/core/lib/iomgr/pollset_uv.c +156 -0
  292. data/src/core/lib/iomgr/pollset_uv.h +42 -0
  293. data/src/core/lib/iomgr/pollset_windows.c +232 -0
  294. data/src/core/lib/iomgr/pollset_windows.h +78 -0
  295. data/src/core/lib/iomgr/port.h +138 -0
  296. data/src/core/lib/iomgr/resolve_address.h +70 -0
  297. data/src/core/lib/iomgr/resolve_address_posix.c +207 -0
  298. data/src/core/lib/iomgr/resolve_address_uv.c +284 -0
  299. data/src/core/lib/iomgr/resolve_address_windows.c +190 -0
  300. data/src/core/lib/iomgr/resource_quota.c +877 -0
  301. data/src/core/lib/iomgr/resource_quota.h +167 -0
  302. data/src/core/lib/iomgr/sockaddr.h +55 -0
  303. data/src/core/lib/iomgr/sockaddr_posix.h +44 -0
  304. data/src/core/lib/iomgr/sockaddr_utils.c +272 -0
  305. data/src/core/lib/iomgr/sockaddr_utils.h +93 -0
  306. data/src/core/lib/iomgr/sockaddr_windows.h +43 -0
  307. data/src/core/lib/iomgr/socket_factory_posix.c +110 -0
  308. data/src/core/lib/iomgr/socket_factory_posix.h +90 -0
  309. data/src/core/lib/iomgr/socket_mutator.c +98 -0
  310. data/src/core/lib/iomgr/socket_mutator.h +80 -0
  311. data/src/core/lib/iomgr/socket_utils.h +42 -0
  312. data/src/core/lib/iomgr/socket_utils_common_posix.c +330 -0
  313. data/src/core/lib/iomgr/socket_utils_linux.c +57 -0
  314. data/src/core/lib/iomgr/socket_utils_posix.c +73 -0
  315. data/src/core/lib/iomgr/socket_utils_posix.h +147 -0
  316. data/src/core/lib/iomgr/socket_utils_uv.c +49 -0
  317. data/src/core/lib/iomgr/socket_utils_windows.c +52 -0
  318. data/src/core/lib/iomgr/socket_windows.c +167 -0
  319. data/src/core/lib/iomgr/socket_windows.h +125 -0
  320. data/src/core/lib/iomgr/tcp_client.h +55 -0
  321. data/src/core/lib/iomgr/tcp_client_posix.c +368 -0
  322. data/src/core/lib/iomgr/tcp_client_posix.h +45 -0
  323. data/src/core/lib/iomgr/tcp_client_uv.c +192 -0
  324. data/src/core/lib/iomgr/tcp_client_windows.c +260 -0
  325. data/src/core/lib/iomgr/tcp_posix.c +677 -0
  326. data/src/core/lib/iomgr/tcp_posix.h +70 -0
  327. data/src/core/lib/iomgr/tcp_server.h +116 -0
  328. data/src/core/lib/iomgr/tcp_server_posix.c +579 -0
  329. data/src/core/lib/iomgr/tcp_server_utils_posix.h +135 -0
  330. data/src/core/lib/iomgr/tcp_server_utils_posix_common.c +221 -0
  331. data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.c +196 -0
  332. data/src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.c +49 -0
  333. data/src/core/lib/iomgr/tcp_server_uv.c +393 -0
  334. data/src/core/lib/iomgr/tcp_server_windows.c +558 -0
  335. data/src/core/lib/iomgr/tcp_uv.c +374 -0
  336. data/src/core/lib/iomgr/tcp_uv.h +59 -0
  337. data/src/core/lib/iomgr/tcp_windows.c +462 -0
  338. data/src/core/lib/iomgr/tcp_windows.h +59 -0
  339. data/src/core/lib/iomgr/time_averaged_stats.c +77 -0
  340. data/src/core/lib/iomgr/time_averaged_stats.h +88 -0
  341. data/src/core/lib/iomgr/timer.h +111 -0
  342. data/src/core/lib/iomgr/timer_generic.c +567 -0
  343. data/src/core/lib/iomgr/timer_generic.h +49 -0
  344. data/src/core/lib/iomgr/timer_heap.c +152 -0
  345. data/src/core/lib/iomgr/timer_heap.h +57 -0
  346. data/src/core/lib/iomgr/timer_uv.c +103 -0
  347. data/src/core/lib/iomgr/timer_uv.h +47 -0
  348. data/src/core/lib/iomgr/udp_server.c +529 -0
  349. data/src/core/lib/iomgr/udp_server.h +89 -0
  350. data/src/core/lib/iomgr/unix_sockets_posix.c +108 -0
  351. data/src/core/lib/iomgr/unix_sockets_posix.h +56 -0
  352. data/src/core/lib/iomgr/unix_sockets_posix_noop.c +62 -0
  353. data/src/core/lib/iomgr/wakeup_fd_cv.c +118 -0
  354. data/src/core/lib/iomgr/wakeup_fd_cv.h +80 -0
  355. data/src/core/lib/iomgr/wakeup_fd_eventfd.c +97 -0
  356. data/src/core/lib/iomgr/wakeup_fd_nospecial.c +51 -0
  357. data/src/core/lib/iomgr/wakeup_fd_pipe.c +112 -0
  358. data/src/core/lib/iomgr/wakeup_fd_pipe.h +41 -0
  359. data/src/core/lib/iomgr/wakeup_fd_posix.c +101 -0
  360. data/src/core/lib/iomgr/wakeup_fd_posix.h +109 -0
  361. data/src/core/lib/iomgr/workqueue.h +87 -0
  362. data/src/core/lib/iomgr/workqueue_uv.c +65 -0
  363. data/src/core/lib/iomgr/workqueue_uv.h +37 -0
  364. data/src/core/lib/iomgr/workqueue_windows.c +63 -0
  365. data/src/core/lib/iomgr/workqueue_windows.h +37 -0
  366. data/src/core/lib/json/json.c +63 -0
  367. data/src/core/lib/json/json.h +88 -0
  368. data/src/core/lib/json/json_common.h +49 -0
  369. data/src/core/lib/json/json_reader.c +675 -0
  370. data/src/core/lib/json/json_reader.h +160 -0
  371. data/src/core/lib/json/json_string.c +379 -0
  372. data/src/core/lib/json/json_writer.c +258 -0
  373. data/src/core/lib/json/json_writer.h +97 -0
  374. data/src/core/lib/profiling/basic_timers.c +298 -0
  375. data/src/core/lib/profiling/stap_timers.c +65 -0
  376. data/src/core/lib/profiling/timers.h +121 -0
  377. data/src/core/lib/security/context/security_context.c +350 -0
  378. data/src/core/lib/security/context/security_context.h +134 -0
  379. data/src/core/lib/security/credentials/composite/composite_credentials.c +274 -0
  380. data/src/core/lib/security/credentials/composite/composite_credentials.h +72 -0
  381. data/src/core/lib/security/credentials/credentials.c +308 -0
  382. data/src/core/lib/security/credentials/credentials.h +268 -0
  383. data/src/core/lib/security/credentials/credentials_metadata.c +103 -0
  384. data/src/core/lib/security/credentials/fake/fake_credentials.c +141 -0
  385. data/src/core/lib/security/credentials/fake/fake_credentials.h +71 -0
  386. data/src/core/lib/security/credentials/google_default/credentials_generic.c +54 -0
  387. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +337 -0
  388. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +60 -0
  389. data/src/core/lib/security/credentials/iam/iam_credentials.c +85 -0
  390. data/src/core/lib/security/credentials/iam/iam_credentials.h +44 -0
  391. data/src/core/lib/security/credentials/jwt/json_token.c +321 -0
  392. data/src/core/lib/security/credentials/jwt/json_token.h +88 -0
  393. data/src/core/lib/security/credentials/jwt/jwt_credentials.c +195 -0
  394. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +63 -0
  395. data/src/core/lib/security/credentials/jwt/jwt_verifier.c +910 -0
  396. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +140 -0
  397. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +468 -0
  398. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +109 -0
  399. data/src/core/lib/security/credentials/plugin/plugin_credentials.c +153 -0
  400. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +45 -0
  401. data/src/core/lib/security/credentials/ssl/ssl_credentials.c +242 -0
  402. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +48 -0
  403. data/src/core/lib/security/transport/auth_filters.h +42 -0
  404. data/src/core/lib/security/transport/client_auth_filter.c +384 -0
  405. data/src/core/lib/security/transport/lb_targets_info.c +70 -0
  406. data/src/core/lib/security/transport/lb_targets_info.h +47 -0
  407. data/src/core/lib/security/transport/secure_endpoint.c +427 -0
  408. data/src/core/lib/security/transport/secure_endpoint.h +49 -0
  409. data/src/core/lib/security/transport/security_connector.c +909 -0
  410. data/src/core/lib/security/transport/security_connector.h +252 -0
  411. data/src/core/lib/security/transport/security_handshaker.c +507 -0
  412. data/src/core/lib/security/transport/security_handshaker.h +49 -0
  413. data/src/core/lib/security/transport/server_auth_filter.c +277 -0
  414. data/src/core/lib/security/transport/tsi_error.c +42 -0
  415. data/src/core/lib/security/transport/tsi_error.h +42 -0
  416. data/src/core/lib/security/util/json_util.c +61 -0
  417. data/src/core/lib/security/util/json_util.h +55 -0
  418. data/src/core/lib/slice/b64.c +251 -0
  419. data/src/core/lib/slice/b64.h +65 -0
  420. data/src/core/lib/slice/percent_encoding.c +182 -0
  421. data/src/core/lib/slice/percent_encoding.h +78 -0
  422. data/src/core/lib/slice/slice.c +466 -0
  423. data/src/core/lib/slice/slice_buffer.c +355 -0
  424. data/src/core/lib/slice/slice_hash_table.c +125 -0
  425. data/src/core/lib/slice/slice_hash_table.h +77 -0
  426. data/src/core/lib/slice/slice_intern.c +346 -0
  427. data/src/core/lib/slice/slice_internal.h +64 -0
  428. data/src/core/lib/slice/slice_string_helpers.c +95 -0
  429. data/src/core/lib/slice/slice_string_helpers.h +63 -0
  430. data/src/core/lib/support/alloc.c +117 -0
  431. data/src/core/lib/support/arena.c +98 -0
  432. data/src/core/lib/support/arena.h +54 -0
  433. data/src/core/lib/support/atm.c +47 -0
  434. data/src/core/lib/support/avl.c +299 -0
  435. data/src/core/lib/support/backoff.c +87 -0
  436. data/src/core/lib/support/backoff.h +71 -0
  437. data/src/core/lib/support/block_annotate.h +48 -0
  438. data/src/core/lib/support/cmdline.c +345 -0
  439. data/src/core/lib/support/cpu_iphone.c +49 -0
  440. data/src/core/lib/support/cpu_linux.c +83 -0
  441. data/src/core/lib/support/cpu_posix.c +72 -0
  442. data/src/core/lib/support/cpu_windows.c +47 -0
  443. data/src/core/lib/support/env.h +58 -0
  444. data/src/core/lib/support/env_linux.c +89 -0
  445. data/src/core/lib/support/env_posix.c +57 -0
  446. data/src/core/lib/support/env_windows.c +79 -0
  447. data/src/core/lib/support/histogram.c +243 -0
  448. data/src/core/lib/support/host_port.c +110 -0
  449. data/src/core/lib/support/log.c +103 -0
  450. data/src/core/lib/support/log_android.c +87 -0
  451. data/src/core/lib/support/log_linux.c +105 -0
  452. data/src/core/lib/support/log_posix.c +106 -0
  453. data/src/core/lib/support/log_windows.c +112 -0
  454. data/src/core/lib/support/mpscq.c +83 -0
  455. data/src/core/lib/support/mpscq.h +65 -0
  456. data/src/core/lib/support/murmur_hash.c +94 -0
  457. data/src/core/lib/support/murmur_hash.h +44 -0
  458. data/src/core/lib/support/spinlock.h +52 -0
  459. data/src/core/lib/support/stack_lockfree.c +185 -0
  460. data/src/core/lib/support/stack_lockfree.h +53 -0
  461. data/src/core/lib/support/string.c +315 -0
  462. data/src/core/lib/support/string.h +128 -0
  463. data/src/core/lib/support/string_posix.c +86 -0
  464. data/src/core/lib/support/string_util_windows.c +94 -0
  465. data/src/core/lib/support/string_windows.c +83 -0
  466. data/src/core/lib/support/string_windows.h +47 -0
  467. data/src/core/lib/support/subprocess_posix.c +114 -0
  468. data/src/core/lib/support/subprocess_windows.c +141 -0
  469. data/src/core/lib/support/sync.c +137 -0
  470. data/src/core/lib/support/sync_posix.c +113 -0
  471. data/src/core/lib/support/sync_windows.c +133 -0
  472. data/src/core/lib/support/thd.c +64 -0
  473. data/src/core/lib/support/thd_internal.h +39 -0
  474. data/src/core/lib/support/thd_posix.c +95 -0
  475. data/src/core/lib/support/thd_windows.c +117 -0
  476. data/src/core/lib/support/time.c +262 -0
  477. data/src/core/lib/support/time_posix.c +176 -0
  478. data/src/core/lib/support/time_precise.c +89 -0
  479. data/src/core/lib/support/time_precise.h +42 -0
  480. data/src/core/lib/support/time_windows.c +116 -0
  481. data/src/core/lib/support/tls_pthread.c +45 -0
  482. data/src/core/lib/support/tmpfile.h +53 -0
  483. data/src/core/lib/support/tmpfile_msys.c +73 -0
  484. data/src/core/lib/support/tmpfile_posix.c +85 -0
  485. data/src/core/lib/support/tmpfile_windows.c +84 -0
  486. data/src/core/lib/support/wrap_memcpy.c +55 -0
  487. data/src/core/lib/surface/alarm.c +87 -0
  488. data/src/core/lib/surface/api_trace.c +36 -0
  489. data/src/core/lib/surface/api_trace.h +65 -0
  490. data/src/core/lib/surface/byte_buffer.c +103 -0
  491. data/src/core/lib/surface/byte_buffer_reader.c +140 -0
  492. data/src/core/lib/surface/call.c +1835 -0
  493. data/src/core/lib/surface/call.h +135 -0
  494. data/src/core/lib/surface/call_details.c +56 -0
  495. data/src/core/lib/surface/call_log_batch.c +131 -0
  496. data/src/core/lib/surface/call_test_only.h +64 -0
  497. data/src/core/lib/surface/channel.c +434 -0
  498. data/src/core/lib/surface/channel.h +99 -0
  499. data/src/core/lib/surface/channel_init.c +140 -0
  500. data/src/core/lib/surface/channel_init.h +96 -0
  501. data/src/core/lib/surface/channel_ping.c +80 -0
  502. data/src/core/lib/surface/channel_stack_type.c +54 -0
  503. data/src/core/lib/surface/channel_stack_type.h +58 -0
  504. data/src/core/lib/surface/completion_queue.c +692 -0
  505. data/src/core/lib/surface/completion_queue.h +102 -0
  506. data/src/core/lib/surface/completion_queue_factory.c +77 -0
  507. data/src/core/lib/surface/completion_queue_factory.h +51 -0
  508. data/src/core/lib/surface/event_string.c +81 -0
  509. data/src/core/lib/surface/event_string.h +42 -0
  510. data/src/core/lib/surface/init.c +261 -0
  511. data/src/core/lib/surface/init.h +42 -0
  512. data/src/core/lib/surface/init_secure.c +94 -0
  513. data/src/core/lib/surface/lame_client.c +188 -0
  514. data/src/core/lib/surface/lame_client.h +41 -0
  515. data/src/core/lib/surface/metadata_array.c +49 -0
  516. data/src/core/lib/surface/server.c +1529 -0
  517. data/src/core/lib/surface/server.h +71 -0
  518. data/src/core/lib/surface/validate_metadata.c +108 -0
  519. data/src/core/lib/surface/validate_metadata.h +43 -0
  520. data/src/core/lib/surface/version.c +41 -0
  521. data/src/core/lib/transport/bdp_estimator.c +104 -0
  522. data/src/core/lib/transport/bdp_estimator.h +76 -0
  523. data/src/core/lib/transport/byte_stream.c +81 -0
  524. data/src/core/lib/transport/byte_stream.h +85 -0
  525. data/src/core/lib/transport/connectivity_state.c +219 -0
  526. data/src/core/lib/transport/connectivity_state.h +101 -0
  527. data/src/core/lib/transport/error_utils.c +124 -0
  528. data/src/core/lib/transport/error_utils.h +56 -0
  529. data/src/core/lib/transport/http2_errors.h +56 -0
  530. data/src/core/lib/transport/metadata.c +529 -0
  531. data/src/core/lib/transport/metadata.h +186 -0
  532. data/src/core/lib/transport/metadata_batch.c +328 -0
  533. data/src/core/lib/transport/metadata_batch.h +166 -0
  534. data/src/core/lib/transport/pid_controller.c +78 -0
  535. data/src/core/lib/transport/pid_controller.h +77 -0
  536. data/src/core/lib/transport/service_config.c +266 -0
  537. data/src/core/lib/transport/service_config.h +77 -0
  538. data/src/core/lib/transport/static_metadata.c +801 -0
  539. data/src/core/lib/transport/static_metadata.h +557 -0
  540. data/src/core/lib/transport/status_conversion.c +113 -0
  541. data/src/core/lib/transport/status_conversion.h +49 -0
  542. data/src/core/lib/transport/timeout_encoding.c +190 -0
  543. data/src/core/lib/transport/timeout_encoding.h +49 -0
  544. data/src/core/lib/transport/transport.c +282 -0
  545. data/src/core/lib/transport/transport.h +354 -0
  546. data/src/core/lib/transport/transport_impl.h +90 -0
  547. data/src/core/lib/transport/transport_op_string.c +217 -0
  548. data/src/core/plugin_registry/grpc_plugin_registry.c +82 -0
  549. data/src/core/tsi/fake_transport_security.c +527 -0
  550. data/src/core/tsi/fake_transport_security.h +61 -0
  551. data/src/core/tsi/ssl_transport_security.c +1533 -0
  552. data/src/core/tsi/ssl_transport_security.h +214 -0
  553. data/src/core/tsi/ssl_types.h +55 -0
  554. data/src/core/tsi/transport_security.c +266 -0
  555. data/src/core/tsi/transport_security.h +111 -0
  556. data/src/core/tsi/transport_security_interface.h +353 -0
  557. data/src/ruby/bin/apis/google/protobuf/empty.rb +44 -0
  558. data/src/ruby/bin/apis/pubsub_demo.rb +256 -0
  559. data/src/ruby/bin/apis/tech/pubsub/proto/pubsub.rb +174 -0
  560. data/src/ruby/bin/apis/tech/pubsub/proto/pubsub_services.rb +103 -0
  561. data/src/ruby/bin/math_client.rb +147 -0
  562. data/src/ruby/bin/math_pb.rb +32 -0
  563. data/src/ruby/bin/math_server.rb +206 -0
  564. data/src/ruby/bin/math_services_pb.rb +66 -0
  565. data/src/ruby/bin/noproto_client.rb +108 -0
  566. data/src/ruby/bin/noproto_server.rb +112 -0
  567. data/src/ruby/ext/grpc/extconf.rb +131 -0
  568. data/src/ruby/ext/grpc/rb_byte_buffer.c +77 -0
  569. data/src/ruby/ext/grpc/rb_byte_buffer.h +50 -0
  570. data/src/ruby/ext/grpc/rb_call.c +1009 -0
  571. data/src/ruby/ext/grpc/rb_call.h +66 -0
  572. data/src/ruby/ext/grpc/rb_call_credentials.c +295 -0
  573. data/src/ruby/ext/grpc/rb_call_credentials.h +46 -0
  574. data/src/ruby/ext/grpc/rb_channel.c +662 -0
  575. data/src/ruby/ext/grpc/rb_channel.h +49 -0
  576. data/src/ruby/ext/grpc/rb_channel_args.c +168 -0
  577. data/src/ruby/ext/grpc/rb_channel_args.h +53 -0
  578. data/src/ruby/ext/grpc/rb_channel_credentials.c +268 -0
  579. data/src/ruby/ext/grpc/rb_channel_credentials.h +47 -0
  580. data/src/ruby/ext/grpc/rb_completion_queue.c +117 -0
  581. data/src/ruby/ext/grpc/rb_completion_queue.h +51 -0
  582. data/src/ruby/ext/grpc/rb_compression_options.c +472 -0
  583. data/src/ruby/ext/grpc/rb_compression_options.h +44 -0
  584. data/src/ruby/ext/grpc/rb_event_thread.c +158 -0
  585. data/src/ruby/ext/grpc/rb_event_thread.h +37 -0
  586. data/src/ruby/ext/grpc/rb_grpc.c +343 -0
  587. data/src/ruby/ext/grpc/rb_grpc.h +87 -0
  588. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +634 -0
  589. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +955 -0
  590. data/src/ruby/ext/grpc/rb_loader.c +72 -0
  591. data/src/ruby/ext/grpc/rb_loader.h +40 -0
  592. data/src/ruby/ext/grpc/rb_server.c +359 -0
  593. data/src/ruby/ext/grpc/rb_server.h +47 -0
  594. data/src/ruby/ext/grpc/rb_server_credentials.c +258 -0
  595. data/src/ruby/ext/grpc/rb_server_credentials.h +47 -0
  596. data/src/ruby/lib/grpc/core/time_consts.rb +71 -0
  597. data/src/ruby/lib/grpc/errors.rb +215 -0
  598. data/src/ruby/lib/grpc/generic/active_call.rb +547 -0
  599. data/src/ruby/lib/grpc/generic/bidi_call.rb +229 -0
  600. data/src/ruby/lib/grpc/generic/client_stub.rb +463 -0
  601. data/src/ruby/lib/grpc/generic/rpc_desc.rb +173 -0
  602. data/src/ruby/lib/grpc/generic/rpc_server.rb +476 -0
  603. data/src/ruby/lib/grpc/generic/service.rb +225 -0
  604. data/src/ruby/lib/grpc/grpc.rb +39 -0
  605. data/src/ruby/lib/grpc/grpc_c.bundle +0 -0
  606. data/src/ruby/lib/grpc/logconfig.rb +59 -0
  607. data/src/ruby/lib/grpc/notifier.rb +60 -0
  608. data/src/ruby/lib/grpc/version.rb +33 -0
  609. data/src/ruby/lib/grpc.rb +49 -0
  610. data/src/ruby/pb/README.md +42 -0
  611. data/src/ruby/pb/generate_proto_ruby.sh +58 -0
  612. data/src/ruby/pb/grpc/health/checker.rb +77 -0
  613. data/src/ruby/pb/grpc/health/v1/health_pb.rb +28 -0
  614. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +56 -0
  615. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +58 -0
  616. data/src/ruby/pb/grpc/testing/metrics_pb.rb +28 -0
  617. data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +64 -0
  618. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +15 -0
  619. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +82 -0
  620. data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +14 -0
  621. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +117 -0
  622. data/src/ruby/pb/test/client.rb +779 -0
  623. data/src/ruby/pb/test/server.rb +267 -0
  624. data/src/ruby/spec/call_credentials_spec.rb +57 -0
  625. data/src/ruby/spec/call_spec.rb +162 -0
  626. data/src/ruby/spec/channel_connection_spec.rb +141 -0
  627. data/src/ruby/spec/channel_credentials_spec.rb +97 -0
  628. data/src/ruby/spec/channel_spec.rb +205 -0
  629. data/src/ruby/spec/client_server_spec.rb +491 -0
  630. data/src/ruby/spec/compression_options_spec.rb +164 -0
  631. data/src/ruby/spec/error_sanity_spec.rb +64 -0
  632. data/src/ruby/spec/generic/active_call_spec.rb +632 -0
  633. data/src/ruby/spec/generic/client_stub_spec.rb +556 -0
  634. data/src/ruby/spec/generic/rpc_desc_spec.rb +351 -0
  635. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +142 -0
  636. data/src/ruby/spec/generic/rpc_server_spec.rb +524 -0
  637. data/src/ruby/spec/generic/service_spec.rb +276 -0
  638. data/src/ruby/spec/pb/duplicate/codegen_spec.rb +71 -0
  639. data/src/ruby/spec/pb/health/checker_spec.rb +222 -0
  640. data/src/ruby/spec/server_credentials_spec.rb +94 -0
  641. data/src/ruby/spec/server_spec.rb +205 -0
  642. data/src/ruby/spec/spec_helper.rb +71 -0
  643. data/src/ruby/spec/testdata/README +1 -0
  644. data/src/ruby/spec/testdata/ca.pem +15 -0
  645. data/src/ruby/spec/testdata/server1.key +16 -0
  646. data/src/ruby/spec/testdata/server1.pem +16 -0
  647. data/src/ruby/spec/time_consts_spec.rb +89 -0
  648. data/third_party/boringssl/crypto/aes/aes.c +1142 -0
  649. data/third_party/boringssl/crypto/aes/internal.h +87 -0
  650. data/third_party/boringssl/crypto/aes/mode_wrappers.c +112 -0
  651. data/third_party/boringssl/crypto/asn1/a_bitstr.c +263 -0
  652. data/third_party/boringssl/crypto/asn1/a_bool.c +110 -0
  653. data/third_party/boringssl/crypto/asn1/a_d2i_fp.c +282 -0
  654. data/third_party/boringssl/crypto/asn1/a_dup.c +111 -0
  655. data/third_party/boringssl/crypto/asn1/a_enum.c +181 -0
  656. data/third_party/boringssl/crypto/asn1/a_gentm.c +256 -0
  657. data/third_party/boringssl/crypto/asn1/a_i2d_fp.c +147 -0
  658. data/third_party/boringssl/crypto/asn1/a_int.c +460 -0
  659. data/third_party/boringssl/crypto/asn1/a_mbstr.c +409 -0
  660. data/third_party/boringssl/crypto/asn1/a_object.c +400 -0
  661. data/third_party/boringssl/crypto/asn1/a_octet.c +77 -0
  662. data/third_party/boringssl/crypto/asn1/a_print.c +121 -0
  663. data/third_party/boringssl/crypto/asn1/a_strnid.c +309 -0
  664. data/third_party/boringssl/crypto/asn1/a_time.c +206 -0
  665. data/third_party/boringssl/crypto/asn1/a_type.c +151 -0
  666. data/third_party/boringssl/crypto/asn1/a_utctm.c +304 -0
  667. data/third_party/boringssl/crypto/asn1/a_utf8.c +234 -0
  668. data/third_party/boringssl/crypto/asn1/asn1_lib.c +483 -0
  669. data/third_party/boringssl/crypto/asn1/asn1_locl.h +63 -0
  670. data/third_party/boringssl/crypto/asn1/asn1_par.c +80 -0
  671. data/third_party/boringssl/crypto/asn1/asn_pack.c +105 -0
  672. data/third_party/boringssl/crypto/asn1/f_enum.c +93 -0
  673. data/third_party/boringssl/crypto/asn1/f_int.c +97 -0
  674. data/third_party/boringssl/crypto/asn1/f_string.c +91 -0
  675. data/third_party/boringssl/crypto/asn1/t_bitst.c +103 -0
  676. data/third_party/boringssl/crypto/asn1/tasn_dec.c +1221 -0
  677. data/third_party/boringssl/crypto/asn1/tasn_enc.c +665 -0
  678. data/third_party/boringssl/crypto/asn1/tasn_fre.c +246 -0
  679. data/third_party/boringssl/crypto/asn1/tasn_new.c +381 -0
  680. data/third_party/boringssl/crypto/asn1/tasn_typ.c +131 -0
  681. data/third_party/boringssl/crypto/asn1/tasn_utl.c +266 -0
  682. data/third_party/boringssl/crypto/asn1/x_bignum.c +153 -0
  683. data/third_party/boringssl/crypto/asn1/x_long.c +197 -0
  684. data/third_party/boringssl/crypto/base64/base64.c +442 -0
  685. data/third_party/boringssl/crypto/bio/bio.c +598 -0
  686. data/third_party/boringssl/crypto/bio/bio_mem.c +328 -0
  687. data/third_party/boringssl/crypto/bio/buffer.c +496 -0
  688. data/third_party/boringssl/crypto/bio/connect.c +553 -0
  689. data/third_party/boringssl/crypto/bio/fd.c +277 -0
  690. data/third_party/boringssl/crypto/bio/file.c +313 -0
  691. data/third_party/boringssl/crypto/bio/hexdump.c +191 -0
  692. data/third_party/boringssl/crypto/bio/internal.h +111 -0
  693. data/third_party/boringssl/crypto/bio/pair.c +803 -0
  694. data/third_party/boringssl/crypto/bio/printf.c +119 -0
  695. data/third_party/boringssl/crypto/bio/socket.c +203 -0
  696. data/third_party/boringssl/crypto/bio/socket_helper.c +113 -0
  697. data/third_party/boringssl/crypto/bn/add.c +377 -0
  698. data/third_party/boringssl/crypto/bn/asm/x86_64-gcc.c +531 -0
  699. data/third_party/boringssl/crypto/bn/bn.c +379 -0
  700. data/third_party/boringssl/crypto/bn/bn_asn1.c +80 -0
  701. data/third_party/boringssl/crypto/bn/cmp.c +225 -0
  702. data/third_party/boringssl/crypto/bn/convert.c +599 -0
  703. data/third_party/boringssl/crypto/bn/ctx.c +311 -0
  704. data/third_party/boringssl/crypto/bn/div.c +671 -0
  705. data/third_party/boringssl/crypto/bn/exponentiation.c +1258 -0
  706. data/third_party/boringssl/crypto/bn/gcd.c +628 -0
  707. data/third_party/boringssl/crypto/bn/generic.c +703 -0
  708. data/third_party/boringssl/crypto/bn/internal.h +245 -0
  709. data/third_party/boringssl/crypto/bn/kronecker.c +175 -0
  710. data/third_party/boringssl/crypto/bn/montgomery.c +410 -0
  711. data/third_party/boringssl/crypto/bn/montgomery_inv.c +160 -0
  712. data/third_party/boringssl/crypto/bn/mul.c +869 -0
  713. data/third_party/boringssl/crypto/bn/prime.c +861 -0
  714. data/third_party/boringssl/crypto/bn/random.c +340 -0
  715. data/third_party/boringssl/crypto/bn/rsaz_exp.c +319 -0
  716. data/third_party/boringssl/crypto/bn/rsaz_exp.h +56 -0
  717. data/third_party/boringssl/crypto/bn/shift.c +299 -0
  718. data/third_party/boringssl/crypto/bn/sqrt.c +504 -0
  719. data/third_party/boringssl/crypto/buf/buf.c +239 -0
  720. data/third_party/boringssl/crypto/bytestring/asn1_compat.c +51 -0
  721. data/third_party/boringssl/crypto/bytestring/ber.c +263 -0
  722. data/third_party/boringssl/crypto/bytestring/cbb.c +473 -0
  723. data/third_party/boringssl/crypto/bytestring/cbs.c +439 -0
  724. data/third_party/boringssl/crypto/bytestring/internal.h +75 -0
  725. data/third_party/boringssl/crypto/chacha/chacha.c +167 -0
  726. data/third_party/boringssl/crypto/cipher/aead.c +156 -0
  727. data/third_party/boringssl/crypto/cipher/cipher.c +652 -0
  728. data/third_party/boringssl/crypto/cipher/derive_key.c +154 -0
  729. data/third_party/boringssl/crypto/cipher/e_aes.c +1717 -0
  730. data/third_party/boringssl/crypto/cipher/e_chacha20poly1305.c +300 -0
  731. data/third_party/boringssl/crypto/cipher/e_des.c +205 -0
  732. data/third_party/boringssl/crypto/cipher/e_null.c +85 -0
  733. data/third_party/boringssl/crypto/cipher/e_rc2.c +443 -0
  734. data/third_party/boringssl/crypto/cipher/e_rc4.c +87 -0
  735. data/third_party/boringssl/crypto/cipher/e_ssl3.c +403 -0
  736. data/third_party/boringssl/crypto/cipher/e_tls.c +602 -0
  737. data/third_party/boringssl/crypto/cipher/internal.h +162 -0
  738. data/third_party/boringssl/crypto/cipher/tls_cbc.c +553 -0
  739. data/third_party/boringssl/crypto/cmac/cmac.c +239 -0
  740. data/third_party/boringssl/crypto/conf/conf.c +788 -0
  741. data/third_party/boringssl/crypto/conf/conf_def.h +127 -0
  742. data/third_party/boringssl/crypto/conf/internal.h +31 -0
  743. data/third_party/boringssl/crypto/cpu-aarch64-linux.c +61 -0
  744. data/third_party/boringssl/crypto/cpu-arm-linux.c +360 -0
  745. data/third_party/boringssl/crypto/cpu-arm.c +38 -0
  746. data/third_party/boringssl/crypto/cpu-intel.c +263 -0
  747. data/third_party/boringssl/crypto/cpu-ppc64le.c +40 -0
  748. data/third_party/boringssl/crypto/crypto.c +164 -0
  749. data/third_party/boringssl/crypto/curve25519/curve25519.c +4944 -0
  750. data/third_party/boringssl/crypto/curve25519/internal.h +109 -0
  751. data/third_party/boringssl/crypto/curve25519/spake25519.c +464 -0
  752. data/third_party/boringssl/crypto/curve25519/x25519-x86_64.c +246 -0
  753. data/third_party/boringssl/crypto/des/des.c +771 -0
  754. data/third_party/boringssl/crypto/des/internal.h +212 -0
  755. data/third_party/boringssl/crypto/dh/check.c +218 -0
  756. data/third_party/boringssl/crypto/dh/dh.c +487 -0
  757. data/third_party/boringssl/crypto/dh/dh_asn1.c +160 -0
  758. data/third_party/boringssl/crypto/dh/params.c +253 -0
  759. data/third_party/boringssl/crypto/digest/digest.c +248 -0
  760. data/third_party/boringssl/crypto/digest/digests.c +321 -0
  761. data/third_party/boringssl/crypto/digest/internal.h +112 -0
  762. data/third_party/boringssl/crypto/digest/md32_common.h +262 -0
  763. data/third_party/boringssl/crypto/dsa/dsa.c +964 -0
  764. data/third_party/boringssl/crypto/dsa/dsa_asn1.c +339 -0
  765. data/third_party/boringssl/crypto/ec/ec.c +847 -0
  766. data/third_party/boringssl/crypto/ec/ec_asn1.c +549 -0
  767. data/third_party/boringssl/crypto/ec/ec_key.c +479 -0
  768. data/third_party/boringssl/crypto/ec/ec_montgomery.c +308 -0
  769. data/third_party/boringssl/crypto/ec/internal.h +276 -0
  770. data/third_party/boringssl/crypto/ec/oct.c +428 -0
  771. data/third_party/boringssl/crypto/ec/p224-64.c +1187 -0
  772. data/third_party/boringssl/crypto/ec/p256-64.c +1741 -0
  773. data/third_party/boringssl/crypto/ec/p256-x86_64-table.h +9543 -0
  774. data/third_party/boringssl/crypto/ec/p256-x86_64.c +574 -0
  775. data/third_party/boringssl/crypto/ec/simple.c +1117 -0
  776. data/third_party/boringssl/crypto/ec/util-64.c +109 -0
  777. data/third_party/boringssl/crypto/ec/wnaf.c +449 -0
  778. data/third_party/boringssl/crypto/ecdh/ecdh.c +159 -0
  779. data/third_party/boringssl/crypto/ecdsa/ecdsa.c +478 -0
  780. data/third_party/boringssl/crypto/ecdsa/ecdsa_asn1.c +227 -0
  781. data/third_party/boringssl/crypto/engine/engine.c +96 -0
  782. data/third_party/boringssl/crypto/err/err.c +756 -0
  783. data/third_party/boringssl/crypto/evp/digestsign.c +159 -0
  784. data/third_party/boringssl/crypto/evp/evp.c +367 -0
  785. data/third_party/boringssl/crypto/evp/evp_asn1.c +337 -0
  786. data/third_party/boringssl/crypto/evp/evp_ctx.c +448 -0
  787. data/third_party/boringssl/crypto/evp/internal.h +237 -0
  788. data/third_party/boringssl/crypto/evp/p_dsa_asn1.c +268 -0
  789. data/third_party/boringssl/crypto/evp/p_ec.c +236 -0
  790. data/third_party/boringssl/crypto/evp/p_ec_asn1.c +257 -0
  791. data/third_party/boringssl/crypto/evp/p_rsa.c +673 -0
  792. data/third_party/boringssl/crypto/evp/p_rsa_asn1.c +200 -0
  793. data/third_party/boringssl/crypto/evp/pbkdf.c +151 -0
  794. data/third_party/boringssl/crypto/evp/print.c +520 -0
  795. data/third_party/boringssl/crypto/evp/sign.c +151 -0
  796. data/third_party/boringssl/crypto/ex_data.c +292 -0
  797. data/third_party/boringssl/crypto/hkdf/hkdf.c +110 -0
  798. data/third_party/boringssl/crypto/hmac/hmac.c +213 -0
  799. data/third_party/boringssl/crypto/internal.h +527 -0
  800. data/third_party/boringssl/crypto/lhash/lhash.c +342 -0
  801. data/third_party/boringssl/crypto/md4/md4.c +234 -0
  802. data/third_party/boringssl/crypto/md5/md5.c +275 -0
  803. data/third_party/boringssl/crypto/mem.c +200 -0
  804. data/third_party/boringssl/crypto/modes/cbc.c +216 -0
  805. data/third_party/boringssl/crypto/modes/cfb.c +230 -0
  806. data/third_party/boringssl/crypto/modes/ctr.c +219 -0
  807. data/third_party/boringssl/crypto/modes/gcm.c +1288 -0
  808. data/third_party/boringssl/crypto/modes/internal.h +358 -0
  809. data/third_party/boringssl/crypto/modes/ofb.c +95 -0
  810. data/third_party/boringssl/crypto/newhope/error_correction.c +131 -0
  811. data/third_party/boringssl/crypto/newhope/internal.h +71 -0
  812. data/third_party/boringssl/crypto/newhope/newhope.c +174 -0
  813. data/third_party/boringssl/crypto/newhope/ntt.c +148 -0
  814. data/third_party/boringssl/crypto/newhope/poly.c +183 -0
  815. data/third_party/boringssl/crypto/newhope/precomp.c +306 -0
  816. data/third_party/boringssl/crypto/newhope/reduce.c +42 -0
  817. data/third_party/boringssl/crypto/obj/obj.c +640 -0
  818. data/third_party/boringssl/crypto/obj/obj_dat.h +5254 -0
  819. data/third_party/boringssl/crypto/obj/obj_xref.c +124 -0
  820. data/third_party/boringssl/crypto/obj/obj_xref.h +96 -0
  821. data/third_party/boringssl/crypto/pem/pem_all.c +262 -0
  822. data/third_party/boringssl/crypto/pem/pem_info.c +381 -0
  823. data/third_party/boringssl/crypto/pem/pem_lib.c +778 -0
  824. data/third_party/boringssl/crypto/pem/pem_oth.c +88 -0
  825. data/third_party/boringssl/crypto/pem/pem_pk8.c +257 -0
  826. data/third_party/boringssl/crypto/pem/pem_pkey.c +227 -0
  827. data/third_party/boringssl/crypto/pem/pem_x509.c +65 -0
  828. data/third_party/boringssl/crypto/pem/pem_xaux.c +67 -0
  829. data/third_party/boringssl/crypto/pkcs8/internal.h +83 -0
  830. data/third_party/boringssl/crypto/pkcs8/p5_pbe.c +151 -0
  831. data/third_party/boringssl/crypto/pkcs8/p5_pbev2.c +441 -0
  832. data/third_party/boringssl/crypto/pkcs8/p8_pkey.c +85 -0
  833. data/third_party/boringssl/crypto/pkcs8/pkcs8.c +1219 -0
  834. data/third_party/boringssl/crypto/poly1305/internal.h +40 -0
  835. data/third_party/boringssl/crypto/poly1305/poly1305.c +324 -0
  836. data/third_party/boringssl/crypto/poly1305/poly1305_arm.c +304 -0
  837. data/third_party/boringssl/crypto/poly1305/poly1305_vec.c +890 -0
  838. data/third_party/boringssl/crypto/rand/deterministic.c +47 -0
  839. data/third_party/boringssl/crypto/rand/internal.h +32 -0
  840. data/third_party/boringssl/crypto/rand/rand.c +244 -0
  841. data/third_party/boringssl/crypto/rand/urandom.c +221 -0
  842. data/third_party/boringssl/crypto/rand/windows.c +53 -0
  843. data/third_party/boringssl/crypto/rc4/rc4.c +98 -0
  844. data/third_party/boringssl/crypto/refcount_c11.c +67 -0
  845. data/third_party/boringssl/crypto/refcount_lock.c +53 -0
  846. data/third_party/boringssl/crypto/rsa/blinding.c +264 -0
  847. data/third_party/boringssl/crypto/rsa/internal.h +148 -0
  848. data/third_party/boringssl/crypto/rsa/padding.c +708 -0
  849. data/third_party/boringssl/crypto/rsa/rsa.c +830 -0
  850. data/third_party/boringssl/crypto/rsa/rsa_asn1.c +446 -0
  851. data/third_party/boringssl/crypto/rsa/rsa_impl.c +1139 -0
  852. data/third_party/boringssl/crypto/sha/sha1.c +337 -0
  853. data/third_party/boringssl/crypto/sha/sha256.c +327 -0
  854. data/third_party/boringssl/crypto/sha/sha512.c +607 -0
  855. data/third_party/boringssl/crypto/stack/stack.c +377 -0
  856. data/third_party/boringssl/crypto/thread.c +110 -0
  857. data/third_party/boringssl/crypto/thread_none.c +59 -0
  858. data/third_party/boringssl/crypto/thread_pthread.c +176 -0
  859. data/third_party/boringssl/crypto/thread_win.c +237 -0
  860. data/third_party/boringssl/crypto/time_support.c +206 -0
  861. data/third_party/boringssl/crypto/x509/a_digest.c +96 -0
  862. data/third_party/boringssl/crypto/x509/a_sign.c +135 -0
  863. data/third_party/boringssl/crypto/x509/a_strex.c +633 -0
  864. data/third_party/boringssl/crypto/x509/a_verify.c +127 -0
  865. data/third_party/boringssl/crypto/x509/algorithm.c +137 -0
  866. data/third_party/boringssl/crypto/x509/asn1_gen.c +818 -0
  867. data/third_party/boringssl/crypto/x509/by_dir.c +453 -0
  868. data/third_party/boringssl/crypto/x509/by_file.c +275 -0
  869. data/third_party/boringssl/crypto/x509/charmap.h +15 -0
  870. data/third_party/boringssl/crypto/x509/i2d_pr.c +83 -0
  871. data/third_party/boringssl/crypto/x509/internal.h +66 -0
  872. data/third_party/boringssl/crypto/x509/pkcs7.c +353 -0
  873. data/third_party/boringssl/crypto/x509/rsa_pss.c +385 -0
  874. data/third_party/boringssl/crypto/x509/t_crl.c +128 -0
  875. data/third_party/boringssl/crypto/x509/t_req.c +246 -0
  876. data/third_party/boringssl/crypto/x509/t_x509.c +506 -0
  877. data/third_party/boringssl/crypto/x509/t_x509a.c +111 -0
  878. data/third_party/boringssl/crypto/x509/vpm_int.h +70 -0
  879. data/third_party/boringssl/crypto/x509/x509.c +157 -0
  880. data/third_party/boringssl/crypto/x509/x509_att.c +381 -0
  881. data/third_party/boringssl/crypto/x509/x509_cmp.c +474 -0
  882. data/third_party/boringssl/crypto/x509/x509_d2.c +106 -0
  883. data/third_party/boringssl/crypto/x509/x509_def.c +98 -0
  884. data/third_party/boringssl/crypto/x509/x509_ext.c +206 -0
  885. data/third_party/boringssl/crypto/x509/x509_lu.c +690 -0
  886. data/third_party/boringssl/crypto/x509/x509_obj.c +197 -0
  887. data/third_party/boringssl/crypto/x509/x509_r2x.c +117 -0
  888. data/third_party/boringssl/crypto/x509/x509_req.c +322 -0
  889. data/third_party/boringssl/crypto/x509/x509_set.c +154 -0
  890. data/third_party/boringssl/crypto/x509/x509_trs.c +326 -0
  891. data/third_party/boringssl/crypto/x509/x509_txt.c +211 -0
  892. data/third_party/boringssl/crypto/x509/x509_v3.c +278 -0
  893. data/third_party/boringssl/crypto/x509/x509_vfy.c +2436 -0
  894. data/third_party/boringssl/crypto/x509/x509_vpm.c +647 -0
  895. data/third_party/boringssl/crypto/x509/x509cset.c +170 -0
  896. data/third_party/boringssl/crypto/x509/x509name.c +386 -0
  897. data/third_party/boringssl/crypto/x509/x509rset.c +81 -0
  898. data/third_party/boringssl/crypto/x509/x509spki.c +137 -0
  899. data/third_party/boringssl/crypto/x509/x509type.c +126 -0
  900. data/third_party/boringssl/crypto/x509/x_algor.c +151 -0
  901. data/third_party/boringssl/crypto/x509/x_all.c +501 -0
  902. data/third_party/boringssl/crypto/x509/x_attrib.c +111 -0
  903. data/third_party/boringssl/crypto/x509/x_crl.c +539 -0
  904. data/third_party/boringssl/crypto/x509/x_exten.c +75 -0
  905. data/third_party/boringssl/crypto/x509/x_info.c +98 -0
  906. data/third_party/boringssl/crypto/x509/x_name.c +534 -0
  907. data/third_party/boringssl/crypto/x509/x_pkey.c +103 -0
  908. data/third_party/boringssl/crypto/x509/x_pubkey.c +368 -0
  909. data/third_party/boringssl/crypto/x509/x_req.c +109 -0
  910. data/third_party/boringssl/crypto/x509/x_sig.c +69 -0
  911. data/third_party/boringssl/crypto/x509/x_spki.c +80 -0
  912. data/third_party/boringssl/crypto/x509/x_val.c +69 -0
  913. data/third_party/boringssl/crypto/x509/x_x509.c +289 -0
  914. data/third_party/boringssl/crypto/x509/x_x509a.c +205 -0
  915. data/third_party/boringssl/crypto/x509v3/ext_dat.h +135 -0
  916. data/third_party/boringssl/crypto/x509v3/pcy_cache.c +284 -0
  917. data/third_party/boringssl/crypto/x509v3/pcy_data.c +130 -0
  918. data/third_party/boringssl/crypto/x509v3/pcy_int.h +217 -0
  919. data/third_party/boringssl/crypto/x509v3/pcy_lib.c +164 -0
  920. data/third_party/boringssl/crypto/x509v3/pcy_map.c +130 -0
  921. data/third_party/boringssl/crypto/x509v3/pcy_node.c +188 -0
  922. data/third_party/boringssl/crypto/x509v3/pcy_tree.c +829 -0
  923. data/third_party/boringssl/crypto/x509v3/v3_akey.c +204 -0
  924. data/third_party/boringssl/crypto/x509v3/v3_akeya.c +72 -0
  925. data/third_party/boringssl/crypto/x509v3/v3_alt.c +614 -0
  926. data/third_party/boringssl/crypto/x509v3/v3_bcons.c +133 -0
  927. data/third_party/boringssl/crypto/x509v3/v3_bitst.c +141 -0
  928. data/third_party/boringssl/crypto/x509v3/v3_conf.c +462 -0
  929. data/third_party/boringssl/crypto/x509v3/v3_cpols.c +496 -0
  930. data/third_party/boringssl/crypto/x509v3/v3_crld.c +561 -0
  931. data/third_party/boringssl/crypto/x509v3/v3_enum.c +100 -0
  932. data/third_party/boringssl/crypto/x509v3/v3_extku.c +148 -0
  933. data/third_party/boringssl/crypto/x509v3/v3_genn.c +250 -0
  934. data/third_party/boringssl/crypto/x509v3/v3_ia5.c +119 -0
  935. data/third_party/boringssl/crypto/x509v3/v3_info.c +212 -0
  936. data/third_party/boringssl/crypto/x509v3/v3_int.c +91 -0
  937. data/third_party/boringssl/crypto/x509v3/v3_lib.c +362 -0
  938. data/third_party/boringssl/crypto/x509v3/v3_ncons.c +482 -0
  939. data/third_party/boringssl/crypto/x509v3/v3_pci.c +317 -0
  940. data/third_party/boringssl/crypto/x509v3/v3_pcia.c +57 -0
  941. data/third_party/boringssl/crypto/x509v3/v3_pcons.c +139 -0
  942. data/third_party/boringssl/crypto/x509v3/v3_pku.c +110 -0
  943. data/third_party/boringssl/crypto/x509v3/v3_pmaps.c +154 -0
  944. data/third_party/boringssl/crypto/x509v3/v3_prn.c +229 -0
  945. data/third_party/boringssl/crypto/x509v3/v3_purp.c +874 -0
  946. data/third_party/boringssl/crypto/x509v3/v3_skey.c +152 -0
  947. data/third_party/boringssl/crypto/x509v3/v3_sxnet.c +274 -0
  948. data/third_party/boringssl/crypto/x509v3/v3_utl.c +1327 -0
  949. data/third_party/boringssl/include/openssl/aead.h +345 -0
  950. data/third_party/boringssl/include/openssl/aes.h +158 -0
  951. data/third_party/boringssl/include/openssl/arm_arch.h +121 -0
  952. data/third_party/boringssl/include/openssl/asn1.h +1038 -0
  953. data/third_party/boringssl/include/openssl/asn1_mac.h +18 -0
  954. data/third_party/boringssl/include/openssl/asn1t.h +896 -0
  955. data/third_party/boringssl/include/openssl/base.h +412 -0
  956. data/third_party/boringssl/include/openssl/base64.h +187 -0
  957. data/third_party/boringssl/include/openssl/bio.h +926 -0
  958. data/third_party/boringssl/include/openssl/blowfish.h +93 -0
  959. data/third_party/boringssl/include/openssl/bn.h +955 -0
  960. data/third_party/boringssl/include/openssl/buf.h +133 -0
  961. data/third_party/boringssl/include/openssl/buffer.h +18 -0
  962. data/third_party/boringssl/include/openssl/bytestring.h +437 -0
  963. data/third_party/boringssl/include/openssl/cast.h +96 -0
  964. data/third_party/boringssl/include/openssl/chacha.h +37 -0
  965. data/third_party/boringssl/include/openssl/cipher.h +588 -0
  966. data/third_party/boringssl/include/openssl/cmac.h +87 -0
  967. data/third_party/boringssl/include/openssl/conf.h +181 -0
  968. data/third_party/boringssl/include/openssl/cpu.h +181 -0
  969. data/third_party/boringssl/include/openssl/crypto.h +94 -0
  970. data/third_party/boringssl/include/openssl/curve25519.h +183 -0
  971. data/third_party/boringssl/include/openssl/des.h +177 -0
  972. data/third_party/boringssl/include/openssl/dh.h +297 -0
  973. data/third_party/boringssl/include/openssl/digest.h +285 -0
  974. data/third_party/boringssl/include/openssl/dsa.h +436 -0
  975. data/third_party/boringssl/include/openssl/dtls1.h +16 -0
  976. data/third_party/boringssl/include/openssl/ec.h +406 -0
  977. data/third_party/boringssl/include/openssl/ec_key.h +337 -0
  978. data/third_party/boringssl/include/openssl/ecdh.h +102 -0
  979. data/third_party/boringssl/include/openssl/ecdsa.h +217 -0
  980. data/third_party/boringssl/include/openssl/engine.h +109 -0
  981. data/third_party/boringssl/include/openssl/err.h +488 -0
  982. data/third_party/boringssl/include/openssl/evp.h +797 -0
  983. data/third_party/boringssl/include/openssl/ex_data.h +213 -0
  984. data/third_party/boringssl/include/openssl/hkdf.h +64 -0
  985. data/third_party/boringssl/include/openssl/hmac.h +174 -0
  986. data/third_party/boringssl/include/openssl/lhash.h +192 -0
  987. data/third_party/boringssl/include/openssl/lhash_macros.h +132 -0
  988. data/third_party/boringssl/include/openssl/md4.h +106 -0
  989. data/third_party/boringssl/include/openssl/md5.h +107 -0
  990. data/third_party/boringssl/include/openssl/mem.h +150 -0
  991. data/third_party/boringssl/include/openssl/newhope.h +158 -0
  992. data/third_party/boringssl/include/openssl/nid.h +4166 -0
  993. data/third_party/boringssl/include/openssl/obj.h +226 -0
  994. data/third_party/boringssl/include/openssl/obj_mac.h +18 -0
  995. data/third_party/boringssl/include/openssl/objects.h +18 -0
  996. data/third_party/boringssl/include/openssl/opensslconf.h +60 -0
  997. data/third_party/boringssl/include/openssl/opensslv.h +18 -0
  998. data/third_party/boringssl/include/openssl/ossl_typ.h +18 -0
  999. data/third_party/boringssl/include/openssl/pem.h +517 -0
  1000. data/third_party/boringssl/include/openssl/pkcs12.h +18 -0
  1001. data/third_party/boringssl/include/openssl/pkcs7.h +16 -0
  1002. data/third_party/boringssl/include/openssl/pkcs8.h +236 -0
  1003. data/third_party/boringssl/include/openssl/poly1305.h +51 -0
  1004. data/third_party/boringssl/include/openssl/rand.h +122 -0
  1005. data/third_party/boringssl/include/openssl/rc4.h +96 -0
  1006. data/third_party/boringssl/include/openssl/ripemd.h +107 -0
  1007. data/third_party/boringssl/include/openssl/rsa.h +699 -0
  1008. data/third_party/boringssl/include/openssl/safestack.h +16 -0
  1009. data/third_party/boringssl/include/openssl/sha.h +260 -0
  1010. data/third_party/boringssl/include/openssl/srtp.h +18 -0
  1011. data/third_party/boringssl/include/openssl/ssl.h +4826 -0
  1012. data/third_party/boringssl/include/openssl/ssl3.h +434 -0
  1013. data/third_party/boringssl/include/openssl/stack.h +293 -0
  1014. data/third_party/boringssl/include/openssl/stack_macros.h +3902 -0
  1015. data/third_party/boringssl/include/openssl/thread.h +191 -0
  1016. data/third_party/boringssl/include/openssl/time_support.h +91 -0
  1017. data/third_party/boringssl/include/openssl/tls1.h +657 -0
  1018. data/third_party/boringssl/include/openssl/type_check.h +91 -0
  1019. data/third_party/boringssl/include/openssl/x509.h +1299 -0
  1020. data/third_party/boringssl/include/openssl/x509_vfy.h +618 -0
  1021. data/third_party/boringssl/include/openssl/x509v3.h +819 -0
  1022. data/third_party/boringssl/ssl/custom_extensions.c +255 -0
  1023. data/third_party/boringssl/ssl/d1_both.c +845 -0
  1024. data/third_party/boringssl/ssl/d1_lib.c +270 -0
  1025. data/third_party/boringssl/ssl/d1_pkt.c +419 -0
  1026. data/third_party/boringssl/ssl/d1_srtp.c +236 -0
  1027. data/third_party/boringssl/ssl/dtls_method.c +203 -0
  1028. data/third_party/boringssl/ssl/dtls_record.c +309 -0
  1029. data/third_party/boringssl/ssl/handshake_client.c +2002 -0
  1030. data/third_party/boringssl/ssl/handshake_server.c +1932 -0
  1031. data/third_party/boringssl/ssl/internal.h +1551 -0
  1032. data/third_party/boringssl/ssl/s3_both.c +745 -0
  1033. data/third_party/boringssl/ssl/s3_enc.c +412 -0
  1034. data/third_party/boringssl/ssl/s3_lib.c +336 -0
  1035. data/third_party/boringssl/ssl/s3_pkt.c +497 -0
  1036. data/third_party/boringssl/ssl/ssl_aead_ctx.c +329 -0
  1037. data/third_party/boringssl/ssl/ssl_asn1.c +748 -0
  1038. data/third_party/boringssl/ssl/ssl_buffer.c +311 -0
  1039. data/third_party/boringssl/ssl/ssl_cert.c +814 -0
  1040. data/third_party/boringssl/ssl/ssl_cipher.c +2062 -0
  1041. data/third_party/boringssl/ssl/ssl_ecdh.c +610 -0
  1042. data/third_party/boringssl/ssl/ssl_file.c +586 -0
  1043. data/third_party/boringssl/ssl/ssl_lib.c +3063 -0
  1044. data/third_party/boringssl/ssl/ssl_rsa.c +793 -0
  1045. data/third_party/boringssl/ssl/ssl_session.c +985 -0
  1046. data/third_party/boringssl/ssl/ssl_stat.c +509 -0
  1047. data/third_party/boringssl/ssl/t1_enc.c +547 -0
  1048. data/third_party/boringssl/ssl/t1_lib.c +3279 -0
  1049. data/third_party/boringssl/ssl/tls13_both.c +440 -0
  1050. data/third_party/boringssl/ssl/tls13_client.c +682 -0
  1051. data/third_party/boringssl/ssl/tls13_enc.c +391 -0
  1052. data/third_party/boringssl/ssl/tls13_server.c +672 -0
  1053. data/third_party/boringssl/ssl/tls_method.c +245 -0
  1054. data/third_party/boringssl/ssl/tls_record.c +461 -0
  1055. data/third_party/cares/ares_build.h +264 -0
  1056. data/third_party/cares/cares/ares.h +636 -0
  1057. data/third_party/cares/cares/ares__close_sockets.c +61 -0
  1058. data/third_party/cares/cares/ares__get_hostent.c +261 -0
  1059. data/third_party/cares/cares/ares__read_line.c +73 -0
  1060. data/third_party/cares/cares/ares__timeval.c +111 -0
  1061. data/third_party/cares/cares/ares_cancel.c +63 -0
  1062. data/third_party/cares/cares/ares_create_query.c +202 -0
  1063. data/third_party/cares/cares/ares_data.c +221 -0
  1064. data/third_party/cares/cares/ares_data.h +72 -0
  1065. data/third_party/cares/cares/ares_destroy.c +108 -0
  1066. data/third_party/cares/cares/ares_dns.h +103 -0
  1067. data/third_party/cares/cares/ares_expand_name.c +205 -0
  1068. data/third_party/cares/cares/ares_expand_string.c +70 -0
  1069. data/third_party/cares/cares/ares_fds.c +59 -0
  1070. data/third_party/cares/cares/ares_free_hostent.c +41 -0
  1071. data/third_party/cares/cares/ares_free_string.c +25 -0
  1072. data/third_party/cares/cares/ares_getenv.c +30 -0
  1073. data/third_party/cares/cares/ares_getenv.h +26 -0
  1074. data/third_party/cares/cares/ares_gethostbyaddr.c +294 -0
  1075. data/third_party/cares/cares/ares_gethostbyname.c +518 -0
  1076. data/third_party/cares/cares/ares_getnameinfo.c +422 -0
  1077. data/third_party/cares/cares/ares_getopt.c +122 -0
  1078. data/third_party/cares/cares/ares_getopt.h +53 -0
  1079. data/third_party/cares/cares/ares_getsock.c +66 -0
  1080. data/third_party/cares/cares/ares_inet_net_pton.h +25 -0
  1081. data/third_party/cares/cares/ares_init.c +2146 -0
  1082. data/third_party/cares/cares/ares_iphlpapi.h +221 -0
  1083. data/third_party/cares/cares/ares_ipv6.h +78 -0
  1084. data/third_party/cares/cares/ares_library_init.c +167 -0
  1085. data/third_party/cares/cares/ares_library_init.h +42 -0
  1086. data/third_party/cares/cares/ares_llist.c +63 -0
  1087. data/third_party/cares/cares/ares_llist.h +39 -0
  1088. data/third_party/cares/cares/ares_mkquery.c +24 -0
  1089. data/third_party/cares/cares/ares_nowarn.c +260 -0
  1090. data/third_party/cares/cares/ares_nowarn.h +61 -0
  1091. data/third_party/cares/cares/ares_options.c +402 -0
  1092. data/third_party/cares/cares/ares_parse_a_reply.c +264 -0
  1093. data/third_party/cares/cares/ares_parse_aaaa_reply.c +264 -0
  1094. data/third_party/cares/cares/ares_parse_mx_reply.c +170 -0
  1095. data/third_party/cares/cares/ares_parse_naptr_reply.c +188 -0
  1096. data/third_party/cares/cares/ares_parse_ns_reply.c +183 -0
  1097. data/third_party/cares/cares/ares_parse_ptr_reply.c +219 -0
  1098. data/third_party/cares/cares/ares_parse_soa_reply.c +133 -0
  1099. data/third_party/cares/cares/ares_parse_srv_reply.c +179 -0
  1100. data/third_party/cares/cares/ares_parse_txt_reply.c +220 -0
  1101. data/third_party/cares/cares/ares_platform.c +11035 -0
  1102. data/third_party/cares/cares/ares_platform.h +43 -0
  1103. data/third_party/cares/cares/ares_private.h +363 -0
  1104. data/third_party/cares/cares/ares_process.c +1359 -0
  1105. data/third_party/cares/cares/ares_query.c +186 -0
  1106. data/third_party/cares/cares/ares_rules.h +125 -0
  1107. data/third_party/cares/cares/ares_search.c +316 -0
  1108. data/third_party/cares/cares/ares_send.c +131 -0
  1109. data/third_party/cares/cares/ares_setup.h +217 -0
  1110. data/third_party/cares/cares/ares_strcasecmp.c +66 -0
  1111. data/third_party/cares/cares/ares_strcasecmp.h +30 -0
  1112. data/third_party/cares/cares/ares_strdup.c +49 -0
  1113. data/third_party/cares/cares/ares_strdup.h +24 -0
  1114. data/third_party/cares/cares/ares_strerror.c +56 -0
  1115. data/third_party/cares/cares/ares_timeout.c +88 -0
  1116. data/third_party/cares/cares/ares_version.c +11 -0
  1117. data/third_party/cares/cares/ares_version.h +24 -0
  1118. data/third_party/cares/cares/ares_writev.c +79 -0
  1119. data/third_party/cares/cares/bitncmp.c +59 -0
  1120. data/third_party/cares/cares/bitncmp.h +26 -0
  1121. data/third_party/cares/cares/config-win32.h +377 -0
  1122. data/third_party/cares/cares/inet_net_pton.c +450 -0
  1123. data/third_party/cares/cares/inet_ntop.c +208 -0
  1124. data/third_party/cares/cares/setup_once.h +554 -0
  1125. data/third_party/cares/cares/windows_port.c +22 -0
  1126. data/third_party/cares/config_darwin/ares_config.h +523 -0
  1127. data/third_party/cares/config_linux/ares_config.h +524 -0
  1128. data/third_party/nanopb/pb.h +579 -0
  1129. data/third_party/nanopb/pb_common.c +97 -0
  1130. data/third_party/nanopb/pb_common.h +42 -0
  1131. data/third_party/nanopb/pb_decode.c +1347 -0
  1132. data/third_party/nanopb/pb_decode.h +149 -0
  1133. data/third_party/nanopb/pb_encode.c +696 -0
  1134. data/third_party/nanopb/pb_encode.h +154 -0
  1135. data/third_party/zlib/adler32.c +179 -0
  1136. data/third_party/zlib/compress.c +80 -0
  1137. data/third_party/zlib/crc32.c +425 -0
  1138. data/third_party/zlib/crc32.h +441 -0
  1139. data/third_party/zlib/deflate.c +1967 -0
  1140. data/third_party/zlib/deflate.h +346 -0
  1141. data/third_party/zlib/gzclose.c +25 -0
  1142. data/third_party/zlib/gzguts.h +209 -0
  1143. data/third_party/zlib/gzlib.c +634 -0
  1144. data/third_party/zlib/gzread.c +594 -0
  1145. data/third_party/zlib/gzwrite.c +577 -0
  1146. data/third_party/zlib/infback.c +640 -0
  1147. data/third_party/zlib/inffast.c +340 -0
  1148. data/third_party/zlib/inffast.h +11 -0
  1149. data/third_party/zlib/inffixed.h +94 -0
  1150. data/third_party/zlib/inflate.c +1512 -0
  1151. data/third_party/zlib/inflate.h +122 -0
  1152. data/third_party/zlib/inftrees.c +306 -0
  1153. data/third_party/zlib/inftrees.h +62 -0
  1154. data/third_party/zlib/trees.c +1226 -0
  1155. data/third_party/zlib/trees.h +128 -0
  1156. data/third_party/zlib/uncompr.c +59 -0
  1157. data/third_party/zlib/zconf.h +511 -0
  1158. data/third_party/zlib/zlib.h +1768 -0
  1159. data/third_party/zlib/zutil.c +324 -0
  1160. data/third_party/zlib/zutil.h +253 -0
  1161. metadata +1397 -0
@@ -0,0 +1,2436 @@
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
+ #include <string.h>
58
+ #include <time.h>
59
+
60
+ #include <openssl/asn1.h>
61
+ #include <openssl/buf.h>
62
+ #include <openssl/err.h>
63
+ #include <openssl/evp.h>
64
+ #include <openssl/lhash.h>
65
+ #include <openssl/mem.h>
66
+ #include <openssl/obj.h>
67
+ #include <openssl/thread.h>
68
+ #include <openssl/x509.h>
69
+ #include <openssl/x509v3.h>
70
+
71
+ #include "vpm_int.h"
72
+ #include "../internal.h"
73
+
74
+ static CRYPTO_EX_DATA_CLASS g_ex_data_class =
75
+ CRYPTO_EX_DATA_CLASS_INIT_WITH_APP_DATA;
76
+
77
+ /* CRL score values */
78
+
79
+ /* No unhandled critical extensions */
80
+
81
+ #define CRL_SCORE_NOCRITICAL 0x100
82
+
83
+ /* certificate is within CRL scope */
84
+
85
+ #define CRL_SCORE_SCOPE 0x080
86
+
87
+ /* CRL times valid */
88
+
89
+ #define CRL_SCORE_TIME 0x040
90
+
91
+ /* Issuer name matches certificate */
92
+
93
+ #define CRL_SCORE_ISSUER_NAME 0x020
94
+
95
+ /* If this score or above CRL is probably valid */
96
+
97
+ #define CRL_SCORE_VALID (CRL_SCORE_NOCRITICAL|CRL_SCORE_TIME|CRL_SCORE_SCOPE)
98
+
99
+ /* CRL issuer is certificate issuer */
100
+
101
+ #define CRL_SCORE_ISSUER_CERT 0x018
102
+
103
+ /* CRL issuer is on certificate path */
104
+
105
+ #define CRL_SCORE_SAME_PATH 0x008
106
+
107
+ /* CRL issuer matches CRL AKID */
108
+
109
+ #define CRL_SCORE_AKID 0x004
110
+
111
+ /* Have a delta CRL with valid times */
112
+
113
+ #define CRL_SCORE_TIME_DELTA 0x002
114
+
115
+ static int null_callback(int ok, X509_STORE_CTX *e);
116
+ static int check_issued(X509_STORE_CTX *ctx, X509 *x, X509 *issuer);
117
+ static X509 *find_issuer(X509_STORE_CTX *ctx, STACK_OF(X509) *sk, X509 *x);
118
+ static int check_chain_extensions(X509_STORE_CTX *ctx);
119
+ static int check_name_constraints(X509_STORE_CTX *ctx);
120
+ static int check_id(X509_STORE_CTX *ctx);
121
+ static int check_trust(X509_STORE_CTX *ctx);
122
+ static int check_revocation(X509_STORE_CTX *ctx);
123
+ static int check_cert(X509_STORE_CTX *ctx);
124
+ static int check_policy(X509_STORE_CTX *ctx);
125
+
126
+ static int get_crl_score(X509_STORE_CTX *ctx, X509 **pissuer,
127
+ unsigned int *preasons, X509_CRL *crl, X509 *x);
128
+ static int get_crl_delta(X509_STORE_CTX *ctx,
129
+ X509_CRL **pcrl, X509_CRL **pdcrl, X509 *x);
130
+ static void get_delta_sk(X509_STORE_CTX *ctx, X509_CRL **dcrl,
131
+ int *pcrl_score, X509_CRL *base,
132
+ STACK_OF(X509_CRL) *crls);
133
+ static void crl_akid_check(X509_STORE_CTX *ctx, X509_CRL *crl, X509 **pissuer,
134
+ int *pcrl_score);
135
+ static int crl_crldp_check(X509 *x, X509_CRL *crl, int crl_score,
136
+ unsigned int *preasons);
137
+ static int check_crl_path(X509_STORE_CTX *ctx, X509 *x);
138
+ static int check_crl_chain(X509_STORE_CTX *ctx,
139
+ STACK_OF(X509) *cert_path,
140
+ STACK_OF(X509) *crl_path);
141
+
142
+ static int internal_verify(X509_STORE_CTX *ctx);
143
+
144
+ static int null_callback(int ok, X509_STORE_CTX *e)
145
+ {
146
+ return ok;
147
+ }
148
+
149
+ #if 0
150
+ static int x509_subject_cmp(X509 **a, X509 **b)
151
+ {
152
+ return X509_subject_name_cmp(*a, *b);
153
+ }
154
+ #endif
155
+ /* Return 1 is a certificate is self signed */
156
+ static int cert_self_signed(X509 *x)
157
+ {
158
+ X509_check_purpose(x, -1, 0);
159
+ if (x->ex_flags & EXFLAG_SS)
160
+ return 1;
161
+ else
162
+ return 0;
163
+ }
164
+
165
+ /* Given a certificate try and find an exact match in the store */
166
+
167
+ static X509 *lookup_cert_match(X509_STORE_CTX *ctx, X509 *x)
168
+ {
169
+ STACK_OF(X509) *certs;
170
+ X509 *xtmp = NULL;
171
+ size_t i;
172
+ /* Lookup all certs with matching subject name */
173
+ certs = ctx->lookup_certs(ctx, X509_get_subject_name(x));
174
+ if (certs == NULL)
175
+ return NULL;
176
+ /* Look for exact match */
177
+ for (i = 0; i < sk_X509_num(certs); i++) {
178
+ xtmp = sk_X509_value(certs, i);
179
+ if (!X509_cmp(xtmp, x))
180
+ break;
181
+ }
182
+ if (i < sk_X509_num(certs))
183
+ X509_up_ref(xtmp);
184
+ else
185
+ xtmp = NULL;
186
+ sk_X509_pop_free(certs, X509_free);
187
+ return xtmp;
188
+ }
189
+
190
+ int X509_verify_cert(X509_STORE_CTX *ctx)
191
+ {
192
+ X509 *x, *xtmp, *xtmp2, *chain_ss = NULL;
193
+ int bad_chain = 0;
194
+ X509_VERIFY_PARAM *param = ctx->param;
195
+ int depth, i, ok = 0;
196
+ int num, j, retry, trust;
197
+ int (*cb) (int xok, X509_STORE_CTX *xctx);
198
+ STACK_OF(X509) *sktmp = NULL;
199
+ if (ctx->cert == NULL) {
200
+ OPENSSL_PUT_ERROR(X509, X509_R_NO_CERT_SET_FOR_US_TO_VERIFY);
201
+ ctx->error = X509_V_ERR_INVALID_CALL;
202
+ return -1;
203
+ }
204
+ if (ctx->chain != NULL) {
205
+ /*
206
+ * This X509_STORE_CTX has already been used to verify a cert. We
207
+ * cannot do another one.
208
+ */
209
+ OPENSSL_PUT_ERROR(X509, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
210
+ ctx->error = X509_V_ERR_INVALID_CALL;
211
+ return -1;
212
+ }
213
+
214
+ cb = ctx->verify_cb;
215
+
216
+ /*
217
+ * first we make sure the chain we are going to build is present and that
218
+ * the first entry is in place
219
+ */
220
+ ctx->chain = sk_X509_new_null();
221
+ if (ctx->chain == NULL || !sk_X509_push(ctx->chain, ctx->cert)) {
222
+ OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
223
+ ctx->error = X509_V_ERR_OUT_OF_MEM;
224
+ goto end;
225
+ }
226
+ X509_up_ref(ctx->cert);
227
+ ctx->last_untrusted = 1;
228
+
229
+ /* We use a temporary STACK so we can chop and hack at it */
230
+ if (ctx->untrusted != NULL
231
+ && (sktmp = sk_X509_dup(ctx->untrusted)) == NULL) {
232
+ OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
233
+ ctx->error = X509_V_ERR_OUT_OF_MEM;
234
+ goto end;
235
+ }
236
+
237
+ num = sk_X509_num(ctx->chain);
238
+ x = sk_X509_value(ctx->chain, num - 1);
239
+ depth = param->depth;
240
+
241
+ for (;;) {
242
+ /* If we have enough, we break */
243
+ if (depth < num)
244
+ break; /* FIXME: If this happens, we should take
245
+ * note of it and, if appropriate, use the
246
+ * X509_V_ERR_CERT_CHAIN_TOO_LONG error code
247
+ * later. */
248
+
249
+ /* If we are self signed, we break */
250
+ if (cert_self_signed(x))
251
+ break;
252
+ /*
253
+ * If asked see if we can find issuer in trusted store first
254
+ */
255
+ if (ctx->param->flags & X509_V_FLAG_TRUSTED_FIRST) {
256
+ ok = ctx->get_issuer(&xtmp, ctx, x);
257
+ if (ok < 0) {
258
+ ctx->error = X509_V_ERR_STORE_LOOKUP;
259
+ goto end;
260
+ }
261
+ /*
262
+ * If successful for now free up cert so it will be picked up
263
+ * again later.
264
+ */
265
+ if (ok > 0) {
266
+ X509_free(xtmp);
267
+ break;
268
+ }
269
+ }
270
+
271
+ /* If we were passed a cert chain, use it first */
272
+ if (ctx->untrusted != NULL) {
273
+ xtmp = find_issuer(ctx, sktmp, x);
274
+ if (xtmp != NULL) {
275
+ if (!sk_X509_push(ctx->chain, xtmp)) {
276
+ OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
277
+ ctx->error = X509_V_ERR_OUT_OF_MEM;
278
+ ok = 0;
279
+ goto end;
280
+ }
281
+ X509_up_ref(xtmp);
282
+ (void)sk_X509_delete_ptr(sktmp, xtmp);
283
+ ctx->last_untrusted++;
284
+ x = xtmp;
285
+ num++;
286
+ /*
287
+ * reparse the full chain for the next one
288
+ */
289
+ continue;
290
+ }
291
+ }
292
+ break;
293
+ }
294
+
295
+ /* Remember how many untrusted certs we have */
296
+ j = num;
297
+ /*
298
+ * at this point, chain should contain a list of untrusted certificates.
299
+ * We now need to add at least one trusted one, if possible, otherwise we
300
+ * complain.
301
+ */
302
+
303
+ do {
304
+ /*
305
+ * Examine last certificate in chain and see if it is self signed.
306
+ */
307
+ i = sk_X509_num(ctx->chain);
308
+ x = sk_X509_value(ctx->chain, i - 1);
309
+ if (cert_self_signed(x)) {
310
+ /* we have a self signed certificate */
311
+ if (sk_X509_num(ctx->chain) == 1) {
312
+ /*
313
+ * We have a single self signed certificate: see if we can
314
+ * find it in the store. We must have an exact match to avoid
315
+ * possible impersonation.
316
+ */
317
+ ok = ctx->get_issuer(&xtmp, ctx, x);
318
+ if ((ok <= 0) || X509_cmp(x, xtmp)) {
319
+ ctx->error = X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT;
320
+ ctx->current_cert = x;
321
+ ctx->error_depth = i - 1;
322
+ if (ok == 1)
323
+ X509_free(xtmp);
324
+ bad_chain = 1;
325
+ ok = cb(0, ctx);
326
+ if (!ok)
327
+ goto end;
328
+ } else {
329
+ /*
330
+ * We have a match: replace certificate with store
331
+ * version so we get any trust settings.
332
+ */
333
+ X509_free(x);
334
+ x = xtmp;
335
+ (void)sk_X509_set(ctx->chain, i - 1, x);
336
+ ctx->last_untrusted = 0;
337
+ }
338
+ } else {
339
+ /*
340
+ * extract and save self signed certificate for later use
341
+ */
342
+ chain_ss = sk_X509_pop(ctx->chain);
343
+ ctx->last_untrusted--;
344
+ num--;
345
+ j--;
346
+ x = sk_X509_value(ctx->chain, num - 1);
347
+ }
348
+ }
349
+ /* We now lookup certs from the certificate store */
350
+ for (;;) {
351
+ /* If we have enough, we break */
352
+ if (depth < num)
353
+ break;
354
+ /* If we are self signed, we break */
355
+ if (cert_self_signed(x))
356
+ break;
357
+ ok = ctx->get_issuer(&xtmp, ctx, x);
358
+
359
+ if (ok < 0) {
360
+ ctx->error = X509_V_ERR_STORE_LOOKUP;
361
+ goto end;
362
+ }
363
+ if (ok == 0)
364
+ break;
365
+ x = xtmp;
366
+ if (!sk_X509_push(ctx->chain, x)) {
367
+ X509_free(xtmp);
368
+ OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
369
+ ctx->error = X509_V_ERR_OUT_OF_MEM;
370
+ ok = 0;
371
+ goto end;
372
+ }
373
+ num++;
374
+ }
375
+
376
+ /* we now have our chain, lets check it... */
377
+ trust = check_trust(ctx);
378
+
379
+ /* If explicitly rejected error */
380
+ if (trust == X509_TRUST_REJECTED) {
381
+ ok = 0;
382
+ goto end;
383
+ }
384
+ /*
385
+ * If it's not explicitly trusted then check if there is an alternative
386
+ * chain that could be used. We only do this if we haven't already
387
+ * checked via TRUSTED_FIRST and the user hasn't switched off alternate
388
+ * chain checking
389
+ */
390
+ retry = 0;
391
+ if (trust != X509_TRUST_TRUSTED
392
+ && !(ctx->param->flags & X509_V_FLAG_TRUSTED_FIRST)
393
+ && !(ctx->param->flags & X509_V_FLAG_NO_ALT_CHAINS)) {
394
+ while (j-- > 1) {
395
+ xtmp2 = sk_X509_value(ctx->chain, j - 1);
396
+ ok = ctx->get_issuer(&xtmp, ctx, xtmp2);
397
+ if (ok < 0)
398
+ goto end;
399
+ /* Check if we found an alternate chain */
400
+ if (ok > 0) {
401
+ /*
402
+ * Free up the found cert we'll add it again later
403
+ */
404
+ X509_free(xtmp);
405
+
406
+ /*
407
+ * Dump all the certs above this point - we've found an
408
+ * alternate chain
409
+ */
410
+ while (num > j) {
411
+ xtmp = sk_X509_pop(ctx->chain);
412
+ X509_free(xtmp);
413
+ num--;
414
+ }
415
+ ctx->last_untrusted = sk_X509_num(ctx->chain);
416
+ retry = 1;
417
+ break;
418
+ }
419
+ }
420
+ }
421
+ } while (retry);
422
+
423
+ /*
424
+ * If not explicitly trusted then indicate error unless it's a single
425
+ * self signed certificate in which case we've indicated an error already
426
+ * and set bad_chain == 1
427
+ */
428
+ if (trust != X509_TRUST_TRUSTED && !bad_chain) {
429
+ if ((chain_ss == NULL) || !ctx->check_issued(ctx, x, chain_ss)) {
430
+ if (ctx->last_untrusted >= num)
431
+ ctx->error = X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY;
432
+ else
433
+ ctx->error = X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT;
434
+ ctx->current_cert = x;
435
+ } else {
436
+
437
+ sk_X509_push(ctx->chain, chain_ss);
438
+ num++;
439
+ ctx->last_untrusted = num;
440
+ ctx->current_cert = chain_ss;
441
+ ctx->error = X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN;
442
+ chain_ss = NULL;
443
+ }
444
+
445
+ ctx->error_depth = num - 1;
446
+ bad_chain = 1;
447
+ ok = cb(0, ctx);
448
+ if (!ok)
449
+ goto end;
450
+ }
451
+
452
+ /* We have the chain complete: now we need to check its purpose */
453
+ ok = check_chain_extensions(ctx);
454
+
455
+ if (!ok)
456
+ goto end;
457
+
458
+ /* Check name constraints */
459
+
460
+ ok = check_name_constraints(ctx);
461
+
462
+ if (!ok)
463
+ goto end;
464
+
465
+ ok = check_id(ctx);
466
+
467
+ if (!ok)
468
+ goto end;
469
+
470
+ /*
471
+ * Check revocation status: we do this after copying parameters because
472
+ * they may be needed for CRL signature verification.
473
+ */
474
+
475
+ ok = ctx->check_revocation(ctx);
476
+ if (!ok)
477
+ goto end;
478
+
479
+ int err = X509_chain_check_suiteb(&ctx->error_depth, NULL, ctx->chain,
480
+ ctx->param->flags);
481
+ if (err != X509_V_OK) {
482
+ ctx->error = err;
483
+ ctx->current_cert = sk_X509_value(ctx->chain, ctx->error_depth);
484
+ ok = cb(0, ctx);
485
+ if (!ok)
486
+ goto end;
487
+ }
488
+
489
+ /* At this point, we have a chain and need to verify it */
490
+ if (ctx->verify != NULL)
491
+ ok = ctx->verify(ctx);
492
+ else
493
+ ok = internal_verify(ctx);
494
+ if (!ok)
495
+ goto end;
496
+
497
+ /* If we get this far evaluate policies */
498
+ if (!bad_chain && (ctx->param->flags & X509_V_FLAG_POLICY_CHECK))
499
+ ok = ctx->check_policy(ctx);
500
+
501
+ end:
502
+ if (sktmp != NULL)
503
+ sk_X509_free(sktmp);
504
+ if (chain_ss != NULL)
505
+ X509_free(chain_ss);
506
+
507
+ /* Safety net, error returns must set ctx->error */
508
+ if (ok <= 0 && ctx->error == X509_V_OK)
509
+ ctx->error = X509_V_ERR_UNSPECIFIED;
510
+ return ok;
511
+ }
512
+
513
+ /*
514
+ * Given a STACK_OF(X509) find the issuer of cert (if any)
515
+ */
516
+
517
+ static X509 *find_issuer(X509_STORE_CTX *ctx, STACK_OF(X509) *sk, X509 *x)
518
+ {
519
+ size_t i;
520
+ X509 *issuer;
521
+ for (i = 0; i < sk_X509_num(sk); i++) {
522
+ issuer = sk_X509_value(sk, i);
523
+ if (ctx->check_issued(ctx, x, issuer))
524
+ return issuer;
525
+ }
526
+ return NULL;
527
+ }
528
+
529
+ /* Given a possible certificate and issuer check them */
530
+
531
+ static int check_issued(X509_STORE_CTX *ctx, X509 *x, X509 *issuer)
532
+ {
533
+ int ret;
534
+ ret = X509_check_issued(issuer, x);
535
+ if (ret == X509_V_OK)
536
+ return 1;
537
+ /* If we haven't asked for issuer errors don't set ctx */
538
+ if (!(ctx->param->flags & X509_V_FLAG_CB_ISSUER_CHECK))
539
+ return 0;
540
+
541
+ ctx->error = ret;
542
+ ctx->current_cert = x;
543
+ ctx->current_issuer = issuer;
544
+ return ctx->verify_cb(0, ctx);
545
+ }
546
+
547
+ /* Alternative lookup method: look from a STACK stored in other_ctx */
548
+
549
+ static int get_issuer_sk(X509 **issuer, X509_STORE_CTX *ctx, X509 *x)
550
+ {
551
+ *issuer = find_issuer(ctx, ctx->other_ctx, x);
552
+ if (*issuer) {
553
+ X509_up_ref(*issuer);
554
+ return 1;
555
+ } else
556
+ return 0;
557
+ }
558
+
559
+ /*
560
+ * Check a certificate chains extensions for consistency with the supplied
561
+ * purpose
562
+ */
563
+
564
+ static int check_chain_extensions(X509_STORE_CTX *ctx)
565
+ {
566
+ int i, ok = 0, must_be_ca, plen = 0;
567
+ X509 *x;
568
+ int (*cb) (int xok, X509_STORE_CTX *xctx);
569
+ int proxy_path_length = 0;
570
+ int purpose;
571
+ int allow_proxy_certs;
572
+ cb = ctx->verify_cb;
573
+
574
+ /*
575
+ * must_be_ca can have 1 of 3 values: -1: we accept both CA and non-CA
576
+ * certificates, to allow direct use of self-signed certificates (which
577
+ * are marked as CA). 0: we only accept non-CA certificates. This is
578
+ * currently not used, but the possibility is present for future
579
+ * extensions. 1: we only accept CA certificates. This is currently used
580
+ * for all certificates in the chain except the leaf certificate.
581
+ */
582
+ must_be_ca = -1;
583
+
584
+ /* CRL path validation */
585
+ if (ctx->parent) {
586
+ allow_proxy_certs = 0;
587
+ purpose = X509_PURPOSE_CRL_SIGN;
588
+ } else {
589
+ allow_proxy_certs =
590
+ ! !(ctx->param->flags & X509_V_FLAG_ALLOW_PROXY_CERTS);
591
+ purpose = ctx->param->purpose;
592
+ }
593
+
594
+ /* Check all untrusted certificates */
595
+ for (i = 0; i < ctx->last_untrusted; i++) {
596
+ int ret;
597
+ x = sk_X509_value(ctx->chain, i);
598
+ if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL)
599
+ && (x->ex_flags & EXFLAG_CRITICAL)) {
600
+ ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION;
601
+ ctx->error_depth = i;
602
+ ctx->current_cert = x;
603
+ ok = cb(0, ctx);
604
+ if (!ok)
605
+ goto end;
606
+ }
607
+ if (!allow_proxy_certs && (x->ex_flags & EXFLAG_PROXY)) {
608
+ ctx->error = X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED;
609
+ ctx->error_depth = i;
610
+ ctx->current_cert = x;
611
+ ok = cb(0, ctx);
612
+ if (!ok)
613
+ goto end;
614
+ }
615
+ ret = X509_check_ca(x);
616
+ switch (must_be_ca) {
617
+ case -1:
618
+ if ((ctx->param->flags & X509_V_FLAG_X509_STRICT)
619
+ && (ret != 1) && (ret != 0)) {
620
+ ret = 0;
621
+ ctx->error = X509_V_ERR_INVALID_CA;
622
+ } else
623
+ ret = 1;
624
+ break;
625
+ case 0:
626
+ if (ret != 0) {
627
+ ret = 0;
628
+ ctx->error = X509_V_ERR_INVALID_NON_CA;
629
+ } else
630
+ ret = 1;
631
+ break;
632
+ default:
633
+ if ((ret == 0)
634
+ || ((ctx->param->flags & X509_V_FLAG_X509_STRICT)
635
+ && (ret != 1))) {
636
+ ret = 0;
637
+ ctx->error = X509_V_ERR_INVALID_CA;
638
+ } else
639
+ ret = 1;
640
+ break;
641
+ }
642
+ if (ret == 0) {
643
+ ctx->error_depth = i;
644
+ ctx->current_cert = x;
645
+ ok = cb(0, ctx);
646
+ if (!ok)
647
+ goto end;
648
+ }
649
+ if (ctx->param->purpose > 0) {
650
+ ret = X509_check_purpose(x, purpose, must_be_ca > 0);
651
+ if ((ret == 0)
652
+ || ((ctx->param->flags & X509_V_FLAG_X509_STRICT)
653
+ && (ret != 1))) {
654
+ ctx->error = X509_V_ERR_INVALID_PURPOSE;
655
+ ctx->error_depth = i;
656
+ ctx->current_cert = x;
657
+ ok = cb(0, ctx);
658
+ if (!ok)
659
+ goto end;
660
+ }
661
+ }
662
+ /* Check pathlen if not self issued */
663
+ if ((i > 1) && !(x->ex_flags & EXFLAG_SI)
664
+ && (x->ex_pathlen != -1)
665
+ && (plen > (x->ex_pathlen + proxy_path_length + 1))) {
666
+ ctx->error = X509_V_ERR_PATH_LENGTH_EXCEEDED;
667
+ ctx->error_depth = i;
668
+ ctx->current_cert = x;
669
+ ok = cb(0, ctx);
670
+ if (!ok)
671
+ goto end;
672
+ }
673
+ /* Increment path length if not self issued */
674
+ if (!(x->ex_flags & EXFLAG_SI))
675
+ plen++;
676
+ /*
677
+ * If this certificate is a proxy certificate, the next certificate
678
+ * must be another proxy certificate or a EE certificate. If not,
679
+ * the next certificate must be a CA certificate.
680
+ */
681
+ if (x->ex_flags & EXFLAG_PROXY) {
682
+ if (x->ex_pcpathlen != -1 && i > x->ex_pcpathlen) {
683
+ ctx->error = X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED;
684
+ ctx->error_depth = i;
685
+ ctx->current_cert = x;
686
+ ok = cb(0, ctx);
687
+ if (!ok)
688
+ goto end;
689
+ }
690
+ proxy_path_length++;
691
+ must_be_ca = 0;
692
+ } else
693
+ must_be_ca = 1;
694
+ }
695
+ ok = 1;
696
+ end:
697
+ return ok;
698
+ }
699
+
700
+ static int check_name_constraints(X509_STORE_CTX *ctx)
701
+ {
702
+ X509 *x;
703
+ int i, j, rv;
704
+ /* Check name constraints for all certificates */
705
+ for (i = sk_X509_num(ctx->chain) - 1; i >= 0; i--) {
706
+ x = sk_X509_value(ctx->chain, i);
707
+ /* Ignore self issued certs unless last in chain */
708
+ if (i && (x->ex_flags & EXFLAG_SI))
709
+ continue;
710
+ /*
711
+ * Check against constraints for all certificates higher in chain
712
+ * including trust anchor. Trust anchor not strictly speaking needed
713
+ * but if it includes constraints it is to be assumed it expects them
714
+ * to be obeyed.
715
+ */
716
+ for (j = sk_X509_num(ctx->chain) - 1; j > i; j--) {
717
+ NAME_CONSTRAINTS *nc = sk_X509_value(ctx->chain, j)->nc;
718
+ if (nc) {
719
+ rv = NAME_CONSTRAINTS_check(x, nc);
720
+ switch (rv) {
721
+ case X509_V_OK:
722
+ continue;
723
+ case X509_V_ERR_OUT_OF_MEM:
724
+ ctx->error = rv;
725
+ return 0;
726
+ default:
727
+ ctx->error = rv;
728
+ ctx->error_depth = i;
729
+ ctx->current_cert = x;
730
+ if (!ctx->verify_cb(0, ctx))
731
+ return 0;
732
+ break;
733
+ }
734
+ }
735
+ }
736
+ }
737
+ return 1;
738
+ }
739
+
740
+ static int check_id_error(X509_STORE_CTX *ctx, int errcode)
741
+ {
742
+ ctx->error = errcode;
743
+ ctx->current_cert = ctx->cert;
744
+ ctx->error_depth = 0;
745
+ return ctx->verify_cb(0, ctx);
746
+ }
747
+
748
+ static int check_hosts(X509 *x, X509_VERIFY_PARAM_ID *id)
749
+ {
750
+ size_t i;
751
+ size_t n = sk_OPENSSL_STRING_num(id->hosts);
752
+ char *name;
753
+
754
+ if (id->peername != NULL) {
755
+ OPENSSL_free(id->peername);
756
+ id->peername = NULL;
757
+ }
758
+ for (i = 0; i < n; ++i) {
759
+ name = sk_OPENSSL_STRING_value(id->hosts, i);
760
+ if (X509_check_host(x, name, strlen(name), id->hostflags,
761
+ &id->peername) > 0)
762
+ return 1;
763
+ }
764
+ return n == 0;
765
+ }
766
+
767
+ static int check_id(X509_STORE_CTX *ctx)
768
+ {
769
+ X509_VERIFY_PARAM *vpm = ctx->param;
770
+ X509_VERIFY_PARAM_ID *id = vpm->id;
771
+ X509 *x = ctx->cert;
772
+ if (id->hosts && check_hosts(x, id) <= 0) {
773
+ if (!check_id_error(ctx, X509_V_ERR_HOSTNAME_MISMATCH))
774
+ return 0;
775
+ }
776
+ if (id->email && X509_check_email(x, id->email, id->emaillen, 0) <= 0) {
777
+ if (!check_id_error(ctx, X509_V_ERR_EMAIL_MISMATCH))
778
+ return 0;
779
+ }
780
+ if (id->ip && X509_check_ip(x, id->ip, id->iplen, 0) <= 0) {
781
+ if (!check_id_error(ctx, X509_V_ERR_IP_ADDRESS_MISMATCH))
782
+ return 0;
783
+ }
784
+ return 1;
785
+ }
786
+
787
+ static int check_trust(X509_STORE_CTX *ctx)
788
+ {
789
+ size_t i;
790
+ int ok;
791
+ X509 *x = NULL;
792
+ int (*cb) (int xok, X509_STORE_CTX *xctx);
793
+ cb = ctx->verify_cb;
794
+ /* Check all trusted certificates in chain */
795
+ for (i = ctx->last_untrusted; i < sk_X509_num(ctx->chain); i++) {
796
+ x = sk_X509_value(ctx->chain, i);
797
+ ok = X509_check_trust(x, ctx->param->trust, 0);
798
+ /* If explicitly trusted return trusted */
799
+ if (ok == X509_TRUST_TRUSTED)
800
+ return X509_TRUST_TRUSTED;
801
+ /*
802
+ * If explicitly rejected notify callback and reject if not
803
+ * overridden.
804
+ */
805
+ if (ok == X509_TRUST_REJECTED) {
806
+ ctx->error_depth = i;
807
+ ctx->current_cert = x;
808
+ ctx->error = X509_V_ERR_CERT_REJECTED;
809
+ ok = cb(0, ctx);
810
+ if (!ok)
811
+ return X509_TRUST_REJECTED;
812
+ }
813
+ }
814
+ /*
815
+ * If we accept partial chains and have at least one trusted certificate
816
+ * return success.
817
+ */
818
+ if (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN) {
819
+ X509 *mx;
820
+ if (ctx->last_untrusted < (int)sk_X509_num(ctx->chain))
821
+ return X509_TRUST_TRUSTED;
822
+ x = sk_X509_value(ctx->chain, 0);
823
+ mx = lookup_cert_match(ctx, x);
824
+ if (mx) {
825
+ (void)sk_X509_set(ctx->chain, 0, mx);
826
+ X509_free(x);
827
+ ctx->last_untrusted = 0;
828
+ return X509_TRUST_TRUSTED;
829
+ }
830
+ }
831
+
832
+ /*
833
+ * If no trusted certs in chain at all return untrusted and allow
834
+ * standard (no issuer cert) etc errors to be indicated.
835
+ */
836
+ return X509_TRUST_UNTRUSTED;
837
+ }
838
+
839
+ static int check_revocation(X509_STORE_CTX *ctx)
840
+ {
841
+ int i, last, ok;
842
+ if (!(ctx->param->flags & X509_V_FLAG_CRL_CHECK))
843
+ return 1;
844
+ if (ctx->param->flags & X509_V_FLAG_CRL_CHECK_ALL)
845
+ last = sk_X509_num(ctx->chain) - 1;
846
+ else {
847
+ /* If checking CRL paths this isn't the EE certificate */
848
+ if (ctx->parent)
849
+ return 1;
850
+ last = 0;
851
+ }
852
+ for (i = 0; i <= last; i++) {
853
+ ctx->error_depth = i;
854
+ ok = check_cert(ctx);
855
+ if (!ok)
856
+ return ok;
857
+ }
858
+ return 1;
859
+ }
860
+
861
+ static int check_cert(X509_STORE_CTX *ctx)
862
+ {
863
+ X509_CRL *crl = NULL, *dcrl = NULL;
864
+ X509 *x;
865
+ int ok = 0, cnum;
866
+ unsigned int last_reasons;
867
+ cnum = ctx->error_depth;
868
+ x = sk_X509_value(ctx->chain, cnum);
869
+ ctx->current_cert = x;
870
+ ctx->current_issuer = NULL;
871
+ ctx->current_crl_score = 0;
872
+ ctx->current_reasons = 0;
873
+ while (ctx->current_reasons != CRLDP_ALL_REASONS) {
874
+ last_reasons = ctx->current_reasons;
875
+ /* Try to retrieve relevant CRL */
876
+ if (ctx->get_crl)
877
+ ok = ctx->get_crl(ctx, &crl, x);
878
+ else
879
+ ok = get_crl_delta(ctx, &crl, &dcrl, x);
880
+ /*
881
+ * If error looking up CRL, nothing we can do except notify callback
882
+ */
883
+ if (!ok) {
884
+ ctx->error = X509_V_ERR_UNABLE_TO_GET_CRL;
885
+ ok = ctx->verify_cb(0, ctx);
886
+ goto err;
887
+ }
888
+ ctx->current_crl = crl;
889
+ ok = ctx->check_crl(ctx, crl);
890
+ if (!ok)
891
+ goto err;
892
+
893
+ if (dcrl) {
894
+ ok = ctx->check_crl(ctx, dcrl);
895
+ if (!ok)
896
+ goto err;
897
+ ok = ctx->cert_crl(ctx, dcrl, x);
898
+ if (!ok)
899
+ goto err;
900
+ } else
901
+ ok = 1;
902
+
903
+ /* Don't look in full CRL if delta reason is removefromCRL */
904
+ if (ok != 2) {
905
+ ok = ctx->cert_crl(ctx, crl, x);
906
+ if (!ok)
907
+ goto err;
908
+ }
909
+
910
+ X509_CRL_free(crl);
911
+ X509_CRL_free(dcrl);
912
+ crl = NULL;
913
+ dcrl = NULL;
914
+ /*
915
+ * If reasons not updated we wont get anywhere by another iteration,
916
+ * so exit loop.
917
+ */
918
+ if (last_reasons == ctx->current_reasons) {
919
+ ctx->error = X509_V_ERR_UNABLE_TO_GET_CRL;
920
+ ok = ctx->verify_cb(0, ctx);
921
+ goto err;
922
+ }
923
+ }
924
+ err:
925
+ X509_CRL_free(crl);
926
+ X509_CRL_free(dcrl);
927
+
928
+ ctx->current_crl = NULL;
929
+ return ok;
930
+
931
+ }
932
+
933
+ /* Check CRL times against values in X509_STORE_CTX */
934
+
935
+ static int check_crl_time(X509_STORE_CTX *ctx, X509_CRL *crl, int notify)
936
+ {
937
+ time_t *ptime;
938
+ int i;
939
+ if (notify)
940
+ ctx->current_crl = crl;
941
+ if (ctx->param->flags & X509_V_FLAG_USE_CHECK_TIME)
942
+ ptime = &ctx->param->check_time;
943
+ else
944
+ ptime = NULL;
945
+
946
+ i = X509_cmp_time(X509_CRL_get_lastUpdate(crl), ptime);
947
+ if (i == 0) {
948
+ if (!notify)
949
+ return 0;
950
+ ctx->error = X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD;
951
+ if (!ctx->verify_cb(0, ctx))
952
+ return 0;
953
+ }
954
+
955
+ if (i > 0) {
956
+ if (!notify)
957
+ return 0;
958
+ ctx->error = X509_V_ERR_CRL_NOT_YET_VALID;
959
+ if (!ctx->verify_cb(0, ctx))
960
+ return 0;
961
+ }
962
+
963
+ if (X509_CRL_get_nextUpdate(crl)) {
964
+ i = X509_cmp_time(X509_CRL_get_nextUpdate(crl), ptime);
965
+
966
+ if (i == 0) {
967
+ if (!notify)
968
+ return 0;
969
+ ctx->error = X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD;
970
+ if (!ctx->verify_cb(0, ctx))
971
+ return 0;
972
+ }
973
+ /* Ignore expiry of base CRL is delta is valid */
974
+ if ((i < 0) && !(ctx->current_crl_score & CRL_SCORE_TIME_DELTA)) {
975
+ if (!notify)
976
+ return 0;
977
+ ctx->error = X509_V_ERR_CRL_HAS_EXPIRED;
978
+ if (!ctx->verify_cb(0, ctx))
979
+ return 0;
980
+ }
981
+ }
982
+
983
+ if (notify)
984
+ ctx->current_crl = NULL;
985
+
986
+ return 1;
987
+ }
988
+
989
+ static int get_crl_sk(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509_CRL **pdcrl,
990
+ X509 **pissuer, int *pscore, unsigned int *preasons,
991
+ STACK_OF(X509_CRL) *crls)
992
+ {
993
+ int crl_score, best_score = *pscore;
994
+ size_t i;
995
+ unsigned int reasons, best_reasons = 0;
996
+ X509 *x = ctx->current_cert;
997
+ X509_CRL *crl, *best_crl = NULL;
998
+ X509 *crl_issuer = NULL, *best_crl_issuer = NULL;
999
+
1000
+ for (i = 0; i < sk_X509_CRL_num(crls); i++) {
1001
+ crl = sk_X509_CRL_value(crls, i);
1002
+ reasons = *preasons;
1003
+ crl_score = get_crl_score(ctx, &crl_issuer, &reasons, crl, x);
1004
+ if (crl_score < best_score || crl_score == 0)
1005
+ continue;
1006
+ /* If current CRL is equivalent use it if it is newer */
1007
+ if (crl_score == best_score && best_crl != NULL) {
1008
+ int day, sec;
1009
+ if (ASN1_TIME_diff(&day, &sec, X509_CRL_get_lastUpdate(best_crl),
1010
+ X509_CRL_get_lastUpdate(crl)) == 0)
1011
+ continue;
1012
+ /*
1013
+ * ASN1_TIME_diff never returns inconsistent signs for |day|
1014
+ * and |sec|.
1015
+ */
1016
+ if (day <= 0 && sec <= 0)
1017
+ continue;
1018
+ }
1019
+ best_crl = crl;
1020
+ best_crl_issuer = crl_issuer;
1021
+ best_score = crl_score;
1022
+ best_reasons = reasons;
1023
+ }
1024
+
1025
+ if (best_crl) {
1026
+ if (*pcrl)
1027
+ X509_CRL_free(*pcrl);
1028
+ *pcrl = best_crl;
1029
+ *pissuer = best_crl_issuer;
1030
+ *pscore = best_score;
1031
+ *preasons = best_reasons;
1032
+ X509_CRL_up_ref(best_crl);
1033
+ if (*pdcrl) {
1034
+ X509_CRL_free(*pdcrl);
1035
+ *pdcrl = NULL;
1036
+ }
1037
+ get_delta_sk(ctx, pdcrl, pscore, best_crl, crls);
1038
+ }
1039
+
1040
+ if (best_score >= CRL_SCORE_VALID)
1041
+ return 1;
1042
+
1043
+ return 0;
1044
+ }
1045
+
1046
+ /*
1047
+ * Compare two CRL extensions for delta checking purposes. They should be
1048
+ * both present or both absent. If both present all fields must be identical.
1049
+ */
1050
+
1051
+ static int crl_extension_match(X509_CRL *a, X509_CRL *b, int nid)
1052
+ {
1053
+ ASN1_OCTET_STRING *exta, *extb;
1054
+ int i;
1055
+ i = X509_CRL_get_ext_by_NID(a, nid, -1);
1056
+ if (i >= 0) {
1057
+ /* Can't have multiple occurrences */
1058
+ if (X509_CRL_get_ext_by_NID(a, nid, i) != -1)
1059
+ return 0;
1060
+ exta = X509_EXTENSION_get_data(X509_CRL_get_ext(a, i));
1061
+ } else
1062
+ exta = NULL;
1063
+
1064
+ i = X509_CRL_get_ext_by_NID(b, nid, -1);
1065
+
1066
+ if (i >= 0) {
1067
+
1068
+ if (X509_CRL_get_ext_by_NID(b, nid, i) != -1)
1069
+ return 0;
1070
+ extb = X509_EXTENSION_get_data(X509_CRL_get_ext(b, i));
1071
+ } else
1072
+ extb = NULL;
1073
+
1074
+ if (!exta && !extb)
1075
+ return 1;
1076
+
1077
+ if (!exta || !extb)
1078
+ return 0;
1079
+
1080
+ if (ASN1_OCTET_STRING_cmp(exta, extb))
1081
+ return 0;
1082
+
1083
+ return 1;
1084
+ }
1085
+
1086
+ /* See if a base and delta are compatible */
1087
+
1088
+ static int check_delta_base(X509_CRL *delta, X509_CRL *base)
1089
+ {
1090
+ /* Delta CRL must be a delta */
1091
+ if (!delta->base_crl_number)
1092
+ return 0;
1093
+ /* Base must have a CRL number */
1094
+ if (!base->crl_number)
1095
+ return 0;
1096
+ /* Issuer names must match */
1097
+ if (X509_NAME_cmp(X509_CRL_get_issuer(base), X509_CRL_get_issuer(delta)))
1098
+ return 0;
1099
+ /* AKID and IDP must match */
1100
+ if (!crl_extension_match(delta, base, NID_authority_key_identifier))
1101
+ return 0;
1102
+ if (!crl_extension_match(delta, base, NID_issuing_distribution_point))
1103
+ return 0;
1104
+ /* Delta CRL base number must not exceed Full CRL number. */
1105
+ if (ASN1_INTEGER_cmp(delta->base_crl_number, base->crl_number) > 0)
1106
+ return 0;
1107
+ /* Delta CRL number must exceed full CRL number */
1108
+ if (ASN1_INTEGER_cmp(delta->crl_number, base->crl_number) > 0)
1109
+ return 1;
1110
+ return 0;
1111
+ }
1112
+
1113
+ /*
1114
+ * For a given base CRL find a delta... maybe extend to delta scoring or
1115
+ * retrieve a chain of deltas...
1116
+ */
1117
+
1118
+ static void get_delta_sk(X509_STORE_CTX *ctx, X509_CRL **dcrl, int *pscore,
1119
+ X509_CRL *base, STACK_OF(X509_CRL) *crls)
1120
+ {
1121
+ X509_CRL *delta;
1122
+ size_t i;
1123
+ if (!(ctx->param->flags & X509_V_FLAG_USE_DELTAS))
1124
+ return;
1125
+ if (!((ctx->current_cert->ex_flags | base->flags) & EXFLAG_FRESHEST))
1126
+ return;
1127
+ for (i = 0; i < sk_X509_CRL_num(crls); i++) {
1128
+ delta = sk_X509_CRL_value(crls, i);
1129
+ if (check_delta_base(delta, base)) {
1130
+ if (check_crl_time(ctx, delta, 0))
1131
+ *pscore |= CRL_SCORE_TIME_DELTA;
1132
+ X509_CRL_up_ref(delta);
1133
+ *dcrl = delta;
1134
+ return;
1135
+ }
1136
+ }
1137
+ *dcrl = NULL;
1138
+ }
1139
+
1140
+ /*
1141
+ * For a given CRL return how suitable it is for the supplied certificate
1142
+ * 'x'. The return value is a mask of several criteria. If the issuer is not
1143
+ * the certificate issuer this is returned in *pissuer. The reasons mask is
1144
+ * also used to determine if the CRL is suitable: if no new reasons the CRL
1145
+ * is rejected, otherwise reasons is updated.
1146
+ */
1147
+
1148
+ static int get_crl_score(X509_STORE_CTX *ctx, X509 **pissuer,
1149
+ unsigned int *preasons, X509_CRL *crl, X509 *x)
1150
+ {
1151
+
1152
+ int crl_score = 0;
1153
+ unsigned int tmp_reasons = *preasons, crl_reasons;
1154
+
1155
+ /* First see if we can reject CRL straight away */
1156
+
1157
+ /* Invalid IDP cannot be processed */
1158
+ if (crl->idp_flags & IDP_INVALID)
1159
+ return 0;
1160
+ /* Reason codes or indirect CRLs need extended CRL support */
1161
+ if (!(ctx->param->flags & X509_V_FLAG_EXTENDED_CRL_SUPPORT)) {
1162
+ if (crl->idp_flags & (IDP_INDIRECT | IDP_REASONS))
1163
+ return 0;
1164
+ } else if (crl->idp_flags & IDP_REASONS) {
1165
+ /* If no new reasons reject */
1166
+ if (!(crl->idp_reasons & ~tmp_reasons))
1167
+ return 0;
1168
+ }
1169
+ /* Don't process deltas at this stage */
1170
+ else if (crl->base_crl_number)
1171
+ return 0;
1172
+ /* If issuer name doesn't match certificate need indirect CRL */
1173
+ if (X509_NAME_cmp(X509_get_issuer_name(x), X509_CRL_get_issuer(crl))) {
1174
+ if (!(crl->idp_flags & IDP_INDIRECT))
1175
+ return 0;
1176
+ } else
1177
+ crl_score |= CRL_SCORE_ISSUER_NAME;
1178
+
1179
+ if (!(crl->flags & EXFLAG_CRITICAL))
1180
+ crl_score |= CRL_SCORE_NOCRITICAL;
1181
+
1182
+ /* Check expiry */
1183
+ if (check_crl_time(ctx, crl, 0))
1184
+ crl_score |= CRL_SCORE_TIME;
1185
+
1186
+ /* Check authority key ID and locate certificate issuer */
1187
+ crl_akid_check(ctx, crl, pissuer, &crl_score);
1188
+
1189
+ /* If we can't locate certificate issuer at this point forget it */
1190
+
1191
+ if (!(crl_score & CRL_SCORE_AKID))
1192
+ return 0;
1193
+
1194
+ /* Check cert for matching CRL distribution points */
1195
+
1196
+ if (crl_crldp_check(x, crl, crl_score, &crl_reasons)) {
1197
+ /* If no new reasons reject */
1198
+ if (!(crl_reasons & ~tmp_reasons))
1199
+ return 0;
1200
+ tmp_reasons |= crl_reasons;
1201
+ crl_score |= CRL_SCORE_SCOPE;
1202
+ }
1203
+
1204
+ *preasons = tmp_reasons;
1205
+
1206
+ return crl_score;
1207
+
1208
+ }
1209
+
1210
+ static void crl_akid_check(X509_STORE_CTX *ctx, X509_CRL *crl,
1211
+ X509 **pissuer, int *pcrl_score)
1212
+ {
1213
+ X509 *crl_issuer = NULL;
1214
+ X509_NAME *cnm = X509_CRL_get_issuer(crl);
1215
+ int cidx = ctx->error_depth;
1216
+ size_t i;
1217
+
1218
+ if ((size_t)cidx != sk_X509_num(ctx->chain) - 1)
1219
+ cidx++;
1220
+
1221
+ crl_issuer = sk_X509_value(ctx->chain, cidx);
1222
+
1223
+ if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) {
1224
+ if (*pcrl_score & CRL_SCORE_ISSUER_NAME) {
1225
+ *pcrl_score |= CRL_SCORE_AKID | CRL_SCORE_ISSUER_CERT;
1226
+ *pissuer = crl_issuer;
1227
+ return;
1228
+ }
1229
+ }
1230
+
1231
+ for (cidx++; cidx < (int)sk_X509_num(ctx->chain); cidx++) {
1232
+ crl_issuer = sk_X509_value(ctx->chain, cidx);
1233
+ if (X509_NAME_cmp(X509_get_subject_name(crl_issuer), cnm))
1234
+ continue;
1235
+ if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) {
1236
+ *pcrl_score |= CRL_SCORE_AKID | CRL_SCORE_SAME_PATH;
1237
+ *pissuer = crl_issuer;
1238
+ return;
1239
+ }
1240
+ }
1241
+
1242
+ /* Anything else needs extended CRL support */
1243
+
1244
+ if (!(ctx->param->flags & X509_V_FLAG_EXTENDED_CRL_SUPPORT))
1245
+ return;
1246
+
1247
+ /*
1248
+ * Otherwise the CRL issuer is not on the path. Look for it in the set of
1249
+ * untrusted certificates.
1250
+ */
1251
+ for (i = 0; i < sk_X509_num(ctx->untrusted); i++) {
1252
+ crl_issuer = sk_X509_value(ctx->untrusted, i);
1253
+ if (X509_NAME_cmp(X509_get_subject_name(crl_issuer), cnm))
1254
+ continue;
1255
+ if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) {
1256
+ *pissuer = crl_issuer;
1257
+ *pcrl_score |= CRL_SCORE_AKID;
1258
+ return;
1259
+ }
1260
+ }
1261
+ }
1262
+
1263
+ /*
1264
+ * Check the path of a CRL issuer certificate. This creates a new
1265
+ * X509_STORE_CTX and populates it with most of the parameters from the
1266
+ * parent. This could be optimised somewhat since a lot of path checking will
1267
+ * be duplicated by the parent, but this will rarely be used in practice.
1268
+ */
1269
+
1270
+ static int check_crl_path(X509_STORE_CTX *ctx, X509 *x)
1271
+ {
1272
+ X509_STORE_CTX crl_ctx;
1273
+ int ret;
1274
+ /* Don't allow recursive CRL path validation */
1275
+ if (ctx->parent)
1276
+ return 0;
1277
+ if (!X509_STORE_CTX_init(&crl_ctx, ctx->ctx, x, ctx->untrusted))
1278
+ return -1;
1279
+
1280
+ crl_ctx.crls = ctx->crls;
1281
+ /* Copy verify params across */
1282
+ X509_STORE_CTX_set0_param(&crl_ctx, ctx->param);
1283
+
1284
+ crl_ctx.parent = ctx;
1285
+ crl_ctx.verify_cb = ctx->verify_cb;
1286
+
1287
+ /* Verify CRL issuer */
1288
+ ret = X509_verify_cert(&crl_ctx);
1289
+
1290
+ if (ret <= 0)
1291
+ goto err;
1292
+
1293
+ /* Check chain is acceptable */
1294
+
1295
+ ret = check_crl_chain(ctx, ctx->chain, crl_ctx.chain);
1296
+ err:
1297
+ X509_STORE_CTX_cleanup(&crl_ctx);
1298
+ return ret;
1299
+ }
1300
+
1301
+ /*
1302
+ * RFC3280 says nothing about the relationship between CRL path and
1303
+ * certificate path, which could lead to situations where a certificate could
1304
+ * be revoked or validated by a CA not authorised to do so. RFC5280 is more
1305
+ * strict and states that the two paths must end in the same trust anchor,
1306
+ * though some discussions remain... until this is resolved we use the
1307
+ * RFC5280 version
1308
+ */
1309
+
1310
+ static int check_crl_chain(X509_STORE_CTX *ctx,
1311
+ STACK_OF(X509) *cert_path,
1312
+ STACK_OF(X509) *crl_path)
1313
+ {
1314
+ X509 *cert_ta, *crl_ta;
1315
+ cert_ta = sk_X509_value(cert_path, sk_X509_num(cert_path) - 1);
1316
+ crl_ta = sk_X509_value(crl_path, sk_X509_num(crl_path) - 1);
1317
+ if (!X509_cmp(cert_ta, crl_ta))
1318
+ return 1;
1319
+ return 0;
1320
+ }
1321
+
1322
+ /*
1323
+ * Check for match between two dist point names: three separate cases. 1.
1324
+ * Both are relative names and compare X509_NAME types. 2. One full, one
1325
+ * relative. Compare X509_NAME to GENERAL_NAMES. 3. Both are full names and
1326
+ * compare two GENERAL_NAMES. 4. One is NULL: automatic match.
1327
+ */
1328
+
1329
+ static int idp_check_dp(DIST_POINT_NAME *a, DIST_POINT_NAME *b)
1330
+ {
1331
+ X509_NAME *nm = NULL;
1332
+ GENERAL_NAMES *gens = NULL;
1333
+ GENERAL_NAME *gena, *genb;
1334
+ size_t i, j;
1335
+ if (!a || !b)
1336
+ return 1;
1337
+ if (a->type == 1) {
1338
+ if (!a->dpname)
1339
+ return 0;
1340
+ /* Case 1: two X509_NAME */
1341
+ if (b->type == 1) {
1342
+ if (!b->dpname)
1343
+ return 0;
1344
+ if (!X509_NAME_cmp(a->dpname, b->dpname))
1345
+ return 1;
1346
+ else
1347
+ return 0;
1348
+ }
1349
+ /* Case 2: set name and GENERAL_NAMES appropriately */
1350
+ nm = a->dpname;
1351
+ gens = b->name.fullname;
1352
+ } else if (b->type == 1) {
1353
+ if (!b->dpname)
1354
+ return 0;
1355
+ /* Case 2: set name and GENERAL_NAMES appropriately */
1356
+ gens = a->name.fullname;
1357
+ nm = b->dpname;
1358
+ }
1359
+
1360
+ /* Handle case 2 with one GENERAL_NAMES and one X509_NAME */
1361
+ if (nm) {
1362
+ for (i = 0; i < sk_GENERAL_NAME_num(gens); i++) {
1363
+ gena = sk_GENERAL_NAME_value(gens, i);
1364
+ if (gena->type != GEN_DIRNAME)
1365
+ continue;
1366
+ if (!X509_NAME_cmp(nm, gena->d.directoryName))
1367
+ return 1;
1368
+ }
1369
+ return 0;
1370
+ }
1371
+
1372
+ /* Else case 3: two GENERAL_NAMES */
1373
+
1374
+ for (i = 0; i < sk_GENERAL_NAME_num(a->name.fullname); i++) {
1375
+ gena = sk_GENERAL_NAME_value(a->name.fullname, i);
1376
+ for (j = 0; j < sk_GENERAL_NAME_num(b->name.fullname); j++) {
1377
+ genb = sk_GENERAL_NAME_value(b->name.fullname, j);
1378
+ if (!GENERAL_NAME_cmp(gena, genb))
1379
+ return 1;
1380
+ }
1381
+ }
1382
+
1383
+ return 0;
1384
+
1385
+ }
1386
+
1387
+ static int crldp_check_crlissuer(DIST_POINT *dp, X509_CRL *crl, int crl_score)
1388
+ {
1389
+ size_t i;
1390
+ X509_NAME *nm = X509_CRL_get_issuer(crl);
1391
+ /* If no CRLissuer return is successful iff don't need a match */
1392
+ if (!dp->CRLissuer)
1393
+ return ! !(crl_score & CRL_SCORE_ISSUER_NAME);
1394
+ for (i = 0; i < sk_GENERAL_NAME_num(dp->CRLissuer); i++) {
1395
+ GENERAL_NAME *gen = sk_GENERAL_NAME_value(dp->CRLissuer, i);
1396
+ if (gen->type != GEN_DIRNAME)
1397
+ continue;
1398
+ if (!X509_NAME_cmp(gen->d.directoryName, nm))
1399
+ return 1;
1400
+ }
1401
+ return 0;
1402
+ }
1403
+
1404
+ /* Check CRLDP and IDP */
1405
+
1406
+ static int crl_crldp_check(X509 *x, X509_CRL *crl, int crl_score,
1407
+ unsigned int *preasons)
1408
+ {
1409
+ size_t i;
1410
+ if (crl->idp_flags & IDP_ONLYATTR)
1411
+ return 0;
1412
+ if (x->ex_flags & EXFLAG_CA) {
1413
+ if (crl->idp_flags & IDP_ONLYUSER)
1414
+ return 0;
1415
+ } else {
1416
+ if (crl->idp_flags & IDP_ONLYCA)
1417
+ return 0;
1418
+ }
1419
+ *preasons = crl->idp_reasons;
1420
+ for (i = 0; i < sk_DIST_POINT_num(x->crldp); i++) {
1421
+ DIST_POINT *dp = sk_DIST_POINT_value(x->crldp, i);
1422
+ if (crldp_check_crlissuer(dp, crl, crl_score)) {
1423
+ if (!crl->idp || idp_check_dp(dp->distpoint, crl->idp->distpoint)) {
1424
+ *preasons &= dp->dp_reasons;
1425
+ return 1;
1426
+ }
1427
+ }
1428
+ }
1429
+ if ((!crl->idp || !crl->idp->distpoint)
1430
+ && (crl_score & CRL_SCORE_ISSUER_NAME))
1431
+ return 1;
1432
+ return 0;
1433
+ }
1434
+
1435
+ /*
1436
+ * Retrieve CRL corresponding to current certificate. If deltas enabled try
1437
+ * to find a delta CRL too
1438
+ */
1439
+
1440
+ static int get_crl_delta(X509_STORE_CTX *ctx,
1441
+ X509_CRL **pcrl, X509_CRL **pdcrl, X509 *x)
1442
+ {
1443
+ int ok;
1444
+ X509 *issuer = NULL;
1445
+ int crl_score = 0;
1446
+ unsigned int reasons;
1447
+ X509_CRL *crl = NULL, *dcrl = NULL;
1448
+ STACK_OF(X509_CRL) *skcrl;
1449
+ X509_NAME *nm = X509_get_issuer_name(x);
1450
+ reasons = ctx->current_reasons;
1451
+ ok = get_crl_sk(ctx, &crl, &dcrl,
1452
+ &issuer, &crl_score, &reasons, ctx->crls);
1453
+
1454
+ if (ok)
1455
+ goto done;
1456
+
1457
+ /* Lookup CRLs from store */
1458
+
1459
+ skcrl = ctx->lookup_crls(ctx, nm);
1460
+
1461
+ /* If no CRLs found and a near match from get_crl_sk use that */
1462
+ if (!skcrl && crl)
1463
+ goto done;
1464
+
1465
+ get_crl_sk(ctx, &crl, &dcrl, &issuer, &crl_score, &reasons, skcrl);
1466
+
1467
+ sk_X509_CRL_pop_free(skcrl, X509_CRL_free);
1468
+
1469
+ done:
1470
+
1471
+ /* If we got any kind of CRL use it and return success */
1472
+ if (crl) {
1473
+ ctx->current_issuer = issuer;
1474
+ ctx->current_crl_score = crl_score;
1475
+ ctx->current_reasons = reasons;
1476
+ *pcrl = crl;
1477
+ *pdcrl = dcrl;
1478
+ return 1;
1479
+ }
1480
+
1481
+ return 0;
1482
+ }
1483
+
1484
+ /* Check CRL validity */
1485
+ static int check_crl(X509_STORE_CTX *ctx, X509_CRL *crl)
1486
+ {
1487
+ X509 *issuer = NULL;
1488
+ EVP_PKEY *ikey = NULL;
1489
+ int ok = 0, chnum, cnum;
1490
+ cnum = ctx->error_depth;
1491
+ chnum = sk_X509_num(ctx->chain) - 1;
1492
+ /* if we have an alternative CRL issuer cert use that */
1493
+ if (ctx->current_issuer)
1494
+ issuer = ctx->current_issuer;
1495
+
1496
+ /*
1497
+ * Else find CRL issuer: if not last certificate then issuer is next
1498
+ * certificate in chain.
1499
+ */
1500
+ else if (cnum < chnum)
1501
+ issuer = sk_X509_value(ctx->chain, cnum + 1);
1502
+ else {
1503
+ issuer = sk_X509_value(ctx->chain, chnum);
1504
+ /* If not self signed, can't check signature */
1505
+ if (!ctx->check_issued(ctx, issuer, issuer)) {
1506
+ ctx->error = X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER;
1507
+ ok = ctx->verify_cb(0, ctx);
1508
+ if (!ok)
1509
+ goto err;
1510
+ }
1511
+ }
1512
+
1513
+ if (issuer) {
1514
+ /*
1515
+ * Skip most tests for deltas because they have already been done
1516
+ */
1517
+ if (!crl->base_crl_number) {
1518
+ /* Check for cRLSign bit if keyUsage present */
1519
+ if ((issuer->ex_flags & EXFLAG_KUSAGE) &&
1520
+ !(issuer->ex_kusage & KU_CRL_SIGN)) {
1521
+ ctx->error = X509_V_ERR_KEYUSAGE_NO_CRL_SIGN;
1522
+ ok = ctx->verify_cb(0, ctx);
1523
+ if (!ok)
1524
+ goto err;
1525
+ }
1526
+
1527
+ if (!(ctx->current_crl_score & CRL_SCORE_SCOPE)) {
1528
+ ctx->error = X509_V_ERR_DIFFERENT_CRL_SCOPE;
1529
+ ok = ctx->verify_cb(0, ctx);
1530
+ if (!ok)
1531
+ goto err;
1532
+ }
1533
+
1534
+ if (!(ctx->current_crl_score & CRL_SCORE_SAME_PATH)) {
1535
+ if (check_crl_path(ctx, ctx->current_issuer) <= 0) {
1536
+ ctx->error = X509_V_ERR_CRL_PATH_VALIDATION_ERROR;
1537
+ ok = ctx->verify_cb(0, ctx);
1538
+ if (!ok)
1539
+ goto err;
1540
+ }
1541
+ }
1542
+
1543
+ if (crl->idp_flags & IDP_INVALID) {
1544
+ ctx->error = X509_V_ERR_INVALID_EXTENSION;
1545
+ ok = ctx->verify_cb(0, ctx);
1546
+ if (!ok)
1547
+ goto err;
1548
+ }
1549
+
1550
+ }
1551
+
1552
+ if (!(ctx->current_crl_score & CRL_SCORE_TIME)) {
1553
+ ok = check_crl_time(ctx, crl, 1);
1554
+ if (!ok)
1555
+ goto err;
1556
+ }
1557
+
1558
+ /* Attempt to get issuer certificate public key */
1559
+ ikey = X509_get_pubkey(issuer);
1560
+
1561
+ if (!ikey) {
1562
+ ctx->error = X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY;
1563
+ ok = ctx->verify_cb(0, ctx);
1564
+ if (!ok)
1565
+ goto err;
1566
+ } else {
1567
+ int rv;
1568
+ rv = X509_CRL_check_suiteb(crl, ikey, ctx->param->flags);
1569
+ if (rv != X509_V_OK) {
1570
+ ctx->error = rv;
1571
+ ok = ctx->verify_cb(0, ctx);
1572
+ if (!ok)
1573
+ goto err;
1574
+ }
1575
+ /* Verify CRL signature */
1576
+ if (X509_CRL_verify(crl, ikey) <= 0) {
1577
+ ctx->error = X509_V_ERR_CRL_SIGNATURE_FAILURE;
1578
+ ok = ctx->verify_cb(0, ctx);
1579
+ if (!ok)
1580
+ goto err;
1581
+ }
1582
+ }
1583
+ }
1584
+
1585
+ ok = 1;
1586
+
1587
+ err:
1588
+ EVP_PKEY_free(ikey);
1589
+ return ok;
1590
+ }
1591
+
1592
+ /* Check certificate against CRL */
1593
+ static int cert_crl(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x)
1594
+ {
1595
+ int ok;
1596
+ X509_REVOKED *rev;
1597
+ /*
1598
+ * The rules changed for this... previously if a CRL contained unhandled
1599
+ * critical extensions it could still be used to indicate a certificate
1600
+ * was revoked. This has since been changed since critical extension can
1601
+ * change the meaning of CRL entries.
1602
+ */
1603
+ if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL)
1604
+ && (crl->flags & EXFLAG_CRITICAL)) {
1605
+ ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION;
1606
+ ok = ctx->verify_cb(0, ctx);
1607
+ if (!ok)
1608
+ return 0;
1609
+ }
1610
+ /*
1611
+ * Look for serial number of certificate in CRL If found make sure reason
1612
+ * is not removeFromCRL.
1613
+ */
1614
+ if (X509_CRL_get0_by_cert(crl, &rev, x)) {
1615
+ if (rev->reason == CRL_REASON_REMOVE_FROM_CRL)
1616
+ return 2;
1617
+ ctx->error = X509_V_ERR_CERT_REVOKED;
1618
+ ok = ctx->verify_cb(0, ctx);
1619
+ if (!ok)
1620
+ return 0;
1621
+ }
1622
+
1623
+ return 1;
1624
+ }
1625
+
1626
+ static int check_policy(X509_STORE_CTX *ctx)
1627
+ {
1628
+ int ret;
1629
+ if (ctx->parent)
1630
+ return 1;
1631
+ ret = X509_policy_check(&ctx->tree, &ctx->explicit_policy, ctx->chain,
1632
+ ctx->param->policies, ctx->param->flags);
1633
+ if (ret == 0) {
1634
+ OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
1635
+ ctx->error = X509_V_ERR_OUT_OF_MEM;
1636
+ return 0;
1637
+ }
1638
+ /* Invalid or inconsistent extensions */
1639
+ if (ret == -1) {
1640
+ /*
1641
+ * Locate certificates with bad extensions and notify callback.
1642
+ */
1643
+ X509 *x;
1644
+ size_t i;
1645
+ for (i = 1; i < sk_X509_num(ctx->chain); i++) {
1646
+ x = sk_X509_value(ctx->chain, i);
1647
+ if (!(x->ex_flags & EXFLAG_INVALID_POLICY))
1648
+ continue;
1649
+ ctx->current_cert = x;
1650
+ ctx->error = X509_V_ERR_INVALID_POLICY_EXTENSION;
1651
+ if (!ctx->verify_cb(0, ctx))
1652
+ return 0;
1653
+ }
1654
+ return 1;
1655
+ }
1656
+ if (ret == -2) {
1657
+ ctx->current_cert = NULL;
1658
+ ctx->error = X509_V_ERR_NO_EXPLICIT_POLICY;
1659
+ return ctx->verify_cb(0, ctx);
1660
+ }
1661
+
1662
+ if (ctx->param->flags & X509_V_FLAG_NOTIFY_POLICY) {
1663
+ ctx->current_cert = NULL;
1664
+ /*
1665
+ * Verification errors need to be "sticky", a callback may have allowed
1666
+ * an SSL handshake to continue despite an error, and we must then
1667
+ * remain in an error state. Therefore, we MUST NOT clear earlier
1668
+ * verification errors by setting the error to X509_V_OK.
1669
+ */
1670
+ if (!ctx->verify_cb(2, ctx))
1671
+ return 0;
1672
+ }
1673
+
1674
+ return 1;
1675
+ }
1676
+
1677
+ static int check_cert_time(X509_STORE_CTX *ctx, X509 *x)
1678
+ {
1679
+ time_t *ptime;
1680
+ int i;
1681
+
1682
+ if (ctx->param->flags & X509_V_FLAG_USE_CHECK_TIME)
1683
+ ptime = &ctx->param->check_time;
1684
+ else
1685
+ ptime = NULL;
1686
+
1687
+ i = X509_cmp_time(X509_get_notBefore(x), ptime);
1688
+ if (i == 0) {
1689
+ ctx->error = X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD;
1690
+ ctx->current_cert = x;
1691
+ if (!ctx->verify_cb(0, ctx))
1692
+ return 0;
1693
+ }
1694
+
1695
+ if (i > 0) {
1696
+ ctx->error = X509_V_ERR_CERT_NOT_YET_VALID;
1697
+ ctx->current_cert = x;
1698
+ if (!ctx->verify_cb(0, ctx))
1699
+ return 0;
1700
+ }
1701
+
1702
+ i = X509_cmp_time(X509_get_notAfter(x), ptime);
1703
+ if (i == 0) {
1704
+ ctx->error = X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD;
1705
+ ctx->current_cert = x;
1706
+ if (!ctx->verify_cb(0, ctx))
1707
+ return 0;
1708
+ }
1709
+
1710
+ if (i < 0) {
1711
+ ctx->error = X509_V_ERR_CERT_HAS_EXPIRED;
1712
+ ctx->current_cert = x;
1713
+ if (!ctx->verify_cb(0, ctx))
1714
+ return 0;
1715
+ }
1716
+
1717
+ return 1;
1718
+ }
1719
+
1720
+ static int internal_verify(X509_STORE_CTX *ctx)
1721
+ {
1722
+ int ok = 0, n;
1723
+ X509 *xs, *xi;
1724
+ EVP_PKEY *pkey = NULL;
1725
+ int (*cb) (int xok, X509_STORE_CTX *xctx);
1726
+
1727
+ cb = ctx->verify_cb;
1728
+
1729
+ n = sk_X509_num(ctx->chain);
1730
+ ctx->error_depth = n - 1;
1731
+ n--;
1732
+ xi = sk_X509_value(ctx->chain, n);
1733
+
1734
+ if (ctx->check_issued(ctx, xi, xi))
1735
+ xs = xi;
1736
+ else {
1737
+ if (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN) {
1738
+ xs = xi;
1739
+ goto check_cert;
1740
+ }
1741
+ if (n <= 0) {
1742
+ ctx->error = X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE;
1743
+ ctx->current_cert = xi;
1744
+ ok = cb(0, ctx);
1745
+ goto end;
1746
+ } else {
1747
+ n--;
1748
+ ctx->error_depth = n;
1749
+ xs = sk_X509_value(ctx->chain, n);
1750
+ }
1751
+ }
1752
+
1753
+ /* ctx->error=0; not needed */
1754
+ while (n >= 0) {
1755
+ ctx->error_depth = n;
1756
+
1757
+ /*
1758
+ * Skip signature check for self signed certificates unless
1759
+ * explicitly asked for. It doesn't add any security and just wastes
1760
+ * time.
1761
+ */
1762
+ if (xs != xi || (ctx->param->flags & X509_V_FLAG_CHECK_SS_SIGNATURE)) {
1763
+ if ((pkey = X509_get_pubkey(xi)) == NULL) {
1764
+ ctx->error = X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY;
1765
+ ctx->current_cert = xi;
1766
+ ok = (*cb) (0, ctx);
1767
+ if (!ok)
1768
+ goto end;
1769
+ } else if (X509_verify(xs, pkey) <= 0) {
1770
+ ctx->error = X509_V_ERR_CERT_SIGNATURE_FAILURE;
1771
+ ctx->current_cert = xs;
1772
+ ok = (*cb) (0, ctx);
1773
+ if (!ok) {
1774
+ EVP_PKEY_free(pkey);
1775
+ goto end;
1776
+ }
1777
+ }
1778
+ EVP_PKEY_free(pkey);
1779
+ pkey = NULL;
1780
+ }
1781
+
1782
+ check_cert:
1783
+ ok = check_cert_time(ctx, xs);
1784
+ if (!ok)
1785
+ goto end;
1786
+
1787
+ /* The last error (if any) is still in the error value */
1788
+ ctx->current_issuer = xi;
1789
+ ctx->current_cert = xs;
1790
+ ok = (*cb) (1, ctx);
1791
+ if (!ok)
1792
+ goto end;
1793
+
1794
+ n--;
1795
+ if (n >= 0) {
1796
+ xi = xs;
1797
+ xs = sk_X509_value(ctx->chain, n);
1798
+ }
1799
+ }
1800
+ ok = 1;
1801
+ end:
1802
+ return ok;
1803
+ }
1804
+
1805
+ int X509_cmp_current_time(const ASN1_TIME *ctm)
1806
+ {
1807
+ return X509_cmp_time(ctm, NULL);
1808
+ }
1809
+
1810
+ int X509_cmp_time(const ASN1_TIME *ctm, time_t *cmp_time)
1811
+ {
1812
+ char *str;
1813
+ ASN1_TIME atm;
1814
+ long offset;
1815
+ char buff1[24], buff2[24], *p;
1816
+ int i, j, remaining;
1817
+
1818
+ p = buff1;
1819
+ remaining = ctm->length;
1820
+ str = (char *)ctm->data;
1821
+ /*
1822
+ * Note that the following (historical) code allows much more slack in
1823
+ * the time format than RFC5280. In RFC5280, the representation is fixed:
1824
+ * UTCTime: YYMMDDHHMMSSZ GeneralizedTime: YYYYMMDDHHMMSSZ
1825
+ */
1826
+ if (ctm->type == V_ASN1_UTCTIME) {
1827
+ /* YYMMDDHHMM[SS]Z or YYMMDDHHMM[SS](+-)hhmm */
1828
+ int min_length = sizeof("YYMMDDHHMMZ") - 1;
1829
+ int max_length = sizeof("YYMMDDHHMMSS+hhmm") - 1;
1830
+ if (remaining < min_length || remaining > max_length)
1831
+ return 0;
1832
+ memcpy(p, str, 10);
1833
+ p += 10;
1834
+ str += 10;
1835
+ remaining -= 10;
1836
+ } else {
1837
+ /*
1838
+ * YYYYMMDDHHMM[SS[.fff]]Z or YYYYMMDDHHMM[SS[.f[f[f]]]](+-)hhmm
1839
+ */
1840
+ int min_length = sizeof("YYYYMMDDHHMMZ") - 1;
1841
+ int max_length = sizeof("YYYYMMDDHHMMSS.fff+hhmm") - 1;
1842
+ if (remaining < min_length || remaining > max_length)
1843
+ return 0;
1844
+ memcpy(p, str, 12);
1845
+ p += 12;
1846
+ str += 12;
1847
+ remaining -= 12;
1848
+ }
1849
+
1850
+ if ((*str == 'Z') || (*str == '-') || (*str == '+')) {
1851
+ *(p++) = '0';
1852
+ *(p++) = '0';
1853
+ } else {
1854
+ /* SS (seconds) */
1855
+ if (remaining < 2)
1856
+ return 0;
1857
+ *(p++) = *(str++);
1858
+ *(p++) = *(str++);
1859
+ remaining -= 2;
1860
+ /*
1861
+ * Skip any (up to three) fractional seconds... TODO(emilia): in
1862
+ * RFC5280, fractional seconds are forbidden. Can we just kill them
1863
+ * altogether?
1864
+ */
1865
+ if (remaining && *str == '.') {
1866
+ str++;
1867
+ remaining--;
1868
+ for (i = 0; i < 3 && remaining; i++, str++, remaining--) {
1869
+ if (*str < '0' || *str > '9')
1870
+ break;
1871
+ }
1872
+ }
1873
+
1874
+ }
1875
+ *(p++) = 'Z';
1876
+ *(p++) = '\0';
1877
+
1878
+ /* We now need either a terminating 'Z' or an offset. */
1879
+ if (!remaining)
1880
+ return 0;
1881
+ if (*str == 'Z') {
1882
+ if (remaining != 1)
1883
+ return 0;
1884
+ offset = 0;
1885
+ } else {
1886
+ /* (+-)HHMM */
1887
+ if ((*str != '+') && (*str != '-'))
1888
+ return 0;
1889
+ /*
1890
+ * Historical behaviour: the (+-)hhmm offset is forbidden in RFC5280.
1891
+ */
1892
+ if (remaining != 5)
1893
+ return 0;
1894
+ if (str[1] < '0' || str[1] > '9' || str[2] < '0' || str[2] > '9' ||
1895
+ str[3] < '0' || str[3] > '9' || str[4] < '0' || str[4] > '9')
1896
+ return 0;
1897
+ offset = ((str[1] - '0') * 10 + (str[2] - '0')) * 60;
1898
+ offset += (str[3] - '0') * 10 + (str[4] - '0');
1899
+ if (*str == '-')
1900
+ offset = -offset;
1901
+ }
1902
+ atm.type = ctm->type;
1903
+ atm.flags = 0;
1904
+ atm.length = sizeof(buff2);
1905
+ atm.data = (unsigned char *)buff2;
1906
+
1907
+ if (X509_time_adj(&atm, offset * 60, cmp_time) == NULL)
1908
+ return 0;
1909
+
1910
+ if (ctm->type == V_ASN1_UTCTIME) {
1911
+ i = (buff1[0] - '0') * 10 + (buff1[1] - '0');
1912
+ if (i < 50)
1913
+ i += 100; /* cf. RFC 2459 */
1914
+ j = (buff2[0] - '0') * 10 + (buff2[1] - '0');
1915
+ if (j < 50)
1916
+ j += 100;
1917
+
1918
+ if (i < j)
1919
+ return -1;
1920
+ if (i > j)
1921
+ return 1;
1922
+ }
1923
+ i = strcmp(buff1, buff2);
1924
+ if (i == 0) /* wait a second then return younger :-) */
1925
+ return -1;
1926
+ else
1927
+ return i;
1928
+ }
1929
+
1930
+ ASN1_TIME *X509_gmtime_adj(ASN1_TIME *s, long adj)
1931
+ {
1932
+ return X509_time_adj(s, adj, NULL);
1933
+ }
1934
+
1935
+ ASN1_TIME *X509_time_adj(ASN1_TIME *s, long offset_sec, time_t *in_tm)
1936
+ {
1937
+ return X509_time_adj_ex(s, 0, offset_sec, in_tm);
1938
+ }
1939
+
1940
+ ASN1_TIME *X509_time_adj_ex(ASN1_TIME *s,
1941
+ int offset_day, long offset_sec, time_t *in_tm)
1942
+ {
1943
+ time_t t = 0;
1944
+
1945
+ if (in_tm)
1946
+ t = *in_tm;
1947
+ else
1948
+ time(&t);
1949
+
1950
+ if (s && !(s->flags & ASN1_STRING_FLAG_MSTRING)) {
1951
+ if (s->type == V_ASN1_UTCTIME)
1952
+ return ASN1_UTCTIME_adj(s, t, offset_day, offset_sec);
1953
+ if (s->type == V_ASN1_GENERALIZEDTIME)
1954
+ return ASN1_GENERALIZEDTIME_adj(s, t, offset_day, offset_sec);
1955
+ }
1956
+ return ASN1_TIME_adj(s, t, offset_day, offset_sec);
1957
+ }
1958
+
1959
+ /* Make a delta CRL as the diff between two full CRLs */
1960
+
1961
+ X509_CRL *X509_CRL_diff(X509_CRL *base, X509_CRL *newer,
1962
+ EVP_PKEY *skey, const EVP_MD *md, unsigned int flags)
1963
+ {
1964
+ X509_CRL *crl = NULL;
1965
+ int i;
1966
+ size_t j;
1967
+ STACK_OF(X509_REVOKED) *revs = NULL;
1968
+ /* CRLs can't be delta already */
1969
+ if (base->base_crl_number || newer->base_crl_number) {
1970
+ OPENSSL_PUT_ERROR(X509, X509_R_CRL_ALREADY_DELTA);
1971
+ return NULL;
1972
+ }
1973
+ /* Base and new CRL must have a CRL number */
1974
+ if (!base->crl_number || !newer->crl_number) {
1975
+ OPENSSL_PUT_ERROR(X509, X509_R_NO_CRL_NUMBER);
1976
+ return NULL;
1977
+ }
1978
+ /* Issuer names must match */
1979
+ if (X509_NAME_cmp(X509_CRL_get_issuer(base), X509_CRL_get_issuer(newer))) {
1980
+ OPENSSL_PUT_ERROR(X509, X509_R_ISSUER_MISMATCH);
1981
+ return NULL;
1982
+ }
1983
+ /* AKID and IDP must match */
1984
+ if (!crl_extension_match(base, newer, NID_authority_key_identifier)) {
1985
+ OPENSSL_PUT_ERROR(X509, X509_R_AKID_MISMATCH);
1986
+ return NULL;
1987
+ }
1988
+ if (!crl_extension_match(base, newer, NID_issuing_distribution_point)) {
1989
+ OPENSSL_PUT_ERROR(X509, X509_R_IDP_MISMATCH);
1990
+ return NULL;
1991
+ }
1992
+ /* Newer CRL number must exceed full CRL number */
1993
+ if (ASN1_INTEGER_cmp(newer->crl_number, base->crl_number) <= 0) {
1994
+ OPENSSL_PUT_ERROR(X509, X509_R_NEWER_CRL_NOT_NEWER);
1995
+ return NULL;
1996
+ }
1997
+ /* CRLs must verify */
1998
+ if (skey && (X509_CRL_verify(base, skey) <= 0 ||
1999
+ X509_CRL_verify(newer, skey) <= 0)) {
2000
+ OPENSSL_PUT_ERROR(X509, X509_R_CRL_VERIFY_FAILURE);
2001
+ return NULL;
2002
+ }
2003
+ /* Create new CRL */
2004
+ crl = X509_CRL_new();
2005
+ if (!crl || !X509_CRL_set_version(crl, 1))
2006
+ goto memerr;
2007
+ /* Set issuer name */
2008
+ if (!X509_CRL_set_issuer_name(crl, X509_CRL_get_issuer(newer)))
2009
+ goto memerr;
2010
+
2011
+ if (!X509_CRL_set_lastUpdate(crl, X509_CRL_get_lastUpdate(newer)))
2012
+ goto memerr;
2013
+ if (!X509_CRL_set_nextUpdate(crl, X509_CRL_get_nextUpdate(newer)))
2014
+ goto memerr;
2015
+
2016
+ /* Set base CRL number: must be critical */
2017
+
2018
+ if (!X509_CRL_add1_ext_i2d(crl, NID_delta_crl, base->crl_number, 1, 0))
2019
+ goto memerr;
2020
+
2021
+ /*
2022
+ * Copy extensions across from newest CRL to delta: this will set CRL
2023
+ * number to correct value too.
2024
+ */
2025
+
2026
+ for (i = 0; i < X509_CRL_get_ext_count(newer); i++) {
2027
+ X509_EXTENSION *ext;
2028
+ ext = X509_CRL_get_ext(newer, i);
2029
+ if (!X509_CRL_add_ext(crl, ext, -1))
2030
+ goto memerr;
2031
+ }
2032
+
2033
+ /* Go through revoked entries, copying as needed */
2034
+
2035
+ revs = X509_CRL_get_REVOKED(newer);
2036
+
2037
+ for (j = 0; j < sk_X509_REVOKED_num(revs); j++) {
2038
+ X509_REVOKED *rvn, *rvtmp;
2039
+ rvn = sk_X509_REVOKED_value(revs, j);
2040
+ /*
2041
+ * Add only if not also in base. TODO: need something cleverer here
2042
+ * for some more complex CRLs covering multiple CAs.
2043
+ */
2044
+ if (!X509_CRL_get0_by_serial(base, &rvtmp, rvn->serialNumber)) {
2045
+ rvtmp = X509_REVOKED_dup(rvn);
2046
+ if (!rvtmp)
2047
+ goto memerr;
2048
+ if (!X509_CRL_add0_revoked(crl, rvtmp)) {
2049
+ X509_REVOKED_free(rvtmp);
2050
+ goto memerr;
2051
+ }
2052
+ }
2053
+ }
2054
+ /* TODO: optionally prune deleted entries */
2055
+
2056
+ if (skey && md && !X509_CRL_sign(crl, skey, md))
2057
+ goto memerr;
2058
+
2059
+ return crl;
2060
+
2061
+ memerr:
2062
+ OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
2063
+ if (crl)
2064
+ X509_CRL_free(crl);
2065
+ return NULL;
2066
+ }
2067
+
2068
+ int X509_STORE_CTX_get_ex_new_index(long argl, void *argp,
2069
+ CRYPTO_EX_unused * unused,
2070
+ CRYPTO_EX_dup *dup_func,
2071
+ CRYPTO_EX_free *free_func)
2072
+ {
2073
+ /*
2074
+ * This function is (usually) called only once, by
2075
+ * SSL_get_ex_data_X509_STORE_CTX_idx (ssl/ssl_cert.c).
2076
+ */
2077
+ int index;
2078
+ if (!CRYPTO_get_ex_new_index(&g_ex_data_class, &index, argl, argp,
2079
+ dup_func, free_func)) {
2080
+ return -1;
2081
+ }
2082
+ return index;
2083
+ }
2084
+
2085
+ int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx, int idx, void *data)
2086
+ {
2087
+ return CRYPTO_set_ex_data(&ctx->ex_data, idx, data);
2088
+ }
2089
+
2090
+ void *X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx, int idx)
2091
+ {
2092
+ return CRYPTO_get_ex_data(&ctx->ex_data, idx);
2093
+ }
2094
+
2095
+ int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx)
2096
+ {
2097
+ return ctx->error;
2098
+ }
2099
+
2100
+ void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx, int err)
2101
+ {
2102
+ ctx->error = err;
2103
+ }
2104
+
2105
+ int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx)
2106
+ {
2107
+ return ctx->error_depth;
2108
+ }
2109
+
2110
+ X509 *X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx)
2111
+ {
2112
+ return ctx->current_cert;
2113
+ }
2114
+
2115
+ STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx)
2116
+ {
2117
+ return ctx->chain;
2118
+ }
2119
+
2120
+ STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx)
2121
+ {
2122
+ if (!ctx->chain)
2123
+ return NULL;
2124
+ return X509_chain_up_ref(ctx->chain);
2125
+ }
2126
+
2127
+ X509 *X509_STORE_CTX_get0_current_issuer(X509_STORE_CTX *ctx)
2128
+ {
2129
+ return ctx->current_issuer;
2130
+ }
2131
+
2132
+ X509_CRL *X509_STORE_CTX_get0_current_crl(X509_STORE_CTX *ctx)
2133
+ {
2134
+ return ctx->current_crl;
2135
+ }
2136
+
2137
+ X509_STORE_CTX *X509_STORE_CTX_get0_parent_ctx(X509_STORE_CTX *ctx)
2138
+ {
2139
+ return ctx->parent;
2140
+ }
2141
+
2142
+ void X509_STORE_CTX_set_cert(X509_STORE_CTX *ctx, X509 *x)
2143
+ {
2144
+ ctx->cert = x;
2145
+ }
2146
+
2147
+ void X509_STORE_CTX_set_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *sk)
2148
+ {
2149
+ ctx->untrusted = sk;
2150
+ }
2151
+
2152
+ void X509_STORE_CTX_set0_crls(X509_STORE_CTX *ctx, STACK_OF(X509_CRL) *sk)
2153
+ {
2154
+ ctx->crls = sk;
2155
+ }
2156
+
2157
+ int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose)
2158
+ {
2159
+ return X509_STORE_CTX_purpose_inherit(ctx, 0, purpose, 0);
2160
+ }
2161
+
2162
+ int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust)
2163
+ {
2164
+ return X509_STORE_CTX_purpose_inherit(ctx, 0, 0, trust);
2165
+ }
2166
+
2167
+ /*
2168
+ * This function is used to set the X509_STORE_CTX purpose and trust values.
2169
+ * This is intended to be used when another structure has its own trust and
2170
+ * purpose values which (if set) will be inherited by the ctx. If they aren't
2171
+ * set then we will usually have a default purpose in mind which should then
2172
+ * be used to set the trust value. An example of this is SSL use: an SSL
2173
+ * structure will have its own purpose and trust settings which the
2174
+ * application can set: if they aren't set then we use the default of SSL
2175
+ * client/server.
2176
+ */
2177
+
2178
+ int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
2179
+ int purpose, int trust)
2180
+ {
2181
+ int idx;
2182
+ /* If purpose not set use default */
2183
+ if (!purpose)
2184
+ purpose = def_purpose;
2185
+ /* If we have a purpose then check it is valid */
2186
+ if (purpose) {
2187
+ X509_PURPOSE *ptmp;
2188
+ idx = X509_PURPOSE_get_by_id(purpose);
2189
+ if (idx == -1) {
2190
+ OPENSSL_PUT_ERROR(X509, X509_R_UNKNOWN_PURPOSE_ID);
2191
+ return 0;
2192
+ }
2193
+ ptmp = X509_PURPOSE_get0(idx);
2194
+ if (ptmp->trust == X509_TRUST_DEFAULT) {
2195
+ idx = X509_PURPOSE_get_by_id(def_purpose);
2196
+ if (idx == -1) {
2197
+ OPENSSL_PUT_ERROR(X509, X509_R_UNKNOWN_PURPOSE_ID);
2198
+ return 0;
2199
+ }
2200
+ ptmp = X509_PURPOSE_get0(idx);
2201
+ }
2202
+ /* If trust not set then get from purpose default */
2203
+ if (!trust)
2204
+ trust = ptmp->trust;
2205
+ }
2206
+ if (trust) {
2207
+ idx = X509_TRUST_get_by_id(trust);
2208
+ if (idx == -1) {
2209
+ OPENSSL_PUT_ERROR(X509, X509_R_UNKNOWN_TRUST_ID);
2210
+ return 0;
2211
+ }
2212
+ }
2213
+
2214
+ if (purpose && !ctx->param->purpose)
2215
+ ctx->param->purpose = purpose;
2216
+ if (trust && !ctx->param->trust)
2217
+ ctx->param->trust = trust;
2218
+ return 1;
2219
+ }
2220
+
2221
+ X509_STORE_CTX *X509_STORE_CTX_new(void)
2222
+ {
2223
+ X509_STORE_CTX *ctx;
2224
+ ctx = (X509_STORE_CTX *)OPENSSL_malloc(sizeof(X509_STORE_CTX));
2225
+ if (!ctx) {
2226
+ OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
2227
+ return NULL;
2228
+ }
2229
+ memset(ctx, 0, sizeof(X509_STORE_CTX));
2230
+ return ctx;
2231
+ }
2232
+
2233
+ void X509_STORE_CTX_free(X509_STORE_CTX *ctx)
2234
+ {
2235
+ if (ctx == NULL) {
2236
+ return;
2237
+ }
2238
+ X509_STORE_CTX_cleanup(ctx);
2239
+ OPENSSL_free(ctx);
2240
+ }
2241
+
2242
+ int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
2243
+ STACK_OF(X509) *chain)
2244
+ {
2245
+ int ret = 1;
2246
+
2247
+ memset(ctx, 0, sizeof(X509_STORE_CTX));
2248
+ ctx->ctx = store;
2249
+ ctx->cert = x509;
2250
+ ctx->untrusted = chain;
2251
+
2252
+ CRYPTO_new_ex_data(&ctx->ex_data);
2253
+
2254
+ ctx->param = X509_VERIFY_PARAM_new();
2255
+ if (!ctx->param)
2256
+ goto err;
2257
+
2258
+ /*
2259
+ * Inherit callbacks and flags from X509_STORE if not set use defaults.
2260
+ */
2261
+
2262
+ if (store)
2263
+ ret = X509_VERIFY_PARAM_inherit(ctx->param, store->param);
2264
+ else
2265
+ ctx->param->inh_flags |= X509_VP_FLAG_DEFAULT | X509_VP_FLAG_ONCE;
2266
+
2267
+ if (store) {
2268
+ ctx->verify_cb = store->verify_cb;
2269
+ ctx->cleanup = store->cleanup;
2270
+ } else
2271
+ ctx->cleanup = 0;
2272
+
2273
+ if (ret)
2274
+ ret = X509_VERIFY_PARAM_inherit(ctx->param,
2275
+ X509_VERIFY_PARAM_lookup("default"));
2276
+
2277
+ if (ret == 0)
2278
+ goto err;
2279
+
2280
+ if (store && store->check_issued)
2281
+ ctx->check_issued = store->check_issued;
2282
+ else
2283
+ ctx->check_issued = check_issued;
2284
+
2285
+ if (store && store->get_issuer)
2286
+ ctx->get_issuer = store->get_issuer;
2287
+ else
2288
+ ctx->get_issuer = X509_STORE_CTX_get1_issuer;
2289
+
2290
+ if (store && store->verify_cb)
2291
+ ctx->verify_cb = store->verify_cb;
2292
+ else
2293
+ ctx->verify_cb = null_callback;
2294
+
2295
+ if (store && store->verify)
2296
+ ctx->verify = store->verify;
2297
+ else
2298
+ ctx->verify = internal_verify;
2299
+
2300
+ if (store && store->check_revocation)
2301
+ ctx->check_revocation = store->check_revocation;
2302
+ else
2303
+ ctx->check_revocation = check_revocation;
2304
+
2305
+ if (store && store->get_crl)
2306
+ ctx->get_crl = store->get_crl;
2307
+ else
2308
+ ctx->get_crl = NULL;
2309
+
2310
+ if (store && store->check_crl)
2311
+ ctx->check_crl = store->check_crl;
2312
+ else
2313
+ ctx->check_crl = check_crl;
2314
+
2315
+ if (store && store->cert_crl)
2316
+ ctx->cert_crl = store->cert_crl;
2317
+ else
2318
+ ctx->cert_crl = cert_crl;
2319
+
2320
+ if (store && store->lookup_certs)
2321
+ ctx->lookup_certs = store->lookup_certs;
2322
+ else
2323
+ ctx->lookup_certs = X509_STORE_get1_certs;
2324
+
2325
+ if (store && store->lookup_crls)
2326
+ ctx->lookup_crls = store->lookup_crls;
2327
+ else
2328
+ ctx->lookup_crls = X509_STORE_get1_crls;
2329
+
2330
+ ctx->check_policy = check_policy;
2331
+
2332
+ return 1;
2333
+
2334
+ err:
2335
+ CRYPTO_free_ex_data(&g_ex_data_class, ctx, &ctx->ex_data);
2336
+ if (ctx->param != NULL) {
2337
+ X509_VERIFY_PARAM_free(ctx->param);
2338
+ }
2339
+
2340
+ memset(ctx, 0, sizeof(X509_STORE_CTX));
2341
+ OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
2342
+ return 0;
2343
+ }
2344
+
2345
+ /*
2346
+ * Set alternative lookup method: just a STACK of trusted certificates. This
2347
+ * avoids X509_STORE nastiness where it isn't needed.
2348
+ */
2349
+
2350
+ void X509_STORE_CTX_trusted_stack(X509_STORE_CTX *ctx, STACK_OF(X509) *sk)
2351
+ {
2352
+ ctx->other_ctx = sk;
2353
+ ctx->get_issuer = get_issuer_sk;
2354
+ }
2355
+
2356
+ void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx)
2357
+ {
2358
+ /* We need to be idempotent because, unfortunately, |X509_STORE_CTX_free|
2359
+ * also calls this function. */
2360
+ if (ctx->cleanup != NULL) {
2361
+ ctx->cleanup(ctx);
2362
+ ctx->cleanup = NULL;
2363
+ }
2364
+ if (ctx->param != NULL) {
2365
+ if (ctx->parent == NULL)
2366
+ X509_VERIFY_PARAM_free(ctx->param);
2367
+ ctx->param = NULL;
2368
+ }
2369
+ if (ctx->tree != NULL) {
2370
+ X509_policy_tree_free(ctx->tree);
2371
+ ctx->tree = NULL;
2372
+ }
2373
+ if (ctx->chain != NULL) {
2374
+ sk_X509_pop_free(ctx->chain, X509_free);
2375
+ ctx->chain = NULL;
2376
+ }
2377
+ CRYPTO_free_ex_data(&g_ex_data_class, ctx, &(ctx->ex_data));
2378
+ memset(&ctx->ex_data, 0, sizeof(CRYPTO_EX_DATA));
2379
+ }
2380
+
2381
+ void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth)
2382
+ {
2383
+ X509_VERIFY_PARAM_set_depth(ctx->param, depth);
2384
+ }
2385
+
2386
+ void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, unsigned long flags)
2387
+ {
2388
+ X509_VERIFY_PARAM_set_flags(ctx->param, flags);
2389
+ }
2390
+
2391
+ void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, unsigned long flags,
2392
+ time_t t)
2393
+ {
2394
+ X509_VERIFY_PARAM_set_time(ctx->param, t);
2395
+ }
2396
+
2397
+ void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx,
2398
+ int (*verify_cb) (int, X509_STORE_CTX *))
2399
+ {
2400
+ ctx->verify_cb = verify_cb;
2401
+ }
2402
+
2403
+ X509_POLICY_TREE *X509_STORE_CTX_get0_policy_tree(X509_STORE_CTX *ctx)
2404
+ {
2405
+ return ctx->tree;
2406
+ }
2407
+
2408
+ int X509_STORE_CTX_get_explicit_policy(X509_STORE_CTX *ctx)
2409
+ {
2410
+ return ctx->explicit_policy;
2411
+ }
2412
+
2413
+ int X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, const char *name)
2414
+ {
2415
+ const X509_VERIFY_PARAM *param;
2416
+ param = X509_VERIFY_PARAM_lookup(name);
2417
+ if (!param)
2418
+ return 0;
2419
+ return X509_VERIFY_PARAM_inherit(ctx->param, param);
2420
+ }
2421
+
2422
+ X509_VERIFY_PARAM *X509_STORE_CTX_get0_param(X509_STORE_CTX *ctx)
2423
+ {
2424
+ return ctx->param;
2425
+ }
2426
+
2427
+ void X509_STORE_CTX_set0_param(X509_STORE_CTX *ctx, X509_VERIFY_PARAM *param)
2428
+ {
2429
+ if (ctx->param)
2430
+ X509_VERIFY_PARAM_free(ctx->param);
2431
+ ctx->param = param;
2432
+ }
2433
+
2434
+ IMPLEMENT_ASN1_SET_OF(X509)
2435
+
2436
+ IMPLEMENT_ASN1_SET_OF(X509_ATTRIBUTE)