Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
6f607665
Commit
6f607665
authored
8 years ago
by
murgatroid99
Browse files
Options
Downloads
Patches
Plain Diff
Load default roots.pem in Node via grpc_set_ssl_roots_override_callback
parent
cca098e7
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/node/ext/node_grpc.cc
+35
-0
35 additions, 0 deletions
src/node/ext/node_grpc.cc
src/node/index.js
+3
-4
3 additions, 4 deletions
src/node/index.js
with
38 additions
and
4 deletions
src/node/ext/node_grpc.cc
+
35
−
0
View file @
6f607665
...
@@ -35,6 +35,8 @@
...
@@ -35,6 +35,8 @@
#include
<nan.h>
#include
<nan.h>
#include
<v8.h>
#include
<v8.h>
#include
"grpc/grpc.h"
#include
"grpc/grpc.h"
#include
"grpc/grpc_security.h"
#include
"grpc/support/alloc.h"
#include
"call.h"
#include
"call.h"
#include
"call_credentials.h"
#include
"call_credentials.h"
...
@@ -51,6 +53,8 @@ using v8::Object;
...
@@ -51,6 +53,8 @@ using v8::Object;
using
v8
::
Uint32
;
using
v8
::
Uint32
;
using
v8
::
String
;
using
v8
::
String
;
static
char
*
pem_root_certs
=
NULL
;
void
InitStatusConstants
(
Local
<
Object
>
exports
)
{
void
InitStatusConstants
(
Local
<
Object
>
exports
)
{
Nan
::
HandleScope
scope
;
Nan
::
HandleScope
scope
;
Local
<
Object
>
status
=
Nan
::
New
<
Object
>
();
Local
<
Object
>
status
=
Nan
::
New
<
Object
>
();
...
@@ -268,9 +272,36 @@ NAN_METHOD(MetadataKeyIsBinary) {
...
@@ -268,9 +272,36 @@ NAN_METHOD(MetadataKeyIsBinary) {
grpc_is_binary_header
(
key_str
,
static_cast
<
size_t
>
(
key
->
Length
()))));
grpc_is_binary_header
(
key_str
,
static_cast
<
size_t
>
(
key
->
Length
()))));
}
}
static
grpc_ssl_roots_override_result
get_ssl_roots_override
(
char
**
pem_root_certs_ptr
)
{
*
pem_root_certs_ptr
=
pem_root_certs
;
if
(
pem_root_certs
==
NULL
)
{
return
GRPC_SSL_ROOTS_OVERRIDE_FAIL
;
}
else
{
return
GRPC_SSL_ROOTS_OVERRIDE_OK
;
}
}
/* This should only be called once, and only before creating any
*ServerCredentials */
NAN_METHOD
(
SetDefaultRootsPem
)
{
if
(
!
info
[
0
]
->
IsString
())
{
return
Nan
::
ThrowTypeError
(
"setDefaultRootsPem's argument must be a string"
);
}
Nan
::
Utf8String
utf8_roots
(
info
[
0
]);
size_t
length
=
static_cast
<
size_t
>
(
utf8_roots
.
length
());
if
(
length
>
0
)
{
const
char
*
data
=
*
utf8_roots
;
pem_root_certs
=
(
char
*
)
gpr_malloc
((
length
+
1
)
*
sizeof
(
char
));
memcpy
(
pem_root_certs
,
data
,
length
+
1
);
}
}
void
init
(
Local
<
Object
>
exports
)
{
void
init
(
Local
<
Object
>
exports
)
{
Nan
::
HandleScope
scope
;
Nan
::
HandleScope
scope
;
grpc_init
();
grpc_init
();
grpc_set_ssl_roots_override_callback
(
get_ssl_roots_override
);
InitStatusConstants
(
exports
);
InitStatusConstants
(
exports
);
InitCallErrorConstants
(
exports
);
InitCallErrorConstants
(
exports
);
InitOpTypeConstants
(
exports
);
InitOpTypeConstants
(
exports
);
...
@@ -298,6 +329,10 @@ void init(Local<Object> exports) {
...
@@ -298,6 +329,10 @@ void init(Local<Object> exports) {
Nan
::
GetFunction
(
Nan
::
GetFunction
(
Nan
::
New
<
FunctionTemplate
>
(
MetadataKeyIsBinary
)
Nan
::
New
<
FunctionTemplate
>
(
MetadataKeyIsBinary
)
).
ToLocalChecked
());
).
ToLocalChecked
());
Nan
::
Set
(
exports
,
Nan
::
New
(
"setDefaultRootsPem"
).
ToLocalChecked
(),
Nan
::
GetFunction
(
Nan
::
New
<
FunctionTemplate
>
(
SetDefaultRootsPem
)
).
ToLocalChecked
());
}
}
NODE_MODULE
(
grpc_node
,
init
)
NODE_MODULE
(
grpc_node
,
init
)
This diff is collapsed.
Click to expand it.
src/node/index.js
+
3
−
4
View file @
6f607665
...
@@ -34,13 +34,10 @@
...
@@ -34,13 +34,10 @@
'
use strict
'
;
'
use strict
'
;
var
path
=
require
(
'
path
'
);
var
path
=
require
(
'
path
'
);
var
fs
=
require
(
'
fs
'
);
var
SSL_ROOTS_PATH
=
path
.
resolve
(
__dirname
,
'
..
'
,
'
..
'
,
'
etc
'
,
'
roots.pem
'
);
var
SSL_ROOTS_PATH
=
path
.
resolve
(
__dirname
,
'
..
'
,
'
..
'
,
'
etc
'
,
'
roots.pem
'
);
if
(
!
process
.
env
.
GRPC_DEFAULT_SSL_ROOTS_FILE_PATH
)
{
process
.
env
.
GRPC_DEFAULT_SSL_ROOTS_FILE_PATH
=
SSL_ROOTS_PATH
;
}
var
_
=
require
(
'
lodash
'
);
var
_
=
require
(
'
lodash
'
);
var
ProtoBuf
=
require
(
'
protobufjs
'
);
var
ProtoBuf
=
require
(
'
protobufjs
'
);
...
@@ -53,6 +50,8 @@ var Metadata = require('./src/metadata.js');
...
@@ -53,6 +50,8 @@ var Metadata = require('./src/metadata.js');
var
grpc
=
require
(
'
./src/grpc_extension
'
);
var
grpc
=
require
(
'
./src/grpc_extension
'
);
grpc
.
setDefaultRootsPem
(
fs
.
readFileSync
(
SSL_ROOTS_PATH
,
'
ascii
'
));
/**
/**
* Load a gRPC object from an existing ProtoBuf.Reflect object.
* Load a gRPC object from an existing ProtoBuf.Reflect object.
* @param {ProtoBuf.Reflect.Namespace} value The ProtoBuf object to load.
* @param {ProtoBuf.Reflect.Namespace} value The ProtoBuf object to load.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment