cryptoservices/filebasedcertificateandkeystores/source/keystore/Server/Ckeystoreconduit.cpp
branchRCL_3
changeset 62 a71299154b21
parent 61 641f389e9157
equal deleted inserted replaced
61:641f389e9157 62:a71299154b21
    27 #include <pbedata.h>
    27 #include <pbedata.h>
    28 #include <mctkeystoremanager.h>
    28 #include <mctkeystoremanager.h>
    29 #include "cfskeystoreserver.h"
    29 #include "cfskeystoreserver.h"
    30 #include <mctkeystoreuids.h>
    30 #include <mctkeystoreuids.h>
    31 
    31 
    32 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
    33 #include <authserver/identity.h>
       
    34 #include <e32debug.h>
       
    35 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
    36 
       
    37 
    32 
    38 // CKeyStoreConduit ////////////////////////////////////////////////////////////
    33 // CKeyStoreConduit ////////////////////////////////////////////////////////////
    39 
    34 
    40 // can keep pointer to session as member
    35 // can keep pointer to session as member
    41 // also, do we need to pass the RMessage everywhere?
    36 // also, do we need to pass the RMessage everywhere?
   176 		DHAgreeL(aMessage, aSession);
   171 		DHAgreeL(aMessage, aSession);
   177 		break;
   172 		break;
   178    	case ECancelDH:
   173    	case ECancelDH:
   179 		CancelDH(aMessage, aSession);
   174 		CancelDH(aMessage, aSession);
   180 		break;	
   175 		break;	
   181 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
   176 
   182 
       
   183 	case ECreateUserKey:
       
   184 		CreateUserKeyL(aMessage);
       
   185 		break;
       
   186 	
       
   187 	case EImportUserKey:
       
   188 	case EImportEncryptedUserKey:
       
   189 		ImportUserKeyL(aMessage);
       
   190 		break;
       
   191 		
       
   192 	case ESetAuthenticationPolicy:
       
   193 		SetAuthenticationPolicyL(aMessage);
       
   194 		break;
       
   195 	
       
   196 	case EGetAuthenticationPolicy:
       
   197 		GetAuthenticationPolicyL(aMessage);
       
   198 		break;
       
   199 #else
       
   200 	case EChangePassphrase:
   177 	case EChangePassphrase:
   201 		ChangePassphrase(aMessage);
   178 		ChangePassphrase(aMessage);
   202 		break;
   179 		break;
   203 	case ECancelChangePassphrase:
   180 	case ECancelChangePassphrase:
   204 		CancelChangePassphrase(aMessage);
   181 		CancelChangePassphrase(aMessage);
   222 		GetTimeout(aMessage);
   199 		GetTimeout(aMessage);
   223 		break;
   200 		break;
   224 	case ERelock:
   201 	case ERelock:
   225 		Relock(aMessage);
   202 		Relock(aMessage);
   226 		break;	
   203 		break;	
   227 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
   204 	
   228 	
       
   229 #ifdef SYMBIAN_AUTH_SERVER
       
   230 	case EUseNewKeyServer:
       
   231 			IsKeyServerNewL(aMessage);
       
   232 			break;
       
   233 #endif // SYMBIAN_AUTH_SERVER
       
   234 			
       
   235 	default:	//	Should not reach here
   205 	default:	//	Should not reach here
   236 		PanicClient(aMessage,EPanicIllegalFunction);
   206 		PanicClient(aMessage,EPanicIllegalFunction);
   237 		break;
   207 		break;
   238 		}
   208 		}
   239 	}
   209 	}
   340 	iStatus = KRequestPending;
   310 	iStatus = KRequestPending;
   341 	SetActive();
   311 	SetActive();
   342 	iServer.CreateKey(*iKeyInfo, iStatus);
   312 	iServer.CreateKey(*iKeyInfo, iStatus);
   343 	}
   313 	}
   344 
   314 
   345 #ifdef SYMBIAN_AUTH_SERVER
       
   346 void CKeyStoreConduit::IsKeyServerNewL(const RMessage2& aMessage)
       
   347 	{
       
   348 	TBool newKeyServer = EFalse;
       
   349 	#ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   350 	newKeyServer = ETrue;
       
   351 	#endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   352 
       
   353 	TPckg<TBool> idNewKeyServer(newKeyServer);
       
   354 	aMessage.WriteL(1,idNewKeyServer);
       
   355 	aMessage.Complete(KErrNone);
       
   356 	}
       
   357 #endif // SYMBIAN_AUTH_SERVER
       
   358 
       
   359 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   360 
       
   361 void CKeyStoreConduit::CreateUserKeyL(const RMessage2& aMessage)
       
   362 	{
       
   363 	ASSERT(!iKeyInfo);
       
   364 		
       
   365 	//	p[0] has the length of the buffer. Check our buffer is big
       
   366 	//	enough, to cope with requests for keys with very long labels.
       
   367 
       
   368 	TInt bufLength = User::LeaveIfError(aMessage.GetDesLength(1));
       
   369 	iServer.CheckRangeL(bufLength);
       
   370 	
       
   371 	TInt authExprLength = User::LeaveIfError(aMessage.GetDesLength(2));
       
   372 	iServer.CheckRangeL(authExprLength);
       
   373 	HBufC* authExprBuf = HBufC::NewMaxLC(authExprLength);
       
   374 
       
   375 	//	p[2] has the authentication expression
       
   376 	TPtr authExprPtr(authExprBuf->Des());
       
   377 	authExprPtr.FillZ();
       
   378 	
       
   379 	aMessage.ReadL(2, authExprPtr);
       
   380 	
       
   381 	TInt freshness = aMessage.Int3();
       
   382 	
       
   383 	// the iKeyInfo buffer should be read at the last as in 
       
   384 	// case of OOM this memory would not get freed.
       
   385 	HBufC8* keyInfoBuf = HBufC8::NewMaxLC(bufLength);
       
   386 
       
   387 	//	p[1] has the CKeyInfo structure required to create a key
       
   388 	//	Read it and convert from descriptor back to a CKeyInfo
       
   389 	TPtr8 thePtr(keyInfoBuf->Des());
       
   390 	thePtr.FillZ();
       
   391 
       
   392 	aMessage.ReadL(1, thePtr);
       
   393 	TokenDataMarshaller::ReadL(*keyInfoBuf, iKeyInfo);
       
   394 	CleanupStack::PopAndDestroy(keyInfoBuf);
       
   395 			
       
   396 	iCurrentRequest.Set(ECreateUserKey, aMessage);
       
   397 	
       
   398 	SetActive();
       
   399 	iServer.CreateUserKey(*iKeyInfo, *authExprBuf, freshness, iStatus);
       
   400 	CleanupStack::PopAndDestroy(authExprBuf);
       
   401 	}
       
   402 
       
   403 void CKeyStoreConduit::ImportUserKeyL(const RMessage2& aMessage)
       
   404 	{
       
   405 	ASSERT(!iImportKey);
       
   406 	ASSERT(!iKeyInfo);
       
   407 	
       
   408 	// p[0] has the descriptor containing the PKCS8 object (may or may not be encrypted)
       
   409 	TInt keyLen = User::LeaveIfError(aMessage.GetDesLength(0));
       
   410 	iServer.CheckRangeL(keyLen);
       
   411 	
       
   412 	HBufC8* importBuf = HBufC8::NewMaxLC(keyLen);
       
   413 	TPtr8 theKeyData(importBuf->Des());
       
   414 	theKeyData.FillZ();
       
   415 	aMessage.ReadL(0, theKeyData);
       
   416 
       
   417 		
       
   418 	TInt bufLen = User::LeaveIfError(aMessage.GetDesLength(1));
       
   419 	iServer.CheckRangeL(bufLen);
       
   420 	
       
   421 	// retrieve the authentication expression
       
   422 	TInt authExprLength = User::LeaveIfError(aMessage.GetDesLength(2));
       
   423 	iServer.CheckRangeL(authExprLength);
       
   424 	HBufC* authExprBuf = HBufC::NewMaxLC(authExprLength);
       
   425 
       
   426 	//	p[2] has the authentication expression
       
   427 	TPtr authExprPtr(authExprBuf->Des());
       
   428 	authExprPtr.FillZ();
       
   429 	
       
   430 	aMessage.ReadL(2, authExprPtr);
       
   431 	
       
   432 	// retrieve the freshness value
       
   433 	TInt freshness = aMessage.Int3();
       
   434 	
       
   435 	HBufC8* keyInfoBuf = HBufC8::NewMaxLC(bufLen);
       
   436 
       
   437 	// p[1] has the CKeyInfo structure required to create a key
       
   438 	// Read it and convert from descriptor back to a CKeyInfo
       
   439 	TPtr8 thePtr(keyInfoBuf->Des());
       
   440 	thePtr.FillZ();
       
   441 	aMessage.ReadL(1, thePtr);
       
   442 
       
   443 	TokenDataMarshaller::ReadL(*keyInfoBuf, iKeyInfo);
       
   444 	CleanupStack::PopAndDestroy(keyInfoBuf);
       
   445 
       
   446 	iImportKey = importBuf;
       
   447 	iCurrentRequest.Set(static_cast<TFSTokenMessages>(aMessage.Function()), aMessage);
       
   448 	
       
   449 	TBool isEncrypted = (aMessage.Function() == EImportEncryptedUserKey);
       
   450 	SetActive();
       
   451 	iServer.ImportUserKey(*iImportKey, *iKeyInfo, isEncrypted, *authExprBuf, freshness, iStatus);
       
   452 	CleanupStack::PopAndDestroy(authExprBuf);
       
   453 	CleanupStack::Pop(importBuf);
       
   454 }
       
   455 
       
   456 void CKeyStoreConduit::SetAuthenticationPolicyL(const RMessage2& aMessage)
       
   457 	{
       
   458 	TInt objectId = aMessage.Int0();
       
   459 	
       
   460 	TInt authExprLen = User::LeaveIfError(aMessage.GetDesLength(1));
       
   461 	iServer.CheckRangeL(authExprLen);
       
   462 	HBufC* authExpr = HBufC::NewMaxLC(authExprLen);
       
   463 	TPtr authExprPtr(authExpr->Des());
       
   464 	authExprPtr.FillZ();
       
   465 	aMessage.ReadL(1, authExprPtr);
       
   466 
       
   467 	TInt freshness = aMessage.Int2();
       
   468 	iCurrentRequest.Set(ESetAuthenticationPolicy, aMessage);
       
   469 		
       
   470 	SetActive();
       
   471 	// ownership of authExpr is with the caller
       
   472 	iServer.SetAuthenticationPolicy(objectId, authExpr, freshness, iStatus);
       
   473 	CleanupStack::Pop(authExpr);
       
   474 	}
       
   475 
       
   476 void CKeyStoreConduit::GetAuthenticationPolicyL(const RMessage2& aMessage)
       
   477 	{
       
   478 	TInt objectId = aMessage.Int0();
       
   479 	HBufC* authExpression = iServer.AuthExpressionL(objectId);
       
   480 	CleanupStack::PushL(authExpression);
       
   481 	TInt freshness = iServer.FreshnessL(objectId);
       
   482 	TPckg<TInt> pckgFreshness(freshness); 
       
   483 	aMessage.WriteL(1, *authExpression);
       
   484 	aMessage.WriteL(2, pckgFreshness);
       
   485 	CleanupStack::PopAndDestroy(authExpression);
       
   486 	aMessage.Complete(KErrNone);
       
   487 	}
       
   488 
       
   489 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   490 
   315 
   491 void CKeyStoreConduit::CancelCreateKey(const RMessage2& aMessage)
   316 void CKeyStoreConduit::CancelCreateKey(const RMessage2& aMessage)
   492 	{
   317 	{
   493 	if (iCurrentRequest.OutstandingRequest() == ECreateKey)
   318 	if (iCurrentRequest.OutstandingRequest() == ECreateKey)
   494 		{
   319 		{
   908 	{
   733 	{
   909 	aSession.RemoveOpenedKeyL(aMessage.Int0());
   734 	aSession.RemoveOpenedKeyL(aMessage.Int0());
   910 	aMessage.Complete(KErrNone);
   735 	aMessage.Complete(KErrNone);
   911 	}
   736 	}
   912 
   737 
   913 #ifndef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   914 
       
   915 void CKeyStoreConduit::ChangePassphrase(const RMessage2& aMessage)
   738 void CKeyStoreConduit::ChangePassphrase(const RMessage2& aMessage)
   916 	{
   739 	{
   917 	iCurrentRequest.Set(EChangePassphrase, aMessage);
   740 	iCurrentRequest.Set(EChangePassphrase, aMessage);
   918 	iStatus=KRequestPending;
   741 	iStatus=KRequestPending;
   919 	SetActive();
   742 	SetActive();
   980 void CKeyStoreConduit::Relock(const RMessage2& aMessage)
   803 void CKeyStoreConduit::Relock(const RMessage2& aMessage)
   981 	{
   804 	{
   982 	iServer.Relock();
   805 	iServer.Relock();
   983 	aMessage.Complete(KErrNone);
   806 	aMessage.Complete(KErrNone);
   984 	}
   807 	}
   985 
       
   986 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
   987 
   808 
   988 //
   809 //
   989 //	CActive functions
   810 //	CActive functions
   990 //
   811 //
   991 void CKeyStoreConduit::DoCancel()
   812 void CKeyStoreConduit::DoCancel()
  1018 
   839 
  1019 		case EExportEncryptedKey:
   840 		case EExportEncryptedKey:
  1020 			iServer.CancelExportEncryptedKey();
   841 			iServer.CancelExportEncryptedKey();
  1021 			break;
   842 			break;
  1022 			
   843 			
  1023 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
  1024 		case ECreateUserKey:
       
  1025 			iServer.CancelCreateKey();
       
  1026 			break;
       
  1027 		case EImportUserKey:
       
  1028 		case EImportEncryptedUserKey:
       
  1029 			iServer.CancelImportKey();
       
  1030 #else
       
  1031 		case EChangePassphrase:
   844 		case EChangePassphrase:
  1032 			iServer.CancelChangePassphrase();
   845 			iServer.CancelChangePassphrase();
  1033 			break;
   846 			break;
  1034 
   847 
  1035 		case EAuthOpen:
   848 		case EAuthOpen:
  1036 			iServer.CancelAuthOpen();
   849 			iServer.CancelAuthOpen();
  1037 			break;
   850 			break;
  1038 
       
  1039 			
       
  1040 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
  1041 			
   851 			
  1042 		default:
   852 		default:
  1043 			// Nothing to do
   853 			// Nothing to do
  1044 			break;
   854 			break;
  1045 		}
   855 		}
  1058 	// Handle errors from server
   868 	// Handle errors from server
  1059 	User::LeaveIfError(iStatus.Int());
   869 	User::LeaveIfError(iStatus.Int());
  1060 
   870 
  1061 	switch (iCurrentRequest.OutstandingRequest())
   871 	switch (iCurrentRequest.OutstandingRequest())
  1062 		{
   872 		{
  1063 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
  1064 		case ESetAuthenticationPolicy:
       
  1065 			break;
       
  1066 		case ECreateUserKey:
       
  1067 		case EImportUserKey:
       
  1068 		case EImportEncryptedUserKey:
       
  1069 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER	
       
  1070 		case ECreateKey:
   873 		case ECreateKey:
  1071 		case EImportKey:
   874 		case EImportKey:
  1072 		case EImportEncryptedKey:
   875 		case EImportEncryptedKey:
  1073 			{
   876 			{
  1074 			//	Marshal TKeyUpdate to client - the client's buffer will be large
   877 			//	Marshal TKeyUpdate to client - the client's buffer will be large
  1142 			FinishDHPublicKeyL();
   945 			FinishDHPublicKeyL();
  1143 			break;
   946 			break;
  1144 		case EDHAgree:
   947 		case EDHAgree:
  1145 			FinishDHAgreeL();
   948 			FinishDHAgreeL();
  1146 			break;
   949 			break;
  1147 #ifndef SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
  1148 		case EChangePassphrase:
   950 		case EChangePassphrase:
  1149 		case EAuthOpen:
   951 		case EAuthOpen:
  1150 			// Nothing to do
   952 			// Nothing to do
  1151 			break;
   953 			break;	
  1152 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER
       
  1153 			
       
  1154 		default:
   954 		default:
  1155 			__ASSERT_DEBUG(EFalse, PanicServer(EPanicInvalidRequest));
   955 			__ASSERT_DEBUG(EFalse, PanicServer(EPanicInvalidRequest));
  1156 			User::Leave(KErrNotSupported);
   956 			User::Leave(KErrNotSupported);
  1157 		}
   957 		}
  1158 
   958