sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
/**
|
sl@0
|
20 |
@file
|
sl@0
|
21 |
*/
|
sl@0
|
22 |
|
sl@0
|
23 |
#include "filecertstorenibbler.h"
|
sl@0
|
24 |
#include <f32file.h>
|
sl@0
|
25 |
|
sl@0
|
26 |
_LIT(KFileCertstorePath, "\\system\\data\\cacerts.dat");
|
sl@0
|
27 |
|
sl@0
|
28 |
/*static*/ CFileCertstoreNibbler* CFileCertstoreNibbler::NewL(TTimeIntervalMicroSeconds32 aInterval)
|
sl@0
|
29 |
{
|
sl@0
|
30 |
CFileCertstoreNibbler* me = new (ELeave) CFileCertstoreNibbler(aInterval);
|
sl@0
|
31 |
CleanupStack::PushL(me);
|
sl@0
|
32 |
me->ConstructL();
|
sl@0
|
33 |
CleanupStack::Pop(me);
|
sl@0
|
34 |
return (me);
|
sl@0
|
35 |
}
|
sl@0
|
36 |
|
sl@0
|
37 |
CFileCertstoreNibbler::CFileCertstoreNibbler(TTimeIntervalMicroSeconds32 aInterval)
|
sl@0
|
38 |
: CTimer(EPriorityHigh), iNibbleInterval(aInterval)
|
sl@0
|
39 |
{
|
sl@0
|
40 |
CActiveScheduler::Add(this);
|
sl@0
|
41 |
}
|
sl@0
|
42 |
|
sl@0
|
43 |
CFileCertstoreNibbler::~CFileCertstoreNibbler()
|
sl@0
|
44 |
{
|
sl@0
|
45 |
Cancel();
|
sl@0
|
46 |
iFs.Close();
|
sl@0
|
47 |
}
|
sl@0
|
48 |
|
sl@0
|
49 |
void CFileCertstoreNibbler::StartTimer()
|
sl@0
|
50 |
{
|
sl@0
|
51 |
After(iNibbleInterval);
|
sl@0
|
52 |
}
|
sl@0
|
53 |
|
sl@0
|
54 |
void CFileCertstoreNibbler::ConstructL()
|
sl@0
|
55 |
{
|
sl@0
|
56 |
User::LeaveIfError(iFs.Connect());
|
sl@0
|
57 |
|
sl@0
|
58 |
RFile file;
|
sl@0
|
59 |
TDriveUnit sysDrive (RFs::GetSystemDrive());
|
sl@0
|
60 |
TBuf<128> fileCertstorePath (sysDrive.Name());
|
sl@0
|
61 |
fileCertstorePath.Append(KFileCertstorePath);
|
sl@0
|
62 |
User::LeaveIfError(file.Open(iFs, fileCertstorePath, EFileWrite|EFileRead|EFileShareExclusive));
|
sl@0
|
63 |
CleanupClosePushL(file);
|
sl@0
|
64 |
CPermanentFileStore* store = CPermanentFileStore::FromLC(file);
|
sl@0
|
65 |
|
sl@0
|
66 |
RStoreWriteStream stream;
|
sl@0
|
67 |
iNibbleStreamId = stream.CreateLC(*store); // stream for cert
|
sl@0
|
68 |
|
sl@0
|
69 |
// Write to stream
|
sl@0
|
70 |
_LIT(KNibble, "wool");
|
sl@0
|
71 |
stream << KNibble;
|
sl@0
|
72 |
|
sl@0
|
73 |
stream.CommitL();
|
sl@0
|
74 |
CleanupStack::PopAndDestroy(); // stream
|
sl@0
|
75 |
store->CommitL();
|
sl@0
|
76 |
CleanupStack::PopAndDestroy(store);
|
sl@0
|
77 |
CleanupStack::Pop(); // file cleanup
|
sl@0
|
78 |
|
sl@0
|
79 |
CTimer::ConstructL();
|
sl@0
|
80 |
StartTimer();
|
sl@0
|
81 |
}
|
sl@0
|
82 |
|
sl@0
|
83 |
void CFileCertstoreNibbler::RunL()
|
sl@0
|
84 |
{
|
sl@0
|
85 |
NibbleFileL();
|
sl@0
|
86 |
StartTimer();
|
sl@0
|
87 |
}
|
sl@0
|
88 |
|
sl@0
|
89 |
// Writes to the filecertstore file (\system\data\cacerts.dat on system drive) to test
|
sl@0
|
90 |
// concurrency access. Writes to a separate stream so will have no effect
|
sl@0
|
91 |
// on certs data. This doesn't test integrity of certstore in any way, is
|
sl@0
|
92 |
// simply a quick check that the file can be opened and written to whilst
|
sl@0
|
93 |
// other tests proceed.
|
sl@0
|
94 |
void CFileCertstoreNibbler::NibbleFileL()
|
sl@0
|
95 |
{
|
sl@0
|
96 |
RFile file;
|
sl@0
|
97 |
TDriveUnit sysDrive (RFs::GetSystemDrive());
|
sl@0
|
98 |
TBuf<128> fileCertstorePath (sysDrive.Name());
|
sl@0
|
99 |
fileCertstorePath.Append(KFileCertstorePath);
|
sl@0
|
100 |
User::LeaveIfError(file.Open(iFs, fileCertstorePath, EFileWrite|EFileRead|EFileShareExclusive));
|
sl@0
|
101 |
CleanupClosePushL(file);
|
sl@0
|
102 |
CPermanentFileStore* store = CPermanentFileStore::FromLC(file);
|
sl@0
|
103 |
|
sl@0
|
104 |
RStoreWriteStream stream;
|
sl@0
|
105 |
stream.ReplaceLC(*store, iNibbleStreamId);
|
sl@0
|
106 |
|
sl@0
|
107 |
// Write to stream
|
sl@0
|
108 |
_LIT(KNibble, "clanger");
|
sl@0
|
109 |
stream << KNibble;
|
sl@0
|
110 |
|
sl@0
|
111 |
stream.CommitL();
|
sl@0
|
112 |
CleanupStack::PopAndDestroy(); // stream
|
sl@0
|
113 |
store->CommitL();
|
sl@0
|
114 |
CleanupStack::PopAndDestroy(store);
|
sl@0
|
115 |
CleanupStack::Pop(); // file cleanup
|
sl@0
|
116 |
}
|
sl@0
|
117 |
|
sl@0
|
118 |
TInt CFileCertstoreNibbler::RunError(TInt /*anError*/)
|
sl@0
|
119 |
{
|
sl@0
|
120 |
// _LIT(KNibblerError, "CFileCertstoreNibbler::RunError");
|
sl@0
|
121 |
// User::Panic(KNibblerError, anError);
|
sl@0
|
122 |
return (KErrNone);
|
sl@0
|
123 |
}
|
sl@0
|
124 |
|