pkiutilities/CertSaver/inc/CertSaverModel.h
changeset 0 164170e6151a
child 30 cc1cea6aabaf
child 49 09b1ac925e3f
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2003-2007 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:   Model of the CertSaver. Saves the keys and certificates
       
    15 *              : to the databases and shows appropriate dialogs for user
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef CERTSAVERMODEL_H
       
    21 #define CERTSAVERMODEL_H
       
    22 
       
    23 // INCLUDES
       
    24 #include <f32file.h>
       
    25 #include <e32std.h>
       
    26 #include <ct/rmpointerarray.h>
       
    27 #include <securitydefs.h>
       
    28 #include <mpkcs12.h>
       
    29 #include <cctcertinfo.h>
       
    30 #include <signed.h>
       
    31 
       
    32 // FORWARD DECLARATIONS
       
    33 class CCertSaverDocument;
       
    34 class CCertSaverAppUi;
       
    35 class RFs;
       
    36 class CCertSaverSyncWrapper;
       
    37 class CUnifiedCertStore;
       
    38 class CCTCertInfo;
       
    39 class CX509Certificate;
       
    40 class TCertificateAppInfo;
       
    41 class CCertParser;
       
    42 
       
    43 // CONSTANTS
       
    44 
       
    45 
       
    46 // CLASS DECLARATION
       
    47 
       
    48 
       
    49 /**
       
    50 * CCertSaverModel dialog class.
       
    51 * Saves certificates and shows
       
    52 * needed queries and error notes for user.
       
    53 */
       
    54 class CCertSaverModel : public CBase
       
    55     {
       
    56 
       
    57     public: // Constructors and destructor
       
    58 
       
    59         CCertSaverModel( CCertSaverAppUi* aAppUi, const CCertParser& aParser );
       
    60 
       
    61         /**
       
    62         * Destructor.
       
    63         */
       
    64         ~CCertSaverModel();
       
    65 
       
    66     public: // New functions
       
    67 
       
    68         void SaveCertificateL(
       
    69                 const CX509Certificate& aCertificate,
       
    70                 const TCertificateOwnerType& aOwnerType,
       
    71                 const TCertificateFormat& aCertFormat );
       
    72 
       
    73          /**
       
    74         * Saves content of the PKCS#12 PDU.
       
    75         * @param void
       
    76         */
       
    77         void SavePKCS12L();
       
    78 
       
    79 
       
    80         /**
       
    81         * Shows a error note with given text.
       
    82         * @param aResourceID Id of the resource text to be shown.
       
    83         */
       
    84         void ShowErrorNoteL( TInt aResourceID ) const;
       
    85 
       
    86     private:  // New functions
       
    87 
       
    88         /**
       
    89         * Initialises unified certstore.
       
    90         */
       
    91         void InitCertStoreL();
       
    92 
       
    93          /**
       
    94         * Checks that there is enough space in filesystem
       
    95         * @param aDataToSave Data to be saved.
       
    96         */
       
    97         void CheckFSSpaceL( const TDesC8& aDataToSave );
       
    98 
       
    99         void SaveCertL();
       
   100 
       
   101         void SavePrivateKeyL();
       
   102 
       
   103         void DoSavePrivateKeyL( const TDesC8& aKey );
       
   104 
       
   105         void CreateKeyLabelL( TDes& aLabel );
       
   106 
       
   107         void GetKeyValidityPeriodL(
       
   108             TTime& aStartDate,
       
   109             TTime& aEndDate,
       
   110             const TKeyIdentifier& aKeyIdentifier );
       
   111 
       
   112         TKeyUsagePKCS15 KeyUsageL(
       
   113             const TKeyIdentifier& aKeyIdentifier,
       
   114             TAlgorithmId aAlgorithm );
       
   115 
       
   116         TBool KeyAlreadyExistsL(
       
   117             TTime& aStartDate,
       
   118             TTime& aEndDate,
       
   119             const TKeyIdentifier& aKeyIdentifier,
       
   120             TKeyUsagePKCS15& aKeyUsage );
       
   121 
       
   122         /**
       
   123         * Saves certificate to database in phone memory.
       
   124         */
       
   125         void DoSaveCertL();
       
   126 
       
   127         /**
       
   128         * Shows appropriate error note if something odd happeneds
       
   129         * certificate is saved. Shows also note if everything
       
   130         * goes fine.
       
   131         * @param aStatus Status of the save operation.
       
   132         */
       
   133         void HandleSaveErrorL( TInt aStatus ) const;
       
   134 
       
   135         /**
       
   136         * Adds string to aMessage.
       
   137         * @param aMessage Buffer where message is saved.
       
   138         * @param aStringResID id of the string to be added. Read from resources.
       
   139         */
       
   140         void AddToMessageL( TDes& aMessage, TInt aStringResID ) const;
       
   141 
       
   142         /**
       
   143         * Constructs the message shown to user in details-dialog.
       
   144         * @param aMessage Buffer where message is saved.
       
   145         */
       
   146         void ConstructMessageL( TDes& aMessage ) const;
       
   147 
       
   148         /**
       
   149         * Constructs the message shown to user in pkcs#12
       
   150         * file contents and saving completed queries.
       
   151         * @param aMessage Buffer where message is saved.
       
   152         */
       
   153         void ConstructPKCS12QueryMsgL(
       
   154             TDes& aMessage,
       
   155             TInt aPrivateKeys,
       
   156             TInt aUserCerts,
       
   157             TInt aCACerts ) const;
       
   158 
       
   159         /**
       
   160         * Adds string to aMessage.
       
   161         * @param aMessage Buffer where message is saved.
       
   162         * @param aStringResID id of the string to be added. Read from resources.
       
   163         * @param aString Replaces the first (and only) %U parameter in resources.
       
   164         */
       
   165         void AddToMessageWithStringL(
       
   166             TDes& aMessage,
       
   167             TInt aStringResID,
       
   168             const TDesC& aString ) const;
       
   169 
       
   170         /**
       
   171         * Adds string to aMessage.
       
   172         * @param aMessage Buffer where message is saved.
       
   173         * @param aStringResID id of the string to be added. Read from resources.
       
   174         * @param aString Replaces the first (and only) %U parameter in resources.
       
   175         */
       
   176         void AddToMessageWithIntL(
       
   177             TDes& aMessage,
       
   178             TInt aStringResID,
       
   179             TInt aInt ) const;
       
   180 
       
   181         /**
       
   182         * Adds validity period of the certificate to aMessage.
       
   183         * @param aMessage Buffer where message is appended.
       
   184         * @param aCert Certificate
       
   185         */
       
   186         void AddValidityPeriodL( TDes& aMessage, const CX509Certificate& ) const;
       
   187 
       
   188         /**
       
   189         * Adds key usage of the certificate to aMessage.
       
   190         * @param aMessage Buffer where message is appended.
       
   191         * @param aCert Certificate
       
   192         */
       
   193         void AddKeyUsageL( TDes& aMessage, const CX509Certificate& aCert ) const;
       
   194 
       
   195         /**
       
   196         * Adds new lines to message.
       
   197         * @param aMessage Buffer where message is saved.
       
   198         */
       
   199         void AddNewlinesToMessage( TDes& aMessage ) const;
       
   200 
       
   201         /**
       
   202         * Shows a confirmation note with given text.
       
   203         * @param aResourceID Id of the resource text to be shown.
       
   204         */
       
   205         void ShowConfirmationNoteL( TInt aResourceID ) const;
       
   206 
       
   207         /**
       
   208         * Shows a information note with given text.
       
   209         * @param aResourceID Id of the resource text to be shown.
       
   210         */
       
   211         void ShowInformationNoteL( TInt aResourceID ) const;
       
   212 
       
   213         /**
       
   214         * Checks that certificate is ok. That is, it's not
       
   215         * corrupted and it's of supported type. If certificate
       
   216         * is not ok an error note is displayed. If certificate
       
   217         * is not valid yet/anymore an error note is displayed
       
   218         * but certificate is considered to be ok ie. can be saved anyway.
       
   219         * @return TBool ETrue if ok else EFalse.
       
   220         */
       
   221         TBool CertificateOkL() const;
       
   222 
       
   223         /**
       
   224         * Checks that certificate is of supported type.
       
   225         * @return TBool ETrue if supported else EFalse.
       
   226         */
       
   227         TBool CertificateSupported() const;
       
   228 
       
   229         /**
       
   230         * Checks if certificate isn't valid anymore.
       
   231         * @return TBool ETrue if not valid else EFalse.
       
   232         */
       
   233         TBool CertNotValidAnymore() const;
       
   234 
       
   235         /**
       
   236         * Checks if certificate isn't valid yet.
       
   237         * @return TBool ETrue if not valid else EFalse.
       
   238         */
       
   239         TBool CertNotValidYet() const;
       
   240 
       
   241         /**
       
   242         * Trims given descriptor so that everything after and
       
   243         * including the fourth semicolon (;) is cropped. .
       
   244         * @param aField data to be trimmed.
       
   245         * @return TPtrC trimmed content
       
   246         */
       
   247         TPtrC TrimCertificateFields( TPtrC aField ) const;
       
   248 
       
   249         /**
       
   250         * If given descriptor contains more than 80
       
   251         * characters, this function cut it to 80.
       
   252         * @param aField data to be possibly cut.
       
   253         * @return TPtrC trimmed content
       
   254         */
       
   255         TPtrC CutCertificateField( TPtrC aField ) const;
       
   256 
       
   257         /**
       
   258         * Queries label from user and confirms that label doesn't already
       
   259         * exist.
       
   260         * @param aLabel IN Default label of the Certificate
       
   261         *               OUT Unique label that might been changed by user
       
   262         * @param aStore Unified Certificate Store
       
   263         * @return KErrNone if everything is ok.
       
   264         *         KErrCancel if user pressed cancel
       
   265         *         Otherwise status of the list operation.
       
   266         *
       
   267         */
       
   268         TInt QueryLabelL( TCertLabel& aLabel, CUnifiedCertStore& aStore );
       
   269 
       
   270         /**
       
   271         * Queries trust settings from user
       
   272         * @param OUT aUids contains user selected uids of
       
   273         * the trusted applications
       
   274         * @return KErrNone if everything is ok.
       
   275         *         KErrCancel if user pressed cancel
       
   276         *         Otherwise status of the list operation.
       
   277         *
       
   278         */
       
   279         TInt QueryTrusterUidsL( RArray<TUid>& aUids );
       
   280 
       
   281         /**
       
   282         * Queries trust site certificate from user
       
   283         * @param
       
   284         * @return KErrNone if everything is ok.
       
   285         *         KErrCancel if user pressed cancel
       
   286         *         Otherwise status of the list operation.
       
   287         *
       
   288         */
       
   289         TInt QueryTrustedSiteL();
       
   290 
       
   291         /**
       
   292         * Updates localised strings to listbox item array
       
   293         * @param aApps All trusted applications
       
   294         * @param aAppsInItemArray Trusted applications in right order.
       
   295         * @param aItemsArray Localised strings in same order.
       
   296         * @return void
       
   297         *
       
   298         */
       
   299         void UpdateTrustListboxItemL(
       
   300             const RArray<TCertificateAppInfo>& aApps,
       
   301             RArray<TCertificateAppInfo>& aAppsInItemArray,
       
   302             CDesCArray& aItemsArray ) const;
       
   303 
       
   304         /**
       
   305         * Divides string to four characters blocks
       
   306         * and delimits them with space.
       
   307         * @param aInput String to devide
       
   308         * @param aOutput Descriptor where result is appended
       
   309         * @return void
       
   310         */
       
   311         void DivideToBlocks( const TDesC8& aInput, TDes& aOutput ) const;
       
   312 
       
   313         TBool DoMessageQueryL(
       
   314             TInt aDialogResId,
       
   315             TInt aHeadingResId,
       
   316             TDesC& aMessage );
       
   317 
       
   318     private: //data
       
   319         TCertificateOwnerType     iCertOwnerType;
       
   320         TCertificateFormat        iCertFormat;
       
   321         const CCertSaverDocument* iDocument;
       
   322         CCertSaverAppUi*          iAppUi;
       
   323         CCertSaverSyncWrapper*    iWrapper;    // synchronous wrapper
       
   324 
       
   325         // variables for SaveCertL
       
   326         CUnifiedCertStore*          iUnifiedCertStore;
       
   327         RMPointerArray<CCTCertInfo> iEntries;
       
   328         const CCertificate*         iNewCert;
       
   329         RArray<TUid>                iTrusterUids;
       
   330         RFs& iFs;
       
   331 
       
   332         const CCertParser& iParser;
       
   333 
       
   334         TInt  iSavedCACertsCount;
       
   335         TInt  iSavedKeysCount;
       
   336         TInt  iSavedUserCertsCount;
       
   337         TInt  iSelectedKeyStore;
       
   338         TBool iKeyAlreadyExists;
       
   339     };
       
   340 
       
   341 #endif
       
   342 
       
   343 // End of File