我有一个代码交叉编译到2个设备。在1个设备上,代码可以完美运行,而在另一个设备上,SSL_connect什么都不做。有关这两种设备的信息:
Device 1: (working)
CPU: PowerPC @ 220MHz
RAM: 128MB SD-RAM
LINUX 2.6.24.6
Device 2: (not working)
CPU: PowerPC @ 133MHz
RAM:32MB SD-RAM
LINUX 2.4.21
这是我在发送EHLO和STARTTLS之后使用的代码:
static SSL_CTX *ctx = NULL;
static SSL *ssl = NULL;
void CreateTLSSession(int sockfd)
{
int RetValue=0;
printf("CREATING TLS SESSION...\n");
SSL_library_init();
SSL_load_error_strings();
OpenSSL_add_all_algorithms();
//ctx = SSL_CTX_new(TLSv1_client_method());
ctx = SSL_CTX_new(TLSv1_client_method());
//(SSL_CTX_set_options(ctx, SSL_OP_NO_COMPRESSION);
//SSL_CTX_set_mode(ctx, SSL_MODE_RELEASE_BUFFERS);
if (ctx == NULL)
{
printf("failed to initialize context\n");
return;
}
printf("CTX created...\n");
ssl = SSL_new(ctx);
if (ssl == NULL)
{
printf("failed to create SSL structure...\n");
return;
}
if (!SSL_set_fd(ssl, sockfd))
{
printf("failed to bind to socket fd\n");
return;
}
printf("SSL bound to sockfd=%d...\n",sockfd);
while (RetValue != 1)
{
RetValue = SSL_connect(ssl);
interpreteError(RetValue);
sleep(1);
}
printf("OK\n");
}
static void interpreteError(int iError)
{
int iRet = 0;
iRet = SSL_get_error(ssl, iError);
switch (iRet)
{
case SSL_ERROR_ZERO_RETURN:
printf("ERROR: TLS/SSL connection has been closed!\n");
break;
case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE:
printf("ERROR: want read/write!\n");
break;
case SSL_ERROR_WANT_CONNECT:
case SSL_ERROR_WANT_ACCEPT:
printf("ERROR: socket not yet connect to the peer!\n");
break;
case SSL_ERROR_WANT_X509_LOOKUP:
printf("ERROR: want x509 lookup!\n");
break;
case SSL_ERROR_SYSCALL:
perror("SSL_ERROR_SYSCALL");
break;
case SSL_ERROR_SSL:
printf("ERROR: failure in SSL library!n");
break;
default:
printf("No errors\n");
}
}
套接字是非阻塞的。我正在使用while循环进行测试。循环将在稍后用“开关”代替。
代码输出如下:
CREATING TLS SESSION...
CTX created...
SSL bound to sockfd=9...
SSL_ERROR_SYSCALL: Success
SSL_ERROR_SYSCALL: Success
SSL_ERROR_SYSCALL: Success
SSL_ERROR_SYSCALL: Success
SSL_ERROR_SYSCALL: Success
SSL_ERROR_SYSCALL: Success
SSL_ERROR_SYSCALL: Success
SSL_ERROR_SYSCALL: Success
SSL_ERROR_SYSCALL: Success
但永远不会离开循环。
我设法将设备2连接到托管交换机,并通过wireshark观察网络流量。令我惊讶的是,SSL_connect()没有任何效果。 wireshark显示的最后一件事是“220 2.0.0准备启动TLS”:
知道如何解决这个问题吗?