2

私はWindowsC++プロジェクトを持っています。既存のwinsockコードの上にsslクライアントとサーバーの両方を実装する必要があります。

opensslを試してみましたが、面倒すぎるようです。私は、opensslよりもこれを実装するためのより良い/より短い/よりクリーンな/より速い方法があると思います。

4

2 に答える 2

3

Windows に組み込まれている SSL の SChannel を使用できます。Google で「SChannel SSL」を検索すると、多くの情報が得られます (ただし、SChannel 自体は文書化されておらず、理解するのも容易ではありません)。

一方、OpenSSL を使用するプロジェクトのソース コードを調べてみると、OpenSSL は面倒ではありません。

于 2012-04-16T09:01:45.587 に答える
1

Acctually .. After some time spent with openssl hacking I wouldnt say its that messy :) In case anyone anytime needs to add ssl to existing winsock code:

existing winsock code was like this:

 0: sockett.Listen etc....
    1: sockett.Accept(client, .....
    2: recv(client , ...)
    3: send(client , .....)

well in short if you want to implement SSL here.. delete lines 2 and 3 :) and add:

SSL_library_init();
SSL_load_error_strings();
OpenSSL_add_all_algorithms();
SSL_CTX *tlsctx;
SSL *ssl;
tlsctx = SSL_CTX_new( SSLv23_method());
// search google : generate self signed certificate openssl
SSL_CTX_use_certificate_file(tlsctx, "ssl\\server1.crt" , SSL_FILETYPE_PEM);
SSL_CTX_use_PrivateKey_file(tlsctx, "ssl\\server1.key", SSL_FILETYPE_PEM);
ssl = SSL_new(tlsctx);
SSL_set_fd(ssl, client);
SSL_accept(ssl);

/* instaed recv SSL_read(ssl, ....*/
/* instaed send SSL_write(ssl, ....*/


/* not 100% sure Sleep and shutdown/free/close are entirely correct here but in my code works fine */
Sleep(3000);
SSL_shutdown(ssl);   
SSL_free(ssl);
SSL_CTX_free(tlsctx);
shutdown(client, SD_BOTH);
Sleep(10);
closesocket(client);

For testing: in command line run:

openssl s_client -host localhost -port <PORT>
于 2012-04-18T05:25:58.227 に答える