|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: The header file of DevCertKeyStore |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef __DEVKEYSTORE_H__ |
|
21 #define __DEVKEYSTORE_H__ |
|
22 |
|
23 #include <mctkeystoremanager.h> |
|
24 #include <ct/rmpointerarray.h> |
|
25 #include "DTClient.h" |
|
26 |
|
27 |
|
28 // Maximum allowed size of digest to RSA sign (implied by max 2048 bit key length). |
|
29 const TInt KMaxRSADigestSize = 2048 / 8; |
|
30 |
|
31 // Maximum allowed size of digest to DSA sign (implied by 160 bit output of SHA1). |
|
32 const TInt KMaxDSADigestSize = 160 / 8; |
|
33 |
|
34 class CDevCertOpenedKey; |
|
35 class MDevTokenKeyInfoArray; |
|
36 class CDevTokenDHParams; |
|
37 |
|
38 |
|
39 /** |
|
40 * Implements the MCTKeyStoreManager interface. Inherits from CDTClient. |
|
41 * |
|
42 * The class implements the keystore manager token interface for the software |
|
43 * keystore. It will be created and owned by the unified keystore. Its main |
|
44 * function is to marshall user requests to the filetokens server and unmarshall |
|
45 * the results back again. |
|
46 |
|
47 * @lib DevTokenClient.dll |
|
48 * @since S60 v3.2 |
|
49 */ |
|
50 class CDevCertKeyStore : public CDTClient, public MCTKeyStoreManager |
|
51 { |
|
52 public:// One creator function for each token interface |
|
53 |
|
54 static MCTTokenInterface* NewKeyStoreUserInterfaceL(MCTToken& aToken, RDevTokenClientSession& aClient); |
|
55 |
|
56 static MCTTokenInterface* NewKeyStoreManagerInterfaceL(MCTToken& aToken, RDevTokenClientSession& aClient); |
|
57 |
|
58 public: |
|
59 |
|
60 virtual ~CDevCertKeyStore(); |
|
61 |
|
62 void AddRef(); |
|
63 |
|
64 public: |
|
65 |
|
66 // MKeyStore |
|
67 virtual void List(RMPointerArray<CCTKeyInfo>& aKeys, const TCTKeyAttributeFilter& aFilter, TRequestStatus& aStatus); |
|
68 |
|
69 virtual void CancelList(); |
|
70 |
|
71 virtual void GetKeyInfo(TCTTokenObjectHandle aHandle, CCTKeyInfo*& aInfo, TRequestStatus& aStatus); |
|
72 |
|
73 virtual void CancelGetKeyInfo(); |
|
74 |
|
75 /** |
|
76 * Open an RSA key for signing |
|
77 * |
|
78 * @param aHandle Handle to the key |
|
79 * @param aSigner pointer to a RSA Signer |
|
80 * @param aStatus |
|
81 * @return |
|
82 */ |
|
83 virtual void Open(const TCTTokenObjectHandle& aHandle, |
|
84 MRSASigner*& aSigner, |
|
85 TRequestStatus& aStatus); |
|
86 |
|
87 /** |
|
88 * Open an DSA key for signing |
|
89 * |
|
90 * @param aHandle Handle to the key |
|
91 * @param aSigner pointer to a DSA Signer |
|
92 * @param aStatus |
|
93 * @return |
|
94 */ |
|
95 virtual void Open(const TCTTokenObjectHandle& aHandle, |
|
96 MDSASigner*& aSigner, |
|
97 TRequestStatus& aStatus); |
|
98 |
|
99 /** |
|
100 * Open a RSA key for private decryption |
|
101 * |
|
102 * @param aHandle Handle to the key |
|
103 * @param aSigner pointer to a RSA Decryptor |
|
104 * @param aStatus |
|
105 * @return |
|
106 */ |
|
107 virtual void Open(const TCTTokenObjectHandle& aHandle, |
|
108 MCTDecryptor*& aDecryptor, |
|
109 TRequestStatus& aStatus); |
|
110 |
|
111 /** |
|
112 * Open a DH key for key agreement |
|
113 * |
|
114 * @param aHandle Handle to the key |
|
115 * @param aSigner pointer to a DH |
|
116 * @param aStatus |
|
117 * @return |
|
118 */ |
|
119 virtual void Open(const TCTTokenObjectHandle& aHandle, |
|
120 MCTDH*& aDH, TRequestStatus& aStatus); |
|
121 |
|
122 /** |
|
123 * Cancels an ongoing open request |
|
124 * |
|
125 * @param |
|
126 * @return |
|
127 */ |
|
128 virtual void CancelOpen(); |
|
129 |
|
130 /** |
|
131 * Returns the public key in DER-encoded ASN-1 |
|
132 * |
|
133 * @param aHandle handle to the public key |
|
134 * @param aPublicKey buffer for the public key |
|
135 * @param aStatus |
|
136 * @return |
|
137 */ |
|
138 virtual void ExportPublic(const TCTTokenObjectHandle& aHandle, |
|
139 HBufC8*& aPublicKey, |
|
140 TRequestStatus& aStatus); |
|
141 |
|
142 virtual void CancelExportPublic(); |
|
143 |
|
144 public: |
|
145 // MCTKeyStoreManager |
|
146 virtual void CreateKey(CCTKeyInfo*& aReturnedKey, TRequestStatus& aStatus); |
|
147 |
|
148 virtual void CancelCreateKey(); |
|
149 |
|
150 virtual void ImportKey(const TDesC8& aKey, CCTKeyInfo*& aReturnedKey, TRequestStatus& aStatus); |
|
151 |
|
152 virtual void CancelImportKey(); |
|
153 |
|
154 virtual void ImportEncryptedKey(const TDesC8& aKey, CCTKeyInfo*& aReturnedKey, TRequestStatus& aStatus); |
|
155 |
|
156 virtual void CancelImportEncryptedKey(); |
|
157 |
|
158 virtual void ExportKey(TCTTokenObjectHandle aHandle, HBufC8*& aKey, TRequestStatus& aStatus); |
|
159 |
|
160 virtual void CancelExportKey(); |
|
161 |
|
162 virtual void ExportEncryptedKey(TCTTokenObjectHandle aHandle, const CPBEncryptParms& aParams, HBufC8*& aKey, TRequestStatus& aStatus); |
|
163 |
|
164 virtual void CancelExportEncryptedKey(); |
|
165 |
|
166 virtual void DeleteKey(TCTTokenObjectHandle aHandle, TRequestStatus& aStatus); |
|
167 |
|
168 virtual void CancelDeleteKey(); |
|
169 |
|
170 virtual void SetUsePolicy(TCTTokenObjectHandle aHandle, const TSecurityPolicy& aPolicy, TRequestStatus& aStatus); |
|
171 |
|
172 virtual void CancelSetUsePolicy(); |
|
173 |
|
174 virtual void SetManagementPolicy(TCTTokenObjectHandle aHandle, const TSecurityPolicy& aPolicy, TRequestStatus& aStatus); |
|
175 |
|
176 virtual void CancelSetManagementPolicy(); |
|
177 |
|
178 virtual void SetPassphraseTimeout(TInt aTimeout, TRequestStatus& aStatus) ; |
|
179 |
|
180 virtual void CancelSetPassphraseTimeout(); |
|
181 |
|
182 virtual void Relock(TRequestStatus& aStatus); |
|
183 |
|
184 virtual void CancelRelock(); |
|
185 |
|
186 void ReleaseObject(const TCTTokenObjectHandle& aObject); |
|
187 |
|
188 public: |
|
189 |
|
190 // From MCTTokenInterface |
|
191 virtual MCTToken& Token(); |
|
192 |
|
193 public: |
|
194 |
|
195 void RepudiableDSASign(const TCTTokenObjectHandle& aObject, const TDesC8& aDigest, CDSASignature*& aSignature, TRequestStatus& aStatus); |
|
196 |
|
197 void RepudiableRSASign(const TCTTokenObjectHandle& aObject, const TDesC8& aDigest, CRSASignature*& aSignature, TRequestStatus& aStatus); |
|
198 |
|
199 void Decrypt(const TCTTokenObjectHandle& aObject, const TDesC8& aCiphertext, TDes8& aPlaintext, TRequestStatus& aStatus); |
|
200 |
|
201 void DHPublicKey(const TCTTokenObjectHandle& aHandle, const TInteger& aN, const TInteger& aG, CDHPublicKey*& aX, TRequestStatus& aStatus); |
|
202 |
|
203 void DHAgree(const TCTTokenObjectHandle& aHandle, const CDHPublicKey& iY, HBufC8*& aAgreedKey, TRequestStatus& aStatus); |
|
204 |
|
205 protected: |
|
206 |
|
207 // From MCTTokenInterface |
|
208 virtual void DoRelease(); |
|
209 |
|
210 protected: |
|
211 |
|
212 // From CActive |
|
213 virtual void RunL(); |
|
214 |
|
215 virtual TInt RunError(TInt aError); |
|
216 |
|
217 virtual void DoCancel(); |
|
218 |
|
219 protected: |
|
220 |
|
221 CDevCertKeyStore(TInt aUID, MCTToken& aToken, RDevTokenClientSession& aClient); |
|
222 |
|
223 virtual void ConstructL(); |
|
224 |
|
225 private: |
|
226 |
|
227 void DoListL(const TCTKeyAttributeFilter& aFilter, MDevTokenKeyInfoArray& aOut); |
|
228 |
|
229 void DoGetKeyInfoL(TCTTokenObjectHandle aHandle, CCTKeyInfo*& aInfo); |
|
230 |
|
231 TInt DoOpenKey(TDevTokenMessages aMessage, const TCTTokenObjectHandle& aHandle, CDevCertOpenedKey* aOpenedKey); |
|
232 |
|
233 void DoImportKey(TDevTokenMessages aMessage, const TDesC8& aKey, CCTKeyInfo*& aReturnedKey, TRequestStatus& aStatus); |
|
234 |
|
235 void DoExportPublicL(const TCTTokenObjectHandle& aHandle, HBufC8*& aPublicKey); |
|
236 |
|
237 TInt MarshalKeyInfo(CCTKeyInfo& aKey); |
|
238 |
|
239 void Process(const TCTTokenObjectHandle& aHandle,const TDesC8& aText,TDevTokenMessages aMessage,TRequestStatus& aStatus,TInt aBufSize); |
|
240 |
|
241 void DoDHPublicKeyL(const TCTTokenObjectHandle& aHandle, const TInteger& aN, const TInteger& aG, CDHPublicKey*& aX, TRequestStatus& aStatus); |
|
242 |
|
243 private: |
|
244 |
|
245 TInt AllocKeyBuffer(TInt aReqdSize); |
|
246 |
|
247 void FreeKeyBuffer(); |
|
248 |
|
249 void UpdateKey(); |
|
250 |
|
251 TUint GetKeySizeL(TInt aObjectId); |
|
252 |
|
253 void Cleanup(); |
|
254 |
|
255 private: |
|
256 |
|
257 TInt iRefCount; |
|
258 |
|
259 // Data holders for server to write into |
|
260 TPckgBuf<TInt> iIntOut; |
|
261 |
|
262 TInt iObjectId; // Id of object passed to server |
|
263 |
|
264 private: |
|
265 |
|
266 // Pointers to client pointers, which we set to return created objects. |
|
267 // Only one of these is ever in use at any one time, determined by the |
|
268 // state. |
|
269 union |
|
270 { |
|
271 TAny* iAny; // generic pointer, used to zero the contents of the union |
|
272 CCTKeyInfo** iKeyInfo; // key info object, used for create and import |
|
273 HBufC8** iBuffer; // generic buffer, used for export key and DH agree |
|
274 TDes8* iDecryptedText; // decypled plaintext, used for RSA decrypt |
|
275 CDSASignature** iDSASignature; // DSA signature |
|
276 CRSASignature** iRSASignature; // RSA signature |
|
277 CDHPublicKey** iDHPublicKey; // DH public key |
|
278 } iClientPtr; |
|
279 |
|
280 private: |
|
281 |
|
282 HBufC8* iKey; // Key data buffer for import/export |
|
283 |
|
284 HBufC8* iText; // Buffer used to hold text for decrypt and sign |
|
285 |
|
286 CDevTokenDHParams* iDHParams; // DH params for DH public key |
|
287 |
|
288 }; |
|
289 |
|
290 #endif // __DEVKEYSTORE_H__ |
|
291 |
|
292 //EOF |