multimediacommsengine/mmcesrv/mmcemediamanager/src/mcesecuredesstream.cpp
branchRCL_3
changeset 46 4da1f672912e
parent 45 3f7c7e6eea8a
equal deleted inserted replaced
45:3f7c7e6eea8a 46:4da1f672912e
    81 //
    81 //
    82 CMceSecureDesStream::CMceSecureDesStream(	CMceSecureMediaSession& aSecureSession,
    82 CMceSecureDesStream::CMceSecureDesStream(	CMceSecureMediaSession& aSecureSession,
    83 											CMccSecureInterface& aSecureInterface,
    83 											CMccSecureInterface& aSecureInterface,
    84         									CMceComMediaStream& aMediaStream
    84         									CMceComMediaStream& aMediaStream
    85         									):
    85         									):
    86 	
    86 	iWaitingBinding(EFalse),
    87 	iSecureSession(aSecureSession),
    87 	iSecureSession(aSecureSession),
    88 	iSecInf(aSecureInterface),
    88 	iSecInf(aSecureInterface),
    89 	iMediaStream(aMediaStream),
    89 	iMediaStream(aMediaStream),
    90 	iIsSAVP(ETrue),
    90 	iIsSAVP(ETrue),
    91 	iWaitingBinding(EFalse),
    91 	iRemoteChangeKey(EFalse),
    92 	iCryptoContextOutId(0),
    92 	iCryptoContextOutId(0),
    93 	iCryptoContextInId(0),
    93 	iCryptoContextInId(0),
    94 	iOldLocalMediaPort(0)
    94 	iOldLocalMediaPort(0)
    95 	{
    95 	{
    96 	
    96 	
   335     	{
   335     	{
   336     	SetMultipleClientCryptoL( *iCryptoIns );
   336     	SetMultipleClientCryptoL( *iCryptoIns );
   337     	MCEMM_DEBUG(" Set Multiple Client Cryptoto")
   337     	MCEMM_DEBUG(" Set Multiple Client Cryptoto")
   338     	User::LeaveIfError ( CountCryptoInOffer( aMediaField ) );
   338     	User::LeaveIfError ( CountCryptoInOffer( aMediaField ) );
   339     	Session().iIsSecureSession =  !iGnoreSdpMsg ? ETrue : EFalse;
   339     	Session().iIsSecureSession =  !iGnoreSdpMsg ? ETrue : EFalse;
       
   340     	if( iSecureSession.iNatBind )
       
   341     		{
       
   342 			SetCryptoContextL( ETrue );
       
   343 			iSecureSession.iNatBind = EFalse;
       
   344     		}
   340     	}
   345     	}
   341     MCEMM_DEBUG("CMceSecureDesStream::DecodeSecureSdpL(), Exit")      
   346     MCEMM_DEBUG("CMceSecureDesStream::DecodeSecureSdpL(), Exit")      
   342     MSG_IGNORE_RETURN()
   347     MSG_IGNORE_RETURN()
   343     }
   348     }
   344 
   349 
   375 				
   380 				
   376 				SetClientCryptoL( iCryptoIn );
   381 				SetClientCryptoL( iCryptoIn );
   377 				}
   382 				}
   378 			if ( iSecureSession.iLSReadyToBind )
   383 			if ( iSecureSession.iLSReadyToBind )
   379 				{
   384 				{
   380 				SetCryptoContextL();
   385 				SetCryptoContextL( EFalse );
       
   386 				iRemoteChangeKey = EFalse;
   381 				}
   387 				}
   382 			MSG_IGNORE_RETURN()
   388 			MSG_IGNORE_RETURN()
   383 			if ( !iCryptoIn.iCryptoSuite.Length() )
   389 			if ( !iCryptoIn.iCryptoSuite.Length() )
   384 				{
   390 				{
   385 				User::Leave( KErrArgument );
   391 				User::Leave( KErrArgument );
   436 // -----------------------------------------------------------------------------
   442 // -----------------------------------------------------------------------------
   437 // CMceSecureDesStream::SetCryptoContext( )
   443 // CMceSecureDesStream::SetCryptoContext( )
   438 // Sets crypto context to MCC
   444 // Sets crypto context to MCC
   439 // -----------------------------------------------------------------------------
   445 // -----------------------------------------------------------------------------
   440 //
   446 //
   441 void CMceSecureDesStream::SetCryptoContextL( )
   447 void CMceSecureDesStream::SetCryptoContextL( TBool aAnswer )
   442     {
   448     {
   443     MCEMM_DEBUG("SetCryptoContext(), Entry")   
   449     MCEMM_DEBUG("SetCryptoContext(), Entry") 
       
   450     TBool bindContext = ETrue;
   444     TBool storedIgnoreSdpMsg = EFalse;
   451     TBool storedIgnoreSdpMsg = EFalse;
   445     //Check state first if the crypto has been set
   452     //Check state first if the crypto has been set
   446     if ( !iCryptoIn.iIfCryptoContextIdSet && 
   453     if ( !iCryptoIn.iIfCryptoContextIdSet && 
   447     	!iCryptoOut.iIfCryptoContextIdSet &&
   454     	!iCryptoOut.iIfCryptoContextIdSet &&
   448     	iCryptoIn.iSetMasterKey.Length() && 
   455     	iCryptoIn.iSetMasterKey.Length() && 
   453     	MCEMM_DEBUG("First Time Bind")
   460     	MCEMM_DEBUG("First Time Bind")
   454     	CreateCryptoContextL( iCryptoIn );
   461     	CreateCryptoContextL( iCryptoIn );
   455     	CreateCryptoContextL( iCryptoOut ); 
   462     	CreateCryptoContextL( iCryptoOut ); 
   456     	MCEMM_DEBUG_DVALUE( "iCryptoContextOutId", iCryptoIn.iCryptoContextId )
   463     	MCEMM_DEBUG_DVALUE( "iCryptoContextOutId", iCryptoIn.iCryptoContextId )
   457 		MCEMM_DEBUG_DVALUE( "iCryptoContextInId", iCryptoOut.iCryptoContextId )
   464 		MCEMM_DEBUG_DVALUE( "iCryptoContextInId", iCryptoOut.iCryptoContextId )
       
   465     	
       
   466     	if( !aAnswer )
       
   467     		{
       
   468 			bindContext = EFalse;
       
   469     	    MCEMM_DEBUG("delay to bind!");
       
   470     		}
   458 
   471 
   459     	iCryptoOuts->Reset();
   472     	iCryptoOuts->Reset();
   460     	
   473     	
   461     
   474     
   462     	}
   475     	}
   471 			iCryptoIn.iCryptoContextId = iCryptoContextInId;
   484 			iCryptoIn.iCryptoContextId = iCryptoContextInId;
   472 			iCryptoOut.iCryptoContextId =  iCryptoContextOutId;
   485 			iCryptoOut.iCryptoContextId =  iCryptoContextOutId;
   473 			}
   486 			}
   474 		MCEMM_DEBUG_DVALUE( "Updated iCryptoContextOutId", iCryptoIn.iCryptoContextId )
   487 		MCEMM_DEBUG_DVALUE( "Updated iCryptoContextOutId", iCryptoIn.iCryptoContextId )
   475 		MCEMM_DEBUG_DVALUE( "Updated iCryptoContextInId", iCryptoOut.iCryptoContextId )
   488 		MCEMM_DEBUG_DVALUE( "Updated iCryptoContextInId", iCryptoOut.iCryptoContextId )
   476     	if ( iSecureSession.iKeyNeedUpdated )
   489     	if ( iSecureSession.iKeyNeedUpdated  || iRemoteChangeKey )
   477     		{
   490     		{
   478     		UpdateCryptoContextL( iCryptoIn ); 
   491     		UpdateCryptoContextL( iCryptoIn ); 
   479     		storedIgnoreSdpMsg = iGnoreSdpMsg;
   492     		storedIgnoreSdpMsg = iGnoreSdpMsg;
   480     		UpdateCryptoContextL( iCryptoOut ); 
   493     		UpdateCryptoContextL( iCryptoOut ); 
   481     		iGnoreSdpMsg = iGnoreSdpMsg && storedIgnoreSdpMsg;
   494     		iGnoreSdpMsg = iGnoreSdpMsg && storedIgnoreSdpMsg;
   487     	iCryptoOuts->Reset(); 
   500     	iCryptoOuts->Reset(); 
   488     	}
   501     	}
   489     iGnoreSdpMsg = (iCryptoIn.iIfCryptoContextIdSet && 
   502     iGnoreSdpMsg = (iCryptoIn.iIfCryptoContextIdSet && 
   490     				iCryptoOut.iIfCryptoContextIdSet ) &&
   503     				iCryptoOut.iIfCryptoContextIdSet ) &&
   491     				!iGnoreSdpMsg ? EFalse : ETrue;		
   504     				!iGnoreSdpMsg ? EFalse : ETrue;		
   492     if ( iWaitingBinding )
   505     if ( iWaitingBinding && bindContext )
   493     	{
   506     	{
   494     	iSecureSession.BindStreamCrypto();
   507     	iSecureSession.BindStreamCrypto();
   495     	}
   508     	}
   496     	
   509     	
   497     MCEMM_DEBUG("SetCryptoContext(), Exit")
   510     MCEMM_DEBUG("SetCryptoContext(), Exit")
   842         	MCEMM_DEBUG("GenerateRandomKeys Key is updated")
   855         	MCEMM_DEBUG("GenerateRandomKeys Key is updated")
   843         	iOldLocalMediaPort = iMediaStream.iLocalMediaPort;
   856         	iOldLocalMediaPort = iMediaStream.iLocalMediaPort;
   844         	}
   857         	}
   845         else
   858         else
   846         	{
   859         	{
       
   860 			if( iRemoteChangeKey )
       
   861 				{
       
   862 				MCEMM_DEBUG("Update CryptoIn" )
       
   863 				TBool tmpSet = iCryptoIn.iIfCryptoContextIdSet;
       
   864 				iCryptoIn.Copy( iCryptoIns->At( 0 ) );
       
   865 				iCryptoIn.iIfCryptoContextIdSet = tmpSet;
       
   866 				}
   847         	if(iOldLocalMediaPort != iMediaStream.iLocalMediaPort)
   867         	if(iOldLocalMediaPort != iMediaStream.iLocalMediaPort)
   848         		{
   868         		{
   849         	    GenerateRandomKeys( iCryptoOut );
   869         	    GenerateRandomKeys( iCryptoOut );
   850         	    MCEMM_DEBUG("GenerateRandomKeys Key is updated when oldport is different from newport")
   870         	    MCEMM_DEBUG("GenerateRandomKeys Key is updated when oldport is different from newport")
   851         	    iOldLocalMediaPort = iMediaStream.iLocalMediaPort;
   871         	    iOldLocalMediaPort = iMediaStream.iLocalMediaPort;
   855 		aResult.Append( KSpace );
   875 		aResult.Append( KSpace );
   856         GenerateCryptoSuiteLineL( aResult, iCryptoOut );
   876         GenerateCryptoSuiteLineL( aResult, iCryptoOut );
   857         MSG_IGNORE_RETURN()
   877         MSG_IGNORE_RETURN()
   858       	if ( iSecureSession.iLSReadyToBind )
   878       	if ( iSecureSession.iLSReadyToBind )
   859       		{
   879       		{
   860       		SetCryptoContextL();
   880       		SetCryptoContextL( ETrue );
       
   881       		iRemoteChangeKey = EFalse;
   861       		}
   882       		}
   862         MSG_IGNORE_RETURN()
   883         MSG_IGNORE_RETURN()
   863         }
   884         }
   864 	 else
   885 	 else
   865     	{
   886     	{
  1205 	        	{
  1226 	        	{
  1206 	        	keyInfoLen = aSecDec.Length()-keyInfoPos;
  1227 	        	keyInfoLen = aSecDec.Length()-keyInfoPos;
  1207 	        	}
  1228 	        	}
  1208     
  1229     
  1209 	    TPtrC8 keyInfo = aSecDec.Mid(keyInfoPos, keyInfoLen);
  1230 	    TPtrC8 keyInfo = aSecDec.Mid(keyInfoPos, keyInfoLen);
  1210 	    if ( iSecureSession.iKeyNeedUpdated )
       
  1211 	    	{
       
  1212 	    	
  1231 	    	
  1213 		    TBool valid = ValidateSecurityDescriptions( keyInfo );
  1232 	    	
  1214 	   		if ( valid )
  1233 		TBool valid = ValidateSecurityDescriptions( keyInfo );
       
  1234 		if ( valid )
       
  1235 	   		{
       
  1236 		    iRemoteChangeKey = iCryptoIn.iEncodedKey.Compare( keyInfo ) != 0;
       
  1237 	   		if( iSecureSession.iKeyNeedUpdated || iRemoteChangeKey ) 
  1215 	   			{
  1238 	   			{
  1216 	   			
       
  1217 		    	// check keyInfo 
  1239 		    	// check keyInfo 
  1218 			    if (iCryptoOut.iEncodedKey.Compare( keyInfo ) == 0)
  1240 			    if (iCryptoOut.iEncodedKey.Compare( keyInfo ) == 0)
  1219 			    	{
  1241 			    	{
  1220 			    	User::Leave( KErrArgument );
  1242 			    	User::Leave( KErrArgument );
  1221 			    	}
  1243 			    	}
  1225 				DecodeMKLifeTimeL( aSecDec, iCryptoIn );		
  1247 				DecodeMKLifeTimeL( aSecDec, iCryptoIn );		
  1226 					//check sessionparam later
  1248 					//check sessionparam later
  1227 				iCryptoIn.iEncodedKey = keyInfo;
  1249 				iCryptoIn.iEncodedKey = keyInfo;
  1228 				StoreKeys(iCryptoIn.iEncodedKey);
  1250 				StoreKeys(iCryptoIn.iEncodedKey);
  1229 	   			}
  1251 	   			}
  1230 	   		else
  1252 	   		}
  1231 	   			{
  1253 		else
  1232 	   			User::Leave( KErrArgument );
  1254 	   		{
  1233 	   			}
  1255 		    User::Leave( KErrArgument );
  1234 	    	}
  1256 	   		}
  1235 	   	}
  1257 	   	}
  1236  	else
  1258  	else
  1237  		{
  1259  		{
  1238  		User::Leave( KErrArgument );
  1260  		User::Leave( KErrArgument );
  1239  		}
  1261  		}
  1284         TPtrC8 keyInfo = aSecDec.Mid(keyInfoPos, keyInfoLen);
  1306         TPtrC8 keyInfo = aSecDec.Mid(keyInfoPos, keyInfoLen);
  1285         TBool valid = ValidateSecurityDescriptions( keyInfo );
  1307         TBool valid = ValidateSecurityDescriptions( keyInfo );
  1286         
  1308         
  1287         if ( valid )
  1309         if ( valid )
  1288         	{
  1310         	{
  1289         	
  1311         	if( !iSecureSession.iKeyNeedUpdated && 
       
  1312         			iCryptoIn.iEncodedKey.Compare( keyInfo ) != 0 )
       
  1313         		{
       
  1314         	    MCEMM_DEBUG("Remote change the key");
       
  1315         	    iRemoteChangeKey = ETrue;
       
  1316         		}
  1290             //check keyinfo mki 
  1317             //check keyinfo mki 
  1291 		     DecodeMKIValueL( aSecDec, EFalse, crypto );   
  1318 		     DecodeMKIValueL( aSecDec, EFalse, crypto );   
  1292 		     MSG_IGNORE_RETURN()
  1319 		     MSG_IGNORE_RETURN()
  1293 		     //set MKI value for our local crypto because all MKI in one crypto suite
  1320 		     //set MKI value for our local crypto because all MKI in one crypto suite
  1294 		     // should be the same
  1321 		     // should be the same