First public contribution.
2 * Copyright (c) 2003-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.
26 #ifndef __MCTKEYSTORE_H__
27 #define __MCTKEYSTORE_H__
29 #include <securitydefs.h>
30 #include <mkeystore.h>
33 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
34 #include <mctkeystoreuids.h>
37 /** The UID of the filekey store */
38 const TInt KTokenTypeFileKeystore = 0x101F7333;
40 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
42 /** The type ID of CCTKeyInfo objects */
43 const TUid KKeyInfoUID = {0x101F5152};
44 const TUid KNonRepudiationSignerUID = {0x101F7A40};
45 const TUid KKeyStoreAuthObjectUID = {0x101FE681};
49 class MCTAuthenticationObject;
52 * Defines the interface for a read-only key store token.
54 * All the details are defined in MKeyStore as they are shared by the unified
57 * The class adds no extra member functions or data.
60 class MCTKeyStore : public MCTTokenInterface, public MKeyStore
65 * Base class for CCTKeyInfo.
68 class CKeyInfoBase : protected CBase
72 /** Key algorithms. */
75 EInvalidAlgorithm = 0,
79 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
84 /** Flags for key access bitfield. */
87 EInvalidAccess = 0x00,
90 EAlwaysSensitive = 0x04,
91 ENeverExtractable = 0x08,
97 inline TKeyIdentifier ID() const; ///< The ID (SHA-1 hash) of the key
98 inline TKeyUsagePKCS15 Usage() const; ///< The key usage
99 inline TUint Size() const; ///< The size of the key
100 inline const TDesC& Label() const; ///< The key's label.
101 inline const TSecurityPolicy& UsePolicy() const; ///< The security policy for key use
102 inline const TSecurityPolicy& ManagementPolicy() const; ///< The security policy for key management
103 inline EKeyAlgorithm Algorithm() const; ///< The key algorithm
106 * The key access type. The return code is bitfield made up of 0 or more
107 * values from EKeyAccess ORed together.
109 inline TInt AccessType() const;
112 * Returns whether the key is native.
114 * A native key is one where operations on the key are performed on the same
115 * hardware as the the key is stored. For instance, if a key that is stored
116 * on secure hardware but calculations are carried out on the main
117 * processor, it isn't native.
119 inline TBool Native() const;
121 inline TTime StartDate() const; ///< The start time, or TTime(0) if not set
122 inline TTime EndDate() const; ///< The end time, or TTime(0) if not set
123 inline const TDesC8& PKCS8AttributeSet() const; ///< The PKCS#8 attribute set.
126 * Externalizes the key data to stream
128 IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
133 * Get the handle of the key. This is a identifier that uniquely identifies
134 * the key within one store, and is used to construct the token handle.
136 inline TInt HandleID() const;
139 * Set the handle of the key. Called by the token when a key is created.
141 * @param aHandle The new handle of the key
143 inline void SetHandle(TInt aHandle);
146 * Called by the token when a key is created, to set the key identifier
147 * (SHA-1 hash) of the new key
149 * @param aId The newly generated SHA-1 hash
151 inline void SetIdentifier(TKeyIdentifier aId);
154 * Set the size of a key.
156 inline void SetSize(TUint aSize);
159 * Set the key algorithm.
161 inline void SetAlgorithm(EKeyAlgorithm aAlg);
166 * Protected constructor, called by derived classes.
168 IMPORT_C CKeyInfoBase(TKeyIdentifier aID,
169 TKeyUsagePKCS15 aUsage,
173 const TSecurityPolicy& aUsePolicy,
174 const TSecurityPolicy& aManagementPolicy,
175 EKeyAlgorithm aAlgorithm,
180 HBufC8* aPKCS8AttributeSet);
183 * Protected constructor, called by derived classes.
185 IMPORT_C CKeyInfoBase();
188 * Second phase constructor. Called by derived classes' NewL methods.
190 IMPORT_C void ConstructL();
193 * Second phase constructor. Called by derived classes' NewL methods.
195 IMPORT_C void ConstructL(RReadStream& aIn);
198 * Destructor is protected so CCTKeyInfo can force users to call Release.
200 IMPORT_C ~CKeyInfoBase();
205 * Internalizes key data from a stream.
207 void InternalizeL(RReadStream& aStream);
210 TKeyIdentifier iID; ///< The ID of the key
211 TKeyUsagePKCS15 iUsage; ///< The usage of the key
212 TUint iSize; ///< The size of the key
213 HBufC* iLabel; ///< The identifying label of the key
214 TInt iHandle; ///< The handle of the key
215 TSecurityPolicy iUsePolicy; ///< The secutity policy for key use
216 TSecurityPolicy iManagementPolicy; ///< The secutity policy for key management
217 EKeyAlgorithm iAlgorithm; ///< The key type (RSA, DSA etc)
218 TInt iAccessType; ///< Key sensitivity
219 TBool iNative; ///< Key is native (cryptographic operations are carried out on the store)
220 TTime iStartDate; ///< Key Start Date
221 TTime iEndDate; ///< Key end date
222 HBufC8* iPKCS8AttributeSet; ///< Attributes as a DER-encoded set
226 * Information about a key, as returned by MCTKeyStore::List.
229 class CCTKeyInfo : public CKeyInfoBase, public MCTTokenObject
235 * Creates a CCTKeyInfo from constituents. This is called by the unified
236 * key store, and should not be called directly.
238 * @param aID The SHA1 hash of the key
239 * @param aUsage The usage of the key
240 * @param aSize The size of the key in bytes
241 * @param aProtector A protector object if the key is protected by a PIN.
242 * This may be NULL if the protector is not known.
243 * @param aLabel The label of the key (takes ownership).
244 * @param aToken The token the key is in
245 * @param aHandle The object ID part of the object handle; an
246 * integer that is unique amongst keys in this token.
247 * @param aUsePolicy The security policy for key use
248 * @param aManagementPolicy The security policy for key management
249 * @param aAlgorithm The key algorithm (RSA, DSA or Diffie-Hellman)
250 * @param aAccessType The access type of the key
251 * @param aNative Defines whether the key is native
252 * @param aStartDate The key validity start date
253 * @param aEndDate The key validity end date
254 * @param aPKCS8AttributeSet (optional) The DER encoded PKCS8 attribute set
257 * @leave KErrKeyUsage If the key usage flags are not valid or not
258 * consistent with the key algorithm.
259 * @leave KErrKeyValidity If the validity start and end dates are specified
260 * but do not form a valid time period.
262 IMPORT_C static CCTKeyInfo* NewL(TKeyIdentifier aID,
263 TKeyUsagePKCS15 aUsage,
265 MCTAuthenticationObject* aProtector,
269 const TSecurityPolicy& aUsePolicy,
270 const TSecurityPolicy& aManagementPolicy,
271 EKeyAlgorithm aAlgorithm,
276 HBufC8* aPKCS8AttributeSet = NULL);
279 * Creates a new KeyInfo from a stream.
281 * @param aStream The stream to read the key data from
282 * @param aToken The token that the key is in
284 * @leave KErrKeyUsage If the key usage flags are not valid or not
285 * consistent with the key algorithm.
286 * @leave KErrKeyValidity If the validity start and end dates are specified
287 * but do not form a valid time period.
289 IMPORT_C static CCTKeyInfo* NewL(RReadStream& aStream, MCTToken& aToken);
294 * The PIN (or other authentication object) that protects the key, or NULL
295 * if not set. This object is owned by key store.
297 inline MCTAuthenticationObject* Protector() const;
300 * Sets the authentication object for this key. The object's Release method
301 * will be called by the destructor, allowing for refence counting of auth
302 * objects to be implemented if desired.
304 inline void SetProtector(MCTAuthenticationObject& aProtector);
306 /** The CT handle to this object. */
307 inline operator TCTTokenObjectHandle() const;
311 // from MCTTokenObject
313 /** The label of the key */
314 virtual const TDesC& Label() const;
316 /** The token the key is in */
317 virtual MCTToken& Token() const;
319 /** Returns KKeyInfoUID to indicate this is a key info object */
320 virtual TUid Type() const;
323 * A handle for the key. This can be used to identify a key to
326 virtual TCTTokenObjectHandle Handle() const;
330 CCTKeyInfo(TKeyIdentifier aID,
331 TKeyUsagePKCS15 aUsage,
333 MCTAuthenticationObject* aProtector,
337 const TSecurityPolicy& aUsePolicy,
338 const TSecurityPolicy& aManagementPolicy,
339 EKeyAlgorithm aAlgorithm,
344 HBufC8* aPKCS8AttributeSet);
346 CCTKeyInfo(MCTToken& aToken);
352 /** The token the key is in*/
355 /** The protector object of the key. This pointer is not owned by the class */
356 MCTAuthenticationObject* iProtector;
360 * A filter to specify which keys should be returned from the store by
364 struct TCTKeyAttributeFilter
371 EUsableOrManageableKeys
375 IMPORT_C TCTKeyAttributeFilter();
378 * The hash of the key we're looking for. A zero-length descriptor means
381 TKeyIdentifier iKeyId;
384 * The required usage of the key. A key must match any of the usages
385 * specified. Use EAllUsages to return all usages.
387 TKeyUsagePKCS15 iUsage;
390 * Filter returned keys by the operations the calling process is allowed to
391 * perform on them (as determined by the security policies set on them).
393 * The default is EUsableKeys. Note that if this is to set to KAllKeys, all
394 * keys will be returned, including those that are unusable by the calling
397 TPolicyFilter iPolicyFilter;
399 /** The algorithm. EInvalidAlgorithm indicates 'don't care */
400 CCTKeyInfo::EKeyAlgorithm iKeyAlgorithm;
403 #include "mctkeystore.inl"
405 #endif // __MCTKEYSTORE_H__