grpc 0.13.1 → 0.14.1.pre1

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

Potentially problematic release.


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

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