gpt4 book ai didi

c++ - 支持 TLS 的 grpc 出错

转载 作者:行者123 更新时间:2023-11-30 05:06:14 25 4
gpt4 key购买 nike

我正在尝试运行安全的 helloworld 程序来检查 GRPC 代码中对 TLS 的支持。我得到这个错误

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)

以下是我的服务器代码。

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 ();

我只是想运行服务器。客户端甚至还没有出现在图片中。这是我用来生成 key 的脚本。

# 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

任何帮助将不胜感激。谢谢

最佳答案

该错误看起来像是加载服务器 x509 证书时出现问题。您是否将服务器 key /证书和 CA 证书放在服务器二进制文件的同一目录中?

我使用您的脚本生成 key 和证书。我使用来自 https://github.com/grpc/grpc/issues/9593 的欢迎客户端/服务器代码一切正常。我无法复制你的错误。

关于c++ - 支持 TLS 的 grpc 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48024793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com