os/security/cryptomgmtlibs/cryptotokenfw/inc_interfaces/MCTKeyStore_v2.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
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
* MCTKeystore.h
sl@0
    16
*
sl@0
    17
*/
sl@0
    18
sl@0
    19
sl@0
    20
/**
sl@0
    21
 @file 
sl@0
    22
 @publishedPartner
sl@0
    23
 @released
sl@0
    24
*/
sl@0
    25
 
sl@0
    26
#ifndef __MCTKEYSTORE_H__
sl@0
    27
#define __MCTKEYSTORE_H__
sl@0
    28
sl@0
    29
#include <securitydefs.h>
sl@0
    30
#include <mkeystore.h>
sl@0
    31
#include <s32file.h>
sl@0
    32
sl@0
    33
#ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
sl@0
    34
#include <mctkeystoreuids.h>
sl@0
    35
#endif
sl@0
    36
sl@0
    37
/** The UID of the filekey store */
sl@0
    38
const TInt KTokenTypeFileKeystore = 0x101F7333;
sl@0
    39
sl@0
    40
#ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
sl@0
    41
sl@0
    42
/** The type ID of CCTKeyInfo objects */
sl@0
    43
const TUid KKeyInfoUID = {0x101F5152};
sl@0
    44
const TUid KNonRepudiationSignerUID = {0x101F7A40};
sl@0
    45
const TUid KKeyStoreAuthObjectUID = {0x101FE681};
sl@0
    46
sl@0
    47
#endif
sl@0
    48
sl@0
    49
class MCTAuthenticationObject;
sl@0
    50
sl@0
    51
/**
sl@0
    52
 * Defines the interface for a read-only key store token.
sl@0
    53
 *
sl@0
    54
 * All the details are defined in MKeyStore as they are shared by the unified
sl@0
    55
 * key store.
sl@0
    56
 * 
sl@0
    57
 * The class adds no extra member functions or data. 
sl@0
    58
 * 
sl@0
    59
 */
sl@0
    60
class MCTKeyStore : public MCTTokenInterface, public MKeyStore
sl@0
    61
	{
sl@0
    62
	};
sl@0
    63
sl@0
    64
/**
sl@0
    65
 * Base class for CCTKeyInfo.
sl@0
    66
 *
sl@0
    67
 */
sl@0
    68
class CKeyInfoBase : protected CBase
sl@0
    69
	{
sl@0
    70
public:
sl@0
    71
sl@0
    72
	/** Key algorithms. */
sl@0
    73
	enum EKeyAlgorithm
sl@0
    74
		{
sl@0
    75
		EInvalidAlgorithm	= 0,
sl@0
    76
		ERSA				= 1,
sl@0
    77
		EDSA				= 2,
sl@0
    78
		EDH					= 3,
sl@0
    79
#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
sl@0
    80
		EECC                = 4,
sl@0
    81
#endif
sl@0
    82
		};
sl@0
    83
sl@0
    84
	/** Flags for key access bitfield. */
sl@0
    85
	enum EKeyAccess
sl@0
    86
		{
sl@0
    87
		EInvalidAccess		= 0x00,
sl@0
    88
		ESensitive			= 0x01,
sl@0
    89
		EExtractable		= 0x02,
sl@0
    90
		EAlwaysSensitive	= 0x04,
sl@0
    91
		ENeverExtractable	= 0x08,
sl@0
    92
		ELocal				= 0x10
sl@0
    93
		};
sl@0
    94
sl@0
    95
public:
sl@0
    96
	
sl@0
    97
	inline TKeyIdentifier ID() const;						///< The ID (SHA-1 hash) of the key 
sl@0
    98
	inline TKeyUsagePKCS15 Usage() const;					///< The key usage 
sl@0
    99
	inline TUint Size() const;								///< The size of the key 
sl@0
   100
	inline const TDesC& Label() const;						///< The key's label.
sl@0
   101
	inline const TSecurityPolicy& UsePolicy() const; 		///< The security policy for key use 
sl@0
   102
	inline const TSecurityPolicy& ManagementPolicy() const; ///< The security policy for key management 
sl@0
   103
	inline EKeyAlgorithm Algorithm() const;					///< The key algorithm
sl@0
   104
sl@0
   105
	/**
sl@0
   106
	 * The key access type. The return code is bitfield made up of 0 or more
sl@0
   107
	 * values from EKeyAccess ORed together.
sl@0
   108
	 */
sl@0
   109
	inline TInt AccessType() const;
sl@0
   110
sl@0
   111
	/**
sl@0
   112
	 * Returns whether the key is native.
sl@0
   113
	 *
sl@0
   114
	 * A native key is one where operations on the key are performed on the same
sl@0
   115
	 * hardware as the the key is stored. For instance, if a key that is stored
sl@0
   116
	 * on secure hardware but calculations are carried out on the main
sl@0
   117
	 * processor, it isn't native.
sl@0
   118
	 */
sl@0
   119
	inline TBool Native() const;
sl@0
   120
	
sl@0
   121
	inline TTime StartDate() const;					///< The start time, or TTime(0) if not set
sl@0
   122
	inline TTime EndDate() const;					///< The end time, or TTime(0) if not set
sl@0
   123
	inline const TDesC8& PKCS8AttributeSet() const;	///< The PKCS#8 attribute set.
sl@0
   124
sl@0
   125
	/**
sl@0
   126
	 * Externalizes the key data to stream
sl@0
   127
	 */
sl@0
   128
	IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
sl@0
   129
sl@0
   130
public:
sl@0
   131
sl@0
   132
	/**
sl@0
   133
	 * Get the handle of the key.  This is a identifier that uniquely identifies
sl@0
   134
	 * the key within one store, and is used to construct the token handle.
sl@0
   135
	 */
sl@0
   136
	inline TInt HandleID() const;
sl@0
   137
sl@0
   138
	/**
sl@0
   139
	 * Set the handle of the key.  Called by the token when a key is created.
sl@0
   140
	 *
sl@0
   141
	 * @param aHandle The new handle of the key
sl@0
   142
	 */
sl@0
   143
	inline void SetHandle(TInt aHandle);
sl@0
   144
sl@0
   145
	/**
sl@0
   146
	 * Called by the token when a key is created, to set the key identifier
sl@0
   147
	 * (SHA-1 hash) of the new key
sl@0
   148
	 *
sl@0
   149
	 * @param aId The newly generated SHA-1 hash
sl@0
   150
	 */
sl@0
   151
	inline void SetIdentifier(TKeyIdentifier aId);
sl@0
   152
sl@0
   153
	/**
sl@0
   154
	 * Set the size of a key.
sl@0
   155
	 */
sl@0
   156
	inline void SetSize(TUint aSize);
sl@0
   157
sl@0
   158
	/**
sl@0
   159
	 * Set the key algorithm.
sl@0
   160
	 */
sl@0
   161
	inline void SetAlgorithm(EKeyAlgorithm aAlg);
sl@0
   162
sl@0
   163
protected:
sl@0
   164
sl@0
   165
	/**
sl@0
   166
	 * Protected constructor, called by derived classes.
sl@0
   167
	 */
sl@0
   168
	IMPORT_C CKeyInfoBase(TKeyIdentifier aID,
sl@0
   169
						  TKeyUsagePKCS15 aUsage,
sl@0
   170
						  TUint aSize,
sl@0
   171
						  HBufC* aLabel,
sl@0
   172
						  TInt aHandle,
sl@0
   173
						  const TSecurityPolicy& aUsePolicy,
sl@0
   174
						  const TSecurityPolicy& aManagementPolicy,
sl@0
   175
						  EKeyAlgorithm aAlgorithm,
sl@0
   176
						  TInt aAccessType,
sl@0
   177
						  TBool aNative,
sl@0
   178
						  TTime aStartDate,
sl@0
   179
						  TTime aEndDate,
sl@0
   180
						  HBufC8* aPKCS8AttributeSet);
sl@0
   181
sl@0
   182
	/**
sl@0
   183
	 * Protected constructor, called by derived classes.
sl@0
   184
	 */
sl@0
   185
	IMPORT_C CKeyInfoBase();
sl@0
   186
sl@0
   187
	/**
sl@0
   188
	 * Second phase constructor.  Called by derived classes' NewL methods.
sl@0
   189
	 */
sl@0
   190
	IMPORT_C void ConstructL();
sl@0
   191
sl@0
   192
	/**
sl@0
   193
	 * Second phase constructor.  Called by derived classes' NewL methods.
sl@0
   194
	 */
sl@0
   195
	IMPORT_C void ConstructL(RReadStream& aIn);
sl@0
   196
sl@0
   197
	/**
sl@0
   198
	 * Destructor is protected so CCTKeyInfo can force users to call Release.
sl@0
   199
	 */
sl@0
   200
	IMPORT_C ~CKeyInfoBase();
sl@0
   201
sl@0
   202
private:
sl@0
   203
sl@0
   204
	/**
sl@0
   205
	 * Internalizes key data from a stream.
sl@0
   206
	 */
sl@0
   207
	void InternalizeL(RReadStream& aStream);
sl@0
   208
	
sl@0
   209
protected:
sl@0
   210
	TKeyIdentifier iID;					///< The ID of the key
sl@0
   211
	TKeyUsagePKCS15 iUsage;				///< The usage of the key 
sl@0
   212
	TUint iSize;						///< The size of the key 
sl@0
   213
	HBufC* iLabel;						///< The identifying label of the key
sl@0
   214
	TInt iHandle;						///< The handle of the key
sl@0
   215
	TSecurityPolicy iUsePolicy;			///< The secutity policy for key use
sl@0
   216
	TSecurityPolicy iManagementPolicy;	///< The secutity policy for key management
sl@0
   217
	EKeyAlgorithm iAlgorithm;			///< The key type (RSA, DSA etc)
sl@0
   218
	TInt iAccessType;					///< Key sensitivity
sl@0
   219
	TBool iNative;						///< Key is native (cryptographic operations are carried out on the store)
sl@0
   220
	TTime iStartDate;					///< Key Start Date 
sl@0
   221
	TTime iEndDate;						///< Key end date 
sl@0
   222
	HBufC8* iPKCS8AttributeSet;			///< Attributes as a DER-encoded set
sl@0
   223
	};
sl@0
   224
sl@0
   225
/**
sl@0
   226
 * Information about a key, as returned by MCTKeyStore::List.
sl@0
   227
 *
sl@0
   228
 */
sl@0
   229
class CCTKeyInfo : public CKeyInfoBase, public MCTTokenObject
sl@0
   230
	{
sl@0
   231
public:
sl@0
   232
sl@0
   233
	/**
sl@0
   234
	 * 
sl@0
   235
	 * Creates a CCTKeyInfo from constituents.  This is called by the unified
sl@0
   236
	 * key store, and should not be called directly.
sl@0
   237
	 *
sl@0
   238
	 * @param aID The SHA1 hash of the key
sl@0
   239
	 * @param aUsage The usage of the key
sl@0
   240
	 * @param aSize The size of the key in bytes
sl@0
   241
	 * @param aProtector A protector object if the key is protected by a PIN.
sl@0
   242
	 * This may be NULL if the protector is not known.
sl@0
   243
	 * @param aLabel The label of the key (takes ownership).
sl@0
   244
	 * @param aToken The token the key is in
sl@0
   245
	 * @param aHandle The object ID part of the object handle; an
sl@0
   246
	 * integer that is unique amongst keys in this token.
sl@0
   247
	 * @param aUsePolicy The security policy for key use
sl@0
   248
	 * @param aManagementPolicy The security policy for key management
sl@0
   249
	 * @param aAlgorithm The key algorithm (RSA, DSA or Diffie-Hellman)
sl@0
   250
	 * @param aAccessType The access type of the key
sl@0
   251
	 * @param aNative	Defines whether the key is native
sl@0
   252
	 * @param aStartDate The key validity start date
sl@0
   253
	 * @param aEndDate The key validity end date
sl@0
   254
	 * @param aPKCS8AttributeSet (optional) The DER encoded PKCS8 attribute set
sl@0
   255
	 * (takes ownership).
sl@0
   256
	 *
sl@0
   257
	 * @leave KErrKeyUsage If the key usage flags are not valid or not
sl@0
   258
	 * consistent with the key algorithm.
sl@0
   259
	 * @leave KErrKeyValidity If the validity start and end dates are specified
sl@0
   260
	 * but do not form a valid time period.
sl@0
   261
	 */
sl@0
   262
	IMPORT_C static CCTKeyInfo* NewL(TKeyIdentifier aID,
sl@0
   263
									 TKeyUsagePKCS15 aUsage,
sl@0
   264
									 TUint aSize,
sl@0
   265
									 MCTAuthenticationObject* aProtector,
sl@0
   266
									 HBufC* aLabel,
sl@0
   267
									 MCTToken& aToken,
sl@0
   268
									 TInt aHandle,
sl@0
   269
									 const TSecurityPolicy& aUsePolicy,
sl@0
   270
									 const TSecurityPolicy& aManagementPolicy,
sl@0
   271
									 EKeyAlgorithm aAlgorithm,
sl@0
   272
									 TInt aAccessType,
sl@0
   273
									 TBool aNative,
sl@0
   274
									 TTime aStartDate,
sl@0
   275
									 TTime aEndDate,
sl@0
   276
									 HBufC8* aPKCS8AttributeSet = NULL);
sl@0
   277
sl@0
   278
	/**
sl@0
   279
	 * Creates a new KeyInfo from a stream.
sl@0
   280
	 *
sl@0
   281
	 * @param aStream The stream to read the key data from
sl@0
   282
	 * @param aToken The token that the key is in
sl@0
   283
	 *
sl@0
   284
	 * @leave KErrKeyUsage If the key usage flags are not valid or not
sl@0
   285
	 * consistent with the key algorithm.
sl@0
   286
	 * @leave KErrKeyValidity If the validity start and end dates are specified
sl@0
   287
	 * but do not form a valid time period.
sl@0
   288
	 */
sl@0
   289
	IMPORT_C static CCTKeyInfo* NewL(RReadStream& aStream, MCTToken& aToken);
sl@0
   290
sl@0
   291
public:
sl@0
   292
sl@0
   293
	/**
sl@0
   294
	 * The PIN (or other authentication object) that protects the key, or NULL
sl@0
   295
	 * if not set.  This object is owned by key store.
sl@0
   296
	 */
sl@0
   297
	inline MCTAuthenticationObject* Protector() const;
sl@0
   298
sl@0
   299
	/**
sl@0
   300
	 * Sets the authentication object for this key.  The object's Release method
sl@0
   301
	 * will be called by the destructor, allowing for refence counting of auth
sl@0
   302
	 * objects to be implemented if desired.
sl@0
   303
	 */
sl@0
   304
	inline void SetProtector(MCTAuthenticationObject& aProtector);
sl@0
   305
	
sl@0
   306
	/** The CT handle to this object. */
sl@0
   307
	inline operator TCTTokenObjectHandle() const;
sl@0
   308
sl@0
   309
public:
sl@0
   310
sl@0
   311
	// from MCTTokenObject
sl@0
   312
sl@0
   313
	/** The label of the key */
sl@0
   314
 	virtual const TDesC& Label() const;
sl@0
   315
sl@0
   316
	/** The token the key is in */
sl@0
   317
	virtual MCTToken& Token() const;
sl@0
   318
sl@0
   319
	/** Returns KKeyInfoUID to indicate this is a key info object */
sl@0
   320
	virtual TUid Type() const;
sl@0
   321
sl@0
   322
	/**
sl@0
   323
	 * A handle for the key. This can be used to identify a key to
sl@0
   324
	 * another process.
sl@0
   325
	 */
sl@0
   326
	virtual TCTTokenObjectHandle Handle() const;
sl@0
   327
sl@0
   328
private:
sl@0
   329
sl@0
   330
	CCTKeyInfo(TKeyIdentifier aID,
sl@0
   331
			   TKeyUsagePKCS15 aUsage,
sl@0
   332
			   TUint aSize,
sl@0
   333
			   MCTAuthenticationObject* aProtector,
sl@0
   334
			   HBufC* aLabel,
sl@0
   335
			   MCTToken& aToken,
sl@0
   336
			   TInt aHandle,
sl@0
   337
			   const TSecurityPolicy& aUsePolicy,
sl@0
   338
			   const TSecurityPolicy& aManagementPolicy,
sl@0
   339
			   EKeyAlgorithm aAlgorithm,
sl@0
   340
			   TInt aAccessType,
sl@0
   341
			   TBool aNative,
sl@0
   342
			   TTime aStartDate,
sl@0
   343
			   TTime aEndDate,
sl@0
   344
			   HBufC8* aPKCS8AttributeSet);
sl@0
   345
sl@0
   346
	CCTKeyInfo(MCTToken& aToken);
sl@0
   347
sl@0
   348
	~CCTKeyInfo();
sl@0
   349
sl@0
   350
private:
sl@0
   351
sl@0
   352
	/** The token the key is in*/
sl@0
   353
	MCTToken& iToken;
sl@0
   354
sl@0
   355
	/** The protector object of the key. This pointer is not owned by the class */
sl@0
   356
	MCTAuthenticationObject* iProtector;
sl@0
   357
};
sl@0
   358
sl@0
   359
/**
sl@0
   360
 * A filter to specify which keys should be returned from the store by
sl@0
   361
 * MCTKeyStore::List.
sl@0
   362
 *
sl@0
   363
 */
sl@0
   364
struct TCTKeyAttributeFilter
sl@0
   365
	{
sl@0
   366
	enum TPolicyFilter
sl@0
   367
		{
sl@0
   368
		EAllKeys,
sl@0
   369
		EUsableKeys,
sl@0
   370
		EManageableKeys,
sl@0
   371
		EUsableOrManageableKeys
sl@0
   372
		};
sl@0
   373
sl@0
   374
	/** Constructor */
sl@0
   375
	IMPORT_C TCTKeyAttributeFilter();
sl@0
   376
sl@0
   377
	/**
sl@0
   378
	 * The hash of the key we're looking for. A zero-length descriptor means
sl@0
   379
	 * 'don't care
sl@0
   380
	 */
sl@0
   381
	TKeyIdentifier iKeyId;
sl@0
   382
sl@0
   383
	/**
sl@0
   384
	 * The required usage of the key. A key must match any of the usages
sl@0
   385
	 * specified. Use EAllUsages to return all usages.
sl@0
   386
	 */
sl@0
   387
	TKeyUsagePKCS15 iUsage;
sl@0
   388
sl@0
   389
	/**
sl@0
   390
	 * Filter returned keys by the operations the calling process is allowed to
sl@0
   391
	 * perform on them (as determined by the security policies set on them).
sl@0
   392
	 * 
sl@0
   393
	 * The default is EUsableKeys.  Note that if this is to set to KAllKeys, all
sl@0
   394
	 * keys will be returned, including those that are unusable by the calling
sl@0
   395
	 * process.
sl@0
   396
	 */
sl@0
   397
	TPolicyFilter iPolicyFilter;
sl@0
   398
sl@0
   399
	/** The algorithm. EInvalidAlgorithm indicates 'don't care */
sl@0
   400
	CCTKeyInfo::EKeyAlgorithm iKeyAlgorithm;
sl@0
   401
	};
sl@0
   402
sl@0
   403
#include "mctkeystore.inl"
sl@0
   404
sl@0
   405
#endif // __MCTKEYSTORE_H__