- openssl genrsa -des3 -out keys/rootca_test.key 2048
- Сертификаты/rootca_test.crt
[*] openssl genrs -opents/server_test. req -new -Key keys/server_test.key -out csr/server_test.csr
[*] openssl ca -days 360 -in csr/server_test.csr -out sertiates/server_test.crt -Keyfile keys/rootca_test.key -cert/rootca_test.crt -keyfile/rootca_test.key -cert/roota_test.crt -keyfile
// Команды для создания клиентского сертификата
openssl genrsa -out keys/client_test.key 2048
[*] openssl. Csr/client_test.csr
[*] openssl ca -days 360 -in csr/client_test.csr -out сертификаты/client_test.crt -Keyfile Cheys/rootca_test.key -cert sertiates/rootca_test.crt
после интеграции кода выглядит так: < /strong> < /p>
client Code - в Windows < /strong> < /p>
#include "stdafx.h"
#include
#include
#include // SSL and SSL_CTX for SSL connections
#include // Error reporting
SOCKET s;
SSL_CTX *ctx;
SSL *ssl;
int OpenConnection(const char *hostname, int port)
{ int sd;
struct hostent *host;
struct sockaddr_in addr;
if ( (host = gethostbyname(hostname)) == NULL )
{
perror(hostname);
abort();
}
sd = socket(AF_INET, SOCK_STREAM,IPPROTO_TCP);
memset(&addr,0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
addr.sin_addr.s_addr = *(long*)(host->h_addr);
if ( connect(sd, (struct sockaddr*)&addr, sizeof(addr)) != 0 )
{
close(sd);
perror(hostname);
abort();
}
return sd;
}
BOOL InitOpenSSL()//OPENSSL
{
//set default locations for trusted CA certificates
CString sslCrtFilePath = "C:\\Program Files\\cv\\certificates\\client_test.crt";
CString sslKeyFilePath = "C:\\Program Files\\cv\\certificates\\client_test.key";
CString sslRootFilePath = "C:\\Program Files\\cv\\certificates\\RootCA_test.crt";
int server;
char buf[1024];
int bytes;
char hostname[]="20.17.127.235";
int portnum = 4005;
SSL_library_init();
SSL_METHOD *method;
OpenSSL_add_all_algorithms(); /* Load cryptos, et.al. */
SSL_load_error_strings(); /* Bring in and register error messages */
method = SSLv23_client_method();//SSLv23_method(); /* Create new client-method instance */
ctx = SSL_CTX_new(method); /* Create new context */
if ( ctx == NULL )
{
abort();
}
if (!(LoadCertificates(sslRootFilePath.GetBuffer(sslRootFilePath.GetLength()),sslCrtFilePath.GetBuffer(sslCrtFilePath.GetLength()), sslKeyFilePath.GetBuffer(sslKeyFilePath.GetLength()))))
{
s = INVALID_SOCKET;
cout
Подробнее здесь: https://stackoverflow.com/questions/336 ... ertificate
Мобильная версия