Update contrib.
2 * Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
21 #include "mctauthobject.h"
22 #include "mctkeystore.h"
23 #include "mctkeystoremanager.h"
24 #include <securityerr.h>
25 #include "ct/logger.h"
27 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
29 /** The type ID of CCTKeyInfo objects */
30 const TUid KKeyInfoUID = {0x101F5152};
33 ////////////////////////////////////////////////////////////////////////////////
35 ////////////////////////////////////////////////////////////////////////////////
37 EXPORT_C CKeyInfoBase::CKeyInfoBase(TKeyIdentifier aID,
38 TKeyUsagePKCS15 aUsage,
42 const TSecurityPolicy& aUsePolicy,
43 const TSecurityPolicy& aManagementPolicy,
44 EKeyAlgorithm aAlgorithm,
49 HBufC8* aPKCS8AttributeSet) :
55 iUsePolicy(aUsePolicy),
56 iManagementPolicy(aManagementPolicy),
57 iAlgorithm(aAlgorithm),
58 iAccessType(aAccessType),
60 iStartDate(aStartDate),
62 iPKCS8AttributeSet(aPKCS8AttributeSet)
66 EXPORT_C CKeyInfoBase::CKeyInfoBase()
70 EXPORT_C CKeyInfoBase::~CKeyInfoBase()
73 delete iPKCS8AttributeSet;
76 EXPORT_C void CKeyInfoBase::ConstructL()
80 EXPORT_C void CKeyInfoBase::ConstructL(RReadStream& aIn)
82 // Called from derived classes' NewL methods when interalizing a stream
87 EXPORT_C void CKeyInfoBase::ExternalizeL(RWriteStream& aStream) const
90 aStream.WriteInt32L(iUsage);
91 aStream.WriteUint32L(iSize);
92 aStream.WriteInt32L(iLabel->Length());
93 TPtr16 theLabel(iLabel->Des());
94 aStream.WriteL(theLabel);
95 aStream.WriteInt32L(iHandle);
96 aStream.WriteL(TPckgC<TSecurityPolicy>(iUsePolicy));
97 aStream.WriteL(TPckgC<TSecurityPolicy>(iManagementPolicy));
98 aStream.WriteInt32L(iAlgorithm);
99 aStream.WriteInt32L(iAccessType);
100 aStream.WriteInt32L(iNative);
101 aStream.WriteL(TPckgC<TTime>(iStartDate));
102 aStream.WriteL(TPckgC<TTime>(iEndDate));
104 if (iPKCS8AttributeSet)
106 aStream.WriteInt32L(iPKCS8AttributeSet->Length());
107 TPtr8 theAttributes(iPKCS8AttributeSet->Des());
108 aStream.WriteL(theAttributes);
111 aStream.WriteInt32L(0);
114 void CKeyInfoBase::InternalizeL(RReadStream& aStream)
117 iUsage = static_cast<TKeyUsagePKCS15>(aStream.ReadInt32L());
118 iSize = aStream.ReadUint32L();
120 TInt labelLen = aStream.ReadInt32L();
121 iLabel = HBufC::NewMaxL(labelLen);
122 TPtr pLabel(iLabel->Des());
124 // This will have made the length of pLabel equal to the length of
125 // the alloc cell of iLabel, which may be longer than labelLen. So
126 // we need to pass the length we want to read into ReadL
127 aStream.ReadL(pLabel, labelLen);
129 iHandle = aStream.ReadInt32L();
131 TPckg<TSecurityPolicy> usePolicy(iUsePolicy);
132 aStream.ReadL(usePolicy);
133 TPckg<TSecurityPolicy> managementPolicy(iManagementPolicy);
134 aStream.ReadL(managementPolicy);
136 iAlgorithm = (EKeyAlgorithm)(aStream.ReadInt32L());
137 iAccessType = (EKeyAccess)(aStream.ReadInt32L());
138 iNative = (TBool)(aStream.ReadInt32L());
139 TPckg<TTime> startDate(iStartDate);
140 aStream.ReadL(startDate);
141 TPckg<TTime> endDate(iEndDate);
142 aStream.ReadL(endDate);
144 TInt attributeLen = aStream.ReadInt32L();
145 if (attributeLen > 0)
147 iPKCS8AttributeSet = HBufC8::NewMaxL(attributeLen);
148 TPtr8 pAttributes(iPKCS8AttributeSet->Des());
150 // This will have made the length of pAttributes equal to the length of
151 // the alloc cell of iPKCS8AttributeSet, which may be longer than attributeLen
152 // So we need to pass the length we want to read into ReadL
153 aStream.ReadL(pAttributes, attributeLen);
157 ////////////////////////////////////////////////////////////////////////////////
159 ////////////////////////////////////////////////////////////////////////////////
161 EXPORT_C CCTKeyInfo* CCTKeyInfo::NewL(TKeyIdentifier aID,
162 TKeyUsagePKCS15 aUsage,
164 MCTAuthenticationObject* aProtector,
168 const TSecurityPolicy& aUsePolicy,
169 const TSecurityPolicy& aManagementPolicy,
170 EKeyAlgorithm aAlgorithm,
175 HBufC8* aPKCS8AttributeSet /*= NULL*/)
177 CCTKeyInfo* me = NULL;
178 me = new (ELeave) CCTKeyInfo(aID,
194 CleanupReleasePushL(*me);
201 CCTKeyInfo::CCTKeyInfo(TKeyIdentifier aID,
202 TKeyUsagePKCS15 aUsage,
204 MCTAuthenticationObject* aProtector,
208 const TSecurityPolicy& aUsePolicy,
209 const TSecurityPolicy& aManagementPolicy,
210 EKeyAlgorithm aAlgorithm,
215 HBufC8* aPKCS8AttributeSet /*= NULL*/) :
229 MCTTokenObject(aToken),
231 iProtector(aProtector)
233 LOG1(_L("CCTKeyInfo::CCTKeyInfo() with iProtector %08x"), iProtector);
236 EXPORT_C CCTKeyInfo* CCTKeyInfo::NewL(RReadStream& aStream, MCTToken& aToken)
238 CCTKeyInfo* me = new (ELeave) CCTKeyInfo(aToken);
239 CleanupReleasePushL(*me);
240 me->ConstructL(aStream);
245 CCTKeyInfo::CCTKeyInfo(MCTToken& aToken) :
247 MCTTokenObject(aToken),
252 CCTKeyInfo::~CCTKeyInfo()
254 LOG(_L("CCTKeyInfo::~CCTKeyInfo"));
258 iProtector->Release();
263 const TDesC& CCTKeyInfo::Label() const
265 return CKeyInfoBase::Label();
268 MCTToken& CCTKeyInfo::Token() const
273 TUid CCTKeyInfo::Type() const
278 TCTTokenObjectHandle CCTKeyInfo::Handle() const
280 return TCTTokenObjectHandle(Token().Handle(), HandleID());
283 ////////////////////////////////////////////////////////////////////////////////
284 // TCTKeyAttributeFilter
285 ////////////////////////////////////////////////////////////////////////////////
287 EXPORT_C TCTKeyAttributeFilter::TCTKeyAttributeFilter()
290 iUsage = EPKCS15UsageAll;
291 iPolicyFilter = EUsableKeys;
292 iKeyAlgorithm = CCTKeyInfo::EInvalidAlgorithm;