I'm trying to add nonblocking https client-side retrieval to my 
application. I'm getting an SSL_ERROR_SSL when I run it, after calling 
SSL_write() for the first time, when the handshake needs to occur. The 
error queue provides reason 276: SSL_R_UNINITIALIZED (see ssl_lib.c:733), 
because handshake_func == 0 (it hasn't been initialized).

I suspect I'm simply missing something in my initialization code. I'd be 
grateful if you could identify where I'm going wrong or what I'm missing 
with this brief code excerpt ... Many thanks.

// Initialization
SSL_METHOD* _sslMethodPtr = SSLv23_client_method();
OpenSSL_add_ssl_algorithms();
SSL_load_error_strings();
SSL_CTX* _contextPtr = SSL_CTX_new(_sslMethodPtr);
if (_contextPtr == NULL) {do_exit("_contextPtr failed to initialize");}
SSL_CTX_set_options(_contextPtr, SSL_OP_ALL|0); // Work around SSL bugs
char* _caFilePtr = 0;
char* _caFilePathPtr = 0;
if ((!SSL_CTX_load_verify_locations(_contextPtr, _caFilePtr, _caFilePathPtr)) |
     (!SSL_CTX_set_default_verify_paths(_contextPtr)))
     cout << "SSL init warning: error setting default verify locations. 
Continuing anyway." << endl;  // Upon execution this DOES print. Problem?
SSL* _connectionPtr = SSL_new(_contextPtr);


// Submit a connected nonblocking socket to OpenSSL
BIO* _sslBIOPtr = BIO_new_socket(_socketID, BIO_NOCLOSE);
SSL_set_bio(_connectionPtr, _sslBIOPtr, _sslBIOPtr);
SSL_set_connect_state(_connectionPtr); // Tells OpenSSL that at the next 
operation a handshake should occur


// Write the GET request, implicitly performing the handshake
while (noTextRemainsToWrite()) {
long _charsWritten = SSL_write(_connectionPtr, _remainingTextPtr, _rtLength);
long _lastError = SSL_get_error(_connectionPtr, _charsWritten);
   switch (_lastError) {
     ...
case SSL_ERROR_SSL:
       doExit("SSL ERROR 'SSL' recorded while attempting to write data to 
socket");
       break;
   };
};

// Read the response
...
// Deinitialization
...

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to