(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.28 and 1.48

version 1.28, 2004/06/09 20:49:35 version 1.48, 2005/03/08 23:19:31
Line 1 
Line 1 
 //%2003////////////////////////////////////////////////////////////////////////  //%2005////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001, 2002  BMC Software, Hewlett-Packard Development  // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.  // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.; // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
 // IBM Corp.; EMC Corporation, The Open Group. // IBM Corp.; EMC Corporation, The Open Group.
   // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
   // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
   // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
   // EMC Corporation; VERITAS Software Corporation; The Open Group.
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to // of this software and associated documentation files (the "Software"), to
Line 29 
Line 33 
 //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
 //              Sushma Fernandes, Hewlett-Packard Company (sushma_fernandes@hp.com) //              Sushma Fernandes, Hewlett-Packard Company (sushma_fernandes@hp.com)
 //              Heather Sterling, IBM (hsterl@us.ibm.com) //              Heather Sterling, IBM (hsterl@us.ibm.com)
   //              Amit K Arora, IBM (amita@in.ibm.com) for Bug#1090
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #ifdef PEGASUS_HAS_SSL #ifdef PEGASUS_HAS_SSL
   
   #ifdef PEGASUS_PLATFORM_WIN32_IX86_MSVC
   //Bugzilla 2366
   //Use the X509_NAME in wincrypt.h on Windows.  See X509.h for more info.
   #include <windows.h>
   #include <wincrypt.h>
   #endif
   
 #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 46 
Line 59 
 #include <Pegasus/Common/FileSystem.h> #include <Pegasus/Common/FileSystem.h>
 #include <time.h> #include <time.h>
 #include <Pegasus/Common/MessageLoader.h> //l10n #include <Pegasus/Common/MessageLoader.h> //l10n
   #include <Pegasus/Common/Formatter.h>
  
 #include "SSLContext.h" #include "SSLContext.h"
 #include "SSLContextRep.h" #include "SSLContextRep.h"
  
   
   //
   // Typedef's for OpenSSL callback functions.
   //
   extern "C"
   {
       typedef void (* CRYPTO_SET_LOCKING_CALLBACK)(int, int, const char *, int);
       typedef unsigned long (* CRYPTO_SET_ID_CALLBACK)(void);
   };
   
   typedef struct x509_store_ctx_st X509_STORE_CTX;
   
 typedef struct Timestamp typedef struct Timestamp
 { {
     char year[4];     char year[4];
Line 69 
Line 95 
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
   const int SSLCallbackInfo::SSL_CALLBACK_INDEX = 0;
   
 // //
 // use the following definitions only if SSL is available // use the following definitions only if SSL is available
 // //
Line 94 
Line 122 
     Timestamp_t timeStamp;     Timestamp_t timeStamp;
     char tempString[80];     char tempString[80];
     char plusOrMinus = '+';     char plusOrMinus = '+';
       unsigned char* utcTimeData = utcTime->data;
  
     memset(&time, '\0', sizeof(time));     memset(&time, '\0', sizeof(time));
  
 #define g2(p) ( ( (p)[0] - '0' ) * 10 + (p)[1] - '0' ) #define g2(p) ( ( (p)[0] - '0' ) * 10 + (p)[1] - '0' )
  
     time.tm_year = g2(utcTime->data);      if (utcTime->type == V_ASN1_GENERALIZEDTIME)
       {
           time.tm_year = g2(utcTimeData) * 100;
           utcTimeData += 2;  // Remaining data is equivalent to ASN1_UTCTIME type
           time.tm_year += g2(utcTimeData);
       }
       else
       {
           time.tm_year = g2(utcTimeData);
     if(time.tm_year < 50)     if(time.tm_year < 50)
     {     {
         time.tm_year += 100;              time.tm_year += 2000;
     }     }
     time.tm_mon = g2(utcTime->data + 2) - 1;          else
     time.tm_mday = g2(utcTime->data + 4);          {
     time.tm_hour = g2(utcTime->data + 6);              time.tm_year += 1900;
     time.tm_min = g2(utcTime->data + 8);          }
     time.tm_sec = g2(utcTime->data + 10);      }
   
       time.tm_mon = g2(utcTimeData + 2) - 1;
       time.tm_mday = g2(utcTimeData + 4);
       time.tm_hour = g2(utcTimeData + 6);
       time.tm_min = g2(utcTimeData + 8);
       time.tm_sec = g2(utcTimeData + 10);
  
     if(utcTime->data[12] == 'Z')      if (utcTimeData[12] == 'Z')
     {     {
         offset = 0;         offset = 0;
     }     }
     else     else
     {     {
         offset = g2(utcTime->data + 13) * 60 + g2(utcTime->data + 15);          offset = g2(utcTimeData + 13) * 60 + g2(utcTimeData + 15);
         if(utcTime->data[12] == '-')          if (utcTimeData[12] == '-')
         {         {
             plusOrMinus = '-';             plusOrMinus = '-';
         }         }
     }     }
 #undef g2 #undef g2
  
     int year = 1900;  
     memset((void *)&timeStamp, 0, sizeof(Timestamp_t));     memset((void *)&timeStamp, 0, sizeof(Timestamp_t));
  
     // Format the date.     // Format the date.
     sprintf((char *) &timeStamp,"%04d%02d%02d%02d%02d%02d.%06d%04d",     sprintf((char *) &timeStamp,"%04d%02d%02d%02d%02d%02d.%06d%04d",
             year + time.tm_year,              time.tm_year,
             time.tm_mon + 1,             time.tm_mon + 1,
             time.tm_mday,             time.tm_mday,
             time.tm_hour,             time.tm_hour,
Line 151 
Line 192 
 } }
  
 // //
   // Static class used to define C++ callback functions for OpenSSL.
   //
   class SSLCallback
   {
   
   public:
       static int verificationCallback(int preVerifyOk, X509_STORE_CTX *ctx);
       static int verificationCRLCallback(int ok, X509_STORE_CTX *ctx, X509_STORE* sslCRLStore);
   };
   
   //
   // Callback function that is called by the OpenSSL library. This function
   // checks whether the certificate is listed in any of the CRL's
   //
   // return 1 if revoked, 0 otherwise
   //
   int SSLCallback::verificationCRLCallback(int ok, X509_STORE_CTX *ctx, X509_STORE* sslCRLStore)
   {
       PEG_METHOD_ENTER(TRC_SSL, "SSLCallback::verificationCRLCallback");
   
       char buf[1024];
   
       //check whether a CRL store was specified
       if (sslCRLStore == NULL)
       {
           PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL3, "---> SSL: CRL store is NULL");
           return 0;
       }
   
       //get the current certificate info
       X509* currentCert;
       X509_NAME* issuerName;
       X509_NAME* subjectName;
       ASN1_INTEGER* serialNumber;
   
       currentCert = X509_STORE_CTX_get_current_cert(ctx);
       subjectName = X509_get_subject_name(currentCert);
       issuerName = X509_get_issuer_name(currentCert);
       serialNumber = X509_get_serialNumber(currentCert);
   
       //log certificate information
       //this is information in the "public" key, so it does no harm to log it
       X509_NAME_oneline(issuerName, buf, sizeof(buf));
       PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4, "---> SSL: Certificate Data: Issuer/Subject");
       PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4, buf);
       X509_NAME_oneline(subjectName, buf, sizeof(buf));
       PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4, buf);
   
       //initialize the CRL store
       X509_STORE_CTX crlStoreCtx;
       X509_STORE_CTX_init(&crlStoreCtx, sslCRLStore, NULL, NULL);
   
       PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4, "---> SSL: Initialized CRL store");
   
       //attempt to get a CRL issued by the certificate's issuer
       X509_OBJECT obj;
       if (X509_STORE_get_by_subject(&crlStoreCtx, X509_LU_CRL, issuerName, &obj) <= 0)
       {
           PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL3, "---> SSL: No CRL by that issuer");
           return 0;
       }
       X509_STORE_CTX_cleanup(&crlStoreCtx);
   
       //get CRL
       X509_CRL* crl = obj.data.crl;
       if (crl == NULL)
       {
           PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4, "---> SSL: CRL is null");
           return 0;
       } else
       {
           PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4, "---> SSL: Found CRL by that issuer");
       }
   
       //get revoked certificates
       STACK_OF(X509_REVOKED)* revokedCerts = NULL;
       revokedCerts = X509_CRL_get_REVOKED(crl);
       int numRevoked = sk_X509_REVOKED_num(revokedCerts);
       Tracer::trace(TRC_SSL, Tracer::LEVEL4,"---> SSL: Number of certificates revoked by the issuer %d\n", numRevoked);
   
       //check whether the subject's certificate is revoked
       X509_REVOKED* revokedCert = NULL;
       for (int i = 0; i < sk_X509_REVOKED_num(revokedCerts); i++)
       {
           revokedCert = (X509_REVOKED *)sk_value(X509_CRL_get_REVOKED(crl), i);
   
           //a matching serial number indicates revocation
           if (ASN1_INTEGER_cmp(revokedCert->serialNumber, serialNumber) == 0)
           {
               PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL2, "---> SSL: Certificate is revoked");
               X509_STORE_CTX_set_error(ctx, X509_V_ERR_CERT_REVOKED);
               return 1;
           }
       }
   
       PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4, "---> SSL: Certificate is not revoked at this level");
   
       PEG_METHOD_EXIT();
       return 0;
   }
   
   //
 // Callback function that is called by the OpenSSL library. This function // Callback function that is called by the OpenSSL library. This function
 // extracts X509 certficate information and pass that on to client application // extracts X509 certficate information and pass that on to client application
 // callback function. // callback function.
   // We HAVE to build the certificate in all cases since it's needed to get the associated username out of the repository
   // later in the transaction
 // //
 int prepareForCallback(int preVerifyOk, X509_STORE_CTX *ctx)  int SSLCallback::verificationCallback(int preVerifyOk, X509_STORE_CTX *ctx)
 { {
     PEG_METHOD_ENTER(TRC_SSL, "prepareForCallback()");      PEG_METHOD_ENTER(TRC_SSL, "SSLCallback::callback()");
  
     char   buf[256];     char   buf[256];
     X509   *currentCert;     X509   *currentCert;
     SSL    *ssl;     SSL    *ssl;
     int    verifyError = X509_V_OK;     int    verifyError = X509_V_OK;
       int    revoked = -1;
   
       Tracer::trace(TRC_SSL, Tracer::LEVEL4,
                     "--->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
     //     //
     ssl = (SSL*) X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx());     ssl = (SSL*) X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx());
     SSLCallbackInfo* exData = (SSLCallbackInfo*) SSL_get_ex_data(ssl, SSL_CALLBACK_INDEX);      SSLCallbackInfo* exData = (SSLCallbackInfo*) SSL_get_ex_data(ssl, SSLCallbackInfo::SSL_CALLBACK_INDEX);
  
     //     //
     // If the SSLContext does not have an additional callback     // If the SSLContext does not have an additional callback
     // simply return the preverification error.      // simply return the preverification error (or check the CRL)
     // We do not need to go through the additional steps.     // We do not need to go through the additional steps.
     //     //
     if (exData->verifyCertificateCallback == NULL)     if (exData->verifyCertificateCallback == NULL)
     {     {
         return (preVerifyOk);          Tracer::trace(TRC_SSL, Tracer::LEVEL4,
                         "--->SSL: No verification callback specified");
   
           if (exData->_crlStore != NULL)
           {
               revoked = verificationCRLCallback(preVerifyOk,ctx,exData->_crlStore);
               Tracer::trace(TRC_SSL, Tracer::LEVEL4, "---> SSL: CRL callback returned %d", revoked);
   
               if (revoked) //with the SSL callbacks '0' indicates failure
               {
                   PEG_METHOD_EXIT();
                   return 0;
               }
           }
       }
   
       //
       // Check to see if a CRL path is defined
       //
       if (exData->_crlStore != NULL)
       {
           revoked = verificationCRLCallback(preVerifyOk,ctx,exData->_crlStore);
           Tracer::trace(TRC_SSL, Tracer::LEVEL4, "---> SSL: CRL callback returned %d", revoked);
   
           if (revoked) //with the SSL callbacks '0' indicates failure
           {
               PEG_METHOD_EXIT();
               return 0;
     }     }
       }
   
       Tracer::trace(TRC_SSL, Tracer::LEVEL4, "---> SSL: CRL callback returned %d", revoked);
  
     //     //
     // get the current certificate     // get the current certificate
Line 228 
Line 407 
     //     //
     if (!preVerifyOk)     if (!preVerifyOk)
     {     {
         PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL4,          Tracer::trace(TRC_SSL, Tracer::LEVEL4,
             "---> SSL: certificate default verification error: " + errorStr);                        "---> SSL: certificate default verification error: %s", (const char*)errorStr.getCString());
     }     }
  
     //     //
Line 245 
Line 424 
     }     }
     String issuerName = String(buf);     String issuerName = String(buf);
  
 //    SSLCertificateInfo certInfo(subjectName, issuerName, version, serialNumber,      //
 //        notBefore, notAfter, depth, errorCode, errorStr, preVerifyOk);      // Create the certificate object
       //
     exData->_peerCertificate = new SSLCertificateInfo(subjectName, issuerName, version, serialNumber,     exData->_peerCertificate = new SSLCertificateInfo(subjectName, issuerName, version, serialNumber,
         notBefore, notAfter, depth, errorCode, errorStr, preVerifyOk);         notBefore, notAfter, depth, errorCode, errorStr, preVerifyOk);
  
Line 257 
Line 436 
     // This is because OpenSSL retains the original default error in case we want to use it later.     // This is because OpenSSL retains the original default error in case we want to use it later.
     // To set the error, we could use X509_STORE_CTX_set_error(ctx, verifyError); but there is no real benefit to doing that here.     // To set the error, we could use X509_STORE_CTX_set_error(ctx, verifyError); but there is no real benefit to doing that here.
     //     //
     if (exData->verifyCertificateCallback(*exData->_peerCertificate))//certInfo))      if (exData->verifyCertificateCallback(*exData->_peerCertificate))
     {     {
         Tracer::trace(TRC_SSL, Tracer::LEVEL4,         Tracer::trace(TRC_SSL, Tracer::LEVEL4,
             "--> SSL: verifyCertificateCallback() returned X509_V_OK");             "--> SSL: verifyCertificateCallback() returned X509_V_OK");
Line 276 
Line 455 
 } }
  
 // //
   // Callback function called by OpenSSL.  This request is merely forwarded to the static
   // function SSLCallback::callback().  The SSLCallback class is a friend class of the
   // Pegasus SSL related classes needed to complete the callback.
   //
   extern "C" int prepareForCallback(int preVerifyOk, X509_STORE_CTX *ctx)
   {
       return SSLCallback::verificationCallback(preVerifyOk, ctx);
   }
   
   //
 // Implement OpenSSL locking callback. // Implement OpenSSL locking callback.
 // //
 void pegasus_locking_callback( int              mode, void pegasus_locking_callback( int              mode,
Line 313 
Line 502 
  
      // Set the ID callback. The ID callback returns a thread ID.      // Set the ID callback. The ID callback returns a thread ID.
  
      CRYPTO_set_id_callback((unsigned long (*)())pegasus_thread_self);       CRYPTO_set_id_callback((CRYPTO_SET_ID_CALLBACK) pegasus_thread_self);
  
      // Set the locking callback to pegasus_locking_callback.      // Set the locking callback to pegasus_locking_callback.
  
      CRYPTO_set_locking_callback((void (*)(int,int,const char *,int))pegasus_locking_callback);       CRYPTO_set_locking_callback((CRYPTO_SET_LOCKING_CALLBACK) pegasus_locking_callback);
  
 } }
  
Line 341 
Line 530 
 // For the OSs that don't have /dev/random device file, // For the OSs that don't have /dev/random device file,
 // must enable PEGASUS_SSL_RANDOMFILE flag. // must enable PEGASUS_SSL_RANDOMFILE flag.
 // //
 SSLContextRep::SSLContextRep(const String& trustStore,  
                        const String& certPath,  
                        const String& keyPath,  
                        SSLCertificateVerifyFunction* verifyCert,  
                        const String& randomFile)  
 {  
     PEG_METHOD_ENTER(TRC_SSL, "SSLContextRep::SSLContextRep()");  
   
     _trustStore = trustStore;  
   
     _certPath = certPath;  
   
     _keyPath = keyPath;  
   
     _certificateVerifyFunction = verifyCert;  
   
         _trustStoreAutoUpdate = false;  
   
         _trustStoreUserName = String::EMPTY;  
   
     //  
     // If a truststore and/or peer verification function is specified, enable peer verification  
     //  
     if (trustStore != String::EMPTY || verifyCert != NULL)  
     {  
         _verifyPeer = true;  
     }  
     else  
     {  
         _verifyPeer = false;  
     }  
   
     //  
     // Initialize SSL callbacks and increment the SSLContextRep object _counter.  
     //  
     _countRepMutex.lock(pegasus_thread_self());  
   
     try  
     {  
         Tracer::trace(TRC_SSL, Tracer::LEVEL4,  
                 "Value of Countrep in constructor %d", _countRep);  
         if ( _countRep == 0 )  
         {  
             init_ssl();  
   
             //  
             // load SSL library  
             //  
             Tracer::trace(TRC_SSL, Tracer::LEVEL4,  
                 "Before calling SSL_load_error_strings %d", pegasus_thread_self());  
   
             SSL_load_error_strings();  
   
             Tracer::trace(TRC_SSL, Tracer::LEVEL4,  
                 "After calling SSL_load_error_strings %d", pegasus_thread_self());  
   
             Tracer::trace(TRC_SSL, Tracer::LEVEL4,  
                 "Before calling SSL_library_init %d", pegasus_thread_self());  
   
             SSL_library_init();  
   
             Tracer::trace(TRC_SSL, Tracer::LEVEL4,  
                 "After calling SSL_library_init %d", pegasus_thread_self());  
   
         }  
     }  
     catch(...)  
     {  
         _countRepMutex.unlock();  
         throw;  
     }  
     _countRep++;  
     _countRepMutex.unlock();  
   
     _randomInit(randomFile);  
   
     _sslContext = _makeSSLContext();  
   
     PEG_METHOD_EXIT();  
 }  
   
 #ifdef PEGASUS_USE_SSL_CLIENT_VERIFICATION  
 SSLContextRep::SSLContextRep( SSLContextRep::SSLContextRep(
                        const String& trustStore,                        const String& trustStore,
                        const String& certPath,                        const String& certPath,
                        const String& keyPath,                        const String& keyPath,
                          const String& crlPath,
                        SSLCertificateVerifyFunction* verifyCert,                        SSLCertificateVerifyFunction* verifyCert,
                        Boolean trustStoreAutoUpdate,  
                                            String trustStoreUserName,  
                        const String& randomFile)                        const String& randomFile)
 { {
     PEG_METHOD_ENTER(TRC_SSL, "SSLContextRep::SSLContextRep()");     PEG_METHOD_ENTER(TRC_SSL, "SSLContextRep::SSLContextRep()");
Line 440 
Line 546 
  
     _keyPath = keyPath;     _keyPath = keyPath;
  
     _certificateVerifyFunction = verifyCert;      _crlPath = crlPath;
  
     _trustStoreAutoUpdate = trustStoreAutoUpdate;      _crlStore = NULL;
  
         _trustStoreUserName = trustStoreUserName;      _certificateVerifyFunction = verifyCert;
  
     //     //
     // If a truststore and/or peer verification function is specified, enable peer verification     // If a truststore and/or peer verification function is specified, enable peer verification
Line 461 
Line 567 
     //     //
     // Initialiaze SSL callbacks and increment the SSLContextRep object _counter.     // Initialiaze SSL callbacks and increment the SSLContextRep object _counter.
     //     //
     _countRepMutex.lock(pegasus_thread_self());  
   
     try  
     {     {
          AutoMutex autoMut(_countRepMutex);
   
         Tracer::trace(TRC_SSL, Tracer::LEVEL4,         Tracer::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 )
Line 491 
Line 596 
                 "After calling SSL_library_init %d", pegasus_thread_self());                 "After calling SSL_library_init %d", pegasus_thread_self());
  
         }         }
     }  
     catch(...)  
     {  
         _countRepMutex.unlock();  
         throw;  
     }  
     _countRep++;     _countRep++;
     _countRepMutex.unlock();      }  // mutex unlocks here
  
     _randomInit(randomFile);     _randomInit(randomFile);
  
Line 506 
Line 606 
  
     PEG_METHOD_EXIT();     PEG_METHOD_EXIT();
 } }
 #endif  
  
 SSLContextRep::SSLContextRep(const SSLContextRep& sslContextRep) SSLContextRep::SSLContextRep(const SSLContextRep& sslContextRep)
 { {
Line 515 
Line 614 
     _trustStore = sslContextRep._trustStore;     _trustStore = sslContextRep._trustStore;
     _certPath = sslContextRep._certPath;     _certPath = sslContextRep._certPath;
     _keyPath = sslContextRep._keyPath;     _keyPath = sslContextRep._keyPath;
       _crlPath = sslContextRep._crlPath;
           _crlStore = sslContextRep._crlStore;
     _verifyPeer = sslContextRep._verifyPeer;     _verifyPeer = sslContextRep._verifyPeer;
     _trustStoreAutoUpdate = sslContextRep._trustStoreAutoUpdate;  
         _trustStoreUserName = sslContextRep._trustStoreUserName;  
     _certificateVerifyFunction = sslContextRep._certificateVerifyFunction;     _certificateVerifyFunction = sslContextRep._certificateVerifyFunction;
     _randomFile = sslContextRep._randomFile;     _randomFile = sslContextRep._randomFile;
  
     // Initialiaze SSL callbacks and increment the SSLContextRep object _counter.     // Initialiaze SSL callbacks and increment the SSLContextRep object _counter.
     _countRepMutex.lock(pegasus_thread_self());  
     try  
     {     {
           AutoMutex autoMut(_countRepMutex);
         Tracer::trace(TRC_SSL, Tracer::LEVEL4,         Tracer::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();
         }         }
     }  
     catch(...)  
     {  
         _countRepMutex.unlock();  
         throw;  
     }  
     _countRep++;     _countRep++;
     _countRepMutex.unlock();      }  // mutex unlocks here
  
     _sslContext = _makeSSLContext();     _sslContext = _makeSSLContext();
     PEG_METHOD_EXIT();     PEG_METHOD_EXIT();
Line 555 
Line 648 
     SSL_CTX_free(_sslContext);     SSL_CTX_free(_sslContext);
  
     // Decrement the SSLContextRep object _counter.     // Decrement the SSLContextRep object _counter.
     _countRepMutex.lock(pegasus_thread_self());      {
           AutoMutex autoMut(_countRepMutex);
     _countRep--;     _countRep--;
     // Free SSL locks if no instances of SSLContextRep exist.     // Free SSL locks if no instances of SSLContextRep exist.
     try  
     {  
         Tracer::trace(TRC_SSL, Tracer::LEVEL4,         Tracer::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();
         }         }
   
     }     }
     catch(...)  
     {  
         _countRepMutex.unlock();  
         throw;  
     }  
     _countRepMutex.unlock();  
     PEG_METHOD_EXIT();     PEG_METHOD_EXIT();
 } }
  
Line 586 
Line 674 
     Boolean ret;     Boolean ret;
     int retVal = 0;     int retVal = 0;
  
     const int DEV_RANDOM_BYTES = 64;            /* how many bytes to read */  
     const String devRandom = "/dev/random";     /* random device name */  
     const String devUrandom = "/dev/urandom";   /* pseudo-random device name */  
   
 #ifdef PEGASUS_SSL_DEVRANDOM  
   
     if ( FileSystem::exists(devRandom) )  
     {  
         while ( RAND_status() == 0 )  
         {  
             //  
             // Always attempt to seed from good entropy sources, first  
             // try /dev/random  
             //  
             retVal = RAND_load_file(devRandom.getCString(), DEV_RANDOM_BYTES);  
             if (retVal <= 0)  
             {  
                 break;  
             }  
         }  
     }  
   
     if ( FileSystem::exists(devUrandom) )  
     {  
         while ( RAND_status() == 0 )  
         {  
             //  
             // If there isn't /dev/random try /dev/urandom  
             //  
             retVal = RAND_load_file(devUrandom.getCString(), DEV_RANDOM_BYTES);  
             if (retVal <= 0)  
             {  
                 break;  
             }  
         }  
     }  
 #endif  /* PEGASUS_SSL_DEVRANDOM */  
   
   
 #ifdef PEGASUS_SSL_RANDOMFILE #ifdef PEGASUS_SSL_RANDOMFILE
     if ( RAND_status() == 0 )     if ( RAND_status() == 0 )
     {     {
Line 876 
Line 925 
         }         }
     }     }
  
       if (_crlPath != String::EMPTY)
       {
           //need to save this -- can we make it static since there's only one CRL for cimserver?
           X509_LOOKUP* pLookup;
   
           _crlStore = X509_STORE_new();
   
           //the validity of the crlstore was checked in ConfigManager during server startup
           if (FileSystem::isDirectory(_crlPath))
           {
               Tracer::trace(TRC_SSL, Tracer::LEVEL3,
                             "---> SSL: CRL store is a directory in %s", (const char*)_crlPath.getCString());
   
               if ((pLookup = X509_STORE_add_lookup(_crlStore, X509_LOOKUP_hash_dir())) == NULL)
               {
                   MessageLoaderParms parms("Common.SSLContext.COULD_NOT_LOAD_CRLS",
                                            "Could not load certificate revocation list.");
                   X509_STORE_free(_crlStore);
                   PEG_METHOD_EXIT();
                   throw SSLException(parms);
               }
   
               X509_LOOKUP_add_dir(pLookup, (const char*)_crlPath.getCString(), X509_FILETYPE_PEM);
   
               PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL3,
                               "---> SSL: Successfully configured CRL directory");
   
           } else
           {
               Tracer::trace(TRC_SSL, Tracer::LEVEL3,
                             "---> SSL: CRL store is the file %s", (const char*)_crlPath.getCString());
   
               if ((pLookup = X509_STORE_add_lookup(_crlStore, X509_LOOKUP_file())) == NULL)
               {
                   MessageLoaderParms parms("Common.SSLContext.COULD_NOT_LOAD_CRLS",
                                            "Could not load certificate revocation list.");
                   X509_STORE_free(_crlStore);
                   PEG_METHOD_EXIT();
                   throw SSLException(parms);
               }
   
               X509_LOOKUP_load_file(pLookup, (const char*)_crlPath.getCString(), X509_FILETYPE_PEM);
   
               PEG_TRACE_STRING(TRC_SSL, Tracer::LEVEL3,
                               "---> SSL: Successfully configured CRL file");
           }
       }
   
     Boolean keyLoaded = false;     Boolean keyLoaded = false;
  
     //     //
Line 996 
Line 1093 
     return _keyPath;     return _keyPath;
 } }
  
 Boolean SSLContextRep::isPeerVerificationEnabled() const  String SSLContextRep::getCRLPath() const
 { {
     return _verifyPeer;      return _crlPath;
 } }
  
 Boolean SSLContextRep::isTrustStoreAutoUpdateEnabled() const  X509_STORE* SSLContextRep::getCRLStore() const
 { {
     return _trustStoreAutoUpdate;      return _crlStore;
 } }
  
 String SSLContextRep::getTrustStoreUserName() const  Boolean SSLContextRep::isPeerVerificationEnabled() const
 { {
         return _trustStoreUserName;      return _verifyPeer;
 } }
  
 SSLCertificateVerifyFunction* SSLContextRep::getSSLCertificateVerifyFunction() const SSLCertificateVerifyFunction* SSLContextRep::getSSLCertificateVerifyFunction() const
Line 1025 
Line 1122 
 SSLContextRep::SSLContextRep(const String& trustStore, SSLContextRep::SSLContextRep(const String& trustStore,
                        const String& certPath,                        const String& certPath,
                        const String& keyPath,                        const String& keyPath,
                          const String& crlPath,
                        SSLCertificateVerifyFunction* verifyCert,                        SSLCertificateVerifyFunction* verifyCert,
                        const String& randomFile) {}                         const String& randomFile)
   {}
 #ifdef PEGASUS_USE_SSL_CLIENT_VERIFICATION  
 SSLContextRep::SSLContextRep(const String& trustStore,  
                        const String& certPath,  
                        const String& keyPath,  
                        SSLCertificateVerifyFunction* verifyCert,  
                        Boolean trustStoreAutoUpdate,  
                                            String trustStoreUserName,  
                        const String& randomFile) {}  
 #endif  
  
 SSLContextRep::SSLContextRep(const SSLContextRep& sslContextRep) {} SSLContextRep::SSLContextRep(const SSLContextRep& sslContextRep) {}
  
Line 1055 
Line 1144 
  
 String SSLContextRep::getKeyPath() const { return String::EMPTY; } String SSLContextRep::getKeyPath() const { return String::EMPTY; }
  
 Boolean SSLContextRep::isPeerVerificationEnabled() const { return false; }  String SSLContextRep::getCRLPath() const { return String::EMPTY; }
  
 Boolean SSLContextRep::isTrustStoreAutoUpdateEnabled() const { return false; }  X509_STORE* SSLContextRep::getCRLStore() const { return NULL; }
  
 String SSLContextRep::getTrustStoreUserName() const { return String::EMPTY; }  Boolean SSLContextRep::isPeerVerificationEnabled() const { return false; }
  
 SSLCertificateVerifyFunction* SSLContextRep::getSSLCertificateVerifyFunction() const { return NULL; } SSLCertificateVerifyFunction* SSLContextRep::getSSLCertificateVerifyFunction() const { return NULL; }
  
Line 1081 
Line 1170 
     SSLCertificateVerifyFunction* verifyCert,     SSLCertificateVerifyFunction* verifyCert,
     const String& randomFile)     const String& randomFile)
 { {
 #ifdef PEGASUS_USE_SSL_CLIENT_VERIFICATION      _rep = new SSLContextRep(trustStore, String::EMPTY, String::EMPTY, String::EMPTY, verifyCert, randomFile);
     _rep = new SSLContextRep(trustStore, String::EMPTY, String::EMPTY,  verifyCert, false, String::EMPTY, randomFile);  
 #else  
     _rep = new SSLContextRep(trustStore, String::EMPTY, String::EMPTY,  verifyCert, randomFile);  
 #endif  
 }  
   
 #ifdef PEGASUS_USE_DEPRECATED_INTERFACES  
 SSLContext::SSLContext(  
     const String& certPath,  
     SSLCertificateVerifyFunction* verifyCert,  
     const String& randomFile,  
     Boolean isCIMClient)  
 {  
 #ifdef PEGASUS_USE_SSL_CLIENT_VERIFICATION  
     _rep = new SSLContextRep(certPath, String::EMPTY, String::EMPTY,  verifyCert, false, String::EMPTY, randomFile);  
 #else  
     _rep = new SSLContextRep(certPath, String::EMPTY, String::EMPTY,  verifyCert, randomFile);  
 #endif  
 }  
   
 SSLContext::SSLContext(  
     const String& certPath,  
     const String& certKeyPath,  
     SSLCertificateVerifyFunction* verifyCert,  
     const String& randomFile)  
 {  
 #ifdef PEGASUS_USE_SSL_CLIENT_VERIFICATION  
     _rep = new SSLContextRep(certPath, certKeyPath, String::EMPTY, verifyCert, false, String::EMPTY, randomFile);  
 #else  
     _rep = new SSLContextRep(certPath, certKeyPath, String::EMPTY, verifyCert, randomFile);  
 #endif  
 } }
 #endif  
  
 SSLContext::SSLContext( SSLContext::SSLContext(
     const String& trustStore,     const String& trustStore,
Line 1123 
Line 1180 
     SSLCertificateVerifyFunction* verifyCert,     SSLCertificateVerifyFunction* verifyCert,
     const String& randomFile)     const String& randomFile)
 { {
 #ifdef PEGASUS_USE_SSL_CLIENT_VERIFICATION      _rep = new SSLContextRep(trustStore, certPath, keyPath, String::EMPTY, verifyCert, randomFile);
     _rep = new SSLContextRep(trustStore, certPath, keyPath, verifyCert, false, String::EMPTY, randomFile);  
 #else  
     _rep = new SSLContextRep(trustStore, certPath, keyPath, verifyCert, randomFile);  
 #endif  
 } }
  
 #ifdef PEGASUS_USE_SSL_CLIENT_VERIFICATION  //PEP187
 SSLContext::SSLContext( SSLContext::SSLContext(
         const String& trustStore,         const String& trustStore,
         const String& certPath,         const String& certPath,
         const String& keyPath,         const String& keyPath,
           const String& crlPath,
         SSLCertificateVerifyFunction* verifyCert,         SSLCertificateVerifyFunction* verifyCert,
         Boolean trustStoreAutoUpdate,  
                 String trustStoreUserName,  
         const String& randomFile)         const String& randomFile)
 { {
     _rep = new SSLContextRep(trustStore, certPath, keyPath, verifyCert, trustStoreAutoUpdate, trustStoreUserName, randomFile);      _rep = new SSLContextRep(trustStore, certPath, keyPath, crlPath, verifyCert, randomFile);
 } }
 #endif  
   
  
 SSLContext::SSLContext(const SSLContext& sslContext) SSLContext::SSLContext(const SSLContext& sslContext)
 { {
Line 1175 
Line 1225 
     return (_rep->getKeyPath());     return (_rep->getKeyPath());
 } }
  
 Boolean SSLContext::isPeerVerificationEnabled() const  String SSLContext::getCRLPath() const
 { {
     return (_rep->isPeerVerificationEnabled());      return (_rep->getCRLPath());
 } }
  
 Boolean SSLContext::isTrustStoreAutoUpdateEnabled() const  X509_STORE* SSLContext::getCRLStore() const
 { {
     return (_rep->isTrustStoreAutoUpdateEnabled());      return (_rep->getCRLStore());
 } }
  
 String SSLContext::getTrustStoreUserName() const  Boolean SSLContext::isPeerVerificationEnabled() const
 { {
         return (_rep->getTrustStoreUserName());      return (_rep->isPeerVerificationEnabled());
 } }
  
 SSLCertificateVerifyFunction* SSLContext::getSSLCertificateVerifyFunction() const SSLCertificateVerifyFunction* SSLContext::getSSLCertificateVerifyFunction() const
Line 1430 
Line 1480 
     return s;     return s;
 } }
  
 SSLCallbackInfo::SSLCallbackInfo(SSLCertificateVerifyFunction* verifyCert)  SSLCallbackInfo::SSLCallbackInfo(SSLCertificateVerifyFunction* verifyCert, X509_STORE* crlStore)
 { {
     verifyCertificateCallback = verifyCert;     verifyCertificateCallback = verifyCert;
       _crlStore = crlStore;
     _peerCertificate = NULL;     _peerCertificate = NULL;
 } }
  


Legend:
Removed from v.1.28  
changed lines
  Added in v.1.48

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2