sl@0: /* sl@0: * Copyright (c) 2001-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 sl@0: #include sl@0: #include "mctauthobject.h" sl@0: #include "mctkeystore.h" sl@0: #include "mctkeystoremanager.h" sl@0: #include sl@0: #include "ct/logger.h" sl@0: sl@0: #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS sl@0: sl@0: /** The type ID of CCTKeyInfo objects */ sl@0: const TUid KKeyInfoUID = {0x101F5152}; sl@0: sl@0: #endif sl@0: //////////////////////////////////////////////////////////////////////////////// sl@0: // CKeyInfoBase sl@0: //////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: EXPORT_C CKeyInfoBase::CKeyInfoBase(TKeyIdentifier aID, sl@0: TKeyUsagePKCS15 aUsage, sl@0: TUint aSize, sl@0: HBufC* aLabel, sl@0: TInt aHandle, sl@0: const TSecurityPolicy& aUsePolicy, sl@0: const TSecurityPolicy& aManagementPolicy, sl@0: EKeyAlgorithm aAlgorithm, sl@0: TInt aAccessType, sl@0: TBool aNative, sl@0: TTime aStartDate, sl@0: TTime aEndDate, sl@0: HBufC8* aPKCS8AttributeSet) : sl@0: iID(aID), sl@0: iUsage(aUsage), sl@0: iSize(aSize), sl@0: iLabel(aLabel), sl@0: iHandle(aHandle), sl@0: iUsePolicy(aUsePolicy), sl@0: iManagementPolicy(aManagementPolicy), sl@0: iAlgorithm(aAlgorithm), sl@0: iAccessType(aAccessType), sl@0: iNative(aNative), sl@0: iStartDate(aStartDate), sl@0: iEndDate(aEndDate), sl@0: iPKCS8AttributeSet(aPKCS8AttributeSet) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C CKeyInfoBase::CKeyInfoBase() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C CKeyInfoBase::~CKeyInfoBase() sl@0: { sl@0: delete iLabel; sl@0: delete iPKCS8AttributeSet; sl@0: } sl@0: sl@0: EXPORT_C void CKeyInfoBase::ConstructL() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void CKeyInfoBase::ConstructL(RReadStream& aIn) sl@0: { sl@0: // Called from derived classes' NewL methods when interalizing a stream sl@0: sl@0: InternalizeL(aIn); sl@0: } sl@0: sl@0: EXPORT_C void CKeyInfoBase::ExternalizeL(RWriteStream& aStream) const sl@0: { sl@0: aStream.WriteL(iID); sl@0: aStream.WriteInt32L(iUsage); sl@0: aStream.WriteUint32L(iSize); sl@0: aStream.WriteInt32L(iLabel->Length()); sl@0: TPtr16 theLabel(iLabel->Des()); sl@0: aStream.WriteL(theLabel); sl@0: aStream.WriteInt32L(iHandle); sl@0: aStream.WriteL(TPckgC(iUsePolicy)); sl@0: aStream.WriteL(TPckgC(iManagementPolicy)); sl@0: aStream.WriteInt32L(iAlgorithm); sl@0: aStream.WriteInt32L(iAccessType); sl@0: aStream.WriteInt32L(iNative); sl@0: aStream.WriteL(TPckgC(iStartDate)); sl@0: aStream.WriteL(TPckgC(iEndDate)); sl@0: sl@0: if (iPKCS8AttributeSet) sl@0: { sl@0: aStream.WriteInt32L(iPKCS8AttributeSet->Length()); sl@0: TPtr8 theAttributes(iPKCS8AttributeSet->Des()); sl@0: aStream.WriteL(theAttributes); sl@0: } sl@0: else sl@0: aStream.WriteInt32L(0); sl@0: } sl@0: sl@0: void CKeyInfoBase::InternalizeL(RReadStream& aStream) sl@0: { sl@0: aStream.ReadL(iID); sl@0: iUsage = static_cast(aStream.ReadInt32L()); sl@0: iSize = aStream.ReadUint32L(); sl@0: sl@0: TInt labelLen = aStream.ReadInt32L(); sl@0: iLabel = HBufC::NewMaxL(labelLen); sl@0: TPtr pLabel(iLabel->Des()); sl@0: pLabel.FillZ(); sl@0: // This will have made the length of pLabel equal to the length of sl@0: // the alloc cell of iLabel, which may be longer than labelLen. So sl@0: // we need to pass the length we want to read into ReadL sl@0: aStream.ReadL(pLabel, labelLen); sl@0: sl@0: iHandle = aStream.ReadInt32L(); sl@0: sl@0: TPckg usePolicy(iUsePolicy); sl@0: aStream.ReadL(usePolicy); sl@0: TPckg managementPolicy(iManagementPolicy); sl@0: aStream.ReadL(managementPolicy); sl@0: sl@0: iAlgorithm = (EKeyAlgorithm)(aStream.ReadInt32L()); sl@0: iAccessType = (EKeyAccess)(aStream.ReadInt32L()); sl@0: iNative = (TBool)(aStream.ReadInt32L()); sl@0: TPckg startDate(iStartDate); sl@0: aStream.ReadL(startDate); sl@0: TPckg endDate(iEndDate); sl@0: aStream.ReadL(endDate); sl@0: sl@0: TInt attributeLen = aStream.ReadInt32L(); sl@0: if (attributeLen > 0) sl@0: { sl@0: iPKCS8AttributeSet = HBufC8::NewMaxL(attributeLen); sl@0: TPtr8 pAttributes(iPKCS8AttributeSet->Des()); sl@0: pAttributes.FillZ(); sl@0: // This will have made the length of pAttributes equal to the length of sl@0: // the alloc cell of iPKCS8AttributeSet, which may be longer than attributeLen sl@0: // So we need to pass the length we want to read into ReadL sl@0: aStream.ReadL(pAttributes, attributeLen); sl@0: } sl@0: } sl@0: sl@0: //////////////////////////////////////////////////////////////////////////////// sl@0: // CCTKeyInfo sl@0: //////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: EXPORT_C CCTKeyInfo* CCTKeyInfo::NewL(TKeyIdentifier aID, sl@0: TKeyUsagePKCS15 aUsage, sl@0: TUint aSize, sl@0: MCTAuthenticationObject* aProtector, sl@0: HBufC* aLabel, sl@0: MCTToken& aToken, sl@0: TInt aHandle, sl@0: const TSecurityPolicy& aUsePolicy, sl@0: const TSecurityPolicy& aManagementPolicy, sl@0: EKeyAlgorithm aAlgorithm, sl@0: TInt aAccessType, sl@0: TBool aNative, sl@0: TTime aStartDate, sl@0: TTime aEndDate, sl@0: HBufC8* aPKCS8AttributeSet /*= NULL*/) sl@0: { sl@0: CCTKeyInfo* me = NULL; sl@0: me = new (ELeave) CCTKeyInfo(aID, sl@0: aUsage, sl@0: aSize, sl@0: aProtector, sl@0: aLabel, sl@0: aToken, sl@0: aHandle, sl@0: aUsePolicy, sl@0: aManagementPolicy, sl@0: aAlgorithm, sl@0: aAccessType, sl@0: aNative, sl@0: aStartDate, sl@0: aEndDate, sl@0: aPKCS8AttributeSet); sl@0: sl@0: CleanupReleasePushL(*me); sl@0: me->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: sl@0: return me; sl@0: } sl@0: sl@0: CCTKeyInfo::CCTKeyInfo(TKeyIdentifier aID, sl@0: TKeyUsagePKCS15 aUsage, sl@0: TUint aSize, sl@0: MCTAuthenticationObject* aProtector, sl@0: HBufC* aLabel, sl@0: MCTToken& aToken, sl@0: TInt aHandle, sl@0: const TSecurityPolicy& aUsePolicy, sl@0: const TSecurityPolicy& aManagementPolicy, sl@0: EKeyAlgorithm aAlgorithm, sl@0: TInt aAccessType, sl@0: TBool aNative, sl@0: TTime aStartDate, sl@0: TTime aEndDate, sl@0: HBufC8* aPKCS8AttributeSet /*= NULL*/) : sl@0: CKeyInfoBase(aID, sl@0: aUsage, sl@0: aSize, sl@0: aLabel, sl@0: aHandle, sl@0: aUsePolicy, sl@0: aManagementPolicy, sl@0: aAlgorithm, sl@0: aAccessType, sl@0: aNative, sl@0: aStartDate, sl@0: aEndDate, sl@0: aPKCS8AttributeSet), sl@0: MCTTokenObject(aToken), sl@0: iToken(aToken), sl@0: iProtector(aProtector) sl@0: { sl@0: LOG1(_L("CCTKeyInfo::CCTKeyInfo() with iProtector %08x"), iProtector); sl@0: } sl@0: sl@0: EXPORT_C CCTKeyInfo* CCTKeyInfo::NewL(RReadStream& aStream, MCTToken& aToken) sl@0: { sl@0: CCTKeyInfo* me = new (ELeave) CCTKeyInfo(aToken); sl@0: CleanupReleasePushL(*me); sl@0: me->ConstructL(aStream); sl@0: CleanupStack::Pop(); sl@0: return me; sl@0: } sl@0: sl@0: CCTKeyInfo::CCTKeyInfo(MCTToken& aToken) : sl@0: CKeyInfoBase(), sl@0: MCTTokenObject(aToken), sl@0: iToken(aToken) sl@0: { sl@0: } sl@0: sl@0: CCTKeyInfo::~CCTKeyInfo() sl@0: { sl@0: LOG(_L("CCTKeyInfo::~CCTKeyInfo")); sl@0: if (iProtector) sl@0: { sl@0: LOG_INC_INDENT(); sl@0: iProtector->Release(); sl@0: LOG_DEC_INDENT(); sl@0: } sl@0: } sl@0: sl@0: const TDesC& CCTKeyInfo::Label() const sl@0: { sl@0: return CKeyInfoBase::Label(); sl@0: } sl@0: sl@0: MCTToken& CCTKeyInfo::Token() const sl@0: { sl@0: return iToken; sl@0: } sl@0: sl@0: TUid CCTKeyInfo::Type() const sl@0: { sl@0: return KKeyInfoUID; sl@0: } sl@0: sl@0: TCTTokenObjectHandle CCTKeyInfo::Handle() const sl@0: { sl@0: return TCTTokenObjectHandle(Token().Handle(), HandleID()); sl@0: } sl@0: sl@0: //////////////////////////////////////////////////////////////////////////////// sl@0: // TCTKeyAttributeFilter sl@0: //////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: EXPORT_C TCTKeyAttributeFilter::TCTKeyAttributeFilter() sl@0: { sl@0: iKeyId = KNullDesC8; sl@0: iUsage = EPKCS15UsageAll; sl@0: iPolicyFilter = EUsableKeys; sl@0: iKeyAlgorithm = CCTKeyInfo::EInvalidAlgorithm; sl@0: }