简体   繁体   English

如何使用 c++ 客户端/服务器在带有 gsoap 的 openssl 中使用 ssl 证书

[英]how to use ssl certificates in openssl with gsoap, using a c++ client/server

I am using gsoap and openssl under Visual Studio C++, I created a client and a server on localhost (port 443).我在 Visual Studio C++ 下使用 gsoap 和 openssl,我在本地主机(端口 443)上创建了一个客户端和一个服务器。

I have a non explicit error without any description when using (from client side) the option: soap_ssl_client_context(&soap, "SOAP_SSL_DEFAULT"...使用(从客户端)选项时,我有一个没有任何描述的非显式错误:soap_ssl_client_context(&soap, "SOAP_SSL_DEFAULT"...

but if I use it with the option: soap_ssl_client_context(&soap, SOAP_SSL_DEFAULT | SOAP_SSL_SKIP_HOST_CHECK, ...但是如果我将它与选项一起使用:soap_ssl_client_context(&soap, SOAP_SSL_DEFAULT | SOAP_SSL_SKIP_HOST_CHECK, ...
it is working correctly (but insecurely I gess).它工作正常(但我猜不安全)。

So I decided to check what is the error by checking packets on localhost (with raw capture), and I see that the communication ends by an Encrypted Alert (21) after terminating the handshake.所以我决定通过检查本地主机上的数据包(使用原始捕获)来检查错误是什么,并且我看到终止握手后通信以加密警报(21)结束。

And I Wonder what I need to do, to get this application working properly and securely on localhost (for testing purpose).我想知道我需要做什么,才能让这个应用程序在本地主机上正常安全地工作(用于测试目的)。

More Info: I have generated ssl certificates for server side with a batch:更多信息:我已经为服务器端批量生成了 ssl 证书:

echo CREATE SERVER CA and CA CERT
echo Generate Private Key (passwd protected)
openssl genrsa -des3 -out .\private\CA_key.pem 2048
pause

echo Generate server CA
echo use your server name for the 'common name' field!
openssl req -out ca.pem -new -x509 -key .\private\CA_key.pem
pause

echo Create certificate signing request for CA pub Key
openssl req -new -key .\private\CA_key.pem -out CA_csr.pem
pause

echo Sign it
openssl req -in CA_csr.pem -out CA_crt.pem -key .\private\CA_key.pem -x509 -days 3020
pause

echo FOR C++ SERVER ONLY
type .\private\CA_key.pem CA_crt.pem > server.pem
pause  

And also for client side:也适用于客户端:

echo CREATE PUB/PRIV key pair and cert for client
echo Generate key pair
openssl genrsa -des3 -out client_key.pem 2048
pause

echo Create CSR for client pub key
openssl req -new -key client_key.pem -out client_csr.pem
pause

echo User ca to sign the request (need serial file with '01')
echo make sure your openssl.cnf is correct (path and right CA certificate file)
openssl ca -in client_csr.pem -out client_crt.pem -config openssl.cfg -days 1825
pause

echo CLIENT SPECIFIC FORMATING (optional)
echo for C++ clients ONLY
type client_key.pem client_crt.pem > LCC.pem

I used: CA_crt.pem as "cacert file" in both soap_ssl_server_context and soap_ssl_client_context.我使用: CA_crt.pem 作为 soap_ssl_server_context 和 soap_ssl_client_context 中的“cacert 文件”。 LCC.pem as client key, and server.pem as server key. LCC.pem 作为客户端密钥,server.pem 作为服务器密钥。

I am not sure if all certificate generation steps are correct but it is working with the option (SOAP_SSL_DEFAULT | SOAP_SSL_SKIP_HOST_CHECK).我不确定所有证书生成步骤是否正确,但它正在使用选项 (SOAP_SSL_DEFAULT | SOAP_SSL_SKIP_HOST_CHECK)。

Can you help me please to find out what is missing to get it working with SOAP_SSL_DEFAULT only?你能帮我找出让它只与 SOAP_SSL_DEFAULT 一起工作所缺少的东西吗?

Thank you谢谢

I am not sure if all certificate generation steps are correct but it is working with the option (SOAP_SSL_DEFAULT | SOAP_SSL_SKIP_HOST_CHECK).我不确定所有证书生成步骤是否正确,但它正在使用选项 (SOAP_SSL_DEFAULT | SOAP_SSL_SKIP_HOST_CHECK)。

If the certificate works with gSoap with SOAP_SSL_SKIP_HOST_CHECK and does not work without it, then the CommonName for your certificate is not a hostname or IP address.如果证书与带有 SOAP_SSL_SKIP_HOST_CHECK 的 gSoap 一起工作,没有它就不能工作,那么证书的 CommonName 不是主机名或 IP 地址。 Depending on the purpose for your certificate, you may not want your certificate CommonName to be the host ip/name and so using SOAP_SSL_SKIP_HOST_CHECK is fine.根据证书的用途,您可能不希望证书 CommonName 成为主机 ip/名称,因此使用 SOAP_SSL_SKIP_HOST_CHECK 就可以了。

If you want to quit using the SOAP_SSL_SKIP_HOST_CHECK flag, then regenerate your certificate to have the CommonName be the host name or ip address.如果您想使用 SOAP_SSL_SKIP_HOST_CHECK 标志退出,请重新生成您的证书,使 CommonName 成为主机名或 IP 地址。 (Note: You may run into conflicts with other certificates installed on your system - if one of them has an identical CommonName.) (注意:您可能会与系统上安装的其他证书发生冲突 - 如果其中一个证书具有相同的 CommonName。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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