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
@@ -60,43 +60,44 @@
60
60
 
61
61
  #include <openssl/mem.h>
62
62
 
63
-
64
63
  int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs,
65
- BIT_STRING_BITNAME *tbl, int indent)
64
+ BIT_STRING_BITNAME *tbl, int indent)
66
65
  {
67
- BIT_STRING_BITNAME *bnam;
68
- char first = 1;
69
- BIO_printf(out, "%*s", indent, "");
70
- for(bnam = tbl; bnam->lname; bnam++) {
71
- if(ASN1_BIT_STRING_get_bit(bs, bnam->bitnum)) {
72
- if(!first) BIO_puts(out, ", ");
73
- BIO_puts(out, bnam->lname);
74
- first = 0;
75
- }
76
- }
77
- BIO_puts(out, "\n");
78
- return 1;
66
+ BIT_STRING_BITNAME *bnam;
67
+ char first = 1;
68
+ BIO_printf(out, "%*s", indent, "");
69
+ for (bnam = tbl; bnam->lname; bnam++) {
70
+ if (ASN1_BIT_STRING_get_bit(bs, bnam->bitnum)) {
71
+ if (!first)
72
+ BIO_puts(out, ", ");
73
+ BIO_puts(out, bnam->lname);
74
+ first = 0;
75
+ }
76
+ }
77
+ BIO_puts(out, "\n");
78
+ return 1;
79
79
  }
80
80
 
81
81
  int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value,
82
- BIT_STRING_BITNAME *tbl)
82
+ BIT_STRING_BITNAME *tbl)
83
83
  {
84
- int bitnum;
85
- bitnum = ASN1_BIT_STRING_num_asc(name, tbl);
86
- if(bitnum < 0) return 0;
87
- if(bs) {
88
- if(!ASN1_BIT_STRING_set_bit(bs, bitnum, value))
89
- return 0;
90
- }
91
- return 1;
84
+ int bitnum;
85
+ bitnum = ASN1_BIT_STRING_num_asc(name, tbl);
86
+ if (bitnum < 0)
87
+ return 0;
88
+ if (bs) {
89
+ if (!ASN1_BIT_STRING_set_bit(bs, bitnum, value))
90
+ return 0;
91
+ }
92
+ return 1;
92
93
  }
93
94
 
94
95
  int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl)
95
96
  {
96
- BIT_STRING_BITNAME *bnam;
97
- for(bnam = tbl; bnam->lname; bnam++) {
98
- if(!strcmp(bnam->sname, name) ||
99
- !strcmp(bnam->lname, name) ) return bnam->bitnum;
100
- }
101
- return -1;
97
+ BIT_STRING_BITNAME *bnam;
98
+ for (bnam = tbl; bnam->lname; bnam++) {
99
+ if (!strcmp(bnam->sname, name) || !strcmp(bnam->lname, name))
100
+ return bnam->bitnum;
101
+ }
102
+ return -1;
102
103
  }
@@ -59,54 +59,52 @@
59
59
  #include <openssl/bio.h>
60
60
  #include <openssl/mem.h>
61
61
 
62
-
63
62
  int ASN1_bn_print(BIO *bp, const char *number, const BIGNUM *num,
64
- unsigned char *buf, int off)
65
- {
66
- int n,i;
67
- const char *neg;
63
+ unsigned char *buf, int off)
64
+ {
65
+ int n, i;
66
+ const char *neg;
67
+
68
+ if (num == NULL)
69
+ return (1);
70
+ neg = (BN_is_negative(num)) ? "-" : "";
71
+ if (!BIO_indent(bp, off, 128))
72
+ return 0;
73
+ if (BN_is_zero(num)) {
74
+ if (BIO_printf(bp, "%s 0\n", number) <= 0)
75
+ return 0;
76
+ return 1;
77
+ }
68
78
 
69
- if (num == NULL) return(1);
70
- neg = (BN_is_negative(num))?"-":"";
71
- if(!BIO_indent(bp,off,128))
72
- return 0;
73
- if (BN_is_zero(num))
74
- {
75
- if (BIO_printf(bp, "%s 0\n", number) <= 0)
76
- return 0;
77
- return 1;
78
- }
79
+ if (BN_num_bytes(num) <= sizeof(long)) {
80
+ if (BIO_printf(bp, "%s %s%lu (%s0x%lx)\n", number, neg,
81
+ (unsigned long)num->d[0], neg,
82
+ (unsigned long)num->d[0])
83
+ <= 0)
84
+ return (0);
85
+ } else {
86
+ buf[0] = 0;
87
+ if (BIO_printf(bp, "%s%s", number,
88
+ (neg[0] == '-') ? " (Negative)" : "") <= 0)
89
+ return (0);
90
+ n = BN_bn2bin(num, &buf[1]);
79
91
 
80
- if (BN_num_bytes(num) <= sizeof(long))
81
- {
82
- if (BIO_printf(bp,"%s %s%lu (%s0x%lx)\n",number,neg,
83
- (unsigned long)num->d[0],neg,(unsigned long)num->d[0])
84
- <= 0) return(0);
85
- }
86
- else
87
- {
88
- buf[0]=0;
89
- if (BIO_printf(bp,"%s%s",number,
90
- (neg[0] == '-')?" (Negative)":"") <= 0)
91
- return(0);
92
- n=BN_bn2bin(num,&buf[1]);
93
-
94
- if (buf[1] & 0x80)
95
- n++;
96
- else buf++;
92
+ if (buf[1] & 0x80)
93
+ n++;
94
+ else
95
+ buf++;
97
96
 
98
- for (i=0; i<n; i++)
99
- {
100
- if ((i%15) == 0)
101
- {
102
- if(BIO_puts(bp,"\n") <= 0
103
- || !BIO_indent(bp,off+4,128))
104
- return 0;
105
- }
106
- if (BIO_printf(bp,"%02x%s",buf[i],((i+1) == n)?"":":")
107
- <= 0) return(0);
108
- }
109
- if (BIO_write(bp,"\n",1) <= 0) return(0);
110
- }
111
- return(1);
112
- }
97
+ for (i = 0; i < n; i++) {
98
+ if ((i % 15) == 0) {
99
+ if (BIO_puts(bp, "\n") <= 0 || !BIO_indent(bp, off + 4, 128))
100
+ return 0;
101
+ }
102
+ if (BIO_printf(bp, "%02x%s", buf[i], ((i + 1) == n) ? "" : ":")
103
+ <= 0)
104
+ return (0);
105
+ }
106
+ if (BIO_write(bp, "\n", 1) <= 0)
107
+ return (0);
108
+ }
109
+ return (1);
110
+ }
@@ -65,1278 +65,1161 @@
65
65
 
66
66
  #include "../internal.h"
67
67
 
68
-
69
68
  static int asn1_check_eoc(const unsigned char **in, long len);
70
69
  static int asn1_find_end(const unsigned char **in, long len, char inf);
71
70
 
72
71
  static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len,
73
- char inf, int tag, int aclass, int depth);
72
+ char inf, int tag, int aclass, int depth);
74
73
 
75
74
  static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen);
76
75
 
77
76
  static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
78
- char *inf, char *cst,
79
- const unsigned char **in, long len,
80
- int exptag, int expclass, char opt,
81
- ASN1_TLC *ctx);
77
+ char *inf, char *cst,
78
+ const unsigned char **in, long len,
79
+ int exptag, int expclass, char opt, ASN1_TLC *ctx);
82
80
 
83
81
  static int asn1_template_ex_d2i(ASN1_VALUE **pval,
84
- const unsigned char **in, long len,
85
- const ASN1_TEMPLATE *tt, char opt,
86
- ASN1_TLC *ctx);
82
+ const unsigned char **in, long len,
83
+ const ASN1_TEMPLATE *tt, char opt,
84
+ ASN1_TLC *ctx);
87
85
  static int asn1_template_noexp_d2i(ASN1_VALUE **val,
88
- const unsigned char **in, long len,
89
- const ASN1_TEMPLATE *tt, char opt,
90
- ASN1_TLC *ctx);
86
+ const unsigned char **in, long len,
87
+ const ASN1_TEMPLATE *tt, char opt,
88
+ ASN1_TLC *ctx);
91
89
  static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
92
- const unsigned char **in, long len,
93
- const ASN1_ITEM *it,
94
- int tag, int aclass, char opt, ASN1_TLC *ctx);
90
+ const unsigned char **in, long len,
91
+ const ASN1_ITEM *it,
92
+ int tag, int aclass, char opt,
93
+ ASN1_TLC *ctx);
95
94
 
96
95
  /* Table to convert tags to bit values, used for MSTRING type */
97
96
  static const unsigned long tag2bit[32] = {
98
- 0, 0, 0, B_ASN1_BIT_STRING, /* tags 0 - 3 */
99
- B_ASN1_OCTET_STRING, 0, 0, B_ASN1_UNKNOWN,/* tags 4- 7 */
100
- B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 8-11 */
101
- B_ASN1_UTF8STRING,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,/* tags 12-15 */
102
- B_ASN1_SEQUENCE,0,B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING, /* tags 16-19 */
103
- B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING, /* tags 20-22 */
104
- B_ASN1_UTCTIME, B_ASN1_GENERALIZEDTIME, /* tags 23-24 */
105
- B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING, /* tags 25-27 */
106
- B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN, /* tags 28-31 */
107
- };
97
+ 0, 0, 0, B_ASN1_BIT_STRING, /* tags 0 - 3 */
98
+ B_ASN1_OCTET_STRING, 0, 0, B_ASN1_UNKNOWN, /* tags 4- 7 */
99
+ B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, /* tags
100
+ * 8-11 */
101
+ B_ASN1_UTF8STRING, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, /* tags
102
+ * 12-15
103
+ */
104
+ B_ASN1_SEQUENCE, 0, B_ASN1_NUMERICSTRING, B_ASN1_PRINTABLESTRING, /* tags
105
+ * 16-19
106
+ */
107
+ B_ASN1_T61STRING, B_ASN1_VIDEOTEXSTRING, B_ASN1_IA5STRING, /* tags 20-22 */
108
+ B_ASN1_UTCTIME, B_ASN1_GENERALIZEDTIME, /* tags 23-24 */
109
+ B_ASN1_GRAPHICSTRING, B_ASN1_ISO64STRING, B_ASN1_GENERALSTRING, /* tags
110
+ * 25-27 */
111
+ B_ASN1_UNIVERSALSTRING, B_ASN1_UNKNOWN, B_ASN1_BMPSTRING, B_ASN1_UNKNOWN, /* tags
112
+ * 28-31
113
+ */
114
+ };
108
115
 
109
116
  unsigned long ASN1_tag2bit(int tag)
110
- {
111
- if ((tag < 0) || (tag > 30)) return 0;
112
- return tag2bit[tag];
113
- }
117
+ {
118
+ if ((tag < 0) || (tag > 30))
119
+ return 0;
120
+ return tag2bit[tag];
121
+ }
114
122
 
115
123
  /* Macro to initialize and invalidate the cache */
116
124
 
117
- #define asn1_tlc_clear(c) if (c) (c)->valid = 0
125
+ #define asn1_tlc_clear(c) if (c) (c)->valid = 0
118
126
  /* Version to avoid compiler warning about 'c' always non-NULL */
119
- #define asn1_tlc_clear_nc(c) (c)->valid = 0
120
-
121
- /* Decode an ASN1 item, this currently behaves just
122
- * like a standard 'd2i' function. 'in' points to
123
- * a buffer to read the data from, in future we will
124
- * have more advanced versions that can input data
125
- * a piece at a time and this will simply be a special
126
- * case.
127
+ #define asn1_tlc_clear_nc(c) (c)->valid = 0
128
+
129
+ /*
130
+ * Decode an ASN1 item, this currently behaves just like a standard 'd2i'
131
+ * function. 'in' points to a buffer to read the data from, in future we
132
+ * will have more advanced versions that can input data a piece at a time and
133
+ * this will simply be a special case.
127
134
  */
128
135
 
129
136
  ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval,
130
- const unsigned char **in, long len, const ASN1_ITEM *it)
131
- {
132
- ASN1_TLC c;
133
- ASN1_VALUE *ptmpval = NULL;
134
- if (!pval)
135
- pval = &ptmpval;
136
- asn1_tlc_clear_nc(&c);
137
- if (ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0)
138
- return *pval;
139
- return NULL;
140
- }
137
+ const unsigned char **in, long len,
138
+ const ASN1_ITEM *it)
139
+ {
140
+ ASN1_TLC c;
141
+ ASN1_VALUE *ptmpval = NULL;
142
+ if (!pval)
143
+ pval = &ptmpval;
144
+ asn1_tlc_clear_nc(&c);
145
+ if (ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0)
146
+ return *pval;
147
+ return NULL;
148
+ }
141
149
 
142
150
  int ASN1_template_d2i(ASN1_VALUE **pval,
143
- const unsigned char **in, long len, const ASN1_TEMPLATE *tt)
144
- {
145
- ASN1_TLC c;
146
- asn1_tlc_clear_nc(&c);
147
- return asn1_template_ex_d2i(pval, in, len, tt, 0, &c);
148
- }
149
-
150
-
151
- /* Decode an item, taking care of IMPLICIT tagging, if any.
152
- * If 'opt' set and tag mismatch return -1 to handle OPTIONAL
151
+ const unsigned char **in, long len,
152
+ const ASN1_TEMPLATE *tt)
153
+ {
154
+ ASN1_TLC c;
155
+ asn1_tlc_clear_nc(&c);
156
+ return asn1_template_ex_d2i(pval, in, len, tt, 0, &c);
157
+ }
158
+
159
+ /*
160
+ * Decode an item, taking care of IMPLICIT tagging, if any. If 'opt' set and
161
+ * tag mismatch return -1 to handle OPTIONAL
153
162
  */
154
163
 
155
164
  int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
156
- const ASN1_ITEM *it,
157
- int tag, int aclass, char opt, ASN1_TLC *ctx)
158
- {
159
- const ASN1_TEMPLATE *tt, *errtt = NULL;
160
- const ASN1_COMPAT_FUNCS *cf;
161
- const ASN1_EXTERN_FUNCS *ef;
162
- const ASN1_AUX *aux = it->funcs;
163
- ASN1_aux_cb *asn1_cb;
164
- const unsigned char *p = NULL, *q;
165
- unsigned char *wp=NULL; /* BIG FAT WARNING! BREAKS CONST WHERE USED */
166
- unsigned char imphack = 0, oclass;
167
- char seq_eoc, seq_nolen, cst, isopt;
168
- long tmplen;
169
- int i;
170
- int otag;
171
- int ret = 0;
172
- ASN1_VALUE **pchptr, *ptmpval;
173
- int combine = aclass & ASN1_TFLG_COMBINE;
174
- if (!pval)
175
- return 0;
176
- if (aux && aux->asn1_cb)
177
- asn1_cb = aux->asn1_cb;
178
- else asn1_cb = 0;
179
-
180
- switch(it->itype)
181
- {
182
- case ASN1_ITYPE_PRIMITIVE:
183
- if (it->templates)
184
- {
185
- /* tagging or OPTIONAL is currently illegal on an item
186
- * template because the flags can't get passed down.
187
- * In practice this isn't a problem: we include the
188
- * relevant flags from the item template in the
189
- * template itself.
190
- */
191
- if ((tag != -1) || opt)
192
- {
193
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);
194
- goto err;
195
- }
196
- return asn1_template_ex_d2i(pval, in, len,
197
- it->templates, opt, ctx);
198
- }
199
- return asn1_d2i_ex_primitive(pval, in, len, it,
200
- tag, aclass, opt, ctx);
201
- break;
202
-
203
- case ASN1_ITYPE_MSTRING:
204
- p = *in;
205
- /* Just read in tag and class */
206
- ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL,
207
- &p, len, -1, 0, 1, ctx);
208
- if (!ret)
209
- {
210
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
211
- goto err;
212
- }
213
-
214
- /* Must be UNIVERSAL class */
215
- if (oclass != V_ASN1_UNIVERSAL)
216
- {
217
- /* If OPTIONAL, assume this is OK */
218
- if (opt) return -1;
219
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_MSTRING_NOT_UNIVERSAL);
220
- goto err;
221
- }
222
- /* Check tag matches bit map */
223
- if (!(ASN1_tag2bit(otag) & it->utype))
224
- {
225
- /* If OPTIONAL, assume this is OK */
226
- if (opt)
227
- return -1;
228
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_MSTRING_WRONG_TAG);
229
- goto err;
230
- }
231
- return asn1_d2i_ex_primitive(pval, in, len,
232
- it, otag, 0, 0, ctx);
233
-
234
- case ASN1_ITYPE_EXTERN:
235
- /* Use new style d2i */
236
- ef = it->funcs;
237
- return ef->asn1_ex_d2i(pval, in, len,
238
- it, tag, aclass, opt, ctx);
239
-
240
- case ASN1_ITYPE_COMPAT:
241
- /* we must resort to old style evil hackery */
242
- cf = it->funcs;
243
-
244
- /* If OPTIONAL see if it is there */
245
- if (opt)
246
- {
247
- int exptag;
248
- p = *in;
249
- if (tag == -1)
250
- exptag = it->utype;
251
- else exptag = tag;
252
- /* Don't care about anything other than presence
253
- * of expected tag */
254
-
255
- ret = asn1_check_tlen(NULL, NULL, NULL, NULL, NULL,
256
- &p, len, exptag, aclass, 1, ctx);
257
- if (!ret)
258
- {
259
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
260
- goto err;
261
- }
262
- if (ret == -1)
263
- return -1;
264
- }
265
-
266
- /* This is the old style evil hack IMPLICIT handling:
267
- * since the underlying code is expecting a tag and
268
- * class other than the one present we change the
269
- * buffer temporarily then change it back afterwards.
270
- * This doesn't and never did work for tags > 30.
271
- *
272
- * Yes this is *horrible* but it is only needed for
273
- * old style d2i which will hopefully not be around
274
- * for much longer.
275
- * FIXME: should copy the buffer then modify it so
276
- * the input buffer can be const: we should *always*
277
- * copy because the old style d2i might modify the
278
- * buffer.
279
- */
280
-
281
- if (tag != -1)
282
- {
283
- wp = *(unsigned char **)in;
284
- imphack = *wp;
285
- if (p == NULL)
286
- {
287
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
288
- goto err;
289
- }
290
- *wp = (unsigned char)((*p & V_ASN1_CONSTRUCTED)
291
- | it->utype);
292
- }
293
-
294
- ptmpval = cf->asn1_d2i(pval, in, len);
295
-
296
- if (tag != -1)
297
- *wp = imphack;
298
-
299
- if (ptmpval)
300
- return 1;
301
-
302
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
303
- goto err;
304
-
305
-
306
- case ASN1_ITYPE_CHOICE:
307
- if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
308
- goto auxerr;
309
-
310
- if (*pval)
311
- {
312
- /* Free up and zero CHOICE value if initialised */
313
- i = asn1_get_choice_selector(pval, it);
314
- if ((i >= 0) && (i < it->tcount))
315
- {
316
- tt = it->templates + i;
317
- pchptr = asn1_get_field_ptr(pval, tt);
318
- ASN1_template_free(pchptr, tt);
319
- asn1_set_choice_selector(pval, -1, it);
320
- }
321
- }
322
- else if (!ASN1_item_ex_new(pval, it))
323
- {
324
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
325
- goto err;
326
- }
327
- /* CHOICE type, try each possibility in turn */
328
- p = *in;
329
- for (i = 0, tt=it->templates; i < it->tcount; i++, tt++)
330
- {
331
- pchptr = asn1_get_field_ptr(pval, tt);
332
- /* We mark field as OPTIONAL so its absence
333
- * can be recognised.
334
- */
335
- ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, ctx);
336
- /* If field not present, try the next one */
337
- if (ret == -1)
338
- continue;
339
- /* If positive return, read OK, break loop */
340
- if (ret > 0)
341
- break;
342
- /* Otherwise must be an ASN1 parsing error */
343
- errtt = tt;
344
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
345
- goto err;
346
- }
347
-
348
- /* Did we fall off the end without reading anything? */
349
- if (i == it->tcount)
350
- {
351
- /* If OPTIONAL, this is OK */
352
- if (opt)
353
- {
354
- /* Free and zero it */
355
- ASN1_item_ex_free(pval, it);
356
- return -1;
357
- }
358
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NO_MATCHING_CHOICE_TYPE);
359
- goto err;
360
- }
361
-
362
- asn1_set_choice_selector(pval, i, it);
363
- if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL))
364
- goto auxerr;
365
- *in = p;
366
- return 1;
367
-
368
- case ASN1_ITYPE_NDEF_SEQUENCE:
369
- case ASN1_ITYPE_SEQUENCE:
370
- p = *in;
371
- tmplen = len;
372
-
373
- /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */
374
- if (tag == -1)
375
- {
376
- tag = V_ASN1_SEQUENCE;
377
- aclass = V_ASN1_UNIVERSAL;
378
- }
379
- /* Get SEQUENCE length and update len, p */
380
- ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst,
381
- &p, len, tag, aclass, opt, ctx);
382
- if (!ret)
383
- {
384
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
385
- goto err;
386
- }
387
- else if (ret == -1)
388
- return -1;
389
- if (aux && (aux->flags & ASN1_AFLG_BROKEN))
390
- {
391
- len = tmplen - (p - *in);
392
- seq_nolen = 1;
393
- }
394
- /* If indefinite we don't do a length check */
395
- else seq_nolen = seq_eoc;
396
- if (!cst)
397
- {
398
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_SEQUENCE_NOT_CONSTRUCTED);
399
- goto err;
400
- }
401
-
402
- if (!*pval && !ASN1_item_ex_new(pval, it))
403
- {
404
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
405
- goto err;
406
- }
407
-
408
- if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
409
- goto auxerr;
410
-
411
- /* Free up and zero any ADB found */
412
- for (i = 0, tt = it->templates; i < it->tcount; i++, tt++)
413
- {
414
- if (tt->flags & ASN1_TFLG_ADB_MASK)
415
- {
416
- const ASN1_TEMPLATE *seqtt;
417
- ASN1_VALUE **pseqval;
418
- seqtt = asn1_do_adb(pval, tt, 1);
419
- pseqval = asn1_get_field_ptr(pval, seqtt);
420
- ASN1_template_free(pseqval, seqtt);
421
- }
422
- }
423
-
424
- /* Get each field entry */
425
- for (i = 0, tt = it->templates; i < it->tcount; i++, tt++)
426
- {
427
- const ASN1_TEMPLATE *seqtt;
428
- ASN1_VALUE **pseqval;
429
- seqtt = asn1_do_adb(pval, tt, 1);
430
- if (!seqtt)
431
- goto err;
432
- pseqval = asn1_get_field_ptr(pval, seqtt);
433
- /* Have we ran out of data? */
434
- if (!len)
435
- break;
436
- q = p;
437
- if (asn1_check_eoc(&p, len))
438
- {
439
- if (!seq_eoc)
440
- {
441
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNEXPECTED_EOC);
442
- goto err;
443
- }
444
- len -= p - q;
445
- seq_eoc = 0;
446
- q = p;
447
- break;
448
- }
449
- /* This determines the OPTIONAL flag value. The field
450
- * cannot be omitted if it is the last of a SEQUENCE
451
- * and there is still data to be read. This isn't
452
- * strictly necessary but it increases efficiency in
453
- * some cases.
454
- */
455
- if (i == (it->tcount - 1))
456
- isopt = 0;
457
- else isopt = (char)(seqtt->flags & ASN1_TFLG_OPTIONAL);
458
- /* attempt to read in field, allowing each to be
459
- * OPTIONAL */
460
-
461
- ret = asn1_template_ex_d2i(pseqval, &p, len,
462
- seqtt, isopt, ctx);
463
- if (!ret)
464
- {
465
- errtt = seqtt;
466
- goto err;
467
- }
468
- else if (ret == -1)
469
- {
470
- /* OPTIONAL component absent.
471
- * Free and zero the field.
472
- */
473
- ASN1_template_free(pseqval, seqtt);
474
- continue;
475
- }
476
- /* Update length */
477
- len -= p - q;
478
- }
479
-
480
- /* Check for EOC if expecting one */
481
- if (seq_eoc && !asn1_check_eoc(&p, len))
482
- {
483
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_EOC);
484
- goto err;
485
- }
486
- /* Check all data read */
487
- if (!seq_nolen && len)
488
- {
489
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_SEQUENCE_LENGTH_MISMATCH);
490
- goto err;
491
- }
492
-
493
- /* If we get here we've got no more data in the SEQUENCE,
494
- * however we may not have read all fields so check all
495
- * remaining are OPTIONAL and clear any that are.
496
- */
497
- for (; i < it->tcount; tt++, i++)
498
- {
499
- const ASN1_TEMPLATE *seqtt;
500
- seqtt = asn1_do_adb(pval, tt, 1);
501
- if (!seqtt)
502
- goto err;
503
- if (seqtt->flags & ASN1_TFLG_OPTIONAL)
504
- {
505
- ASN1_VALUE **pseqval;
506
- pseqval = asn1_get_field_ptr(pval, seqtt);
507
- ASN1_template_free(pseqval, seqtt);
508
- }
509
- else
510
- {
511
- errtt = seqtt;
512
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_FIELD_MISSING);
513
- goto err;
514
- }
515
- }
516
- /* Save encoding */
517
- if (!asn1_enc_save(pval, *in, p - *in, it))
518
- goto auxerr;
519
- if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL))
520
- goto auxerr;
521
- *in = p;
522
- return 1;
523
-
524
- default:
525
- return 0;
526
- }
527
- auxerr:
528
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_AUX_ERROR);
529
- err:
530
- if (combine == 0)
531
- ASN1_item_ex_free(pval, it);
532
- if (errtt)
533
- ERR_add_error_data(4, "Field=", errtt->field_name,
534
- ", Type=", it->sname);
535
- else
536
- ERR_add_error_data(2, "Type=", it->sname);
537
- return 0;
538
- }
539
-
540
- /* Templates are handled with two separate functions.
541
- * One handles any EXPLICIT tag and the other handles the rest.
165
+ const ASN1_ITEM *it,
166
+ int tag, int aclass, char opt, ASN1_TLC *ctx)
167
+ {
168
+ const ASN1_TEMPLATE *tt, *errtt = NULL;
169
+ const ASN1_COMPAT_FUNCS *cf;
170
+ const ASN1_EXTERN_FUNCS *ef;
171
+ const ASN1_AUX *aux = it->funcs;
172
+ ASN1_aux_cb *asn1_cb;
173
+ const unsigned char *p = NULL, *q;
174
+ unsigned char *wp = NULL; /* BIG FAT WARNING! BREAKS CONST WHERE USED */
175
+ unsigned char imphack = 0, oclass;
176
+ char seq_eoc, seq_nolen, cst, isopt;
177
+ long tmplen;
178
+ int i;
179
+ int otag;
180
+ int ret = 0;
181
+ ASN1_VALUE **pchptr, *ptmpval;
182
+ int combine = aclass & ASN1_TFLG_COMBINE;
183
+ if (!pval)
184
+ return 0;
185
+ if (aux && aux->asn1_cb)
186
+ asn1_cb = aux->asn1_cb;
187
+ else
188
+ asn1_cb = 0;
189
+
190
+ switch (it->itype) {
191
+ case ASN1_ITYPE_PRIMITIVE:
192
+ if (it->templates) {
193
+ /*
194
+ * tagging or OPTIONAL is currently illegal on an item template
195
+ * because the flags can't get passed down. In practice this
196
+ * isn't a problem: we include the relevant flags from the item
197
+ * template in the template itself.
198
+ */
199
+ if ((tag != -1) || opt) {
200
+ OPENSSL_PUT_ERROR(ASN1,
201
+ ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);
202
+ goto err;
203
+ }
204
+ return asn1_template_ex_d2i(pval, in, len,
205
+ it->templates, opt, ctx);
206
+ }
207
+ return asn1_d2i_ex_primitive(pval, in, len, it,
208
+ tag, aclass, opt, ctx);
209
+ break;
210
+
211
+ case ASN1_ITYPE_MSTRING:
212
+ p = *in;
213
+ /* Just read in tag and class */
214
+ ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL,
215
+ &p, len, -1, 0, 1, ctx);
216
+ if (!ret) {
217
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
218
+ goto err;
219
+ }
220
+
221
+ /* Must be UNIVERSAL class */
222
+ if (oclass != V_ASN1_UNIVERSAL) {
223
+ /* If OPTIONAL, assume this is OK */
224
+ if (opt)
225
+ return -1;
226
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_MSTRING_NOT_UNIVERSAL);
227
+ goto err;
228
+ }
229
+ /* Check tag matches bit map */
230
+ if (!(ASN1_tag2bit(otag) & it->utype)) {
231
+ /* If OPTIONAL, assume this is OK */
232
+ if (opt)
233
+ return -1;
234
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_MSTRING_WRONG_TAG);
235
+ goto err;
236
+ }
237
+ return asn1_d2i_ex_primitive(pval, in, len, it, otag, 0, 0, ctx);
238
+
239
+ case ASN1_ITYPE_EXTERN:
240
+ /* Use new style d2i */
241
+ ef = it->funcs;
242
+ return ef->asn1_ex_d2i(pval, in, len, it, tag, aclass, opt, ctx);
243
+
244
+ case ASN1_ITYPE_COMPAT:
245
+ /* we must resort to old style evil hackery */
246
+ cf = it->funcs;
247
+
248
+ /* If OPTIONAL see if it is there */
249
+ if (opt) {
250
+ int exptag;
251
+ p = *in;
252
+ if (tag == -1)
253
+ exptag = it->utype;
254
+ else
255
+ exptag = tag;
256
+ /*
257
+ * Don't care about anything other than presence of expected tag
258
+ */
259
+
260
+ ret = asn1_check_tlen(NULL, NULL, NULL, NULL, NULL,
261
+ &p, len, exptag, aclass, 1, ctx);
262
+ if (!ret) {
263
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
264
+ goto err;
265
+ }
266
+ if (ret == -1)
267
+ return -1;
268
+ }
269
+
270
+ /*
271
+ * This is the old style evil hack IMPLICIT handling: since the
272
+ * underlying code is expecting a tag and class other than the one
273
+ * present we change the buffer temporarily then change it back
274
+ * afterwards. This doesn't and never did work for tags > 30. Yes
275
+ * this is *horrible* but it is only needed for old style d2i which
276
+ * will hopefully not be around for much longer. FIXME: should copy
277
+ * the buffer then modify it so the input buffer can be const: we
278
+ * should *always* copy because the old style d2i might modify the
279
+ * buffer.
280
+ */
281
+
282
+ if (tag != -1) {
283
+ wp = *(unsigned char **)in;
284
+ imphack = *wp;
285
+ if (p == NULL) {
286
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
287
+ goto err;
288
+ }
289
+ *wp = (unsigned char)((*p & V_ASN1_CONSTRUCTED)
290
+ | it->utype);
291
+ }
292
+
293
+ ptmpval = cf->asn1_d2i(pval, in, len);
294
+
295
+ if (tag != -1)
296
+ *wp = imphack;
297
+
298
+ if (ptmpval)
299
+ return 1;
300
+
301
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
302
+ goto err;
303
+
304
+ case ASN1_ITYPE_CHOICE:
305
+ if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
306
+ goto auxerr;
307
+
308
+ if (*pval) {
309
+ /* Free up and zero CHOICE value if initialised */
310
+ i = asn1_get_choice_selector(pval, it);
311
+ if ((i >= 0) && (i < it->tcount)) {
312
+ tt = it->templates + i;
313
+ pchptr = asn1_get_field_ptr(pval, tt);
314
+ ASN1_template_free(pchptr, tt);
315
+ asn1_set_choice_selector(pval, -1, it);
316
+ }
317
+ } else if (!ASN1_item_ex_new(pval, it)) {
318
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
319
+ goto err;
320
+ }
321
+ /* CHOICE type, try each possibility in turn */
322
+ p = *in;
323
+ for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
324
+ pchptr = asn1_get_field_ptr(pval, tt);
325
+ /*
326
+ * We mark field as OPTIONAL so its absence can be recognised.
327
+ */
328
+ ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, ctx);
329
+ /* If field not present, try the next one */
330
+ if (ret == -1)
331
+ continue;
332
+ /* If positive return, read OK, break loop */
333
+ if (ret > 0)
334
+ break;
335
+ /* Otherwise must be an ASN1 parsing error */
336
+ errtt = tt;
337
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
338
+ goto err;
339
+ }
340
+
341
+ /* Did we fall off the end without reading anything? */
342
+ if (i == it->tcount) {
343
+ /* If OPTIONAL, this is OK */
344
+ if (opt) {
345
+ /* Free and zero it */
346
+ ASN1_item_ex_free(pval, it);
347
+ return -1;
348
+ }
349
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NO_MATCHING_CHOICE_TYPE);
350
+ goto err;
351
+ }
352
+
353
+ asn1_set_choice_selector(pval, i, it);
354
+ if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL))
355
+ goto auxerr;
356
+ *in = p;
357
+ return 1;
358
+
359
+ case ASN1_ITYPE_NDEF_SEQUENCE:
360
+ case ASN1_ITYPE_SEQUENCE:
361
+ p = *in;
362
+ tmplen = len;
363
+
364
+ /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */
365
+ if (tag == -1) {
366
+ tag = V_ASN1_SEQUENCE;
367
+ aclass = V_ASN1_UNIVERSAL;
368
+ }
369
+ /* Get SEQUENCE length and update len, p */
370
+ ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst,
371
+ &p, len, tag, aclass, opt, ctx);
372
+ if (!ret) {
373
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
374
+ goto err;
375
+ } else if (ret == -1)
376
+ return -1;
377
+ if (aux && (aux->flags & ASN1_AFLG_BROKEN)) {
378
+ len = tmplen - (p - *in);
379
+ seq_nolen = 1;
380
+ }
381
+ /* If indefinite we don't do a length check */
382
+ else
383
+ seq_nolen = seq_eoc;
384
+ if (!cst) {
385
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_SEQUENCE_NOT_CONSTRUCTED);
386
+ goto err;
387
+ }
388
+
389
+ if (!*pval && !ASN1_item_ex_new(pval, it)) {
390
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
391
+ goto err;
392
+ }
393
+
394
+ if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
395
+ goto auxerr;
396
+
397
+ /* Free up and zero any ADB found */
398
+ for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
399
+ if (tt->flags & ASN1_TFLG_ADB_MASK) {
400
+ const ASN1_TEMPLATE *seqtt;
401
+ ASN1_VALUE **pseqval;
402
+ seqtt = asn1_do_adb(pval, tt, 1);
403
+ pseqval = asn1_get_field_ptr(pval, seqtt);
404
+ ASN1_template_free(pseqval, seqtt);
405
+ }
406
+ }
407
+
408
+ /* Get each field entry */
409
+ for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
410
+ const ASN1_TEMPLATE *seqtt;
411
+ ASN1_VALUE **pseqval;
412
+ seqtt = asn1_do_adb(pval, tt, 1);
413
+ if (!seqtt)
414
+ goto err;
415
+ pseqval = asn1_get_field_ptr(pval, seqtt);
416
+ /* Have we ran out of data? */
417
+ if (!len)
418
+ break;
419
+ q = p;
420
+ if (asn1_check_eoc(&p, len)) {
421
+ if (!seq_eoc) {
422
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNEXPECTED_EOC);
423
+ goto err;
424
+ }
425
+ len -= p - q;
426
+ seq_eoc = 0;
427
+ q = p;
428
+ break;
429
+ }
430
+ /*
431
+ * This determines the OPTIONAL flag value. The field cannot be
432
+ * omitted if it is the last of a SEQUENCE and there is still
433
+ * data to be read. This isn't strictly necessary but it
434
+ * increases efficiency in some cases.
435
+ */
436
+ if (i == (it->tcount - 1))
437
+ isopt = 0;
438
+ else
439
+ isopt = (char)(seqtt->flags & ASN1_TFLG_OPTIONAL);
440
+ /*
441
+ * attempt to read in field, allowing each to be OPTIONAL
442
+ */
443
+
444
+ ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, ctx);
445
+ if (!ret) {
446
+ errtt = seqtt;
447
+ goto err;
448
+ } else if (ret == -1) {
449
+ /*
450
+ * OPTIONAL component absent. Free and zero the field.
451
+ */
452
+ ASN1_template_free(pseqval, seqtt);
453
+ continue;
454
+ }
455
+ /* Update length */
456
+ len -= p - q;
457
+ }
458
+
459
+ /* Check for EOC if expecting one */
460
+ if (seq_eoc && !asn1_check_eoc(&p, len)) {
461
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_EOC);
462
+ goto err;
463
+ }
464
+ /* Check all data read */
465
+ if (!seq_nolen && len) {
466
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_SEQUENCE_LENGTH_MISMATCH);
467
+ goto err;
468
+ }
469
+
470
+ /*
471
+ * If we get here we've got no more data in the SEQUENCE, however we
472
+ * may not have read all fields so check all remaining are OPTIONAL
473
+ * and clear any that are.
474
+ */
475
+ for (; i < it->tcount; tt++, i++) {
476
+ const ASN1_TEMPLATE *seqtt;
477
+ seqtt = asn1_do_adb(pval, tt, 1);
478
+ if (!seqtt)
479
+ goto err;
480
+ if (seqtt->flags & ASN1_TFLG_OPTIONAL) {
481
+ ASN1_VALUE **pseqval;
482
+ pseqval = asn1_get_field_ptr(pval, seqtt);
483
+ ASN1_template_free(pseqval, seqtt);
484
+ } else {
485
+ errtt = seqtt;
486
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_FIELD_MISSING);
487
+ goto err;
488
+ }
489
+ }
490
+ /* Save encoding */
491
+ if (!asn1_enc_save(pval, *in, p - *in, it))
492
+ goto auxerr;
493
+ if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL))
494
+ goto auxerr;
495
+ *in = p;
496
+ return 1;
497
+
498
+ default:
499
+ return 0;
500
+ }
501
+ auxerr:
502
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_AUX_ERROR);
503
+ err:
504
+ if (combine == 0)
505
+ ASN1_item_ex_free(pval, it);
506
+ if (errtt)
507
+ ERR_add_error_data(4, "Field=", errtt->field_name,
508
+ ", Type=", it->sname);
509
+ else
510
+ ERR_add_error_data(2, "Type=", it->sname);
511
+ return 0;
512
+ }
513
+
514
+ /*
515
+ * Templates are handled with two separate functions. One handles any
516
+ * EXPLICIT tag and the other handles the rest.
542
517
  */
543
518
 
544
519
  static int asn1_template_ex_d2i(ASN1_VALUE **val,
545
- const unsigned char **in, long inlen,
546
- const ASN1_TEMPLATE *tt, char opt,
547
- ASN1_TLC *ctx)
548
- {
549
- int flags, aclass;
550
- int ret;
551
- long len;
552
- const unsigned char *p, *q;
553
- char exp_eoc;
554
- if (!val)
555
- return 0;
556
- flags = tt->flags;
557
- aclass = flags & ASN1_TFLG_TAG_CLASS;
558
-
559
- p = *in;
560
-
561
- /* Check if EXPLICIT tag expected */
562
- if (flags & ASN1_TFLG_EXPTAG)
563
- {
564
- char cst;
565
- /* Need to work out amount of data available to the inner
566
- * content and where it starts: so read in EXPLICIT header to
567
- * get the info.
568
- */
569
- ret = asn1_check_tlen(&len, NULL, NULL, &exp_eoc, &cst,
570
- &p, inlen, tt->tag, aclass, opt, ctx);
571
- q = p;
572
- if (!ret)
573
- {
574
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
575
- return 0;
576
- }
577
- else if (ret == -1)
578
- return -1;
579
- if (!cst)
580
- {
581
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED);
582
- return 0;
583
- }
584
- /* We've found the field so it can't be OPTIONAL now */
585
- ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx);
586
- if (!ret)
587
- {
588
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
589
- return 0;
590
- }
591
- /* We read the field in OK so update length */
592
- len -= p - q;
593
- if (exp_eoc)
594
- {
595
- /* If NDEF we must have an EOC here */
596
- if (!asn1_check_eoc(&p, len))
597
- {
598
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_EOC);
599
- goto err;
600
- }
601
- }
602
- else
603
- {
604
- /* Otherwise we must hit the EXPLICIT tag end or its
605
- * an error */
606
- if (len)
607
- {
608
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_EXPLICIT_LENGTH_MISMATCH);
609
- goto err;
610
- }
611
- }
612
- }
613
- else
614
- return asn1_template_noexp_d2i(val, in, inlen,
615
- tt, opt, ctx);
616
-
617
- *in = p;
618
- return 1;
619
-
620
- err:
621
- ASN1_template_free(val, tt);
622
- return 0;
623
- }
520
+ const unsigned char **in, long inlen,
521
+ const ASN1_TEMPLATE *tt, char opt,
522
+ ASN1_TLC *ctx)
523
+ {
524
+ int flags, aclass;
525
+ int ret;
526
+ long len;
527
+ const unsigned char *p, *q;
528
+ char exp_eoc;
529
+ if (!val)
530
+ return 0;
531
+ flags = tt->flags;
532
+ aclass = flags & ASN1_TFLG_TAG_CLASS;
533
+
534
+ p = *in;
535
+
536
+ /* Check if EXPLICIT tag expected */
537
+ if (flags & ASN1_TFLG_EXPTAG) {
538
+ char cst;
539
+ /*
540
+ * Need to work out amount of data available to the inner content and
541
+ * where it starts: so read in EXPLICIT header to get the info.
542
+ */
543
+ ret = asn1_check_tlen(&len, NULL, NULL, &exp_eoc, &cst,
544
+ &p, inlen, tt->tag, aclass, opt, ctx);
545
+ q = p;
546
+ if (!ret) {
547
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
548
+ return 0;
549
+ } else if (ret == -1)
550
+ return -1;
551
+ if (!cst) {
552
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED);
553
+ return 0;
554
+ }
555
+ /* We've found the field so it can't be OPTIONAL now */
556
+ ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx);
557
+ if (!ret) {
558
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
559
+ return 0;
560
+ }
561
+ /* We read the field in OK so update length */
562
+ len -= p - q;
563
+ if (exp_eoc) {
564
+ /* If NDEF we must have an EOC here */
565
+ if (!asn1_check_eoc(&p, len)) {
566
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_EOC);
567
+ goto err;
568
+ }
569
+ } else {
570
+ /*
571
+ * Otherwise we must hit the EXPLICIT tag end or its an error
572
+ */
573
+ if (len) {
574
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_EXPLICIT_LENGTH_MISMATCH);
575
+ goto err;
576
+ }
577
+ }
578
+ } else
579
+ return asn1_template_noexp_d2i(val, in, inlen, tt, opt, ctx);
580
+
581
+ *in = p;
582
+ return 1;
583
+
584
+ err:
585
+ ASN1_template_free(val, tt);
586
+ return 0;
587
+ }
624
588
 
625
589
  static int asn1_template_noexp_d2i(ASN1_VALUE **val,
626
- const unsigned char **in, long len,
627
- const ASN1_TEMPLATE *tt, char opt,
628
- ASN1_TLC *ctx)
629
- {
630
- int flags, aclass;
631
- int ret;
632
- const unsigned char *p;
633
- if (!val)
634
- return 0;
635
- flags = tt->flags;
636
- aclass = flags & ASN1_TFLG_TAG_CLASS;
637
-
638
- p = *in;
639
-
640
- if (flags & ASN1_TFLG_SK_MASK)
641
- {
642
- /* SET OF, SEQUENCE OF */
643
- int sktag, skaclass;
644
- char sk_eoc;
645
- /* First work out expected inner tag value */
646
- if (flags & ASN1_TFLG_IMPTAG)
647
- {
648
- sktag = tt->tag;
649
- skaclass = aclass;
650
- }
651
- else
652
- {
653
- skaclass = V_ASN1_UNIVERSAL;
654
- if (flags & ASN1_TFLG_SET_OF)
655
- sktag = V_ASN1_SET;
656
- else
657
- sktag = V_ASN1_SEQUENCE;
658
- }
659
- /* Get the tag */
660
- ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL,
661
- &p, len, sktag, skaclass, opt, ctx);
662
- if (!ret)
663
- {
664
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
665
- return 0;
666
- }
667
- else if (ret == -1)
668
- return -1;
669
- if (!*val)
670
- *val = (ASN1_VALUE *)sk_new_null();
671
- else
672
- {
673
- /* We've got a valid STACK: free up any items present */
674
- STACK_OF(ASN1_VALUE) *sktmp
675
- = (STACK_OF(ASN1_VALUE) *)*val;
676
- ASN1_VALUE *vtmp;
677
- while(sk_ASN1_VALUE_num(sktmp) > 0)
678
- {
679
- vtmp = sk_ASN1_VALUE_pop(sktmp);
680
- ASN1_item_ex_free(&vtmp,
681
- ASN1_ITEM_ptr(tt->item));
682
- }
683
- }
684
-
685
- if (!*val)
686
- {
687
- OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
688
- goto err;
689
- }
690
-
691
- /* Read as many items as we can */
692
- while(len > 0)
693
- {
694
- ASN1_VALUE *skfield;
695
- const unsigned char *q = p;
696
- /* See if EOC found */
697
- if (asn1_check_eoc(&p, len))
698
- {
699
- if (!sk_eoc)
700
- {
701
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNEXPECTED_EOC);
702
- goto err;
703
- }
704
- len -= p - q;
705
- sk_eoc = 0;
706
- break;
707
- }
708
- skfield = NULL;
709
- if (!ASN1_item_ex_d2i(&skfield, &p, len,
710
- ASN1_ITEM_ptr(tt->item),
711
- -1, 0, 0, ctx))
712
- {
713
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
714
- goto err;
715
- }
716
- len -= p - q;
717
- if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val,
718
- skfield))
719
- {
720
- OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
721
- goto err;
722
- }
723
- }
724
- if (sk_eoc)
725
- {
726
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_EOC);
727
- goto err;
728
- }
729
- }
730
- else if (flags & ASN1_TFLG_IMPTAG)
731
- {
732
- /* IMPLICIT tagging */
733
- ret = ASN1_item_ex_d2i(val, &p, len,
734
- ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, ctx);
735
- if (!ret)
736
- {
737
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
738
- goto err;
739
- }
740
- else if (ret == -1)
741
- return -1;
742
- }
743
- else
744
- {
745
- /* Nothing special */
746
- ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item),
747
- -1, tt->flags & ASN1_TFLG_COMBINE, opt, ctx);
748
- if (!ret)
749
- {
750
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
751
- goto err;
752
- }
753
- else if (ret == -1)
754
- return -1;
755
- }
756
-
757
- *in = p;
758
- return 1;
759
-
760
- err:
761
- ASN1_template_free(val, tt);
762
- return 0;
763
- }
590
+ const unsigned char **in, long len,
591
+ const ASN1_TEMPLATE *tt, char opt,
592
+ ASN1_TLC *ctx)
593
+ {
594
+ int flags, aclass;
595
+ int ret;
596
+ const unsigned char *p;
597
+ if (!val)
598
+ return 0;
599
+ flags = tt->flags;
600
+ aclass = flags & ASN1_TFLG_TAG_CLASS;
601
+
602
+ p = *in;
603
+
604
+ if (flags & ASN1_TFLG_SK_MASK) {
605
+ /* SET OF, SEQUENCE OF */
606
+ int sktag, skaclass;
607
+ char sk_eoc;
608
+ /* First work out expected inner tag value */
609
+ if (flags & ASN1_TFLG_IMPTAG) {
610
+ sktag = tt->tag;
611
+ skaclass = aclass;
612
+ } else {
613
+ skaclass = V_ASN1_UNIVERSAL;
614
+ if (flags & ASN1_TFLG_SET_OF)
615
+ sktag = V_ASN1_SET;
616
+ else
617
+ sktag = V_ASN1_SEQUENCE;
618
+ }
619
+ /* Get the tag */
620
+ ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL,
621
+ &p, len, sktag, skaclass, opt, ctx);
622
+ if (!ret) {
623
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
624
+ return 0;
625
+ } else if (ret == -1)
626
+ return -1;
627
+ if (!*val)
628
+ *val = (ASN1_VALUE *)sk_new_null();
629
+ else {
630
+ /*
631
+ * We've got a valid STACK: free up any items present
632
+ */
633
+ STACK_OF(ASN1_VALUE) *sktmp = (STACK_OF(ASN1_VALUE) *)*val;
634
+ ASN1_VALUE *vtmp;
635
+ while (sk_ASN1_VALUE_num(sktmp) > 0) {
636
+ vtmp = sk_ASN1_VALUE_pop(sktmp);
637
+ ASN1_item_ex_free(&vtmp, ASN1_ITEM_ptr(tt->item));
638
+ }
639
+ }
640
+
641
+ if (!*val) {
642
+ OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
643
+ goto err;
644
+ }
645
+
646
+ /* Read as many items as we can */
647
+ while (len > 0) {
648
+ ASN1_VALUE *skfield;
649
+ const unsigned char *q = p;
650
+ /* See if EOC found */
651
+ if (asn1_check_eoc(&p, len)) {
652
+ if (!sk_eoc) {
653
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNEXPECTED_EOC);
654
+ goto err;
655
+ }
656
+ len -= p - q;
657
+ sk_eoc = 0;
658
+ break;
659
+ }
660
+ skfield = NULL;
661
+ if (!ASN1_item_ex_d2i(&skfield, &p, len,
662
+ ASN1_ITEM_ptr(tt->item), -1, 0, 0, ctx)) {
663
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
664
+ goto err;
665
+ }
666
+ len -= p - q;
667
+ if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val, skfield)) {
668
+ OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
669
+ goto err;
670
+ }
671
+ }
672
+ if (sk_eoc) {
673
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_EOC);
674
+ goto err;
675
+ }
676
+ } else if (flags & ASN1_TFLG_IMPTAG) {
677
+ /* IMPLICIT tagging */
678
+ ret = ASN1_item_ex_d2i(val, &p, len,
679
+ ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt,
680
+ ctx);
681
+ if (!ret) {
682
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
683
+ goto err;
684
+ } else if (ret == -1)
685
+ return -1;
686
+ } else {
687
+ /* Nothing special */
688
+ ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item),
689
+ -1, tt->flags & ASN1_TFLG_COMBINE, opt, ctx);
690
+ if (!ret) {
691
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
692
+ goto err;
693
+ } else if (ret == -1)
694
+ return -1;
695
+ }
696
+
697
+ *in = p;
698
+ return 1;
699
+
700
+ err:
701
+ ASN1_template_free(val, tt);
702
+ return 0;
703
+ }
764
704
 
765
705
  static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
766
- const unsigned char **in, long inlen,
767
- const ASN1_ITEM *it,
768
- int tag, int aclass, char opt, ASN1_TLC *ctx)
769
- OPENSSL_SUPPRESS_POTENTIALLY_UNINITIALIZED_WARNINGS
770
- {
771
- int ret = 0, utype;
772
- long plen;
773
- char cst, inf, free_cont = 0;
774
- const unsigned char *p;
775
- BUF_MEM buf;
776
- const unsigned char *cont = NULL;
777
- long len;
778
- if (!pval)
779
- {
780
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_NULL);
781
- return 0; /* Should never happen */
782
- }
783
-
784
- if (it->itype == ASN1_ITYPE_MSTRING)
785
- {
786
- utype = tag;
787
- tag = -1;
788
- }
789
- else
790
- utype = it->utype;
791
-
792
- if (utype == V_ASN1_ANY)
793
- {
794
- /* If type is ANY need to figure out type from tag */
795
- unsigned char oclass;
796
- if (tag >= 0)
797
- {
798
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_TAGGED_ANY);
799
- return 0;
800
- }
801
- if (opt)
802
- {
803
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_OPTIONAL_ANY);
804
- return 0;
805
- }
806
- p = *in;
807
- ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL,
808
- &p, inlen, -1, 0, 0, ctx);
809
- if (!ret)
810
- {
811
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
812
- return 0;
813
- }
814
- if (oclass != V_ASN1_UNIVERSAL)
815
- utype = V_ASN1_OTHER;
816
- }
817
- if (tag == -1)
818
- {
819
- tag = utype;
820
- aclass = V_ASN1_UNIVERSAL;
821
- }
822
- p = *in;
823
- /* Check header */
824
- ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst,
825
- &p, inlen, tag, aclass, opt, ctx);
826
- if (!ret)
827
- {
828
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
829
- return 0;
830
- }
831
- else if (ret == -1)
832
- return -1;
833
- ret = 0;
834
- /* SEQUENCE, SET and "OTHER" are left in encoded form */
835
- if ((utype == V_ASN1_SEQUENCE)
836
- || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER))
837
- {
838
- /* Clear context cache for type OTHER because the auto clear
839
- * when we have a exact match wont work
840
- */
841
- if (utype == V_ASN1_OTHER)
842
- {
843
- asn1_tlc_clear(ctx);
844
- }
845
- /* SEQUENCE and SET must be constructed */
846
- else if (!cst)
847
- {
848
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_CONSTRUCTED);
849
- return 0;
850
- }
851
-
852
- cont = *in;
853
- /* If indefinite length constructed find the real end */
854
- if (inf)
855
- {
856
- if (!asn1_find_end(&p, plen, inf))
857
- goto err;
858
- len = p - cont;
859
- }
860
- else
861
- {
862
- len = p - cont + plen;
863
- p += plen;
864
- buf.data = NULL;
865
- }
866
- }
867
- else if (cst)
868
- {
869
- if (utype == V_ASN1_NULL || utype == V_ASN1_BOOLEAN
870
- || utype == V_ASN1_OBJECT || utype == V_ASN1_INTEGER
871
- || utype == V_ASN1_ENUMERATED)
872
- {
873
- /* These types only have primitive encodings. */
874
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_PRIMITIVE);
875
- return 0;
876
- }
877
-
878
- buf.length = 0;
879
- buf.max = 0;
880
- buf.data = NULL;
881
- /* Should really check the internal tags are correct but
882
- * some things may get this wrong. The relevant specs
883
- * say that constructed string types should be OCTET STRINGs
884
- * internally irrespective of the type. So instead just check
885
- * for UNIVERSAL class and ignore the tag.
886
- */
887
- if (!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL, 0))
888
- {
889
- free_cont = 1;
890
- goto err;
891
- }
892
- len = buf.length;
893
- /* Append a final null to string */
894
- if (!BUF_MEM_grow_clean(&buf, len + 1))
895
- {
896
- OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
897
- return 0;
898
- }
899
- buf.data[len] = 0;
900
- cont = (const unsigned char *)buf.data;
901
- free_cont = 1;
902
- }
903
- else
904
- {
905
- cont = p;
906
- len = plen;
907
- p += plen;
908
- }
909
-
910
- /* We now have content length and type: translate into a structure */
911
- if (!asn1_ex_c2i(pval, cont, len, utype, &free_cont, it))
912
- goto err;
913
-
914
- *in = p;
915
- ret = 1;
916
- err:
917
- if (free_cont && buf.data) OPENSSL_free(buf.data);
918
- return ret;
919
- }
706
+ const unsigned char **in, long inlen,
707
+ const ASN1_ITEM *it,
708
+ int tag, int aclass, char opt, ASN1_TLC *ctx)
709
+ OPENSSL_SUPPRESS_POTENTIALLY_UNINITIALIZED_WARNINGS
710
+ {
711
+ int ret = 0, utype;
712
+ long plen;
713
+ char cst, inf, free_cont = 0;
714
+ const unsigned char *p;
715
+ BUF_MEM buf;
716
+ const unsigned char *cont = NULL;
717
+ long len;
718
+ if (!pval) {
719
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_NULL);
720
+ return 0; /* Should never happen */
721
+ }
722
+
723
+ if (it->itype == ASN1_ITYPE_MSTRING) {
724
+ utype = tag;
725
+ tag = -1;
726
+ } else
727
+ utype = it->utype;
728
+
729
+ if (utype == V_ASN1_ANY) {
730
+ /* If type is ANY need to figure out type from tag */
731
+ unsigned char oclass;
732
+ if (tag >= 0) {
733
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_TAGGED_ANY);
734
+ return 0;
735
+ }
736
+ if (opt) {
737
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_OPTIONAL_ANY);
738
+ return 0;
739
+ }
740
+ p = *in;
741
+ ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL,
742
+ &p, inlen, -1, 0, 0, ctx);
743
+ if (!ret) {
744
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
745
+ return 0;
746
+ }
747
+ if (oclass != V_ASN1_UNIVERSAL)
748
+ utype = V_ASN1_OTHER;
749
+ }
750
+ if (tag == -1) {
751
+ tag = utype;
752
+ aclass = V_ASN1_UNIVERSAL;
753
+ }
754
+ p = *in;
755
+ /* Check header */
756
+ ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst,
757
+ &p, inlen, tag, aclass, opt, ctx);
758
+ if (!ret) {
759
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
760
+ return 0;
761
+ } else if (ret == -1)
762
+ return -1;
763
+ ret = 0;
764
+ /* SEQUENCE, SET and "OTHER" are left in encoded form */
765
+ if ((utype == V_ASN1_SEQUENCE)
766
+ || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) {
767
+ /*
768
+ * Clear context cache for type OTHER because the auto clear when we
769
+ * have a exact match wont work
770
+ */
771
+ if (utype == V_ASN1_OTHER) {
772
+ asn1_tlc_clear(ctx);
773
+ }
774
+ /* SEQUENCE and SET must be constructed */
775
+ else if (!cst) {
776
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_CONSTRUCTED);
777
+ return 0;
778
+ }
779
+
780
+ cont = *in;
781
+ /* If indefinite length constructed find the real end */
782
+ if (inf) {
783
+ if (!asn1_find_end(&p, plen, inf))
784
+ goto err;
785
+ len = p - cont;
786
+ } else {
787
+ len = p - cont + plen;
788
+ p += plen;
789
+ buf.data = NULL;
790
+ }
791
+ } else if (cst) {
792
+ if (utype == V_ASN1_NULL || utype == V_ASN1_BOOLEAN
793
+ || utype == V_ASN1_OBJECT || utype == V_ASN1_INTEGER
794
+ || utype == V_ASN1_ENUMERATED) {
795
+ /* These types only have primitive encodings. */
796
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_PRIMITIVE);
797
+ return 0;
798
+ }
799
+
800
+ buf.length = 0;
801
+ buf.max = 0;
802
+ buf.data = NULL;
803
+ /*
804
+ * Should really check the internal tags are correct but some things
805
+ * may get this wrong. The relevant specs say that constructed string
806
+ * types should be OCTET STRINGs internally irrespective of the type.
807
+ * So instead just check for UNIVERSAL class and ignore the tag.
808
+ */
809
+ if (!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL, 0)) {
810
+ free_cont = 1;
811
+ goto err;
812
+ }
813
+ len = buf.length;
814
+ /* Append a final null to string */
815
+ if (!BUF_MEM_grow_clean(&buf, len + 1)) {
816
+ OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
817
+ return 0;
818
+ }
819
+ buf.data[len] = 0;
820
+ cont = (const unsigned char *)buf.data;
821
+ free_cont = 1;
822
+ } else {
823
+ cont = p;
824
+ len = plen;
825
+ p += plen;
826
+ }
827
+
828
+ /* We now have content length and type: translate into a structure */
829
+ if (!asn1_ex_c2i(pval, cont, len, utype, &free_cont, it))
830
+ goto err;
831
+
832
+ *in = p;
833
+ ret = 1;
834
+ err:
835
+ if (free_cont && buf.data)
836
+ OPENSSL_free(buf.data);
837
+ return ret;
838
+ }
920
839
 
921
840
  /* Translate ASN1 content octets into a structure */
922
841
 
923
842
  int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
924
- int utype, char *free_cont, const ASN1_ITEM *it)
925
- {
926
- ASN1_VALUE **opval = NULL;
927
- ASN1_STRING *stmp;
928
- ASN1_TYPE *typ = NULL;
929
- int ret = 0;
930
- const ASN1_PRIMITIVE_FUNCS *pf;
931
- ASN1_INTEGER **tint;
932
- pf = it->funcs;
933
-
934
- if (pf && pf->prim_c2i)
935
- return pf->prim_c2i(pval, cont, len, utype, free_cont, it);
936
- /* If ANY type clear type and set pointer to internal value */
937
- if (it->utype == V_ASN1_ANY)
938
- {
939
- if (!*pval)
940
- {
941
- typ = ASN1_TYPE_new();
942
- if (typ == NULL)
943
- goto err;
944
- *pval = (ASN1_VALUE *)typ;
945
- }
946
- else
947
- typ = (ASN1_TYPE *)*pval;
948
-
949
- if (utype != typ->type)
950
- ASN1_TYPE_set(typ, utype, NULL);
951
- opval = pval;
952
- pval = &typ->value.asn1_value;
953
- }
954
- switch(utype)
955
- {
956
- case V_ASN1_OBJECT:
957
- if (!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len))
958
- goto err;
959
- break;
960
-
961
- case V_ASN1_NULL:
962
- if (len)
963
- {
964
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NULL_IS_WRONG_LENGTH);
965
- goto err;
966
- }
967
- *pval = (ASN1_VALUE *)1;
968
- break;
969
-
970
- case V_ASN1_BOOLEAN:
971
- if (len != 1)
972
- {
973
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
974
- goto err;
975
- }
976
- else
977
- {
978
- ASN1_BOOLEAN *tbool;
979
- tbool = (ASN1_BOOLEAN *)pval;
980
- *tbool = *cont;
981
- }
982
- break;
983
-
984
- case V_ASN1_BIT_STRING:
985
- if (!c2i_ASN1_BIT_STRING((ASN1_BIT_STRING **)pval, &cont, len))
986
- goto err;
987
- break;
988
-
989
- case V_ASN1_INTEGER:
990
- case V_ASN1_NEG_INTEGER:
991
- case V_ASN1_ENUMERATED:
992
- case V_ASN1_NEG_ENUMERATED:
993
- tint = (ASN1_INTEGER **)pval;
994
- if (!c2i_ASN1_INTEGER(tint, &cont, len))
995
- goto err;
996
- /* Fixup type to match the expected form */
997
- (*tint)->type = utype | ((*tint)->type & V_ASN1_NEG);
998
- break;
999
-
1000
- case V_ASN1_OCTET_STRING:
1001
- case V_ASN1_NUMERICSTRING:
1002
- case V_ASN1_PRINTABLESTRING:
1003
- case V_ASN1_T61STRING:
1004
- case V_ASN1_VIDEOTEXSTRING:
1005
- case V_ASN1_IA5STRING:
1006
- case V_ASN1_UTCTIME:
1007
- case V_ASN1_GENERALIZEDTIME:
1008
- case V_ASN1_GRAPHICSTRING:
1009
- case V_ASN1_VISIBLESTRING:
1010
- case V_ASN1_GENERALSTRING:
1011
- case V_ASN1_UNIVERSALSTRING:
1012
- case V_ASN1_BMPSTRING:
1013
- case V_ASN1_UTF8STRING:
1014
- case V_ASN1_OTHER:
1015
- case V_ASN1_SET:
1016
- case V_ASN1_SEQUENCE:
1017
- default:
1018
- if (utype == V_ASN1_BMPSTRING && (len & 1))
1019
- {
1020
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_BMPSTRING_IS_WRONG_LENGTH);
1021
- goto err;
1022
- }
1023
- if (utype == V_ASN1_UNIVERSALSTRING && (len & 3))
1024
- {
1025
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH);
1026
- goto err;
1027
- }
1028
- /* All based on ASN1_STRING and handled the same */
1029
- if (!*pval)
1030
- {
1031
- stmp = ASN1_STRING_type_new(utype);
1032
- if (!stmp)
1033
- {
1034
- OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
1035
- goto err;
1036
- }
1037
- *pval = (ASN1_VALUE *)stmp;
1038
- }
1039
- else
1040
- {
1041
- stmp = (ASN1_STRING *)*pval;
1042
- stmp->type = utype;
1043
- }
1044
- /* If we've already allocated a buffer use it */
1045
- if (*free_cont)
1046
- {
1047
- if (stmp->data)
1048
- OPENSSL_free(stmp->data);
1049
- stmp->data = (unsigned char *)cont; /* UGLY CAST! RL */
1050
- stmp->length = len;
1051
- *free_cont = 0;
1052
- }
1053
- else
1054
- {
1055
- if (!ASN1_STRING_set(stmp, cont, len))
1056
- {
1057
- OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
1058
- ASN1_STRING_free(stmp);
1059
- *pval = NULL;
1060
- goto err;
1061
- }
1062
- }
1063
- break;
1064
- }
1065
- /* If ASN1_ANY and NULL type fix up value */
1066
- if (typ && (utype == V_ASN1_NULL))
1067
- typ->value.ptr = NULL;
1068
-
1069
- ret = 1;
1070
- err:
1071
- if (!ret)
1072
- {
1073
- ASN1_TYPE_free(typ);
1074
- if (opval)
1075
- *opval = NULL;
1076
- }
1077
- return ret;
1078
- }
1079
-
1080
-
1081
- /* This function finds the end of an ASN1 structure when passed its maximum
1082
- * length, whether it is indefinite length and a pointer to the content.
1083
- * This is more efficient than calling asn1_collect because it does not
1084
- * recurse on each indefinite length header.
843
+ int utype, char *free_cont, const ASN1_ITEM *it)
844
+ {
845
+ ASN1_VALUE **opval = NULL;
846
+ ASN1_STRING *stmp;
847
+ ASN1_TYPE *typ = NULL;
848
+ int ret = 0;
849
+ const ASN1_PRIMITIVE_FUNCS *pf;
850
+ ASN1_INTEGER **tint;
851
+ pf = it->funcs;
852
+
853
+ if (pf && pf->prim_c2i)
854
+ return pf->prim_c2i(pval, cont, len, utype, free_cont, it);
855
+ /* If ANY type clear type and set pointer to internal value */
856
+ if (it->utype == V_ASN1_ANY) {
857
+ if (!*pval) {
858
+ typ = ASN1_TYPE_new();
859
+ if (typ == NULL)
860
+ goto err;
861
+ *pval = (ASN1_VALUE *)typ;
862
+ } else
863
+ typ = (ASN1_TYPE *)*pval;
864
+
865
+ if (utype != typ->type)
866
+ ASN1_TYPE_set(typ, utype, NULL);
867
+ opval = pval;
868
+ pval = &typ->value.asn1_value;
869
+ }
870
+ switch (utype) {
871
+ case V_ASN1_OBJECT:
872
+ if (!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len))
873
+ goto err;
874
+ break;
875
+
876
+ case V_ASN1_NULL:
877
+ if (len) {
878
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NULL_IS_WRONG_LENGTH);
879
+ goto err;
880
+ }
881
+ *pval = (ASN1_VALUE *)1;
882
+ break;
883
+
884
+ case V_ASN1_BOOLEAN:
885
+ if (len != 1) {
886
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
887
+ goto err;
888
+ } else {
889
+ ASN1_BOOLEAN *tbool;
890
+ tbool = (ASN1_BOOLEAN *)pval;
891
+ *tbool = *cont;
892
+ }
893
+ break;
894
+
895
+ case V_ASN1_BIT_STRING:
896
+ if (!c2i_ASN1_BIT_STRING((ASN1_BIT_STRING **)pval, &cont, len))
897
+ goto err;
898
+ break;
899
+
900
+ case V_ASN1_INTEGER:
901
+ case V_ASN1_NEG_INTEGER:
902
+ case V_ASN1_ENUMERATED:
903
+ case V_ASN1_NEG_ENUMERATED:
904
+ tint = (ASN1_INTEGER **)pval;
905
+ if (!c2i_ASN1_INTEGER(tint, &cont, len))
906
+ goto err;
907
+ /* Fixup type to match the expected form */
908
+ (*tint)->type = utype | ((*tint)->type & V_ASN1_NEG);
909
+ break;
910
+
911
+ case V_ASN1_OCTET_STRING:
912
+ case V_ASN1_NUMERICSTRING:
913
+ case V_ASN1_PRINTABLESTRING:
914
+ case V_ASN1_T61STRING:
915
+ case V_ASN1_VIDEOTEXSTRING:
916
+ case V_ASN1_IA5STRING:
917
+ case V_ASN1_UTCTIME:
918
+ case V_ASN1_GENERALIZEDTIME:
919
+ case V_ASN1_GRAPHICSTRING:
920
+ case V_ASN1_VISIBLESTRING:
921
+ case V_ASN1_GENERALSTRING:
922
+ case V_ASN1_UNIVERSALSTRING:
923
+ case V_ASN1_BMPSTRING:
924
+ case V_ASN1_UTF8STRING:
925
+ case V_ASN1_OTHER:
926
+ case V_ASN1_SET:
927
+ case V_ASN1_SEQUENCE:
928
+ default:
929
+ if (utype == V_ASN1_BMPSTRING && (len & 1)) {
930
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_BMPSTRING_IS_WRONG_LENGTH);
931
+ goto err;
932
+ }
933
+ if (utype == V_ASN1_UNIVERSALSTRING && (len & 3)) {
934
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH);
935
+ goto err;
936
+ }
937
+ /* All based on ASN1_STRING and handled the same */
938
+ if (!*pval) {
939
+ stmp = ASN1_STRING_type_new(utype);
940
+ if (!stmp) {
941
+ OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
942
+ goto err;
943
+ }
944
+ *pval = (ASN1_VALUE *)stmp;
945
+ } else {
946
+ stmp = (ASN1_STRING *)*pval;
947
+ stmp->type = utype;
948
+ }
949
+ /* If we've already allocated a buffer use it */
950
+ if (*free_cont) {
951
+ if (stmp->data)
952
+ OPENSSL_free(stmp->data);
953
+ stmp->data = (unsigned char *)cont; /* UGLY CAST! RL */
954
+ stmp->length = len;
955
+ *free_cont = 0;
956
+ } else {
957
+ if (!ASN1_STRING_set(stmp, cont, len)) {
958
+ OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
959
+ ASN1_STRING_free(stmp);
960
+ *pval = NULL;
961
+ goto err;
962
+ }
963
+ }
964
+ break;
965
+ }
966
+ /* If ASN1_ANY and NULL type fix up value */
967
+ if (typ && (utype == V_ASN1_NULL))
968
+ typ->value.ptr = NULL;
969
+
970
+ ret = 1;
971
+ err:
972
+ if (!ret) {
973
+ ASN1_TYPE_free(typ);
974
+ if (opval)
975
+ *opval = NULL;
976
+ }
977
+ return ret;
978
+ }
979
+
980
+ /*
981
+ * This function finds the end of an ASN1 structure when passed its maximum
982
+ * length, whether it is indefinite length and a pointer to the content. This
983
+ * is more efficient than calling asn1_collect because it does not recurse on
984
+ * each indefinite length header.
1085
985
  */
1086
986
 
1087
987
  static int asn1_find_end(const unsigned char **in, long len, char inf)
1088
- {
1089
- int expected_eoc;
1090
- long plen;
1091
- const unsigned char *p = *in, *q;
1092
- /* If not indefinite length constructed just add length */
1093
- if (inf == 0)
1094
- {
1095
- *in += len;
1096
- return 1;
1097
- }
1098
- expected_eoc = 1;
1099
- /* Indefinite length constructed form. Find the end when enough EOCs
1100
- * are found. If more indefinite length constructed headers
1101
- * are encountered increment the expected eoc count otherwise just
1102
- * skip to the end of the data.
1103
- */
1104
- while (len > 0)
1105
- {
1106
- if(asn1_check_eoc(&p, len))
1107
- {
1108
- expected_eoc--;
1109
- if (expected_eoc == 0)
1110
- break;
1111
- len -= 2;
1112
- continue;
1113
- }
1114
- q = p;
1115
- /* Just read in a header: only care about the length */
1116
- if(!asn1_check_tlen(&plen, NULL, NULL, &inf, NULL, &p, len,
1117
- -1, 0, 0, NULL))
1118
- {
1119
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
1120
- return 0;
1121
- }
1122
- if (inf)
1123
- expected_eoc++;
1124
- else
1125
- p += plen;
1126
- len -= p - q;
1127
- }
1128
- if (expected_eoc)
1129
- {
1130
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_EOC);
1131
- return 0;
1132
- }
1133
- *in = p;
1134
- return 1;
1135
- }
1136
- /* This function collects the asn1 data from a constructred string
1137
- * type into a buffer. The values of 'in' and 'len' should refer
1138
- * to the contents of the constructed type and 'inf' should be set
1139
- * if it is indefinite length.
988
+ {
989
+ int expected_eoc;
990
+ long plen;
991
+ const unsigned char *p = *in, *q;
992
+ /* If not indefinite length constructed just add length */
993
+ if (inf == 0) {
994
+ *in += len;
995
+ return 1;
996
+ }
997
+ expected_eoc = 1;
998
+ /*
999
+ * Indefinite length constructed form. Find the end when enough EOCs are
1000
+ * found. If more indefinite length constructed headers are encountered
1001
+ * increment the expected eoc count otherwise just skip to the end of the
1002
+ * data.
1003
+ */
1004
+ while (len > 0) {
1005
+ if (asn1_check_eoc(&p, len)) {
1006
+ expected_eoc--;
1007
+ if (expected_eoc == 0)
1008
+ break;
1009
+ len -= 2;
1010
+ continue;
1011
+ }
1012
+ q = p;
1013
+ /* Just read in a header: only care about the length */
1014
+ if (!asn1_check_tlen(&plen, NULL, NULL, &inf, NULL, &p, len,
1015
+ -1, 0, 0, NULL)) {
1016
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
1017
+ return 0;
1018
+ }
1019
+ if (inf)
1020
+ expected_eoc++;
1021
+ else
1022
+ p += plen;
1023
+ len -= p - q;
1024
+ }
1025
+ if (expected_eoc) {
1026
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_EOC);
1027
+ return 0;
1028
+ }
1029
+ *in = p;
1030
+ return 1;
1031
+ }
1032
+
1033
+ /*
1034
+ * This function collects the asn1 data from a constructred string type into
1035
+ * a buffer. The values of 'in' and 'len' should refer to the contents of the
1036
+ * constructed type and 'inf' should be set if it is indefinite length.
1140
1037
  */
1141
1038
 
1142
1039
  #ifndef ASN1_MAX_STRING_NEST
1143
- /* This determines how many levels of recursion are permitted in ASN1
1144
- * string types. If it is not limited stack overflows can occur. If set
1145
- * to zero no recursion is allowed at all. Although zero should be adequate
1146
- * examples exist that require a value of 1. So 5 should be more than enough.
1040
+ /*
1041
+ * This determines how many levels of recursion are permitted in ASN1 string
1042
+ * types. If it is not limited stack overflows can occur. If set to zero no
1043
+ * recursion is allowed at all. Although zero should be adequate examples
1044
+ * exist that require a value of 1. So 5 should be more than enough.
1147
1045
  */
1148
- #define ASN1_MAX_STRING_NEST 5
1046
+ # define ASN1_MAX_STRING_NEST 5
1149
1047
  #endif
1150
1048
 
1151
-
1152
1049
  static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len,
1153
- char inf, int tag, int aclass, int depth)
1154
- {
1155
- const unsigned char *p, *q;
1156
- long plen;
1157
- char cst, ininf;
1158
- p = *in;
1159
- inf &= 1;
1160
- /* If no buffer and not indefinite length constructed just pass over
1161
- * the encoded data */
1162
- if (!buf && !inf)
1163
- {
1164
- *in += len;
1165
- return 1;
1166
- }
1167
- while(len > 0)
1168
- {
1169
- q = p;
1170
- /* Check for EOC */
1171
- if (asn1_check_eoc(&p, len))
1172
- {
1173
- /* EOC is illegal outside indefinite length
1174
- * constructed form */
1175
- if (!inf)
1176
- {
1177
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNEXPECTED_EOC);
1178
- return 0;
1179
- }
1180
- inf = 0;
1181
- break;
1182
- }
1183
-
1184
- if (!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p,
1185
- len, tag, aclass, 0, NULL))
1186
- {
1187
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
1188
- return 0;
1189
- }
1190
-
1191
- /* If indefinite length constructed update max length */
1192
- if (cst)
1193
- {
1194
- if (depth >= ASN1_MAX_STRING_NEST)
1195
- {
1196
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_STRING);
1197
- return 0;
1198
- }
1199
- if (!asn1_collect(buf, &p, plen, ininf, tag, aclass,
1200
- depth + 1))
1201
- return 0;
1202
- }
1203
- else if (plen && !collect_data(buf, &p, plen))
1204
- return 0;
1205
- len -= p - q;
1206
- }
1207
- if (inf)
1208
- {
1209
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_EOC);
1210
- return 0;
1211
- }
1212
- *in = p;
1213
- return 1;
1214
- }
1050
+ char inf, int tag, int aclass, int depth)
1051
+ {
1052
+ const unsigned char *p, *q;
1053
+ long plen;
1054
+ char cst, ininf;
1055
+ p = *in;
1056
+ inf &= 1;
1057
+ /*
1058
+ * If no buffer and not indefinite length constructed just pass over the
1059
+ * encoded data
1060
+ */
1061
+ if (!buf && !inf) {
1062
+ *in += len;
1063
+ return 1;
1064
+ }
1065
+ while (len > 0) {
1066
+ q = p;
1067
+ /* Check for EOC */
1068
+ if (asn1_check_eoc(&p, len)) {
1069
+ /*
1070
+ * EOC is illegal outside indefinite length constructed form
1071
+ */
1072
+ if (!inf) {
1073
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNEXPECTED_EOC);
1074
+ return 0;
1075
+ }
1076
+ inf = 0;
1077
+ break;
1078
+ }
1079
+
1080
+ if (!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p,
1081
+ len, tag, aclass, 0, NULL)) {
1082
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
1083
+ return 0;
1084
+ }
1085
+
1086
+ /* If indefinite length constructed update max length */
1087
+ if (cst) {
1088
+ if (depth >= ASN1_MAX_STRING_NEST) {
1089
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_STRING);
1090
+ return 0;
1091
+ }
1092
+ if (!asn1_collect(buf, &p, plen, ininf, tag, aclass, depth + 1))
1093
+ return 0;
1094
+ } else if (plen && !collect_data(buf, &p, plen))
1095
+ return 0;
1096
+ len -= p - q;
1097
+ }
1098
+ if (inf) {
1099
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_EOC);
1100
+ return 0;
1101
+ }
1102
+ *in = p;
1103
+ return 1;
1104
+ }
1215
1105
 
1216
1106
  static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen)
1217
- {
1218
- int len;
1219
- if (buf)
1220
- {
1221
- len = buf->length;
1222
- if (!BUF_MEM_grow_clean(buf, len + plen))
1223
- {
1224
- OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
1225
- return 0;
1226
- }
1227
- memcpy(buf->data + len, *p, plen);
1228
- }
1229
- *p += plen;
1230
- return 1;
1231
- }
1107
+ {
1108
+ int len;
1109
+ if (buf) {
1110
+ len = buf->length;
1111
+ if (!BUF_MEM_grow_clean(buf, len + plen)) {
1112
+ OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
1113
+ return 0;
1114
+ }
1115
+ memcpy(buf->data + len, *p, plen);
1116
+ }
1117
+ *p += plen;
1118
+ return 1;
1119
+ }
1232
1120
 
1233
1121
  /* Check for ASN1 EOC and swallow it if found */
1234
1122
 
1235
1123
  static int asn1_check_eoc(const unsigned char **in, long len)
1236
- {
1237
- const unsigned char *p;
1238
- if (len < 2) return 0;
1239
- p = *in;
1240
- if (!p[0] && !p[1])
1241
- {
1242
- *in += 2;
1243
- return 1;
1244
- }
1245
- return 0;
1246
- }
1247
-
1248
- /* Check an ASN1 tag and length: a bit like ASN1_get_object
1249
- * but it sets the length for indefinite length constructed
1250
- * form, we don't know the exact length but we can set an
1251
- * upper bound to the amount of data available minus the
1252
- * header length just read.
1124
+ {
1125
+ const unsigned char *p;
1126
+ if (len < 2)
1127
+ return 0;
1128
+ p = *in;
1129
+ if (!p[0] && !p[1]) {
1130
+ *in += 2;
1131
+ return 1;
1132
+ }
1133
+ return 0;
1134
+ }
1135
+
1136
+ /*
1137
+ * Check an ASN1 tag and length: a bit like ASN1_get_object but it sets the
1138
+ * length for indefinite length constructed form, we don't know the exact
1139
+ * length but we can set an upper bound to the amount of data available minus
1140
+ * the header length just read.
1253
1141
  */
1254
1142
 
1255
1143
  static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
1256
- char *inf, char *cst,
1257
- const unsigned char **in, long len,
1258
- int exptag, int expclass, char opt,
1259
- ASN1_TLC *ctx)
1260
- {
1261
- int i;
1262
- int ptag, pclass;
1263
- long plen;
1264
- const unsigned char *p, *q;
1265
- p = *in;
1266
- q = p;
1267
-
1268
- if (ctx && ctx->valid)
1269
- {
1270
- i = ctx->ret;
1271
- plen = ctx->plen;
1272
- pclass = ctx->pclass;
1273
- ptag = ctx->ptag;
1274
- p += ctx->hdrlen;
1275
- }
1276
- else
1277
- {
1278
- i = ASN1_get_object(&p, &plen, &ptag, &pclass, len);
1279
- if (ctx)
1280
- {
1281
- ctx->ret = i;
1282
- ctx->plen = plen;
1283
- ctx->pclass = pclass;
1284
- ctx->ptag = ptag;
1285
- ctx->hdrlen = p - q;
1286
- ctx->valid = 1;
1287
- /* If definite length, and no error, length +
1288
- * header can't exceed total amount of data available.
1289
- */
1290
- if (!(i & 0x81) && ((plen + ctx->hdrlen) > len))
1291
- {
1292
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_TOO_LONG);
1293
- asn1_tlc_clear(ctx);
1294
- return 0;
1295
- }
1296
- }
1297
- }
1298
-
1299
- if (i & 0x80)
1300
- {
1301
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_OBJECT_HEADER);
1302
- asn1_tlc_clear(ctx);
1303
- return 0;
1304
- }
1305
- if (exptag >= 0)
1306
- {
1307
- if ((exptag != ptag) || (expclass != pclass))
1308
- {
1309
- /* If type is OPTIONAL, not an error:
1310
- * indicate missing type.
1311
- */
1312
- if (opt) return -1;
1313
- asn1_tlc_clear(ctx);
1314
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_TAG);
1315
- return 0;
1316
- }
1317
- /* We have a tag and class match:
1318
- * assume we are going to do something with it */
1319
- asn1_tlc_clear(ctx);
1320
- }
1321
-
1322
- if (i & 1)
1323
- plen = len - (p - q);
1324
-
1325
- if (inf)
1326
- *inf = i & 1;
1327
-
1328
- if (cst)
1329
- *cst = i & V_ASN1_CONSTRUCTED;
1330
-
1331
- if (olen)
1332
- *olen = plen;
1333
-
1334
- if (oclass)
1335
- *oclass = pclass;
1336
-
1337
- if (otag)
1338
- *otag = ptag;
1339
-
1340
- *in = p;
1341
- return 1;
1342
- }
1144
+ char *inf, char *cst,
1145
+ const unsigned char **in, long len,
1146
+ int exptag, int expclass, char opt, ASN1_TLC *ctx)
1147
+ {
1148
+ int i;
1149
+ int ptag, pclass;
1150
+ long plen;
1151
+ const unsigned char *p, *q;
1152
+ p = *in;
1153
+ q = p;
1154
+
1155
+ if (ctx && ctx->valid) {
1156
+ i = ctx->ret;
1157
+ plen = ctx->plen;
1158
+ pclass = ctx->pclass;
1159
+ ptag = ctx->ptag;
1160
+ p += ctx->hdrlen;
1161
+ } else {
1162
+ i = ASN1_get_object(&p, &plen, &ptag, &pclass, len);
1163
+ if (ctx) {
1164
+ ctx->ret = i;
1165
+ ctx->plen = plen;
1166
+ ctx->pclass = pclass;
1167
+ ctx->ptag = ptag;
1168
+ ctx->hdrlen = p - q;
1169
+ ctx->valid = 1;
1170
+ /*
1171
+ * If definite length, and no error, length + header can't exceed
1172
+ * total amount of data available.
1173
+ */
1174
+ if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) {
1175
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_TOO_LONG);
1176
+ asn1_tlc_clear(ctx);
1177
+ return 0;
1178
+ }
1179
+ }
1180
+ }
1181
+
1182
+ if (i & 0x80) {
1183
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_OBJECT_HEADER);
1184
+ asn1_tlc_clear(ctx);
1185
+ return 0;
1186
+ }
1187
+ if (exptag >= 0) {
1188
+ if ((exptag != ptag) || (expclass != pclass)) {
1189
+ /*
1190
+ * If type is OPTIONAL, not an error: indicate missing type.
1191
+ */
1192
+ if (opt)
1193
+ return -1;
1194
+ asn1_tlc_clear(ctx);
1195
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_TAG);
1196
+ return 0;
1197
+ }
1198
+ /*
1199
+ * We have a tag and class match: assume we are going to do something
1200
+ * with it
1201
+ */
1202
+ asn1_tlc_clear(ctx);
1203
+ }
1204
+
1205
+ if (i & 1)
1206
+ plen = len - (p - q);
1207
+
1208
+ if (inf)
1209
+ *inf = i & 1;
1210
+
1211
+ if (cst)
1212
+ *cst = i & V_ASN1_CONSTRUCTED;
1213
+
1214
+ if (olen)
1215
+ *olen = plen;
1216
+
1217
+ if (oclass)
1218
+ *oclass = pclass;
1219
+
1220
+ if (otag)
1221
+ *otag = ptag;
1222
+
1223
+ *in = p;
1224
+ return 1;
1225
+ }