• Main Page
  • Classes
  • Files
  • File List

/var/tmp/axbld-11697/rpm/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 
00219     SSLCertificateInfo(
00220         const String subjectName,
00221         const String issuerName,
00222         const int errorDepth,
00223         const int errorCode,
00224         const int respCode);
00225 
00229     SSLCertificateInfo(const SSLCertificateInfo& certificateInfo);
00230 
00231     ~SSLCertificateInfo();
00232 
00236     String getSubjectName() const;
00237 
00241     String getIssuerName() const;
00242 
00247     CIMDateTime getNotAfter() const;
00248 
00253     CIMDateTime getNotBefore() const;
00254 
00258     Uint32 getVersionNumber() const;
00259 
00263     long getSerialNumber() const;
00264 
00268     Uint32 getErrorDepth() const;
00269 
00273     Uint32 getErrorCode() const;
00274 
00278     void setErrorCode(const int errorCode);
00279 
00283     String getErrorString() const;
00284 
00288     Uint32 getResponseCode() const;
00289 
00295     void setResponseCode(const int respCode);
00296 
00300     String toString() const;
00301 
00305 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
00306     const String &getPeerCertificate() const;
00307 #endif
00308 
00309 private:
00310 
00328     SSLCertificateInfo(
00329         const String subjectName,
00330         const String issuerName,
00331         const Uint32 versionNumber,
00332         const long   serialNumber,
00333         const CIMDateTime notBefore,
00334         const CIMDateTime notAfter,
00335         const Uint32 depth,
00336         const Uint32 errorCode,
00337         const String errorString,
00338         const Uint32 respCode);
00339 
00340     SSLCertificateInfo();
00341     SSLCertificateInfo& operator=(const SSLCertificateInfo& sslCertificateInfo);
00342 
00343     SSLCertificateInfoRep* _rep;
00344 
00345     // SSLSocket needs to use the private constructor to create
00346     // a certificate object to pass to the AuthenticationInfo and
00347     // OperationContext classes
00348     friend class SSLSocket;
00349 
00350     friend class SSLCallback;
00351 };
00352 
00356 class PEGASUS_COMMON_LINKAGE SSLContext
00357 {
00358 public:
00359 
00381     SSLContext(
00382         const String& trustStore,
00383         SSLCertificateVerifyFunction* verifyCert,
00384         const String& randomFile = String::EMPTY);
00385 
00390     SSLContext(const SSLContext& sslContext);
00391 
00395     ~SSLContext();
00396 
00401     String getTrustStore() const;
00402 
00406     String getCertPath() const;
00407 
00411     String getKeyPath() const;
00412 
00416     String getCRLPath() const;
00417 
00421     X509_STORE* getCRLStore() const;
00422 
00427     Boolean isPeerVerificationEnabled() const;
00428 
00429 #ifdef PEGASUS_USE_DEPRECATED_INTERFACES
00430 
00435     String getTrustStoreUserName() const;
00436 #endif
00437 
00442     SSLCertificateVerifyFunction* getSSLCertificateVerifyFunction() const;
00443 
00468     SSLContext(
00469         const String& trustStore,
00470         const String& certPath,
00471         const String& keyPath,
00472         SSLCertificateVerifyFunction* verifyCert,
00473         const String& randomFile);
00474 
00475 
00501     SSLContext(
00502         const String& trustStore,
00503         const String& certPath,
00504         const String& keyPath,
00505         const String& crlPath,
00506         SSLCertificateVerifyFunction* verifyCert,
00507         const String& randomFile);
00508 
00509 #ifdef PEGASUS_USE_DEPRECATED_INTERFACES
00510 
00527     SSLContext(
00528         const String& trustStore,
00529         const String& certPath,
00530         const String& keyPath,
00531         SSLCertificateVerifyFunction* verifyCert,
00532         String trustStoreUserName,
00533         const String& randomFile);
00534 #endif
00535 
00536 private:
00537 
00538     SSLContext();
00539     SSLContext& operator=(const SSLContext& sslContext);
00540 
00541     void _validateCertificate();
00542 
00543     SSLContextRep* _rep;
00544 
00545     friend class SSLSocket;
00546     friend class CIMServer;
00547     friend class SSLContextManager;
00548 };
00549 
00550 PEGASUS_NAMESPACE_END
00551 
00552 #endif /* Pegasus_SSLContext_h */