我刚刚为64位Windows编译和安装了OpenSSL . 我使用以下命令创建了自签名证书和私钥:
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 10000 -nodes
我正在测试使用Firefox在OpenSSL Wiki中找到的"Simple TLS Server" example和一些支持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客户端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循环之前和 Headers 中:
#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);
Edit: 当我尝试使用带有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
---
3 回答
事实证明,找到证书和私钥时出现问题 . 问题解决了 .
EJP的评论解决了我的问题 . 在我的例子中,我使用SSL_CTX创建了一个SSL对象,但在创建ssl对象后设置了SSL_CTX的证书和密钥,因此从未将证书和密钥复制到SSL对象 . 在我创建SSL对象之前移动我的证书和密钥代码解决了这个问题 .
错误的方法:
正确的方法
还有其他方法可以将密钥直接添加到SSL对象,在这种情况下,这不适用,但我没有采用这种方法 .
我也遇到过同样的问题 . 我也解决了它:
berofe(这是错误的)
之后(没关系)