28 #include <ct.h> |
28 #include <ct.h> |
29 #include <securityerr.h> |
29 #include <securityerr.h> |
30 #include <e32base.h> |
30 #include <e32base.h> |
31 #include <mctkeystoreuids.h> |
31 #include <mctkeystoreuids.h> |
32 |
32 |
33 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
34 #include <authserver/authtypes.h> |
|
35 #include <authserver/auth_srv_errs.h> |
|
36 #include <s32mem.h> |
|
37 #include "keystore_errs.h" |
|
38 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
39 |
33 |
40 // COpenedKey ////////////////////////////////////////////////////////////////// |
34 // COpenedKey ////////////////////////////////////////////////////////////////// |
41 |
35 |
42 COpenedKey* COpenedKey::NewL(const CFileKeyData& aKeyData, TUid aType, const RMessage2& aMessage, |
36 COpenedKey* COpenedKey::NewL(const CFileKeyData& aKeyData, TUid aType, const RMessage2& aMessage, |
43 CFileKeyDataManager& aKeyDataMan, CPassphraseManager& aPassMan) |
37 CFileKeyDataManager& aKeyDataMan, CPassphraseManager& aPassMan) |
74 COpenedKey::COpenedKey(const CFileKeyData& aKeyData, CFileKeyDataManager& aKeyDataMan, CPassphraseManager& aPassMan) : |
68 COpenedKey::COpenedKey(const CFileKeyData& aKeyData, CFileKeyDataManager& aKeyDataMan, CPassphraseManager& aPassMan) : |
75 CActive(EPriorityStandard), |
69 CActive(EPriorityStandard), |
76 iKeyData(aKeyData), |
70 iKeyData(aKeyData), |
77 iKeyDataMan(aKeyDataMan), |
71 iKeyDataMan(aKeyDataMan), |
78 iPassMan(aPassMan) |
72 iPassMan(aPassMan) |
79 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
80 ,iUserIdentity(NULL) |
|
81 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
82 { |
73 { |
83 } |
74 } |
84 |
75 |
85 void COpenedKey::ConstructL(const RMessage2& aMessage) |
76 void COpenedKey::ConstructL(const RMessage2& aMessage) |
86 { |
77 { |
87 CKeyInfo* keyInfo = iKeyDataMan.ReadKeyInfoLC(iKeyData); |
78 CKeyInfo* keyInfo = iKeyDataMan.ReadKeyInfoLC(iKeyData); |
88 CleanupStack::Pop(keyInfo); |
79 CleanupStack::Pop(keyInfo); |
89 iKeyInfo = keyInfo; |
80 iKeyInfo = keyInfo; |
90 CheckKeyL(aMessage); |
81 CheckKeyL(aMessage); |
91 iLabel = iKeyInfo->Label().AllocL(); |
82 iLabel = iKeyInfo->Label().AllocL(); |
92 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
93 User::LeaveIfError(iAuthClient.Connect()); |
|
94 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
95 CActiveScheduler::Add(this); |
83 CActiveScheduler::Add(this); |
96 } |
84 } |
97 |
85 |
98 COpenedKey::~COpenedKey() |
86 COpenedKey::~COpenedKey() |
99 { |
87 { |
100 Cancel(); |
88 Cancel(); |
101 delete iLabel; |
89 delete iLabel; |
102 delete iKeyInfo; |
90 delete iKeyInfo; |
103 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
104 iAuthClient.Close(); |
|
105 delete iExpression; |
|
106 delete iUserIdentity; |
|
107 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
108 |
91 |
109 } |
92 } |
110 |
93 |
111 const TDesC& COpenedKey::Label() const |
94 const TDesC& COpenedKey::Label() const |
112 { |
95 { |
166 |
148 |
167 iPassMan.GetPassphrase(passphraseId, timeout, iPassphrase, iStatus); |
149 iPassMan.GetPassphrase(passphraseId, timeout, iPassphrase, iStatus); |
168 iState = EGetPassphrase; |
150 iState = EGetPassphrase; |
169 SetActive(); |
151 SetActive(); |
170 } |
152 } |
171 #else |
153 |
172 void COpenedKey::AuthenticateL() |
|
173 { |
|
174 iExpression = iAuthClient.CreateAuthExpressionL(iKeyInfo->AuthExpression()); |
|
175 TUid uid = TUid::Uid(0); |
|
176 iAuthClient.AuthenticateL(*iExpression,iKeyInfo->Freshness(), EFalse, uid, EFalse, KNullDesC, iUserIdentity, iStatus); |
|
177 iState = EAuthenticate; |
|
178 SetActive(); |
|
179 } |
|
180 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
181 |
154 |
182 void COpenedKey::RunL() |
155 void COpenedKey::RunL() |
183 { |
156 { |
184 User::LeaveIfError(iStatus.Int()); |
157 User::LeaveIfError(iStatus.Int()); |
185 |
158 |
186 switch (iState) |
159 switch (iState) |
187 { |
160 { |
188 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
189 case EDoAuthenticate: |
|
190 AuthenticateL(); |
|
191 break; |
|
192 |
|
193 case EAuthenticate: |
|
194 if(iUserIdentity->Id() == AuthServer::KUnknownIdentity) |
|
195 { |
|
196 User::Leave(KErrAuthenticationFailure); |
|
197 } |
|
198 |
|
199 if (!iKeyRead) |
|
200 { |
|
201 RStoreReadStream stream; |
|
202 iKeyDataMan.OpenPrivateDataStreamLC(iKeyData, stream); |
|
203 TPtrC8 key = iUserIdentity->Key().KeyData(); |
|
204 HBufC8* plaintext = DecryptFromStreamL(stream, key); |
|
205 CleanupStack::PushL(plaintext); |
|
206 TAny* ptr = const_cast<TAny*>(static_cast<const TAny*>(plaintext->Des().PtrZ())); |
|
207 |
|
208 RMemReadStream decryptedStream(ptr, plaintext->Length()); |
|
209 decryptedStream.PushL(); |
|
210 ReadPrivateKeyL(decryptedStream); |
|
211 CleanupStack::PopAndDestroy(3,&stream); // plaintext, decryptedStream |
|
212 iKeyRead = ETrue; |
|
213 } |
|
214 |
|
215 delete iUserIdentity; |
|
216 iUserIdentity = NULL; |
|
217 delete iExpression; |
|
218 iExpression = NULL; |
|
219 PerformOperationL(); |
|
220 Complete(KErrNone); |
|
221 break; |
|
222 #else |
|
223 case EGetPassphrase: |
161 case EGetPassphrase: |
224 ASSERT(iPassphrase); |
162 ASSERT(iPassphrase); |
225 if (!iKeyRead) |
163 if (!iKeyRead) |
226 { |
164 { |
227 RStoreReadStream stream; |
165 RStoreReadStream stream; |
261 iState = EIdle; |
198 iState = EIdle; |
262 } |
199 } |
263 |
200 |
264 void COpenedKey::Cleanup() |
201 void COpenedKey::Cleanup() |
265 { |
202 { |
266 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
203 |
267 delete iUserIdentity; |
|
268 iUserIdentity = NULL; |
|
269 delete iExpression; |
|
270 iExpression = NULL; |
|
271 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
272 } |
204 } |
273 |
205 |
274 // CRSARepudiableSigner //////////////////////////////////////////////////////// |
206 // CRSARepudiableSigner //////////////////////////////////////////////////////// |
275 |
207 |
276 CRSARepudiableSigner::CRSARepudiableSigner(const CFileKeyData& aKeyData, CFileKeyDataManager& aKeyDataMan, CPassphraseManager& aPassMan) : |
208 CRSARepudiableSigner::CRSARepudiableSigner(const CFileKeyData& aKeyData, CFileKeyDataManager& aKeyDataMan, CPassphraseManager& aPassMan) : |
304 { |
236 { |
305 ASSERT(iPlaintext.Ptr() == NULL); |
237 ASSERT(iPlaintext.Ptr() == NULL); |
306 ASSERT(iSignaturePtr == NULL); |
238 ASSERT(iSignaturePtr == NULL); |
307 iPlaintext.Set(aPlaintext); |
239 iPlaintext.Set(aPlaintext); |
308 iSignaturePtr = &aSignature; |
240 iSignaturePtr = &aSignature; |
309 #ifndef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
310 GetPassphrase(aStatus); |
241 GetPassphrase(aStatus); |
311 #else |
|
312 aStatus = KRequestPending; |
|
313 iClientStatus = &aStatus; |
|
314 iState = EDoAuthenticate; |
|
315 SetActive(); |
|
316 TRequestStatus* status = &iStatus; |
|
317 User::RequestComplete(status, KErrNone); |
|
318 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
319 } |
242 } |
320 |
243 |
321 void CRSARepudiableSigner::ReadPrivateKeyL(RReadStream& aStream) |
244 void CRSARepudiableSigner::ReadPrivateKeyL(RReadStream& aStream) |
322 { |
245 { |
323 ASSERT(iPrivateKey == NULL); |
246 ASSERT(iPrivateKey == NULL); |
334 *iSignaturePtr = const_cast<CRSASignature*>(signature); |
257 *iSignaturePtr = const_cast<CRSASignature*>(signature); |
335 } |
258 } |
336 |
259 |
337 void CRSARepudiableSigner::Cleanup() |
260 void CRSARepudiableSigner::Cleanup() |
338 { |
261 { |
339 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
340 COpenedKey::Cleanup(); |
|
341 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
342 iPlaintext.Set(NULL, 0); |
262 iPlaintext.Set(NULL, 0); |
343 iSignaturePtr = NULL; |
263 iSignaturePtr = NULL; |
344 } |
264 } |
345 |
265 |
346 // CDSARepudiableSigner //////////////////////////////////////////////////////// |
266 // CDSARepudiableSigner //////////////////////////////////////////////////////// |
376 { |
296 { |
377 ASSERT(iPlaintext.Ptr() == NULL); |
297 ASSERT(iPlaintext.Ptr() == NULL); |
378 ASSERT(iSignaturePtr == NULL); |
298 ASSERT(iSignaturePtr == NULL); |
379 iPlaintext.Set(aPlaintext); |
299 iPlaintext.Set(aPlaintext); |
380 iSignaturePtr = &aSignature; |
300 iSignaturePtr = &aSignature; |
381 #ifndef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
382 GetPassphrase(aStatus); |
301 GetPassphrase(aStatus); |
383 #else |
|
384 aStatus = KRequestPending; |
|
385 iClientStatus = &aStatus; |
|
386 iState = EDoAuthenticate; |
|
387 SetActive(); |
|
388 TRequestStatus* status = &iStatus; |
|
389 User::RequestComplete(status, KErrNone); |
|
390 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
391 } |
302 } |
392 |
303 |
393 void CDSARepudiableSigner::ReadPrivateKeyL(RReadStream& aStream) |
304 void CDSARepudiableSigner::ReadPrivateKeyL(RReadStream& aStream) |
394 { |
305 { |
395 ASSERT(iPrivateKey == NULL); |
306 ASSERT(iPrivateKey == NULL); |
406 *iSignaturePtr = const_cast<CDSASignature*>(signature); |
317 *iSignaturePtr = const_cast<CDSASignature*>(signature); |
407 } |
318 } |
408 |
319 |
409 void CDSARepudiableSigner::Cleanup() |
320 void CDSARepudiableSigner::Cleanup() |
410 { |
321 { |
411 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
412 COpenedKey::Cleanup(); |
|
413 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
414 |
|
415 iPlaintext.Set(NULL, 0); |
322 iPlaintext.Set(NULL, 0); |
416 iSignaturePtr = NULL; |
323 iSignaturePtr = NULL; |
417 } |
324 } |
418 |
325 |
419 // CFSRSADecryptor ///////////////////////////////////////////////////////////// |
326 // CFSRSADecryptor ///////////////////////////////////////////////////////////// |
449 { |
356 { |
450 ASSERT(iCiphertext.Ptr() == NULL); |
357 ASSERT(iCiphertext.Ptr() == NULL); |
451 ASSERT(iPlaintextPtr == NULL); |
358 ASSERT(iPlaintextPtr == NULL); |
452 iCiphertext.Set(aCiphertext); |
359 iCiphertext.Set(aCiphertext); |
453 iPlaintextPtr = &aPlaintext; |
360 iPlaintextPtr = &aPlaintext; |
454 #ifndef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
455 GetPassphrase(aStatus); |
361 GetPassphrase(aStatus); |
456 #else |
|
457 aStatus = KRequestPending; |
|
458 iClientStatus = &aStatus; |
|
459 iState = EDoAuthenticate; |
|
460 SetActive(); |
|
461 TRequestStatus* status = &iStatus; |
|
462 User::RequestComplete(status, KErrNone); |
|
463 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
464 } |
362 } |
465 |
363 |
466 void CFSRSADecryptor::ReadPrivateKeyL(RReadStream& aStream) |
364 void CFSRSADecryptor::ReadPrivateKeyL(RReadStream& aStream) |
467 { |
365 { |
468 ASSERT(iPrivateKey == NULL); |
366 ASSERT(iPrivateKey == NULL); |
483 CleanupStack::PopAndDestroy(decryptor); |
381 CleanupStack::PopAndDestroy(decryptor); |
484 } |
382 } |
485 |
383 |
486 void CFSRSADecryptor::Cleanup() |
384 void CFSRSADecryptor::Cleanup() |
487 { |
385 { |
488 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
489 COpenedKey::Cleanup(); |
|
490 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
491 |
|
492 iCiphertext.Set(NULL, 0); |
386 iCiphertext.Set(NULL, 0); |
493 iPlaintextPtr = NULL; |
387 iPlaintextPtr = NULL; |
494 } |
388 } |
495 |
389 |
496 // CDHAgreement //////////////////////////////////////////////////////////////// |
390 // CDHAgreement //////////////////////////////////////////////////////////////// |
525 ASSERT(iPKParams == NULL); |
419 ASSERT(iPKParams == NULL); |
526 ASSERT(iPKPublicKeyPtr == NULL); |
420 ASSERT(iPKPublicKeyPtr == NULL); |
527 iPKParams = &aParameters; |
421 iPKParams = &aParameters; |
528 iPKPublicKeyPtr = &aPublicKey; |
422 iPKPublicKeyPtr = &aPublicKey; |
529 iDHState = EPublicKey; |
423 iDHState = EPublicKey; |
530 #ifndef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
531 GetPassphrase(aStatus); |
424 GetPassphrase(aStatus); |
532 #else |
|
533 aStatus = KRequestPending; |
|
534 iClientStatus = &aStatus; |
|
535 iState = EDoAuthenticate; |
|
536 SetActive(); |
|
537 TRequestStatus* status = &iStatus; |
|
538 User::RequestComplete(status, KErrNone); |
|
539 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
540 } |
425 } |
541 |
426 |
542 void CDHAgreement::Agree(CDHPublicKey& aY, HBufC8*& aAgreedKey, TRequestStatus& aStatus) |
427 void CDHAgreement::Agree(CDHPublicKey& aY, HBufC8*& aAgreedKey, TRequestStatus& aStatus) |
543 { |
428 { |
544 ASSERT(iAKPublicKey == NULL); |
429 ASSERT(iAKPublicKey == NULL); |
545 ASSERT(iAKAgreedKeyPtr == NULL); |
430 ASSERT(iAKAgreedKeyPtr == NULL); |
546 iAKPublicKey = &aY; |
431 iAKPublicKey = &aY; |
547 iAKAgreedKeyPtr = &aAgreedKey; |
432 iAKAgreedKeyPtr = &aAgreedKey; |
548 iDHState = EAgree; |
433 iDHState = EAgree; |
549 #ifndef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
550 GetPassphrase(aStatus); |
434 GetPassphrase(aStatus); |
551 #else |
|
552 aStatus = KRequestPending; |
|
553 iClientStatus = &aStatus; |
|
554 iState = EDoAuthenticate; |
|
555 SetActive(); |
|
556 TRequestStatus* status = &iStatus; |
|
557 User::RequestComplete(status, KErrNone); |
|
558 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
559 } |
435 } |
560 |
436 |
561 void CDHAgreement::ReadPrivateKeyL(RReadStream& aStream) |
437 void CDHAgreement::ReadPrivateKeyL(RReadStream& aStream) |
562 { |
438 { |
563 CreateLC(aStream, iKey); |
439 CreateLC(aStream, iKey); |
618 CleanupStack::PopAndDestroy(2, privKey); |
494 CleanupStack::PopAndDestroy(2, privKey); |
619 } |
495 } |
620 |
496 |
621 void CDHAgreement::Cleanup() |
497 void CDHAgreement::Cleanup() |
622 { |
498 { |
623 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
624 COpenedKey::Cleanup(); |
|
625 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
626 |
|
627 iPKParams = NULL; |
499 iPKParams = NULL; |
628 iPKPublicKeyPtr = NULL; |
500 iPKPublicKeyPtr = NULL; |
629 iAKPublicKey = NULL; |
501 iAKPublicKey = NULL; |
630 iAKAgreedKeyPtr = NULL; |
502 iAKAgreedKeyPtr = NULL; |
631 iDHState = EIdle; |
503 iDHState = EIdle; |