我编辑了代码,这就是现在的样子。服务器正在尝试在套接字上写入一些字节。
int r;
FILE *fp;
fp = stderr;
const SSL_METHOD *method;
method = SSLv23_server_method();
ERR_clear_error();
if ( !ctx)
{
ctx = SSL_CTX_new(method);
if (!ctx) {
return 0;
}
SSL_CTX_set_ecdh_auto(ctx, 1);
if (SSL_CTX_use_certificate_file(ctx, "/home/cert.pem", SSL_FILETYPE_PEM) <= 0) {
ERR_print_errors_fp(fp);
}
if (SSL_CTX_use_PrivateKey_file(ctx, "/home/key.pem", SSL_FILETYPE_PEM) <= 0 ) {
ERR_print_errors_fp(fp);
}
}
if (!ctx) {
return;
}
SSL *ssl;
ssl = SSL_new(ctx);
SSL_set_fd(ssl, fd);
ERR_clear_error();
if (SSL_accept(ssl) <= 0) {
ERR_print_errors_fp(fp);
}
int rce = 0;
ERR_clear_error();
char *buffer = (char *) malloc(iova.iov_len);
memcpy(buffer, iova.iov_base, iova.iov_len);
r = SSL_write(ssl, buffer, (int)iova.iov_len);
// check how many bytes were written
if ( r <= 0 )
{
ERR_print_errors_fp(fp);
int err = errno;
switch(SSL_get_error(ssl,r)){
case SSL_ERROR_NONE:
continue;
case SSL_ERROR_ZERO_RETURN:
syslog(LOG_INFO, "SSL read encountered an error %d. Peer disconnected.", SSL_ERROR_ZERO_RETURN);
break;
case SSL_RECEIVED_SHUTDOWN:
syslog(LOG_INFO, "SSL read encountered an error %d. Shutdown.", SSL_RECEIVED_SHUTDOWN);
break;
case SSL_ERROR_SYSCALL:
syslog(LOG_INFO, "SSL write encountered an error %d and %lu. SYSCALL", SSL_get_error(ssl,r), ERR_get_error());
break;
default:
syslog(LOG_INFO, "SSL write encountered an error %d and %d. Quitting", SSL_get_error(ssl,r), err);
break;
}
我无法解决的夫妻问题-
SSL_accept()失败
SSL_write()然后失败,并显示SSL_RECEIVED_SHUTDOWN和err string = error:00000002:lib(0):func(0):system lib
在这里SSL_accept
和SSL_write()
在做什么?
我正在尝试使用Openssl执行SSL_write()
,并且在SSL_write()
期间收到以下错误。服务器正在尝试向套接字连接fd
-
error:140D0114:SSL routines:SSL_write:uninitialized:ssl_lib.c:1039:
Error: error:00000005:lib(0):func(0):DH lib
这是我的代码
SSL *ssl;
if ( !ctx )
return 0;
ssl = SSL_new(ctx);
//SSL_set_fd(ssl, fd);
BIO *sbio = NULL;
sbio = BIO_new_socket(fd, BIO_NOCLOSE);
SSL_set_bio(ssl, sbio, sbio);
ERR_clear_error();
FILE *fp;
fp = stderr;
r = SSL_write(ssl, buffer, (len);
if ( r <= 0 )
{
ERR_print_errors_fp(fp);
switch(SSL_get_error(ssl,r)){
case SSL_ERROR_NONE:
syslog(LOG_INFO, "No real error. Continue.");
continue;
case SSL_ERROR_ZERO_RETURN:
syslog(LOG_INFO, "SSL read encountered an error %d. Peer disconnected.", SSL_ERROR_ZERO_RETURN);
break;
case SSL_RECEIVED_SHUTDOWN:
syslog(LOG_INFO, "SSL read encountered an error %d. Shutdown.", SSL_RECEIVED_SHUTDOWN);
break;
case SSL_ERROR_SYSCALL:
syslog(LOG_INFO, "SSL write encountered an error %d and %lu. SYSCALL", SSL_get_error(ssl,r), ERR_get_error());
break;
default:
syslog(LOG_INFO, "SSL write encountered an error %d and %d. Quitting", SSL_get_error(ssl,r), err);
break;
}
SSL上下文(ctx)首先是有效的。
我尝试查找错误的解释,但没有找到。我也没有找到可以解决该问题的类似问题。谁能帮助我了解我可以做些什么来进一步调试它?还是他们有解决方案?
Openssl版本1.0.2g