pkiutilities/untrustedcertificatedialog/src/untrustedcertificatewidget_symbian.cpp
changeset 26 aad866c37519
child 30 cc1cea6aabaf
equal deleted inserted replaced
22:6b63ca65093a 26:aad866c37519
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Device dialog plugin that shows untrusted certificate
       
    15 *               dialog for TLS server authentication failure errors.
       
    16 *
       
    17 */
       
    18 
       
    19 #include "untrustedcertificatewidget.h"
       
    20 #include "untrustedcertificatedefinitions.h"
       
    21 #include "untrustedcertificateinfobase.h"
       
    22 #include "untrustedcertificateinfo_symbian.h"
       
    23 #include <x509cert.h>                   // CX509Certificate
       
    24 
       
    25 
       
    26 // ======== LOCAL FUNCTIONS ========
       
    27 
       
    28 // ----------------------------------------------------------------------------
       
    29 // DoProcessEncodedCertificateL()
       
    30 // ----------------------------------------------------------------------------
       
    31 //
       
    32 UntrustedCertificateInfoBase* DoProcessEncodedCertificateL( const QByteArray &encodedCert )
       
    33 {
       
    34     TPtrC8 ptr8( reinterpret_cast<const TText8*>(encodedCert.constData()), encodedCert.length());
       
    35     CX509Certificate* cert = CX509Certificate::NewLC( ptr8 );
       
    36 
       
    37     UntrustedCertificateInfoSymbian *info = 0;
       
    38     info = new UntrustedCertificateInfoSymbian(*cert);
       
    39     CleanupStack::PopAndDestroy( cert );
       
    40 
       
    41     return info;
       
    42 }
       
    43 
       
    44 
       
    45 // ======== MEMBER FUNCTIONS ========
       
    46 
       
    47 // ----------------------------------------------------------------------------
       
    48 // UntrustedCertificateWidget::isInvalidCertificate()
       
    49 // ----------------------------------------------------------------------------
       
    50 //
       
    51 bool UntrustedCertificateWidget::isCertificateValid()
       
    52 {
       
    53     return (mValidationError != ESignatureInvalid && mValidationError != ECertificateRevoked);
       
    54 }
       
    55 
       
    56 // ----------------------------------------------------------------------------
       
    57 // UntrustedCertificateWidget::processEncodedCertificate()
       
    58 // ----------------------------------------------------------------------------
       
    59 //
       
    60 void UntrustedCertificateWidget::processEncodedCertificate(const QByteArray &encodedCert)
       
    61 {
       
    62     UntrustedCertificateInfoBase *info = 0;
       
    63     QT_TRAP_THROWING(info = DoProcessEncodedCertificateL(encodedCert));
       
    64     if (mCertificateInfo) {
       
    65         delete mCertificateInfo;
       
    66         mCertificateInfo = 0;
       
    67     }
       
    68     mCertificateInfo = info;
       
    69 }
       
    70 
       
    71 // ----------------------------------------------------------------------------
       
    72 // UntrustedCertificateWidget::descriptionText()
       
    73 // ----------------------------------------------------------------------------
       
    74 //
       
    75 QString UntrustedCertificateWidget::descriptionText()
       
    76 {
       
    77     QString text;
       
    78     if (!isCertificateValid()) {
       
    79         //: Information note text shown if the server certificate has an invalid signature
       
    80         // TODO: localised UI string
       
    81         text = tr("'%1' has sent an invalid certificate. Connection cannot be created.");
       
    82     } else if (mValidationError == EValidatedOK || mValidationError == EDateOutOfRange) {
       
    83         bool isDateValid = mCertificateInfo->isDateValid();
       
    84         bool isSiteValid = mCertificateInfo->commonNameMatches(mServerName);
       
    85         if (!isDateValid && !isSiteValid) {
       
    86             // TODO: hbTrId("txt_untrustedcert_dialog _accept_site_ood")
       
    87             text = tr("'%1' has sent a certificate with different site name and which is out of date. Accept anyway?");
       
    88         } else if (!isSiteValid) {
       
    89             // TODO: hbTrId("txt_untrustedcert_dialog _accept_site"
       
    90             text = tr("'%1' has sent a certificate with different site name. Accept anyway?");
       
    91         } else {
       
    92             // TODO: hbTrId("txt_untrustedcert_dialog_accept_ood")
       
    93             text = tr("'%1' has sent a certificate which is out of date. Accept anyway?");
       
    94         }
       
    95     } else {
       
    96         bool isDateValid = mCertificateInfo->isDateValid();
       
    97         bool isSiteValid = mCertificateInfo->commonNameMatches(mServerName);
       
    98         if (!isDateValid && !isSiteValid) {
       
    99             // TODO: hbTrId("txt_untrustedcert_dialog _accept_untrusted_site_ood"
       
   100             text = tr("'%1' has sent an untrusted certificate with different site name and which is out of date. Accept anyway?");
       
   101         } else if (!isSiteValid) {
       
   102             // TODO: hbTrId("txt_untrustedcert_dialog _accept_untrusted_site"
       
   103             text = tr("'%1' has sent an untrusted certificate with different site name. Accept anyway?");
       
   104         } else if (!isDateValid) {
       
   105             // TODO: hbTrId("txt_untrustedcert_dialog _accept_untrusted_ood")
       
   106             text = tr("'%1' has sent an untrusted certificate which is out of date. Accept anyway?");
       
   107         } else {
       
   108             // TODO: hbTrId("txt_untrustedcert_dialog _accept_untrusted"
       
   109             text = tr("'%1' has sent an untrusted certificate. Accept anyway?");
       
   110         }
       
   111     }
       
   112     return text;
       
   113 }
       
   114