BIO_do_connect函数始终返回-1。我不确定我在这里做错了什么。 请帮忙
以下代码段返回-1错误。
SSL_load_error_strings();
ERR_load_BIO_strings();
OpenSSL_add_all_algorithms();
SSL_library_init(); //mandatory and missing from some examples
/* Set up the SSL context */
ctx = SSL_CTX_new(SSLv23_client_method());
if(ctx == NULL)
{
return -1;
}
retval = SSL_CTX_use_certificate_file(ctx, CERTFILE, SSL_FILETYPE_PEM);
if(retval != 1)
{
SSL_CTX_free(ctx);
return -1;
}
if(! SSL_CTX_load_verify_locations(ctx, CERTFILE, NULL))
{
SSL_CTX_free(ctx);
return 0;
}
if (SSL_CTX_use_certificate_chain_file(ctx, CERTFILE) != 1)
{
SSL_CTX_free(ctx);
return 0;
}
//BIO Based Implementation
// Setup the connection
bio = BIO_new_ssl_connect(ctx);
if(bio == NULL)
{
return -2;
}
BIO_get_ssl(bio, & ssl);
// Create and setup the connection
// Set the SSL_MODE_AUTO_RETRY flag
SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
BIO_set_conn_hostname(bio, "buxconnect.net:https/transact.aspx");
retval = BIO_do_connect(bio);
if(retval <= 0)
{
fprintf(stderr, "Error attempting to connect\n");
ERR_print_errors_fp(stderr);
BIO_free_all(bio);
SSL_CTX_free(ctx);
return -1;
}
此致 AH