os/security/cryptoservices/certificateandkeymgmt/tcertstore/filecertstorenibbler.cpp
First public contribution.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
23 #include "filecertstorenibbler.h"
26 _LIT(KFileCertstorePath, "\\system\\data\\cacerts.dat");
28 /*static*/ CFileCertstoreNibbler* CFileCertstoreNibbler::NewL(TTimeIntervalMicroSeconds32 aInterval)
30 CFileCertstoreNibbler* me = new (ELeave) CFileCertstoreNibbler(aInterval);
31 CleanupStack::PushL(me);
33 CleanupStack::Pop(me);
37 CFileCertstoreNibbler::CFileCertstoreNibbler(TTimeIntervalMicroSeconds32 aInterval)
38 : CTimer(EPriorityHigh), iNibbleInterval(aInterval)
40 CActiveScheduler::Add(this);
43 CFileCertstoreNibbler::~CFileCertstoreNibbler()
49 void CFileCertstoreNibbler::StartTimer()
51 After(iNibbleInterval);
54 void CFileCertstoreNibbler::ConstructL()
56 User::LeaveIfError(iFs.Connect());
59 TDriveUnit sysDrive (RFs::GetSystemDrive());
60 TBuf<128> fileCertstorePath (sysDrive.Name());
61 fileCertstorePath.Append(KFileCertstorePath);
62 User::LeaveIfError(file.Open(iFs, fileCertstorePath, EFileWrite|EFileRead|EFileShareExclusive));
63 CleanupClosePushL(file);
64 CPermanentFileStore* store = CPermanentFileStore::FromLC(file);
66 RStoreWriteStream stream;
67 iNibbleStreamId = stream.CreateLC(*store); // stream for cert
70 _LIT(KNibble, "wool");
74 CleanupStack::PopAndDestroy(); // stream
76 CleanupStack::PopAndDestroy(store);
77 CleanupStack::Pop(); // file cleanup
83 void CFileCertstoreNibbler::RunL()
89 // Writes to the filecertstore file (\system\data\cacerts.dat on system drive) to test
90 // concurrency access. Writes to a separate stream so will have no effect
91 // on certs data. This doesn't test integrity of certstore in any way, is
92 // simply a quick check that the file can be opened and written to whilst
93 // other tests proceed.
94 void CFileCertstoreNibbler::NibbleFileL()
97 TDriveUnit sysDrive (RFs::GetSystemDrive());
98 TBuf<128> fileCertstorePath (sysDrive.Name());
99 fileCertstorePath.Append(KFileCertstorePath);
100 User::LeaveIfError(file.Open(iFs, fileCertstorePath, EFileWrite|EFileRead|EFileShareExclusive));
101 CleanupClosePushL(file);
102 CPermanentFileStore* store = CPermanentFileStore::FromLC(file);
104 RStoreWriteStream stream;
105 stream.ReplaceLC(*store, iNibbleStreamId);
108 _LIT(KNibble, "clanger");
112 CleanupStack::PopAndDestroy(); // stream
114 CleanupStack::PopAndDestroy(store);
115 CleanupStack::Pop(); // file cleanup
118 TInt CFileCertstoreNibbler::RunError(TInt /*anError*/)
120 // _LIT(KNibblerError, "CFileCertstoreNibbler::RunError");
121 // User::Panic(KNibblerError, anError);