Skip to content

Commit

Permalink
Merge pull request grpc#11607 from yihuazhang/tsi_init
Browse files Browse the repository at this point in the history
Add GTS plugin
  • Loading branch information
markdroth authored Jul 18, 2017
2 parents c39d4c1 + 1435bfc commit ea8f591
Show file tree
Hide file tree
Showing 19 changed files with 123 additions and 0 deletions.
3 changes: 3 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1404,12 +1404,14 @@ grpc_cc_library(
name = "tsi",
srcs = [
"src/core/tsi/fake_transport_security.c",
"src/core/tsi/gts_transport_security.c",
"src/core/tsi/ssl_transport_security.c",
"src/core/tsi/transport_security.c",
"src/core/tsi/transport_security_adapter.c",
],
hdrs = [
"src/core/tsi/fake_transport_security.h",
"src/core/tsi/gts_transport_security.h",
"src/core/tsi/ssl_transport_security.h",
"src/core/tsi/ssl_types.h",
"src/core/tsi/transport_security.h",
Expand All @@ -1422,6 +1424,7 @@ grpc_cc_library(
language = "c",
deps = [
"gpr",
"grpc_base",
"grpc_trace",
],
)
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,7 @@ add_library(grpc
src/core/lib/security/util/json_util.c
src/core/lib/surface/init_secure.c
src/core/tsi/fake_transport_security.c
src/core/tsi/gts_transport_security.c
src/core/tsi/ssl_transport_security.c
src/core/tsi/transport_security.c
src/core/tsi/transport_security_adapter.c
Expand Down Expand Up @@ -1490,6 +1491,7 @@ add_library(grpc_cronet
src/core/lib/security/util/json_util.c
src/core/lib/surface/init_secure.c
src/core/tsi/fake_transport_security.c
src/core/tsi/gts_transport_security.c
src/core/tsi/ssl_transport_security.c
src/core/tsi/transport_security.c
src/core/tsi/transport_security_adapter.c
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3064,6 +3064,7 @@ LIBGRPC_SRC = \
src/core/lib/security/util/json_util.c \
src/core/lib/surface/init_secure.c \
src/core/tsi/fake_transport_security.c \
src/core/tsi/gts_transport_security.c \
src/core/tsi/ssl_transport_security.c \
src/core/tsi/transport_security.c \
src/core/tsi/transport_security_adapter.c \
Expand Down Expand Up @@ -3428,6 +3429,7 @@ LIBGRPC_CRONET_SRC = \
src/core/lib/security/util/json_util.c \
src/core/lib/surface/init_secure.c \
src/core/tsi/fake_transport_security.c \
src/core/tsi/gts_transport_security.c \
src/core/tsi/ssl_transport_security.c \
src/core/tsi/transport_security.c \
src/core/tsi/transport_security_adapter.c \
Expand Down Expand Up @@ -19174,6 +19176,7 @@ src/core/lib/surface/init_secure.c: $(OPENSSL_DEP)
src/core/plugin_registry/grpc_cronet_plugin_registry.c: $(OPENSSL_DEP)
src/core/plugin_registry/grpc_plugin_registry.c: $(OPENSSL_DEP)
src/core/tsi/fake_transport_security.c: $(OPENSSL_DEP)
src/core/tsi/gts_transport_security.c: $(OPENSSL_DEP)
src/core/tsi/ssl_transport_security.c: $(OPENSSL_DEP)
src/core/tsi/transport_security.c: $(OPENSSL_DEP)
src/core/tsi/transport_security_adapter.c: $(OPENSSL_DEP)
Expand Down
1 change: 1 addition & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@
'src/core/lib/security/util/json_util.c',
'src/core/lib/surface/init_secure.c',
'src/core/tsi/fake_transport_security.c',
'src/core/tsi/gts_transport_security.c',
'src/core/tsi/ssl_transport_security.c',
'src/core/tsi/transport_security.c',
'src/core/tsi/transport_security_adapter.c',
Expand Down
4 changes: 4 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -876,21 +876,25 @@ filegroups:
- name: tsi
headers:
- src/core/tsi/fake_transport_security.h
- src/core/tsi/gts_transport_security.h
- src/core/tsi/ssl_transport_security.h
- src/core/tsi/ssl_types.h
- src/core/tsi/transport_security.h
- src/core/tsi/transport_security_adapter.h
- src/core/tsi/transport_security_interface.h
src:
- src/core/tsi/fake_transport_security.c
- src/core/tsi/gts_transport_security.c
- src/core/tsi/ssl_transport_security.c
- src/core/tsi/transport_security.c
- src/core/tsi/transport_security_adapter.c
deps:
- gpr
plugin: grpc_tsi_gts
secure: true
uses:
- grpc_trace
- grpc_base
- name: grpc++_base
language: c++
public_headers:
Expand Down
1 change: 1 addition & 0 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ if test "$PHP_GRPC" != "no"; then
src/core/lib/security/util/json_util.c \
src/core/lib/surface/init_secure.c \
src/core/tsi/fake_transport_security.c \
src/core/tsi/gts_transport_security.c \
src/core/tsi/ssl_transport_security.c \
src/core/tsi/transport_security.c \
src/core/tsi/transport_security_adapter.c \
Expand Down
1 change: 1 addition & 0 deletions config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ if (PHP_GRPC != "no") {
"src\\core\\lib\\security\\util\\json_util.c " +
"src\\core\\lib\\surface\\init_secure.c " +
"src\\core\\tsi\\fake_transport_security.c " +
"src\\core\\tsi\\gts_transport_security.c " +
"src\\core\\tsi\\ssl_transport_security.c " +
"src\\core\\tsi\\transport_security.c " +
"src\\core\\tsi\\transport_security_adapter.c " +
Expand Down
3 changes: 3 additions & 0 deletions gRPC-Core.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ Pod::Spec.new do |s|
'src/core/lib/security/transport/tsi_error.h',
'src/core/lib/security/util/json_util.h',
'src/core/tsi/fake_transport_security.h',
'src/core/tsi/gts_transport_security.h',
'src/core/tsi/ssl_transport_security.h',
'src/core/tsi/ssl_types.h',
'src/core/tsi/transport_security.h',
Expand Down Expand Up @@ -637,6 +638,7 @@ Pod::Spec.new do |s|
'src/core/lib/security/util/json_util.c',
'src/core/lib/surface/init_secure.c',
'src/core/tsi/fake_transport_security.c',
'src/core/tsi/gts_transport_security.c',
'src/core/tsi/ssl_transport_security.c',
'src/core/tsi/transport_security.c',
'src/core/tsi/transport_security_adapter.c',
Expand Down Expand Up @@ -880,6 +882,7 @@ Pod::Spec.new do |s|
'src/core/lib/security/transport/tsi_error.h',
'src/core/lib/security/util/json_util.h',
'src/core/tsi/fake_transport_security.h',
'src/core/tsi/gts_transport_security.h',
'src/core/tsi/ssl_transport_security.h',
'src/core/tsi/ssl_types.h',
'src/core/tsi/transport_security.h',
Expand Down
2 changes: 2 additions & 0 deletions grpc.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/security/transport/tsi_error.h )
s.files += %w( src/core/lib/security/util/json_util.h )
s.files += %w( src/core/tsi/fake_transport_security.h )
s.files += %w( src/core/tsi/gts_transport_security.h )
s.files += %w( src/core/tsi/ssl_transport_security.h )
s.files += %w( src/core/tsi/ssl_types.h )
s.files += %w( src/core/tsi/transport_security.h )
Expand Down Expand Up @@ -573,6 +574,7 @@ Gem::Specification.new do |s|
s.files += %w( src/core/lib/security/util/json_util.c )
s.files += %w( src/core/lib/surface/init_secure.c )
s.files += %w( src/core/tsi/fake_transport_security.c )
s.files += %w( src/core/tsi/gts_transport_security.c )
s.files += %w( src/core/tsi/ssl_transport_security.c )
s.files += %w( src/core/tsi/transport_security.c )
s.files += %w( src/core/tsi/transport_security_adapter.c )
Expand Down
2 changes: 2 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@
<file baseinstalldir="/" name="src/core/lib/security/transport/tsi_error.h" role="src" />
<file baseinstalldir="/" name="src/core/lib/security/util/json_util.h" role="src" />
<file baseinstalldir="/" name="src/core/tsi/fake_transport_security.h" role="src" />
<file baseinstalldir="/" name="src/core/tsi/gts_transport_security.h" role="src" />
<file baseinstalldir="/" name="src/core/tsi/ssl_transport_security.h" role="src" />
<file baseinstalldir="/" name="src/core/tsi/ssl_types.h" role="src" />
<file baseinstalldir="/" name="src/core/tsi/transport_security.h" role="src" />
Expand Down Expand Up @@ -587,6 +588,7 @@
<file baseinstalldir="/" name="src/core/lib/security/util/json_util.c" role="src" />
<file baseinstalldir="/" name="src/core/lib/surface/init_secure.c" role="src" />
<file baseinstalldir="/" name="src/core/tsi/fake_transport_security.c" role="src" />
<file baseinstalldir="/" name="src/core/tsi/gts_transport_security.c" role="src" />
<file baseinstalldir="/" name="src/core/tsi/ssl_transport_security.c" role="src" />
<file baseinstalldir="/" name="src/core/tsi/transport_security.c" role="src" />
<file baseinstalldir="/" name="src/core/tsi/transport_security_adapter.c" role="src" />
Expand Down
4 changes: 4 additions & 0 deletions src/core/plugin_registry/grpc_cronet_plugin_registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ extern void grpc_deadline_filter_init(void);
extern void grpc_deadline_filter_shutdown(void);
extern void grpc_client_channel_init(void);
extern void grpc_client_channel_shutdown(void);
extern void grpc_tsi_gts_init(void);
extern void grpc_tsi_gts_shutdown(void);
extern void grpc_load_reporting_plugin_init(void);
extern void grpc_load_reporting_plugin_shutdown(void);

Expand All @@ -38,6 +40,8 @@ void grpc_register_built_in_plugins(void) {
grpc_deadline_filter_shutdown);
grpc_register_plugin(grpc_client_channel_init,
grpc_client_channel_shutdown);
grpc_register_plugin(grpc_tsi_gts_init,
grpc_tsi_gts_shutdown);
grpc_register_plugin(grpc_load_reporting_plugin_init,
grpc_load_reporting_plugin_shutdown);
}
4 changes: 4 additions & 0 deletions src/core/plugin_registry/grpc_plugin_registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ extern void grpc_http_filters_init(void);
extern void grpc_http_filters_shutdown(void);
extern void grpc_chttp2_plugin_init(void);
extern void grpc_chttp2_plugin_shutdown(void);
extern void grpc_tsi_gts_init(void);
extern void grpc_tsi_gts_shutdown(void);
extern void grpc_deadline_filter_init(void);
extern void grpc_deadline_filter_shutdown(void);
extern void grpc_client_channel_init(void);
Expand Down Expand Up @@ -58,6 +60,8 @@ void grpc_register_built_in_plugins(void) {
grpc_http_filters_shutdown);
grpc_register_plugin(grpc_chttp2_plugin_init,
grpc_chttp2_plugin_shutdown);
grpc_register_plugin(grpc_tsi_gts_init,
grpc_tsi_gts_shutdown);
grpc_register_plugin(grpc_deadline_filter_init,
grpc_deadline_filter_shutdown);
grpc_register_plugin(grpc_client_channel_init,
Expand Down
40 changes: 40 additions & 0 deletions src/core/tsi/gts_transport_security.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
*
* Copyright 2017 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include "src/core/tsi/gts_transport_security.h"

#include <string.h>

static gts_shared_resource g_gts_resource;

gts_shared_resource *gts_get_shared_resource(void) { return &g_gts_resource; }

void grpc_tsi_gts_init() {
memset(&g_gts_resource, 0, sizeof(gts_shared_resource));
gpr_mu_init(&g_gts_resource.mu);
}

void grpc_tsi_gts_shutdown() {
gpr_mu_destroy(&g_gts_resource.mu);
if (g_gts_resource.cq == NULL) {
return;
}
grpc_completion_queue_destroy(g_gts_resource.cq);
grpc_channel_destroy(g_gts_resource.channel);
gpr_thd_join(g_gts_resource.thread_id);
}
37 changes: 37 additions & 0 deletions src/core/tsi/gts_transport_security.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
*
* Copyright 2017 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#ifndef GRPC_CORE_TSI_GTS_TRANSPORT_SECURITY_H
#define GRPC_CORE_TSI_GTS_TRANSPORT_SECURITY_H

#include <grpc/grpc.h>
#include <grpc/support/sync.h>
#include <grpc/support/thd.h>

typedef struct gts_shared_resource {
gpr_thd_id thread_id;
grpc_channel *channel;
grpc_completion_queue *cq;
gpr_mu mu;
} gts_shared_resource;

/* This method returns the address of gts_shared_resource object shared by all
* TSI handshakes. */
gts_shared_resource *gts_get_shared_resource(void);

#endif /* GRPC_CORE_TSI_GTS_TRANSPORT_SECURITY_H */
1 change: 1 addition & 0 deletions src/python/grpcio/grpc_core_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
'src/core/lib/security/util/json_util.c',
'src/core/lib/surface/init_secure.c',
'src/core/tsi/fake_transport_security.c',
'src/core/tsi/gts_transport_security.c',
'src/core/tsi/ssl_transport_security.c',
'src/core/tsi/transport_security.c',
'src/core/tsi/transport_security_adapter.c',
Expand Down
2 changes: 2 additions & 0 deletions tools/doxygen/Doxyfile.core.internal
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,8 @@ src/core/plugin_registry/grpc_plugin_registry.c \
src/core/tsi/README.md \
src/core/tsi/fake_transport_security.c \
src/core/tsi/fake_transport_security.h \
src/core/tsi/gts_transport_security.c \
src/core/tsi/gts_transport_security.h \
src/core/tsi/ssl_transport_security.c \
src/core/tsi/ssl_transport_security.h \
src/core/tsi/ssl_types.h \
Expand Down
4 changes: 4 additions & 0 deletions tools/run_tests/generated/sources_and_headers.json
Original file line number Diff line number Diff line change
Expand Up @@ -8892,10 +8892,12 @@
{
"deps": [
"gpr",
"grpc_base",
"grpc_trace"
],
"headers": [
"src/core/tsi/fake_transport_security.h",
"src/core/tsi/gts_transport_security.h",
"src/core/tsi/ssl_transport_security.h",
"src/core/tsi/ssl_types.h",
"src/core/tsi/transport_security.h",
Expand All @@ -8908,6 +8910,8 @@
"src": [
"src/core/tsi/fake_transport_security.c",
"src/core/tsi/fake_transport_security.h",
"src/core/tsi/gts_transport_security.c",
"src/core/tsi/gts_transport_security.h",
"src/core/tsi/ssl_transport_security.c",
"src/core/tsi/ssl_transport_security.h",
"src/core/tsi/ssl_types.h",
Expand Down
3 changes: 3 additions & 0 deletions vsprojects/vcxproj/grpc/grpc.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@
<ClInclude Include="$(SolutionDir)\..\src\core\lib\security\transport\tsi_error.h" />
<ClInclude Include="$(SolutionDir)\..\src\core\lib\security\util\json_util.h" />
<ClInclude Include="$(SolutionDir)\..\src\core\tsi\fake_transport_security.h" />
<ClInclude Include="$(SolutionDir)\..\src\core\tsi\gts_transport_security.h" />
<ClInclude Include="$(SolutionDir)\..\src\core\tsi\ssl_transport_security.h" />
<ClInclude Include="$(SolutionDir)\..\src\core\tsi\ssl_types.h" />
<ClInclude Include="$(SolutionDir)\..\src\core\tsi\transport_security.h" />
Expand Down Expand Up @@ -879,6 +880,8 @@
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\tsi\fake_transport_security.c">
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\tsi\gts_transport_security.c">
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\tsi\ssl_transport_security.c">
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\tsi\transport_security.c">
Expand Down
6 changes: 6 additions & 0 deletions vsprojects/vcxproj/grpc/grpc.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,9 @@
<ClCompile Include="$(SolutionDir)\..\src\core\tsi\fake_transport_security.c">
<Filter>src\core\tsi</Filter>
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\tsi\gts_transport_security.c">
<Filter>src\core\tsi</Filter>
</ClCompile>
<ClCompile Include="$(SolutionDir)\..\src\core\tsi\ssl_transport_security.c">
<Filter>src\core\tsi</Filter>
</ClCompile>
Expand Down Expand Up @@ -1319,6 +1322,9 @@
<ClInclude Include="$(SolutionDir)\..\src\core\tsi\fake_transport_security.h">
<Filter>src\core\tsi</Filter>
</ClInclude>
<ClInclude Include="$(SolutionDir)\..\src\core\tsi\gts_transport_security.h">
<Filter>src\core\tsi</Filter>
</ClInclude>
<ClInclude Include="$(SolutionDir)\..\src\core\tsi\ssl_transport_security.h">
<Filter>src\core\tsi</Filter>
</ClInclude>
Expand Down

0 comments on commit ea8f591

Please sign in to comment.