• Main Page
  • Classes
  • Files
  • File List

/usr/src/startcom/BUILD/pegasus/src/Pegasus/Common/SSLContext.h

00001 //%LICENSE////////////////////////////////////////////////////////////////
00002 //
00003 // Licensed to The Open Group (TOG) under one or more contributor license
00004 // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
00005 // this work for additional information regarding copyright ownership.
00006 // Each contributor licenses this file to you under the OpenPegasus Open
00007 // Source License; you may not use this file except in compliance with the
00008 // License.
00009 //
00010 // Permission is hereby granted, free of charge, to any person obtaining a
00011 // copy of this software and associated documentation files (the "Software"),
00012 // to deal in the Software without restriction, including without limitation
00013 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
00014 // and/or sell copies of the Software, and to permit persons to whom the
00015 // Software is furnished to do so, subject to the following conditions:
00016 //
00017 // The above copyright notice and this permission notice shall be included
00018 // in all copies or substantial portions of the Software.
00019 //
00020 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00021 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00022 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00023 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
00024 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00025 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00026 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00027 //
00029 //
00030 //%/////////////////////////////////////////////////////////////////////////////
00031 
00032 #ifndef Pegasus_SSLContext_h
00033 #define Pegasus_SSLContext_h
00034 
00035 #include <Pegasus/Common/CIMDateTime.h>
00036 #include <Pegasus/Common/Config.h>
00037 #include <Pegasus/Common/String.h>
00038 #include <Pegasus/Common/Exception.h>
00039 #include <Pegasus/Common/Linkage.h>
00040 
00041 #ifdef PEGASUS_HAS_SSL
00042 typedef struct x509_store_st X509_STORE;
00043 #else
00044 # define X509_STORE int
00045 #endif
00046 
00047 PEGASUS_NAMESPACE_BEGIN
00048 
00049 class SSLCertificateInfoRep;
00050 class SSLContextRep;
00051 class SSLContext;
00052 class SSLSocket;
00053 class CIMServer;
00054 class SSLCertificateInfo;
00055 class SSLCallback;
00056 class SSLContextManager;
00057 class SSLCallbackInfoRep;
00058 
00059 // Pegasus-defined SSL certificate verification callback
00060 typedef Boolean (SSLCertificateVerifyFunction) (SSLCertificateInfo &certInfo);
00061 
00074 class PEGASUS_COMMON_LINKAGE SSLCallbackInfo
00075 {
00076 public:
00077 
00081     static const int SSL_CALLBACK_INDEX;
00082 
00089     SSLCallbackInfo(SSLCertificateVerifyFunction* verifyCert);
00090 
00099     SSLCallbackInfo(
00100         SSLCertificateVerifyFunction* verifyCert,
00101         X509_STORE* crlStore);
00102 
00106     ~SSLCallbackInfo();
00107 
00108 private:
00109 
00110     SSLCallbackInfo(
00111         SSLCertificateVerifyFunction* verifyCert,
00112         X509_STORE* crlStore,
00113         String ipAddress);
00114 
00115     SSLCallbackInfo();
00116 
00117     SSLCallbackInfo(const SSLCallbackInfo& sslCallbackInfo);
00118     SSLCallbackInfo& operator=(const SSLCallbackInfo& sslCallbackInfo);
00119 
00120     SSLCallbackInfoRep* _rep;
00121 
00122     friend class SSLSocket;
00123 
00124     friend class SSLCallback;
00125 };
00126 
00127 
00131 class PEGASUS_COMMON_LINKAGE SSLCertificateInfo
00132 {
00133 public:
00134 
00139     static const int V_OK;
00140 
00142     static const int V_ERR_UNABLE_TO_GET_ISSUER_CERT;
00144     static const int V_ERR_UNABLE_TO_GET_CRL;
00146     static const int V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE;
00148     static const int V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE;
00150     static const int V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY;
00152     static const int V_ERR_CERT_SIGNATURE_FAILURE;
00154     static const int V_ERR_CRL_SIGNATURE_FAILURE;
00156     static const int V_ERR_CERT_NOT_YET_VALID;
00158     static const int V_ERR_CERT_HAS_EXPIRED;
00160     static const int V_ERR_CRL_NOT_YET_VALID;
00162     static const int V_ERR_CRL_HAS_EXPIRED;
00164     static const int V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD;
00166     static const int V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD;
00168     static const int V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD;
00170     static const int V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD;
00172     static const int V_ERR_OUT_OF_MEM;
00174     static const int V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT;
00176     static const int V_ERR_SELF_SIGNED_CERT_IN_CHAIN;
00178     static const int V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY;
00180     static const int V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE;
00182     static const int V_ERR_CERT_CHAIN_TOO_LONG;
00184     static const int V_ERR_CERT_REVOKED;
00186     static const int V_ERR_INVALID_CA;
00188     static const int V_ERR_PATH_LENGTH_EXCEEDED;
00190     static const int V_ERR_INVALID_PURPOSE;
00192     static const int V_ERR_CERT_UNTRUSTED;
00194     static const int V_ERR_CERT_REJECTED;
00196     static const int V_ERR_SUBJECT_ISSUER_MISMATCH;
00198     static const int V_ERR_AKID_SKID_MISMATCH;
00200     static const int V_ERR_AKID_ISSUER_SERIAL_MISMATCH;
00202     static const int V_ERR_KEYUSAGE_NO_CERTSIGN;
00203 
00205     static const int V_ERR_APPLICATION_VERIFICATION;
00206 
00207 
00220     SSLCertificateInfo(
00221         const String subjectName,
00222         const String issuerName,
00223         const int errorDepth,
00224         const int errorCode,
00225         const int respCode);
00226 
00230     SSLCertificateInfo(const SSLCertificateInfo& certificateInfo);
00231 
00232     ~SSLCertificateInfo();
00233 
00237     String getSubjectName() const;
00238 
00242     String getIssuerName() const;
00243 
00248     CIMDateTime getNotAfter() const;
00249 
00254     CIMDateTime getNotBefore() const;
00255 
00259     Uint32 getVersionNumber() const;
00260 
00264     long getSerialNumber() const;
00265 
00269     Uint32 getErrorDepth() const;
00270 
00274     Uint32 getErrorCode() const;
00275 
00279     void setErrorCode(const int errorCode);
00280 
00284     String getErrorString() const;
00285 
00289     Uint32 getResponseCode() const;
00290 
00296     void setResponseCode(const int respCode);
00297 
00301     String toString() const;
00302 
00303 private:
00304 
00322     SSLCertificateInfo(
00323         const String subjectName,
00324         const String issuerName,
00325         const Uint32 versionNumber,
00326         const long   serialNumber,
00327         const CIMDateTime notBefore,
00328         const CIMDateTime notAfter,
00329         const Uint32 depth,
00330         const Uint32 errorCode,
00331         const String errorString,
00332         const Uint32 respCode);
00333 
00334     SSLCertificateInfo();
00335     SSLCertificateInfo& operator=(const SSLCertificateInfo& sslCertificateInfo);
00336 
00337     SSLCertificateInfoRep* _rep;
00338 
00339     // SSLSocket needs to use the private constructor to create
00340     // a certificate object to pass to the AuthenticationInfo and
00341     // OperationContext classes
00342     friend class SSLSocket;
00343 
00344     friend class SSLCallback;
00345 };
00346 
00350 class PEGASUS_COMMON_LINKAGE SSLContext
00351 {
00352 public:
00353 
00375     SSLContext(
00376         const String& trustStore,
00377         SSLCertificateVerifyFunction* verifyCert,
00378         const String& randomFile = String::EMPTY);
00379 
00384     SSLContext(const SSLContext& sslContext);
00385 
00389     ~SSLContext();
00390 
00395     String getTrustStore() const;
00396 
00400     String getCertPath() const;
00401 
00405     String getKeyPath() const;
00406 
00410     String getCRLPath() const;
00411 
00415     X509_STORE* getCRLStore() const;
00416 
00421     Boolean isPeerVerificationEnabled() const;
00422 
00423 #ifdef PEGASUS_USE_DEPRECATED_INTERFACES
00424 
00429     String getTrustStoreUserName() const;
00430 #endif
00431 
00436     SSLCertificateVerifyFunction* getSSLCertificateVerifyFunction() const;
00437 
00462     SSLContext(
00463         const String& trustStore,
00464         const String& certPath,
00465         const String& keyPath,
00466         SSLCertificateVerifyFunction* verifyCert,
00467         const String& randomFile);
00468 
00469 
00495     SSLContext(
00496         const String& trustStore,
00497         const String& certPath,
00498         const String& keyPath,
00499         const String& crlPath,
00500         SSLCertificateVerifyFunction* verifyCert,
00501         const String& randomFile);
00502 
00503 #ifdef PEGASUS_USE_DEPRECATED_INTERFACES
00504 
00521     SSLContext(
00522         const String& trustStore,
00523         const String& certPath,
00524         const String& keyPath,
00525         SSLCertificateVerifyFunction* verifyCert,
00526         String trustStoreUserName,
00527         const String& randomFile);
00528 #endif
00529 
00530 private:
00531 
00532     SSLContext();
00533     SSLContext& operator=(const SSLContext& sslContext);
00534 
00535     void _validateCertificate();
00536 
00537     SSLContextRep* _rep;
00538 
00539     friend class SSLSocket;
00540     friend class CIMServer;
00541     friend class SSLContextManager;
00542 };
00543 
00544 PEGASUS_NAMESPACE_END
00545 
00546 #endif /* Pegasus_SSLContext_h */