installationservices/swi/source/sisregistry/server_legacy/siscontrollerverifier.cpp
changeset 0 ba25891c3a9e
child 18 f9033e605ee2
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2006-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 * CSisControllerVerifier class implementation
       
    16 * @released
       
    17 * @internalComponent
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 #include <s32mem.h>
       
    23 
       
    24 #include "log.h"
       
    25 #include "arrayutils.h"
       
    26 #include "cleanuputils.h"
       
    27 #include "siscontrollerverifier.h"
       
    28 #include "sisregistryserversession.h"
       
    29 #include "dessisdataprovider.h"
       
    30 #include "securitymanager.h"
       
    31 
       
    32 using namespace Swi;
       
    33 
       
    34 CSisControllerVerifier* CSisControllerVerifier::NewL(const RMessage2& aMessage)
       
    35 	{
       
    36 	CSisControllerVerifier* self = new (ELeave) CSisControllerVerifier(aMessage);
       
    37 	CleanupStack::PushL(self);
       
    38 	self->ConstructL();
       
    39 	CleanupStack::Pop(self);
       
    40 	return self;
       
    41 	}
       
    42 	
       
    43 CSisControllerVerifier::CSisControllerVerifier(const RMessage2& aMessage)
       
    44 				:CActive(EPriorityStandard), 
       
    45 				iMessage(aMessage),
       
    46 				isVerified(EFalse),
       
    47 				iIsEmbedded(ETrue)
       
    48 	{
       
    49 	}
       
    50 
       
    51 void CSisControllerVerifier::ConstructL()
       
    52 	{
       
    53 	CActiveScheduler::Add(this);
       
    54 	iSecurityManager = Swi::CSecurityManager::NewL();
       
    55 	}
       
    56 	
       
    57 
       
    58 CSisControllerVerifier::~CSisControllerVerifier()
       
    59 	{
       
    60 	Cancel();
       
    61 	delete iSecurityManager;
       
    62 	delete iDesProvider;
       
    63 	delete iController;
       
    64 	
       
    65 	iPkixResultsOut.ResetAndDestroy();
       
    66 	iCertsOut.ResetAndDestroy();
       
    67 	iX509RootCertArray.ResetAndDestroy();
       
    68 	}
       
    69 	
       
    70 void CSisControllerVerifier::RunL()
       
    71 	{
       
    72 	if(KErrNone != iStatus.Int())
       
    73 		{
       
    74 		iMessage.Complete(iStatus.Int());
       
    75 		return;
       
    76 		}
       
    77 	
       
    78 	if(iResultOut != EValidationSucceeded)
       
    79 		{
       
    80 		isVerified = EFalse;
       
    81 		}
       
    82 	else
       
    83 		{
       
    84 		if(iCurrentController >= 0)
       
    85 			{
       
    86 			VerifyControllerL((*iControllers)[iCurrentController--]);
       
    87 			return;
       
    88 			}
       
    89 		
       
    90 		isVerified = ETrue;
       
    91 		}
       
    92 		
       
    93 	CompleteRequestL();
       
    94 	}
       
    95 
       
    96 void CSisControllerVerifier::CompleteRequestL()
       
    97 	{
       
    98 	TPckg<TBool> packageResult(isVerified);
       
    99 
       
   100 	iMessage.WriteL(EIpcArgument0, packageResult);
       
   101 	iMessage.Complete(KErrNone);
       
   102 	}
       
   103 	
       
   104 TInt CSisControllerVerifier::RunError(TInt)
       
   105 	{
       
   106 	return KErrNone;
       
   107 	}
       
   108 
       
   109 void CSisControllerVerifier::DoCancel()
       
   110 	{
       
   111 	iSecurityManager->DoCancel();
       
   112 	}
       
   113 
       
   114 void CSisControllerVerifier::VerifyControllerL(RPointerArray<HBufC8>& aControllers)
       
   115 	{
       
   116 	DEBUG_PRINTF(_L("CSisRegistry::VerifyControllerSignature"));
       
   117 	
       
   118 	TInt srcLen = iMessage.GetDesLengthL(EIpcArgument1);
       
   119 	HBufC8* buffer = HBufC8::NewLC(srcLen);
       
   120 	TPtr8 dest = buffer->Des();
       
   121 
       
   122 	// read data in the buffer
       
   123 	iMessage.ReadL(EIpcArgument1, dest, 0);
       
   124 
       
   125 	// lets store all in a stream
       
   126 	RDesReadStream stream(dest);
       
   127     CleanupClosePushL(stream);
       
   128 
       
   129 	iX509RootCertArray.ResetAndDestroy();
       
   130 	InternalizePointerArrayL(iX509RootCertArray, stream);
       
   131 
       
   132 	CleanupStack::PopAndDestroy(2, buffer);
       
   133 	
       
   134 	iControllers = &aControllers;
       
   135 	iCurrentController = iControllers->Count() - 1;
       
   136 	VerifyControllerL((*iControllers)[iCurrentController--]);
       
   137 	}
       
   138 
       
   139 void CSisControllerVerifier::VerifyControllerL(HBufC8* aRawController)
       
   140 	{
       
   141 	delete iDesProvider;
       
   142 	delete iController;
       
   143 	
       
   144 	iDesProvider = CDesDataProvider::NewL(*aRawController);
       
   145 	// read the controller
       
   146 	iController = Sis::CController::NewL(*iDesProvider, Sis::EAssumeType);
       
   147 	
       
   148 	// If user provided certificates are there
       
   149 	if(0 != iX509RootCertArray.Count())
       
   150 		{
       
   151 		iSecurityManager->SetRootCerts(&iX509RootCertArray);
       
   152 		}
       
   153 
       
   154 	// Clean the output files
       
   155 	iPkixResultsOut.ResetAndDestroy();
       
   156 	iCertsOut.ResetAndDestroy();
       
   157 	
       
   158 	TBool checkDateAndTime;
       
   159 	TPckg<TBool> pkgDateCheck(checkDateAndTime);
       
   160 	iMessage.ReadL(EIpcArgument2, pkgDateCheck);
       
   161 	
       
   162 	SetActive();
       
   163 	iSecurityManager->VerifyControllerL(*aRawController,
       
   164 										*iController,
       
   165 										&iResultOut,
       
   166 										iPkixResultsOut,
       
   167 										iCertsOut,
       
   168 										&iCapabilitySetOut,
       
   169 										iAllowUnsigned,
       
   170 										iIsEmbedded,
       
   171 										iStatus,
       
   172 										checkDateAndTime);
       
   173 
       
   174 	}
       
   175 	
       
   176