⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sslcontext.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 4 页
字号:
#endif // end of PEGASUS_HAS_SSL/////////////////////////////////////////////////////////////////////////////////// SSLContext/////////////////////////////////////////////////////////////////////////////////SSLContext::SSLContext(    const String& trustStore,    SSLCertificateVerifyFunction* verifyCert,    const String& randomFile){    _rep = new SSLContextRep(        trustStore,        String::EMPTY,        String::EMPTY,        String::EMPTY,        verifyCert,        randomFile);}SSLContext::SSLContext(    const String& trustStore,    const String& certPath,    const String& keyPath,    SSLCertificateVerifyFunction* verifyCert,    const String& randomFile){    _rep = new SSLContextRep(        trustStore, certPath, keyPath, String::EMPTY, verifyCert, randomFile);}//PEP187SSLContext::SSLContext(        const String& trustStore,        const String& certPath,        const String& keyPath,        const String& crlPath,        SSLCertificateVerifyFunction* verifyCert,        const String& randomFile){#ifndef PEGASUS_ENABLE_SSL_CRL_VERIFICATION    if (crlPath.size() > 0)    {        MessageLoaderParms parms(            "Common.Exception.SSL_CRL_NOT_ENABLED_EXCEPTION",            "SSL CRL verification is not enabled.");        throw Exception(parms);    }#endif    _rep = new SSLContextRep(        trustStore, certPath, keyPath, crlPath, verifyCert, randomFile);}#ifdef PEGASUS_USE_DEPRECATED_INTERFACESSSLContext::SSLContext(    const String& trustStore,    const String& certPath,    const String& keyPath,    SSLCertificateVerifyFunction* verifyCert,    String trustStoreUserName,    const String& randomFile){    _rep = new SSLContextRep(        trustStore, certPath, keyPath, String::EMPTY, verifyCert, randomFile);}#endifSSLContext::SSLContext(const SSLContext& sslContext){    _rep = new SSLContextRep(*sslContext._rep);}// Dummy constructor made private to disallow default constructionSSLContext::SSLContext(){}SSLContext::~SSLContext(){    delete _rep;}String SSLContext::getTrustStore() const{    return _rep->getTrustStore();}String SSLContext::getCertPath() const{    return _rep->getCertPath();}String SSLContext::getKeyPath() const{    return _rep->getKeyPath();}String SSLContext::getCRLPath() const{#ifdef PEGASUS_ENABLE_SSL_CRL_VERIFICATION    return _rep->getCRLPath();#else    MessageLoaderParms parms(        "Common.Exception.SSL_CRL_NOT_ENABLED_EXCEPTION",        "SSL CRL verification is not enabled.");    throw Exception(parms);    PEGASUS_UNREACHABLE(return String::EMPTY;)#endif}X509_STORE* SSLContext::getCRLStore() const{#ifdef PEGASUS_ENABLE_SSL_CRL_VERIFICATION    return _rep->getCRLStore();#else    MessageLoaderParms parms(        "Common.Exception.SSL_CRL_NOT_ENABLED_EXCEPTION",        "SSL CRL verification is not enabled.");    throw Exception(parms);    PEGASUS_UNREACHABLE(return 0;)#endif}Boolean SSLContext::isPeerVerificationEnabled() const{    return _rep->isPeerVerificationEnabled();}#ifdef PEGASUS_USE_DEPRECATED_INTERFACESString SSLContext::getTrustStoreUserName() const{    return _rep->getTrustStoreUserName();}#endifSSLCertificateVerifyFunction*    SSLContext::getSSLCertificateVerifyFunction() const{    return _rep->getSSLCertificateVerifyFunction();}/////////////////////////////////////////////////////////////////////////////////// SSLCertificateInfo///////////////////////////////////////////////////////////////////////////////////// Certificate validation result codes.//const int    SSLCertificateInfo::V_OK                                      = 0;const int    SSLCertificateInfo::V_ERR_UNABLE_TO_GET_ISSUER_CERT           = 2;const int    SSLCertificateInfo::V_ERR_UNABLE_TO_GET_CRL                   = 3;const int    SSLCertificateInfo::V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE    = 4;const int    SSLCertificateInfo::V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE     = 5;const int    SSLCertificateInfo::V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY  = 6;const int    SSLCertificateInfo::V_ERR_CERT_SIGNATURE_FAILURE              = 7;const int    SSLCertificateInfo::V_ERR_CRL_SIGNATURE_FAILURE               = 8;const int    SSLCertificateInfo::V_ERR_CERT_NOT_YET_VALID                  = 9;const int    SSLCertificateInfo::V_ERR_CERT_HAS_EXPIRED                    = 10;const int    SSLCertificateInfo::V_ERR_CRL_NOT_YET_VALID                   = 11;const int    SSLCertificateInfo::V_ERR_CRL_HAS_EXPIRED                     = 12;const int    SSLCertificateInfo::V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD      = 13;const int    SSLCertificateInfo::V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD       = 14;const int    SSLCertificateInfo::V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD      = 15;const int    SSLCertificateInfo::V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD      = 16;const int    SSLCertificateInfo::V_ERR_OUT_OF_MEM                          = 17;const int    SSLCertificateInfo::V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT         = 18;const int    SSLCertificateInfo::V_ERR_SELF_SIGNED_CERT_IN_CHAIN           = 19;const int    SSLCertificateInfo::V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY   = 20;const int    SSLCertificateInfo::V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE     = 21;const int    SSLCertificateInfo::V_ERR_CERT_CHAIN_TOO_LONG                 = 22;const int    SSLCertificateInfo::V_ERR_CERT_REVOKED                        = 23;const int    SSLCertificateInfo::V_ERR_INVALID_CA                          = 24;const int    SSLCertificateInfo::V_ERR_PATH_LENGTH_EXCEEDED                = 25;const int    SSLCertificateInfo::V_ERR_INVALID_PURPOSE                     = 26;const int    SSLCertificateInfo::V_ERR_CERT_UNTRUSTED                      = 27;const int    SSLCertificateInfo::V_ERR_CERT_REJECTED                       = 28;const int    SSLCertificateInfo::V_ERR_SUBJECT_ISSUER_MISMATCH             = 29;const int    SSLCertificateInfo::V_ERR_AKID_SKID_MISMATCH                  = 30;const int    SSLCertificateInfo::V_ERR_AKID_ISSUER_SERIAL_MISMATCH         = 31;const int    SSLCertificateInfo::V_ERR_KEYUSAGE_NO_CERTSIGN                = 32;const int    SSLCertificateInfo::V_ERR_APPLICATION_VERIFICATION            = 50;class SSLCertificateInfoRep{public:    String    subjectName;    String    issuerName;    Uint32    depth;    Uint32    errorCode;    Uint32    respCode;    String    errorString;    Uint32    versionNumber;    long      serialNumber;    CIMDateTime    notBefore;    CIMDateTime    notAfter;};SSLCertificateInfo::SSLCertificateInfo(    const String subjectName,    const String issuerName,    const int errorDepth,    const int errorCode,    const int respCode){    _rep = new SSLCertificateInfoRep();    _rep->subjectName = subjectName;    _rep->issuerName = issuerName;    _rep->versionNumber = 0;    _rep->serialNumber = 0;    _rep->notBefore = CIMDateTime();    _rep->notAfter = CIMDateTime();    _rep->depth = errorDepth;    _rep->errorCode = errorCode;    _rep->errorString = String::EMPTY;    _rep->respCode = respCode;}SSLCertificateInfo::SSLCertificateInfo(    const String subjectName,    const String issuerName,    const Uint32 versionNumber,    const long serialNumber,    const CIMDateTime notBefore,    const CIMDateTime notAfter,    const Uint32 depth,    const Uint32 errorCode,    const String errorString,    const Uint32 respCode){    _rep = new SSLCertificateInfoRep();    _rep->subjectName = subjectName;    _rep->issuerName = issuerName;    _rep->versionNumber = versionNumber;    _rep->serialNumber = serialNumber;    _rep->notBefore = notBefore;    _rep->notAfter = notAfter;    _rep->depth = depth;    _rep->errorCode = errorCode;    _rep->errorString = errorString;    _rep->respCode = respCode;}SSLCertificateInfo::SSLCertificateInfo(    const SSLCertificateInfo& certificateInfo){    _rep = new SSLCertificateInfoRep();    _rep->subjectName = certificateInfo._rep->subjectName;    _rep->issuerName = certificateInfo._rep->issuerName;    _rep->versionNumber = certificateInfo._rep->versionNumber;    _rep->serialNumber = certificateInfo._rep->serialNumber;    _rep->notBefore = certificateInfo._rep->notBefore;    _rep->notAfter = certificateInfo._rep->notAfter;    _rep->depth = certificateInfo._rep->depth;    _rep->errorCode = certificateInfo._rep->errorCode;    _rep->errorString = certificateInfo._rep->errorString;    _rep->respCode = certificateInfo._rep->respCode;}// Dummy constructor made private to disallow default constructionSSLCertificateInfo::SSLCertificateInfo(){}SSLCertificateInfo::~SSLCertificateInfo(){    delete _rep;}String SSLCertificateInfo::getSubjectName() const{    return _rep->subjectName;}String SSLCertificateInfo::getIssuerName() const{    return _rep->issuerName;}Uint32 SSLCertificateInfo::getVersionNumber() const{    return _rep->versionNumber;}long SSLCertificateInfo::getSerialNumber() const{    return _rep->serialNumber;}CIMDateTime SSLCertificateInfo::getNotBefore() const{    return _rep->notBefore;}CIMDateTime SSLCertificateInfo::getNotAfter() const{    return _rep->notAfter;}Uint32 SSLCertificateInfo::getErrorDepth() const{    return _rep->depth;}Uint32 SSLCertificateInfo::getErrorCode()  const{    return _rep->errorCode;}void SSLCertificateInfo::setErrorCode(const int errorCode){    _rep->errorCode = errorCode;}String SSLCertificateInfo::getErrorString() const{    return _rep->errorString;}Uint32 SSLCertificateInfo::getResponseCode()  const{    return _rep->respCode;}void SSLCertificateInfo::setResponseCode(const int respCode){    _rep->respCode = respCode;}String SSLCertificateInfo::toString() const{    char buf[1024];    String s;    s.append("Subject Name:\n\t");    s.append(_rep->subjectName);    s.append("\n");    s.append("Issuer Name:\n\t");    s.append(_rep->issuerName);    s.append("\n");    sprintf(buf, "Depth: %d\n", _rep->depth);    s.append(buf);    sprintf(buf, "Error code: %d\n", _rep->errorCode);    s.append(buf);    sprintf(buf, "Response (preverify) code: %d\n", _rep->respCode);    s.append(buf);    s.append("Error string: ");    s.append(_rep->errorString);    s.append("\n");    sprintf(buf, "Version number: %d\n", _rep->versionNumber);    s.append(buf);    sprintf(buf, "Serial number: %lu\n", _rep->serialNumber);    s.append(buf);    s.append("Not before date: ");    s.append((_rep->notBefore).toString());    s.append("\n");    s.append("Not after date: ");    s.append((_rep->notAfter).toString());    s.append("\n");    return s;}/////////////////////////////////////////////////////////////////////////////////// SSLCallbackInfo/////////////////////////////////////////////////////////////////////////////////SSLCallbackInfo::SSLCallbackInfo(SSLCertificateVerifyFunction* verifyCert){    _rep = new SSLCallbackInfoRep();    _rep->verifyCertificateCallback = verifyCert;    _rep->crlStore = NULL;}SSLCallbackInfo::SSLCallbackInfo(    SSLCertificateVerifyFunction* verifyCert,    X509_STORE* crlStore){    _rep = new SSLCallbackInfoRep();    _rep->verifyCertificateCallback = verifyCert;    _rep->crlStore = crlStore;}SSLCallbackInfo::~SSLCallbackInfo(){    PEG_METHOD_ENTER(TRC_SSL, "SSLCallbackInfo::~SSLCallbackInfo");    for (Uint32 i = 0; i < _rep->peerCertificate.size(); i++)    {        delete _rep->peerCertificate[i];    }    delete _rep;    PEG_METHOD_EXIT();}PEGASUS_NAMESPACE_END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -