wim/WimServer/src/WimKeyMgmtHandler.cpp
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2002-2009 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:  Key management services
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "WimKeyMgmtHandler.h"
       
    22 #include    "WimSession.h"
       
    23 #include    "WimConsts.h"
       
    24 #include    "WimMemMgmt.h"
       
    25 #include    "WimUtilityFuncs.h"
       
    26 #include    "WimTrace.h"
       
    27 
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CWimKeyMgmtHandler::CWimKeyMgmtHandler
       
    33 // C++ default constructor can NOT contain any code, that
       
    34 // might leave.
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CWimKeyMgmtHandler::CWimKeyMgmtHandler()
       
    38     {
       
    39     _WIMTRACE(_L("WIM | WIMServer | CWimKeyMgmtHandler::CWimKeyMgmtHandler | Begin"));
       
    40     }
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CWimKeyMgmtHandler::ConstructL
       
    44 // Symbian 2nd phase constructor can leave.
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 void CWimKeyMgmtHandler::ConstructL()
       
    48     {
       
    49     _WIMTRACE(_L("WIM | WIMServer | CWimKeyMgmtHandler::ConstructL | Begin"));
       
    50     iWimUtilFuncs = CWimUtilityFuncs::NewL();
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CWimKeyMgmtHandler::NewL
       
    55 // Two-phased constructor.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CWimKeyMgmtHandler* CWimKeyMgmtHandler::NewL()
       
    59     {
       
    60     _WIMTRACE(_L("WIM | WIMServer | CWimKeyMgmtHandler::NewL | Begin"));
       
    61     CWimKeyMgmtHandler* self = new( ELeave ) CWimKeyMgmtHandler;
       
    62     CleanupStack::PushL( self );
       
    63     self->ConstructL();
       
    64     CleanupStack::Pop( self );
       
    65     return self;
       
    66     }
       
    67     
       
    68 // Destructor
       
    69 CWimKeyMgmtHandler::~CWimKeyMgmtHandler()
       
    70     {
       
    71     _WIMTRACE(_L("WIM | WIMServer | CWimKeyMgmtHandler::~CWimKeyMgmtHandler | Begin"));
       
    72     delete iWimUtilFuncs;
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CWimKeyMgmtHandler::DoesKeyExistL
       
    77 // Checks if the given key exists.
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 void CWimKeyMgmtHandler::DoesKeyExistL( const RMessage2& aMessage )
       
    81     {
       
    82     _WIMTRACE(_L("WIM | WIMServer | CWimKeyMgmtHandler::DoesKeyExistL | Begin"));
       
    83     HBufC8* buf = iWimUtilFuncs->DesLC( 0, aMessage );
       
    84     TUint8* keyHash = const_cast<TUint8*>( buf->Des().Ptr() );
       
    85     WIMI_Ref_t* tmpKeyRef = NULL;
       
    86     WIMI_STAT status = WIMI_GetKeyByHash( keyHash, &tmpKeyRef );
       
    87     if ( status == WIMI_Ok )
       
    88         {
       
    89         free_WIMI_Ref_t( tmpKeyRef );
       
    90         }
       
    91     CleanupStack::PopAndDestroy( buf );
       
    92     aMessage.Complete( CWimUtilityFuncs::MapWIMError( status ) );
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CWimKeyMgmtHandler::GetKeyDetailsL
       
    97 // Fetches the details of the given key.
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 void CWimKeyMgmtHandler::GetKeyDetailsL( const RMessage2& aMessage )
       
   101     { 
       
   102     _WIMTRACE(_L("WIM | WIMServer | CWimKeyMgmtHandler::GetKeyDetailsL | Begin"));
       
   103     WIMI_Ref_t* pKeyRef = const_cast<WIMI_Ref_pt>( aMessage.Ptr0() );
       
   104         
       
   105     WIMI_Ref_t* pWimRef;    
       
   106     TUint8 keyType;
       
   107     TUint8 keyNumber;
       
   108     TUint8 pinNumber;
       
   109     TUint16 usage;
       
   110     TUint16 key_length;
       
   111     WIMI_BinData_t pt_label;
       
   112     WIMI_BinData_t pt_keyid;
       
   113 
       
   114     WIMI_STAT callStatus = WIMI_GetKeyInfo( pKeyRef,
       
   115                                             &pWimRef,
       
   116                                             NULL,
       
   117                                             &keyType,
       
   118                                             &keyNumber,
       
   119                                             &pinNumber,
       
   120                                             &usage,
       
   121                                             &pt_keyid,
       
   122                                             &pt_label,
       
   123                                             &key_length );
       
   124 
       
   125     if ( callStatus == WIMI_Ok )
       
   126         {
       
   127         // Code MAY NOT leave before pWimRef, pt_keyid.pb_buf, and
       
   128         // pt_label.pb_buf are deallocated.
       
   129 
       
   130         free_WIMI_Ref_t( pWimRef );
       
   131 
       
   132         TPckgBuf<TKeyInfo> keyInfoPckg;
       
   133         TInt readErr = aMessage.Read( 1, keyInfoPckg );
       
   134         if( readErr )
       
   135             {
       
   136             WSL_OS_Free( pt_label.pb_buf );
       
   137             WSL_OS_Free( pt_keyid.pb_buf );
       
   138             // Code can leave after this point.
       
   139             User::Leave( readErr );
       
   140             }
       
   141 
       
   142         keyInfoPckg().iLabel.Copy( TPtr8(
       
   143                 pt_label.pb_buf, pt_label.ui_buf_length,
       
   144                 pt_label.ui_buf_length ) );
       
   145 
       
   146         keyInfoPckg().iKeyId.Copy( TPtr8(
       
   147                 pt_keyid.pb_buf, pt_keyid.ui_buf_length,
       
   148                 pt_keyid.ui_buf_length ) );
       
   149 
       
   150         keyInfoPckg().iType = keyType;
       
   151         keyInfoPckg().iUsage = usage;
       
   152         keyInfoPckg().iLength = key_length;
       
   153         keyInfoPckg().iKeyNumber = keyNumber;
       
   154         keyInfoPckg().iPinNumber = pinNumber;
       
   155 
       
   156         WSL_OS_Free( pt_label.pb_buf );
       
   157         WSL_OS_Free( pt_keyid.pb_buf );
       
   158         // Code can leave after this point.
       
   159 
       
   160         aMessage.WriteL( 1, keyInfoPckg );
       
   161         }
       
   162     aMessage.Complete( CWimUtilityFuncs::MapWIMError( callStatus ) );
       
   163     }
       
   164 
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 // CWimKeyMgmtHandler::GetKeyListL
       
   168 // Fetches the list of keys in a Wim.
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 void CWimKeyMgmtHandler::GetKeyListL(
       
   172     const RMessage2& aMessage,
       
   173     CWimMemMgmt* aWimMgmt ) const
       
   174     {
       
   175     _WIMTRACE(_L("WIM | WIMServer | CWimKeyMgmtHandler::GetKeyListL | Begin"));
       
   176     HBufC8* keyInfo = HBufC8::NewLC( KLabelLen );
       
   177     TPtr8 ptr = keyInfo->Des();
       
   178 
       
   179     WIMI_STAT status;
       
   180     WIMI_Ref_t* wimRef = aWimMgmt->WimRef();
       
   181     TUint16 keyNum = 0;
       
   182     WIMI_RefList_t refList;
       
   183 
       
   184     status = WIMI_GetKeyListByWIM( wimRef, &keyNum, &refList );
       
   185     if ( status == WIMI_Ok )
       
   186         {
       
   187         for ( TUint8 keyIndex = 0; keyIndex < keyNum; keyIndex++ )
       
   188             {
       
   189             ptr.AppendNum( ( TInt32 ) refList[keyIndex], EDecimal );
       
   190             ptr.Append( _L8(" ") ); //Space character
       
   191             }
       
   192         aWimMgmt->AppendWIMRefLstL( refList );
       
   193         }
       
   194     aMessage.WriteL( 0, keyInfo->Des() );
       
   195     TPckg<TInt> pckg( keyNum );
       
   196     aMessage.WriteL( 1, pckg );
       
   197     CleanupStack::PopAndDestroy( keyInfo );
       
   198     aMessage.Complete( CWimUtilityFuncs::MapWIMError( status ) );
       
   199     }
       
   200 
       
   201 //  End of File