os/security/cryptoservices/certificateandkeymgmt/tadditionalstores/Test1certstoretoken.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/tadditionalstores/Test1certstoretoken.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,200 @@
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 +#include "test1certstoretoken.h"
1.23 +#include "test1certstore.h"
1.24 +
1.25 +_LIT(KName1, "Test store 1");
1.26 +_LIT(KName2, "Test store 2");
1.27 +#ifdef CERTSTORE_HARDWARE_SIM
1.28 + _LIT(KTest1CertStoreFullPath, "\\system\\data\\test1simcertstore.dat");
1.29 + _LIT(KTest2CertStoreFullPath, "\\system\\data\\test2simcertstore.dat");
1.30 +#else
1.31 + #ifdef CERTSTORE_HARDWARE_WIM
1.32 + _LIT(KTest1CertStoreFullPath, "\\system\\data\\test1wimcertstore.dat");
1.33 + _LIT(KTest2CertStoreFullPath, "\\system\\data\\test2wimcertstore.dat");
1.34 + #else
1.35 + #ifdef CERTSTORE_HARDWARE_UICC
1.36 + _LIT(KTest1CertStoreFullPath, "\\system\\data\\test1uicccertstore.dat");
1.37 + _LIT(KTest2CertStoreFullPath, "\\system\\data\\test2uicccertstore.dat");
1.38 + #else
1.39 + #ifdef CERTSTORE_DEVICE_IMMUTABLE
1.40 + _LIT(KTest1CertStoreFullPath, "\\system\\data\\test1deviceimmutablecertstore.dat");
1.41 + _LIT(KTest2CertStoreFullPath, "\\system\\data\\test2deviceimmutablecertstore.dat");
1.42 + #else
1.43 + _LIT(KTest1CertStoreFullPath, "\\system\\data\\test1certstore.dat");
1.44 + _LIT(KTest2CertStoreFullPath, "\\system\\data\\test2certstore.dat");
1.45 + #endif
1.46 + #endif
1.47 + #endif
1.48 +#endif
1.49 +
1.50 +
1.51 +CTest1CertStoreToken* CTest1CertStoreToken::New(CTest1CertStoreTokenType::TTokenId aTokenId,
1.52 + CTest1CertStoreTokenType& aFileCertStoreTokenType)
1.53 + {
1.54 + return new CTest1CertStoreToken(aTokenId, aFileCertStoreTokenType);
1.55 + }
1.56 +
1.57 +CTest1CertStoreToken::~CTest1CertStoreToken()
1.58 + {
1.59 + }
1.60 +
1.61 +MCTTokenType& CTest1CertStoreToken::TokenType()
1.62 + {
1.63 + return iTokenType;
1.64 + }
1.65 +
1.66 +const TDesC& CTest1CertStoreToken::Label()
1.67 + {
1.68 + switch (iTokenId)
1.69 + {
1.70 + case CTest1CertStoreTokenType::ETest1CertStore:
1.71 + return KName1;
1.72 +
1.73 + case CTest1CertStoreTokenType::ETest2CertStore:
1.74 + return KName2;
1.75 +
1.76 + default:
1.77 + return KNullDesC;
1.78 + }
1.79 + }
1.80 +
1.81 +const TDesC& CTest1CertStoreToken::Information(TTokenInformation)
1.82 + {
1.83 + _LIT(KAnswer, "I Know Nothing");
1.84 + return KAnswer;
1.85 + }
1.86 +
1.87 +TCTTokenHandle CTest1CertStoreToken::Handle()
1.88 + {
1.89 + return TCTTokenHandle(iTokenType.Type(), iTokenId);
1.90 + }
1.91 +
1.92 +void CTest1CertStoreToken::DoRelease()
1.93 + {
1.94 + delete this;
1.95 + }
1.96 +
1.97 +TInt& CTest1CertStoreToken::ReferenceCount()
1.98 + {
1.99 + return iRefCount;
1.100 + }
1.101 +
1.102 +void CTest1CertStoreToken::DoGetInterface(TUid aRequiredInterface,
1.103 + MCTTokenInterface*& aReturnedInterface,
1.104 + TRequestStatus& aStatus)
1.105 + {
1.106 + RFs& fs = static_cast<CCTTokenType&>(TokenType()).Fs();
1.107 + MCTTokenInterface* result = 0;
1.108 + TInt error = KErrNone;
1.109 +
1.110 + //gets the system drive
1.111 + TDriveUnit sysDrive (RFs::GetSystemDrive());
1.112 + TDriveName driveName(sysDrive.Name());
1.113 + TBuf<128> fullPath (driveName);
1.114 + TInt* refCountInterface = &iRefCountInterface;
1.115 +
1.116 + if (iTokenId == CTest1CertStoreTokenType::ETest1CertStore)
1.117 + {
1.118 + fullPath.Append(KTest1CertStoreFullPath);
1.119 + refCountInterface = &iRefCountInterface;
1.120 + }
1.121 +
1.122 + // This is mainly used for testing and also as an example on how to manage
1.123 + // multiple tokens within one TokenType.
1.124 + else if (iTokenId == CTest1CertStoreTokenType::ETest2CertStore)
1.125 + {
1.126 + fullPath.Append(KTest2CertStoreFullPath);
1.127 + refCountInterface = &iRefCountInterface2;
1.128 + }
1.129 + else
1.130 + {
1.131 + // If not certstore 1 or 2, then we complete with bad name.
1.132 + TRequestStatus* r = &aStatus;
1.133 + User::RequestComplete(r, KErrBadName);
1.134 + return;
1.135 + }
1.136 +
1.137 + switch (aRequiredInterface.iUid)
1.138 + {
1.139 + case KInterfaceCertStore:
1.140 + {
1.141 + if (!iFileCertStore)
1.142 + {
1.143 + TRAP(error, iFileCertStore = CTest1CertStore::NewL(fs, *this, fullPath,
1.144 + EFileShareReadersOnly));
1.145 + iFileMode = EFileRead;
1.146 + }
1.147 + MCTCertStore* temp = iFileCertStore;
1.148 + result = temp;
1.149 + }
1.150 + break;
1.151 +
1.152 + case KInterfaceWritableCertStore:
1.153 + {
1.154 + if (!iFileCertStore)
1.155 + {
1.156 + TRAP(error, iFileCertStore = CTest1CertStore::NewL(fs, *this, fullPath, EFileWrite));
1.157 + iFileMode = EFileWrite;
1.158 + }
1.159 + if (iFileMode == EFileRead)
1.160 + {
1.161 + error = KErrInUse;
1.162 + }
1.163 + else
1.164 + {
1.165 + MCTWritableCertStore* temp = iFileCertStore;
1.166 + result = temp;
1.167 + }
1.168 + }
1.169 + break;
1.170 +
1.171 + default:
1.172 + error = KErrNotSupported;
1.173 + break;
1.174 + }
1.175 +
1.176 + if (error == KErrNotSupported)
1.177 + {
1.178 + Release();
1.179 + }
1.180 + else if ((error != KErrNone) || !result)
1.181 + {
1.182 + Release();
1.183 + }
1.184 + else
1.185 + {
1.186 + (*refCountInterface)++;
1.187 + aReturnedInterface = result;
1.188 + }
1.189 +
1.190 + TRequestStatus* r = &aStatus;
1.191 + User::RequestComplete(r, error);
1.192 + }
1.193 +
1.194 +TBool CTest1CertStoreToken::DoCancelGetInterface()
1.195 + {
1.196 + return EFalse;
1.197 + }
1.198 +
1.199 +CTest1CertStoreToken::CTest1CertStoreToken(CTest1CertStoreTokenType::TTokenId aTokenId,
1.200 + CTest1CertStoreTokenType& aFileCertStoreTokenType)
1.201 + : iTokenType(aFileCertStoreTokenType), iTokenId(aTokenId)
1.202 + {
1.203 + }