os/security/cryptoservices/certificateandkeymgmt/tcertstore/filecertstorenibbler.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) 2005-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 /**
    20  @file
    21 */
    22 
    23 #include "filecertstorenibbler.h"
    24 #include <f32file.h>
    25 
    26 _LIT(KFileCertstorePath, "\\system\\data\\cacerts.dat");
    27 
    28 /*static*/ CFileCertstoreNibbler* CFileCertstoreNibbler::NewL(TTimeIntervalMicroSeconds32 aInterval)
    29 {
    30 	CFileCertstoreNibbler* me = new (ELeave) CFileCertstoreNibbler(aInterval);
    31 	CleanupStack::PushL(me);
    32 	me->ConstructL();
    33 	CleanupStack::Pop(me);
    34 	return (me);
    35 }
    36 
    37 CFileCertstoreNibbler::CFileCertstoreNibbler(TTimeIntervalMicroSeconds32 aInterval)
    38 :	CTimer(EPriorityHigh), iNibbleInterval(aInterval)
    39 {
    40 	CActiveScheduler::Add(this);
    41 }
    42 
    43 CFileCertstoreNibbler::~CFileCertstoreNibbler()
    44 {
    45 	Cancel();
    46 	iFs.Close();
    47 }
    48 
    49 void CFileCertstoreNibbler::StartTimer()
    50 {
    51 	After(iNibbleInterval);
    52 }
    53 
    54 void CFileCertstoreNibbler::ConstructL()
    55 {
    56 	User::LeaveIfError(iFs.Connect());
    57 		
    58 	RFile file;
    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);	
    65 	
    66 	RStoreWriteStream stream;
    67 	iNibbleStreamId = stream.CreateLC(*store);	//	stream for cert
    68 	
    69 //	Write to stream
    70 	_LIT(KNibble, "wool");
    71 	stream << KNibble;
    72 	
    73 	stream.CommitL();
    74 	CleanupStack::PopAndDestroy();	//	stream
    75 	store->CommitL();
    76 	CleanupStack::PopAndDestroy(store);
    77 	CleanupStack::Pop();			//	file cleanup
    78 		
    79 	CTimer::ConstructL();
    80 	StartTimer();
    81 }
    82 
    83 void CFileCertstoreNibbler::RunL()
    84 {
    85 	NibbleFileL();
    86 	StartTimer();	
    87 }
    88 
    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()
    95 {	
    96 	RFile file;
    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);	
   103 		
   104 	RStoreWriteStream stream;
   105 	stream.ReplaceLC(*store, iNibbleStreamId);
   106 	
   107 //	Write to stream
   108 	_LIT(KNibble, "clanger");
   109 	stream << KNibble;
   110 	
   111 	stream.CommitL();
   112 	CleanupStack::PopAndDestroy();	//	stream
   113 	store->CommitL();
   114 	CleanupStack::PopAndDestroy(store);
   115 	CleanupStack::Pop();			//	file cleanup
   116 }
   117 
   118 TInt CFileCertstoreNibbler::RunError(TInt /*anError*/)
   119 {
   120 //	_LIT(KNibblerError, "CFileCertstoreNibbler::RunError");
   121 //	User::Panic(KNibblerError, anError);
   122 	return (KErrNone);
   123 }
   124