os/security/cryptoservices/certificateandkeymgmt/tadditionalstores/Test1certstoretoken.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.
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
#include "test1certstoretoken.h"
sl@0
    20
#include "test1certstore.h"
sl@0
    21
sl@0
    22
_LIT(KName1, "Test store 1");
sl@0
    23
_LIT(KName2, "Test store 2");
sl@0
    24
#ifdef CERTSTORE_HARDWARE_SIM
sl@0
    25
	_LIT(KTest1CertStoreFullPath, "\\system\\data\\test1simcertstore.dat");
sl@0
    26
	_LIT(KTest2CertStoreFullPath, "\\system\\data\\test2simcertstore.dat");
sl@0
    27
#else
sl@0
    28
	#ifdef CERTSTORE_HARDWARE_WIM
sl@0
    29
		_LIT(KTest1CertStoreFullPath, "\\system\\data\\test1wimcertstore.dat");
sl@0
    30
		_LIT(KTest2CertStoreFullPath, "\\system\\data\\test2wimcertstore.dat");
sl@0
    31
	#else
sl@0
    32
		#ifdef CERTSTORE_HARDWARE_UICC
sl@0
    33
			_LIT(KTest1CertStoreFullPath, "\\system\\data\\test1uicccertstore.dat");
sl@0
    34
			_LIT(KTest2CertStoreFullPath, "\\system\\data\\test2uicccertstore.dat");
sl@0
    35
 		#else
sl@0
    36
			#ifdef CERTSTORE_DEVICE_IMMUTABLE
sl@0
    37
				_LIT(KTest1CertStoreFullPath, "\\system\\data\\test1deviceimmutablecertstore.dat");
sl@0
    38
				_LIT(KTest2CertStoreFullPath, "\\system\\data\\test2deviceimmutablecertstore.dat");
sl@0
    39
			#else
sl@0
    40
				_LIT(KTest1CertStoreFullPath, "\\system\\data\\test1certstore.dat");
sl@0
    41
				_LIT(KTest2CertStoreFullPath, "\\system\\data\\test2certstore.dat");
sl@0
    42
			#endif
sl@0
    43
 		#endif
sl@0
    44
	#endif
sl@0
    45
#endif
sl@0
    46
sl@0
    47
sl@0
    48
CTest1CertStoreToken* CTest1CertStoreToken::New(CTest1CertStoreTokenType::TTokenId aTokenId,
sl@0
    49
												CTest1CertStoreTokenType& aFileCertStoreTokenType)
sl@0
    50
	{
sl@0
    51
	return new CTest1CertStoreToken(aTokenId, aFileCertStoreTokenType);
sl@0
    52
	}
sl@0
    53
sl@0
    54
CTest1CertStoreToken::~CTest1CertStoreToken()
sl@0
    55
	{
sl@0
    56
	}
sl@0
    57
sl@0
    58
MCTTokenType& CTest1CertStoreToken::TokenType()
sl@0
    59
	{
sl@0
    60
	return iTokenType;
sl@0
    61
	}
sl@0
    62
sl@0
    63
const TDesC& CTest1CertStoreToken::Label()
sl@0
    64
	{
sl@0
    65
	switch (iTokenId)
sl@0
    66
		{
sl@0
    67
	case CTest1CertStoreTokenType::ETest1CertStore:
sl@0
    68
		return KName1;
sl@0
    69
sl@0
    70
	case CTest1CertStoreTokenType::ETest2CertStore:
sl@0
    71
		return KName2;
sl@0
    72
sl@0
    73
	default:
sl@0
    74
		return KNullDesC;
sl@0
    75
		}
sl@0
    76
	}
sl@0
    77
sl@0
    78
const TDesC& CTest1CertStoreToken::Information(TTokenInformation)
sl@0
    79
	{
sl@0
    80
	_LIT(KAnswer, "I Know Nothing");
sl@0
    81
	return KAnswer;
sl@0
    82
	}
sl@0
    83
sl@0
    84
TCTTokenHandle CTest1CertStoreToken::Handle()
sl@0
    85
	{
sl@0
    86
	return TCTTokenHandle(iTokenType.Type(), iTokenId);
sl@0
    87
	}
sl@0
    88
sl@0
    89
void CTest1CertStoreToken::DoRelease()
sl@0
    90
	{
sl@0
    91
	delete this;
sl@0
    92
	}
sl@0
    93
sl@0
    94
TInt& CTest1CertStoreToken::ReferenceCount()
sl@0
    95
	{
sl@0
    96
	return iRefCount;
sl@0
    97
	}
sl@0
    98
sl@0
    99
void CTest1CertStoreToken::DoGetInterface(TUid aRequiredInterface,
sl@0
   100
										  MCTTokenInterface*& aReturnedInterface,
sl@0
   101
										  TRequestStatus& aStatus)
sl@0
   102
	{
sl@0
   103
	RFs& fs = static_cast<CCTTokenType&>(TokenType()).Fs();
sl@0
   104
	MCTTokenInterface* result = 0;
sl@0
   105
	TInt error = KErrNone;
sl@0
   106
sl@0
   107
	//gets the system drive
sl@0
   108
	TDriveUnit sysDrive (RFs::GetSystemDrive());
sl@0
   109
	TDriveName driveName(sysDrive.Name());	
sl@0
   110
	TBuf<128> fullPath (driveName);
sl@0
   111
	TInt* refCountInterface = &iRefCountInterface;
sl@0
   112
	
sl@0
   113
	if (iTokenId == CTest1CertStoreTokenType::ETest1CertStore)
sl@0
   114
		{
sl@0
   115
		fullPath.Append(KTest1CertStoreFullPath);
sl@0
   116
		refCountInterface = &iRefCountInterface;
sl@0
   117
		}
sl@0
   118
		
sl@0
   119
	// This is mainly used for testing and also as an example on how to manage
sl@0
   120
	// multiple tokens within one TokenType.
sl@0
   121
	else if (iTokenId == CTest1CertStoreTokenType::ETest2CertStore)
sl@0
   122
		{
sl@0
   123
		fullPath.Append(KTest2CertStoreFullPath);
sl@0
   124
		refCountInterface = &iRefCountInterface2;
sl@0
   125
		}
sl@0
   126
	else
sl@0
   127
		{
sl@0
   128
		// If not certstore 1 or 2, then we complete with bad name.
sl@0
   129
		TRequestStatus* r = &aStatus;
sl@0
   130
		User::RequestComplete(r, KErrBadName);
sl@0
   131
		return;
sl@0
   132
		}
sl@0
   133
sl@0
   134
	switch (aRequiredInterface.iUid)
sl@0
   135
		{
sl@0
   136
	case KInterfaceCertStore:
sl@0
   137
		{
sl@0
   138
		if (!iFileCertStore)
sl@0
   139
			{
sl@0
   140
			TRAP(error, iFileCertStore = CTest1CertStore::NewL(fs, *this, fullPath, 
sl@0
   141
				EFileShareReadersOnly));
sl@0
   142
			iFileMode = EFileRead;
sl@0
   143
			}
sl@0
   144
		MCTCertStore* temp = iFileCertStore;
sl@0
   145
		result = temp;
sl@0
   146
		}
sl@0
   147
		break;
sl@0
   148
sl@0
   149
	case KInterfaceWritableCertStore:
sl@0
   150
		{
sl@0
   151
		if (!iFileCertStore)
sl@0
   152
			{
sl@0
   153
			TRAP(error, iFileCertStore = CTest1CertStore::NewL(fs, *this, fullPath, EFileWrite));
sl@0
   154
			iFileMode = EFileWrite;
sl@0
   155
			}
sl@0
   156
		if (iFileMode == EFileRead)
sl@0
   157
			{
sl@0
   158
			error = KErrInUse;
sl@0
   159
			}
sl@0
   160
		else
sl@0
   161
			{
sl@0
   162
			MCTWritableCertStore* temp = iFileCertStore;
sl@0
   163
			result = temp;
sl@0
   164
			}
sl@0
   165
		}
sl@0
   166
		break;
sl@0
   167
sl@0
   168
	default:
sl@0
   169
		error = KErrNotSupported;
sl@0
   170
		break;
sl@0
   171
		}
sl@0
   172
sl@0
   173
	if (error == KErrNotSupported)
sl@0
   174
		{
sl@0
   175
		Release();
sl@0
   176
		}
sl@0
   177
	else if ((error != KErrNone) || !result)
sl@0
   178
		{
sl@0
   179
		Release();
sl@0
   180
		}
sl@0
   181
	else
sl@0
   182
		{
sl@0
   183
		(*refCountInterface)++;
sl@0
   184
		aReturnedInterface = result;
sl@0
   185
		}
sl@0
   186
sl@0
   187
	TRequestStatus* r = &aStatus;
sl@0
   188
	User::RequestComplete(r, error);
sl@0
   189
	}
sl@0
   190
sl@0
   191
TBool CTest1CertStoreToken::DoCancelGetInterface()
sl@0
   192
	{
sl@0
   193
	return EFalse;
sl@0
   194
	}
sl@0
   195
sl@0
   196
CTest1CertStoreToken::CTest1CertStoreToken(CTest1CertStoreTokenType::TTokenId aTokenId,
sl@0
   197
										   CTest1CertStoreTokenType& aFileCertStoreTokenType)
sl@0
   198
	:  iTokenType(aFileCertStoreTokenType), iTokenId(aTokenId)
sl@0
   199
	{
sl@0
   200
	}