os/security/cryptoservices/filebasedcertificateandkeystores/test/certtool/certtool_setapps.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2004-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 the License "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 #include "certtool_commands.h"
    20 #include "certtool_controller.h"
    21 
    22 
    23 /*static*/ CCertToolSetApps* CCertToolSetApps::NewLC(CCertToolController* aController)
    24 	{
    25 	CCertToolSetApps* self = new (ELeave) CCertToolSetApps(aController);
    26 	CleanupStack::PushL(self);
    27 	self->ConstructL();
    28 	return self;
    29 	}
    30 	
    31 /*static*/ CCertToolSetApps* CCertToolSetApps::NewL(CCertToolController* aController)
    32 	{
    33 	CCertToolSetApps* self = CCertToolSetApps::NewLC(aController);
    34 	CleanupStack::Pop(self);
    35 	return self;
    36 	}
    37 
    38 CCertToolSetApps::CCertToolSetApps(CCertToolController* aController) : CCertToolList(aController), iCertIndex (-1)
    39 	{
    40 	}
    41 
    42 	
    43 CCertToolSetApps::~CCertToolSetApps()
    44 	{
    45 	Cancel();	
    46 	}
    47 
    48 void CCertToolSetApps::RunL()
    49 	{
    50 	if (iStatus.Int() != KErrNone)
    51 		{
    52 		// A problem occured. Handle gracefully.
    53 		User::Leave(iStatus.Int());
    54 		}	
    55 		
    56 	switch (iState)
    57 		{	 
    58 		case EListCerts:
    59 			{
    60 			if (iCertInfos.Count()==0)
    61 				{
    62 				iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_EMPTY);
    63 				CActiveScheduler::Stop();				
    64 				}
    65 			else
    66 				{ 
    67 				if (iParams->iDefault)    
    68 					{
    69 					// Look for a specific certificate					
    70 					for (TInt j = 0; j < iCertInfos.Count(); j++)
    71 						{
    72 						if (iCertInfos[j]->Label() == *iParams->iDefault) 
    73 							{
    74 							iCertIndex = j;
    75 							break;
    76 							}
    77 						}	
    78 						
    79 					if (iCertIndex != -1)
    80 						{
    81 						// Certificate found set app uids!
    82 						if (iParams->iCertstoreIndex == -1)
    83 							{
    84 							iParams->iCertstoreIndex = 0;
    85 							}
    86 						if (iParams->iCertstoreIndex >= iCertStore->CertStoreCount())
    87 							{
    88 							iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_NOTEXIST);	
    89 							User::Leave(KErrArgument);			
    90 							}
    91 						if(iCertInfos[iCertIndex]->CertificateOwnerType() == ECACertificate)							
    92 							{
    93 							iState = ESetTrust;
    94 							}
    95 						else
    96 							{
    97 							iState = EFinished;								
    98 							}	
    99 						iCertStore->SetApplicability(*iCertInfos[iCertIndex], iParams->iUIDs, iStatus);
   100 						SetActive();
   101 						break;
   102 						}
   103 					else 
   104 						{
   105 						User::Leave(KErrNotFound);
   106 						}			
   107 					}
   108 				}
   109 			}
   110 		case ESetTrust:
   111 			{
   112 			iState = EFinished;
   113 			const TBool caCert = ETrue;
   114 			iCertStore->SetTrust(*iCertInfos[iCertIndex],caCert,iStatus);
   115 			SetActive();				
   116 			}
   117 			break;
   118 		case EFinished:
   119 			{
   120 			iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_SETAPPS_SUCCESS);				
   121 			CActiveScheduler::Stop();			
   122 			}
   123 			break;
   124 		default:
   125 			{
   126 			User::Panic(_L("SETAPPS action: Illegal state."), 1);
   127 			}
   128 		}
   129 	}
   130 
   131 
   132 TInt CCertToolSetApps::RunError(TInt aError)
   133 	{
   134 	CActiveScheduler::Stop();
   135 
   136 	switch (aError)
   137 		{
   138 		case KErrNotFound :
   139 			{
   140 			TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_NOTFOUND));
   141 			TRAP_IGNORE(iController->DisplayErrorL(_L("\n"), iParams->iPageWise));			
   142 			}
   143 			break;
   144 		default:
   145 			{
   146 			TRAP_IGNORE(iController->DisplayLocalisedMsgL(R_CERTTOOL_ERR_ADDAPPS_FAIL));			
   147 			TRAP_IGNORE(iController->DisplayErrorL(_L("\n"), iParams->iPageWise));			
   148 			}
   149 		}	
   150 
   151 	return KErrNone;	
   152 	}