|
1 /* |
|
2 * Copyright (c) 2004-2009 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 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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <ct.h> |
|
21 #include <mctkeystore.h> |
|
22 #include "ClientOpenedKeys.h" |
|
23 #include "cfskeystoreclient.h" |
|
24 #include "hash.h" |
|
25 |
|
26 // COpenedKey ////////////////////////////////////////////////////////////////// |
|
27 |
|
28 COpenedKey::~COpenedKey() |
|
29 { |
|
30 iClient->ReleaseObject(iHandle); |
|
31 delete iLabel; |
|
32 } |
|
33 |
|
34 // CRSARepudiableSigner //////////////////////////////////////////////////////// |
|
35 |
|
36 CRSARepudiableSigner* CRSARepudiableSigner::New(CFSKeyStoreClient* aClient) |
|
37 { |
|
38 return new CRSARepudiableSigner(aClient); |
|
39 } |
|
40 |
|
41 CRSARepudiableSigner::CRSARepudiableSigner(CFSKeyStoreClient* aClient) |
|
42 : MCTSigner<CRSASignature*>(aClient->Token()) |
|
43 { |
|
44 iClient = aClient; |
|
45 iHandle.iTokenHandle = aClient->Token().Handle(); |
|
46 iHandle.iObjectId = 0; |
|
47 } |
|
48 |
|
49 CRSARepudiableSigner::~CRSARepudiableSigner() |
|
50 { |
|
51 delete iDigest; |
|
52 } |
|
53 |
|
54 void CRSARepudiableSigner::Release() |
|
55 { |
|
56 MCTTokenObject::Release(); |
|
57 } |
|
58 |
|
59 const TDesC& CRSARepudiableSigner::Label() const |
|
60 { |
|
61 return iLabel ? static_cast<const TDesC&>(*iLabel) : static_cast<const TDesC&>(KNullDesC); |
|
62 } |
|
63 |
|
64 MCTToken& CRSARepudiableSigner::Token() const |
|
65 { |
|
66 return iClient->Token(); |
|
67 } |
|
68 |
|
69 TUid CRSARepudiableSigner::Type() const |
|
70 { |
|
71 return KRSARepudiableSignerUID; |
|
72 } |
|
73 |
|
74 TCTTokenObjectHandle CRSARepudiableSigner::Handle() const |
|
75 { |
|
76 return iHandle; |
|
77 } |
|
78 |
|
79 void CRSARepudiableSigner::SignMessage(const TDesC8& aPlaintext, |
|
80 CRSASignature*& aSignature, |
|
81 TRequestStatus& aStatus) |
|
82 { |
|
83 // Hash the data on the client side |
|
84 TRAPD(err, iDigest = CSHA1::NewL()); |
|
85 if (err != KErrNone) |
|
86 { |
|
87 TRequestStatus* status = &aStatus; |
|
88 User::RequestComplete(status, err); |
|
89 } |
|
90 else |
|
91 { |
|
92 iDigest->Update(aPlaintext); |
|
93 Sign(iDigest->Final(), aSignature, aStatus); |
|
94 } |
|
95 } |
|
96 |
|
97 void CRSARepudiableSigner::Sign(const TDesC8& aPlaintext, |
|
98 CRSASignature*& aSignature, |
|
99 TRequestStatus& aStatus) |
|
100 { |
|
101 iClient->RepudiableRSASign(Handle(),aPlaintext, aSignature, aStatus); |
|
102 } |
|
103 |
|
104 void CRSARepudiableSigner::CancelSign() |
|
105 { |
|
106 iClient->CancelRepudiableRSASign(); |
|
107 } |
|
108 |
|
109 // CDSARepudiableSigner //////////////////////////////////////////////////////// |
|
110 |
|
111 CDSARepudiableSigner* CDSARepudiableSigner::New(CFSKeyStoreClient* aClient) |
|
112 { |
|
113 return new CDSARepudiableSigner(aClient); |
|
114 } |
|
115 |
|
116 CDSARepudiableSigner::CDSARepudiableSigner(CFSKeyStoreClient* aClient) |
|
117 : MCTSigner<CDSASignature*>(aClient->Token()) |
|
118 { |
|
119 iClient = aClient; |
|
120 iHandle.iTokenHandle = aClient->Token().Handle(); |
|
121 iHandle.iObjectId = 0; |
|
122 } |
|
123 |
|
124 |
|
125 CDSARepudiableSigner::~CDSARepudiableSigner() |
|
126 { |
|
127 delete iDigest; |
|
128 } |
|
129 |
|
130 void CDSARepudiableSigner::Release() |
|
131 { |
|
132 MCTTokenObject::Release(); |
|
133 } |
|
134 |
|
135 const TDesC& CDSARepudiableSigner::Label() const |
|
136 { |
|
137 return iLabel ? static_cast<const TDesC&>(*iLabel) : static_cast<const TDesC&>(KNullDesC); |
|
138 } |
|
139 |
|
140 MCTToken& CDSARepudiableSigner::Token() const |
|
141 { |
|
142 return iClient->Token(); |
|
143 } |
|
144 |
|
145 TUid CDSARepudiableSigner::Type() const |
|
146 { |
|
147 return KDSARepudiableSignerUID; |
|
148 } |
|
149 |
|
150 TCTTokenObjectHandle CDSARepudiableSigner::Handle() const |
|
151 { |
|
152 return iHandle; |
|
153 } |
|
154 |
|
155 void CDSARepudiableSigner::SignMessage(const TDesC8& aPlaintext, |
|
156 CDSASignature*& aSignature, |
|
157 TRequestStatus& aStatus) |
|
158 { |
|
159 // Hash the data on the client side |
|
160 TRAPD(err, iDigest = CSHA1::NewL()); |
|
161 if (err != KErrNone) |
|
162 { |
|
163 TRequestStatus* status = &aStatus; |
|
164 User::RequestComplete(status, err); |
|
165 } |
|
166 else |
|
167 { |
|
168 iDigest->Update(aPlaintext); |
|
169 Sign(iDigest->Final(), aSignature, aStatus); |
|
170 } |
|
171 } |
|
172 |
|
173 void CDSARepudiableSigner::Sign(const TDesC8& aPlaintext, |
|
174 CDSASignature*& aSignature, |
|
175 TRequestStatus& aStatus) |
|
176 { |
|
177 iClient->RepudiableDSASign(Handle(),aPlaintext, aSignature, aStatus); |
|
178 } |
|
179 |
|
180 void CDSARepudiableSigner::CancelSign() |
|
181 { |
|
182 iClient->CancelRepudiableDSASign(); |
|
183 } |
|
184 |
|
185 // CFSRSADecryptor ///////////////////////////////////////////////////////////// |
|
186 |
|
187 CFSRSADecryptor* CFSRSADecryptor::New(CFSKeyStoreClient* aClient) |
|
188 { |
|
189 return new CFSRSADecryptor(aClient); |
|
190 } |
|
191 |
|
192 CFSRSADecryptor::CFSRSADecryptor(CFSKeyStoreClient* aClient) |
|
193 : MCTDecryptor(aClient->Token()) |
|
194 { |
|
195 iClient = aClient; |
|
196 iHandle.iTokenHandle = aClient->Token().Handle(); |
|
197 iHandle.iObjectId = 0; |
|
198 } |
|
199 |
|
200 CFSRSADecryptor::~CFSRSADecryptor() |
|
201 { |
|
202 } |
|
203 |
|
204 void CFSRSADecryptor::Release() |
|
205 { |
|
206 MCTTokenObject::Release(); |
|
207 } |
|
208 |
|
209 const TDesC& CFSRSADecryptor::Label() const |
|
210 { |
|
211 return iLabel ? static_cast<const TDesC&>(*iLabel) : static_cast<const TDesC&>(KNullDesC); |
|
212 } |
|
213 |
|
214 MCTToken& CFSRSADecryptor::Token() const |
|
215 { |
|
216 return iClient->Token(); |
|
217 } |
|
218 |
|
219 TUid CFSRSADecryptor::Type() const |
|
220 { |
|
221 return KPrivateDecryptorUID; |
|
222 } |
|
223 |
|
224 TCTTokenObjectHandle CFSRSADecryptor::Handle() const |
|
225 { |
|
226 return iHandle; |
|
227 } |
|
228 |
|
229 void CFSRSADecryptor::Decrypt(const TDesC8& aCiphertext, |
|
230 TDes8& aPlaintext, |
|
231 TRequestStatus& aStatus |
|
232 ) |
|
233 { |
|
234 iClient->Decrypt(Handle(),aCiphertext,aPlaintext, aStatus); |
|
235 } |
|
236 |
|
237 void CFSRSADecryptor::CancelDecrypt() |
|
238 { |
|
239 iClient->CancelDecrypt(); |
|
240 } |
|
241 |
|
242 // CDHAgreement //////////////////////////////////////////////////////////////// |
|
243 |
|
244 CDHAgreement* CDHAgreement::New(CFSKeyStoreClient* aClient) |
|
245 { |
|
246 return new CDHAgreement(aClient); |
|
247 } |
|
248 |
|
249 CDHAgreement::CDHAgreement(CFSKeyStoreClient* aClient) |
|
250 : MCTDH(aClient->Token()) |
|
251 { |
|
252 iClient = aClient; |
|
253 iHandle.iTokenHandle = aClient->Token().Handle(); |
|
254 iHandle.iObjectId = 0; |
|
255 } |
|
256 |
|
257 CDHAgreement::~CDHAgreement() |
|
258 { |
|
259 } |
|
260 |
|
261 void CDHAgreement::Release() |
|
262 { |
|
263 MCTTokenObject::Release(); |
|
264 } |
|
265 |
|
266 const TDesC& CDHAgreement::Label() const |
|
267 { |
|
268 return iLabel ? static_cast<const TDesC&>(*iLabel) : static_cast<const TDesC&>(KNullDesC); |
|
269 } |
|
270 |
|
271 MCTToken& CDHAgreement::Token() const |
|
272 { |
|
273 return iClient->Token(); |
|
274 } |
|
275 |
|
276 TUid CDHAgreement::Type() const |
|
277 { |
|
278 return KKeyAgreementUID; |
|
279 } |
|
280 |
|
281 TCTTokenObjectHandle CDHAgreement::Handle() const |
|
282 { |
|
283 return iHandle; |
|
284 } |
|
285 |
|
286 /** Returns the public key ('Big X') for the supplied set of parameters */ |
|
287 void CDHAgreement::PublicKey(const TInteger& aN, const TInteger& aG, |
|
288 CDHPublicKey*& aX, TRequestStatus& aStatus) |
|
289 { |
|
290 iClient->DHPublicKey(Handle(), aN, aG, aX, aStatus); |
|
291 } |
|
292 |
|
293 /** Agrees a session key given the public key of the other party */ |
|
294 void CDHAgreement::Agree(const CDHPublicKey& iY, HBufC8*& aAgreedKey, |
|
295 TRequestStatus& aStatus) |
|
296 { |
|
297 iClient->DHAgree(Handle(), iY, aAgreedKey, aStatus); |
|
298 } |
|
299 |
|
300 /** Cancels either a PublicKey or Agree operation */ |
|
301 void CDHAgreement::CancelAgreement() |
|
302 { |
|
303 iClient->CancelDH(); |
|
304 } |