grpc 0.14.1 → 0.15.0

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 (277) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1398 -817
  3. data/include/grpc/compression.h +2 -1
  4. data/include/grpc/grpc.h +10 -1
  5. data/include/grpc/grpc_cronet.h +51 -0
  6. data/include/grpc/grpc_posix.h +70 -0
  7. data/include/grpc/impl/codegen/atm.h +2 -2
  8. data/include/grpc/impl/codegen/{atm_win32.h → atm_windows.h} +3 -3
  9. data/include/grpc/impl/codegen/compression_types.h +39 -5
  10. data/include/grpc/impl/codegen/connectivity_state.h +1 -1
  11. data/include/grpc/impl/codegen/grpc_types.h +10 -0
  12. data/include/grpc/impl/codegen/log.h +2 -1
  13. data/include/grpc/impl/codegen/port_platform.h +30 -12
  14. data/include/grpc/impl/codegen/slice_buffer.h +2 -3
  15. data/include/grpc/impl/codegen/sync.h +2 -2
  16. data/include/grpc/impl/codegen/{sync_win32.h → sync_windows.h} +3 -3
  17. data/include/grpc/support/{sync_win32.h → atm_windows.h} +4 -4
  18. data/include/grpc/support/avl.h +5 -0
  19. data/include/grpc/support/{log_win32.h → log_windows.h} +3 -3
  20. data/include/grpc/support/string_util.h +2 -1
  21. data/include/grpc/support/{atm_win32.h → sync_windows.h} +4 -4
  22. data/src/core/ext/census/gen/census.pb.c +179 -0
  23. data/src/core/ext/census/gen/census.pb.h +294 -0
  24. data/src/core/ext/census/grpc_filter.c +11 -7
  25. data/src/core/ext/client_config/channel_connectivity.c +28 -14
  26. data/src/core/ext/client_config/client_channel.c +77 -53
  27. data/src/core/ext/client_config/connector.h +1 -1
  28. data/src/core/ext/client_config/lb_policy.c +9 -6
  29. data/src/core/ext/client_config/lb_policy.h +9 -5
  30. data/src/core/ext/client_config/subchannel.c +58 -39
  31. data/src/core/ext/client_config/subchannel.h +3 -2
  32. data/src/core/ext/client_config/subchannel_call_holder.c +34 -19
  33. data/src/core/ext/client_config/subchannel_call_holder.h +2 -1
  34. data/src/core/ext/client_config/subchannel_index.c +20 -9
  35. data/src/core/ext/lb_policy/grpclb/load_balancer_api.c +7 -7
  36. data/src/core/ext/lb_policy/grpclb/load_balancer_api.h +5 -5
  37. data/src/core/ext/lb_policy/grpclb/proto/grpc/lb/{v0 → v1}/load_balancer.pb.c +29 -30
  38. data/src/core/ext/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +178 -0
  39. data/src/core/ext/lb_policy/pick_first/pick_first.c +65 -45
  40. data/src/core/ext/lb_policy/round_robin/round_robin.c +84 -43
  41. data/src/core/ext/load_reporting/load_reporting.c +133 -0
  42. data/src/core/ext/load_reporting/load_reporting.h +75 -0
  43. data/src/core/ext/load_reporting/load_reporting_filter.c +151 -0
  44. data/src/core/ext/load_reporting/load_reporting_filter.h +41 -0
  45. data/src/core/ext/resolver/dns/native/dns_resolver.c +22 -8
  46. data/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +2 -2
  47. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +4 -4
  48. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c +95 -0
  49. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +14 -18
  50. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +49 -24
  51. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c +82 -0
  52. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +104 -60
  53. data/src/core/ext/transport/chttp2/transport/bin_decoder.c +232 -0
  54. data/src/{ruby/ext/grpc/rb_signal.c → core/ext/transport/chttp2/transport/bin_decoder.h} +27 -31
  55. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +481 -260
  56. data/src/core/ext/transport/chttp2/transport/frame.h +1 -7
  57. data/src/core/ext/transport/chttp2/transport/frame_data.c +44 -27
  58. data/src/core/ext/transport/chttp2/transport/frame_data.h +6 -5
  59. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +23 -17
  60. data/src/core/ext/transport/chttp2/transport/frame_goaway.h +2 -2
  61. data/src/core/ext/transport/chttp2/transport/frame_ping.c +12 -7
  62. data/src/core/ext/transport/chttp2/transport/frame_ping.h +3 -3
  63. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +25 -12
  64. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +2 -2
  65. data/src/core/ext/transport/chttp2/transport/frame_settings.c +23 -21
  66. data/src/core/ext/transport/chttp2/transport/frame_settings.h +2 -2
  67. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +17 -9
  68. data/src/core/ext/transport/chttp2/transport/frame_window_update.h +2 -2
  69. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +365 -287
  70. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +8 -6
  71. data/src/core/ext/transport/chttp2/transport/hpack_table.c +24 -20
  72. data/src/core/ext/transport/chttp2/transport/hpack_table.h +5 -4
  73. data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +1 -0
  74. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +1 -0
  75. data/src/core/ext/transport/chttp2/transport/internal.h +34 -32
  76. data/src/core/ext/transport/chttp2/transport/parsing.c +296 -212
  77. data/src/core/ext/transport/chttp2/transport/writing.c +12 -9
  78. data/src/core/lib/channel/channel_args.c +26 -12
  79. data/src/core/lib/channel/channel_args.h +1 -1
  80. data/src/core/lib/channel/channel_stack.c +12 -8
  81. data/src/core/lib/channel/channel_stack.h +27 -11
  82. data/src/core/lib/channel/channel_stack_builder.c +2 -2
  83. data/src/core/lib/channel/compress_filter.c +26 -31
  84. data/src/core/lib/channel/compress_filter.h +4 -4
  85. data/src/core/lib/channel/connected_channel.c +7 -5
  86. data/src/core/lib/channel/http_client_filter.c +34 -8
  87. data/src/core/lib/channel/http_client_filter.h +1 -1
  88. data/src/core/lib/channel/http_server_filter.c +21 -12
  89. data/src/core/lib/compression/{compression_algorithm.c → compression.c} +22 -21
  90. data/src/core/lib/http/httpcli.c +81 -59
  91. data/src/core/lib/http/httpcli.h +11 -15
  92. data/src/core/lib/http/httpcli_security_connector.c +5 -3
  93. data/src/core/lib/http/parser.c +127 -118
  94. data/src/core/lib/http/parser.h +11 -6
  95. data/src/core/lib/iomgr/closure.c +20 -16
  96. data/src/core/lib/iomgr/closure.h +19 -15
  97. data/src/core/lib/iomgr/endpoint.h +1 -1
  98. data/src/core/lib/iomgr/endpoint_pair_posix.c +2 -2
  99. data/src/core/lib/iomgr/error.c +535 -0
  100. data/src/core/lib/iomgr/error.h +192 -0
  101. data/src/core/lib/iomgr/ev_poll_and_epoll_posix.c +190 -83
  102. data/src/core/lib/iomgr/ev_poll_posix.c +1267 -0
  103. data/src/{ruby/ext/grpc/rb_signal.h → core/lib/iomgr/ev_poll_posix.h} +7 -5
  104. data/src/core/lib/iomgr/ev_posix.c +104 -14
  105. data/src/core/lib/iomgr/ev_posix.h +17 -7
  106. data/src/core/lib/iomgr/exec_ctx.c +25 -7
  107. data/src/core/lib/iomgr/exec_ctx.h +27 -8
  108. data/src/core/lib/iomgr/executor.c +2 -2
  109. data/src/core/lib/iomgr/executor.h +1 -1
  110. data/src/core/lib/iomgr/iocp_windows.c +2 -41
  111. data/src/core/lib/iomgr/iocp_windows.h +0 -8
  112. data/src/core/lib/iomgr/iomgr.c +5 -4
  113. data/src/core/lib/iomgr/iomgr_posix.c +5 -1
  114. data/src/core/lib/iomgr/iomgr_windows.c +1 -1
  115. data/src/core/lib/{support → iomgr}/load_file.c +15 -17
  116. data/src/core/lib/{support → iomgr}/load_file.h +8 -7
  117. data/src/core/lib/iomgr/polling_entity.c +104 -0
  118. data/src/core/lib/iomgr/polling_entity.h +81 -0
  119. data/src/core/lib/iomgr/pollset.h +6 -5
  120. data/src/core/lib/iomgr/pollset_set_windows.c +4 -1
  121. data/src/core/lib/iomgr/pollset_windows.c +10 -6
  122. data/src/core/lib/iomgr/resolve_address.h +5 -9
  123. data/src/core/lib/iomgr/resolve_address_posix.c +55 -38
  124. data/src/core/lib/iomgr/resolve_address_windows.c +51 -37
  125. data/src/core/lib/iomgr/sockaddr.h +2 -2
  126. data/src/core/lib/iomgr/{sockaddr_win32.h → sockaddr_windows.h} +3 -3
  127. data/src/core/lib/iomgr/socket_utils_common_posix.c +92 -45
  128. data/src/core/lib/iomgr/socket_utils_posix.h +19 -12
  129. data/src/core/lib/iomgr/socket_windows.c +61 -2
  130. data/src/core/lib/iomgr/socket_windows.h +13 -0
  131. data/src/core/lib/iomgr/tcp_client_posix.c +54 -39
  132. data/src/core/lib/iomgr/tcp_client_windows.c +34 -34
  133. data/src/core/lib/iomgr/tcp_posix.c +43 -39
  134. data/src/core/lib/iomgr/tcp_server.h +5 -3
  135. data/src/core/lib/iomgr/tcp_server_posix.c +103 -64
  136. data/src/core/lib/iomgr/tcp_server_windows.c +114 -101
  137. data/src/core/lib/iomgr/tcp_windows.c +45 -50
  138. data/src/core/lib/iomgr/tcp_windows.h +1 -1
  139. data/src/core/lib/iomgr/timer.c +26 -13
  140. data/src/core/lib/iomgr/udp_server.c +28 -4
  141. data/src/core/lib/iomgr/udp_server.h +5 -1
  142. data/src/core/lib/iomgr/unix_sockets_posix.c +8 -7
  143. data/src/core/lib/iomgr/unix_sockets_posix.h +2 -1
  144. data/src/core/lib/iomgr/unix_sockets_posix_noop.c +4 -2
  145. data/src/core/lib/iomgr/wakeup_fd_eventfd.c +15 -5
  146. data/src/core/lib/iomgr/wakeup_fd_pipe.c +13 -9
  147. data/src/core/lib/iomgr/wakeup_fd_posix.c +6 -6
  148. data/src/core/lib/iomgr/wakeup_fd_posix.h +9 -6
  149. data/src/core/lib/iomgr/workqueue.h +5 -4
  150. data/src/core/lib/iomgr/workqueue_posix.c +40 -26
  151. data/src/core/lib/iomgr/workqueue_windows.c +2 -2
  152. data/src/core/lib/profiling/basic_timers.c +2 -2
  153. data/src/core/lib/security/{security_context.c → context/security_context.c} +1 -1
  154. data/src/core/lib/security/{security_context.h → context/security_context.h} +4 -4
  155. data/src/core/lib/security/credentials/composite/composite_credentials.c +263 -0
  156. data/src/core/lib/security/credentials/composite/composite_credentials.h +72 -0
  157. data/src/core/lib/security/credentials/credentials.c +233 -0
  158. data/src/core/lib/security/{credentials.h → credentials/credentials.h} +19 -157
  159. data/src/core/lib/security/{credentials_metadata.c → credentials/credentials_metadata.c} +1 -1
  160. data/src/core/lib/security/credentials/fake/fake_credentials.c +139 -0
  161. data/src/core/lib/security/credentials/fake/fake_credentials.h +56 -0
  162. data/src/core/lib/security/{credentials_posix.c → credentials/google_default/credentials_posix.c} +1 -1
  163. data/src/core/lib/security/{credentials_win32.c → credentials/google_default/credentials_windows.c} +3 -3
  164. data/src/core/lib/security/{google_default_credentials.c → credentials/google_default/google_default_credentials.c} +93 -35
  165. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +46 -0
  166. data/src/core/lib/security/credentials/iam/iam_credentials.c +85 -0
  167. data/src/core/lib/security/credentials/iam/iam_credentials.h +44 -0
  168. data/src/core/lib/security/{json_token.c → credentials/jwt/json_token.c} +10 -101
  169. data/src/core/lib/security/{json_token.h → credentials/jwt/json_token.h} +3 -33
  170. data/src/core/lib/security/credentials/jwt/jwt_credentials.c +160 -0
  171. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +62 -0
  172. data/src/core/lib/security/{jwt_verifier.c → credentials/jwt/jwt_verifier.c} +35 -15
  173. data/src/core/lib/security/{jwt_verifier.h → credentials/jwt/jwt_verifier.h} +3 -3
  174. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +433 -0
  175. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +109 -0
  176. data/src/core/lib/security/credentials/plugin/plugin_credentials.c +129 -0
  177. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +45 -0
  178. data/src/core/lib/security/credentials/ssl/ssl_credentials.c +240 -0
  179. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +48 -0
  180. data/src/core/lib/security/{auth_filters.h → transport/auth_filters.h} +3 -3
  181. data/src/core/lib/security/{client_auth_filter.c → transport/client_auth_filter.c} +27 -20
  182. data/src/core/lib/security/{handshake.c → transport/handshake.c} +77 -45
  183. data/src/core/lib/security/{handshake.h → transport/handshake.h} +9 -11
  184. data/src/core/lib/security/{secure_endpoint.c → transport/secure_endpoint.c} +19 -12
  185. data/src/core/lib/security/{secure_endpoint.h → transport/secure_endpoint.h} +3 -3
  186. data/src/core/lib/security/{security_connector.c → transport/security_connector.c} +26 -17
  187. data/src/core/lib/security/{security_connector.h → transport/security_connector.h} +8 -8
  188. data/src/core/lib/security/{server_auth_filter.c → transport/server_auth_filter.c} +24 -16
  189. data/src/core/lib/security/transport/tsi_error.c +40 -0
  190. data/src/core/lib/security/transport/tsi_error.h +42 -0
  191. data/src/core/lib/security/{b64.c → util/b64.c} +1 -1
  192. data/src/core/lib/security/{b64.h → util/b64.h} +3 -3
  193. data/src/core/lib/security/util/json_util.c +61 -0
  194. data/src/core/lib/security/util/json_util.h +55 -0
  195. data/src/core/lib/support/avl.c +11 -0
  196. data/src/core/lib/support/cpu_windows.c +2 -2
  197. data/src/core/lib/support/{env_win32.c → env_windows.c} +3 -3
  198. data/src/core/lib/support/log.c +3 -1
  199. data/src/core/lib/support/log_linux.c +2 -2
  200. data/src/core/lib/support/{log_win32.c → log_windows.c} +4 -4
  201. data/src/core/lib/support/murmur_hash.c +3 -5
  202. data/src/core/lib/support/string.c +10 -0
  203. data/src/core/lib/support/string.h +4 -0
  204. data/src/core/lib/support/{string_util_win32.c → string_util_windows.c} +3 -3
  205. data/src/core/lib/support/{string_win32.c → string_windows.c} +2 -2
  206. data/src/core/lib/support/{string_win32.h → string_windows.h} +5 -5
  207. data/src/core/lib/support/subprocess_windows.c +1 -1
  208. data/src/core/lib/support/{sync_win32.c → sync_windows.c} +2 -2
  209. data/src/core/lib/support/{thd_win32.c → thd_windows.c} +2 -2
  210. data/src/core/lib/support/{time_win32.c → time_windows.c} +2 -2
  211. data/src/core/lib/support/tmpfile_msys.c +1 -1
  212. data/src/core/lib/support/{tmpfile_win32.c → tmpfile_windows.c} +3 -3
  213. data/src/core/lib/surface/alarm.c +2 -2
  214. data/src/core/lib/surface/byte_buffer_reader.c +13 -6
  215. data/src/core/lib/surface/call.c +323 -123
  216. data/src/core/lib/surface/call.h +2 -0
  217. data/src/core/lib/surface/call_log_batch.c +1 -1
  218. data/src/core/lib/surface/channel.c +64 -15
  219. data/src/core/lib/surface/channel.h +9 -0
  220. data/src/core/lib/surface/channel_ping.c +3 -3
  221. data/src/core/lib/surface/completion_queue.c +75 -19
  222. data/src/core/lib/surface/completion_queue.h +7 -2
  223. data/src/core/lib/surface/init.c +2 -1
  224. data/src/core/lib/surface/init_secure.c +4 -4
  225. data/src/core/lib/surface/lame_client.c +12 -8
  226. data/src/core/lib/surface/server.c +213 -120
  227. data/src/core/lib/surface/server.h +1 -0
  228. data/src/core/lib/surface/version.c +1 -1
  229. data/src/core/lib/transport/connectivity_state.c +40 -18
  230. data/src/core/lib/transport/connectivity_state.h +4 -1
  231. data/src/core/lib/transport/metadata.c +23 -23
  232. data/src/core/lib/transport/metadata.h +4 -0
  233. data/src/core/lib/transport/metadata_batch.c +9 -0
  234. data/src/core/lib/transport/metadata_batch.h +3 -0
  235. data/src/core/lib/transport/static_metadata.c +6 -5
  236. data/src/core/lib/transport/static_metadata.h +64 -60
  237. data/src/core/lib/transport/transport.c +24 -12
  238. data/src/core/lib/transport/transport.h +6 -5
  239. data/src/core/lib/transport/transport_impl.h +4 -0
  240. data/src/core/lib/transport/transport_op_string.c +2 -2
  241. data/src/core/plugin_registry/grpc_plugin_registry.c +4 -0
  242. data/src/ruby/bin/math_services.rb +41 -2
  243. data/src/ruby/ext/grpc/rb_call.c +42 -40
  244. data/src/ruby/ext/grpc/rb_channel.c +1 -1
  245. data/src/ruby/ext/grpc/rb_completion_queue.c +59 -6
  246. data/src/ruby/ext/grpc/rb_completion_queue.h +1 -1
  247. data/src/ruby/ext/grpc/rb_grpc.c +1 -3
  248. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +12 -2
  249. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +21 -5
  250. data/src/ruby/ext/grpc/rb_loader.c +1 -1
  251. data/src/ruby/ext/grpc/rb_server.c +5 -3
  252. data/src/ruby/lib/grpc.rb +0 -3
  253. data/src/ruby/lib/grpc/errors.rb +3 -2
  254. data/src/ruby/lib/grpc/generic/active_call.rb +32 -42
  255. data/src/ruby/lib/grpc/generic/bidi_call.rb +20 -0
  256. data/src/ruby/lib/grpc/generic/client_stub.rb +31 -54
  257. data/src/ruby/lib/grpc/generic/rpc_desc.rb +4 -4
  258. data/src/ruby/lib/grpc/generic/rpc_server.rb +12 -23
  259. data/src/ruby/lib/grpc/generic/service.rb +8 -8
  260. data/src/ruby/lib/grpc/version.rb +1 -1
  261. data/src/ruby/pb/grpc/health/v1/health_services.rb +30 -2
  262. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services.rb +34 -4
  263. data/src/ruby/pb/grpc/testing/metrics_services.rb +39 -2
  264. data/src/ruby/pb/src/proto/grpc/testing/empty.rb +15 -0
  265. data/src/ruby/pb/src/proto/grpc/testing/messages.rb +84 -0
  266. data/src/ruby/pb/src/proto/grpc/testing/test.rb +14 -0
  267. data/src/ruby/pb/src/proto/grpc/testing/test_services.rb +110 -0
  268. data/src/ruby/pb/test/client.rb +5 -2
  269. data/src/ruby/spec/generic/active_call_spec.rb +3 -2
  270. data/src/ruby/spec/generic/client_stub_spec.rb +27 -24
  271. data/src/ruby/spec/generic/rpc_desc_spec.rb +11 -11
  272. data/src/ruby/spec/generic/rpc_server_spec.rb +42 -61
  273. data/src/ruby/spec/pb/health/checker_spec.rb +3 -5
  274. metadata +86 -48
  275. data/src/core/ext/lb_policy/grpclb/proto/grpc/lb/v0/load_balancer.pb.h +0 -182
  276. data/src/core/lib/security/credentials.c +0 -1296
  277. data/src/ruby/lib/grpc/signals.rb +0 -69
@@ -31,7 +31,7 @@
31
31
  *
32
32
  */
33
33
 
34
- #include "src/core/lib/security/credentials.h"
34
+ #include "src/core/lib/security/credentials/credentials.h"
35
35
 
36
36
  #include <grpc/support/alloc.h>
37
37
 
@@ -0,0 +1,139 @@
1
+ /*
2
+ *
3
+ * Copyright 2016, Google Inc.
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are
8
+ * met:
9
+ *
10
+ * * Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ * * Redistributions in binary form must reproduce the above
13
+ * copyright notice, this list of conditions and the following disclaimer
14
+ * in the documentation and/or other materials provided with the
15
+ * distribution.
16
+ * * Neither the name of Google Inc. nor the names of its
17
+ * contributors may be used to endorse or promote products derived from
18
+ * this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ *
32
+ */
33
+
34
+ #include "src/core/lib/security/credentials/fake/fake_credentials.h"
35
+
36
+ #include <string.h>
37
+
38
+ #include "src/core/lib/channel/channel_args.h"
39
+ #include "src/core/lib/iomgr/executor.h"
40
+
41
+ #include <grpc/support/alloc.h>
42
+ #include <grpc/support/log.h>
43
+ #include <grpc/support/string_util.h>
44
+
45
+ /* -- Fake transport security credentials. -- */
46
+
47
+ static grpc_security_status fake_transport_security_create_security_connector(
48
+ grpc_channel_credentials *c, grpc_call_credentials *call_creds,
49
+ const char *target, const grpc_channel_args *args,
50
+ grpc_channel_security_connector **sc, grpc_channel_args **new_args) {
51
+ *sc = grpc_fake_channel_security_connector_create(call_creds);
52
+ return GRPC_SECURITY_OK;
53
+ }
54
+
55
+ static grpc_security_status
56
+ fake_transport_security_server_create_security_connector(
57
+ grpc_server_credentials *c, grpc_server_security_connector **sc) {
58
+ *sc = grpc_fake_server_security_connector_create();
59
+ return GRPC_SECURITY_OK;
60
+ }
61
+
62
+ static grpc_channel_credentials_vtable
63
+ fake_transport_security_credentials_vtable = {
64
+ NULL, fake_transport_security_create_security_connector};
65
+
66
+ static grpc_server_credentials_vtable
67
+ fake_transport_security_server_credentials_vtable = {
68
+ NULL, fake_transport_security_server_create_security_connector};
69
+
70
+ grpc_channel_credentials *grpc_fake_transport_security_credentials_create(
71
+ void) {
72
+ grpc_channel_credentials *c = gpr_malloc(sizeof(grpc_channel_credentials));
73
+ memset(c, 0, sizeof(grpc_channel_credentials));
74
+ c->type = GRPC_CHANNEL_CREDENTIALS_TYPE_FAKE_TRANSPORT_SECURITY;
75
+ c->vtable = &fake_transport_security_credentials_vtable;
76
+ gpr_ref_init(&c->refcount, 1);
77
+ return c;
78
+ }
79
+
80
+ grpc_server_credentials *grpc_fake_transport_security_server_credentials_create(
81
+ void) {
82
+ grpc_server_credentials *c = gpr_malloc(sizeof(grpc_server_credentials));
83
+ memset(c, 0, sizeof(grpc_server_credentials));
84
+ c->type = GRPC_CHANNEL_CREDENTIALS_TYPE_FAKE_TRANSPORT_SECURITY;
85
+ gpr_ref_init(&c->refcount, 1);
86
+ c->vtable = &fake_transport_security_server_credentials_vtable;
87
+ return c;
88
+ }
89
+
90
+ /* -- Metadata-only test credentials. -- */
91
+
92
+ static void md_only_test_destruct(grpc_call_credentials *creds) {
93
+ grpc_md_only_test_credentials *c = (grpc_md_only_test_credentials *)creds;
94
+ grpc_credentials_md_store_unref(c->md_store);
95
+ }
96
+
97
+ static void on_simulated_token_fetch_done(grpc_exec_ctx *exec_ctx,
98
+ void *user_data, grpc_error *error) {
99
+ grpc_credentials_metadata_request *r =
100
+ (grpc_credentials_metadata_request *)user_data;
101
+ grpc_md_only_test_credentials *c = (grpc_md_only_test_credentials *)r->creds;
102
+ r->cb(exec_ctx, r->user_data, c->md_store->entries, c->md_store->num_entries,
103
+ GRPC_CREDENTIALS_OK);
104
+ grpc_credentials_metadata_request_destroy(r);
105
+ }
106
+
107
+ static void md_only_test_get_request_metadata(
108
+ grpc_exec_ctx *exec_ctx, grpc_call_credentials *creds,
109
+ grpc_polling_entity *pollent, grpc_auth_metadata_context context,
110
+ grpc_credentials_metadata_cb cb, void *user_data) {
111
+ grpc_md_only_test_credentials *c = (grpc_md_only_test_credentials *)creds;
112
+
113
+ if (c->is_async) {
114
+ grpc_credentials_metadata_request *cb_arg =
115
+ grpc_credentials_metadata_request_create(creds, cb, user_data);
116
+ grpc_executor_push(
117
+ grpc_closure_create(on_simulated_token_fetch_done, cb_arg),
118
+ GRPC_ERROR_NONE);
119
+ } else {
120
+ cb(exec_ctx, user_data, c->md_store->entries, 1, GRPC_CREDENTIALS_OK);
121
+ }
122
+ }
123
+
124
+ static grpc_call_credentials_vtable md_only_test_vtable = {
125
+ md_only_test_destruct, md_only_test_get_request_metadata};
126
+
127
+ grpc_call_credentials *grpc_md_only_test_credentials_create(
128
+ const char *md_key, const char *md_value, int is_async) {
129
+ grpc_md_only_test_credentials *c =
130
+ gpr_malloc(sizeof(grpc_md_only_test_credentials));
131
+ memset(c, 0, sizeof(grpc_md_only_test_credentials));
132
+ c->base.type = GRPC_CALL_CREDENTIALS_TYPE_OAUTH2;
133
+ c->base.vtable = &md_only_test_vtable;
134
+ gpr_ref_init(&c->base.refcount, 1);
135
+ c->md_store = grpc_credentials_md_store_create(1);
136
+ grpc_credentials_md_store_add_cstrings(c->md_store, md_key, md_value);
137
+ c->is_async = is_async;
138
+ return &c->base;
139
+ }
@@ -0,0 +1,56 @@
1
+ /*
2
+ *
3
+ * Copyright 2016, Google Inc.
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are
8
+ * met:
9
+ *
10
+ * * Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ * * Redistributions in binary form must reproduce the above
13
+ * copyright notice, this list of conditions and the following disclaimer
14
+ * in the documentation and/or other materials provided with the
15
+ * distribution.
16
+ * * Neither the name of Google Inc. nor the names of its
17
+ * contributors may be used to endorse or promote products derived from
18
+ * this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ *
32
+ */
33
+
34
+ #ifndef GRPC_CORE_LIB_SECURITY_CREDENTIALS_FAKE_FAKE_CREDENTIALS_H
35
+ #define GRPC_CORE_LIB_SECURITY_CREDENTIALS_FAKE_FAKE_CREDENTIALS_H
36
+
37
+ #include "src/core/lib/security/credentials/credentials.h"
38
+
39
+ /* -- Fake transport security credentials. -- */
40
+
41
+ /* Creates a fake transport security credentials object for testing. */
42
+ grpc_channel_credentials *grpc_fake_transport_security_credentials_create(void);
43
+
44
+ /* Creates a fake server transport security credentials object for testing. */
45
+ grpc_server_credentials *grpc_fake_transport_security_server_credentials_create(
46
+ void);
47
+
48
+ /* -- Metadata-only Test credentials. -- */
49
+
50
+ typedef struct {
51
+ grpc_call_credentials base;
52
+ grpc_credentials_md_store *md_store;
53
+ int is_async;
54
+ } grpc_md_only_test_credentials;
55
+
56
+ #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_FAKE_FAKE_CREDENTIALS_H */
@@ -35,7 +35,7 @@
35
35
 
36
36
  #ifdef GPR_POSIX_FILE
37
37
 
38
- #include "src/core/lib/security/credentials.h"
38
+ #include "src/core/lib/security/credentials/google_default/google_default_credentials.h"
39
39
 
40
40
  #include <grpc/support/alloc.h>
41
41
  #include <grpc/support/log.h>
@@ -33,9 +33,9 @@
33
33
 
34
34
  #include <grpc/support/port_platform.h>
35
35
 
36
- #ifdef GPR_WIN32
36
+ #ifdef GPR_WINDOWS
37
37
 
38
- #include "src/core/lib/security/credentials.h"
38
+ #include "src/core/lib/security/credentials/google_default/google_default_credentials.h"
39
39
 
40
40
  #include <grpc/support/alloc.h>
41
41
  #include <grpc/support/log.h>
@@ -58,4 +58,4 @@ char *grpc_get_well_known_google_credentials_file_path_impl(void) {
58
58
  return result;
59
59
  }
60
60
 
61
- #endif /* GPR_WIN32 */
61
+ #endif /* GPR_WINDOWS */
@@ -31,7 +31,7 @@
31
31
  *
32
32
  */
33
33
 
34
- #include "src/core/lib/security/credentials.h"
34
+ #include "src/core/lib/security/credentials/credentials.h"
35
35
 
36
36
  #include <string.h>
37
37
 
@@ -41,8 +41,12 @@
41
41
 
42
42
  #include "src/core/lib/http/httpcli.h"
43
43
  #include "src/core/lib/http/parser.h"
44
+ #include "src/core/lib/iomgr/load_file.h"
45
+ #include "src/core/lib/iomgr/polling_entity.h"
46
+ #include "src/core/lib/security/credentials/jwt/jwt_credentials.h"
47
+ #include "src/core/lib/security/credentials/oauth2/oauth2_credentials.h"
44
48
  #include "src/core/lib/support/env.h"
45
- #include "src/core/lib/support/load_file.h"
49
+ #include "src/core/lib/support/string.h"
46
50
  #include "src/core/lib/surface/api_trace.h"
47
51
 
48
52
  /* -- Constants. -- */
@@ -60,21 +64,23 @@ static gpr_once g_once = GPR_ONCE_INIT;
60
64
  static void init_default_credentials(void) { gpr_mu_init(&g_state_mu); }
61
65
 
62
66
  typedef struct {
63
- grpc_pollset *pollset;
67
+ grpc_polling_entity pollent;
64
68
  int is_done;
65
69
  int success;
70
+ grpc_http_response response;
66
71
  } compute_engine_detector;
67
72
 
68
- static void on_compute_engine_detection_http_response(
69
- grpc_exec_ctx *exec_ctx, void *user_data,
70
- const grpc_http_response *response) {
73
+ static void on_compute_engine_detection_http_response(grpc_exec_ctx *exec_ctx,
74
+ void *user_data,
75
+ grpc_error *error) {
71
76
  compute_engine_detector *detector = (compute_engine_detector *)user_data;
72
- if (response != NULL && response->status == 200 && response->hdr_count > 0) {
77
+ if (error == GRPC_ERROR_NONE && detector->response.status == 200 &&
78
+ detector->response.hdr_count > 0) {
73
79
  /* Internet providers can return a generic response to all requests, so
74
80
  it is necessary to check that metadata header is present also. */
75
81
  size_t i;
76
- for (i = 0; i < response->hdr_count; i++) {
77
- grpc_http_header *header = &response->hdrs[i];
82
+ for (i = 0; i < detector->response.hdr_count; i++) {
83
+ grpc_http_header *header = &detector->response.hdrs[i];
78
84
  if (strcmp(header->key, "Metadata-Flavor") == 0 &&
79
85
  strcmp(header->value, "Google") == 0) {
80
86
  detector->success = 1;
@@ -84,11 +90,13 @@ static void on_compute_engine_detection_http_response(
84
90
  }
85
91
  gpr_mu_lock(g_polling_mu);
86
92
  detector->is_done = 1;
87
- grpc_pollset_kick(detector->pollset, NULL);
93
+ GRPC_LOG_IF_ERROR(
94
+ "Pollset kick",
95
+ grpc_pollset_kick(grpc_polling_entity_pollset(&detector->pollent), NULL));
88
96
  gpr_mu_unlock(g_polling_mu);
89
97
  }
90
98
 
91
- static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, bool s) {
99
+ static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, grpc_error *e) {
92
100
  grpc_pollset_destroy(p);
93
101
  }
94
102
 
@@ -103,11 +111,13 @@ static int is_stack_running_on_compute_engine(void) {
103
111
  on compute engine. */
104
112
  gpr_timespec max_detection_delay = gpr_time_from_seconds(1, GPR_TIMESPAN);
105
113
 
106
- detector.pollset = gpr_malloc(grpc_pollset_size());
107
- grpc_pollset_init(detector.pollset, &g_polling_mu);
114
+ grpc_pollset *pollset = gpr_malloc(grpc_pollset_size());
115
+ grpc_pollset_init(pollset, &g_polling_mu);
116
+ detector.pollent = grpc_polling_entity_create_from_pollset(pollset);
108
117
  detector.is_done = 0;
109
118
  detector.success = 0;
110
119
 
120
+ memset(&detector.response, 0, sizeof(detector.response));
111
121
  memset(&request, 0, sizeof(grpc_httpcli_request));
112
122
  request.host = GRPC_COMPUTE_ENGINE_DETECTION_HOST;
113
123
  request.http.path = "/";
@@ -115,48 +125,71 @@ static int is_stack_running_on_compute_engine(void) {
115
125
  grpc_httpcli_context_init(&context);
116
126
 
117
127
  grpc_httpcli_get(
118
- &exec_ctx, &context, detector.pollset, &request,
128
+ &exec_ctx, &context, &detector.pollent, &request,
119
129
  gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), max_detection_delay),
120
- on_compute_engine_detection_http_response, &detector);
130
+ grpc_closure_create(on_compute_engine_detection_http_response, &detector),
131
+ &detector.response);
121
132
 
122
- grpc_exec_ctx_finish(&exec_ctx);
133
+ grpc_exec_ctx_flush(&exec_ctx);
123
134
 
124
135
  /* Block until we get the response. This is not ideal but this should only be
125
136
  called once for the lifetime of the process by the default credentials. */
126
137
  gpr_mu_lock(g_polling_mu);
127
138
  while (!detector.is_done) {
128
139
  grpc_pollset_worker *worker = NULL;
129
- grpc_pollset_work(&exec_ctx, detector.pollset, &worker,
130
- gpr_now(GPR_CLOCK_MONOTONIC),
131
- gpr_inf_future(GPR_CLOCK_MONOTONIC));
140
+ if (!GRPC_LOG_IF_ERROR(
141
+ "pollset_work",
142
+ grpc_pollset_work(&exec_ctx,
143
+ grpc_polling_entity_pollset(&detector.pollent),
144
+ &worker, gpr_now(GPR_CLOCK_MONOTONIC),
145
+ gpr_inf_future(GPR_CLOCK_MONOTONIC)))) {
146
+ detector.is_done = 1;
147
+ detector.success = 0;
148
+ }
132
149
  }
133
150
  gpr_mu_unlock(g_polling_mu);
134
151
 
135
152
  grpc_httpcli_context_destroy(&context);
136
- grpc_closure_init(&destroy_closure, destroy_pollset, detector.pollset);
137
- grpc_pollset_shutdown(&exec_ctx, detector.pollset, &destroy_closure);
153
+ grpc_closure_init(&destroy_closure, destroy_pollset,
154
+ grpc_polling_entity_pollset(&detector.pollent));
155
+ grpc_pollset_shutdown(&exec_ctx,
156
+ grpc_polling_entity_pollset(&detector.pollent),
157
+ &destroy_closure);
138
158
  grpc_exec_ctx_finish(&exec_ctx);
139
159
  g_polling_mu = NULL;
140
160
 
141
- gpr_free(detector.pollset);
161
+ gpr_free(grpc_polling_entity_pollset(&detector.pollent));
162
+ grpc_http_response_destroy(&detector.response);
142
163
 
143
164
  return detector.success;
144
165
  }
145
166
 
146
167
  /* Takes ownership of creds_path if not NULL. */
147
- static grpc_call_credentials *create_default_creds_from_path(char *creds_path) {
168
+ static grpc_error *create_default_creds_from_path(
169
+ char *creds_path, grpc_call_credentials **creds) {
148
170
  grpc_json *json = NULL;
149
171
  grpc_auth_json_key key;
150
172
  grpc_auth_refresh_token token;
151
173
  grpc_call_credentials *result = NULL;
152
174
  gpr_slice creds_data = gpr_empty_slice();
153
- int file_ok = 0;
154
- if (creds_path == NULL) goto end;
155
- creds_data = gpr_load_file(creds_path, 0, &file_ok);
156
- if (!file_ok) goto end;
175
+ grpc_error *error = GRPC_ERROR_NONE;
176
+ if (creds_path == NULL) {
177
+ error = GRPC_ERROR_CREATE("creds_path unset");
178
+ goto end;
179
+ }
180
+ error = grpc_load_file(creds_path, 0, &creds_data);
181
+ if (error != GRPC_ERROR_NONE) {
182
+ goto end;
183
+ }
157
184
  json = grpc_json_parse_string_with_len(
158
185
  (char *)GPR_SLICE_START_PTR(creds_data), GPR_SLICE_LENGTH(creds_data));
159
- if (json == NULL) goto end;
186
+ if (json == NULL) {
187
+ char *dump = gpr_dump_slice(creds_data, GPR_DUMP_HEX | GPR_DUMP_ASCII);
188
+ error = grpc_error_set_str(GRPC_ERROR_CREATE("Failed to parse JSON"),
189
+ GRPC_ERROR_STR_RAW_BYTES, dump);
190
+ gpr_free(dump);
191
+ goto end;
192
+ }
160
193
 
161
194
  /* First, try an auth json key. */
162
195
  key = grpc_auth_json_key_create_from_json(json);
@@ -164,6 +197,11 @@ static grpc_call_credentials *create_default_creds_from_path(char *creds_path) {
164
197
  result =
165
198
  grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
166
199
  key, grpc_max_auth_token_lifetime());
200
+ if (result == NULL) {
201
+ error = GRPC_ERROR_CREATE(
202
+ "grpc_service_account_jwt_access_credentials_create_from_auth_json_"
203
+ "key failed");
204
+ }
167
205
  goto end;
168
206
  }
169
207
 
@@ -172,19 +210,28 @@ static grpc_call_credentials *create_default_creds_from_path(char *creds_path) {
172
210
  if (grpc_auth_refresh_token_is_valid(&token)) {
173
211
  result =
174
212
  grpc_refresh_token_credentials_create_from_auth_refresh_token(token);
213
+ if (result == NULL) {
214
+ error = GRPC_ERROR_CREATE(
215
+ "grpc_refresh_token_credentials_create_from_auth_refresh_token "
216
+ "failed");
217
+ }
175
218
  goto end;
176
219
  }
177
220
 
178
221
  end:
222
+ GPR_ASSERT((result == NULL) + (error == GRPC_ERROR_NONE) == 1);
179
223
  if (creds_path != NULL) gpr_free(creds_path);
180
224
  gpr_slice_unref(creds_data);
181
225
  if (json != NULL) grpc_json_destroy(json);
182
- return result;
226
+ *creds = result;
227
+ return error;
183
228
  }
184
229
 
185
230
  grpc_channel_credentials *grpc_google_default_credentials_create(void) {
186
231
  grpc_channel_credentials *result = NULL;
187
232
  grpc_call_credentials *call_creds = NULL;
233
+ grpc_error *error = GRPC_ERROR_CREATE("Failed to create Google credentials");
234
+ grpc_error *err;
188
235
 
189
236
  GRPC_API_TRACE("grpc_google_default_credentials_create(void)", 0, ());
190
237
 
@@ -198,14 +245,16 @@ grpc_channel_credentials *grpc_google_default_credentials_create(void) {
198
245
  }
199
246
 
200
247
  /* First, try the environment variable. */
201
- call_creds = create_default_creds_from_path(
202
- gpr_getenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR));
203
- if (call_creds != NULL) goto end;
248
+ err = create_default_creds_from_path(
249
+ gpr_getenv(GRPC_GOOGLE_CREDENTIALS_ENV_VAR), &call_creds);
250
+ if (err == GRPC_ERROR_NONE) goto end;
251
+ error = grpc_error_add_child(error, err);
204
252
 
205
253
  /* Then the well-known file. */
206
- call_creds = create_default_creds_from_path(
207
- grpc_get_well_known_google_credentials_file_path());
208
- if (call_creds != NULL) goto end;
254
+ err = create_default_creds_from_path(
255
+ grpc_get_well_known_google_credentials_file_path(), &call_creds);
256
+ if (err == GRPC_ERROR_NONE) goto end;
257
+ error = grpc_error_add_child(error, err);
209
258
 
210
259
  /* At last try to see if we're on compute engine (do the detection only once
211
260
  since it requires a network test). */
@@ -214,6 +263,10 @@ grpc_channel_credentials *grpc_google_default_credentials_create(void) {
214
263
  compute_engine_detection_done = 1;
215
264
  if (need_compute_engine_creds) {
216
265
  call_creds = grpc_google_compute_engine_credentials_create(NULL);
266
+ if (call_creds == NULL) {
267
+ error = grpc_error_add_child(
268
+ error, GRPC_ERROR_CREATE("Failed to get credentials from network"));
269
+ }
217
270
  }
218
271
  }
219
272
 
@@ -237,6 +290,11 @@ end:
237
290
  }
238
291
  }
239
292
  gpr_mu_unlock(&g_state_mu);
293
+ if (result == NULL) {
294
+ GRPC_LOG_IF_ERROR("grpc_google_default_credentials_create", error);
295
+ } else {
296
+ GRPC_ERROR_UNREF(error);
297
+ }
240
298
  return result;
241
299
  }
242
300