vpnengine/ikev1lib/inc/credentialcache.h
branchRCL_3
changeset 41 e06095241a65
parent 38 9f4e37332ce5
equal deleted inserted replaced
40:473321461bba 41:e06095241a65
       
     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:  Cache for authentication credentials
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef CREDENTIALCACHE_H
       
    19 #define CREDENTIALCACHE_H
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <vpnapidefs.h>
       
    23 
       
    24 
       
    25 class MIkeDebug;
       
    26 
       
    27 
       
    28 const TInt KCredentialMaxLen = 64;
       
    29 
       
    30 
       
    31 /**
       
    32  * Cache buffer stored to file.
       
    33  */
       
    34 struct TCacheBuffer{
       
    35   TVpnPolicyId             iId;
       
    36   TBuf8<KCredentialMaxLen> iUser;
       
    37   TBuf8<KCredentialMaxLen> iSecret;
       
    38 };
       
    39 
       
    40 
       
    41 /**
       
    42  * Cache for authentication credentials.
       
    43  * The public interface of the class has been
       
    44  * designed for CTransNegotiation use.
       
    45  *
       
    46  * Error handling:
       
    47  * The methods return error code or leave only if
       
    48  * it is useful for the method caller to handle the error.
       
    49  * The user of CCredentialCache must work even if the
       
    50  * cache fails. (The credentials are asked from user in that case.)
       
    51  *
       
    52  * Example usage sequence:
       
    53  *   NewL
       
    54  *   SetUserName
       
    55  *   SetSecret
       
    56  *   Store
       
    57  *   GetCredentials
       
    58  */
       
    59 NONSHARABLE_CLASS( CCredentialCache ) : public CBase{
       
    60   public:
       
    61     /**
       
    62      * Two-phased constructor.
       
    63      * @param aDebug Debug log interface.
       
    64      */
       
    65     static CCredentialCache* NewL( MIkeDebug& aDebug );
       
    66 
       
    67     ~CCredentialCache();
       
    68 
       
    69     /**
       
    70      * Sets user-name. Does not store to file.
       
    71      * @param aUser User name.
       
    72      */
       
    73     void SetUserName( const TDesC8& aUser );
       
    74 
       
    75     /**
       
    76      * Sets secret, e.g. password. Does not store to file.
       
    77      * @param aSecret Secret, e.g. password.
       
    78      */
       
    79     void SetSecret( const TDesC8& aSecret );
       
    80 
       
    81     /**
       
    82      * Gets credentials from cache file.
       
    83      * Caller is responsible for deallocating aUser and aSecret.
       
    84      *
       
    85      * @param aVpnApId VPN access point id
       
    86      * @param aUser On return, user name.
       
    87      * @param aSecret On return, secret.
       
    88      *
       
    89      * @return KErrNone if credentials are fetched from cache.
       
    90      * @return System-wide error code if cached credentials are not available.
       
    91      */
       
    92     TInt GetCredentials(
       
    93         const TUint32 aVpnApId, HBufC8*& aUser, HBufC8*& aSecret
       
    94     );
       
    95 
       
    96     /**
       
    97      * Stores user-name and secret to private file.
       
    98      * @param aVpnApId VPN access point id.
       
    99      */
       
   100     void Store( const TUint32 aVpnApId );
       
   101 
       
   102     /**
       
   103      * Clears cache.
       
   104      */
       
   105     void Clear();
       
   106 
       
   107   private:
       
   108     CCredentialCache( MIkeDebug& aDebug );
       
   109 
       
   110     void ConstructL();
       
   111 
       
   112     /**
       
   113      * Gets credentials from cache file.
       
   114      */
       
   115     TInt GetCredentialsL(
       
   116         const TUint32 aVpnApId, HBufC8*& aUser, HBufC8*& aSecret
       
   117     );
       
   118 
       
   119     /**
       
   120      * Stores user-name and secret to private file.
       
   121      */
       
   122     void StoreL( const TUint32 aVpnApId );
       
   123 
       
   124     TInt CheckCredential( const TDesC8& cr );
       
   125 
       
   126     /**
       
   127      * Stores cache to private file.
       
   128      */
       
   129     void StoreToFileL();
       
   130 
       
   131     /**
       
   132      * Reads cache data to iBuf.
       
   133      */ 
       
   134     TInt ReadFile();
       
   135 
       
   136     /**
       
   137      * Stores file name with path to iFileName.
       
   138      * Creates private path if needed.
       
   139      */
       
   140     TInt CreateFileNameAndPath();
       
   141 
       
   142     RFs iFs;
       
   143 
       
   144     TCacheBuffer iBuf;
       
   145 
       
   146     TFileName iFileName;
       
   147 
       
   148     MIkeDebug& iDebug;
       
   149 };
       
   150 
       
   151 
       
   152 #endif  // CREDENTIALCACHE_H