sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2001-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 <e32base.h>
|
sl@0
|
20 |
#include <ct.h>
|
sl@0
|
21 |
#include "mctauthobject.h"
|
sl@0
|
22 |
#include "mctkeystore.h"
|
sl@0
|
23 |
#include "mctkeystoremanager.h"
|
sl@0
|
24 |
#include <securityerr.h>
|
sl@0
|
25 |
#include "ct/logger.h"
|
sl@0
|
26 |
|
sl@0
|
27 |
#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
|
sl@0
|
28 |
|
sl@0
|
29 |
/** The type ID of CCTKeyInfo objects */
|
sl@0
|
30 |
const TUid KKeyInfoUID = {0x101F5152};
|
sl@0
|
31 |
|
sl@0
|
32 |
#endif
|
sl@0
|
33 |
////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
34 |
// CKeyInfoBase
|
sl@0
|
35 |
////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
36 |
|
sl@0
|
37 |
EXPORT_C CKeyInfoBase::CKeyInfoBase(TKeyIdentifier aID,
|
sl@0
|
38 |
TKeyUsagePKCS15 aUsage,
|
sl@0
|
39 |
TUint aSize,
|
sl@0
|
40 |
HBufC* aLabel,
|
sl@0
|
41 |
TInt aHandle,
|
sl@0
|
42 |
const TSecurityPolicy& aUsePolicy,
|
sl@0
|
43 |
const TSecurityPolicy& aManagementPolicy,
|
sl@0
|
44 |
EKeyAlgorithm aAlgorithm,
|
sl@0
|
45 |
TInt aAccessType,
|
sl@0
|
46 |
TBool aNative,
|
sl@0
|
47 |
TTime aStartDate,
|
sl@0
|
48 |
TTime aEndDate,
|
sl@0
|
49 |
HBufC8* aPKCS8AttributeSet) :
|
sl@0
|
50 |
iID(aID),
|
sl@0
|
51 |
iUsage(aUsage),
|
sl@0
|
52 |
iSize(aSize),
|
sl@0
|
53 |
iLabel(aLabel),
|
sl@0
|
54 |
iHandle(aHandle),
|
sl@0
|
55 |
iUsePolicy(aUsePolicy),
|
sl@0
|
56 |
iManagementPolicy(aManagementPolicy),
|
sl@0
|
57 |
iAlgorithm(aAlgorithm),
|
sl@0
|
58 |
iAccessType(aAccessType),
|
sl@0
|
59 |
iNative(aNative),
|
sl@0
|
60 |
iStartDate(aStartDate),
|
sl@0
|
61 |
iEndDate(aEndDate),
|
sl@0
|
62 |
iPKCS8AttributeSet(aPKCS8AttributeSet)
|
sl@0
|
63 |
{
|
sl@0
|
64 |
}
|
sl@0
|
65 |
|
sl@0
|
66 |
EXPORT_C CKeyInfoBase::CKeyInfoBase()
|
sl@0
|
67 |
{
|
sl@0
|
68 |
}
|
sl@0
|
69 |
|
sl@0
|
70 |
EXPORT_C CKeyInfoBase::~CKeyInfoBase()
|
sl@0
|
71 |
{
|
sl@0
|
72 |
delete iLabel;
|
sl@0
|
73 |
delete iPKCS8AttributeSet;
|
sl@0
|
74 |
}
|
sl@0
|
75 |
|
sl@0
|
76 |
EXPORT_C void CKeyInfoBase::ConstructL()
|
sl@0
|
77 |
{
|
sl@0
|
78 |
}
|
sl@0
|
79 |
|
sl@0
|
80 |
EXPORT_C void CKeyInfoBase::ConstructL(RReadStream& aIn)
|
sl@0
|
81 |
{
|
sl@0
|
82 |
// Called from derived classes' NewL methods when interalizing a stream
|
sl@0
|
83 |
|
sl@0
|
84 |
InternalizeL(aIn);
|
sl@0
|
85 |
}
|
sl@0
|
86 |
|
sl@0
|
87 |
EXPORT_C void CKeyInfoBase::ExternalizeL(RWriteStream& aStream) const
|
sl@0
|
88 |
{
|
sl@0
|
89 |
aStream.WriteL(iID);
|
sl@0
|
90 |
aStream.WriteInt32L(iUsage);
|
sl@0
|
91 |
aStream.WriteUint32L(iSize);
|
sl@0
|
92 |
aStream.WriteInt32L(iLabel->Length());
|
sl@0
|
93 |
TPtr16 theLabel(iLabel->Des());
|
sl@0
|
94 |
aStream.WriteL(theLabel);
|
sl@0
|
95 |
aStream.WriteInt32L(iHandle);
|
sl@0
|
96 |
aStream.WriteL(TPckgC<TSecurityPolicy>(iUsePolicy));
|
sl@0
|
97 |
aStream.WriteL(TPckgC<TSecurityPolicy>(iManagementPolicy));
|
sl@0
|
98 |
aStream.WriteInt32L(iAlgorithm);
|
sl@0
|
99 |
aStream.WriteInt32L(iAccessType);
|
sl@0
|
100 |
aStream.WriteInt32L(iNative);
|
sl@0
|
101 |
aStream.WriteL(TPckgC<TTime>(iStartDate));
|
sl@0
|
102 |
aStream.WriteL(TPckgC<TTime>(iEndDate));
|
sl@0
|
103 |
|
sl@0
|
104 |
if (iPKCS8AttributeSet)
|
sl@0
|
105 |
{
|
sl@0
|
106 |
aStream.WriteInt32L(iPKCS8AttributeSet->Length());
|
sl@0
|
107 |
TPtr8 theAttributes(iPKCS8AttributeSet->Des());
|
sl@0
|
108 |
aStream.WriteL(theAttributes);
|
sl@0
|
109 |
}
|
sl@0
|
110 |
else
|
sl@0
|
111 |
aStream.WriteInt32L(0);
|
sl@0
|
112 |
}
|
sl@0
|
113 |
|
sl@0
|
114 |
void CKeyInfoBase::InternalizeL(RReadStream& aStream)
|
sl@0
|
115 |
{
|
sl@0
|
116 |
aStream.ReadL(iID);
|
sl@0
|
117 |
iUsage = static_cast<TKeyUsagePKCS15>(aStream.ReadInt32L());
|
sl@0
|
118 |
iSize = aStream.ReadUint32L();
|
sl@0
|
119 |
|
sl@0
|
120 |
TInt labelLen = aStream.ReadInt32L();
|
sl@0
|
121 |
iLabel = HBufC::NewMaxL(labelLen);
|
sl@0
|
122 |
TPtr pLabel(iLabel->Des());
|
sl@0
|
123 |
pLabel.FillZ();
|
sl@0
|
124 |
// This will have made the length of pLabel equal to the length of
|
sl@0
|
125 |
// the alloc cell of iLabel, which may be longer than labelLen. So
|
sl@0
|
126 |
// we need to pass the length we want to read into ReadL
|
sl@0
|
127 |
aStream.ReadL(pLabel, labelLen);
|
sl@0
|
128 |
|
sl@0
|
129 |
iHandle = aStream.ReadInt32L();
|
sl@0
|
130 |
|
sl@0
|
131 |
TPckg<TSecurityPolicy> usePolicy(iUsePolicy);
|
sl@0
|
132 |
aStream.ReadL(usePolicy);
|
sl@0
|
133 |
TPckg<TSecurityPolicy> managementPolicy(iManagementPolicy);
|
sl@0
|
134 |
aStream.ReadL(managementPolicy);
|
sl@0
|
135 |
|
sl@0
|
136 |
iAlgorithm = (EKeyAlgorithm)(aStream.ReadInt32L());
|
sl@0
|
137 |
iAccessType = (EKeyAccess)(aStream.ReadInt32L());
|
sl@0
|
138 |
iNative = (TBool)(aStream.ReadInt32L());
|
sl@0
|
139 |
TPckg<TTime> startDate(iStartDate);
|
sl@0
|
140 |
aStream.ReadL(startDate);
|
sl@0
|
141 |
TPckg<TTime> endDate(iEndDate);
|
sl@0
|
142 |
aStream.ReadL(endDate);
|
sl@0
|
143 |
|
sl@0
|
144 |
TInt attributeLen = aStream.ReadInt32L();
|
sl@0
|
145 |
if (attributeLen > 0)
|
sl@0
|
146 |
{
|
sl@0
|
147 |
iPKCS8AttributeSet = HBufC8::NewMaxL(attributeLen);
|
sl@0
|
148 |
TPtr8 pAttributes(iPKCS8AttributeSet->Des());
|
sl@0
|
149 |
pAttributes.FillZ();
|
sl@0
|
150 |
// This will have made the length of pAttributes equal to the length of
|
sl@0
|
151 |
// the alloc cell of iPKCS8AttributeSet, which may be longer than attributeLen
|
sl@0
|
152 |
// So we need to pass the length we want to read into ReadL
|
sl@0
|
153 |
aStream.ReadL(pAttributes, attributeLen);
|
sl@0
|
154 |
}
|
sl@0
|
155 |
}
|
sl@0
|
156 |
|
sl@0
|
157 |
////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
158 |
// CCTKeyInfo
|
sl@0
|
159 |
////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
160 |
|
sl@0
|
161 |
EXPORT_C CCTKeyInfo* CCTKeyInfo::NewL(TKeyIdentifier aID,
|
sl@0
|
162 |
TKeyUsagePKCS15 aUsage,
|
sl@0
|
163 |
TUint aSize,
|
sl@0
|
164 |
MCTAuthenticationObject* aProtector,
|
sl@0
|
165 |
HBufC* aLabel,
|
sl@0
|
166 |
MCTToken& aToken,
|
sl@0
|
167 |
TInt aHandle,
|
sl@0
|
168 |
const TSecurityPolicy& aUsePolicy,
|
sl@0
|
169 |
const TSecurityPolicy& aManagementPolicy,
|
sl@0
|
170 |
EKeyAlgorithm aAlgorithm,
|
sl@0
|
171 |
TInt aAccessType,
|
sl@0
|
172 |
TBool aNative,
|
sl@0
|
173 |
TTime aStartDate,
|
sl@0
|
174 |
TTime aEndDate,
|
sl@0
|
175 |
HBufC8* aPKCS8AttributeSet /*= NULL*/)
|
sl@0
|
176 |
{
|
sl@0
|
177 |
CCTKeyInfo* me = NULL;
|
sl@0
|
178 |
me = new (ELeave) CCTKeyInfo(aID,
|
sl@0
|
179 |
aUsage,
|
sl@0
|
180 |
aSize,
|
sl@0
|
181 |
aProtector,
|
sl@0
|
182 |
aLabel,
|
sl@0
|
183 |
aToken,
|
sl@0
|
184 |
aHandle,
|
sl@0
|
185 |
aUsePolicy,
|
sl@0
|
186 |
aManagementPolicy,
|
sl@0
|
187 |
aAlgorithm,
|
sl@0
|
188 |
aAccessType,
|
sl@0
|
189 |
aNative,
|
sl@0
|
190 |
aStartDate,
|
sl@0
|
191 |
aEndDate,
|
sl@0
|
192 |
aPKCS8AttributeSet);
|
sl@0
|
193 |
|
sl@0
|
194 |
CleanupReleasePushL(*me);
|
sl@0
|
195 |
me->ConstructL();
|
sl@0
|
196 |
CleanupStack::Pop();
|
sl@0
|
197 |
|
sl@0
|
198 |
return me;
|
sl@0
|
199 |
}
|
sl@0
|
200 |
|
sl@0
|
201 |
CCTKeyInfo::CCTKeyInfo(TKeyIdentifier aID,
|
sl@0
|
202 |
TKeyUsagePKCS15 aUsage,
|
sl@0
|
203 |
TUint aSize,
|
sl@0
|
204 |
MCTAuthenticationObject* aProtector,
|
sl@0
|
205 |
HBufC* aLabel,
|
sl@0
|
206 |
MCTToken& aToken,
|
sl@0
|
207 |
TInt aHandle,
|
sl@0
|
208 |
const TSecurityPolicy& aUsePolicy,
|
sl@0
|
209 |
const TSecurityPolicy& aManagementPolicy,
|
sl@0
|
210 |
EKeyAlgorithm aAlgorithm,
|
sl@0
|
211 |
TInt aAccessType,
|
sl@0
|
212 |
TBool aNative,
|
sl@0
|
213 |
TTime aStartDate,
|
sl@0
|
214 |
TTime aEndDate,
|
sl@0
|
215 |
HBufC8* aPKCS8AttributeSet /*= NULL*/) :
|
sl@0
|
216 |
CKeyInfoBase(aID,
|
sl@0
|
217 |
aUsage,
|
sl@0
|
218 |
aSize,
|
sl@0
|
219 |
aLabel,
|
sl@0
|
220 |
aHandle,
|
sl@0
|
221 |
aUsePolicy,
|
sl@0
|
222 |
aManagementPolicy,
|
sl@0
|
223 |
aAlgorithm,
|
sl@0
|
224 |
aAccessType,
|
sl@0
|
225 |
aNative,
|
sl@0
|
226 |
aStartDate,
|
sl@0
|
227 |
aEndDate,
|
sl@0
|
228 |
aPKCS8AttributeSet),
|
sl@0
|
229 |
MCTTokenObject(aToken),
|
sl@0
|
230 |
iToken(aToken),
|
sl@0
|
231 |
iProtector(aProtector)
|
sl@0
|
232 |
{
|
sl@0
|
233 |
LOG1(_L("CCTKeyInfo::CCTKeyInfo() with iProtector %08x"), iProtector);
|
sl@0
|
234 |
}
|
sl@0
|
235 |
|
sl@0
|
236 |
EXPORT_C CCTKeyInfo* CCTKeyInfo::NewL(RReadStream& aStream, MCTToken& aToken)
|
sl@0
|
237 |
{
|
sl@0
|
238 |
CCTKeyInfo* me = new (ELeave) CCTKeyInfo(aToken);
|
sl@0
|
239 |
CleanupReleasePushL(*me);
|
sl@0
|
240 |
me->ConstructL(aStream);
|
sl@0
|
241 |
CleanupStack::Pop();
|
sl@0
|
242 |
return me;
|
sl@0
|
243 |
}
|
sl@0
|
244 |
|
sl@0
|
245 |
CCTKeyInfo::CCTKeyInfo(MCTToken& aToken) :
|
sl@0
|
246 |
CKeyInfoBase(),
|
sl@0
|
247 |
MCTTokenObject(aToken),
|
sl@0
|
248 |
iToken(aToken)
|
sl@0
|
249 |
{
|
sl@0
|
250 |
}
|
sl@0
|
251 |
|
sl@0
|
252 |
CCTKeyInfo::~CCTKeyInfo()
|
sl@0
|
253 |
{
|
sl@0
|
254 |
LOG(_L("CCTKeyInfo::~CCTKeyInfo"));
|
sl@0
|
255 |
if (iProtector)
|
sl@0
|
256 |
{
|
sl@0
|
257 |
LOG_INC_INDENT();
|
sl@0
|
258 |
iProtector->Release();
|
sl@0
|
259 |
LOG_DEC_INDENT();
|
sl@0
|
260 |
}
|
sl@0
|
261 |
}
|
sl@0
|
262 |
|
sl@0
|
263 |
const TDesC& CCTKeyInfo::Label() const
|
sl@0
|
264 |
{
|
sl@0
|
265 |
return CKeyInfoBase::Label();
|
sl@0
|
266 |
}
|
sl@0
|
267 |
|
sl@0
|
268 |
MCTToken& CCTKeyInfo::Token() const
|
sl@0
|
269 |
{
|
sl@0
|
270 |
return iToken;
|
sl@0
|
271 |
}
|
sl@0
|
272 |
|
sl@0
|
273 |
TUid CCTKeyInfo::Type() const
|
sl@0
|
274 |
{
|
sl@0
|
275 |
return KKeyInfoUID;
|
sl@0
|
276 |
}
|
sl@0
|
277 |
|
sl@0
|
278 |
TCTTokenObjectHandle CCTKeyInfo::Handle() const
|
sl@0
|
279 |
{
|
sl@0
|
280 |
return TCTTokenObjectHandle(Token().Handle(), HandleID());
|
sl@0
|
281 |
}
|
sl@0
|
282 |
|
sl@0
|
283 |
////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
284 |
// TCTKeyAttributeFilter
|
sl@0
|
285 |
////////////////////////////////////////////////////////////////////////////////
|
sl@0
|
286 |
|
sl@0
|
287 |
EXPORT_C TCTKeyAttributeFilter::TCTKeyAttributeFilter()
|
sl@0
|
288 |
{
|
sl@0
|
289 |
iKeyId = KNullDesC8;
|
sl@0
|
290 |
iUsage = EPKCS15UsageAll;
|
sl@0
|
291 |
iPolicyFilter = EUsableKeys;
|
sl@0
|
292 |
iKeyAlgorithm = CCTKeyInfo::EInvalidAlgorithm;
|
sl@0
|
293 |
}
|