os/security/cryptoservices/certificateandkeymgmt/tcertstore/filecertstorenibbler.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/tcertstore/filecertstorenibbler.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,124 @@
     1.4 +/*
     1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +/**
    1.23 + @file
    1.24 +*/
    1.25 +
    1.26 +#include "filecertstorenibbler.h"
    1.27 +#include <f32file.h>
    1.28 +
    1.29 +_LIT(KFileCertstorePath, "\\system\\data\\cacerts.dat");
    1.30 +
    1.31 +/*static*/ CFileCertstoreNibbler* CFileCertstoreNibbler::NewL(TTimeIntervalMicroSeconds32 aInterval)
    1.32 +{
    1.33 +	CFileCertstoreNibbler* me = new (ELeave) CFileCertstoreNibbler(aInterval);
    1.34 +	CleanupStack::PushL(me);
    1.35 +	me->ConstructL();
    1.36 +	CleanupStack::Pop(me);
    1.37 +	return (me);
    1.38 +}
    1.39 +
    1.40 +CFileCertstoreNibbler::CFileCertstoreNibbler(TTimeIntervalMicroSeconds32 aInterval)
    1.41 +:	CTimer(EPriorityHigh), iNibbleInterval(aInterval)
    1.42 +{
    1.43 +	CActiveScheduler::Add(this);
    1.44 +}
    1.45 +
    1.46 +CFileCertstoreNibbler::~CFileCertstoreNibbler()
    1.47 +{
    1.48 +	Cancel();
    1.49 +	iFs.Close();
    1.50 +}
    1.51 +
    1.52 +void CFileCertstoreNibbler::StartTimer()
    1.53 +{
    1.54 +	After(iNibbleInterval);
    1.55 +}
    1.56 +
    1.57 +void CFileCertstoreNibbler::ConstructL()
    1.58 +{
    1.59 +	User::LeaveIfError(iFs.Connect());
    1.60 +		
    1.61 +	RFile file;
    1.62 +	TDriveUnit sysDrive (RFs::GetSystemDrive());
    1.63 +	TBuf<128> fileCertstorePath (sysDrive.Name());
    1.64 +	fileCertstorePath.Append(KFileCertstorePath);
    1.65 +	User::LeaveIfError(file.Open(iFs, fileCertstorePath, EFileWrite|EFileRead|EFileShareExclusive));
    1.66 +	CleanupClosePushL(file);
    1.67 +	CPermanentFileStore* store = CPermanentFileStore::FromLC(file);	
    1.68 +	
    1.69 +	RStoreWriteStream stream;
    1.70 +	iNibbleStreamId = stream.CreateLC(*store);	//	stream for cert
    1.71 +	
    1.72 +//	Write to stream
    1.73 +	_LIT(KNibble, "wool");
    1.74 +	stream << KNibble;
    1.75 +	
    1.76 +	stream.CommitL();
    1.77 +	CleanupStack::PopAndDestroy();	//	stream
    1.78 +	store->CommitL();
    1.79 +	CleanupStack::PopAndDestroy(store);
    1.80 +	CleanupStack::Pop();			//	file cleanup
    1.81 +		
    1.82 +	CTimer::ConstructL();
    1.83 +	StartTimer();
    1.84 +}
    1.85 +
    1.86 +void CFileCertstoreNibbler::RunL()
    1.87 +{
    1.88 +	NibbleFileL();
    1.89 +	StartTimer();	
    1.90 +}
    1.91 +
    1.92 +//	Writes to the filecertstore file (\system\data\cacerts.dat on system drive) to test
    1.93 +//	concurrency access. Writes to a separate stream so will have no effect
    1.94 +//	on certs data.  This doesn't test integrity of certstore in any way, is
    1.95 +//	simply a quick check that the file can be opened and written to whilst
    1.96 +//	other tests proceed.
    1.97 +void CFileCertstoreNibbler::NibbleFileL()
    1.98 +{	
    1.99 +	RFile file;
   1.100 +	TDriveUnit sysDrive (RFs::GetSystemDrive());
   1.101 +	TBuf<128> fileCertstorePath (sysDrive.Name());
   1.102 +	fileCertstorePath.Append(KFileCertstorePath);
   1.103 +	User::LeaveIfError(file.Open(iFs, fileCertstorePath, EFileWrite|EFileRead|EFileShareExclusive));
   1.104 +	CleanupClosePushL(file);
   1.105 +	CPermanentFileStore* store = CPermanentFileStore::FromLC(file);	
   1.106 +		
   1.107 +	RStoreWriteStream stream;
   1.108 +	stream.ReplaceLC(*store, iNibbleStreamId);
   1.109 +	
   1.110 +//	Write to stream
   1.111 +	_LIT(KNibble, "clanger");
   1.112 +	stream << KNibble;
   1.113 +	
   1.114 +	stream.CommitL();
   1.115 +	CleanupStack::PopAndDestroy();	//	stream
   1.116 +	store->CommitL();
   1.117 +	CleanupStack::PopAndDestroy(store);
   1.118 +	CleanupStack::Pop();			//	file cleanup
   1.119 +}
   1.120 +
   1.121 +TInt CFileCertstoreNibbler::RunError(TInt /*anError*/)
   1.122 +{
   1.123 +//	_LIT(KNibblerError, "CFileCertstoreNibbler::RunError");
   1.124 +//	User::Panic(KNibblerError, anError);
   1.125 +	return (KErrNone);
   1.126 +}
   1.127 +