sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2003-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 |
* UNIFIEDKEYSTORE.H
|
sl@0
|
16 |
* The unified key store implementation
|
sl@0
|
17 |
*
|
sl@0
|
18 |
*/
|
sl@0
|
19 |
|
sl@0
|
20 |
|
sl@0
|
21 |
/**
|
sl@0
|
22 |
@file
|
sl@0
|
23 |
@publishedPartner
|
sl@0
|
24 |
@released
|
sl@0
|
25 |
*/
|
sl@0
|
26 |
|
sl@0
|
27 |
#ifndef __UNIFIEDKEYSTORE_H__
|
sl@0
|
28 |
#define __UNIFIEDKEYSTORE_H__
|
sl@0
|
29 |
|
sl@0
|
30 |
#include <f32file.h>
|
sl@0
|
31 |
#include <e32base.h>
|
sl@0
|
32 |
|
sl@0
|
33 |
#include <mctkeystoremanager.h>
|
sl@0
|
34 |
|
sl@0
|
35 |
#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
|
sl@0
|
36 |
namespace CryptoSpi
|
sl@0
|
37 |
{
|
sl@0
|
38 |
class CSigner;
|
sl@0
|
39 |
class CAsymmetricCipher;
|
sl@0
|
40 |
class CCryptoParams;
|
sl@0
|
41 |
}
|
sl@0
|
42 |
#endif
|
sl@0
|
43 |
|
sl@0
|
44 |
/**
|
sl@0
|
45 |
* Unified KeyStore panics
|
sl@0
|
46 |
*
|
sl@0
|
47 |
* @publishedPartner
|
sl@0
|
48 |
* @released
|
sl@0
|
49 |
*/
|
sl@0
|
50 |
enum TUnifiedKeyStorePanic
|
sl@0
|
51 |
{
|
sl@0
|
52 |
EUnexpectedInitialise = 1, ///< Unexpected initialise
|
sl@0
|
53 |
EArrayAccessOutOfBounds = 2, ///< Array access out of bounds
|
sl@0
|
54 |
ETokensArrayAlreadyInUse = 3, ///< Tokens array already in use
|
sl@0
|
55 |
EUnrecognisedState = 4, ///< Unrecognised state
|
sl@0
|
56 |
};
|
sl@0
|
57 |
|
sl@0
|
58 |
/**
|
sl@0
|
59 |
* The unified key store.
|
sl@0
|
60 |
*
|
sl@0
|
61 |
* This class provides a key store whose contents are the sum of the contents of
|
sl@0
|
62 |
* all key store implementations on the device. It is intended a single point
|
sl@0
|
63 |
* of access for clients wishing to access key stores.
|
sl@0
|
64 |
*
|
sl@0
|
65 |
* Since this class is intended for widespread use, capability checks relating
|
sl@0
|
66 |
* to key access are documented here even though the checks are actually made in
|
sl@0
|
67 |
* the individual key store implementations.
|
sl@0
|
68 |
*
|
sl@0
|
69 |
* @publishedPartner
|
sl@0
|
70 |
* @released
|
sl@0
|
71 |
*/
|
sl@0
|
72 |
NONSHARABLE_CLASS(CUnifiedKeyStore) : public CActive, public MKeyStore
|
sl@0
|
73 |
{
|
sl@0
|
74 |
public:
|
sl@0
|
75 |
/**
|
sl@0
|
76 |
* Creates a new CUnifiedKeyStore object.
|
sl@0
|
77 |
*
|
sl@0
|
78 |
* @param aFs A file server session. It must already be open.
|
sl@0
|
79 |
* @return A pointer to an instance of the CUnifiedKeyStore class.
|
sl@0
|
80 |
*/
|
sl@0
|
81 |
IMPORT_C static CUnifiedKeyStore* NewL(RFs& aFs);
|
sl@0
|
82 |
|
sl@0
|
83 |
/**
|
sl@0
|
84 |
* Creates a new CUnifiedKeyStore object and and puts a pointer to the new object
|
sl@0
|
85 |
* onto the cleanup stack.
|
sl@0
|
86 |
*
|
sl@0
|
87 |
* @param aFs A file server session. It must already be open.
|
sl@0
|
88 |
* @return A pointer to an instance of the CUnifiedKeyStore class.
|
sl@0
|
89 |
*/
|
sl@0
|
90 |
IMPORT_C static CUnifiedKeyStore* NewLC(RFs& aFs);
|
sl@0
|
91 |
|
sl@0
|
92 |
/**
|
sl@0
|
93 |
* The destructor destroys all the resources owned by this object.
|
sl@0
|
94 |
*/
|
sl@0
|
95 |
IMPORT_C ~CUnifiedKeyStore();
|
sl@0
|
96 |
|
sl@0
|
97 |
/**
|
sl@0
|
98 |
* Initialises the manager.
|
sl@0
|
99 |
*
|
sl@0
|
100 |
* It must be called after the manager has been constructed and before any call
|
sl@0
|
101 |
* to the manager functions.
|
sl@0
|
102 |
*
|
sl@0
|
103 |
* This is an asynchronous request.
|
sl@0
|
104 |
*
|
sl@0
|
105 |
* @param aStatus The request status object; contains the result of the Initialize()
|
sl@0
|
106 |
* request when complete. Set to KErrCancel if any outstanding request is cancelled.
|
sl@0
|
107 |
*/
|
sl@0
|
108 |
IMPORT_C void Initialize(TRequestStatus& aStatus);
|
sl@0
|
109 |
|
sl@0
|
110 |
/**
|
sl@0
|
111 |
* Cancels an ongoing Initialize() operation.
|
sl@0
|
112 |
*
|
sl@0
|
113 |
* The operation completes with KErrCancel.
|
sl@0
|
114 |
*/
|
sl@0
|
115 |
IMPORT_C void CancelInitialize();
|
sl@0
|
116 |
|
sl@0
|
117 |
public: // Implementation of MKeyStore interface
|
sl@0
|
118 |
virtual void List(RMPointerArray<CCTKeyInfo>& aKeys, const TCTKeyAttributeFilter& aFilter, TRequestStatus& aStatus);
|
sl@0
|
119 |
virtual void CancelList();
|
sl@0
|
120 |
virtual void GetKeyInfo(TCTTokenObjectHandle aHandle, CCTKeyInfo*& aInfo,TRequestStatus& aStatus);
|
sl@0
|
121 |
virtual void CancelGetKeyInfo();
|
sl@0
|
122 |
virtual void Open(const TCTTokenObjectHandle& aHandle,
|
sl@0
|
123 |
MRSASigner*& aSigner,
|
sl@0
|
124 |
TRequestStatus& aStatus);
|
sl@0
|
125 |
virtual void Open(const TCTTokenObjectHandle& aHandle,
|
sl@0
|
126 |
MDSASigner*& aSigner,
|
sl@0
|
127 |
TRequestStatus& aStatus);
|
sl@0
|
128 |
virtual void Open(const TCTTokenObjectHandle& aHandle,
|
sl@0
|
129 |
MCTDecryptor*& aDecryptor,
|
sl@0
|
130 |
TRequestStatus& aStatus);
|
sl@0
|
131 |
virtual void Open(const TCTTokenObjectHandle& aHandle,
|
sl@0
|
132 |
MCTDH*& aDH, TRequestStatus& aStatus);
|
sl@0
|
133 |
virtual void CancelOpen();
|
sl@0
|
134 |
virtual void ExportPublic(const TCTTokenObjectHandle& aHandle,
|
sl@0
|
135 |
HBufC8*& aPublicKey,
|
sl@0
|
136 |
TRequestStatus& aStatus);
|
sl@0
|
137 |
virtual void CancelExportPublic();
|
sl@0
|
138 |
|
sl@0
|
139 |
#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
|
sl@0
|
140 |
virtual void Open(const TCTTokenObjectHandle& aHandle,
|
sl@0
|
141 |
CryptoSpi::CSigner*& aSigner,
|
sl@0
|
142 |
TRequestStatus& aStatus);
|
sl@0
|
143 |
virtual void Open(const TCTTokenObjectHandle& aHandle,
|
sl@0
|
144 |
CryptoSpi::CAsymmetricCipher*& asymmetricCipherObj,
|
sl@0
|
145 |
TRequestStatus& aStatus);
|
sl@0
|
146 |
virtual void Decrypt(const TCTTokenObjectHandle& aHandle,
|
sl@0
|
147 |
const TDesC8& aCiphertext,
|
sl@0
|
148 |
HBufC8*& aPlaintextPtr,
|
sl@0
|
149 |
TRequestStatus& aStatus);
|
sl@0
|
150 |
virtual void Sign(const TCTTokenObjectHandle& aHandle,
|
sl@0
|
151 |
const TDesC8& aPlaintext,
|
sl@0
|
152 |
CryptoSpi::CCryptoParams*& aSignature,
|
sl@0
|
153 |
TRequestStatus& aStatus);
|
sl@0
|
154 |
#endif
|
sl@0
|
155 |
|
sl@0
|
156 |
public: // For MCTKeyStoreManager except those (CreateKey, ImportKey, ImportEncryptedKey)
|
sl@0
|
157 |
// that require a caller-specified store
|
sl@0
|
158 |
|
sl@0
|
159 |
/**
|
sl@0
|
160 |
* Exports a key pair in the clear.
|
sl@0
|
161 |
*
|
sl@0
|
162 |
* The key is exported as DER-encoded PKCS#8 data.
|
sl@0
|
163 |
*
|
sl@0
|
164 |
* @param aHandle The handle of the key to export
|
sl@0
|
165 |
* @param aKey A reference to a HBufC8 pointer. The pointer will be set to
|
sl@0
|
166 |
* a newly allocated buffer containing the key data. It is the caller's
|
sl@0
|
167 |
* responsibility to delete this buffer.
|
sl@0
|
168 |
* @param aStatus The request status object; contains the result of the ExportKey() request
|
sl@0
|
169 |
* when complete. Set to KErrCancel if any outstanding request is cancelled.
|
sl@0
|
170 |
*
|
sl@0
|
171 |
* @capability ReadUserData Requires the caller to have ReadUserData capability
|
sl@0
|
172 |
* @leave KErrPermissionDenied If the caller does not have ReadUserData capability,
|
sl@0
|
173 |
* or is not the owner of the key.
|
sl@0
|
174 |
* @leave KErrNotFound If the key the handle referes to does not exist.
|
sl@0
|
175 |
* @leave KErrKeyAccess If the sensitive flag is set for the key, or the
|
sl@0
|
176 |
* exportable flag is not set.
|
sl@0
|
177 |
* @leave KErrKeyAlgorithm If this type of key cannot be exported.
|
sl@0
|
178 |
*/
|
sl@0
|
179 |
IMPORT_C void ExportKey(TCTTokenObjectHandle aHandle, HBufC8*& aKey, TRequestStatus& aStatus);
|
sl@0
|
180 |
|
sl@0
|
181 |
/**
|
sl@0
|
182 |
* Cancels an ongoing ExportKey() operation.
|
sl@0
|
183 |
*
|
sl@0
|
184 |
* The operation completes with KErrCancel.
|
sl@0
|
185 |
*/
|
sl@0
|
186 |
IMPORT_C void CancelExportKey();
|
sl@0
|
187 |
|
sl@0
|
188 |
/**
|
sl@0
|
189 |
* Exports an encrypted key pair.
|
sl@0
|
190 |
*
|
sl@0
|
191 |
* The key is exported as DER-encoded PKCS#5/PKCS#8 data.
|
sl@0
|
192 |
*
|
sl@0
|
193 |
* @param aHandle The handle of the key to export
|
sl@0
|
194 |
* @param aKey A reference to a HBufC8 pointer. The pointer will be set to
|
sl@0
|
195 |
* a newly allocated buffer containing the key data.
|
sl@0
|
196 |
* @param aParams The PBE encryption parameters to use when encrypting the key.
|
sl@0
|
197 |
* @param aStatus The request status object; contains the result of the ExportEncryptedKey() request
|
sl@0
|
198 |
* when complete. Set to KErrCancel if any outstanding request is cancelled.
|
sl@0
|
199 |
*
|
sl@0
|
200 |
* @capability ReadUserData Requires the caller to have ReadUserData capability
|
sl@0
|
201 |
* @leave KErrPermissionDenied If the caller does not have ReadUserData capability,
|
sl@0
|
202 |
* or is not the owner of the key.
|
sl@0
|
203 |
* @leave KErrNotFound If the key the handle referes to does not exist.
|
sl@0
|
204 |
* @leave KErrKeyAccess If the exportable flag is not set for the key.
|
sl@0
|
205 |
* @leave KErrKeyAlgorithm If this type of key cannot be exported.
|
sl@0
|
206 |
*/
|
sl@0
|
207 |
IMPORT_C void ExportEncryptedKey(TCTTokenObjectHandle aHandle, const CPBEncryptParms& aEncryptParams,
|
sl@0
|
208 |
HBufC8*& aKey, TRequestStatus& aStatus);
|
sl@0
|
209 |
|
sl@0
|
210 |
/**
|
sl@0
|
211 |
* Cancels an ongoing ExportEncryptedKey() operation.
|
sl@0
|
212 |
*
|
sl@0
|
213 |
* The operation completes with KErrCancel.
|
sl@0
|
214 |
*/
|
sl@0
|
215 |
IMPORT_C void CancelExportEncryptedKey();
|
sl@0
|
216 |
|
sl@0
|
217 |
/**
|
sl@0
|
218 |
* Deletes a key.
|
sl@0
|
219 |
*
|
sl@0
|
220 |
* @param aHandle The handle of the key to delete
|
sl@0
|
221 |
* @param aStatus The request status object; contains the result of the DeleteKey() request
|
sl@0
|
222 |
* when complete. Set to KErrCancel if any outstanding request is cancelled.
|
sl@0
|
223 |
*
|
sl@0
|
224 |
* @capability WriteUserData Requires the caller to have WriteUserData capability
|
sl@0
|
225 |
* @leave KErrPermissionDenied If the caller does not have WriteUserData capability,
|
sl@0
|
226 |
* or is not the owner of the key.
|
sl@0
|
227 |
* @leave KErrNotFound If the key the handle referes to does not exist.
|
sl@0
|
228 |
* @leave KErrAccessDenied If the calling process is not allowed to delete the key.
|
sl@0
|
229 |
* @leave KErrInUse If another client is currently using the key.
|
sl@0
|
230 |
*/
|
sl@0
|
231 |
IMPORT_C void DeleteKey(TCTTokenObjectHandle aHandle, TRequestStatus& aStatus);
|
sl@0
|
232 |
|
sl@0
|
233 |
/**
|
sl@0
|
234 |
* Cancels an ongoing DeleteKey() operation.
|
sl@0
|
235 |
*
|
sl@0
|
236 |
* The operation completes with KErrCancel.
|
sl@0
|
237 |
*/
|
sl@0
|
238 |
IMPORT_C void CancelDeleteKey();
|
sl@0
|
239 |
|
sl@0
|
240 |
/**
|
sl@0
|
241 |
* Sets the security policy for key use.
|
sl@0
|
242 |
*
|
sl@0
|
243 |
* Specifies which processes are allowed to use the key for cryptographic
|
sl@0
|
244 |
* operations.
|
sl@0
|
245 |
*
|
sl@0
|
246 |
* @param aHandle The handle of the key
|
sl@0
|
247 |
* @param aPolicy The new security policy.
|
sl@0
|
248 |
* @param aStatus The request status object; contains the result of the SetUsePolicy() request
|
sl@0
|
249 |
* when complete. Set to KErrCancel if any outstanding request is cancelled.
|
sl@0
|
250 |
*
|
sl@0
|
251 |
* @capability WriteUserData Requires the caller to have WriteUserData capability
|
sl@0
|
252 |
* @leave KErrPermissionDenied If the caller does not have WriteUserData capability,
|
sl@0
|
253 |
* or is not the owner of the key.
|
sl@0
|
254 |
* @leave KErrNotFound If the key the handle referes to does not exist.
|
sl@0
|
255 |
*/
|
sl@0
|
256 |
IMPORT_C void SetUsePolicy(TCTTokenObjectHandle aHandle,
|
sl@0
|
257 |
const TSecurityPolicy& aPolicy,
|
sl@0
|
258 |
TRequestStatus& aStatus);
|
sl@0
|
259 |
|
sl@0
|
260 |
/**
|
sl@0
|
261 |
* Cancels an ongoing SetUsePolicy() operation.
|
sl@0
|
262 |
*
|
sl@0
|
263 |
* The operation completes with KErrCancel.
|
sl@0
|
264 |
*/
|
sl@0
|
265 |
IMPORT_C void CancelSetUsePolicy();
|
sl@0
|
266 |
|
sl@0
|
267 |
/**
|
sl@0
|
268 |
* Sets the security policy for key management.
|
sl@0
|
269 |
*
|
sl@0
|
270 |
* Specifies which processes are allowed to perform management operations on
|
sl@0
|
271 |
* the key.
|
sl@0
|
272 |
*
|
sl@0
|
273 |
* @param aHandle The handle of the key
|
sl@0
|
274 |
* @param aPolicy The new security policy.
|
sl@0
|
275 |
* @param aStatus The request status object; contains the result of the SetManagementPolicy() request
|
sl@0
|
276 |
* when complete. Set to KErrCancel if any outstanding request is cancelled.
|
sl@0
|
277 |
*
|
sl@0
|
278 |
* @capability WriteUserData Requires the caller to have WriteUserData capability
|
sl@0
|
279 |
* @leave KErrPermissionDenied If the caller does not have WriteUserData capability,
|
sl@0
|
280 |
* or is not the owner of the key.
|
sl@0
|
281 |
* @leave KErrNotFound If the key the handle referes to does not exist.
|
sl@0
|
282 |
*/
|
sl@0
|
283 |
IMPORT_C void SetManagementPolicy(TCTTokenObjectHandle aHandle,
|
sl@0
|
284 |
const TSecurityPolicy& aPolicy,
|
sl@0
|
285 |
TRequestStatus& aStatus);
|
sl@0
|
286 |
|
sl@0
|
287 |
/**
|
sl@0
|
288 |
* Cancels an ongoing SetManagementPolicy() operation.
|
sl@0
|
289 |
*
|
sl@0
|
290 |
* The operation completes with KErrCancel.
|
sl@0
|
291 |
*/
|
sl@0
|
292 |
IMPORT_C void CancelSetManagementPolicy();
|
sl@0
|
293 |
|
sl@0
|
294 |
/**
|
sl@0
|
295 |
* Sets the passphrase timeout for all keys owned by this process.
|
sl@0
|
296 |
*
|
sl@0
|
297 |
* @param aTimeout The timeout in seconds. 0 means that the passphrase is
|
sl@0
|
298 |
* always asked for, and -1 means that it is never expired
|
sl@0
|
299 |
* @param aStatus The request status object; contains the result of the SetPassphraseTimeout() request
|
sl@0
|
300 |
* when complete. Set to KErrCancel if any outstanding request is cancelled.
|
sl@0
|
301 |
*
|
sl@0
|
302 |
* @capability WriteUserData Requires the caller to have WriteUserData capability
|
sl@0
|
303 |
* @leave KErrPermissionDenied If the caller does not have WriteUserData capability,
|
sl@0
|
304 |
* or is not the owner of the key
|
sl@0
|
305 |
* @leave KErrArgument If the timeout specified is invalid.
|
sl@0
|
306 |
*/
|
sl@0
|
307 |
IMPORT_C void SetPassphraseTimeout(TInt aTimeout, TRequestStatus& aStatus);
|
sl@0
|
308 |
|
sl@0
|
309 |
/**
|
sl@0
|
310 |
* Cancels an ongoing SetPassphraseTimeout() operation.
|
sl@0
|
311 |
*
|
sl@0
|
312 |
* The operation completes with KErrCancel.
|
sl@0
|
313 |
*/
|
sl@0
|
314 |
IMPORT_C void CancelSetPassphraseTimeout();
|
sl@0
|
315 |
|
sl@0
|
316 |
/**
|
sl@0
|
317 |
* Re-locks the entire store (i.e., forget the passphrase).
|
sl@0
|
318 |
*
|
sl@0
|
319 |
* @param aStatus The request status object; contains the result of the Relock() request
|
sl@0
|
320 |
* when complete. Set to KErrCancel if any outstanding request is cancelled.
|
sl@0
|
321 |
*/
|
sl@0
|
322 |
IMPORT_C void Relock(TRequestStatus& aStatus);
|
sl@0
|
323 |
|
sl@0
|
324 |
/**
|
sl@0
|
325 |
* Cancels an ongoing Relock() operation.
|
sl@0
|
326 |
*
|
sl@0
|
327 |
* The operation completes with KErrCancel.
|
sl@0
|
328 |
*/
|
sl@0
|
329 |
IMPORT_C void CancelRelock();
|
sl@0
|
330 |
|
sl@0
|
331 |
public:
|
sl@0
|
332 |
/**
|
sl@0
|
333 |
* Generates a new key pair.
|
sl@0
|
334 |
*
|
sl@0
|
335 |
* For the software key store, the owner of the new key is set to the
|
sl@0
|
336 |
* calling process. Users can subsequently be added by calling SetUsers().
|
sl@0
|
337 |
*
|
sl@0
|
338 |
* @param aKeyStoreIndex The index of the key store manager in which to
|
sl@0
|
339 |
* create the key. Must be between zero and
|
sl@0
|
340 |
* KeyStoreMangerCount() exclusive.
|
sl@0
|
341 |
* @param aUsage The key usage flags in the PKCS#15 format.
|
sl@0
|
342 |
* @param aSize The size of the key in bits.
|
sl@0
|
343 |
* @param aLabel A textual label for the key.
|
sl@0
|
344 |
* @param aAlgorithm The type of key.
|
sl@0
|
345 |
* @param aAccessType The key access type - a bitfield specifying key
|
sl@0
|
346 |
* access requirements. Allowed values are zero, or
|
sl@0
|
347 |
* a comination of CCTKeyInfo::EKeyAccess::ESenstive
|
sl@0
|
348 |
* and CCTKeyInfo::EKeyAccess::EExtractable
|
sl@0
|
349 |
* @param aStartDate The start of the validity period.
|
sl@0
|
350 |
* @param aEndDate The end of the validity period.
|
sl@0
|
351 |
* @param aKeyInfoOut A pointer that is set to a newly created key info
|
sl@0
|
352 |
* object on successful completion.
|
sl@0
|
353 |
* @param aStatus The request status object; contains the result of
|
sl@0
|
354 |
* the CreateKey() request when complete. Set to
|
sl@0
|
355 |
* KErrCancel if any outstanding request is cancelled.
|
sl@0
|
356 |
*
|
sl@0
|
357 |
* @capability WriteUserData Requires the caller to have WriteUserData capability
|
sl@0
|
358 |
* @leave KErrPermissionDenied If the caller does not have WriteUserData capability
|
sl@0
|
359 |
* @leave KErrKeyUsage If the key usage flags are not valid or not
|
sl@0
|
360 |
* consistent with the key algorithm.
|
sl@0
|
361 |
* @leave KErrKeyValidity If the validity start and end dates are specified
|
sl@0
|
362 |
* but do not form a valid time period.
|
sl@0
|
363 |
* @panic If aKeyStoreIndex does not specify a valid keystore manager.
|
sl@0
|
364 |
*/
|
sl@0
|
365 |
IMPORT_C void CreateKey(TInt aKeyStoreIndex, TKeyUsagePKCS15 aUsage,TUint aSize,
|
sl@0
|
366 |
const TDesC& aLabel, CCTKeyInfo::EKeyAlgorithm aAlgorithm,
|
sl@0
|
367 |
TInt aAccessType, TTime aStartDate, TTime aEndDate,
|
sl@0
|
368 |
CCTKeyInfo*& aKeyInfoOut, TRequestStatus& aStatus);
|
sl@0
|
369 |
|
sl@0
|
370 |
/**
|
sl@0
|
371 |
* Cancels an ongoing CreateKey() operation.
|
sl@0
|
372 |
*
|
sl@0
|
373 |
* The operation completes with KErrCancel.
|
sl@0
|
374 |
*/
|
sl@0
|
375 |
IMPORT_C void CancelCreateKey();
|
sl@0
|
376 |
|
sl@0
|
377 |
/**
|
sl@0
|
378 |
* Imports a key pair.
|
sl@0
|
379 |
*
|
sl@0
|
380 |
* For the software key store, the owner of the new key is set to the
|
sl@0
|
381 |
* calling process. Users can subsequently be added by calling SetUsers().
|
sl@0
|
382 |
*
|
sl@0
|
383 |
* The key data should be in PKCS#8 format. Both encrypted and cleartext
|
sl@0
|
384 |
* versions are allowed.
|
sl@0
|
385 |
*
|
sl@0
|
386 |
* @param aKeyStoreIndex The index of the key store manager in which to
|
sl@0
|
387 |
* create the key. Must be between zero and
|
sl@0
|
388 |
* KeyStoreMangerCount() exclusive.
|
sl@0
|
389 |
* @param aKeyData The key data to import, ASN.1 DER encoded PKCS#8.
|
sl@0
|
390 |
* @param aUsage The key usage flags in the PKCS#15 format.
|
sl@0
|
391 |
* @param aLabel A textual label for the key.
|
sl@0
|
392 |
* @param aAccessType The key access type - a bitfield specifying key
|
sl@0
|
393 |
* access requirements. Allowed values are zero, or
|
sl@0
|
394 |
* a comination of CCTKeyInfo::EKeyAccess::ESenstive
|
sl@0
|
395 |
* and CCTKeyInfo::EKeyAccess::EExtractable
|
sl@0
|
396 |
* @param aStartDate The start of the validity period.
|
sl@0
|
397 |
* @param aEndDate The end of the validity period.
|
sl@0
|
398 |
* @param aKeyInfoOut A pointer that is set to a newly created key info
|
sl@0
|
399 |
* object on successful completion.
|
sl@0
|
400 |
* @param aStatus The request status object; contains the result of
|
sl@0
|
401 |
* the ImportKey() request when complete. Set to
|
sl@0
|
402 |
* KErrCancel if any outstanding request is cancelled.
|
sl@0
|
403 |
*
|
sl@0
|
404 |
* @capability WriteUserData Requires the caller to have WriteUserData capability
|
sl@0
|
405 |
* @leave KErrPermissionDenied If the caller does not have WriteUserData capability
|
sl@0
|
406 |
* @leave KErrKeyUsage If the key usage flags are not valid or not
|
sl@0
|
407 |
* consistent with the key algorithm.
|
sl@0
|
408 |
* @leave KErrKeyValidity If the validity start and end dates are specified
|
sl@0
|
409 |
* but do not form a valid time period.
|
sl@0
|
410 |
* @leave KErrArgument If the key data cannot be parsed.
|
sl@0
|
411 |
* @panic If aKeyStoreIndex does not specify a valid keystore manager.
|
sl@0
|
412 |
*/
|
sl@0
|
413 |
IMPORT_C void ImportKey(TInt aKeyStoreIndex, const TDesC8& aKeyData,
|
sl@0
|
414 |
TKeyUsagePKCS15 aUsage, const TDesC& aLabel,
|
sl@0
|
415 |
TInt aAccessType, TTime aStartDate, TTime aEndDate,
|
sl@0
|
416 |
CCTKeyInfo*& aKeyInfoOut, TRequestStatus& aStatus);
|
sl@0
|
417 |
|
sl@0
|
418 |
/**
|
sl@0
|
419 |
* Cancels an ongoing ImportKey() operation.
|
sl@0
|
420 |
*
|
sl@0
|
421 |
* The operation completes with KErrCancel.
|
sl@0
|
422 |
*/
|
sl@0
|
423 |
IMPORT_C void CancelImportKey();
|
sl@0
|
424 |
|
sl@0
|
425 |
public:
|
sl@0
|
426 |
|
sl@0
|
427 |
/**
|
sl@0
|
428 |
* Gets the number of available read-only key stores.
|
sl@0
|
429 |
*
|
sl@0
|
430 |
* @return The number of available read-only key stores.
|
sl@0
|
431 |
*/
|
sl@0
|
432 |
IMPORT_C TInt KeyStoreCount() const;
|
sl@0
|
433 |
|
sl@0
|
434 |
/**
|
sl@0
|
435 |
* Gets a read-only interface to a key store.
|
sl@0
|
436 |
*
|
sl@0
|
437 |
* @param aIndex An ordinal number that identifies the key store.
|
sl@0
|
438 |
* @return A read-only interface to the key store specified by aIndex.
|
sl@0
|
439 |
*
|
sl@0
|
440 |
* @panic CUnifiedKeyStore 2 If aIndex is out of range, ie it is greater
|
sl@0
|
441 |
* than or equal to the value returned by KeyStoreCount().
|
sl@0
|
442 |
*/
|
sl@0
|
443 |
IMPORT_C MCTKeyStore& KeyStore(TInt aIndex);
|
sl@0
|
444 |
|
sl@0
|
445 |
/**
|
sl@0
|
446 |
* Gets the number of available read-write key stores.
|
sl@0
|
447 |
*
|
sl@0
|
448 |
* @return The number of key stores that are open for read-write access.
|
sl@0
|
449 |
*/
|
sl@0
|
450 |
IMPORT_C TInt KeyStoreManagerCount() const;
|
sl@0
|
451 |
|
sl@0
|
452 |
/**
|
sl@0
|
453 |
* Gets a read-write interface to the store specified by aIndex.
|
sl@0
|
454 |
*
|
sl@0
|
455 |
* @param aIndex An ordinal number that identifies the key store.
|
sl@0
|
456 |
* @return A read-write interface to the key store specified by aIndex.
|
sl@0
|
457 |
*
|
sl@0
|
458 |
* @panic CUnifiedKeyStore 2 If aIndex s out of range, ie it is greater than
|
sl@0
|
459 |
* or equal to the value returned by KeyStoreManagerCount().
|
sl@0
|
460 |
*/
|
sl@0
|
461 |
IMPORT_C MCTKeyStoreManager& KeyStoreManager(TInt aIndex);
|
sl@0
|
462 |
|
sl@0
|
463 |
#ifdef SYMBIAN_AUTH_SERVER
|
sl@0
|
464 |
public:
|
sl@0
|
465 |
/**
|
sl@0
|
466 |
* Generates a new key pair. The creation of key is for currently authenticated
|
sl@0
|
467 |
* user. If currently there is no authenticated user then authentication of an user
|
sl@0
|
468 |
* would be required.
|
sl@0
|
469 |
*
|
sl@0
|
470 |
* For the software key store, the owner of the new key is set to the
|
sl@0
|
471 |
* calling process. Users can subsequently be added by calling SetUsers().
|
sl@0
|
472 |
*
|
sl@0
|
473 |
* @param aKeyStoreIndex The index of the key store manager in which to
|
sl@0
|
474 |
* create the key. Must be between zero and
|
sl@0
|
475 |
* KeyStoreMangerCount() exclusive.
|
sl@0
|
476 |
* @param aUsage The key usage flags in the PKCS#15 format.
|
sl@0
|
477 |
* @param aSize The size of the key in bits.
|
sl@0
|
478 |
* @param aLabel A textual label for the key.
|
sl@0
|
479 |
* @param aAlgorithm The type of key.
|
sl@0
|
480 |
* @param aAccessType The key access type - a bitfield specifying key
|
sl@0
|
481 |
* access requirements. Allowed values are zero, or
|
sl@0
|
482 |
* a comination of CCTKeyInfo::EKeyAccess::ESenstive
|
sl@0
|
483 |
* and CCTKeyInfo::EKeyAccess::EExtractable
|
sl@0
|
484 |
* @param aStartDate The start of the validity period.
|
sl@0
|
485 |
* @param aEndDate The end of the validity period.
|
sl@0
|
486 |
* @param aAuthenticationString The expression through which a user can be authenticated.
|
sl@0
|
487 |
* Currently this should correspond to one of the alias values
|
sl@0
|
488 |
* set by the licensee for authentication server configuration.
|
sl@0
|
489 |
* @param aFreshness The validity to be considered for an already authenticated
|
sl@0
|
490 |
* identity. Specification is in seconds.
|
sl@0
|
491 |
* @param aKeyInfoOut A pointer that is set to a newly created key info
|
sl@0
|
492 |
* object on successful completion.
|
sl@0
|
493 |
* @param aStatus Final status of the operation.
|
sl@0
|
494 |
*
|
sl@0
|
495 |
* @capability WriteUserData Requires the caller to have WriteUserData capability
|
sl@0
|
496 |
* @leave KErrPermissionDenied If the caller does not have WriteUserData capability
|
sl@0
|
497 |
* @leave KErrKeyUsage If the key usage flags are not valid or not
|
sl@0
|
498 |
* consistent with the key algorithm.
|
sl@0
|
499 |
* @leave KErrKeyValidity If the validity start and end dates are specified
|
sl@0
|
500 |
* but do not form a valid time period.
|
sl@0
|
501 |
* @leave KErrAuthenticationFailure If the user authentication fails.
|
sl@0
|
502 |
* @leave ... Any of the system wide error code.
|
sl@0
|
503 |
* @panic If aKeyStoreIndex does not specify a valid keystore manager.
|
sl@0
|
504 |
*/
|
sl@0
|
505 |
|
sl@0
|
506 |
IMPORT_C void CreateKey(TInt aKeyStoreIndex, TKeyUsagePKCS15 aUsage,TUint aSize,
|
sl@0
|
507 |
const TDesC& aLabel, CCTKeyInfo::EKeyAlgorithm aAlgorithm,
|
sl@0
|
508 |
TInt aAccessType, TTime aStartDate, TTime aEndDate,
|
sl@0
|
509 |
const TDesC& aAuthenticationString, TInt aFreshness,
|
sl@0
|
510 |
CCTKeyInfo*& aKeyInfoOut, TRequestStatus& aStatus) ;
|
sl@0
|
511 |
|
sl@0
|
512 |
/**
|
sl@0
|
513 |
* Imports a key pair. The import of key is for currently authenticated
|
sl@0
|
514 |
* user. If currently there is no authenticated user then authentication
|
sl@0
|
515 |
* of an user would be required.
|
sl@0
|
516 |
*
|
sl@0
|
517 |
* For the software key store, the owner of the new key is set to the
|
sl@0
|
518 |
* calling process. Users can subsequently be added by calling SetUsers().
|
sl@0
|
519 |
*
|
sl@0
|
520 |
* The key data should be in PKCS#8 format. Both encrypted and cleartext
|
sl@0
|
521 |
* versions are allowed.
|
sl@0
|
522 |
*
|
sl@0
|
523 |
* @param aKeyStoreIndex The index of the key store manager in which to
|
sl@0
|
524 |
* create the key. Must be between zero and
|
sl@0
|
525 |
* KeyStoreMangerCount() exclusive.
|
sl@0
|
526 |
* @param aKeyData The key data to import, ASN.1 DER encoded PKCS#8.
|
sl@0
|
527 |
* @param aUsage The key usage flags in the PKCS#15 format.
|
sl@0
|
528 |
* @param aLabel A textual label for the key.
|
sl@0
|
529 |
* @param aAccessType The key access type - a bitfield specifying key
|
sl@0
|
530 |
* access requirements. Allowed values are zero, or
|
sl@0
|
531 |
* a comination of CCTKeyInfo::EKeyAccess::ESenstive
|
sl@0
|
532 |
* and CCTKeyInfo::EKeyAccess::EExtractable
|
sl@0
|
533 |
* @param aStartDate The start of the validity period.
|
sl@0
|
534 |
* @param aEndDate The end of the validity period.
|
sl@0
|
535 |
* @param aAuthenticationString The expression through which a user can be authenticated.
|
sl@0
|
536 |
* Currently this should correspond to one of the alias values
|
sl@0
|
537 |
* set by the licensee for authentication server configuration.
|
sl@0
|
538 |
* @param aFreshness The validity to be considered for an already authenticated
|
sl@0
|
539 |
* identity. Specification is in seconds.
|
sl@0
|
540 |
* @param aKeyInfoOut A pointer that is set to a newly created key info
|
sl@0
|
541 |
* object on successful completion.
|
sl@0
|
542 |
* @param aStatus Final status of the operation.
|
sl@0
|
543 |
*
|
sl@0
|
544 |
* @capability WriteUserData Requires the caller to have WriteUserData capability
|
sl@0
|
545 |
* @leave KErrPermissionDenied If the caller does not have WriteUserData capability
|
sl@0
|
546 |
* @leave KErrKeyUsage If the key usage flags are not valid or not
|
sl@0
|
547 |
* consistent with the key algorithm.
|
sl@0
|
548 |
* @leave KErrKeyValidity If the validity start and end dates are specified
|
sl@0
|
549 |
* but do not form a valid time period.
|
sl@0
|
550 |
* @leave KErrArgument If the key data cannot be parsed.
|
sl@0
|
551 |
* @panic If aKeyStoreIndex does not specify a valid keystore manager.
|
sl@0
|
552 |
*/
|
sl@0
|
553 |
|
sl@0
|
554 |
IMPORT_C void ImportKey( TInt aKeyStoreIndex, const TDesC8& aKeyData,
|
sl@0
|
555 |
TKeyUsagePKCS15 aUsage, const TDesC& aLabel,
|
sl@0
|
556 |
TInt aAccessType, TTime aStartDate, TTime aEndDate,
|
sl@0
|
557 |
const TDesC& aAuthenticationString, TInt aFreshness,
|
sl@0
|
558 |
CCTKeyInfo*& aKeyInfoOut, TRequestStatus& aStatus);
|
sl@0
|
559 |
|
sl@0
|
560 |
/**
|
sl@0
|
561 |
* Set the authentication policy for an already existing key in the store.
|
sl@0
|
562 |
*
|
sl@0
|
563 |
* @param aHandle The handle of the key whose policy is to be changed.
|
sl@0
|
564 |
* @param aAuthenticationString The expression associated to this key.
|
sl@0
|
565 |
* @param aFreshness The validity associated to this key.
|
sl@0
|
566 |
* Specification is in seconds.
|
sl@0
|
567 |
* @param aStatus Final status of the operation.
|
sl@0
|
568 |
*/
|
sl@0
|
569 |
|
sl@0
|
570 |
IMPORT_C void SetAuthenticationPolicy( const TCTTokenObjectHandle aHandle,
|
sl@0
|
571 |
const TDesC& aAuthenticationString,
|
sl@0
|
572 |
TInt aFreshness,
|
sl@0
|
573 |
TRequestStatus& aStatus);
|
sl@0
|
574 |
|
sl@0
|
575 |
/**
|
sl@0
|
576 |
* Retrieve authentication policy for an already existing key in the store.
|
sl@0
|
577 |
*
|
sl@0
|
578 |
* @param aHandle The handle of the key whose policy is to be retrieved.
|
sl@0
|
579 |
* @param aAuthenticationString The expression associated to this key. The memory would
|
sl@0
|
580 |
* be allocated at the server side.
|
sl@0
|
581 |
* @param aFreshness The validity associated to this key.
|
sl@0
|
582 |
* Specification is in seconds.
|
sl@0
|
583 |
* @param aStatus Final status of the operation.
|
sl@0
|
584 |
*/
|
sl@0
|
585 |
|
sl@0
|
586 |
IMPORT_C void GetAuthenticationPolicy( const TCTTokenObjectHandle aHandle,
|
sl@0
|
587 |
HBufC*& aAuthenticationString,
|
sl@0
|
588 |
TInt& aFreshness,
|
sl@0
|
589 |
TRequestStatus& aStatus);
|
sl@0
|
590 |
#endif // SYMBIAN_AUTH_SERVER
|
sl@0
|
591 |
|
sl@0
|
592 |
private:
|
sl@0
|
593 |
CUnifiedKeyStore(RFs& aFs);
|
sl@0
|
594 |
void ConstructL();
|
sl@0
|
595 |
private: // From CActive
|
sl@0
|
596 |
void RunL();
|
sl@0
|
597 |
TInt RunError(TInt aError);
|
sl@0
|
598 |
void DoCancel();
|
sl@0
|
599 |
private:
|
sl@0
|
600 |
enum TState
|
sl@0
|
601 |
{
|
sl@0
|
602 |
EIdle,
|
sl@0
|
603 |
EInitializeGetTokenList,
|
sl@0
|
604 |
EInitializeGetToken,
|
sl@0
|
605 |
EInitialiseGetKeyManagerInterface,
|
sl@0
|
606 |
EInitializeGetKeyUserInterface,
|
sl@0
|
607 |
EInitializeGetKeyUserInterfaceFinished,
|
sl@0
|
608 |
EInitializeFinished,
|
sl@0
|
609 |
// ----------------------------------------------
|
sl@0
|
610 |
EList,
|
sl@0
|
611 |
EGetKeyInfo,
|
sl@0
|
612 |
EOpen,
|
sl@0
|
613 |
// ----------------------------------------------
|
sl@0
|
614 |
ECreateKey,
|
sl@0
|
615 |
EImportKey,
|
sl@0
|
616 |
EImportKeyEncrypted,
|
sl@0
|
617 |
EExportKey,
|
sl@0
|
618 |
EExportEncryptedKey,
|
sl@0
|
619 |
EExportPublic,
|
sl@0
|
620 |
EDeleteKey,
|
sl@0
|
621 |
ESetUsePolicy,
|
sl@0
|
622 |
ESetManagementPolicy,
|
sl@0
|
623 |
ESetPassphraseTimeout,
|
sl@0
|
624 |
ERelock,
|
sl@0
|
625 |
ESetAuthenticationPolicy,
|
sl@0
|
626 |
EGetAuthenticationPolicy
|
sl@0
|
627 |
};
|
sl@0
|
628 |
private:
|
sl@0
|
629 |
void StartAsyncOperation(TState aState, TRequestStatus& aStatus);
|
sl@0
|
630 |
void DoInitializeL();
|
sl@0
|
631 |
TBool DoOpen(const TCTTokenObjectHandle& aHandle,
|
sl@0
|
632 |
TRequestStatus& aStatus);
|
sl@0
|
633 |
void PrepareToCreateKeyL(TInt aKeyStoreIndex,
|
sl@0
|
634 |
TKeyUsagePKCS15 aUsage, TUint aSize,
|
sl@0
|
635 |
const TDesC& aLabel,
|
sl@0
|
636 |
CCTKeyInfo::EKeyAlgorithm aAlgorithm,
|
sl@0
|
637 |
TInt aAccessType,
|
sl@0
|
638 |
TTime aStartDate, TTime aEndDate,
|
sl@0
|
639 |
TRequestStatus& aStatus);
|
sl@0
|
640 |
/**
|
sl@0
|
641 |
* A synchronous method to find the key store given a token object handle.
|
sl@0
|
642 |
* Returns NULL if none found.
|
sl@0
|
643 |
*/
|
sl@0
|
644 |
MCTKeyStore* FindKeyStore(const TCTTokenObjectHandle& aHandle);
|
sl@0
|
645 |
/**
|
sl@0
|
646 |
* A synchronous method to find the key store manager given a token object
|
sl@0
|
647 |
* handle. Returns NULL if none found.
|
sl@0
|
648 |
*/
|
sl@0
|
649 |
MCTKeyStoreManager* FindKeyStoreManager(const TCTTokenObjectHandle& aHandle);
|
sl@0
|
650 |
/** Complete the user's request and clean up state. */
|
sl@0
|
651 |
void Complete(TInt aError);
|
sl@0
|
652 |
/** Clean up state. */
|
sl@0
|
653 |
void Cleanup();
|
sl@0
|
654 |
/** Cancel the outstanding request. */
|
sl@0
|
655 |
void CancelOutstandingRequest();
|
sl@0
|
656 |
private:
|
sl@0
|
657 |
/**
|
sl@0
|
658 |
* A wrapper around a keystore interface that remebers whether it is a
|
sl@0
|
659 |
* readonly or manager interface.
|
sl@0
|
660 |
*/
|
sl@0
|
661 |
class CKeyStoreIF
|
sl@0
|
662 |
{
|
sl@0
|
663 |
public:
|
sl@0
|
664 |
CKeyStoreIF(MCTTokenInterface*, TBool);
|
sl@0
|
665 |
~CKeyStoreIF();
|
sl@0
|
666 |
public:
|
sl@0
|
667 |
inline MCTTokenInterface* KeyStore() const {return (iKeyStore);};
|
sl@0
|
668 |
inline TBool IsKeyManager() const {return (iIsKeyManager);};
|
sl@0
|
669 |
private:
|
sl@0
|
670 |
CKeyStoreIF(){};
|
sl@0
|
671 |
private:
|
sl@0
|
672 |
MCTTokenInterface* iKeyStore;
|
sl@0
|
673 |
TBool iIsKeyManager;
|
sl@0
|
674 |
};
|
sl@0
|
675 |
private:
|
sl@0
|
676 |
RFs& iFs;
|
sl@0
|
677 |
TState iState;
|
sl@0
|
678 |
TRequestStatus* iOriginalRequestStatus;
|
sl@0
|
679 |
RPointerArray<CKeyStoreIF> iKeyStoresHolder;
|
sl@0
|
680 |
|
sl@0
|
681 |
RCPointerArray<CCTTokenTypeInfo> iTokenTypes;
|
sl@0
|
682 |
TInt iIndexTokenTypes;
|
sl@0
|
683 |
MCTTokenType* iTokenType;
|
sl@0
|
684 |
MCTToken* iToken;
|
sl@0
|
685 |
MCTTokenInterface* iTokenInterface;
|
sl@0
|
686 |
TUid iRequestUid;
|
sl@0
|
687 |
RCPointerArray<HBufC> iTokens;
|
sl@0
|
688 |
TInt iIndexTokens;
|
sl@0
|
689 |
|
sl@0
|
690 |
MCTKeyStore* iKeyStore; ///< The key store in use by the current operation or NULL
|
sl@0
|
691 |
MCTKeyStoreManager* iKeyStoreManager; ///< The key store manager in use by the current operation or NULL
|
sl@0
|
692 |
|
sl@0
|
693 |
RMPointerArray<CCTKeyInfo>* iKeyInfos;
|
sl@0
|
694 |
TCTKeyAttributeFilter* iFilter;
|
sl@0
|
695 |
CCTKeyInfo* iKeyInfo;
|
sl@0
|
696 |
HBufC8* iKeyData;
|
sl@0
|
697 |
CCTKeyInfo** iKeyInfoOut; ///< Pointer to client's key info pointer
|
sl@0
|
698 |
CPBEncryptParms* iPbeParams; // PBE parameters for encrypted key export
|
sl@0
|
699 |
|
sl@0
|
700 |
TInt iIndex;
|
sl@0
|
701 |
TInt iNewTimeout;
|
sl@0
|
702 |
};
|
sl@0
|
703 |
|
sl@0
|
704 |
#endif
|