Monday, 26 August 2013

BIO_do_connect always returns -1

BIO_do_connect always returns -1

the BIO_do_connect function always returns -1. I am not sure what i am
making wrong here. Please help
the following code snippet is return -1 error.
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; }
Regards AH

No comments:

Post a Comment