(file) Return to SSLContext.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

Diff for /pegasus/src/Pegasus/Common/SSLContext.cpp between version 1.76 and 1.84

version 1.76, 2006/11/17 18:37:28 version 1.84, 2007/08/06 09:46:20
Line 32 
Line 32 
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #ifdef PEGASUS_HAS_SSL #ifdef PEGASUS_HAS_SSL
   
 #include <Pegasus/Common/Config.h> #include <Pegasus/Common/Config.h>
   # include <Pegasus/Common/Executor.h>
 #include "Network.h"  # include <Pegasus/Common/Network.h>
   
 #define OPENSSL_NO_KRB5 1 #define OPENSSL_NO_KRB5 1
 #include <openssl/err.h> #include <openssl/err.h>
 #include <openssl/ssl.h> #include <openssl/ssl.h>
Line 44 
Line 42 
 #else #else
 #define SSL_CTX void #define SSL_CTX void
 #endif // end of PEGASUS_HAS_SSL #endif // end of PEGASUS_HAS_SSL
   
   #include <time.h>
 #include <Pegasus/Common/Socket.h> #include <Pegasus/Common/Socket.h>
 #include <Pegasus/Common/Tracer.h> #include <Pegasus/Common/Tracer.h>
 #include <Pegasus/Common/FileSystem.h> #include <Pegasus/Common/FileSystem.h>
 #include <time.h>  
 #include <Pegasus/Common/MessageLoader.h> #include <Pegasus/Common/MessageLoader.h>
 #include <Pegasus/Common/Formatter.h>  #include <Pegasus/Common/AuditLogger.h>
  
 #include "SSLContext.h" #include "SSLContext.h"
 #include "SSLContextRep.h" #include "SSLContextRep.h"
  
 #ifdef PEGASUS_OS_OS400  #ifdef PEGASUS_OS_PASE
 #include "SSLWrapperOS400.h"  # include <ILEWrapper/ILEUtilities.h>
 #endif #endif
   
 // //
 // Typedef's for OpenSSL callback functions. // Typedef's for OpenSSL callback functions.
 // //
Line 218 
Line 216 
     //check whether a CRL store was specified     //check whether a CRL store was specified
     if (sslCRLStore == NULL)     if (sslCRLStore == NULL)
     {     {
         PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL3,          PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL3,
             "---> SSL: CRL store is NULL");             "---> SSL: CRL store is NULL");
         PEG_METHOD_EXIT();         PEG_METHOD_EXIT();
         return 0;         return 0;
Line 238 
Line 236 
     //log certificate information     //log certificate information
     //this is information in the "public" key, so it does no harm to log it     //this is information in the "public" key, so it does no harm to log it
     X509_NAME_oneline(issuerName, buf, sizeof(buf));     X509_NAME_oneline(issuerName, buf, sizeof(buf));
     PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4,      PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL4,
         "---> SSL: Certificate Data: Issuer/Subject");         "---> SSL: Certificate Data: Issuer/Subject");
     PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4, buf);      PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL4, buf);
     X509_NAME_oneline(subjectName, buf, sizeof(buf));     X509_NAME_oneline(subjectName, buf, sizeof(buf));
     PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4, buf);      PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL4, buf);
  
     //initialize the CRL store     //initialize the CRL store
     X509_STORE_CTX crlStoreCtx;     X509_STORE_CTX crlStoreCtx;
     X509_STORE_CTX_init(&crlStoreCtx, sslCRLStore, NULL, NULL);     X509_STORE_CTX_init(&crlStoreCtx, sslCRLStore, NULL, NULL);
  
     PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4,      PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL4,
         "---> SSL: Initialized CRL store");         "---> SSL: Initialized CRL store");
  
     //attempt to get a CRL issued by the certificate's issuer     //attempt to get a CRL issued by the certificate's issuer
Line 256 
Line 254 
     if (X509_STORE_get_by_subject(     if (X509_STORE_get_by_subject(
             &crlStoreCtx, X509_LU_CRL, issuerName, &obj) <= 0)             &crlStoreCtx, X509_LU_CRL, issuerName, &obj) <= 0)
     {     {
         PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL3,          PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL3,
             "---> SSL: No CRL by that issuer");             "---> SSL: No CRL by that issuer");
         PEG_METHOD_EXIT();         PEG_METHOD_EXIT();
         return 0;         return 0;
Line 267 
Line 265 
     X509_CRL* crl = obj.data.crl;     X509_CRL* crl = obj.data.crl;
     if (crl == NULL)     if (crl == NULL)
     {     {
         PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4, "---> SSL: CRL is null");          PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL4, "---> SSL: CRL is null");
         PEG_METHOD_EXIT();         PEG_METHOD_EXIT();
         return 0;         return 0;
     }     }
     else     else
     {     {
         PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4,          PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL4,
             "---> SSL: Found CRL by that issuer");             "---> SSL: Found CRL by that issuer");
     }     }
  
Line 281 
Line 279 
     STACK_OF(X509_REVOKED)* revokedCerts = NULL;     STACK_OF(X509_REVOKED)* revokedCerts = NULL;
     revokedCerts = X509_CRL_get_REVOKED(crl);     revokedCerts = X509_CRL_get_REVOKED(crl);
     int numRevoked = sk_X509_REVOKED_num(revokedCerts);     int numRevoked = sk_X509_REVOKED_num(revokedCerts);
     Tracer::trace(TRC_SSL, Tracer::LEVEL4,      PEG_TRACE((TRC_SSL, Tracer::LEVEL4,
         "---> SSL: Number of certificates revoked by the issuer %d\n",         "---> SSL: Number of certificates revoked by the issuer %d\n",
         numRevoked);          numRevoked));
  
     //check whether the subject's certificate is revoked     //check whether the subject's certificate is revoked
     X509_REVOKED* revokedCert = NULL;     X509_REVOKED* revokedCert = NULL;
Line 294 
Line 292 
         //a matching serial number indicates revocation         //a matching serial number indicates revocation
         if (ASN1_INTEGER_cmp(revokedCert->serialNumber, serialNumber) == 0)         if (ASN1_INTEGER_cmp(revokedCert->serialNumber, serialNumber) == 0)
         {         {
             PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2,              PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL2,
                 "---> SSL: Certificate is revoked");                 "---> SSL: Certificate is revoked");
             X509_STORE_CTX_set_error(ctx, X509_V_ERR_CERT_REVOKED);             X509_STORE_CTX_set_error(ctx, X509_V_ERR_CERT_REVOKED);
             PEG_METHOD_EXIT();             PEG_METHOD_EXIT();
Line 302 
Line 300 
         }         }
     }     }
  
     PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4,      PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL4,
         "---> SSL: Certificate is not revoked at this level");         "---> SSL: Certificate is not revoked at this level");
  
     PEG_METHOD_EXIT();     PEG_METHOD_EXIT();
Line 326 
Line 324 
     int    verifyError = X509_V_OK;     int    verifyError = X509_V_OK;
     int    revoked = -1;     int    revoked = -1;
  
     Tracer::trace(TRC_SSL, Tracer::LEVEL4,      PEG_TRACE((TRC_SSL, Tracer::LEVEL4,
         "--->SSL: Preverify Error %d", verifyError);          "--->SSL: Preverify Error %d", verifyError));
  
     //     //
     // get the verification callback info specific to each SSL connection     // get the verification callback info specific to each SSL connection
Line 345 
Line 343 
     {     {
         revoked = verificationCRLCallback(         revoked = verificationCRLCallback(
             preVerifyOk,ctx,exData->_rep->crlStore);             preVerifyOk,ctx,exData->_rep->crlStore);
         Tracer::trace(TRC_SSL, Tracer::LEVEL4,          PEG_TRACE((TRC_SSL, Tracer::LEVEL4,
             "---> SSL: CRL callback returned %d", revoked);              "---> SSL: CRL callback returned %d", revoked));
  
         if (revoked) //with the SSL callbacks '0' indicates failure         if (revoked) //with the SSL callbacks '0' indicates failure
         {         {
Line 355 
Line 353 
         }         }
     }     }
  
     Tracer::trace(TRC_SSL, Tracer::LEVEL4,      PEG_TRACE((TRC_SSL, Tracer::LEVEL4,
         "---> SSL: CRL callback returned %d", revoked);          "---> SSL: CRL callback returned %d", revoked));
 #endif #endif
  
     //     //
Line 383 
Line 381 
     // get the serial number of the certificate     // get the serial number of the certificate
     //     //
     long serialNumber = ASN1_INTEGER_get(X509_get_serialNumber(currentCert));     long serialNumber = ASN1_INTEGER_get(X509_get_serialNumber(currentCert));
       char serialNumberString[32];
       sprintf(serialNumberString, "%lu", serialNumber);
  
     //     //
     // get the validity of the certificate     // get the validity of the certificate
Line 407 
Line 407 
     //     //
     if (!preVerifyOk)     if (!preVerifyOk)
     {     {
         Tracer::trace(TRC_SSL, Tracer::LEVEL4,          PEG_TRACE((TRC_SSL, Tracer::LEVEL4,
             "---> SSL: certificate default verification error: %s",             "---> SSL: certificate default verification error: %s",
             (const char*)errorStr.getCString());              (const char*)errorStr.getCString()));
     }     }
  
     //     //
Line 428 
Line 428 
         subjectName, issuerName, version, serialNumber,         subjectName, issuerName, version, serialNumber,
         notBefore, notAfter, depth, errorCode, errorStr, preVerifyOk));         notBefore, notAfter, depth, errorCode, errorStr, preVerifyOk));
  
     PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL3, "Created SSLCertificateInfo");      PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL3, "Created SSLCertificateInfo");
  
     // NOT_YET_VALID checks do not work correctly on subsequent tries --     // NOT_YET_VALID checks do not work correctly on subsequent tries --
     // Bugzilla#4283     // Bugzilla#4283
Line 438 
Line 438 
         (CIMDateTime::getDifference(         (CIMDateTime::getDifference(
              CIMDateTime::getCurrentDateTime(), notBefore) > 0))              CIMDateTime::getCurrentDateTime(), notBefore) > 0))
     {     {
         PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4,          PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL4,
             "Certificate was not yet valid.");             "Certificate was not yet valid.");
   
         X509_STORE_CTX_set_error(ctx, X509_V_ERR_CERT_NOT_YET_VALID);         X509_STORE_CTX_set_error(ctx, X509_V_ERR_CERT_NOT_YET_VALID);
   
           PEG_AUDIT_LOG(logCertificateBasedAuthentication(
               issuerName,
               subjectName,
               serialNumberString,
               exData->_rep->ipAddress,
               false));
     }     }
  
     //     //
Line 455 
Line 463 
     //     //
     if (exData->_rep->verifyCertificateCallback == NULL)     if (exData->_rep->verifyCertificateCallback == NULL)
     {     {
         return preVerifyOk;          PEG_AUDIT_LOG(logCertificateBasedAuthentication(
               issuerName,
               subjectName,
               serialNumberString,
               exData->_rep->ipAddress,
               preVerifyOk));
  
           return preVerifyOk;
     }     }
     else     else
     {     {
         if (exData->_rep->verifyCertificateCallback(         if (exData->_rep->verifyCertificateCallback(
                 *exData->_rep->peerCertificate[0]))                 *exData->_rep->peerCertificate[0]))
         {         {
             Tracer::trace(TRC_SSL, Tracer::LEVEL4,              PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL4,
                 "--> SSL: _rep->verifyCertificateCallback() returned "                 "--> SSL: _rep->verifyCertificateCallback() returned "
                     "X509_V_OK");                     "X509_V_OK");
  
               PEG_AUDIT_LOG(logCertificateBasedAuthentication(
                    issuerName,
                    subjectName,
                    serialNumberString,
                    exData->_rep->ipAddress,
                    true));
   
             PEG_METHOD_EXIT();             PEG_METHOD_EXIT();
             return 1;             return 1;
         }         }
         else // verification failed, handshake will be immediately terminated         else // verification failed, handshake will be immediately terminated
         {         {
             Tracer::trace(TRC_SSL, Tracer::LEVEL4,              PEG_TRACE((TRC_SSL, Tracer::LEVEL4,
                 "--> SSL: _rep->verifyCertificateCallback() returned error %d",                 "--> SSL: _rep->verifyCertificateCallback() returned error %d",
                 exData->_rep->peerCertificate[0]->getErrorCode());                  exData->_rep->peerCertificate[0]->getErrorCode()));
   
               PEG_AUDIT_LOG(logCertificateBasedAuthentication(
                    issuerName,
                    subjectName,
                    serialNumberString,
                    exData->_rep->ipAddress,
                    false));
  
             PEG_METHOD_EXIT();             PEG_METHOD_EXIT();
             return 0;             return 0;
Line 506 
Line 534 
  
     if ( mode & CRYPTO_LOCK )     if ( mode & CRYPTO_LOCK )
     {     {
         /*Tracer::trace(TRC_SSL, Tracer::LEVEL4,          /*PEG_TRACE((TRC_SSL, Tracer::LEVEL4,
                 "Now locking for %d", Threads::id());*/                  "Now locking for type %d", type));*/
         SSLContextRep::_sslLocks.get()[type].lock( );         SSLContextRep::_sslLocks.get()[type].lock( );
     }     }
     else     else
     {     {
         /*Tracer::trace(TRC_SSL, Tracer::LEVEL4,          /*PEG_TRACE((TRC_SSL, Tracer::LEVEL4,
                 "Now unlocking for %d", Threads::id());*/                  "Now unlocking for type %d", type));*/
         SSLContextRep::_sslLocks.get()[type].unlock( );         SSLContextRep::_sslLocks.get()[type].unlock( );
     }     }
 } }
Line 525 
Line 553 
 { {
      // Allocate Memory for _sslLocks. SSL locks needs to be able to handle      // Allocate Memory for _sslLocks. SSL locks needs to be able to handle
      // up to CRYPTO_num_locks() different mutex locks.      // up to CRYPTO_num_locks() different mutex locks.
      PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4,       PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL4,
            "Initialized SSL callback.");            "Initialized SSL callback.");
  
 #ifdef PEGASUS_OS_OS400  
      // Load the OpenSSL library and get the exports  
      SSL_OS400_Init();  
 #endif  
   
      _sslLocks.reset(new Mutex[CRYPTO_num_locks()]);      _sslLocks.reset(new Mutex[CRYPTO_num_locks()]);
  
 #if defined(PEGASUS_HAVE_PTHREADS) && !defined(PEGASUS_OS_VMS) #if defined(PEGASUS_HAVE_PTHREADS) && !defined(PEGASUS_OS_VMS)
Line 554 
Line 577 
  
     CRYPTO_set_locking_callback(NULL);     CRYPTO_set_locking_callback(NULL);
     CRYPTO_set_id_callback     (NULL);     CRYPTO_set_id_callback     (NULL);
     PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4,      PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL4,
              "Freed SSL callback.");              "Freed SSL callback.");
     _sslLocks.reset();     _sslLocks.reset();
 } }
Line 607 
Line 630 
     {     {
        AutoMutex autoMut(_countRepMutex);        AutoMutex autoMut(_countRepMutex);
  
        Tracer::trace(TRC_SSL, Tracer::LEVEL4,         PEG_TRACE((TRC_SSL, Tracer::LEVEL4,
                 "Value of Countrep in constructor %d", _countRep);                  "Value of Countrep in constructor %d", _countRep));
         if ( _countRep == 0 )         if ( _countRep == 0 )
         {         {
             init_ssl();             init_ssl();
Line 616 
Line 639 
             //             //
             // load SSL library             // load SSL library
             //             //
             Tracer::trace(TRC_SSL, Tracer::LEVEL4,              PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL4,
                 "Before calling SSL_load_error_strings %d", Threads::id());                  "Before calling SSL_load_error_strings");
  
             SSL_load_error_strings();             SSL_load_error_strings();
  
             Tracer::trace(TRC_SSL, Tracer::LEVEL4,              PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL4,
                 "After calling SSL_load_error_strings %d", Threads::id());                  "After calling SSL_load_error_strings");
  
             Tracer::trace(TRC_SSL, Tracer::LEVEL4,              PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL4,
                 "Before calling SSL_library_init %d", Threads::id());                  "Before calling SSL_library_init");
  
             SSL_library_init();             SSL_library_init();
  
             Tracer::trace(TRC_SSL, Tracer::LEVEL4,              PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL4,
                 "After calling SSL_library_init %d", Threads::id());                  "After calling SSL_library_init");
         }         }
  
         _countRep++;         _countRep++;
Line 659 
Line 682 
     // Initialize SSL callbacks and increment the SSLContextRep object _counter.     // Initialize SSL callbacks and increment the SSLContextRep object _counter.
     {     {
         AutoMutex autoMut(_countRepMutex);         AutoMutex autoMut(_countRepMutex);
         Tracer::trace(TRC_SSL, Tracer::LEVEL4,          PEG_TRACE((TRC_SSL, Tracer::LEVEL4,
             "Value of Countrep in copy constructor %d", _countRep);              "Value of Countrep in copy constructor %d", _countRep));
         if ( _countRep == 0 )         if ( _countRep == 0 )
         {         {
             init_ssl();             init_ssl();
Line 689 
Line 712 
         _countRep--;         _countRep--;
         // Free SSL locks if no instances of SSLContextRep exist.         // Free SSL locks if no instances of SSLContextRep exist.
  
         Tracer::trace(TRC_SSL, Tracer::LEVEL4,          PEG_TRACE((TRC_SSL, Tracer::LEVEL4,
             "Value of Countrep in destructor %d", _countRep);              "Value of Countrep in destructor %d", _countRep));
         if ( _countRep == 0 )         if ( _countRep == 0 )
         {         {
             free_ssl();             free_ssl();
Line 710 
Line 733 
     Boolean ret;     Boolean ret;
     int retVal = 0;     int retVal = 0;
  
 #ifdef PEGASUS_SSL_RANDOMFILE  #if defined(PEGASUS_SSL_RANDOMFILE) && !defined(PEGASUS_OS_PASE)
     if ( RAND_status() == 0 )     if ( RAND_status() == 0 )
     {     {
         //         //
Line 718 
Line 741 
         //         //
         if ( randomFile == String::EMPTY )         if ( randomFile == String::EMPTY )
         {         {
             PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4,              PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL4,
                 "Random seed file is required.");                 "Random seed file is required.");
             PEG_METHOD_EXIT();             PEG_METHOD_EXIT();
             MessageLoaderParms parms(             MessageLoaderParms parms(
Line 737 
Line 760 
             if ( retVal < 0 )             if ( retVal < 0 )
             {             {
                 PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4,                 PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4,
                     "Not enough seed data in seed file: " + randomFile);                      String("Not enough seed data in seed file: ") + randomFile);
                 PEG_METHOD_EXIT();                 PEG_METHOD_EXIT();
                 // do not put in $0 in default message, but pass in filename                 // do not put in $0 in default message, but pass in filename
                 // for bundle message                 // for bundle message
Line 751 
Line 774 
         else         else
         {         {
             PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4,             PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4,
                 "seed file - " + randomFile + " does not exist.");                  String("seed file - " + randomFile + " does not exist."));
             PEG_METHOD_EXIT();             PEG_METHOD_EXIT();
             MessageLoaderParms parms(             MessageLoaderParms parms(
                 "Common.SSLContext.SEED_FILE_DOES_NOT_EXIST",                 "Common.SSLContext.SEED_FILE_DOES_NOT_EXIST",
Line 778 
Line 801 
             int  seedRet = RAND_status();             int  seedRet = RAND_status();
             if ( seedRet == 0 )             if ( seedRet == 0 )
             {             {
                 PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4,                  PEG_TRACE((TRC_SSL, Tracer::LEVEL4,
                     "Not enough seed data in random seed file, RAND_status = " +                      "Not enough seed data in random seed file, "
                     seedRet);                          "RAND_status = %d",
                       seedRet));
                 PEG_METHOD_EXIT();                 PEG_METHOD_EXIT();
                 // do not put in $0 in default message, but pass in filename                 // do not put in $0 in default message, but pass in filename
                 // for bundle message                 // for bundle message
Line 797 
Line 821 
     int seedRet = RAND_status();     int seedRet = RAND_status();
     if (seedRet == 0)     if (seedRet == 0)
     {     {
         PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4,  // pase for different logic
             "Not enough seed data , RAND_status = " + seedRet );  #ifdef PEGASUS_OS_PASE
           unsigned char prn[1024];
   
           umeGenerateRandomNumber(prn);
   
           RAND_seed(prn, 1024);
   
           if (RAND_status() == 0)
           {
   #endif
           PEG_TRACE((TRC_SSL, Tracer::LEVEL4,
               "Not enough seed data, RAND_status = %d",
               seedRet));
         PEG_METHOD_EXIT();         PEG_METHOD_EXIT();
         MessageLoaderParms parms(         MessageLoaderParms parms(
             "Common.SSLContext.NOT_ENOUGH_SEED_DATA",             "Common.SSLContext.NOT_ENOUGH_SEED_DATA",
             "Not enough seed data.");             "Not enough seed data.");
         throw SSLException(parms);         throw SSLException(parms);
   #ifdef PEGASUS_OS_PASE
           }
   #endif
     }     }
  
     PEG_METHOD_EXIT();     PEG_METHOD_EXIT();
Line 865 
Line 904 
  
         if (_certificateVerifyFunction != NULL)         if (_certificateVerifyFunction != NULL)
         {         {
             PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL3,              PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL3,
                 "---> SSL: certificate verification callback specified");                 "---> SSL: certificate verification callback specified");
             SSL_CTX_set_verify(sslContext,             SSL_CTX_set_verify(sslContext,
                 SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE, prepareForCallback);                 SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE, prepareForCallback);
         }         }
         else         else
         {         {
             PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL3,              PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL3,
                 "---> SSL: Trust Store specified");                 "---> SSL: Trust Store specified");
             SSL_CTX_set_verify(sslContext,             SSL_CTX_set_verify(sslContext,
                 SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE |                 SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE |
Line 882 
Line 921 
     }     }
     else     else
     {     {
         PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL3,          PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL3,
             "---> SSL: Trust Store and certificate verification callback "             "---> SSL: Trust Store and certificate verification callback "
                 "are NOT specified");                 "are NOT specified");
         SSL_CTX_set_verify(sslContext, SSL_VERIFY_NONE, NULL);         SSL_CTX_set_verify(sslContext, SSL_VERIFY_NONE, NULL);
Line 905 
Line 944 
         //         //
         if (FileSystem::isDirectory(_trustStore))         if (FileSystem::isDirectory(_trustStore))
         {         {
             PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL3,              PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL3,
                             "---> SSL: Truststore is a directory");                             "---> SSL: Truststore is a directory");
             //             //
             // load certificates from the trust store             // load certificates from the trust store
             //             //
             PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2,             PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2,
                 "---> SSL: Loading certificates from the trust store: " +                  String("---> SSL: Loading certificates from the trust store: " +
                     _trustStore);                      _trustStore));
  
             if ((!SSL_CTX_load_verify_locations(             if ((!SSL_CTX_load_verify_locations(
                      sslContext, NULL, _trustStore.getCString())) ||                      sslContext, NULL, _trustStore.getCString())) ||
                 (!SSL_CTX_set_default_verify_paths(sslContext)))                 (!SSL_CTX_set_default_verify_paths(sslContext)))
             {             {
                 PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2,                 PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2,
                     "---> SSL: Could not load certificates from the trust "                      String("---> SSL: Could not load certificates from the "
                         "store: " + _trustStore);                          "trust store: " + _trustStore));
                 MessageLoaderParms parms(                 MessageLoaderParms parms(
                     "Common.SSLContext.COULD_NOT_LOAD_CERTIFICATES",                     "Common.SSLContext.COULD_NOT_LOAD_CERTIFICATES",
                     "Could not load certificates in to trust store.");                     "Could not load certificates in to trust store.");
Line 931 
Line 970 
         }         }
         else if (FileSystem::exists(_trustStore))         else if (FileSystem::exists(_trustStore))
         {         {
             PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL3,              PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL3,
                 "---> SSL: Truststore is a file");                 "---> SSL: Truststore is a file");
             //             //
             // Get size of the trust store file:             // Get size of the trust store file:
Line 946 
Line 985 
                 // load certificates from the trust store                 // load certificates from the trust store
                 //                 //
                 PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2,                 PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2,
                     "---> SSL: Loading certificates from the trust store: " +                      String("---> SSL: Loading certificates from the trust "
                         _trustStore);                          "store: " + _trustStore));
  
                 if ((!SSL_CTX_load_verify_locations(                 if ((!SSL_CTX_load_verify_locations(
                          sslContext, _trustStore.getCString(), NULL)) ||                          sslContext, _trustStore.getCString(), NULL)) ||
                     (!SSL_CTX_set_default_verify_paths(sslContext)))                     (!SSL_CTX_set_default_verify_paths(sslContext)))
                 {                 {
                     PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2,                     PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2,
                         "---> SSL: Could not load certificates from the "                          String("---> SSL: Could not load certificates from the "
                             "trust store: " + _trustStore);                              "trust store: " + _trustStore));
                     MessageLoaderParms parms(                     MessageLoaderParms parms(
                         "Common.SSLContext.COULD_NOT_LOAD_CERTIFICATES",                         "Common.SSLContext.COULD_NOT_LOAD_CERTIFICATES",
                         "Could not load certificates in to trust store.");                         "Could not load certificates in to trust store.");
Line 969 
Line 1008 
                 // no certificates found in the trust store                 // no certificates found in the trust store
                 //                 //
                 PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2,                 PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2,
                     "---> SSL: No certificates to load from the trust "                      String("---> SSL: No certificates to load from the trust "
                         "store: " + _trustStore);                          "store: " + _trustStore));
             }             }
         }         }
     }     }
Line 987 
Line 1026 
         // during server startup         // during server startup
         if (FileSystem::isDirectory(_crlPath))         if (FileSystem::isDirectory(_crlPath))
         {         {
             Tracer::trace(TRC_SSL, Tracer::LEVEL3,              PEG_TRACE((TRC_SSL, Tracer::LEVEL3,
                 "---> SSL: CRL store is a directory in %s",                 "---> SSL: CRL store is a directory in %s",
                 (const char*)_crlPath.getCString());                  (const char*)_crlPath.getCString()));
  
             if ((pLookup = X509_STORE_add_lookup(             if ((pLookup = X509_STORE_add_lookup(
                      _crlStore, X509_LOOKUP_hash_dir())) == NULL)                      _crlStore, X509_LOOKUP_hash_dir())) == NULL)
Line 1005 
Line 1044 
             X509_LOOKUP_add_dir(             X509_LOOKUP_add_dir(
                 pLookup, (const char*)_crlPath.getCString(), X509_FILETYPE_PEM);                 pLookup, (const char*)_crlPath.getCString(), X509_FILETYPE_PEM);
  
             PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL3,              PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL3,
                 "---> SSL: Successfully configured CRL directory");                 "---> SSL: Successfully configured CRL directory");
         }         }
         else         else
         {         {
             Tracer::trace(TRC_SSL, Tracer::LEVEL3,              PEG_TRACE((TRC_SSL, Tracer::LEVEL3,
                 "---> SSL: CRL store is the file %s",                 "---> SSL: CRL store is the file %s",
                 (const char*)_crlPath.getCString());                  (const char*)_crlPath.getCString()));
  
             if ((pLookup = X509_STORE_add_lookup(             if ((pLookup = X509_STORE_add_lookup(
                    _crlStore, X509_LOOKUP_file())) == NULL)                    _crlStore, X509_LOOKUP_file())) == NULL)
Line 1028 
Line 1067 
             X509_LOOKUP_load_file(             X509_LOOKUP_load_file(
                 pLookup, (const char*)_crlPath.getCString(), X509_FILETYPE_PEM);                 pLookup, (const char*)_crlPath.getCString(), X509_FILETYPE_PEM);
  
             PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL3,              PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL3,
                 "---> SSL: Successfully configured CRL file");                 "---> SSL: Successfully configured CRL file");
         }         }
     }     }
Line 1046 
Line 1085 
         // load the specified server certificates         // load the specified server certificates
         //         //
         PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2,         PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2,
             "---> SSL: Loading server certificate from: " + _certPath);              String("---> SSL: Loading server certificate from: " + _certPath));
  
         if (SSL_CTX_use_certificate_file(sslContext,         if (SSL_CTX_use_certificate_file(sslContext,
             _certPath.getCString(), SSL_FILETYPE_PEM) <=0)             _certPath.getCString(), SSL_FILETYPE_PEM) <=0)
         {         {
             PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2,             PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2,
                 "---> SSL: No server certificate found in " + _certPath);                  String("---> SSL: No server certificate found in " +
                       _certPath));
             MessageLoaderParms parms(             MessageLoaderParms parms(
                 "Common.SSLContext.COULD_NOT_GET_SERVER_CERTIFICATE",                 "Common.SSLContext.COULD_NOT_GET_SERVER_CERTIFICATE",
                 "Could not get server certificate.");                 "Could not get server certificate.");
Line 1070 
Line 1110 
         if (_keyPath == String::EMPTY)         if (_keyPath == String::EMPTY)
         {         {
             PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2,             PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2,
                 "---> SSL: loading private key from: " + _certPath);                  String("---> SSL: loading private key from: " + _certPath));
             //             //
             // load the private key and check for validity             // load the private key and check for validity
             //             //
Line 1094 
Line 1134 
     if (_keyPath != String::EMPTY && !keyLoaded)     if (_keyPath != String::EMPTY && !keyLoaded)
     {     {
         PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2,         PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2,
             "---> SSL: loading private key from: " + _keyPath);              String("---> SSL: loading private key from: " + _keyPath));
         //         //
         // load given private key and check for validity         // load given private key and check for validity
         //         //
Line 1117 
Line 1157 
 { {
     PEG_METHOD_ENTER(TRC_SSL, "_verifyPrivateKey()");     PEG_METHOD_ENTER(TRC_SSL, "_verifyPrivateKey()");
  
     if (SSL_CTX_use_PrivateKey_file(      // Open the private key file.
             ctx, keyPath.getCString(), SSL_FILETYPE_PEM) <= 0)  
       FILE* is = Executor::openFile(keyPath.getCString(), 'r');
   
       if (!is)
       {
           PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2,
               String("failed to open private key file: " + keyPath));
           return false;
       }
   
       // Read the private key from the input stream.
   
       EVP_PKEY* pkey;
       pkey = PEM_read_PrivateKey(is, NULL, NULL, NULL);
   
       if (!pkey)
       {
           PEG_TRACE_CSTRING(
               TRC_SSL, Tracer::LEVEL2, "failed to create private key");
           return false;
       }
   
       // Close the input stream.
   
       fclose(is);
   
       // Associate the new private key with the SSL context object.
   
       if (SSL_CTX_use_PrivateKey(ctx, pkey) <= 0)
     {     {
         PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2,         PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2,
             "---> SSL: no private key found in " + String(keyPath));              String("---> SSL: no private key found in " + keyPath));
         PEG_METHOD_EXIT();         PEG_METHOD_EXIT();
         return false;         return false;
     }     }
  
       // Check private key for validity.
   
     if (!SSL_CTX_check_private_key(ctx))     if (!SSL_CTX_check_private_key(ctx))
     {     {
         PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2,          PEG_TRACE_CSTRING(TRC_SSL, Tracer::LEVEL2,
             "---> SSL: Private and public key do not match");             "---> SSL: Private and public key do not match");
         PEG_METHOD_EXIT();         PEG_METHOD_EXIT();
         return false;         return false;
Line 1651 
Line 1721 
     _rep->crlStore = crlStore;     _rep->crlStore = crlStore;
 } }
  
   SSLCallbackInfo::SSLCallbackInfo(
       SSLCertificateVerifyFunction* verifyCert,
       X509_STORE* crlStore,
       String ipAddress)
   {
       _rep = new SSLCallbackInfoRep();
       _rep->verifyCertificateCallback = verifyCert;
       _rep->crlStore = crlStore;
       _rep->ipAddress = ipAddress;
   }
   
 SSLCallbackInfo::~SSLCallbackInfo() SSLCallbackInfo::~SSLCallbackInfo()
 { {
     PEG_METHOD_ENTER(TRC_SSL, "SSLCallbackInfo::~SSLCallbackInfo");     PEG_METHOD_ENTER(TRC_SSL, "SSLCallbackInfo::~SSLCallbackInfo");


Legend:
Removed from v.1.76  
changed lines
  Added in v.1.84

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2