Using GPT and my own thinking, this error usually means that the SSL/TLS handshake process has failed, where the SSLv3 handshake failure may be due to security issues related to SSLv3 version, Therefore, SSLv3 is generally not recommended. In this case, it is recommended that you try to use a more secure TLS protocol version such as TLSv1.0, TLSv1.1, or TLSv1.2.
Here are the suggested solutions:
1 Try using TLSv1.0, TLSv1.1, or TLSv1.2 protocol versions, which are more secure than SSLv3. You can specify supported TLS versions using the SSL_CTX_set_options function.
2 Ensure that the target server supports the SSL/TLS protocol version you are using. You can run the openssl s_client command to test the supported protocol version of the target server. For example, to test TLSv1.2 support, use the following command:
openssl s_client-connect servername: port-tls1_2
3 If the target server supports only SSLv3, you may need to contact the server administrator to upgrade SSL/TLS support.
4 Check whether the certificate is correct. If the certificate is invalid or does not match the server, the SSL handshake may fail.
If you want to try using a more secure version of the TLS protocol, such as TLSv1.0, TLSv1.1, or TLSv1.2, you can use the following code:
int init_SSL(int tcp_fd, SSL **ssl, SSL_CTX **ctx)
{
int n, ret;
/* 初始化https的SSL加密协议 */
//加载错误字符串资源
SSL_load_error_strings();
//初始化SSL库
SSL_library_init();
//新建SSL会话
*ctx = SSL_CTX_new(TLSv1_2_client_method()); // 使用TLSv1.2协议
if (*ctx == NULL)
{
fprintf(stderr, "init SSL CTX failed:%s\n",
ERR_reason_error_string(ERR_get_error()));
return -1;
}
//根据会话新建SSL加密
*ssl = SSL_new(*ctx);
if (*ssl == NULL)
{
fprintf(stderr, "new SSL with created CTX failed:%s\n",
ERR_reason_error_string(ERR_get_error()));
return -1;
}
//绑定文件描述符,tcp_fd是连接完服务器的文件描述符
ret = SSL_set_fd(*ssl, tcp_fd);
if (ret == 0)
{
fprintf(stderr, "add SSL to tcp socket failed:%s\n",
ERR_reason_error_string(ERR_get_error()));
return -1;
}
/* 利用SSL加密连接服务器 */
ret = SSL_connect(*ssl);
if (ret != 1)
{
fprintf(stderr, "SSL connection failed:%s\n",
ERR_reason_error_string(ERR_get_error()));
return -1;
}
return 0;
}
After this modification, the program establishes an SSL connection to the server using the TLSv1.2 protocol version. Note that you can specify supported TLS versions using the SSL_CTX_set_options function. For example, to support both TLSv1.0, TLSv1.1, and TLSv1.2, use the following code:
SSL_CTX_set_options(*ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1);
If it helps you, please give it, thank you.