policymanagement/policyengine/policyengineserver/src/PolicyProcessor.cpp
changeset 72 8ee66fcd0a7c
parent 57 f5b689a4f7a2
child 73 ae69c2e8bc34
equal deleted inserted replaced
68:415c00f1675d 72:8ee66fcd0a7c
    31 #include "PolicyEngineClientServer.h"
    31 #include "PolicyEngineClientServer.h"
    32 #include "debug.h"
    32 #include "debug.h"
    33 #include <hbdevicedialogsymbian.h>
    33 #include <hbdevicedialogsymbian.h>
    34 #include <hbdevicenotificationdialogsymbian.h>
    34 #include <hbdevicenotificationdialogsymbian.h>
    35 #include <hbtextresolversymbian.h>
    35 #include <hbtextresolversymbian.h>
       
    36 
       
    37 #include "DMUtilClient.h"
       
    38 #include "PMUtilInternalCRKeys.h"
       
    39 
       
    40 #include <eikenv.h>
       
    41 #include <centralrepository.h>
       
    42 
       
    43 #include <s32mem.h>
    36 // CONSTANTS
    44 // CONSTANTS
    37 const TUid KUidPolicyEngineUi = { 0x10207817 };
    45 const TUid KUidPolicyEngineUi = { 0x10207817 };
    38 const TUint KDelimeterChar = '|';
    46 const TUint KDelimeterChar = '|';
    39 _LIT8( KUserAcceptMark, "A");
    47 _LIT8( KUserAcceptMark, "A");
       
    48 
       
    49 const TInt KMaxServerIdLength = 250;
       
    50 const TInt KMaxLabelIdLength = 25;
       
    51 const TInt KMaxCertSize = 1024;
       
    52         
       
    53 _LIT(KSymbianCertificateStoreLabel, "Software certificate store");
       
    54 _LIT(KDMTrustedCertLabel,"DMTrustedServer_");
       
    55 _LIT8(KNoKeyFound,"");
    40 
    56 
    41 enum TUserResponse
    57 enum TUserResponse
    42     {
    58     {
    43     EUserAccept,
    59     EUserAccept,
    44     EUserDeny,
    60     EUserDeny,
   119 // CPolicyProcessor::~CPolicyProcessor()
   135 // CPolicyProcessor::~CPolicyProcessor()
   120 // -----------------------------------------------------------------------------
   136 // -----------------------------------------------------------------------------
   121 //
   137 //
   122 
   138 
   123 CPolicyProcessor::~CPolicyProcessor()
   139 CPolicyProcessor::~CPolicyProcessor()
   124 {
   140 {  
   125 	ResetRequestContext();
   141     delete iCertBuffer;
       
   142     iCertBuffer=NULL;
       
   143     delete iStore;
       
   144     ////
       
   145     ResetRequestContext();
   126 	delete iRequestBuffer;
   146 	delete iRequestBuffer;
   127 
   147 
   128 	CPolicyEngineServer::RemoveActiveObject( this);
   148 	CPolicyEngineServer::RemoveActiveObject( this);
   129 }
   149 }
   130 
   150 
   135 
   155 
   136 void CPolicyProcessor::ConstructL()
   156 void CPolicyProcessor::ConstructL()
   137 {
   157 {
   138 	CPolicyEngineServer::AddActiveObjectL( this);
   158 	CPolicyEngineServer::AddActiveObjectL( this);
   139 }
   159 }
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // CPolicyProcessor::AddCertificateToStoreL()
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 
       
   166 TInt CPolicyProcessor::AddCertificateToStoreL(const RMessage2& aMessage)
       
   167     {
       
   168     RDEBUG("CPolicyProcessor::AddCertificateToStore" );
       
   169     TInt size = aMessage.Int1();
       
   170     TBuf<KMaxCertSize> certData;    
       
   171     
       
   172     aMessage.ReadL(0, certData, 0);     
       
   173     iCertBuffer = HBufC8::NewL(size);     
       
   174     iCertBuffer->Des().Copy(certData);
       
   175     
       
   176     //check if the trust already exists with same server
       
   177     TInt result = CheckCurrentServerIdFromCR();     
       
   178     if(result == KErrInUse)
       
   179         {       
       
   180         return KErrInUse;    
       
   181         }
       
   182     
       
   183     iStore = CCertStore::NewL();
       
   184     iStore->InitializeCertStore();
       
   185     TInt res = iStore->AddCert(iCertBuffer);
       
   186     if(res == KErrNone)
       
   187         {        
       
   188         //update the new counter value in CR
       
   189         iStore->UpdateLabelCounterInCR();  
       
   190         // return the newly generated label
       
   191         aMessage.WriteL( 2, iStore->GetCurrentCertLabel()->Des() );     
       
   192         }
       
   193     
       
   194     return res; 
       
   195     }
       
   196 
       
   197 
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 // CPolicyProcessor::RemoveCertificateFromStoreL()
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 TInt CPolicyProcessor::RemoveCertificateFromStoreL(const RMessage2& aMessage)
       
   204     {
       
   205     RDEBUG("CPolicyProcessor::RemoveCertificateFromStoreL" );
       
   206     TBuf<128> certLabel;
       
   207     aMessage.ReadL(0, certLabel, 0);   
       
   208        
       
   209     HBufC *label = HBufC::NewL(aMessage.GetDesLength(0));
       
   210     label->Des().Copy(certLabel);  
       
   211     TInt result = CheckCurrentServerIdFromCR();
       
   212     
       
   213     //check if the trust already exists with same server
       
   214     if(result == KErrInUse)
       
   215         {
       
   216         RDEBUG("CPolicyProcessor::RemoveCertificateFromStore -14" );
       
   217         return KErrInUse;    
       
   218         }
       
   219   
       
   220     if ( iStore != NULL )
       
   221        {
       
   222        delete iStore;
       
   223        iStore = NULL;
       
   224        }
       
   225     iStore = CCertStore::NewL();
       
   226     iStore->InitializeCertStore();    
       
   227     
       
   228     TInt res;
       
   229     if(label->Des() == KNullDesC)
       
   230         {
       
   231         // If NULL is passed for removing label then remove the current label
       
   232         HBufC* rLabel = iStore->GetCurrentCertLabel()->AllocL();
       
   233         res = iStore->RemoveCert(*rLabel);
       
   234         delete rLabel;
       
   235         }
       
   236     else
       
   237         {
       
   238         res = iStore->RemoveCert(*label); 
       
   239         }
       
   240  
       
   241     delete label;
       
   242     label = NULL;
       
   243     return res;
       
   244     }
       
   245 
       
   246 // -----------------------------------------------------------------------------
       
   247 // CPolicyProcessor::CheckCurrentServerIdFromCR()
       
   248 // -----------------------------------------------------------------------------
       
   249 //
       
   250 TInt CPolicyProcessor::CheckCurrentServerIdFromCR()
       
   251     {
       
   252     RDEBUG("CPolicyProcessor::CheckCurrentServerIdFromCR" );
       
   253     TBuf8<KMaxServerIdLength>  serverIdCR;         
       
   254     TRAPD( err, 
       
   255            {
       
   256            CRepository* rep = CRepository::NewL( KCRUidPolicyManagementUtilInternalKeys );
       
   257            CleanupStack::PushL( rep );
       
   258            rep->Get( KTrustedServerId, serverIdCR );
       
   259            CleanupStack::PopAndDestroy( rep );
       
   260            } );
       
   261   
       
   262     if(err!=KErrNone)
       
   263         {
       
   264         return err;
       
   265         }    
       
   266     TBool result = CPolicyStorage::PolicyStorage()->IsServerIdValid(serverIdCR);    
       
   267     if(result)
       
   268         {
       
   269         return KErrInUse;
       
   270         }
       
   271     else
       
   272         {
       
   273         return KErrNone;
       
   274         }
       
   275         
       
   276     }
   140 
   277 
   141 // -----------------------------------------------------------------------------
   278 // -----------------------------------------------------------------------------
   142 // CPolicyProcessor::HandleErrorL()
   279 // CPolicyProcessor::HandleErrorL()
   143 // -----------------------------------------------------------------------------
   280 // -----------------------------------------------------------------------------
   144 //
   281 //
   731 	}	
   868 	}	
   732 }
   869 }
   733 
   870 
   734 
   871 
   735 // -----------------------------------------------------------------------------
   872 // -----------------------------------------------------------------------------
       
   873 // CPolicyProcessor::GetCertCounterValue()
       
   874 // -----------------------------------------------------------------------------
       
   875 //
       
   876 TInt CPolicyProcessor::GetCertCounterValue()
       
   877     {
       
   878     RDEBUG("CPolicyProcessor::GetCertCounterValue" );
       
   879 
       
   880     TInt counter = -1;
       
   881     
       
   882     TRAPD( err, 
       
   883        {
       
   884        CRepository* rep = CRepository::NewL( KCRUidPolicyManagementUtilInternalKeys );
       
   885        CleanupStack::PushL( rep );
       
   886        rep->Get( KCertificateCounter, counter );
       
   887        CleanupStack::PopAndDestroy( rep );
       
   888        } );
       
   889    
       
   890     return counter;
       
   891     }
       
   892 
       
   893 
       
   894 // -----------------------------------------------------------------------------
       
   895 // CPolicyProcessor::UpdateSilentTrustServerId()
       
   896 // -----------------------------------------------------------------------------
       
   897 //
       
   898 void CPolicyProcessor::UpdateSilentTrustServerId()
       
   899     { 
       
   900     RDEBUG("CPolicyProcessor::UpdateSilentTrustServerId" );
       
   901     //get server id and store in cenrep
       
   902     //connect to DM util client...
       
   903     RDMUtil dmutil;
       
   904     dmutil.Connect();
       
   905     CleanupClosePushL( dmutil);
       
   906     
       
   907     //..and get server id
       
   908     TBuf8<KMaxServerIdLength> serverid;
       
   909     dmutil.GetDMSessionServerId( serverid);
       
   910     CleanupStack::PopAndDestroy( &dmutil); 
       
   911     
       
   912     TInt ret;
       
   913     TRAPD( err, 
       
   914       {
       
   915         CRepository* rep = CRepository::NewL( KCRUidPolicyManagementUtilInternalKeys );
       
   916         CleanupStack::PushL( rep );
       
   917         ret = rep->Set( KTrustedServerId, serverid );
       
   918         CleanupStack::PopAndDestroy( rep );
       
   919       } );
       
   920 
       
   921     }
       
   922 
       
   923 // -----------------------------------------------------------------------------
   736 // CPolicyProcessor::CorporateUserAcceptFunctionL()
   924 // CPolicyProcessor::CorporateUserAcceptFunctionL()
   737 // -----------------------------------------------------------------------------
   925 // -----------------------------------------------------------------------------
   738 //
   926 //
   739 
   927 
   740 void CPolicyProcessor::CorporateUserAcceptFunctionL( const RParameterList& aParams, CAttributeValue* aResponseElement )
   928 void CPolicyProcessor::CorporateUserAcceptFunctionL( const RParameterList& aParams, CAttributeValue* aResponseElement )
   760 	
   948 	
   761 	RDEBUG8_2("CPolicyProcessor::fingerPrint: %S", &fingerPrint);
   949 	RDEBUG8_2("CPolicyProcessor::fingerPrint: %S", &fingerPrint);
   762 	RDEBUG8_2("CPolicyProcessor::fingerPrint: %S", &ptr);
   950 	RDEBUG8_2("CPolicyProcessor::fingerPrint: %S", &ptr);
   763 	    
   951 	    
   764 	TUserResponse response = EUserDeny;
   952 	TUserResponse response = EUserDeny;
   765 
   953 	
   766     CProcessorClient *client = new CProcessorClient();
   954     TBool showUserScreen = ETrue;
   767     TInt res = client->LaunchDialog(ptr, name);
   955       
   768     
   956     if(GetCertCounterValue() > 0)
   769     if(res == 0)
   957         {   
   770         response = EUserAccept;
   958         if ( iStore != NULL )
   771     else
   959                 {
   772         response = EUserDeny;  
   960                 delete iStore;
       
   961                 iStore = NULL;
       
   962                 }
       
   963         iStore = CCertStore::NewL();
       
   964         iStore->InitializeCertStore();
       
   965         HBufC* certLabel = iStore->GetCurrentCertLabel();       
       
   966         const TDesC8& fingerPrintSilent = iStore->RetrieveCertFPrint(*certLabel);      
       
   967         
       
   968         // Compare the fingerprints of cert stored with received from server  
       
   969         TInt result = fingerPrintSilent.Compare(fingerPrint); 
       
   970         RDEBUG_2("CorporateUserAcceptFunction FP Match ( %d )", result ); 
       
   971         
       
   972         if(result==KErrNone)
       
   973             {
       
   974             UpdateSilentTrustServerId();
       
   975             response = EUserAccept;
       
   976             showUserScreen = EFalse;
       
   977             
       
   978             // call device dialog to show notification                
       
   979             _LIT(KDialogText, "Silent Trust Done!");
       
   980             _LIT(KDialogTitle, "TRUST");
       
   981             _LIT(KDialogIcon, "qtg_large_info");                
       
   982             CHbDeviceNotificationDialogSymbian* dialog = CHbDeviceNotificationDialogSymbian::NewL();
       
   983             CleanupStack::PushL(dialog);
       
   984             dialog->SetTextL(KDialogText);
       
   985             dialog->SetTitleL(KDialogTitle);
       
   986             dialog->SetIconNameL(KDialogIcon);
       
   987             dialog->ShowL();
       
   988             CleanupStack::PopAndDestroy(dialog);            
       
   989             }
       
   990                
       
   991         }
       
   992 
       
   993     if(showUserScreen)
       
   994         {       
       
   995         CProcessorClient *client = new CProcessorClient();
       
   996         TInt res = client->LaunchDialog(ptr, name);
       
   997         
       
   998         if(res == 0)
       
   999             response = EUserAccept;
       
  1000         else
       
  1001             response = EUserDeny; 
       
  1002         }
   773 
  1003 
   774 
  1004 
   775 	MakeBooleanResponseL( response == EUserAccept, aResponseElement);
  1005 	MakeBooleanResponseL( response == EUserAccept, aResponseElement);
   776 }
  1006 }
   777 
  1007 
  1382 	};
  1612 	};
  1383 #endif	
  1613 #endif	
  1384 	
  1614 	
  1385 	return response;
  1615 	return response;
  1386 }
  1616 }
  1387 	
  1617 
       
  1618 
       
  1619 void CCertStore::ConstructL()
       
  1620     {
       
  1621     RDEBUG("CCertStore::ConstructL" );
       
  1622 
       
  1623     }
       
  1624 
       
  1625 CCertStore::CCertStore():CActive(EPriorityStandard)
       
  1626     {
       
  1627     RDEBUG("CCertStore::CCertStore" );
       
  1628     iCertState = EReady;
       
  1629     iCertStore = NULL;
       
  1630    
       
  1631     CActiveScheduler::Add(this);
       
  1632     iWait = new CActiveSchedulerWait();
       
  1633     }
       
  1634 
       
  1635 CCertStore::~CCertStore()
       
  1636     {
       
  1637     RDEBUG("CCertStore::~CCertStore" );
       
  1638 
       
  1639     delete iWait;     
       
  1640     delete iCertLabel;
       
  1641     iCertLabel = NULL;    
       
  1642     delete iCertBuffer;
       
  1643     iCertBuffer = NULL;    
       
  1644     delete iCertStore;
       
  1645     iCertStore = NULL;
       
  1646   
       
  1647     }
       
  1648 
       
  1649 CCertStore* CCertStore::NewL()
       
  1650     { 
       
  1651     RDEBUG("CCertStore::NewL" );
       
  1652 
       
  1653     CCertStore* self = new(ELeave) CCertStore();   
       
  1654     CleanupStack::PushL(self);
       
  1655     self->ConstructL();
       
  1656     CleanupStack::Pop();
       
  1657     return self;    
       
  1658     }
       
  1659 
       
  1660 
       
  1661 void CCertStore::InitializeCertStore()
       
  1662     {
       
  1663     RDEBUG("CCertStore::InitializeCertStore");
       
  1664     if(iCertStore == NULL)
       
  1665         {
       
  1666         RFs* fs = new RFs();
       
  1667         fs->Connect();
       
  1668         iCertStore = CUnifiedCertStore::NewL(*fs, ETrue);         
       
  1669          
       
  1670         iCertStore->Initialize(iStatus);
       
  1671         iCertState = EInitializeStore;    
       
  1672        
       
  1673         SetActive();   
       
  1674         iWait->Start();
       
  1675         TInt res = iStatus.Int();
       
  1676         }     
       
  1677     }
       
  1678 
       
  1679 
       
  1680 
       
  1681 // Checks for the existence of a certificate
       
  1682  // -----------------------------------------------------------------------------
       
  1683  TBool CCertStore::CheckCertInStore( const TDesC& aLabel )
       
  1684      {
       
  1685      RDEBUG("CCertStore::CheckCertInStore");
       
  1686 
       
  1687     // Create filter
       
  1688     CCertAttributeFilter* filter = CCertAttributeFilter::NewL();
       
  1689     TCertLabel label( aLabel );
       
  1690     filter->SetLabel( label ); 
       
  1691     filter->SetFormat(EX509Certificate);
       
  1692     filter->SetOwnerType(ECACertificate);
       
  1693     iCertState = EExistsInStore;
       
  1694     
       
  1695     iCertStore->List( iCertInfoArray, *filter, iStatus );   
       
  1696     SetActive();    
       
  1697     iWait->Start();
       
  1698     
       
  1699     delete filter;
       
  1700     TBool retVal = ( iCertInfoArray.Count() > 0 ); 
       
  1701     
       
  1702     if(retVal)
       
  1703       {
       
  1704       iCertInfoRetrieved = iCertInfoArray[0];
       
  1705       }            
       
  1706     return retVal;    
       
  1707     }
       
  1708  
       
  1709 
       
  1710 TInt CCertStore::RemoveCert(const TDesC& aCertLabel)
       
  1711     { 
       
  1712     RDEBUG("CCertStore::RemoveCert");
       
  1713     if(CheckCertInStore(aCertLabel))
       
  1714         {        
       
  1715         MCTWritableCertStore& writableStore = iCertStore->WritableCertStore(iStoreIndex);         
       
  1716         writableStore.Remove(*iCertInfoRetrieved, iStatus);        
       
  1717         iCertState = ERemoveCert;       
       
  1718         WaitUntilOperationDone();               
       
  1719         return KErrNone;             
       
  1720         }
       
  1721     else
       
  1722         return KErrNotFound;                 
       
  1723     }
       
  1724 
       
  1725 
       
  1726 TInt CCertStore::GenerateNewCertLabel()
       
  1727     {
       
  1728     RDEBUG("CCertStore::GenerateNewCertLabel");
       
  1729     TInt result = KErrNone;
       
  1730     TInt counter=0;
       
  1731    
       
  1732     TRAPD( err, 
       
  1733             {
       
  1734             CRepository* rep = CRepository::NewL( KCRUidPolicyManagementUtilInternalKeys );
       
  1735             CleanupStack::PushL( rep );           
       
  1736             result = rep->Get( KCertificateCounter, counter );
       
  1737             RDEBUG_2("CCertStore::GenerateNewCertLabel( %d )", result );
       
  1738             CleanupStack::PopAndDestroy( rep );
       
  1739             } );
       
  1740     if( err != KErrNone )
       
  1741         {
       
  1742         result = err;
       
  1743         return err;
       
  1744         }   
       
  1745     iCertLabel=HBufC::NewL(KMaxLabelIdLength);     
       
  1746     // use central repository to generte new label each time for addition
       
  1747     *iCertLabel = KDMTrustedCertLabel;
       
  1748     TPtr ptr = iCertLabel->Des();
       
  1749     counter++;
       
  1750     ptr.AppendNum(counter);
       
  1751     iLabelCounter = counter;
       
  1752  
       
  1753     return result;
       
  1754     }
       
  1755 
       
  1756 
       
  1757 
       
  1758 
       
  1759 void CCertStore::UpdateLabelCounterInCR()
       
  1760     {
       
  1761     RDEBUG("CCertStore::UpdateLabelCounterInCR");
       
  1762 
       
  1763     TInt res;
       
  1764     //update the CR with new counter value
       
  1765     TRAPD( err1, 
       
  1766            {
       
  1767            CRepository* rep = CRepository::NewL( KCRUidPolicyManagementUtilInternalKeys );
       
  1768            CleanupStack::PushL( rep );
       
  1769            res = rep->Set( KCertificateCounter, iLabelCounter );
       
  1770            RDEBUG_2("CCertStore::UpdateLabelCounterInCR( %d )", res );
       
  1771            CleanupStack::PopAndDestroy( rep );
       
  1772            } );
       
  1773 
       
  1774     }
       
  1775 
       
  1776 
       
  1777 HBufC* CCertStore::GetCurrentCertLabel()
       
  1778     {  
       
  1779     RDEBUG("CCertStore::GetCurrentCertLabel");
       
  1780 
       
  1781     TInt counter;
       
  1782     TRAPD( err, 
       
  1783            {
       
  1784            CRepository* rep = CRepository::NewL( KCRUidPolicyManagementUtilInternalKeys );
       
  1785            CleanupStack::PushL( rep );
       
  1786            TInt res = rep->Get( KCertificateCounter, counter );           
       
  1787            CleanupStack::PopAndDestroy( rep );
       
  1788            } );
       
  1789     if(iCertLabel)
       
  1790         {
       
  1791         delete iCertLabel;
       
  1792         iCertLabel = NULL;
       
  1793         }
       
  1794     iCertLabel=HBufC::NewL(KMaxLabelIdLength);     
       
  1795     // use central repository to generte new label each time for addition
       
  1796     *iCertLabel = KDMTrustedCertLabel;
       
  1797     TPtr ptr = iCertLabel->Des();   
       
  1798     ptr.AppendNum(counter);
       
  1799     return iCertLabel;
       
  1800     }
       
  1801 
       
  1802 
       
  1803 TInt CCertStore::AddCert(HBufC8 *aCertBuffer)
       
  1804     {  
       
  1805     RDEBUG("CCertStore::AddCert");
       
  1806 
       
  1807     GenerateNewCertLabel();  
       
  1808     //create object of writable certificate store 
       
  1809     MCTWritableCertStore& writableStore = iCertStore->WritableCertStore(iStoreIndex);
       
  1810   
       
  1811     writableStore.Add(*iCertLabel,EX509Certificate, ECACertificate, NULL, NULL, *aCertBuffer,EFalse,iStatus);
       
  1812     iCertState = EAddCert;  
       
  1813     //SetActive();
       
  1814     WaitUntilOperationDone();    
       
  1815     return iStatus.Int();      
       
  1816     }
       
  1817 
       
  1818 
       
  1819 void CCertStore::WaitUntilOperationDone()
       
  1820     {
       
  1821     SetActive();
       
  1822     iWait->Start();
       
  1823     }
       
  1824 
       
  1825 
       
  1826 //Sets the writable certificate store index used for addition and removal
       
  1827 void CCertStore::GetWritableCertStoreIndex()
       
  1828     {
       
  1829     RDEBUG("CCertStore::GetWritableCertStoreIndex");
       
  1830 
       
  1831     //count total availiable cert stores.
       
  1832     TInt count = iCertStore->WritableCertStoreCount();                
       
  1833     
       
  1834     TBool found = EFalse;
       
  1835     TInt i = 0;
       
  1836     TPtrC pElementID(KSymbianCertificateStoreLabel());
       
  1837     
       
  1838     for (i = 0; (i < count) && (!found); i++)
       
  1839       {
       
  1840       // Select the first store with the specified label.
       
  1841      const TDesC& storeLabel = iCertStore->WritableCertStore(i).Token().Label();
       
  1842      if (storeLabel == pElementID)
       
  1843             {
       
  1844             found = ETrue;
       
  1845             iStoreIndex = i;
       
  1846             }                
       
  1847       }
       
  1848 
       
  1849     }
       
  1850 
       
  1851 const TDesC8&  CCertStore::RetrieveCertFPrint(const TDesC& aCertLabel)
       
  1852     {
       
  1853     RDEBUG("CCertStore::RetrieveCertFPrint");
       
  1854 
       
  1855     if(CheckCertInStore(aCertLabel))
       
  1856         {
       
  1857         MCTWritableCertStore& WritableStore = iCertStore->WritableCertStore(iStoreIndex);        
       
  1858         
       
  1859         iCertData = HBufC8::NewMaxL(iCertInfoRetrieved->Size());        
       
  1860         TPtr8 ptr = iCertData->Des();
       
  1861         
       
  1862         WritableStore.Retrieve(*iCertInfoRetrieved,ptr,iStatus);    
       
  1863         
       
  1864         iCertState = EGetFPrint;
       
  1865         
       
  1866         WaitUntilOperationDone();
       
  1867         RDEBUG("CCertStore::RetrieveCertFPrint");
       
  1868         return iFingerPrint;
       
  1869         
       
  1870         }
       
  1871     else
       
  1872       
       
  1873         RDEBUG("CCertStore::RetrieveCertFPrint-- not Found");
       
  1874         return TDesC8(KNoKeyFound) ;
       
  1875    
       
  1876     
       
  1877     
       
  1878     }
       
  1879 
       
  1880 void CCertStore::RunL()
       
  1881     {
       
  1882     RDEBUG("CCertStore::RunL");
       
  1883 
       
  1884     TInt result = iStatus.Int();
       
  1885         if (iStatus == KErrNone) 
       
  1886             {
       
  1887             switch (iCertState) {              
       
  1888                     
       
  1889                 case EInitializeStore:
       
  1890                     {                                 
       
  1891                     GetWritableCertStoreIndex();
       
  1892                     iWait->AsyncStop();  
       
  1893                     break;
       
  1894                     }
       
  1895                 case ERemoveCert:                    
       
  1896                 case EAddCert: 
       
  1897                 case EExistsInStore:    
       
  1898                     {                   
       
  1899                     iWait->AsyncStop();                       
       
  1900                     break;
       
  1901                     }   
       
  1902                     
       
  1903                case EGetFPrint:
       
  1904                    {
       
  1905                    iWait->AsyncStop();
       
  1906                     CX509Certificate* certR = CX509Certificate::NewL(*iCertData);  
       
  1907                                        
       
  1908                     HBufC8* fingerprint = certR->Fingerprint().AllocL(); 
       
  1909                 
       
  1910                     TBuf8<20> fingerP;                
       
  1911                     fingerP.Copy(fingerprint->Des());
       
  1912                     
       
  1913                                    
       
  1914                     iFingerPrint.Zero();
       
  1915                     
       
  1916                     //convert fingerprint to plain text
       
  1917                     for ( TInt i(0); i < fingerP.Length(); i++)
       
  1918                       {
       
  1919                       iFingerPrint.AppendNumFixedWidth(fingerP[i] , EHex,2);
       
  1920                       iFingerPrint.UpperCase();
       
  1921                       }                      
       
  1922                   
       
  1923                    delete fingerprint;
       
  1924                    delete certR;
       
  1925                    certR = NULL;
       
  1926                    break;                   
       
  1927                    }                   
       
  1928               
       
  1929               default:
       
  1930                     break;       
       
  1931             } 
       
  1932             
       
  1933            }
       
  1934         else
       
  1935             {
       
  1936             if(iWait)
       
  1937                 {
       
  1938                 iWait->AsyncStop();
       
  1939                 }
       
  1940             }
       
  1941                 
       
  1942           
       
  1943     }
       
  1944 
       
  1945 void CCertStore::DoCancel()
       
  1946     {
       
  1947     RDEBUG("CCertStore::DoCancel");
       
  1948 
       
  1949     if (iWait && iWait->IsStarted() && iWait->CanStopNow()) 
       
  1950         {        
       
  1951         iWait->AsyncStop();
       
  1952         }  
       
  1953     switch( iCertState )
       
  1954        {
       
  1955           case EInitializeStore:          
       
  1956                {
       
  1957                iCertStore->CancelInitialize();
       
  1958                break;
       
  1959                }
       
  1960        }  
       
  1961 
       
  1962     }