sl@0: /* sl@0: * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "unifiedcertstore.h" sl@0: #include "unifiedcertstoreworkingvars.h" sl@0: #include "CCheckedCertStore.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: _LIT(KUCSPanic, "CUnifiedCertStore"); sl@0: #define assert(x) __ASSERT_ALWAYS((x), User::Panic(KUCSPanic, 1)); sl@0: sl@0: ///////////////////////////////////////////////////////////////////////////////////// sl@0: //CUnifiedCertStore sl@0: ///////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: EXPORT_C CUnifiedCertStore* CUnifiedCertStore::NewL(RFs& aFs, TBool aOpenForWrite) sl@0: { sl@0: CUnifiedCertStore* self = CUnifiedCertStore::NewLC(aFs, aOpenForWrite); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CUnifiedCertStore* CUnifiedCertStore::NewLC(RFs& aFs, TBool aOpenForWrite) sl@0: { sl@0: CUnifiedCertStore* self = new(ELeave) CUnifiedCertStore(aFs, aOpenForWrite); sl@0: CleanupStack::PushL(self); sl@0: RArray orderingFilter; sl@0: self->ConstructL(orderingFilter); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CUnifiedCertStore::~CUnifiedCertStore() sl@0: { sl@0: Cancel(); sl@0: sl@0: assert(!iWorkingVars); sl@0: sl@0: TInt end = iReadOnlyCertStores.Count(); sl@0: TInt i; sl@0: for (i = 0; i < end; i++) sl@0: { sl@0: iReadOnlyCertStores[i]->Release(); sl@0: } sl@0: iReadOnlyCertStores.Close(); sl@0: sl@0: end = iWritableCertStores.Count(); sl@0: for (i = 0; i < end; i++) sl@0: { sl@0: iWritableCertStores[i]->Release(); sl@0: } sl@0: iWritableCertStores.Close(); sl@0: sl@0: // The elements are already released by the two loops above sl@0: iCertStores.Close(); sl@0: sl@0: // release resources allocated to order attributes list sl@0: iOrderAttributes.Close(); sl@0: sl@0: DestroyTemporaryMembers(); sl@0: iHardwareTypeUids.Close(); sl@0: REComSession::FinalClose(); sl@0: } sl@0: sl@0: sl@0: EXPORT_C void CUnifiedCertStore::Initialize(TRequestStatus& aStatus) sl@0: { sl@0: BeginAsyncOp(aStatus, EInitializeGetTokenList); sl@0: TRAPD(err, InitializeL()); sl@0: if (err != KErrNone) sl@0: { sl@0: Complete(err); sl@0: } sl@0: } sl@0: sl@0: void CUnifiedCertStore::InitializeL() sl@0: { sl@0: AllocWorkingVarsL(); sl@0: sl@0: // We want the list of all token types that support a readable or writable sl@0: // certstore interface sl@0: RArray uidArray; sl@0: CleanupClosePushL(uidArray); sl@0: sl@0: User::LeaveIfError(uidArray.Append(TUid::Uid(KInterfaceWritableCertStore))); sl@0: sl@0: TCTFindTokenTypesByInterface filter(uidArray.Array()); sl@0: CCTTokenTypeInfo::ListL(iWorkingVars->iWritableTokenTypes, filter); sl@0: sl@0: uidArray.Reset(); sl@0: sl@0: User::LeaveIfError(uidArray.Append(TUid::Uid(KInterfaceCertStore))); sl@0: sl@0: RCPointerArray tokenTypes; sl@0: CleanupClosePushL(tokenTypes); sl@0: sl@0: TCTFindTokenTypesByInterface filter2(uidArray.Array()); sl@0: CCTTokenTypeInfo::ListL(tokenTypes, filter2); sl@0: sl@0: // Check whether client specified order list has attributes in it sl@0: if(iOrderAttributes.Count() > 0) sl@0: { sl@0: ApplyOrderingL(tokenTypes); sl@0: } sl@0: sl@0: // Make a note of all hardware token types sl@0: TInt i = 0; sl@0: TInt end = tokenTypes.Count(); sl@0: for (; i < end; i++) sl@0: { sl@0: TCTTokenTypeAttribute software; sl@0: software.iUID = KCTSoftware; sl@0: TInt find = tokenTypes[i]->Attributes().Find(software); sl@0: // In the case (TInt)ETrue == KThirdPartyCertStore == 1 sl@0: if (find != KErrNotFound && tokenTypes[i]->Attributes()[find].iVal != sl@0: (TInt)ETrue && tokenTypes[i]->Attributes()[find].iVal != KManufactureCertStore) sl@0: { sl@0: // This is a hardware type. Add its UID to the list. sl@0: User::LeaveIfError(iHardwareTypeUids.Append(tokenTypes[i]->Type())); sl@0: } sl@0: } sl@0: sl@0: i = 0; sl@0: while (i < end) sl@0: { sl@0: TInt j = 0; sl@0: TInt jEnd = iWorkingVars->iWritableTokenTypes.Count(); sl@0: while (j < jEnd) sl@0: { sl@0: if (iWorkingVars->iWritableTokenTypes[j]->Type() == tokenTypes[i]->Type()) sl@0: { sl@0: break; sl@0: } sl@0: j++; sl@0: } sl@0: if (j == jEnd) sl@0: { sl@0: User::LeaveIfError(iWorkingVars->iReadOnlyTokenTypes.Append(tokenTypes[i])); sl@0: tokenTypes.Remove(i); sl@0: end--; sl@0: } sl@0: else sl@0: { sl@0: i++; sl@0: } sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(2); // uidArray, tokenTypes sl@0: sl@0: iWorkingVars->iIndex = -1; sl@0: sl@0: TRequestStatus* status = &iStatus; sl@0: User::RequestComplete(status, KErrNone); sl@0: SetActive(); sl@0: } sl@0: sl@0: EXPORT_C void CUnifiedCertStore::CancelInitialize() sl@0: { sl@0: if (iState == EInitializeGetTokenList || sl@0: iState == EInitializeGetToken || sl@0: iState == EInitializeGetWritableInterface || sl@0: iState == EInitializeGetReadableInterface || sl@0: iState == EInitializeGetReadableInterfaceFinished || sl@0: iState == EInitializeFinished) sl@0: { sl@0: Cancel(); sl@0: } sl@0: } sl@0: sl@0: void CUnifiedCertStore::List(RMPointerArray& aCertInfos, sl@0: const CCertAttributeFilter& aFilter, sl@0: TRequestStatus& aStatus) sl@0: { sl@0: BeginAsyncOp(aStatus, EList); sl@0: TRAPD(err, ListL(aCertInfos, aFilter)); sl@0: if (err != KErrNone) sl@0: { sl@0: Complete(err); sl@0: } sl@0: } sl@0: sl@0: void CUnifiedCertStore::ListL(RMPointerArray& aCertInfos, sl@0: const CCertAttributeFilter& aFilter) sl@0: { sl@0: if (!iIsInitialized) sl@0: { sl@0: User::Leave(KErrNotReady); sl@0: } sl@0: sl@0: AllocWorkingVarsL(); sl@0: iWorkingVars->iCertInfos = &aCertInfos; sl@0: iWorkingVars->iFilter = &aFilter; sl@0: iWorkingVars->iCertIndex = aCertInfos.Count(); sl@0: iIndex = -1; sl@0: sl@0: SetActive(); sl@0: TRequestStatus* status = &iStatus; sl@0: User::RequestComplete(status, KErrNone); sl@0: } sl@0: sl@0: void CUnifiedCertStore::CancelList() sl@0: { sl@0: if (iState == EList || sl@0: iState == ERetrieveForList) sl@0: { sl@0: Cancel(); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CUnifiedCertStore::List(RMPointerArray& aCertInfos, sl@0: const CCertAttributeFilter& aFilter, sl@0: const TDesC8& aIssuer, sl@0: TRequestStatus& aStatus) sl@0: { sl@0: RPointerArray array; sl@0: if (array.Append(&aIssuer) != KErrNone) sl@0: { sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, KErrNoMemory); sl@0: } sl@0: else sl@0: { sl@0: List(aCertInfos, aFilter, array, aStatus); sl@0: array.Close(); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CUnifiedCertStore::List(RMPointerArray& aCertInfos, sl@0: const CCertAttributeFilter& aFilter, sl@0: RPointerArray aIssuers, sl@0: TRequestStatus& aStatus) sl@0: { sl@0: BeginAsyncOp(aStatus, EList); sl@0: TRAPD(err, ListL(aCertInfos, aFilter, aIssuers)); sl@0: if (err != KErrNone) sl@0: { sl@0: Complete(err); sl@0: } sl@0: } sl@0: sl@0: void CUnifiedCertStore::ListL(RMPointerArray& aCertInfos, sl@0: const CCertAttributeFilter& aFilter, sl@0: RPointerArray aIssuers) sl@0: { sl@0: // Obscure special case: If aIssuers has no elements, we should sl@0: // return nothing. sl@0: if (aIssuers.Count() == 0) sl@0: { sl@0: Complete(KErrNone); sl@0: return; sl@0: } sl@0: sl@0: AllocWorkingVarsL(); sl@0: iWorkingVars->iCertInfos = &aCertInfos; sl@0: iWorkingVars->iFilter = &aFilter; sl@0: iWorkingVars->iCertIndex = aCertInfos.Count(); sl@0: sl@0: TInt count = aIssuers.Count(); sl@0: for (TInt i = 0 ; i < count ; ++i) sl@0: { sl@0: User::LeaveIfError(iWorkingVars->iIssuerNames.Append(aIssuers[i])); sl@0: } sl@0: sl@0: iIndex = -1; sl@0: SetActive(); sl@0: TRequestStatus* status = &iStatus; sl@0: User::RequestComplete(status, KErrNone); sl@0: } sl@0: sl@0: EXPORT_C void CUnifiedCertStore::Retrieve(const CCTCertInfo& aCertInfo, sl@0: CCertificate*& aCert, sl@0: TRequestStatus& aStatus) sl@0: { sl@0: BeginAsyncOp(aStatus, ERetrieve); sl@0: TRAPD(err, RetrieveL(aCertInfo, aCert)); sl@0: if (err != KErrNone) sl@0: { sl@0: Complete(err); sl@0: } sl@0: } sl@0: sl@0: void CUnifiedCertStore::RetrieveL(const CCTCertInfo& aCertInfo, sl@0: CCertificate*& aCert) sl@0: { sl@0: FindCertStoreL(aCertInfo.Handle()); sl@0: sl@0: if (aCertInfo.CertificateFormat() != EX509Certificate && sl@0: aCertInfo.CertificateFormat() != EWTLSCertificate) sl@0: { sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: sl@0: AllocWorkingVarsL(); sl@0: iWorkingVars->iCertDesC = HBufC8::NewMaxL(aCertInfo.Size()); sl@0: iWorkingVars->iReturnedCert = &aCert; sl@0: iWorkingVars->iCertType = aCertInfo.CertificateFormat(); sl@0: iWorkingVars->iCertDes.Set(iWorkingVars->iCertDesC->Des()); sl@0: iCurrentCertStore->Retrieve(aCertInfo, iWorkingVars->iCertDes, iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: void CUnifiedCertStore::GetCert(CCTCertInfo*& aCertInfo, sl@0: const TCTTokenObjectHandle& aHandle, sl@0: TRequestStatus& aStatus) sl@0: { sl@0: BeginAsyncOp(aStatus, EGetCert); sl@0: TRAPD(err, GetCertL(aCertInfo, aHandle)); sl@0: if (err != KErrNone) sl@0: { sl@0: Complete(err); sl@0: } sl@0: } sl@0: sl@0: void CUnifiedCertStore::GetCertL(CCTCertInfo*& aCertInfo, sl@0: const TCTTokenObjectHandle& aHandle) sl@0: { sl@0: FindCertStoreL(aHandle); sl@0: iCurrentCertStore->GetCert(aCertInfo, aHandle, iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: void CUnifiedCertStore::CancelGetCert() sl@0: { sl@0: if (iState == EGetCert) sl@0: { sl@0: Cancel(); sl@0: } sl@0: } sl@0: sl@0: void CUnifiedCertStore::Applications(const CCTCertInfo& aCertInfo, sl@0: RArray& aApplications, sl@0: TRequestStatus& aStatus) sl@0: { sl@0: BeginAsyncOp(aStatus, EApplications); sl@0: TRAPD(err, ApplicationsL(aCertInfo, aApplications)); sl@0: if (err != KErrNone) sl@0: { sl@0: Complete(err); sl@0: } sl@0: } sl@0: sl@0: void CUnifiedCertStore::ApplicationsL(const CCTCertInfo& aCertInfo, sl@0: RArray& aApplications) sl@0: { sl@0: FindCertStoreL(aCertInfo.Handle()); sl@0: iCurrentCertStore->Applications(aCertInfo, aApplications, iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: void CUnifiedCertStore::CancelApplications() sl@0: { sl@0: if (iState == EApplications) sl@0: { sl@0: Cancel(); sl@0: } sl@0: } sl@0: sl@0: void CUnifiedCertStore::IsApplicable(const CCTCertInfo& aCertInfo, sl@0: TUid aApplication, sl@0: TBool& aIsApplicable, sl@0: TRequestStatus& aStatus) sl@0: { sl@0: BeginAsyncOp(aStatus, EIsApplicable); sl@0: TRAPD(err, IsApplicableL(aCertInfo, aApplication, aIsApplicable)); sl@0: if (err != KErrNone) sl@0: { sl@0: Complete(err); sl@0: } sl@0: } sl@0: sl@0: void CUnifiedCertStore::IsApplicableL(const CCTCertInfo& aCertInfo, sl@0: TUid aApplication, sl@0: TBool& aIsApplicable) sl@0: { sl@0: FindCertStoreL(aCertInfo.Handle()); sl@0: iCurrentCertStore->IsApplicable(aCertInfo, aApplication, aIsApplicable, iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: void CUnifiedCertStore::CancelIsApplicable() sl@0: { sl@0: if (iState == EIsApplicable) sl@0: { sl@0: Cancel(); sl@0: } sl@0: } sl@0: sl@0: void CUnifiedCertStore::Trusted(const CCTCertInfo& aCertInfo, sl@0: TBool& aTrusted, sl@0: TRequestStatus& aStatus) sl@0: { sl@0: BeginAsyncOp(aStatus, ETrusted); sl@0: TRAPD(err, TrustedL(aCertInfo, aTrusted)); sl@0: if (err != KErrNone) sl@0: { sl@0: Complete(err); sl@0: } sl@0: } sl@0: sl@0: void CUnifiedCertStore::TrustedL(const CCTCertInfo& aCertInfo, sl@0: TBool& aTrusted) sl@0: { sl@0: FindCertStoreL(aCertInfo.Handle()); sl@0: iCurrentCertStore->Trusted(aCertInfo, aTrusted, iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: void CUnifiedCertStore::CancelTrusted() sl@0: { sl@0: if (iState == ETrusted) sl@0: { sl@0: Cancel(); sl@0: } sl@0: } sl@0: sl@0: void CUnifiedCertStore::Retrieve(const CCTCertInfo& aCertInfo, sl@0: TDes8& aEncodedCert, sl@0: TRequestStatus& aStatus) sl@0: { sl@0: BeginAsyncOp(aStatus, ERetrieveData); sl@0: TRAPD(err, RetrieveDataL(aCertInfo, aEncodedCert)); sl@0: if (err != KErrNone) sl@0: { sl@0: Complete(err); sl@0: } sl@0: } sl@0: sl@0: void CUnifiedCertStore::RetrieveDataL(const CCTCertInfo& aCertInfo, sl@0: TDes8& aEncodedCert) sl@0: { sl@0: FindCertStoreL(aCertInfo.Handle()); sl@0: iCurrentCertStore->Retrieve(aCertInfo, aEncodedCert, iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: void CUnifiedCertStore::CancelRetrieve() sl@0: { sl@0: if (iState == ERetrieveData) sl@0: { sl@0: Cancel(); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CUnifiedCertStore::Remove(const CCTCertInfo& aCertInfo, sl@0: TRequestStatus& aStatus) sl@0: { sl@0: BeginAsyncOp(aStatus, ERemove); sl@0: TRAPD(err, RemoveL(aCertInfo)); sl@0: if (err != KErrNone) sl@0: { sl@0: Complete(err); sl@0: } sl@0: } sl@0: sl@0: void CUnifiedCertStore::RemoveL(const CCTCertInfo& aCertInfo) sl@0: { sl@0: FindWritableCertStoreL(aCertInfo.Handle()); sl@0: iCurrentWritableCertStore->Remove(aCertInfo, iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: EXPORT_C void CUnifiedCertStore::CancelRemove() sl@0: { sl@0: if (iState == ERemove) sl@0: { sl@0: Cancel(); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CUnifiedCertStore::SetApplicability(const CCTCertInfo& aCertInfo, sl@0: const RArray& aApplications, sl@0: TRequestStatus& aStatus) sl@0: { sl@0: BeginAsyncOp(aStatus, ESetApplicability); sl@0: TRAPD(err, SetApplicabilityL(aCertInfo, aApplications)); sl@0: if (err != KErrNone) sl@0: { sl@0: Complete(err); sl@0: } sl@0: } sl@0: sl@0: void CUnifiedCertStore::SetApplicabilityL(const CCTCertInfo& aCertInfo, sl@0: const RArray& aApplications) sl@0: { sl@0: FindWritableCertStoreL(aCertInfo.Handle()); sl@0: sl@0: // Search for duplicates in the array of application sl@0: // complete with KErrArgument if there are any duplicates sl@0: if(aApplications.Count() > 1) sl@0: { sl@0: TInt i=0, j=1; sl@0: sl@0: for(i=0; i& applications = appInfoManager->Applications(); sl@0: sl@0: for (TInt i = 0 ; i < aApplications.Count() ; ++i) sl@0: { sl@0: TInt j = 0; sl@0: for ( ; j < applications.Count() ; ++j) sl@0: { sl@0: if (aApplications[i] == applications[j].Id()) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: if (j == applications.Count()) sl@0: { sl@0: User::Leave(KErrArgument); sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(appInfoManager); sl@0: sl@0: iCurrentWritableCertStore->SetApplicability(aCertInfo, aApplications, iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: EXPORT_C void CUnifiedCertStore::CancelSetApplicability() sl@0: { sl@0: if (iState == ESetApplicability) sl@0: { sl@0: Cancel(); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CUnifiedCertStore::SetTrust(const CCTCertInfo& aCertInfo, sl@0: TBool aTrusted, sl@0: TRequestStatus& aStatus) sl@0: { sl@0: BeginAsyncOp(aStatus, ESetTrust); sl@0: TRAPD(err, SetTrustL(aCertInfo, aTrusted)); sl@0: if (err != KErrNone) sl@0: { sl@0: Complete(err); sl@0: } sl@0: } sl@0: sl@0: void CUnifiedCertStore::SetTrustL(const CCTCertInfo& aCertInfo, TBool aTrusted) sl@0: { sl@0: FindWritableCertStoreL(aCertInfo.Handle()); sl@0: iCurrentWritableCertStore->SetTrust(aCertInfo, aTrusted, iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: EXPORT_C void CUnifiedCertStore::CancelSetTrust() sl@0: { sl@0: if (iState == ESetTrust) sl@0: { sl@0: Cancel(); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Get the certstore containing a given certificate. sl@0: * sl@0: * Returns the certstore containing the cert referenced in certinfo or NULL if sl@0: * not found. sl@0: */ sl@0: MCTCertStore* CUnifiedCertStore::GetCertStore(const TCTTokenObjectHandle& aHandle) sl@0: { sl@0: TInt count = iCertStores.Count(); sl@0: for (TInt i = 0; i < count; i++) sl@0: { sl@0: MCTCertStore* certstore = iCertStores[i]; sl@0: MCTToken& token = certstore->Token(); sl@0: if (token.Handle() == aHandle.iTokenHandle) sl@0: { sl@0: return certstore; sl@0: } sl@0: } sl@0: return NULL; sl@0: } sl@0: sl@0: /** sl@0: * Set iCurrentCertStore to the certstore containing a given certificate, or sl@0: * leave if it could not be found. The handle is the handle of the *certinfo*, sl@0: * *NOT* the token. sl@0: */ sl@0: void CUnifiedCertStore::FindCertStoreL(const TCTTokenObjectHandle& aHandle) sl@0: { sl@0: assert(!iCurrentCertStore); sl@0: assert(!iCurrentWritableCertStore); sl@0: sl@0: if (!iIsInitialized) sl@0: { sl@0: User::Leave(KErrNotReady); sl@0: } sl@0: sl@0: iCurrentCertStore = GetCertStore(aHandle); sl@0: sl@0: if (!iCurrentCertStore) sl@0: { sl@0: User::Leave(KErrNotFound); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: * Set iCurrentWritableCertStore to the writable certstore containing a given sl@0: * certificate, or leave if it could not be found. The handle is the handle of sl@0: * the *certinfo*, *NOT* the token. sl@0: */ sl@0: void CUnifiedCertStore::FindWritableCertStoreL(const TCTTokenObjectHandle& aHandle) sl@0: { sl@0: assert(!iCurrentCertStore); sl@0: assert(!iCurrentWritableCertStore); sl@0: sl@0: if (!iIsInitialized) sl@0: { sl@0: User::Leave(KErrNotReady); sl@0: } sl@0: sl@0: if (!iOpenedForWrite) sl@0: { sl@0: User::Leave(KErrAccessDenied); sl@0: } sl@0: sl@0: iCurrentWritableCertStore = NULL; sl@0: TInt count = iWritableCertStores.Count(); sl@0: for (TInt i = 0; i < count; i++) sl@0: { sl@0: MCTWritableCertStore* certstore = iWritableCertStores[i]; sl@0: MCTToken& token = certstore->Token(); sl@0: if (token.Handle() == aHandle.iTokenHandle) sl@0: { sl@0: iCurrentWritableCertStore = certstore; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: if (!iCurrentWritableCertStore) sl@0: { sl@0: User::Leave(KErrNotFound); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C TInt CUnifiedCertStore::CertStoreCount() const sl@0: { sl@0: return iCertStores.Count(); sl@0: } sl@0: sl@0: EXPORT_C MCTCertStore& CUnifiedCertStore::CertStore(TInt aIndex) sl@0: { sl@0: assert(aIndex < iCertStores.Count()); sl@0: return *iCertStores[aIndex]; sl@0: } sl@0: sl@0: EXPORT_C TInt CUnifiedCertStore::WritableCertStoreCount() const sl@0: { sl@0: return iWritableCertStores.Count(); sl@0: } sl@0: sl@0: EXPORT_C MCTWritableCertStore& CUnifiedCertStore::WritableCertStore(TInt aIndex) sl@0: { sl@0: assert(aIndex < iWritableCertStores.Count()); sl@0: return *iWritableCertStores[aIndex]; sl@0: } sl@0: sl@0: EXPORT_C TInt CUnifiedCertStore::ReadOnlyCertStoreCount() const sl@0: { sl@0: return iReadOnlyCertStores.Count(); sl@0: } sl@0: sl@0: EXPORT_C MCTCertStore& CUnifiedCertStore::ReadOnlyCertStore(TInt aIndex) sl@0: { sl@0: assert(aIndex < iReadOnlyCertStores.Count()); sl@0: return *iReadOnlyCertStores[aIndex]; sl@0: } sl@0: sl@0: CUnifiedCertStore::CUnifiedCertStore(RFs& aFs, TBool aOpenForWrite) sl@0: : CActive(EPriorityNormal), iFs(aFs), iOpenedForWrite(aOpenForWrite), iOrderAttributes() sl@0: { sl@0: CActiveScheduler::Add(this); sl@0: assert(IsAdded()); sl@0: } sl@0: sl@0: void CUnifiedCertStore::ConstructL(RArray& aOrderFilter) sl@0: { sl@0: sl@0: for (TInt i=0;iiIndex++; sl@0: TInt end; sl@0: if (!iCurrentlyDoingReadOnly) sl@0: { sl@0: end = iWorkingVars->iWritableTokenTypes.Count(); sl@0: } sl@0: else sl@0: { sl@0: end = iWorkingVars->iReadOnlyTokenTypes.Count(); sl@0: } sl@0: if (iWorkingVars->iIndex < end) sl@0: { sl@0: assert(!iTokenType); sl@0: TInt createRes = KErrNone; sl@0: if (iCurrentlyDoingReadOnly) sl@0: { sl@0: TRAP(createRes, iTokenType = MCTTokenType::NewL(*iWorkingVars->iReadOnlyTokenTypes[iWorkingVars->iIndex], iFs)); sl@0: } sl@0: else sl@0: { sl@0: TRAP(createRes, iTokenType = MCTTokenType::NewL(*iWorkingVars->iWritableTokenTypes[iWorkingVars->iIndex], iFs)); sl@0: } sl@0: sl@0: if (KErrNoMemory==createRes) sl@0: { sl@0: // Leave if there's no memory, so OOM tests work sl@0: User::Leave(createRes); sl@0: } sl@0: else if (KErrNone!=createRes) sl@0: { sl@0: // ECOM couldn't load that token type, don't give up, try the next... sl@0: TRequestStatus* stat = &iStatus; sl@0: User::RequestComplete(stat, KErrNone); sl@0: } sl@0: else sl@0: { sl@0: assert(iTokens.Count() == 0); sl@0: iTokenType->List(iTokens, iStatus); sl@0: iIndexTokens = -1; sl@0: iState = EInitializeGetToken; sl@0: } sl@0: } sl@0: else if (!iCurrentlyDoingReadOnly) sl@0: { sl@0: iCurrentlyDoingReadOnly = ETrue; sl@0: iWorkingVars->iIndex = -1; sl@0: TRequestStatus* status = &iStatus; sl@0: User::RequestComplete(status, KErrNone); sl@0: } sl@0: else sl@0: { sl@0: iState = EInitializeFinished; sl@0: TRequestStatus* status = &iStatus; sl@0: User::RequestComplete(status, KErrNone); sl@0: } sl@0: SetActive(); sl@0: break; sl@0: sl@0: case EInitializeGetToken: sl@0: if (iStatus.Int() == KErrHardwareNotAvailable) sl@0: { sl@0: // If the hardware corresponding to this sl@0: // TokenType has been removed then just skip it sl@0: // but DO NOT leave! sl@0: ++iIndexTokens; sl@0: iState = EInitializeGetToken; sl@0: TRequestStatus* status = &iStatus; sl@0: User::RequestComplete(status,KErrNone); sl@0: } sl@0: else sl@0: { sl@0: User::LeaveIfError(iStatus.Int()); sl@0: sl@0: // iIndexTokens is initialized at EInitializeGetTokenList sl@0: ++iIndexTokens; sl@0: sl@0: // We need to try to get a certstore interface (readable or sl@0: // writable) for each of the Tokens in iTokens sl@0: if (iIndexTokens < iTokens.Count()) sl@0: { sl@0: assert(!iToken); sl@0: iTokenType->OpenToken(*iTokens[iIndexTokens], iToken, iStatus); sl@0: if ((iOpenedForWrite) && !iCurrentlyDoingReadOnly) sl@0: { sl@0: iState = EInitializeGetWritableInterface; sl@0: } sl@0: else sl@0: { sl@0: iState = EInitializeGetReadableInterface; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: // We don't need the iTokenType anymore sl@0: iTokenType->Release(); sl@0: iTokenType = 0; sl@0: // We don't need the list of Tokens anymore sl@0: iTokens.Close(); sl@0: iState = EInitializeGetTokenList; sl@0: TRequestStatus* status = &iStatus; sl@0: User::RequestComplete(status, KErrNone); sl@0: } sl@0: } sl@0: SetActive(); sl@0: break; sl@0: sl@0: case EInitializeGetWritableInterface: sl@0: { sl@0: User::LeaveIfError(iStatus.Int()); sl@0: // First we try to get a writable interface to the store, if sl@0: // that doesn't work we will try to get a readable interface sl@0: assert(iToken); sl@0: assert(!iTokenInterface); sl@0: TUid uid = { KInterfaceWritableCertStore }; sl@0: iToken->GetInterface(uid, iTokenInterface, iStatus); sl@0: iState = EInitializeGetReadableInterface; sl@0: SetActive(); sl@0: } sl@0: break; sl@0: sl@0: case EInitializeGetReadableInterface: sl@0: // We check if we managed to get a writable interface sl@0: if (iStatus == KErrNoMemory) sl@0: { sl@0: User::Leave(KErrNoMemory); sl@0: } sl@0: sl@0: if (!iCurrentlyDoingReadOnly && iOpenedForWrite && (iStatus == KErrNone)) sl@0: { sl@0: assert(iTokenInterface); sl@0: sl@0: // Drop the interface into a "writable checking" object sl@0: CCheckedCertStore* interf = sl@0: CCheckedCertStore::NewCheckedWritableCertStoreL(iTokenInterface, iPSCertstoreChangeProperty); sl@0: sl@0: CleanupReleasePushL(*interf); sl@0: iTokenInterface = 0; sl@0: sl@0: User::LeaveIfError(iWritableCertStores.Append(interf)); sl@0: CleanupStack::Pop(); sl@0: sl@0: User::LeaveIfError(iCertStores.Append(interf)); sl@0: sl@0: // We don't need the Token anymore sl@0: iToken->Release(); sl@0: iToken = 0; sl@0: iState = EInitializeGetToken; sl@0: TRequestStatus* status = &iStatus; sl@0: User::RequestComplete(status, KErrNone); sl@0: } sl@0: else sl@0: { sl@0: // We do the check only if we were not trying to get a Writeable Interface sl@0: // before, if we trying to get a writeable interface before, we know that we sl@0: // have a valid iToken. sl@0: if ((iCurrentlyDoingReadOnly || !iOpenedForWrite) && (iStatus != KErrNone)) sl@0: { sl@0: User::Leave(iStatus.Int()); sl@0: } sl@0: else sl@0: { sl@0: assert(iToken); sl@0: assert(!iTokenInterface); sl@0: TUid uid = { KInterfaceCertStore }; sl@0: iToken->GetInterface(uid, iTokenInterface, iStatus); sl@0: iState = EInitializeGetReadableInterfaceFinished; sl@0: } sl@0: } sl@0: SetActive(); sl@0: break; sl@0: sl@0: case EInitializeGetReadableInterfaceFinished: sl@0: { sl@0: if (iStatus == KErrNoMemory) sl@0: { sl@0: User::Leave(KErrNoMemory); sl@0: } sl@0: sl@0: if (iStatus == KErrNone) sl@0: { sl@0: assert(iTokenInterface); sl@0: sl@0: // Drop the interface into a "read only checking" object sl@0: CCheckedCertStore* interf = sl@0: CCheckedCertStore::NewCheckedCertStoreL(iTokenInterface, iPSCertstoreChangeProperty); sl@0: sl@0: CleanupReleasePushL(*interf); sl@0: iTokenInterface = 0; sl@0: sl@0: User::LeaveIfError(iReadOnlyCertStores.Append(interf)); sl@0: CleanupStack::Pop(interf); sl@0: sl@0: User::LeaveIfError(iCertStores.Append(interf)); sl@0: } sl@0: sl@0: // We don't need the Token anymore sl@0: iToken->Release(); sl@0: iToken = 0; sl@0: sl@0: iStatus = KErrNone; sl@0: iState = EInitializeGetToken; sl@0: TRequestStatus* status = &iStatus; sl@0: User::RequestComplete(status, iStatus.Int()); sl@0: SetActive(); sl@0: } sl@0: break; sl@0: sl@0: case EInitializeFinished: sl@0: assert(!iTokenType); sl@0: assert(!iToken); sl@0: assert(!iTokenInterface); sl@0: iIsInitialized = ETrue; sl@0: Complete(iStatus.Int()); sl@0: break; sl@0: sl@0: case EList: sl@0: // iIndex has been initialized in List sl@0: iIndex++; sl@0: iCurrentCertStore = NULL; sl@0: if (iIndex < iCertStores.Count()) sl@0: { sl@0: iCurrentCertStore = iCertStores[iIndex]; sl@0: iCurrentCertStore->List(*iWorkingVars->iCertInfos, *iWorkingVars->iFilter, iStatus); sl@0: iWorkingVars->iCertIndex = 0; sl@0: SetActive(); sl@0: } sl@0: else if (iWorkingVars->iIssuerNames.Count() > 0) sl@0: { sl@0: // We have an issuer name. We now remove all certs sl@0: // that don't match that issuer. sl@0: sl@0: // If this is the first time in here, we need to parse sl@0: // and hash all the issuer names. sl@0: if (iWorkingVars->iParsedIssuerNames.Count() == 0) sl@0: { sl@0: CSHA1* sha1 = CSHA1::NewL(); sl@0: CleanupStack::PushL(sha1); sl@0: TInt count = iWorkingVars->iIssuerNames.Count(); sl@0: for (TInt i = 0; i < count; i++) sl@0: { sl@0: CX500DistinguishedName* dn = sl@0: CX500DistinguishedName::NewLC(*iWorkingVars-> sl@0: iIssuerNames[i]); sl@0: User::LeaveIfError( sl@0: iWorkingVars->iParsedIssuerNames.Append(dn)); sl@0: CleanupStack::Pop(dn); sl@0: TPtrC8 hash=sha1->Hash(*iWorkingVars->iIssuerNames[i]); sl@0: User::LeaveIfError( sl@0: iWorkingVars->iHashedIssuerNames.Append( sl@0: hash.AllocLC())); sl@0: CleanupStack::Pop(); sl@0: } sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: sl@0: while (iWorkingVars->iCertIndex < sl@0: iWorkingVars->iCertInfos->Count()) sl@0: { sl@0: CCTCertInfo* info = sl@0: (*iWorkingVars->iCertInfos)[iWorkingVars->iCertIndex]; sl@0: TCompareResults res = CompareCertInfoDN(info); sl@0: if (res == EYes) sl@0: { sl@0: // It matches. leave it for the next one. sl@0: iWorkingVars->iCertIndex++; sl@0: } sl@0: else if (res == ENo) sl@0: { sl@0: // It doesn't match. Remove it and try the next one. sl@0: info->Release(); sl@0: iWorkingVars->iCertInfos-> sl@0: Remove(iWorkingVars->iCertIndex); sl@0: } sl@0: else // res == EMaybe sl@0: { sl@0: // Need to load the cert and properly compare the DNs. sl@0: iCurrentCertStore = GetCertStore(info->Handle()); sl@0: assert(iCurrentCertStore); sl@0: sl@0: iWorkingVars->iCertDesC=HBufC8::NewMaxL(info->Size()); sl@0: iWorkingVars->iCertType = info->CertificateFormat(); sl@0: iState = ERetrieveForList; sl@0: iWorkingVars->iCertDes.Set(iWorkingVars->iCertDesC->Des()); sl@0: iCurrentCertStore->Retrieve(*info, iWorkingVars->iCertDes, iStatus); sl@0: SetActive(); sl@0: return; sl@0: } sl@0: } sl@0: Complete(KErrNone); sl@0: } sl@0: else sl@0: { sl@0: Complete(KErrNone); sl@0: } sl@0: break; sl@0: sl@0: case ERetrieve: sl@0: { sl@0: switch (iWorkingVars->iCertType) sl@0: { sl@0: case EX509Certificate: sl@0: { sl@0: TPtr8 theCert(iWorkingVars->iCertDesC->Des()); sl@0: *(iWorkingVars->iReturnedCert) = CX509Certificate::NewL(theCert); sl@0: } sl@0: break; sl@0: case EWTLSCertificate: sl@0: { sl@0: TPtr8 theCert(iWorkingVars->iCertDesC->Des()); sl@0: *(iWorkingVars->iReturnedCert) = CWTLSCertificate::NewL(theCert); sl@0: } sl@0: break; sl@0: default: sl@0: assert(EFalse); sl@0: break; sl@0: } sl@0: Complete(KErrNone); sl@0: } sl@0: break; sl@0: sl@0: case ERetrieveForList: sl@0: { sl@0: TPtr8 theCert(iWorkingVars->iCertDesC->Des()); sl@0: CX509Certificate* cert=CX509Certificate::NewLC(theCert); sl@0: if (MatchL(cert->IssuerName())) sl@0: { sl@0: // It matches. leave it for the next one. sl@0: iWorkingVars->iCertIndex++; sl@0: } sl@0: else sl@0: { sl@0: // It doesn't match. Remove it and try the next one. sl@0: (*iWorkingVars->iCertInfos)[iWorkingVars->iCertIndex]->Release(); sl@0: iWorkingVars->iCertInfos->Remove(iWorkingVars->iCertIndex); sl@0: } sl@0: CleanupStack::PopAndDestroy(cert); sl@0: delete iWorkingVars->iCertDesC; sl@0: iWorkingVars->iCertDesC = 0; sl@0: iState = EList; sl@0: SetActive(); sl@0: TRequestStatus* status = & iStatus; sl@0: User::RequestComplete(status, KErrNone); sl@0: break; sl@0: } sl@0: sl@0: case ERemove: sl@0: case ESetApplicability: sl@0: case ESetTrust: sl@0: case EGetCert: sl@0: case EApplications: sl@0: case EIsApplicable: sl@0: case ETrusted: sl@0: case ERetrieveData: sl@0: Complete(KErrNone); sl@0: break; sl@0: sl@0: default: sl@0: User::Panic(KUCSPanic, 1); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: TInt CUnifiedCertStore::RunError(TInt aError) sl@0: { sl@0: Complete(aError); sl@0: return KErrNone; sl@0: } sl@0: sl@0: void CUnifiedCertStore::DoCancel() sl@0: { sl@0: // If the current state is the last state involved in handling a request, we sl@0: // check to see if we have already been completed - in this case we can sl@0: // simply complete the client with iStatus (this may be KErrNone). If we sl@0: // have not we cancel the outstanding request and pass the resulting iStatus sl@0: // back to the client - this too may indicate a successful completion if the sl@0: // cancel arrived after the request was executed. sl@0: // sl@0: // For more complex cases, where there are more states to go through before sl@0: // we finish servicing the client request, we cancel any outstanding sl@0: // request, and return KErrCancel to the client. sl@0: sl@0: switch (iState) sl@0: { sl@0: case EInitializeFinished: sl@0: case ERetrieve: sl@0: case EGetCert: sl@0: case EApplications: sl@0: case EIsApplicable: sl@0: case ETrusted: sl@0: case ERetrieveData: sl@0: case ERemove: sl@0: case ESetApplicability: sl@0: case ESetTrust: sl@0: if (iStatus == KRequestPending) sl@0: { sl@0: // Attempt to cancel outstanding request and pass status back to sl@0: // client sl@0: CancelOutstandingRequest(); sl@0: Complete(iStatus.Int()); sl@0: } sl@0: else sl@0: { sl@0: // We've already been completed - call RunL() to process results sl@0: // and complete client sl@0: TRAPD(err, RunL()); sl@0: if (err != KErrNone) sl@0: { sl@0: RunError(err); sl@0: } sl@0: } sl@0: break; sl@0: sl@0: default: sl@0: CancelOutstandingRequest(); sl@0: Complete(KErrCancel); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void CUnifiedCertStore::CancelOutstandingRequest() sl@0: { sl@0: switch (iState) sl@0: { sl@0: case EInitializeGetTokenList: sl@0: case EInitializeGetToken: sl@0: case EInitializeGetWritableInterface: sl@0: case EInitializeGetReadableInterface: sl@0: case EInitializeGetReadableInterfaceFinished: sl@0: case EInitializeFinished: sl@0: // Don't have to cancel initialisation stuff - this happens when we sl@0: // release the objects in DestroyTemporaryMembers(). sl@0: iStatus = KErrCancel; sl@0: break; sl@0: sl@0: case EList: sl@0: if (iCurrentCertStore) sl@0: { sl@0: iCurrentCertStore->CancelList(); sl@0: } sl@0: break; sl@0: sl@0: case ERetrieve: sl@0: case ERetrieveForList: sl@0: case ERetrieveData: sl@0: assert(iCurrentCertStore); sl@0: iCurrentCertStore->CancelRetrieve(); sl@0: break; sl@0: sl@0: case EGetCert: sl@0: assert(iCurrentCertStore); sl@0: iCurrentCertStore->CancelGetCert(); sl@0: break; sl@0: sl@0: case EApplications: sl@0: assert(iCurrentCertStore); sl@0: iCurrentCertStore->CancelApplications(); sl@0: break; sl@0: sl@0: case EIsApplicable: sl@0: assert(iCurrentCertStore); sl@0: iCurrentCertStore->CancelIsApplicable(); sl@0: break; sl@0: sl@0: case ETrusted: sl@0: assert(iCurrentCertStore); sl@0: iCurrentCertStore->CancelTrusted(); sl@0: break; sl@0: sl@0: case ERemove: sl@0: assert(iCurrentWritableCertStore); sl@0: iCurrentWritableCertStore->CancelRemove(); sl@0: break; sl@0: sl@0: case ESetApplicability: sl@0: assert(iCurrentWritableCertStore); sl@0: iCurrentWritableCertStore->CancelSetApplicability(); sl@0: break; sl@0: sl@0: case ESetTrust: sl@0: assert(iCurrentWritableCertStore); sl@0: iCurrentWritableCertStore->CancelSetTrust(); sl@0: break; sl@0: sl@0: default: sl@0: User::Panic(KUCSPanic, 1); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: TBool CUnifiedCertStore::MatchL(const CX500DistinguishedName& aName) const sl@0: { sl@0: // Return true if the supplied DN is the same as any of the supplied DNs. sl@0: TInt count = iWorkingVars->iIssuerNames.Count(); sl@0: for (TInt i = 0; i < count; i++) sl@0: { sl@0: if (aName.ExactMatchL(*iWorkingVars->iParsedIssuerNames[i])) sl@0: return ETrue; sl@0: } sl@0: return EFalse; sl@0: } sl@0: sl@0: void CUnifiedCertStore::AllocWorkingVarsL() sl@0: { sl@0: assert(!iWorkingVars); sl@0: iWorkingVars = new (ELeave) CUnifiedCertStoreWorkingVars; sl@0: } sl@0: sl@0: void CUnifiedCertStore::BeginAsyncOp(TRequestStatus& aStatus, TState aState) sl@0: { sl@0: assert(iState == EIdle); sl@0: assert(!iClientStatus); sl@0: sl@0: iClientStatus = &aStatus; sl@0: *iClientStatus = KRequestPending; sl@0: iState = aState; sl@0: } sl@0: sl@0: void CUnifiedCertStore::Complete(TInt aError) sl@0: { sl@0: assert(iClientStatus); sl@0: User::RequestComplete(iClientStatus, aError); sl@0: DestroyTemporaryMembers(); sl@0: iState = EIdle; sl@0: } sl@0: sl@0: void CUnifiedCertStore::DestroyTemporaryMembers() sl@0: { sl@0: if (!iIsInitialized) sl@0: { sl@0: TInt end = iReadOnlyCertStores.Count(); sl@0: TInt i; sl@0: for (i = 0; i < end; i++) sl@0: { sl@0: iReadOnlyCertStores[i]->Release(); sl@0: } sl@0: iReadOnlyCertStores.Close(); sl@0: sl@0: end = iWritableCertStores.Count(); sl@0: for (i = 0; i < end; i++) sl@0: { sl@0: iWritableCertStores[i]->Release(); sl@0: } sl@0: iWritableCertStores.Close(); sl@0: sl@0: // The elements are already released by the two loops above sl@0: iCertStores.Close(); sl@0: } sl@0: sl@0: if (iTokenType) sl@0: { sl@0: iTokenType->Release(); sl@0: iTokenType = 0; sl@0: } sl@0: sl@0: if (iToken) sl@0: { sl@0: iToken->Release(); sl@0: iToken = 0; sl@0: } sl@0: sl@0: if (iTokenInterface) sl@0: { sl@0: iTokenInterface->Release(); sl@0: iTokenInterface = 0; sl@0: } sl@0: sl@0: iTokens.Close(); sl@0: sl@0: delete iWorkingVars; sl@0: iWorkingVars = 0; sl@0: sl@0: iCurrentCertStore = NULL; sl@0: iCurrentWritableCertStore = NULL; sl@0: } sl@0: sl@0: CUnifiedCertStore::TCompareResults sl@0: CUnifiedCertStore::CompareCertInfoDN(const CCTCertInfo* aCertInfo) sl@0: { sl@0: if (aCertInfo->IssuerHash() && sl@0: (aCertInfo->CertificateFormat() == EX509CertificateUrl || sl@0: iHardwareTypeUids.Find(aCertInfo->Token().TokenType().Type()) != sl@0: KErrNotFound)) sl@0: { sl@0: TInt count = iWorkingVars->iHashedIssuerNames.Count(); sl@0: for (TInt i = 0; i < count; i++) sl@0: { sl@0: if (*aCertInfo->IssuerHash()==*iWorkingVars->iHashedIssuerNames[i]) sl@0: return EYes; sl@0: } sl@0: return ENo; sl@0: } sl@0: if (aCertInfo->CertificateFormat() != EX509Certificate) sl@0: return ENo; sl@0: return EMaybe; sl@0: } sl@0: sl@0: EXPORT_C CUnifiedCertStore* CUnifiedCertStore::NewL(RFs& aFs, sl@0: TBool aOpenForWrite, sl@0: RArray& aOrderFilter) sl@0: { sl@0: CUnifiedCertStore* self = CUnifiedCertStore::NewLC(aFs, sl@0: aOpenForWrite, sl@0: aOrderFilter); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: EXPORT_C CUnifiedCertStore* CUnifiedCertStore::NewLC(RFs& aFs, sl@0: TBool aOpenForWrite, sl@0: RArray& aOrderFilter) sl@0: { sl@0: CUnifiedCertStore* self = new(ELeave) CUnifiedCertStore(aFs, sl@0: aOpenForWrite); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aOrderFilter); sl@0: return self; sl@0: } sl@0: sl@0: void CUnifiedCertStore::FilterTokenTypesL(RCPointerArray& aSearchTokenTypes, sl@0: RCPointerArray& aTempTokenTypes, sl@0: TInt aOrderAttribute) sl@0: { sl@0: //We allow aOrderAttribute=KUnknownHardwareCertStore here to keep DC. sl@0: //assert(aOrderAttribute); sl@0: sl@0: // Get number of token types sl@0: TInt tokenTypesCount = aSearchTokenTypes.Count(); sl@0: sl@0: // loop through token types sl@0: for(TInt tokenTypesLoop = tokenTypesCount-1; tokenTypesLoop >= 0; tokenTypesLoop--) sl@0: { sl@0: // get the list of attributes supported by this token type. sl@0: // Note: The attribute list consists of values such as sl@0: // KCTSoftware defined in TCTTokenTypeAttribute.h sl@0: const RArray& attributesList = sl@0: aSearchTokenTypes[tokenTypesLoop]->Attributes(); sl@0: sl@0: // Get the number of attributes in the attribute list. sl@0: // The number of attributes will match the ECOM resource sl@0: // file definition. E.g. see 101f5015.rss for the software sl@0: // implementation of certstore. sl@0: TInt attributeCount = attributesList.Count(); sl@0: sl@0: // Check each attribute in the attribute list sl@0: for(TInt attribLoop = 0; attribLoop < attributeCount; attribLoop++) sl@0: { sl@0: // Check whether attribute in the list matches an order attribute sl@0: // E.g. KCTSoftware sl@0: if(attributesList[attribLoop].iUID == KCTSoftware sl@0: && attributesList[attribLoop].iVal == aOrderAttribute) sl@0: { sl@0: // Found the attribute of interest. Add token type to the temp container. sl@0: User::LeaveIfError(aTempTokenTypes.Append(aSearchTokenTypes[tokenTypesLoop])); sl@0: // Remove from the Searchlist. sl@0: aSearchTokenTypes.Remove(tokenTypesLoop); sl@0: // No need to examine the other attributes, so break loop sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CUnifiedCertStore::ApplyOrderingL(RCPointerArray& aTokenTypes) sl@0: { sl@0: // Number of attributes in ordering filter sl@0: TInt numOrderAttributes=iOrderAttributes.Count(); sl@0: assert(numOrderAttributes>0); sl@0: sl@0: // Contains writable tokens types sl@0: RCPointerArray tempWritableTokenTypes; sl@0: CleanupClosePushL(tempWritableTokenTypes); sl@0: sl@0: // Contains read-only tokens types sl@0: RCPointerArray tempReadOnlyTokenTypes; sl@0: CleanupClosePushL(tempReadOnlyTokenTypes); sl@0: sl@0: // For each order attribute, order the token types sl@0: for(TInt attributeLoop = 0; attributeLoop < numOrderAttributes; attributeLoop++) sl@0: { sl@0: // Get ordering attribute Uid from Order filter sl@0: TInt orderAttribute = iOrderAttributes[attributeLoop]; sl@0: sl@0: // Order for writable token types sl@0: FilterTokenTypesL(iWorkingVars->iWritableTokenTypes, sl@0: tempWritableTokenTypes, sl@0: orderAttribute); sl@0: sl@0: // Order for read-only token types sl@0: FilterTokenTypesL(aTokenTypes, sl@0: tempReadOnlyTokenTypes, sl@0: orderAttribute); sl@0: } sl@0: sl@0: // release and close the resources so can refill container, and get rid of sl@0: // the TokenType which have been filtered out. sl@0: TInt tokenTypesCount = iWorkingVars->iWritableTokenTypes.Count(); sl@0: TInt i; sl@0: for(i = tokenTypesCount-1; i >= 0 ;i--) sl@0: { sl@0: if (iWorkingVars->iWritableTokenTypes[i]) sl@0: { sl@0: CCTTokenTypeInfo* ptr=iWorkingVars->iWritableTokenTypes[i]; sl@0: iWorkingVars->iWritableTokenTypes.Remove(i); sl@0: delete ptr; sl@0: } sl@0: } sl@0: iWorkingVars->iWritableTokenTypes.Reset(); sl@0: sl@0: // release and close the resources so can refill container, and get rid of sl@0: // the TokenType which have been filtered out. sl@0: tokenTypesCount = aTokenTypes.Count(); sl@0: for(i = tokenTypesCount-1; i >= 0 ;i--) sl@0: { sl@0: if (aTokenTypes[i]) sl@0: { sl@0: CCTTokenTypeInfo* ptr=aTokenTypes[i]; sl@0: aTokenTypes.Remove(i); sl@0: delete ptr; sl@0: } sl@0: } sl@0: aTokenTypes.Reset(); sl@0: sl@0: // Assign contents of temp token types to containers. sl@0: // Note: temp tokens types are ordered according to user specification sl@0: tokenTypesCount = tempWritableTokenTypes.Count(); sl@0: for(i = 0; i < tokenTypesCount; i++) sl@0: { sl@0: User::LeaveIfError(iWorkingVars->iWritableTokenTypes.Append(tempWritableTokenTypes[i])); sl@0: tempWritableTokenTypes[i] = NULL; sl@0: } sl@0: sl@0: tokenTypesCount = tempReadOnlyTokenTypes.Count(); sl@0: for(i = 0; i < tokenTypesCount; i++) sl@0: { sl@0: User::LeaveIfError(aTokenTypes.Append(tempReadOnlyTokenTypes[i])); sl@0: tempReadOnlyTokenTypes[i] = NULL; sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(2); // tempReadOnlyTokenTypes, tempWritableTokenTypes, sl@0: } sl@0: