简体   繁体   中英

Error in grpc with TLS support

I am trying to run the secure helloworld program to check the support of TLS in the GRPC code. I get this error

E1228 23:15:44.054232298   10843 ssl_transport_security.cc:621] Invalid cert chain file.
E1228 23:15:44.054286682   10843 security_connector.cc:1108] Handshaker factory creation failed with TSI_INVALID_ARGUMENT.
E1228 23:15:44.054304555   10843 server_secure_chttp2.cc:83] {"created":"@1514520944.054294700","description":"Unable to create secure server with credentials of type Ssl.","file":"src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc","file_line":62,"security_status":1}
Server listening on localhost:50051
Segmentation fault (core dumped)

Following is my server code.

std::string server_address ( "localhost:50051" );

std::string key;
std::string cert;
std::string root;

read ( "server.crt", cert );
read ( "server.key", key );
read ( "ca.crt", root );

ServerBuilder builder;

grpc::SslServerCredentialsOptions::PemKeyCertPair keycert =
{
    key,
    cert
};

grpc::SslServerCredentialsOptions sslOps;
sslOps.pem_root_certs = root;
sslOps.pem_key_cert_pairs.push_back ( keycert );

builder.AddListeningPort(server_address, grpc::SslServerCredentials( sslOps ));

GreeterServiceImpl service;
builder.RegisterService(&service);

std::unique_ptr < Server > server ( builder.BuildAndStart () );
std::cout << "Server listening on " << server_address << std::endl;

server->Wait ();

I am just trying to run the server. CLient isnt even in the picture yet. Here is the script i used to generate the keys.

# Generate valid CA
openssl genrsa -passout pass:1234 -des3 -out ca.key 4096
openssl req -passin pass:1234 -new -x509 -days 365 -key ca.key -out ca.crt -subj  "/C=CA/ST=Ontario/L=Ontario/O=Test/OU=Test/CN=Root CA"

# Generate valid Server Key/Cert
openssl genrsa -passout pass:1234 -des3 -out server.key 4096
openssl req -passin pass:1234 -new -key server.key -out server.csr -subj "/C=CA/ST=Ontario/L=Ontario/O=Test/OU=Server/CN=localhost"
openssl x509 -req -passin pass:1234 -days 365 -in server.csr -CA ca.crt -
CAkey ca.key -set_serial 01 -out server.crt

# Remove passphrase from the Server Key
openssl rsa -passin pass:1234 -in server.key -out server.key

# Generate valid Client Key/Cert
openssl genrsa -passout pass:1234 -des3 -out client.key 4096
openssl req -passin pass:1234 -new -key client.key -out client.csr -subj  "/C=CA/ST=Ontario/L=Ontario/O=Test/OU=Client/CN=localhost"
openssl x509 -passin pass:1234 -req -days 365 -in client.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out client.crt

# Remove passphrase from Client Key
openssl rsa -passin pass:1234 -in client.key -out client.key

Any help would be deeply appreciated. Thanks

The error looks like there was something wrong with loading server x509 certificate. Did you put your server key/certificate and CA certificate in the same directory of your server binary?

I use your script to generate keys and certificates. I use the greeter client/server code from https://github.com/grpc/grpc/issues/9593 Everything works fine. I could not duplicate your error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM