javaextensions/satsa/apdu/src.s60/cstspinmanager.h
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 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:
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CSTSPINMANAGER_H
       
    20 #define CSTSPINMANAGER_H
       
    21 
       
    22 //  INCLUDES
       
    23 #include <e32base.h>
       
    24 #include <secdlg.h>
       
    25 #include "cstspinapdu.h"    // for TPinApduType
       
    26 #include "functionserver.h"
       
    27 #include "cstsconnection.h"
       
    28 #include <jni.h>
       
    29 
       
    30 class SecurityDialogFactory;
       
    31 class MSecurityDialog;
       
    32 
       
    33 namespace java
       
    34 {
       
    35 namespace satsa
       
    36 {
       
    37 
       
    38 // FORWARD DECLARATIONS
       
    39 
       
    40 
       
    41 class CSTSApduExchanger;
       
    42 class CSTSAccessControl;
       
    43 class CSTSAuthType;
       
    44 class CSTSPinAttributes;
       
    45 class CSTSPinApduResp;
       
    46 class MSTSRespHandler;
       
    47 
       
    48 // CLASS DECLARATION
       
    49 
       
    50 /**
       
    51  *  Handles PIN related methods and shows needed UIs.
       
    52  *
       
    53  *  @since 3.0
       
    54  */
       
    55 NONSHARABLE_CLASS(CSTSPinManager): public CActive
       
    56 {
       
    57 
       
    58 public: // data types
       
    59     enum TPinRetryCounter
       
    60     {
       
    61         EFirstTime = 0,
       
    62         ERetrying = 1,
       
    63         EPINBlocked = 2
       
    64     };
       
    65 private:
       
    66     enum TPinManagerState
       
    67     {
       
    68         EShowingPinBlockedUI,
       
    69         EShowing1ValuePinUI,
       
    70         EShowing2ValuePinUI,
       
    71         ESendingPINApdu
       
    72     };
       
    73 
       
    74 public: // Constructors and destructor
       
    75 
       
    76     /**
       
    77      * Two-phased constructor.
       
    78      */
       
    79     static CSTSPinManager* NewL(JNIEnv* aJni,jobject aPeer,
       
    80                                 CSTSApduExchanger* aApduExchanger,
       
    81                                 CSTSAccessControl* aAccessControl,
       
    82                                 MSTSRespHandler* aRespHandler);
       
    83 
       
    84     /**
       
    85      * Destructor.
       
    86      */
       
    87     virtual ~CSTSPinManager();
       
    88 
       
    89 public: // New functions
       
    90 
       
    91     /**
       
    92      * Uses UI for getting PIN value from user. Constructs
       
    93      * needed APDU message and sends it to card. Returns
       
    94      * response adpu to caller.
       
    95      * @since 3.0
       
    96      * @param aPinID Which PIN value will be used
       
    97      */
       
    98     void DisablePinL(TInt aPinID);
       
    99 
       
   100     /**
       
   101      * Uses UI for getting PIN value from user. Constructs
       
   102      * needed APDU message and sends it to card. Returns
       
   103      * response adpu to caller.
       
   104      * @since 3.0
       
   105      * @param aPinID Which PIN value will be used
       
   106      */
       
   107     void ChangePinL(TInt aPinID);
       
   108 
       
   109     /**
       
   110      * Uses UI for getting PIN value from user. Constructs
       
   111      * needed APDU message and sends it to card. Returns
       
   112      * response adpu to caller.
       
   113      * @since 3.0
       
   114      * @param aPinID Which PIN value will be used
       
   115      */
       
   116     void EnablePinL(TInt aPinID);
       
   117 
       
   118     /**
       
   119      * Uses UI for getting PIN value from user. Constructs
       
   120      * needed APDU message and sends it to card. Returns
       
   121      * response adpu to caller.
       
   122      * @since 3.0
       
   123      * @param aPinID Which PIN value will be used
       
   124      */
       
   125     void EnterPinL(TInt aPinID);
       
   126 
       
   127     /**
       
   128      * Uses UI for getting PIN values from user. Constructs
       
   129      * needed APDU message and sends it to card. Returns
       
   130      * response adpu to caller.
       
   131      * @since 3.0
       
   132      * @param aBlockedPinID Which PIN value is blocked
       
   133      * @param aUnblockedPinID Which PIN value will unblock the PIN
       
   134      */
       
   135     void UnblockPinL(TInt aBlockedPinID, TInt aUnblockedPinID);
       
   136 
       
   137     /**
       
   138      * Cancels pin method operation execution.
       
   139      * @since 3.0
       
   140      */
       
   141     void CancelOperation();
       
   142 
       
   143 protected: // Functions from base classes
       
   144 
       
   145     /**
       
   146      * From CActive RunL
       
   147      * @return void
       
   148      */
       
   149     void RunL();
       
   150 
       
   151     /**
       
   152      * From CActive Cancel request
       
   153      * @return void
       
   154      */
       
   155     void DoCancel();
       
   156 
       
   157     /**
       
   158      * From CActive RunError
       
   159      * @return The leave code
       
   160      */
       
   161     TInt RunError(TInt aError);
       
   162 
       
   163 private:
       
   164 
       
   165     /**
       
   166      * C++ default constructor.
       
   167      */
       
   168     CSTSPinManager(CSTSApduExchanger* aApduExchanger,
       
   169                    CSTSAccessControl* aAccessControl,
       
   170                    MSTSRespHandler* aRespHandler);
       
   171 
       
   172     /**
       
   173      * By default Symbian 2nd phase constructor is private.
       
   174      */
       
   175     void ConstructL();
       
   176 
       
   177     /**
       
   178      * Convert gived PIN value to needed form with help of PIN attributes
       
   179      * @since 3.0
       
   180      * @param aPinAttributes PIN attributes
       
   181      * @param aPinValue PIN value which must be converted
       
   182      * @param aConvertedPIN Adds converted PIN to this buffer
       
   183      */
       
   184     void ConvertPINL(const CSTSPinAttributes& aPinAttributes,
       
   185                      const TDes& aPinValue,
       
   186                      HBufC8*& aConvertedPIN);
       
   187 
       
   188     /**
       
   189      * Makes preparation common for all PIN methods.
       
   190      * @since 3.0
       
   191      * @param aPinApduType Type of PIN APDU
       
   192      * @param aFirstPinID PIN id number
       
   193      * @param aUnblockedPinID Unblocked PIN id number in Unblock case.
       
   194      *                       Otherwise can be left empty.
       
   195      */
       
   196     void PreparePinMethodL(CSTSPinApdu::TSTSPinApduType aPinApduType,
       
   197                            TInt aFirstPinID,
       
   198                            TInt aUnblockedPinID = KErrNotFound);
       
   199 
       
   200     /**
       
   201      * Shows correct PIN UI depending on PIN apdu type
       
   202      * @since 3.0
       
   203      * @param aPinApduType Type of PIN APDU
       
   204      */
       
   205     void ShowPinUI(CSTSPinApdu::TSTSPinApduType aPinApduType);
       
   206 
       
   207     /**
       
   208      * Delivers responsebytes to response handler (to java side).
       
   209      * @since 3.0
       
   210      */
       
   211     void DeliverResponseL();
       
   212 
       
   213     /**
       
   214      * Sets needed parameters for PIN UI.
       
   215      * @since 3.0
       
   216      * @param aAuthType Authtype where parameters will be get
       
   217      * @param aPINParams Object where parameters will be set
       
   218      */
       
   219     void SetPINUIParametersL(const CSTSAuthType* aAuthType,
       
   220                              TPINParams& aPINParams);
       
   221 
       
   222     /**
       
   223      * Does needed operations after APDU is send and response
       
   224      * is got from card.
       
   225      * @since 3.0
       
   226      */
       
   227     void DoAfterSendApduL();
       
   228 
       
   229     /**
       
   230      * Does needed operations after PIN UI of one PIN value is
       
   231      * showed to user.
       
   232      * @since 3.0
       
   233      */
       
   234     void DoAfter1ValuePinUIL();
       
   235 
       
   236     /**
       
   237      * Does needed operations after PIN UI of two PIN value is
       
   238      * showed to user.
       
   239      * @since 3.0
       
   240      */
       
   241     void DoAfter2ValuePinUIL();
       
   242 
       
   243     /**
       
   244      * Finds proper maximum length of PIN.
       
   245      * @since 3.0
       
   246      * @param aAuthType Authtype where lengths will be get
       
   247      * @param aReturnBiggest If there is need to get maxlength or
       
   248      * stored length depending on which one is biggest for buffer creation
       
   249      * purposes this must be set to ETrue.
       
   250      */
       
   251     TInt PINMaxLength(const CSTSAuthType* aAuthType,
       
   252                       TBool aReturnBiggest = EFalse) const;
       
   253 
       
   254 private: // Data
       
   255 
       
   256     MSecurityDialog* iSecurityDialog;
       
   257     CSTSApduExchanger* iApduExchanger; //not owned
       
   258     CSTSAccessControl* iAccessControl; //not owned
       
   259 
       
   260     TPINParams iPINParamsFirstPin;
       
   261     TPINParams iPINParamsSecondPin;
       
   262 
       
   263     //pointer to authTypes, owned
       
   264     CSTSAuthType* iAuthTypeFirstPin;
       
   265     CSTSAuthType* iAuthTypeSecondPin;
       
   266 
       
   267     //save information of current PIN retry state
       
   268     TPinRetryCounter iRetries;
       
   269 
       
   270     CSTSCmdApdu* iPinApdu; //owned
       
   271     CSTSPinApduResp* iPinApduResp; //owned
       
   272 
       
   273     MSTSRespHandler* iRespHandler; //not owned
       
   274 
       
   275     HBufC8* iResponseBuf;
       
   276 
       
   277     TPinManagerState iState;
       
   278 
       
   279     //PIN UI returned pin will be put to this
       
   280     TPINValue iPinValueForFirstPin;
       
   281     TPINValue iPinValueForSecondPin;
       
   282 
       
   283     //saves information which pin method is called
       
   284     CSTSPinApdu::TSTSPinApduType iPinApduType;
       
   285     JNIEnv* mJni;
       
   286     jobject mPeer;
       
   287 };
       
   288 
       
   289 } //namespace satsa
       
   290 } //namespace java
       
   291 #endif // CSTSPINMANAGER_H
       
   292 // End of File