我刚刚为 64 位 Windows 编译并安装了 OpenSSL。我使用以下命令创建了一个自签名证书和一个私钥:
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 10000 -nodes
我现在正在使用 Firefox 测试在 OpenSSL Wiki 上找到的“简单 TLS 服务器”示例,并进行了一些修改以支持 Winsock,但我不断收到错误消息
11216:error:1417A0C1:SSL routines:tls_post_process_client_hello:no shared cipher:ssl\statem\statem_srvr.c:1422:
(第一个数字总是变化的)在 SSL_accept() 函数执行期间。当使用 Wireshark 连接到某些 HTTPS 服务器时,我已经检查了 Firefox (v 43.0.1) 在其 TLS v1.2 Client Hello 中发送的 (11) 密码列表(因为在 localhost 上捕获很困难)并将其与支持的密码进行比较通过我安装的 OpenSSL(使用 找到openssl.exe ciphers -s -tls1_2 -V
)。结果是有通用密码,所以我错过了什么?!
包含 statem_srvr.c 的第 1422 行的块如下,从 1420 开始:
if (cipher == NULL) {
SSLerr(SSL_F_TLS_POST_PROCESS_CLIENT_HELLO,
SSL_R_NO_SHARED_CIPHER);
goto f_err;
}
对原始代码的修改在 while 循环之前和标题中:
#pragma comment(lib,"Ws2_32.lib")
#include <stdio.h>
#include <winerror.h>
#include <WinSock2.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/applink.c>
和
int sock;
SSL_CTX *ctx;
WSADATA WsaDat;
if (WSAStartup(MAKEWORD(2, 2), &WsaDat) != 0) perror("Winsock fatal startup error");
init_openssl();
ctx = create_context();
configure_context(ctx);
sock = create_socket(4433);
编辑:当我尝试使用带有 TLSv1.2 的 s_client 连接到服务器时,会发生这种情况:
CONNECTED(000000F0)
23368:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure:ssl\record\rec_layer_s3.c:1362:SSL alert number 40
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 7 bytes and written 176 bytes
Verification: OK
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1.2
Cipher : 0000
Session-ID:
Session-ID-ctx:
Master-Key:
PSK identity: None
PSK identity hint: None
SRP username: None
Start Time: 1473536238
Timeout : 7200 (sec)
Verify return code: 0 (ok)
Extended master secret: no
---