|
|
|
@ -148,11 +148,13 @@ static ID id_pem_cert_chain; |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
call-seq: |
|
|
|
|
creds1 = Credentials.new(pem_root_certs) |
|
|
|
|
creds1 = Credentials.new() |
|
|
|
|
... |
|
|
|
|
creds2 = Credentials.new(pem_root_certs, pem_private_key, |
|
|
|
|
creds2 = Credentials.new(pem_root_certs) |
|
|
|
|
... |
|
|
|
|
creds3 = Credentials.new(pem_root_certs, pem_private_key, |
|
|
|
|
pem_cert_chain) |
|
|
|
|
pem_root_certs: (required) PEM encoding of the server root certificate |
|
|
|
|
pem_root_certs: (optional) PEM encoding of the server root certificate |
|
|
|
|
pem_private_key: (optional) PEM encoding of the client's private key |
|
|
|
|
pem_cert_chain: (optional) PEM encoding of the client's cert chain |
|
|
|
|
Initializes Credential instances. */ |
|
|
|
@ -163,26 +165,23 @@ static VALUE grpc_rb_channel_credentials_init(int argc, VALUE *argv, VALUE self) |
|
|
|
|
grpc_rb_channel_credentials *wrapper = NULL; |
|
|
|
|
grpc_channel_credentials *creds = NULL; |
|
|
|
|
grpc_ssl_pem_key_cert_pair key_cert_pair; |
|
|
|
|
const char *pem_root_certs_cstr = NULL; |
|
|
|
|
MEMZERO(&key_cert_pair, grpc_ssl_pem_key_cert_pair, 1); |
|
|
|
|
/* TODO: Remove mandatory arg when we support default roots. */ |
|
|
|
|
/* "12" == 1 mandatory arg, 2 (credentials) is optional */ |
|
|
|
|
rb_scan_args(argc, argv, "12", &pem_root_certs, &pem_private_key, |
|
|
|
|
/* "03" == no mandatory arg, 3 optional */ |
|
|
|
|
rb_scan_args(argc, argv, "03", &pem_root_certs, &pem_private_key, |
|
|
|
|
&pem_cert_chain); |
|
|
|
|
|
|
|
|
|
TypedData_Get_Struct(self, grpc_rb_channel_credentials, |
|
|
|
|
&grpc_rb_channel_credentials_data_type, wrapper); |
|
|
|
|
if (pem_root_certs == Qnil) { |
|
|
|
|
rb_raise(rb_eRuntimeError, |
|
|
|
|
"could not create a credential: nil pem_root_certs"); |
|
|
|
|
return Qnil; |
|
|
|
|
if (pem_root_certs != Qnil) { |
|
|
|
|
pem_root_certs_cstr = RSTRING_PTR(pem_root_certs); |
|
|
|
|
} |
|
|
|
|
if (pem_private_key == Qnil && pem_cert_chain == Qnil) { |
|
|
|
|
creds = |
|
|
|
|
grpc_ssl_credentials_create(RSTRING_PTR(pem_root_certs), NULL, NULL); |
|
|
|
|
creds = grpc_ssl_credentials_create(pem_root_certs_cstr, NULL, NULL); |
|
|
|
|
} else { |
|
|
|
|
key_cert_pair.private_key = RSTRING_PTR(pem_private_key); |
|
|
|
|
key_cert_pair.cert_chain = RSTRING_PTR(pem_cert_chain); |
|
|
|
|
creds = grpc_ssl_credentials_create(RSTRING_PTR(pem_root_certs), |
|
|
|
|
creds = grpc_ssl_credentials_create(pem_root_certs_cstr, |
|
|
|
|
&key_cert_pair, NULL); |
|
|
|
|
} |
|
|
|
|
if (creds == NULL) { |
|
|
|
|