VirtualBox

Changeset 60341 in vbox for trunk


Ignore:
Timestamp:
Apr 5, 2016 11:37:57 PM (9 years ago)
Author:
vboxsync
Message:

ICertificate, Import wizard: Some adjustments to make it do and show what comment 22 indicated. Note that the 3rd case (mismatching signature) is handled via errors set by Appliance::i_readTailProcessing.

Location:
trunk/src/VBox
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance/UIWizardImportAppPageBasic2.cpp

    r60339 r60341  
    4040
    4141/*********************************************************************************************************************************
    42 *   Class UIApplianceCertificateViewer implementation.                                                                           *
     42*   Class UIApplianceCertificateViewer.                                                                                          *
    4343*********************************************************************************************************************************/
    4444
    45 UIApplianceCertificateViewer::UIApplianceCertificateViewer(QWidget *pParent, const CCertificate &certificate)
     45UIApplianceUnverifiedCertificate::UIApplianceUnverifiedCertificate(QWidget *pParent, const CCertificate &certificate)
    4646    : QIWithRetranslateUI<QIDialog>(pParent)
    4747    , m_certificate(certificate)
    48     , m_pTextLabel(0)
    49     , m_pTextBrowser(0)
     48    , m_pTextLabel(NULL)
     49    , m_pTextBrowser(NULL)
    5050{
    5151    /* Prepare: */
     
    5353}
    5454
    55 void UIApplianceCertificateViewer::prepare()
     55void UIApplianceUnverifiedCertificate::prepare()
    5656{
    5757    /* Create layout: */
     
    6868            pLayout->addWidget(m_pTextLabel);
    6969        }
     70
    7071        /* Create text-browser: */
    7172        m_pTextBrowser = new QTextBrowser;
     
    7778            pLayout->addWidget(m_pTextBrowser);
    7879        }
     80
    7981        /* Create button-box: */
    8082        QIDialogButtonBox *pButtonBox = new QIDialogButtonBox;
     
    8284        {
    8385            /* Configure button-box: */
    84             pButtonBox->setStandardButtons(QDialogButtonBox::Ok);
    85             pButtonBox->button(QDialogButtonBox::Ok)->setShortcut(Qt::Key_Enter);
     86            pButtonBox->setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No);
     87
     88            pButtonBox->button(QDialogButtonBox::Yes)->setShortcut(Qt::Key_Enter);
    8689            connect(pButtonBox, SIGNAL(accepted()), this, SLOT(close()));
     90
     91            //pButtonBox->button(QDialogButtonBox::No)->setShortcut(Qt::Key_Esc);
     92            connect(pButtonBox, SIGNAL(rejected()), this, SLOT(close()));
     93
    8794            /* Add button-box into layout: */
    8895            pLayout->addWidget(pButtonBox);
     
    93100}
    94101
    95 void UIApplianceCertificateViewer::retranslateUi()
     102void UIApplianceUnverifiedCertificate::retranslateUi()
    96103{
    97104    /* Translate dialog title: */
    98     setWindowTitle(tr("Certificate Information"));
     105    setWindowTitle(tr("Unverifiable Certificate! Continue?"));
     106
    99107    /* Translate text-label caption: */
    100     m_pTextLabel->setText(tr("<b>The X509 certificate exists but hasn't been verified or trusted. "
    101                              "You can proceed with the importing but should understand the risks. "
    102                              "If you are not sure - just stop here and interrupt the importing process.</b>"));
     108    if (m_certificate.GetSelfSigned())
     109        m_pTextLabel->setText(tr("<b>The appliance is signed by an unverified self signed certificate issued by '%1'. "
     110                                 "We recommend to only proceed with the importing if you are sure you should trust this entity.</b>"
     111                                 ).arg(m_certificate.GetFriendlyName()));
     112    else
     113        m_pTextLabel->setText(tr("<b>The appliance is signed by an unverified certificate issued to '%1'. "
     114                                 "We recommend to only proceed with the importing if you are sure you should trust this entity.</b>"
     115                                 ).arg(m_certificate.GetFriendlyName()));
     116
    103117    /* Translate text-browser contents: */
    104118    QStringList info;
    105     KCertificateVersion ver = (m_certificate.GetVersionNumber());
    106     info << tr("Certificate Version Number: %1").arg(ver);
    107     info << tr("Certificate Serial Number: 0x%1").arg(m_certificate.GetSerialNumber());
    108     info << tr("Certificate Authority (CA): %1").arg(m_certificate.GetCertificateAuthority() ? tr("True") : tr("False"));
    109     info << tr("Certificate Self-Signed: %1").arg(m_certificate.GetSelfSigned() ? tr("True") : tr("False"));
    110     info << tr("Certificate Trusted: %1").arg(m_certificate.GetTrusted() ? tr("True") : tr("False"));
    111     info << tr("Certificate Issuer: %1").arg(QStringList(m_certificate.GetIssuerName().toList()).join(", "));
    112     info << tr("Certificate Subject: %1").arg(QStringList(m_certificate.GetSubjectName().toList()).join(", "));
    113     info << tr("Certificate Public Algorithm: %1").arg(m_certificate.GetPublicKeyAlgorithm());
    114     info << tr("Certificate Signature Algorithm: %1").arg(m_certificate.GetSignatureAlgorithmName());
    115     info << tr("Certificate Signature Algorithm OID: %1").arg(m_certificate.GetSignatureAlgorithmOID());
    116     info << tr("Certificate Validity Period Not Before: %1").arg(m_certificate.GetValidityPeriodNotBefore());
    117     info << tr("Certificate Validity Period Not After: %1").arg(m_certificate.GetValidityPeriodNotAfter());
    118     m_pTextBrowser->setText(info.join("<br><br>"));
     119    KCertificateVersion ver = m_certificate.GetVersionNumber();
     120    info << tr("Issuer:               %1").arg(QStringList(m_certificate.GetIssuerName().toList()).join(", "));
     121    info << tr("Subject:              %1").arg(QStringList(m_certificate.GetSubjectName().toList()).join(", "));
     122    info << tr("Not Valid Before:     %1").arg(m_certificate.GetValidityPeriodNotBefore());
     123    info << tr("Not Valid After:      %1").arg(m_certificate.GetValidityPeriodNotAfter());
     124    info << tr("Serial Number:        %1").arg(m_certificate.GetSerialNumber());
     125    info << tr("Self-Signed:          %1").arg(m_certificate.GetSelfSigned() ? tr("True") : tr("False"));
     126    info << tr("Authority (CA):       %1").arg(m_certificate.GetCertificateAuthority() ? tr("True") : tr("False"));
     127    //info << tr("Trusted:              %1").arg(m_certificate.GetTrusted() ? tr("True") : tr("False")); - no, that's why we're here
     128    info << tr("Public Algorithm:     %1 (%1)").arg(m_certificate.GetPublicKeyAlgorithm()).arg(m_certificate.GetPublicKeyAlgorithmOID());
     129    info << tr("Signature Algorithm:  %1 (%1)").arg(m_certificate.GetSignatureAlgorithmName()).arg(m_certificate.GetSignatureAlgorithmOID());
     130    info << tr("X.509 Version Number: %1").arg(ver);
     131    m_pTextBrowser->setText(info.join("<br>"));
    119132}
    120133
     
    134147
    135148UIWizardImportAppPageBasic2::UIWizardImportAppPageBasic2(const QString &strFileName)
     149    : m_enmCertText(kCertText_Uninitialized)
    136150{
    137151    /* Create widgets: */
     
    144158            m_pApplianceWidget->setFile(strFileName);
    145159        }
     160        m_pCertLabel = new QLabel("<cert label>", this);
    146161        pMainLayout->addWidget(m_pLabel);
    147162        pMainLayout->addWidget(m_pApplianceWidget);
     163        pMainLayout->addWidget(m_pCertLabel);
    148164    }
    149165
     
    164180                                            "You can change many of the properties shown by double-clicking "
    165181                                            "on the items and disable others using the check boxes below."));
     182    switch (m_enmCertText)
     183    {
     184        case kCertText_Unsigned:
     185            m_pCertLabel->setText(UIWizardImportApp::tr("Appliance is not signed"));
     186            break;
     187        case kCertText_IssuedTrusted:
     188            m_pCertLabel->setText(UIWizardImportApp::tr("Appliance signed by %1 (trusted)").arg(m_strSignedBy));
     189            break;
     190        case kCertText_IssuedExpired:
     191            m_pCertLabel->setText(UIWizardImportApp::tr("Appliance signed by %1 (expired!)").arg(m_strSignedBy));
     192            break;
     193        case kCertText_IssuedUnverified:
     194            m_pCertLabel->setText(UIWizardImportApp::tr("Unverified signature by %1!").arg(m_strSignedBy));
     195            break;
     196        case kCertText_SelfSignedTrusted:
     197            m_pCertLabel->setText(UIWizardImportApp::tr("Self signed by %1 (trusted)").arg(m_strSignedBy));
     198            break;
     199        case kCertText_SelfSignedExpired:
     200            m_pCertLabel->setText(UIWizardImportApp::tr("Self signed by %1 (expired!)").arg(m_strSignedBy));
     201            break;
     202        case kCertText_SelfSignedUnverified:
     203            m_pCertLabel->setText(UIWizardImportApp::tr("Unverified self signed signature by %1!").arg(m_strSignedBy));
     204            break;
     205        default:
     206            AssertFailed();
     207        case kCertText_Uninitialized:
     208            m_pCertLabel->setText("<uninitialized page>");
     209            break;
     210    }
    166211}
    167212
    168213void UIWizardImportAppPageBasic2::initializePage()
    169214{
    170     /* Translate page: */
    171     retranslateUi();
    172 
    173215    /* Acquire appliance and certificate: */
    174216    CAppliance *pAppliance = m_pApplianceWidget->appliance();
    175217    CCertificate certificate = pAppliance->GetCertificate();
    176     if (!certificate.isNull())
    177     {
    178         if(!certificate.GetTrusted() || certificate.GetSelfSigned())
    179         {
    180             /* Create certificate viewer to notify user about it is not verified: */
    181             QPointer<UIApplianceCertificateViewer> pDialog =
    182                 new UIApplianceCertificateViewer(this, certificate);
    183             AssertPtrReturnVoid(pDialog.data());
    184             {
    185                 /* Show viewer in modal mode: */
    186                 pDialog->exec();
    187                 /* Leave if destroyed prematurely: */
    188                 if (!pDialog)
    189                     return;
    190                 /* Delete viewer finally: */
    191                 delete pDialog;
    192                 pDialog = 0;
    193             }
    194         }
    195     }
     218    if (certificate.isNull())
     219        m_enmCertText = kCertText_Unsigned;
    196220    else
    197221    {
    198         /* Translate page: */
    199         retranslateUi();
    200         /* Create dialog: */
    201         QDialog *pDialog = new QDialog(this, Qt::Dialog);
    202         AssertPtrReturnVoid(pDialog);
    203         /* Create layout: */
    204         QVBoxLayout *pLayout = new QVBoxLayout(pDialog);
    205         AssertPtrReturnVoid(pLayout);
    206         {
    207             /* Prepare dialog: */
    208             pDialog->resize(500, 100);
    209             /*todo: show an error message and prohibit OVF import */
    210             {
    211                 /* Create text-label: */
    212                 QLabel *m_pTextLabel = new QLabel;
    213                 AssertPtrReturnVoid(m_pTextLabel);
    214                 {
    215                     /* Configure text-label: */
    216                     m_pTextLabel->setWordWrap(true);
    217                     m_pTextLabel->setText(tr("<b>The X509 certificate exists but hasn't been verified."
    218                              "You should stop here and interrupt the importing process.</b>"));
    219                     /* Add text-label into layout: */
    220                     pLayout->addWidget(m_pTextLabel);
    221                 }
    222 
    223                 pLayout->addStretch();
    224 
    225                 /* Create button-box: */
    226                 QIDialogButtonBox *pButtonBox = new QIDialogButtonBox;
    227                 AssertPtrReturnVoid(pButtonBox);
    228                 {
    229                     /* Configure button-box: */
    230                     pButtonBox->setStandardButtons(QDialogButtonBox::Ok);
    231                     pButtonBox->button(QDialogButtonBox::Ok)->setShortcut(Qt::Key_Enter);
    232                     connect(pButtonBox, SIGNAL(accepted()), this, SLOT(close()));
    233                     /* Add button-box into layout: */
    234                     pLayout->addWidget(pButtonBox);
    235                 }
    236             }
    237             /* Show dialog in modal mode: */
     222        /* Pick a 'signed-by' name. */
     223        m_strSignedBy = certificate.GetFriendlyName();
     224
     225        /*
     226         * If trusted, just select the right message.
     227         */
     228        if (certificate.GetTrusted())
     229        {
     230            if (certificate.GetSelfSigned())
     231                m_enmCertText = !certificate.GetExpired() ? kCertText_SelfSignedTrusted : kCertText_SelfSignedExpired;
     232            else
     233                m_enmCertText = !certificate.GetExpired() ? kCertText_IssuedTrusted     : kCertText_IssuedExpired;
     234        }
     235        else
     236        {
     237            /*
     238             * Not trusted!  Must ask the user whether to continue in this case.
     239             */
     240            m_enmCertText = !certificate.GetExpired() ? kCertText_SelfSignedUnverified : kCertText_SelfSignedUnverified;
     241            retranslateUi();
     242
     243            /* Instantiate the dialog: */
     244            QPointer<UIApplianceUnverifiedCertificate> pDialog = new UIApplianceUnverifiedCertificate(this, certificate);
     245            AssertPtrReturnVoid(pDialog.data());
     246
     247            /* Show viewer in modal mode: */
    238248            pDialog->exec();
    239             /* Delete dialog finally: */
     249
     250/** @todo
     251 *
     252 * Must dismiss the wizard if dialog was rejected!
     253 * Must dismiss the wizard if dialog was rejected!
     254 * Must dismiss the wizard if dialog was rejected!
     255 *
     256 * Someone with clue try figure out how.
     257 *
     258 */
     259
     260            /* Leave if destroyed prematurely: */
     261            if (!pDialog)
     262                return; /** @todo r=bird: what happened to this dialog in that case?? */
     263
     264            /* Delete viewer finally: */
    240265            delete pDialog;
    241             pDialog = 0;
     266            pDialog = NULL;
    242267        }
    243268    }
     269
     270    /* Translate page: */
     271    retranslateUi();
    244272}
    245273
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance/UIWizardImportAppPageBasic2.h

    r60276 r60341  
    1616 */
    1717
    18 #ifndef __UIWizardImportAppPageBasic2_h__
    19 #define __UIWizardImportAppPageBasic2_h__
     18#ifndef ___UIWizardImportAppPageBasic2_h___
     19#define ___UIWizardImportAppPageBasic2_h___
    2020
    2121/* GUI includes: */
     
    3333
    3434
    35 /** QIDialog extension providing user with the information
    36   * about the appliance certificate which validation failed. */
    37 class UIApplianceCertificateViewer : public QIWithRetranslateUI<QIDialog>
    38 {
    39     Q_OBJECT;
    40 
    41 public:
    42 
    43     /** Constructs appliance @a certificate viewer for passed @a pParent. */
    44     UIApplianceCertificateViewer(QWidget *pParent, const CCertificate &certificate);
    45 
    46 protected:
    47 
    48     /** Prepares all. */
    49     void prepare();
    50 
    51     /** Handles translation event. */
    52     virtual void retranslateUi() /* override */;
    53 
    54 private:
    55 
    56     /** Holds the certificate reference. */
    57     const CCertificate &m_certificate;
    58 
    59     /** Holds the text-label instance. */
    60     QLabel *m_pTextLabel;
    61     /** Holds the text-browser instance. */
    62     QTextBrowser *m_pTextBrowser;
    63 };
    64 
    65 
    66 /* 2nd page of the Import Appliance wizard (base part): */
     35/** 2nd page of the Import Appliance wizard (base part): */
    6736class UIWizardImportAppPage2 : public UIWizardPageBase
    6837{
     
    7948};
    8049
    81 /* 2nd page of the Import Appliance wizard (basic extension): */
     50/** 2nd page of the Import Appliance wizard (basic extension): */
    8251class UIWizardImportAppPageBasic2 : public UIWizardPage, public UIWizardImportAppPage2
    8352{
     
    10473    /* Widgets: */
    10574    QIRichTextLabel *m_pLabel;
     75    QLabel *m_pCertLabel;       /**< Signature/certificate info label. */
     76    enum {
     77        kCertText_Uninitialized = 0, kCertText_Unsigned,
     78        kCertText_IssuedTrusted,     kCertText_IssuedExpired,     kCertText_IssuedUnverified,
     79        kCertText_SelfSignedTrusted, kCertText_SelfSignedExpired, kCertText_SelfSignedUnverified
     80    } m_enmCertText;
     81    QString m_strSignedBy;
    10682};
    10783
    108 #endif /* __UIWizardImportAppPageBasic2_h__ */
     84/**
     85 * Dialog for asking consent to continue with unverifiable certificate.
     86 */
     87class UIApplianceUnverifiedCertificate : public QIWithRetranslateUI<QIDialog>
     88{
     89    Q_OBJECT;
    10990
     91public:
     92    /** Constructs appliance @a certificate viewer for passed @a pParent. */
     93    UIApplianceUnverifiedCertificate(QWidget *pParent, const CCertificate &certificate);
     94
     95protected:
     96    /** Prepares all. */
     97    void prepare();
     98
     99    /** Handles translation event. */
     100    virtual void retranslateUi() /* override */;
     101
     102private:
     103    /** Holds the certificate reference. */
     104    const CCertificate &m_certificate;
     105
     106    /** Holds the text-label instance. */
     107    QLabel *m_pTextLabel;
     108    /** Holds the text-browser instance. */
     109    QTextBrowser *m_pTextBrowser;
     110};
     111
     112
     113#endif /* !___UIWizardImportAppPageBasic2_h___ */
     114
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r60334 r60341  
    29992999  <interface
    30003000    name="ICertificate" extends="$unknown"
    3001     uuid="c85f71ef-dd7f-4b9c-aa58-5c186a95d7f9"
     3001    uuid="392f1de4-80e1-4a8a-93a1-67c5f92a838a"
    30023002    wsmap="managed"
    30033003    reservedAttributes="12" reservedMethods="2"
     
    30273027      <desc>Subject name.  Same format as issuerName.</desc>
    30283028    </attribute>
     3029    <attribute name="friendlyName" type="wstring" readonly="yes">
     3030      <desc>Friendly subject name or similar.</desc>
     3031    </attribute>
    30293032    <attribute name="validityPeriodNotBefore" type="wstring" readonly="yes">
    30303033      <desc>Certificate not valid before ISO time stamp.</desc>
     
    30653068      <desc>Set if self signed certificate.</desc>
    30663069    </attribute>
     3070
     3071    <!-- The following is subject to the parent object views. -->
    30673072    <attribute name="trusted" type="boolean" readonly="yes">
    3068       <desc>Set if the certificate is trusted.</desc>
    3069     </attribute>
     3073      <desc>Set if the certificate is trusted (by the parent object).</desc>
     3074    </attribute>
     3075    <attribute name="expired" type="boolean" readonly="yes"> <!-- isCurrentlyExpired is clearer than isCurrentlyValid. -->
     3076      <desc>Set if the certificate has expired (relevant to the parent object)/</desc>
     3077    </attribute>
     3078
     3079    <method name="isCurrentlyExpired">
     3080      <desc>
     3081        Tests if the certificate has expired at the present time according to
     3082        the X.509 validity of the certificate.</desc>
     3083      <param name="result" type="boolean" dir="return" />
     3084    </method>
    30703085
    30713086    <method name="queryInfo">
  • trunk/src/VBox/Main/include/CertificateImpl.h

    r60334 r60341  
    3636    DECLARE_EMPTY_CTOR_DTOR(Certificate)
    3737
    38     HRESULT initCertificate(PCRTCRX509CERTIFICATE a_pCert, bool a_fTrusted);
     38    HRESULT initCertificate(PCRTCRX509CERTIFICATE a_pCert, bool a_fTrusted, bool a_fExpired);
    3939    void uninit();
    4040
     
    5252    HRESULT getIssuerName(std::vector<com::Utf8Str> &aIssuerName);
    5353    HRESULT getSubjectName(std::vector<com::Utf8Str> &aSubjectName);
     54    HRESULT getFriendlyName(com::Utf8Str &aFriendlyName);
    5455    HRESULT getValidityPeriodNotBefore(com::Utf8Str &aValidityPeriodNotBefore);
    5556    HRESULT getValidityPeriodNotAfter(com::Utf8Str &aValidityPeriodNotAfter);
     
    6364    HRESULT getSelfSigned(BOOL *aSelfSigned);
    6465    HRESULT getTrusted(BOOL *aTrusted);
     66    HRESULT getExpired(BOOL *aExpired);
    6567    // wrapped ICertificate methods
     68    HRESULT isCurrentlyExpired(BOOL *aResult);
    6669    HRESULT queryInfo(LONG aWhat, com::Utf8Str &aResult);
    6770
  • trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp

    r60334 r60341  
    18081808             * is acceptible.  But, first make sure it makes internal sense.
    18091809             */
    1810             m->fCertificateMissingPath = false; /** @todo need to check if the certificate is trusted by the system! */
     1810            m->fCertificateMissingPath = true; /** @todo need to check if the certificate is trusted by the system! */
    18111811            vrc = RTCrX509Certificate_VerifySignatureSelfSigned(&m->SignerCert, RTErrInfoInitStatic(&StaticErrInfo));
    18121812            if (RT_SUCCESS(vrc))
     
    19531953    {
    19541954        m->ptrCertificateInfo.createObject();
    1955         m->ptrCertificateInfo->initCertificate(&m->SignerCert, m->fCertificateValid && !m->fCertificateMissingPath);
     1955        m->ptrCertificateInfo->initCertificate(&m->SignerCert,
     1956                                               m->fCertificateValid && !m->fCertificateMissingPath,
     1957                                               !m->fCertificateValidTime);
    19561958    }
    19571959
  • trunk/src/VBox/Main/src-server/CertificateImpl.cpp

    r60334 r60341  
    3333    CertificateData()
    3434        : fTrusted(false)
     35        , fExpired(false)
    3536        , fValidX509(false)
    3637    {
     
    5051    /** Whether the certificate is trusted.  */
    5152    bool fTrusted;
     53    /** Whether the certificate is trusted.  */
     54    bool fExpired;
    5255    /** Valid data in mX509. */
    5356    bool fValidX509;
     
    9093 * @param   a_pCert         The certificate.
    9194 * @param   a_fTrusted      Whether the caller trusts the certificate or not.
    92  */
    93 HRESULT Certificate::initCertificate(PCRTCRX509CERTIFICATE a_pCert, bool a_fTrusted)
     95 * @param   a_fExpired      Whether the caller consideres the certificate to be
     96 *                          expired.
     97 */
     98HRESULT Certificate::initCertificate(PCRTCRX509CERTIFICATE a_pCert, bool a_fTrusted, bool a_fExpired)
    9499{
    95100    HRESULT rc = S_OK;
     
    106111    {
    107112        mData->m->fValidX509 = true;
    108         mData->m->fTrusted  = a_fTrusted;
     113        mData->m->fTrusted   = a_fTrusted;
     114        mData->m->fExpired   = a_fExpired;
    109115        autoInitSpan.setSucceeded();
    110116    }
     
    127133    mData = NULL;
    128134}
     135
     136
     137/** @name wrapped ICertificate properties
     138 * @{
     139 */
    129140
    130141/**
     
    223234}
    224235
     236HRESULT Certificate::getFriendlyName(com::Utf8Str &aFriendlyName)
     237{
     238    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     239
     240    Assert(mData->m->fValidX509);
     241
     242    PCRTCRX509NAME pName = &mData->m->X509.TbsCertificate.Subject;
     243
     244    /*
     245     * Enumerate the subject name and pick interesting attributes we can use to
     246     * form a name more friendly than the RTCrX509Name_FormatAsString output.
     247     */
     248    const char *pszOrg       = NULL;
     249    const char *pszOrgUnit   = NULL;
     250    const char *pszGivenName = NULL;
     251    const char *pszSurname   = NULL;
     252    const char *pszEmail     = NULL;
     253    for (uint32_t i = 0; i < pName->cItems; i++)
     254    {
     255        PCRTCRX509RELATIVEDISTINGUISHEDNAME pRdn = &pName->paItems[i];
     256        for (uint32_t j = 0; j < pRdn->cItems; j++)
     257        {
     258            PCRTCRX509ATTRIBUTETYPEANDVALUE pComponent = &pRdn->paItems[j];
     259            AssertContinue(pComponent->Value.enmType == RTASN1TYPE_STRING);
     260
     261            /* Select interesting components based on the short RDN prefix
     262               string (easier to read and write than OIDs, for now). */
     263            const char *pszPrefix = RTCrX509Name_GetShortRdn(&pComponent->Type);
     264            if (pszPrefix)
     265            {
     266                const char *pszUtf8;
     267                int vrc = RTAsn1String_QueryUtf8(&pComponent->Value.u.String, &pszUtf8, NULL);
     268                if (RT_SUCCESS(vrc) && *pszUtf8)
     269                {
     270                    if (!strcmp(pszPrefix, "Email"))
     271                        pszEmail = pszUtf8;
     272                    else if (!strcmp(pszPrefix, "O"))
     273                        pszOrg = pszUtf8;
     274                    else if (!strcmp(pszPrefix, "OU"))
     275                        pszOrgUnit = pszUtf8;
     276                    else if (!strcmp(pszPrefix, "S"))
     277                        pszSurname = pszUtf8;
     278                    else if (!strcmp(pszPrefix, "G"))
     279                        pszGivenName = pszUtf8;
     280                }
     281            }
     282        }
     283    }
     284
     285    if (pszGivenName && pszSurname)
     286    {
     287        if (pszEmail)
     288            aFriendlyName = Utf8StrFmt("%s, %s <%s>", pszSurname, pszGivenName, pszEmail);
     289        else if (pszOrg)
     290            aFriendlyName = Utf8StrFmt("%s, %s (%s)", pszSurname, pszGivenName, pszOrg);
     291        else if (pszOrgUnit)
     292            aFriendlyName = Utf8StrFmt("%s, %s (%s)", pszSurname, pszGivenName, pszOrgUnit);
     293        else
     294            aFriendlyName = Utf8StrFmt("%s, %s", pszSurname, pszGivenName);
     295    }
     296    else if (pszOrg && pszOrgUnit)
     297        aFriendlyName = Utf8StrFmt("%s, %s", pszOrg, pszOrgUnit);
     298    else if (pszOrg)
     299        aFriendlyName = Utf8StrFmt("%s", pszOrg);
     300    else if (pszOrgUnit)
     301        aFriendlyName = Utf8StrFmt("%s", pszOrgUnit);
     302    else
     303    {
     304        /*
     305         * Fall back on unfriendly but accurate.
     306         */
     307        char szTmp[_8K];
     308        RT_ZERO(szTmp);
     309        RTCrX509Name_FormatAsString(pName, szTmp, sizeof(szTmp) - 1, NULL);
     310        aFriendlyName = szTmp;
     311    }
     312
     313    return S_OK;
     314}
     315
    225316/**
    226317 * Private method implementation.
     
    382473    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    383474
     475    Assert(mData->m->fValidX509);
    384476    *aTrusted = mData->m->fTrusted;
    385477
     
    387479}
    388480
    389 /**
    390  * Private method implementation.
    391  * @param aWhat
    392  * @param aResult
    393  * @return
    394  */
     481HRESULT Certificate::getExpired(BOOL *aExpired)
     482{
     483    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     484    Assert(mData->m->fValidX509);
     485    *aExpired = mData->m->fExpired;
     486    return S_OK;
     487}
     488
     489/** @} */
     490
     491/** @name Wrapped ICertificate methods
     492 * @{
     493 */
     494
     495HRESULT Certificate::isCurrentlyExpired(BOOL *aResult)
     496{
     497    AssertReturnStmt(mData->m->fValidX509, *aResult = TRUE, E_UNEXPECTED);
     498    RTTIMESPEC Now;
     499    *aResult = RTCrX509Validity_IsValidAtTimeSpec(&mData->m->X509.TbsCertificate.Validity, RTTimeNow(&Now)) ? FALSE : TRUE;
     500    return S_OK;
     501}
     502
    395503HRESULT Certificate::queryInfo(LONG aWhat, com::Utf8Str &aResult)
    396504{
     
    400508    return setError(E_FAIL, "Unknown item %u", aWhat);
    401509}
     510
     511/** @} */
     512
     513
     514/** @name Methods extracting COM data from the certificate object
     515 * @{
     516 */
    402517
    403518HRESULT Certificate::i_getAlgorithmName(PCRTCRX509ALGORITHMIDENTIFIER a_pAlgId, com::Utf8Str &a_rReturn)
     
    506621}
    507622
    508 
     623/** @} */
     624
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette