- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在编写一个 https 服务器。我已经创建了 csr 并使用我的测试域的根证书对其进行了签名。当客户端连接时,SSL_accept() 成功完成。我正在使用非阻塞 IO。因此,我将首先在 char 缓冲区中使用 WSARecv() 和 IOCP 在 Windows 中异步接收数据。从那个字符缓冲区,我将它写入 BIO(BIO_write 返回写入的字节数)并尝试使用 SSL_read() 解密该 BIO 的内容,它返回 ssl_error_ssl 和错误字符串 error:00000001:lib(0):func (0):原因(1)。
我在这里添加了我的代码结构。
const SSL_METHOD *method;
SSL_CTX *ctx;
method = SSLv23_method(); /* create new server-method instance */
ctx = SSL_CTX_new(method); /* create new context from method */
if ( ctx == NULL )
{
printf("SSL Context Creation failed\n");
}
//create bio
BIO *bioIn = BIO_new(BIO_s_mem());
BIO *bioOut = BIO_new(BIO_s_mem());
/* get new SSL state with context */
SSL *clientSSL = SSL_new(ctx);
SSL_set_bio(clientSSL, bioIn , bioOut);
/* set connection socket to SSL state */
SSL_set_fd(clientSSL, mClientSocket);
/* serverNameCallBack will set ctx with certificate created for this domain */
SSL_CTX_set_tlsext_servername_callback(ctx, serverNameCallback);
/* accept ssl connection */
SSL_accept(clientSSL);
//Using WSARecv() here to get encrypted request to a buffer
//read from buffer
//bridge->getBuffer() returns the buffer with encrypted data received
int retBio = BIO_write(bioIn, bridge->getBuffer(), bytesTransfered);
char *buffer = (char *)malloc(sizeof(char) * 1024);
ZeroMemory(buffer, sizeof(buffer));
int retSSL = SSL_read(clientSSL, (void*)buffer, 1023);
retSSL == -1 和 SSL_get_error(clientSSL, retSSL) 返回 SSL_ERROR_SSL
最佳答案
多亏了一些博客,我解决了这个问题。执行此操作的正确顺序是,应在调用 ssl_accept 之后创建 BIO 并将其与 ssl 对象相关联。如果您在 ssl_accept 之前关联它,那么您必须以不同的方式处理它。您应该在调用 ssl_accept 之前设置 SSL_set_accept_state。
这是正确的代码序列
const SSL_METHOD *method;
SSL_CTX *ctx;
method = SSLv23_method(); /* create new server-method instance */
ctx = SSL_CTX_new(method); /* create new context from method */
if ( ctx == NULL )
{
printf("SSL Context Creation failed\n");
}
/* get new SSL state with context */
SSL *clientSSL = SSL_new(ctx);
/* set connection socket to SSL state */
SSL_set_fd(clientSSL, mClientSocket);
/* serverNameCallBack will set ctx with certificate created for this domain */
SSL_CTX_set_tlsext_servername_callback(ctx, serverNameCallback);
/* set ssl handle to be used as a server */
SSL_set_accept_state(clientSSL);
/* accept ssl connection */
SSL_accept(clientSSL);
//Using WSARecv() here to get encrypted request to a buffer
//create bio
BIO *bioIn = BIO_new(BIO_s_mem());
BIO *bioOut = BIO_new(BIO_s_mem());
SSL_set_bio(clientSSL, bioIn , bioOut);
//read from buffer
//bridge->getBuffer() returns the buffer with encrypted data received
int retBio = BIO_write(bioIn, bridge->getBuffer(), bytesTransfered);
char *buffer = (char *)malloc(sizeof(char) * 1024);
ZeroMemory(buffer, sizeof(buffer));
int retSSL = SSL_read(clientSSL, (void*)buffer, 1023);
关于c++ - SSL_read 失败并显示 SSL_ERROR_SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23888517/
我正在编写一个 https 服务器。我已经创建了 csr 并使用我的测试域的根证书对其进行了签名。当客户端连接时,SSL_accept() 成功完成。我正在使用非阻塞 IO。因此,我将首先在 char
当我使用 openssl 创建一个 ssl base server-client 程序时,服务器端的 SSL_accept 和客户端的 SSL_connect 都返回一个名为“SSL_ERROR_SS
我得到了一些SSL Error (这导致我的项目停止/挂起而没有崩溃,因为我有一个 DispatchGroup 等待请求),我不知道它们是如何引起的,它们是什么,或者如何处理它。 我已经粗略阅读了很多
我正在学习本教程 https://hyperledger.github.io/composer/latest/tutorials/deploy-to-fabric-multi-org将 compose
尝试从 MSSQL 数据库容器中的 C# (C Sharp) 微服务播种/迁移数据(图片为 mssql-server-linux:2017-latest)... 连接成功 异常信息如下 examp
我是 grpc 和 tensorflow 模型服务器的新手。我已经使用 bazel 从源代码构建了 tensorflow 模型服务器(TF2.2)。我正在尝试使用带有 SSL 身份验证的 tensor
我在做这样的事情时在标题中得到了错误: $zurl = "https://api.zotero.org/something"; require_once 'HTTP/Request2.php'; $r
我的应用程序在使用 openssl 0.9.8.y 全新安装时工作正常使用 openssl 0.9.8.zb 进行全新安装时效果很好 但是当我将应用程序从 openssl 0.9.8.y 升级到 op
此错误发生在单个端点上。它是试图从 SqlServer 中提取数据的那个。如果我尝试运行 IIS,一切正常。当我在 linux docker 容器中运行时,它不再工作了。我有以下错误: OpenSsl
我是一名优秀的程序员,十分优秀!