cryptoservices/filebasedcertificateandkeystores/source/keystore/Server/CKeyDataManager.cpp
branchRCL_3
changeset 62 a71299154b21
parent 61 641f389e9157
equal deleted inserted replaced
61:641f389e9157 62:a71299154b21
    22 #include "fstokenutil.h"
    22 #include "fstokenutil.h"
    23 #include "keystorepassphrase.h"
    23 #include "keystorepassphrase.h"
    24 
    24 
    25 _LIT(KKeyStoreFilename,"keys.dat");
    25 _LIT(KKeyStoreFilename,"keys.dat");
    26 
    26 
    27 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
    28 #include <e32property.h>
       
    29 #include <authserver/aspubsubdefs.h>
       
    30 #else
       
    31 const TInt KDefaultPassphraseTimeout = 30;
    27 const TInt KDefaultPassphraseTimeout = 30;
    32 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
    33 
    28 
    34 //	*********************************************************************
    29 //	*********************************************************************
    35 //	Key store data manager - maintains array of objects representing keys
    30 //	Key store data manager - maintains array of objects representing keys
    36 //	*********************************************************************
    31 //	*********************************************************************
    37 
    32 
    55 	iFile.Close(); // May already have been closed by store
    50 	iFile.Close(); // May already have been closed by store
    56 	iFs.Close();
    51 	iFs.Close();
    57 		
    52 		
    58 	iKeys.ResetAndDestroy();
    53 	iKeys.ResetAndDestroy();
    59 	iKeys.Close();
    54 	iKeys.Close();
    60 	#ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
    61 	iIdentityId.Close();
       
    62 	#endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
    63 	}
    55 	}
    64 
    56 
    65 CFileKeyDataManager::CFileKeyDataManager() :
    57 CFileKeyDataManager::CFileKeyDataManager() :
    66 	iRootStreamId(KNullStreamId),
    58 	iRootStreamId(KNullStreamId),
    67 	iInfoStreamId(KNullStreamId)
    59 	iInfoStreamId(KNullStreamId)
    68 #ifndef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
    69 	,iPassStreamId(KNullStreamId),
    60 	,iPassStreamId(KNullStreamId),
    70 	iTimeoutStreamId(KNullStreamId)
    61 	iTimeoutStreamId(KNullStreamId)
    71 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
    72 	{
    62 	{
    73 	}
    63 	}
    74 
    64 
    75 void CFileKeyDataManager::ConstructL()
    65 void CFileKeyDataManager::ConstructL()
    76 	{
    66 	{
    79 	OpenStoreL();
    69 	OpenStoreL();
    80 
    70 
    81 	RStoreReadStream lookupStream;
    71 	RStoreReadStream lookupStream;
    82 	lookupStream.OpenLC(*iFileStore, iInfoStreamId);
    72 	lookupStream.OpenLC(*iFileStore, iInfoStreamId);
    83 
    73 
    84 	#ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
    85 	User::LeaveIfError(iIdentityId.Attach(	AuthServer::KAuthServerSecureId,
       
    86 											AuthServer::KUidAuthServerAuthChangeEvent));
       
    87 	#else
       
    88 	iPassStreamId = (TStreamId) lookupStream.ReadUint32L();
    74 	iPassStreamId = (TStreamId) lookupStream.ReadUint32L();
    89 	iTimeoutStreamId = (TStreamId) lookupStream.ReadUint32L();
    75 	iTimeoutStreamId = (TStreamId) lookupStream.ReadUint32L();
    90 	#endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
    91 
    76 
    92 	TInt count = lookupStream.ReadInt32L();
    77 	TInt count = lookupStream.ReadInt32L();
    93 	for (TInt index = 0; index < count; index++)
    78 	for (TInt index = 0; index < count; index++)
    94 		{
    79 		{
    95 		CFileKeyData* keyData = CFileKeyData::NewL(lookupStream);
    80 		CFileKeyData* keyData = CFileKeyData::NewL(lookupStream);
   101 		iKeys.AppendL(keyData);
    86 		iKeys.AppendL(keyData);
   102 		CleanupStack::Pop(keyData);
    87 		CleanupStack::Pop(keyData);
   103 		}
    88 		}
   104 	
    89 	
   105 	CleanupStack::PopAndDestroy(&lookupStream);
    90 	CleanupStack::PopAndDestroy(&lookupStream);
   106 
       
   107 #ifndef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   108 	ReadPassphraseTimeoutL();
    91 	ReadPassphraseTimeoutL();
   109 #endif //SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   110 	
       
   111 	}
    92 	}
   112 
    93 
   113 CPassphraseManager* CFileKeyDataManager::CreatePassphraseManagerLC()
    94 CPassphraseManager* CFileKeyDataManager::CreatePassphraseManagerLC()
   114 	{
    95 	{
   115 	CPassphraseManager* result = CPassphraseManager::NewL(*iFileStore);
    96 	CPassphraseManager* result = CPassphraseManager::NewL(*iFileStore);
   184 	iFileStore->SetTypeL(KPermanentFileStoreLayoutUid);
   165 	iFileStore->SetTypeL(KPermanentFileStoreLayoutUid);
   185 
   166 
   186 	TCleanupItem cleanupStore(RevertStore, iFileStore);
   167 	TCleanupItem cleanupStore(RevertStore, iFileStore);
   187 	CleanupStack::PushL(cleanupStore);
   168 	CleanupStack::PushL(cleanupStore);
   188 	
   169 	
   189 #ifndef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   190 	// Create timeout stream with default timeout
   170 	// Create timeout stream with default timeout
   191 	RStoreWriteStream timeoutStream;
   171 	RStoreWriteStream timeoutStream;
   192 	iTimeoutStreamId = timeoutStream.CreateLC(*iFileStore);
   172 	iTimeoutStreamId = timeoutStream.CreateLC(*iFileStore);
   193 	timeoutStream.WriteUint32L(KDefaultPassphraseTimeout);
   173 	timeoutStream.WriteUint32L(KDefaultPassphraseTimeout);
   194 	timeoutStream.CommitL();
   174 	timeoutStream.CommitL();
   195 	CleanupStack::PopAndDestroy(&timeoutStream);
   175 	CleanupStack::PopAndDestroy(&timeoutStream);
   196 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   197 	
   176 	
   198 	// Create info stream - Currently no passphrase created, and no keys
   177 	// Create info stream - Currently no passphrase created, and no keys
   199 	RStoreWriteStream infoStream;
   178 	RStoreWriteStream infoStream;
   200 	iInfoStreamId = infoStream.CreateLC(*iFileStore);
   179 	iInfoStreamId = infoStream.CreateLC(*iFileStore);
   201 	
   180 	
   202 #ifndef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   203 	infoStream.WriteUint32L(KNullStreamId.Value());
   181 	infoStream.WriteUint32L(KNullStreamId.Value());
   204 	infoStream.WriteUint32L(iTimeoutStreamId.Value());
   182 	infoStream.WriteUint32L(iTimeoutStreamId.Value());
   205 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   206 	
   183 	
   207 	infoStream.WriteUint32L(0); // Write key count of zero
   184 	infoStream.WriteUint32L(0); // Write key count of zero
   208 	infoStream.CommitL();
   185 	infoStream.CommitL();
   209 	CleanupStack::PopAndDestroy(&infoStream);
   186 	CleanupStack::PopAndDestroy(&infoStream);
   210 
   187 
   262 void CFileKeyDataManager::WriteKeysToStoreL()
   239 void CFileKeyDataManager::WriteKeysToStoreL()
   263 	{
   240 	{
   264 	RStoreWriteStream lookupStream;
   241 	RStoreWriteStream lookupStream;
   265 	lookupStream.ReplaceLC(*iFileStore, iInfoStreamId);
   242 	lookupStream.ReplaceLC(*iFileStore, iInfoStreamId);
   266 
   243 
   267 	#ifndef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
   244 	lookupStream.WriteUint32L(iPassStreamId.Value());
   268 		lookupStream.WriteUint32L(iPassStreamId.Value());
   245 	lookupStream.WriteUint32L(iTimeoutStreamId.Value());
   269 		lookupStream.WriteUint32L(iTimeoutStreamId.Value());
   246 
   270 	#endif //SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   271 	
   247 	
   272 	TInt keyCount = iKeys.Count();
   248 	TInt keyCount = iKeys.Count();
   273 	lookupStream.WriteInt32L(keyCount);
   249 	lookupStream.WriteInt32L(keyCount);
   274 
   250 
   275 	for (TInt index = 0; index < keyCount; index++)
   251 	for (TInt index = 0; index < keyCount; index++)
   287  * and private key) have already been written.
   263  * and private key) have already been written.
   288  */
   264  */
   289 void CFileKeyDataManager::AddL(const CFileKeyData* aKeyData)
   265 void CFileKeyDataManager::AddL(const CFileKeyData* aKeyData)
   290 	{
   266 	{
   291 	ASSERT(aKeyData);
   267 	ASSERT(aKeyData);
   292 #ifndef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
   268 	ASSERT(aKeyData->PassphraseStreamId() != KNullStreamId);
   293 		ASSERT(aKeyData->PassphraseStreamId() != KNullStreamId);
       
   294 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   295 
   269 
   296 	// Add the key to to the array, rewrite the infostream and 
   270 	// Add the key to to the array, rewrite the infostream and 
   297 	// ONLY THEN commit the store
   271 	// ONLY THEN commit the store
   298 	User::LeaveIfError(iKeys.Append(aKeyData));
   272 	User::LeaveIfError(iKeys.Append(aKeyData));
   299 
       
   300 #ifndef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   301 	TStreamId oldDefaultPassphraseId;
   273 	TStreamId oldDefaultPassphraseId;
   302 
   274 
   303 	// Set the default passphrase id if this is the first key
   275 	// Set the default passphrase id if this is the first key
   304 	oldDefaultPassphraseId = iPassStreamId;
   276 	oldDefaultPassphraseId = iPassStreamId;
   305 	if (iKeys.Count() == 1)
   277 	if (iKeys.Count() == 1)
   306 		{
   278 		{
   307 		iPassStreamId = aKeyData->PassphraseStreamId();
   279 		iPassStreamId = aKeyData->PassphraseStreamId();
   308 		}
   280 		}
   309 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   310 	
   281 	
   311 	TRAPD(err,UpdateStoreL());
   282 	TRAPD(err,UpdateStoreL());
   312 	
   283 	
   313 	if (err != KErrNone)
   284 	if (err != KErrNone)
   314 		{
   285 		{
   315 		iKeys.Remove(iKeys.Count() - 1);
   286 		iKeys.Remove(iKeys.Count() - 1);
   316 		#ifndef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
   287 		iPassStreamId = oldDefaultPassphraseId;
   317 			iPassStreamId = oldDefaultPassphraseId;
       
   318 		#endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   319 		User::Leave(err);
   288 		User::Leave(err);
   320 		}
   289 		}
   321 	}
   290 	}
   322 
   291 
   323 void CFileKeyDataManager::UpdateStoreL()
   292 void CFileKeyDataManager::UpdateStoreL()
   361 
   330 
   362 	iFileStore->DeleteL(key->PrivateDataStreamId());
   331 	iFileStore->DeleteL(key->PrivateDataStreamId());
   363 	iFileStore->DeleteL(key->PublicDataStreamId());
   332 	iFileStore->DeleteL(key->PublicDataStreamId());
   364 	iFileStore->DeleteL(key->InfoDataStreamId());
   333 	iFileStore->DeleteL(key->InfoDataStreamId());
   365 
   334 
   366 #ifndef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   367 	// Remove the passphrase if it's the last key
   335 	// Remove the passphrase if it's the last key
   368 	TStreamId oldPassphraseId = iPassStreamId;
   336 	TStreamId oldPassphraseId = iPassStreamId;
   369 	if (Count() == 1)
   337 	if (Count() == 1)
   370 		{
   338 		{
   371 		iFileStore->DeleteL(iPassStreamId);
   339 		iFileStore->DeleteL(iPassStreamId);
   372 		iPassStreamId = KNullStreamId;
   340 		iPassStreamId = KNullStreamId;
   373 		}
   341 		}
   374 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   375 	
   342 	
   376 	// Remove the key
   343 	// Remove the key
   377 	iKeys.Remove(index);
   344 	iKeys.Remove(index);
   378 	
   345 	
   379 	TRAPD(res, WriteKeysToStoreL());
   346 	TRAPD(res, WriteKeysToStoreL());
   380 
   347 
   381 	if (res != KErrNone)
   348 	if (res != KErrNone)
   382 		{
   349 		{
   383 #ifndef SYMBIAN_KEYSTORE_USE_AUTH_SERVER		
       
   384 		iPassStreamId = oldPassphraseId;
   350 		iPassStreamId = oldPassphraseId;
   385 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
   351 
   386 		User::LeaveIfError(iKeys.Append(key)); // Put it back, shouldn't leave
   352 		User::LeaveIfError(iKeys.Append(key)); // Put it back, shouldn't leave
   387 		User::Leave(res);
   353 		User::Leave(res);
   388 		}
   354 		}
   389 	else 
   355 	else 
   390 		{
   356 		{
   394 
   360 
   395 	CleanupStack::Pop(); // cleanupStore
   361 	CleanupStack::Pop(); // cleanupStore
   396 	CompactStore();
   362 	CompactStore();
   397 }
   363 }
   398 
   364 
   399 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   400 TBool CFileKeyDataManager::IsKeyAlreadyInStore(const TDesC& aKeyLabel, AuthServer::TIdentityId aIdentity) const
       
   401 	{//	Check each key in the store to determine if aKeyLabel already exists
       
   402 	TInt keyCount = iKeys.Count();
       
   403 	TBool isInStore = EFalse;
       
   404 	for (TInt index = 0; index < keyCount; ++index)
       
   405 		{
       
   406 		const TDesC& keyLabel = iKeys[index]->Label();
       
   407 		if (keyLabel.Compare(aKeyLabel)==0 && (iKeys[index]->Identity() == aIdentity))
       
   408 			{
       
   409 			isInStore = ETrue;
       
   410 			break;
       
   411 			}
       
   412 		}
       
   413 	return (isInStore);
       
   414 	}
       
   415 
       
   416 #else
       
   417 TBool CFileKeyDataManager::IsKeyAlreadyInStore(const TDesC& aKeyLabel) const
   365 TBool CFileKeyDataManager::IsKeyAlreadyInStore(const TDesC& aKeyLabel) const
   418 {//	Check each key in the store to determine if aKeyLabel already exists
   366 {//	Check each key in the store to determine if aKeyLabel already exists
   419 	TInt keyCount = iKeys.Count();
   367 	TInt keyCount = iKeys.Count();
   420 	TBool isInStore = EFalse;
   368 	TBool isInStore = EFalse;
   421 	for (TInt index = 0; index < keyCount; index++)
   369 	for (TInt index = 0; index < keyCount; index++)
   429 	}
   377 	}
   430 
   378 
   431 	return (isInStore);
   379 	return (isInStore);
   432 }
   380 }
   433 
   381 
   434 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   435 
   382 
   436 TInt CFileKeyDataManager::Count() const
   383 TInt CFileKeyDataManager::Count() const
   437 	{
   384 	{
   438 	return iKeys.Count();
   385 	return iKeys.Count();
   439 	}	
   386 	}	
   458 
   405 
   459 //	*********************************************************************
   406 //	*********************************************************************
   460 //	Management of file and store therein
   407 //	Management of file and store therein
   461 //	*********************************************************************
   408 //	*********************************************************************
   462 
   409 
   463 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   464 
       
   465 const CFileKeyData* CFileKeyDataManager::CreateKeyDataLC(const TDesC& aLabel, AuthServer::TIdentityId aIdentityId)
       
   466 	{
       
   467 	TInt objectId = ++iKeyIdentifier;
       
   468 	TStreamId infoData = CreateWriteStreamL();
       
   469 	TStreamId publicKeyData = CreateWriteStreamL();
       
   470 	TStreamId privateKeyData = CreateWriteStreamL();
       
   471 	return CFileKeyData::NewLC(objectId, aLabel, infoData, publicKeyData, privateKeyData, aIdentityId);
       
   472 	}
       
   473 
       
   474 #else
       
   475 const CFileKeyData* CFileKeyDataManager::CreateKeyDataLC(const TDesC& aLabel, TStreamId aPassStreamId)
   410 const CFileKeyData* CFileKeyDataManager::CreateKeyDataLC(const TDesC& aLabel, TStreamId aPassStreamId)
   476 	{
   411 	{
   477 	ASSERT(aPassStreamId != KNullStreamId);
   412 	ASSERT(aPassStreamId != KNullStreamId);
   478 	TInt objectId = ++iKeyIdentifier;
   413 	TInt objectId = ++iKeyIdentifier;
   479 	TStreamId infoData = CreateWriteStreamL();
   414 	TStreamId infoData = CreateWriteStreamL();
   480 	TStreamId publicKeyData = CreateWriteStreamL();
   415 	TStreamId publicKeyData = CreateWriteStreamL();
   481 	TStreamId privateKeyData = CreateWriteStreamL();
   416 	TStreamId privateKeyData = CreateWriteStreamL();
   482 	return CFileKeyData::NewLC(objectId, aLabel, infoData, aPassStreamId, publicKeyData, privateKeyData);
   417 	return CFileKeyData::NewLC(objectId, aLabel, infoData, aPassStreamId, publicKeyData, privateKeyData);
   483 	}
   418 	}
   484 
   419 
   485 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   486 
   420 
   487 //	Creates a new write stream in the store (which it then closes)
   421 //	Creates a new write stream in the store (which it then closes)
   488 //	Returns the TStreamId associated with it
   422 //	Returns the TStreamId associated with it
   489 TStreamId CFileKeyDataManager::CreateWriteStreamL()
   423 TStreamId CFileKeyDataManager::CreateWriteStreamL()
   490 	{
   424 	{
   508 	__ASSERT_ALWAYS(iFileStore, PanicServer(EPanicStoreInitialised));
   442 	__ASSERT_ALWAYS(iFileStore, PanicServer(EPanicStoreInitialised));
   509 	RStoreReadStream stream;
   443 	RStoreReadStream stream;
   510 	stream.OpenLC(*iFileStore, aKeyData.InfoDataStreamId());
   444 	stream.OpenLC(*iFileStore, aKeyData.InfoDataStreamId());
   511 	CKeyInfo* info = CKeyInfo::NewL(stream);
   445 	CKeyInfo* info = CKeyInfo::NewL(stream);
   512 	
   446 	
   513 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   514 	ReadAuthDetailsL(stream, *info);
       
   515 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   516 	CleanupStack::PopAndDestroy(&stream);
   447 	CleanupStack::PopAndDestroy(&stream);
   517 	info->CleanupPushL();
   448 	info->CleanupPushL();
   518 	if (info->Handle() != aKeyData.Handle())
   449 	if (info->Handle() != aKeyData.Handle())
   519 		{
   450 		{
   520 		User::Leave(KErrCorrupt); // is this appropriate?
   451 		User::Leave(KErrCorrupt); // is this appropriate?
   525 void CFileKeyDataManager::WriteKeyInfoL(const CFileKeyData& aKeyData, const CKeyInfo& aKeyInfo)
   456 void CFileKeyDataManager::WriteKeyInfoL(const CFileKeyData& aKeyData, const CKeyInfo& aKeyInfo)
   526 	{
   457 	{
   527 	RStoreWriteStream infoStream;
   458 	RStoreWriteStream infoStream;
   528 	OpenInfoDataStreamLC(aKeyData, infoStream);
   459 	OpenInfoDataStreamLC(aKeyData, infoStream);
   529 	infoStream << aKeyInfo;
   460 	infoStream << aKeyInfo;
   530 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   531 	WriteAuthDetailsL(infoStream, aKeyInfo);
       
   532 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   533 	infoStream.CommitL();
   461 	infoStream.CommitL();
   534 	CleanupStack::PopAndDestroy(&infoStream);
   462 	CleanupStack::PopAndDestroy(&infoStream);
   535 	}
   463 	}
   536 
   464 
   537 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   538 void CFileKeyDataManager::WriteAuthDetailsL( RStoreWriteStream& aInfoStream, const CKeyInfo& aKeyInfo )
       
   539 	{
       
   540 	aInfoStream.WriteInt32L(aKeyInfo.Identity());
       
   541 	aInfoStream << aKeyInfo.AuthExpression();
       
   542   	aInfoStream.WriteInt32L(aKeyInfo.Freshness());
       
   543 	}
       
   544 
       
   545 void CFileKeyDataManager::ReadAuthDetailsL( RStoreReadStream& aInfoStream, CKeyInfo& aKeyInfo ) const
       
   546 	{
       
   547 	aKeyInfo.SetIdentity(aInfoStream.ReadInt32L());
       
   548 	HBufC* expression = HBufC::NewLC(aInfoStream, KMaxTInt);
       
   549 	aKeyInfo.SetAuthExpressionL(*expression);
       
   550 	aKeyInfo.SetFreshness(aInfoStream.ReadInt32L());
       
   551 	CleanupStack::PopAndDestroy(expression);
       
   552 	}
       
   553 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   554 
       
   555 void CFileKeyDataManager::SafeWriteKeyInfoL(const CFileKeyData& aKeyData, const CKeyInfo& aKeyInfo)
   465 void CFileKeyDataManager::SafeWriteKeyInfoL(const CFileKeyData& aKeyData, const CKeyInfo& aKeyInfo)
   556 	{
   466 	{
   557 	TCleanupItem cleanupStore(RevertStore, iFileStore);
   467 	TCleanupItem cleanupStore(RevertStore, iFileStore);
   558 	CleanupStack::PushL(cleanupStore);	
   468 	CleanupStack::PushL(cleanupStore);	
   559 
   469 
   579 	{
   489 	{
   580 	__ASSERT_ALWAYS(iFileStore, PanicServer(EPanicStoreInitialised));
   490 	__ASSERT_ALWAYS(iFileStore, PanicServer(EPanicStoreInitialised));
   581 	aStream.OpenLC(*iFileStore, aKeyData.PublicDataStreamId());
   491 	aStream.OpenLC(*iFileStore, aKeyData.PublicDataStreamId());
   582 	}
   492 	}
   583 
   493 
   584 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   585 
       
   586 void CFileKeyDataManager::OpenPrivateDataStreamLC(const CFileKeyData& aKeyData, RStoreWriteStream& aStream) 
       
   587 	{
       
   588 	__ASSERT_DEBUG(iFileStore, PanicServer(EPanicStoreInitialised));
       
   589 	aStream.ReplaceLC(*iFileStore, aKeyData.PrivateDataStreamId());
       
   590 	}
       
   591 
       
   592 void CFileKeyDataManager::OpenPrivateDataStreamLC(const CFileKeyData& aKeyData, RStoreReadStream& aStream) const
       
   593 	{
       
   594 	__ASSERT_DEBUG(iFileStore, PanicServer(EPanicStoreInitialised));
       
   595 	aStream.OpenLC(*iFileStore, aKeyData.PrivateDataStreamId());
       
   596 	}
       
   597 
       
   598 #else
       
   599 
       
   600 void CFileKeyDataManager::OpenPrivateDataStreamLC(const CFileKeyData& aKeyData, CPassphrase& aPassphrase,
   494 void CFileKeyDataManager::OpenPrivateDataStreamLC(const CFileKeyData& aKeyData, CPassphrase& aPassphrase,
   601 												  RStoreReadStream& aStream) 
   495 												  RStoreReadStream& aStream) 
   602 	{
   496 	{
   603 	__ASSERT_DEBUG(iFileStore, PanicServer(EPanicStoreInitialised));
   497 	__ASSERT_DEBUG(iFileStore, PanicServer(EPanicStoreInitialised));
   604 	aStream.OpenLC(aPassphrase.Store(), aKeyData.PrivateDataStreamId());
   498 	aStream.OpenLC(aPassphrase.Store(), aKeyData.PrivateDataStreamId());
   610 	__ASSERT_DEBUG(iFileStore, PanicServer(EPanicStoreInitialised));
   504 	__ASSERT_DEBUG(iFileStore, PanicServer(EPanicStoreInitialised));
   611 	aStream.ReplaceLC(aPassphrase.Store(), aKeyData.PrivateDataStreamId());
   505 	aStream.ReplaceLC(aPassphrase.Store(), aKeyData.PrivateDataStreamId());
   612 	}
   506 	}
   613 
   507 
   614 
   508 
   615 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   616 
       
   617 #ifndef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   618 TInt CFileKeyDataManager::GetPassphraseTimeout() const
   509 TInt CFileKeyDataManager::GetPassphraseTimeout() const
   619 	{
   510 	{
   620 	return iTimeout;
   511 	return iTimeout;
   621 	}
   512 	}
   622 
   513 
   658 	{
   549 	{
   659 	ASSERT((iPassStreamId == KNullStreamId) == (Count() == 0));
   550 	ASSERT((iPassStreamId == KNullStreamId) == (Count() == 0));
   660 	return iPassStreamId;
   551 	return iPassStreamId;
   661 	}
   552 	}
   662 
   553 
   663 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   664 
   554 
   665 /**
   555 /**
   666  * Attempt to compact the store - it doesn't matter if these calls leave, it
   556  * Attempt to compact the store - it doesn't matter if these calls leave, it
   667  * will only mean that the store takes up more space than necessary.
   557  * will only mean that the store takes up more space than necessary.
   668  */
   558  */
   670 	{
   560 	{
   671 	ASSERT(iFileStore);
   561 	ASSERT(iFileStore);
   672 	TRAP_IGNORE(iFileStore->ReclaimL(); iFileStore->CompactL());
   562 	TRAP_IGNORE(iFileStore->ReclaimL(); iFileStore->CompactL());
   673 	}
   563 	}
   674 
   564 
   675 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   676 TUint32 CFileKeyDataManager::CachedIdentity()
       
   677 	{
       
   678 	TInt value = 0;
       
   679 	iIdentityId.Get(value);
       
   680 	return value;
       
   681 	}
       
   682 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   683 
       
   684 // CFileKeyData ////////////////////////////////////////////////////////////////
   565 // CFileKeyData ////////////////////////////////////////////////////////////////
   685 
   566 
   686 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   687 CFileKeyData* CFileKeyData::NewLC(	TInt aObjectId, const TDesC& aLabel, TStreamId aInfoData,
       
   688 								  TStreamId aPublicData, TStreamId aPrivateData,
       
   689 								  AuthServer::TIdentityId aIdentityId)
       
   690 	{
       
   691 	CFileKeyData* self = new (ELeave) CFileKeyData(aObjectId, aInfoData, aPublicData, aPrivateData, aIdentityId);
       
   692 	CleanupStack::PushL(self);
       
   693 	self->ConstructL(aLabel);
       
   694 	return self;
       
   695 	}
       
   696 #else
       
   697 CFileKeyData* CFileKeyData::NewLC(TInt aObjectId, const TDesC& aLabel, TStreamId aInfoData,
   567 CFileKeyData* CFileKeyData::NewLC(TInt aObjectId, const TDesC& aLabel, TStreamId aInfoData,
   698 								  TStreamId aPassphraseId, TStreamId aPublicData, TStreamId aPrivateData)
   568 								  TStreamId aPassphraseId, TStreamId aPublicData, TStreamId aPrivateData)
   699 	{
   569 	{
   700 	CFileKeyData* self = new (ELeave) CFileKeyData(aObjectId, aInfoData, aPassphraseId, aPublicData, aPrivateData);
   570 	CFileKeyData* self = new (ELeave) CFileKeyData(aObjectId, aInfoData, aPassphraseId, aPublicData, aPrivateData);
   701 	CleanupStack::PushL(self);
   571 	CleanupStack::PushL(self);
   702 	self->ConstructL(aLabel);
   572 	self->ConstructL(aLabel);
   703 	return self;
   573 	return self;
   704 	}
   574 	}
   705 
   575 
   706 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   707 
   576 
   708 CFileKeyData* CFileKeyData::NewL(RStoreReadStream& aReadStream)
   577 CFileKeyData* CFileKeyData::NewL(RStoreReadStream& aReadStream)
   709 	{
   578 	{
   710 	CFileKeyData* self = new (ELeave) CFileKeyData();
   579 	CFileKeyData* self = new (ELeave) CFileKeyData();
   711 	CleanupStack::PushL(self);
   580 	CleanupStack::PushL(self);
   717 CFileKeyData::~CFileKeyData()
   586 CFileKeyData::~CFileKeyData()
   718 	{
   587 	{
   719 	delete iLabel;
   588 	delete iLabel;
   720 	}
   589 	}
   721 
   590 
   722 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   723 CFileKeyData::CFileKeyData(TInt aObjectId, TStreamId aInfoData,  
       
   724 						   TStreamId aPublicData, TStreamId aPrivateData,
       
   725 						   AuthServer::TIdentityId aIdentityId) :
       
   726 	iObjectId(aObjectId), iInfoData(aInfoData), 
       
   727 	iPublicKeyData(aPublicData), iPrivateKeyData(aPrivateData),
       
   728 	iIdentityId(aIdentityId)
       
   729 	{
       
   730 	ASSERT(iObjectId);
       
   731 	ASSERT(iInfoData != KNullStreamId);
       
   732 	ASSERT(iPublicKeyData != KNullStreamId);
       
   733 	ASSERT(iPrivateKeyData != KNullStreamId);
       
   734 	ASSERT(iIdentityId);
       
   735 	}
       
   736 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   737 #ifdef KEYTOOL
   591 #ifdef KEYTOOL
   738 CFileKeyData::CFileKeyData(TInt aObjectId, TStreamId aInfoData,  
   592 CFileKeyData::CFileKeyData(TInt aObjectId, TStreamId aInfoData,  
   739 						   TStreamId aPublicData, TStreamId aPrivateData,
   593 						   TStreamId aPublicData, TStreamId aPrivateData,
   740 						   AuthServer::TIdentityId aIdentityId) :
   594 						   AuthServer::TIdentityId aIdentityId) :
   741 	iObjectId(aObjectId), iInfoData(aInfoData), 
   595 	iObjectId(aObjectId), iInfoData(aInfoData), 
   777 
   631 
   778 void CFileKeyData::InternalizeL(RReadStream& aReadStream)
   632 void CFileKeyData::InternalizeL(RReadStream& aReadStream)
   779 {
   633 {
   780 	iObjectId = aReadStream.ReadInt32L();
   634 	iObjectId = aReadStream.ReadInt32L();
   781 	iInfoData.InternalizeL(aReadStream);
   635 	iInfoData.InternalizeL(aReadStream);
   782 #ifndef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   783 	iPassphraseId.InternalizeL(aReadStream);
   636 	iPassphraseId.InternalizeL(aReadStream);
   784 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   785 	iPublicKeyData.InternalizeL(aReadStream);
   637 	iPublicKeyData.InternalizeL(aReadStream);
   786 	iPrivateKeyData.InternalizeL(aReadStream);
   638 	iPrivateKeyData.InternalizeL(aReadStream);
   787 	
   639 	
   788 	TInt labelLen = aReadStream.ReadInt32L();
   640 	TInt labelLen = aReadStream.ReadInt32L();
   789 	iLabel = HBufC::NewMaxL(labelLen);
   641 	iLabel = HBufC::NewMaxL(labelLen);
   790 	TPtr theLabel((TUint16*)iLabel->Ptr(), labelLen, labelLen);
   642 	TPtr theLabel((TUint16*)iLabel->Ptr(), labelLen, labelLen);
   791 	theLabel.FillZ(labelLen);
   643 	theLabel.FillZ(labelLen);
   792 	aReadStream.ReadL(theLabel);
   644 	aReadStream.ReadL(theLabel);
   793 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   794 	iIdentityId = aReadStream.ReadInt32L();
       
   795 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   796 }
   645 }
   797 
   646 
   798 void CFileKeyData::ExternalizeL(RWriteStream& aWriteStream) const
   647 void CFileKeyData::ExternalizeL(RWriteStream& aWriteStream) const
   799 {
   648 {
   800 	aWriteStream.WriteInt32L(iObjectId);
   649 	aWriteStream.WriteInt32L(iObjectId);
   801 	iInfoData.ExternalizeL(aWriteStream);
   650 	iInfoData.ExternalizeL(aWriteStream);
   802 #ifndef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   803 	iPassphraseId.ExternalizeL(aWriteStream);
   651 	iPassphraseId.ExternalizeL(aWriteStream);
   804 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   805 	iPublicKeyData.ExternalizeL(aWriteStream);
   652 	iPublicKeyData.ExternalizeL(aWriteStream);
   806 	iPrivateKeyData.ExternalizeL(aWriteStream);
   653 	iPrivateKeyData.ExternalizeL(aWriteStream);
   807 
   654 
   808 	TInt labelLen = iLabel->Length();
   655 	TInt labelLen = iLabel->Length();
   809 	aWriteStream.WriteInt32L(labelLen);
   656 	aWriteStream.WriteInt32L(labelLen);
   810 	TPtr theLabel(iLabel->Des());
   657 	TPtr theLabel(iLabel->Des());
   811 	theLabel.SetLength(labelLen);
   658 	theLabel.SetLength(labelLen);
   812 	aWriteStream.WriteL(theLabel);
   659 	aWriteStream.WriteL(theLabel);
   813 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   814 	aWriteStream.WriteInt32L(iIdentityId);
       
   815 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   816 
       
   817 }
   660 }
   818 
   661 
   819 #ifdef KEYTOOL
   662 #ifdef KEYTOOL
   820 
   663 
   821 CFileKeyData* CFileKeyData::CreateOldKeyL(RStoreReadStream& aReadStream)
   664 CFileKeyData* CFileKeyData::CreateOldKeyL(RStoreReadStream& aReadStream)