pkiutilities/securitydialognotifiersrv/src/securitydialogoperbasicpinquery.cpp
changeset 53 25dd1e8b2663
child 66 67b3e3c1fc87
equal deleted inserted replaced
48:6ed68423b759 53:25dd1e8b2663
       
     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:  Basic PIN query operation in security dialog
       
    15 *
       
    16 */
       
    17 
       
    18 #include "securitydialogoperbasicpinquery.h" // CBasicPinQueryOperation
       
    19 #include "securitydialogoperationobserver.h" // MSecurityDialogOperationObserver
       
    20 #include <hb/hbcore/hbtextresolversymbian.h> // HbTextResolverSymbian
       
    21 #include "securitydialogstrace.h"       // TRACE macro
       
    22 
       
    23 // TODO: fix this
       
    24 #include "../../../securitydialogs/SecUi/Inc/SecQueryUi.h"  // CSecQueryUi
       
    25 
       
    26 // Descriptors for different password queries
       
    27 _LIT( KBasicPinQueryKeyStorePassphrase, "Key store passphrase" );
       
    28 _LIT( KBasicPinQueryNewKeyStorePassphrase, "New key store passphrase" );
       
    29 _LIT( KBasicPinQueryImportedKeyFilePassphrase, "Passphrase of the imported key file" );
       
    30 _LIT( KBasicPinQueryExportedKeyFilePassphrase, "Passphrase of the exported key file" );
       
    31 _LIT( KBasicPinQueryPKCS12, "PKCS12");
       
    32 
       
    33 const TInt KMinimunAcceptedKeystorePassphraseLength = 6;
       
    34 
       
    35 
       
    36 // ======== MEMBER FUNCTIONS ========
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // CBasicPinQueryOperation::NewL()
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 CBasicPinQueryOperation* CBasicPinQueryOperation::NewL(
       
    43         MSecurityDialogOperationObserver& aObserver, const RMessage2& aMessage,
       
    44         TInt aReplySlot )
       
    45     {
       
    46     TRACE( "CBasicPinQueryOperation::NewL, aMessage 0x%08x", aMessage.Handle() );
       
    47     return new( ELeave ) CBasicPinQueryOperation( aObserver, aMessage, aReplySlot );
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // CBasicPinQueryOperation::~CBasicPinQueryOperation()
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 CBasicPinQueryOperation::~CBasicPinQueryOperation()
       
    55     {
       
    56     TRACE( "CBasicPinQueryOperation::~CBasicPinQueryOperation" );
       
    57     Cancel();
       
    58     delete iQueryUi;
       
    59     iQueryUi = NULL;
       
    60     iPinInput = NULL;   // not owned
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // CBasicPinQueryOperation::StartL()
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 void CBasicPinQueryOperation::StartL( const TDesC8& aBuffer )
       
    68     {
       
    69     TRACE( "CBasicPinQueryOperation::StartL" );
       
    70     iPinInput = reinterpret_cast< const TPINInput* >( aBuffer.Ptr() );
       
    71     ASSERT( iPinInput != NULL );
       
    72 
       
    73     iStatus = KRequestPending;
       
    74     TRequestStatus* status = &iStatus;
       
    75     User::RequestComplete( status, KErrNone );
       
    76     SetActive();
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // CBasicPinQueryOperation::CancelOperation()
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 void CBasicPinQueryOperation::CancelOperation()
       
    84     {
       
    85     TRACE( "CBasicPinQueryOperation::CancelOperation" );
       
    86     // nothing to do
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // CBasicPinQueryOperation::RunL()
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 void CBasicPinQueryOperation::RunL()
       
    94     {
       
    95     TRACE( "CBasicPinQueryOperation::RunL, iStatus.Int()=%d", iStatus.Int() );
       
    96     User::LeaveIfError( iStatus.Int() );
       
    97 
       
    98     TBool isRetry = ( iPinInput->iOperation & EPINValueIncorrect );
       
    99     if( isRetry )
       
   100         {
       
   101         // Show "Invalid PIN code" error note, as previous attempt was failed.
       
   102         // TODO: localized UI string needed
       
   103         _LIT( KInvalidPinCode, "Invalid PIN code" );
       
   104         ShowWarningNoteL( KInvalidPinCode );
       
   105         }
       
   106 
       
   107     HBufC* caption = NULL;
       
   108     TInt minLength = 0;
       
   109     TInt maxLength = 0;
       
   110     TInt mode = ESecUiAlphaSupported | ESecUiSecretSupported | ESecUiCancelSupported |
       
   111             ESecUiEmergencyNotSupported;
       
   112     if( iPinInput->iPIN.iPINLabel == KBasicPinQueryKeyStorePassphrase )
       
   113         {
       
   114         // "Enter code for phone keystore:"
       
   115         minLength = KMinimunAcceptedKeystorePassphraseLength;
       
   116         // TODO: localized UI string needed
       
   117         _LIT( KText, "Keystore password:" );
       
   118         caption = KText().AllocLC();
       
   119         }
       
   120     else if( iPinInput->iPIN.iPINLabel == KBasicPinQueryNewKeyStorePassphrase )
       
   121         {
       
   122         // "Keystore password must be created for using private keys."
       
   123         minLength = KMinimunAcceptedKeystorePassphraseLength;
       
   124         // SecUi creates two input fields when caption contains two labels
       
   125         // separated with a vertical bar. SecUi verifies that user types the
       
   126         // same passphrase in both fields.
       
   127         // TODO: localized UI strings needed
       
   128         _LIT( KText, "Create keystore password:|Verify:" );
       
   129         caption = KText().AllocLC();
       
   130         }
       
   131     else if( iPinInput->iPIN.iPINLabel == KBasicPinQueryImportedKeyFilePassphrase )
       
   132         {
       
   133         // "Enter code for imported key:"
       
   134         // TODO: localized UI strings needed
       
   135         _LIT( KText, "Enter code for imported key:|Verify:" );
       
   136         caption = KText().AllocLC();
       
   137         }
       
   138     else if( iPinInput->iPIN.iPINLabel == KBasicPinQueryExportedKeyFilePassphrase )
       
   139         {
       
   140         // "Enter new code for exported key:"
       
   141         // TODO: localized UI strings needed
       
   142         _LIT( KText, "Enter new code for exported key:|Verify:" );
       
   143         caption = KText().AllocLC();
       
   144         }
       
   145     else if( iPinInput->iPIN.iPINLabel == KBasicPinQueryPKCS12 )
       
   146         {
       
   147         // "Password for %U:", PKCS#12 password query prompt
       
   148         // TODO: localized UI string needed
       
   149         _LIT( KText, "Password for PKCS#12 file:" );
       
   150         caption = KText().AllocLC();
       
   151         }
       
   152     else
       
   153         {
       
   154         // "Enter code for %0U in %1U"
       
   155         // Data query for PIN request in keystore where %0U is the PIN's name %1U is the keystore's name.
       
   156         // TODO: EEnterPinNR
       
   157         caption = iPinInput->iPIN.iPINLabel.AllocLC();
       
   158         }
       
   159 
       
   160     ASSERT( iQueryUi == NULL );
       
   161     iQueryUi = CSecQueryUi::NewL();
       
   162     TInt resultCode = iQueryUi->SecQueryDialog( *caption, iPinValue, minLength, maxLength, mode );
       
   163     ReturnResultL( resultCode );
       
   164 
       
   165     if( caption )
       
   166         {
       
   167         CleanupStack::PopAndDestroy( caption );
       
   168         caption = NULL;
       
   169         }
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // CBasicPinQueryOperation::DoCancel()
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 void CBasicPinQueryOperation::DoCancel()
       
   177     {
       
   178     TRACE( "CBasicPinQueryOperation::DoCancel" );
       
   179     if( iQueryUi )
       
   180         {
       
   181         delete iQueryUi;
       
   182         iQueryUi = NULL;
       
   183         }
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // CBasicPinQueryOperation::CBasicPinQueryOperation()
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 CBasicPinQueryOperation::CBasicPinQueryOperation(
       
   191         MSecurityDialogOperationObserver& aObserver, const RMessage2& aMessage,
       
   192         TInt aReplySlot ) : CSecurityDialogOperation( aObserver, aMessage, aReplySlot )
       
   193     {
       
   194     }
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 // CBasicPinQueryOperation::ReturnResultL()
       
   198 // ---------------------------------------------------------------------------
       
   199 //
       
   200 void CBasicPinQueryOperation::ReturnResultL( TInt aErrorCode )
       
   201     {
       
   202     TRACE( "CBasicPinQueryOperation::ReturnResultL, begin, aErrorCode=%d", aErrorCode );
       
   203     if( aErrorCode == KErrNone )
       
   204         {
       
   205         TPINValueBuf output( iPinValue );
       
   206         iMessage.WriteL( iReplySlot, output );
       
   207         }
       
   208     TRACE( "CBasicPinQueryOperation::ReturnResultL, completing msg 0x%08x", iMessage.Handle() );
       
   209     iMessage.Complete( aErrorCode );
       
   210     TRACE( "CBasicPinQueryOperation::ReturnResultL, informing observer" );
       
   211     iObserver.OperationComplete();
       
   212     TRACE( "CBasicPinQueryOperation::ReturnResultL, end" );
       
   213     }
       
   214