multimediacommsengine/mmcesrv/mmcemediamanager/src/mcesecuredesstream.cpp
branchRCL_3
changeset 13 fb1bbf85a302
parent 12 91f50911ea81
child 19 3f7c7e6eea8a
equal deleted inserted replaced
12:91f50911ea81 13:fb1bbf85a302
    86 	iWaitingBinding(EFalse),
    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 	iRemoteChangeKey(EFalse),
    91 	iCryptoContextOutId(0),
    92 	iCryptoContextOutId(0),
    92 	iCryptoContextInId(0),
    93 	iCryptoContextInId(0),
    93 	iOldLocalMediaPort(0)
    94 	iOldLocalMediaPort(0)
    94 	{
    95 	{
    95 	
    96 	
   334     	{
   335     	{
   335     	SetMultipleClientCryptoL( *iCryptoIns );
   336     	SetMultipleClientCryptoL( *iCryptoIns );
   336     	MCEMM_DEBUG(" Set Multiple Client Cryptoto")
   337     	MCEMM_DEBUG(" Set Multiple Client Cryptoto")
   337     	User::LeaveIfError ( CountCryptoInOffer( aMediaField ) );
   338     	User::LeaveIfError ( CountCryptoInOffer( aMediaField ) );
   338     	Session().iIsSecureSession =  !iGnoreSdpMsg ? ETrue : EFalse;
   339     	Session().iIsSecureSession =  !iGnoreSdpMsg ? ETrue : EFalse;
       
   340     	if( iSecureSession.iNatBind )
       
   341     		{
       
   342 			SetCryptoContextL( ETrue );
       
   343 			iSecureSession.iNatBind = EFalse;
       
   344     		}
   339     	}
   345     	}
   340     MCEMM_DEBUG("CMceSecureDesStream::DecodeSecureSdpL(), Exit")      
   346     MCEMM_DEBUG("CMceSecureDesStream::DecodeSecureSdpL(), Exit")      
   341     MSG_IGNORE_RETURN()
   347     MSG_IGNORE_RETURN()
   342     }
   348     }
   343 
   349 
   374 				
   380 				
   375 				SetClientCryptoL( iCryptoIn );
   381 				SetClientCryptoL( iCryptoIn );
   376 				}
   382 				}
   377 			if ( iSecureSession.iLSReadyToBind )
   383 			if ( iSecureSession.iLSReadyToBind )
   378 				{
   384 				{
   379 				SetCryptoContextL();
   385 				SetCryptoContextL( EFalse );
       
   386 				iRemoteChangeKey = EFalse;
   380 				}
   387 				}
   381 			MSG_IGNORE_RETURN()
   388 			MSG_IGNORE_RETURN()
   382 			if ( !iCryptoIn.iCryptoSuite.Length() )
   389 			if ( !iCryptoIn.iCryptoSuite.Length() )
   383 				{
   390 				{
   384 				User::Leave( KErrArgument );
   391 				User::Leave( KErrArgument );
   435 // -----------------------------------------------------------------------------
   442 // -----------------------------------------------------------------------------
   436 // CMceSecureDesStream::SetCryptoContext( )
   443 // CMceSecureDesStream::SetCryptoContext( )
   437 // Sets crypto context to MCC
   444 // Sets crypto context to MCC
   438 // -----------------------------------------------------------------------------
   445 // -----------------------------------------------------------------------------
   439 //
   446 //
   440 void CMceSecureDesStream::SetCryptoContextL( )
   447 void CMceSecureDesStream::SetCryptoContextL( TBool aAnswer )
   441     {
   448     {
   442     MCEMM_DEBUG("SetCryptoContext(), Entry")   
   449     MCEMM_DEBUG("SetCryptoContext(), Entry") 
       
   450     TBool bindContext = ETrue;
   443     TBool storedIgnoreSdpMsg = EFalse;
   451     TBool storedIgnoreSdpMsg = EFalse;
   444     //Check state first if the crypto has been set
   452     //Check state first if the crypto has been set
   445     if ( !iCryptoIn.iIfCryptoContextIdSet && 
   453     if ( !iCryptoIn.iIfCryptoContextIdSet && 
   446     	!iCryptoOut.iIfCryptoContextIdSet &&
   454     	!iCryptoOut.iIfCryptoContextIdSet &&
   447     	iCryptoIn.iSetMasterKey.Length() && 
   455     	iCryptoIn.iSetMasterKey.Length() && 
   452     	MCEMM_DEBUG("First Time Bind")
   460     	MCEMM_DEBUG("First Time Bind")
   453     	CreateCryptoContextL( iCryptoIn );
   461     	CreateCryptoContextL( iCryptoIn );
   454     	CreateCryptoContextL( iCryptoOut ); 
   462     	CreateCryptoContextL( iCryptoOut ); 
   455     	MCEMM_DEBUG_DVALUE( "iCryptoContextOutId", iCryptoIn.iCryptoContextId )
   463     	MCEMM_DEBUG_DVALUE( "iCryptoContextOutId", iCryptoIn.iCryptoContextId )
   456 		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     		}
   457 
   471 
   458     	iCryptoOuts->Reset();
   472     	iCryptoOuts->Reset();
   459     	
   473     	
   460     
   474     
   461     	}
   475     	}
   470 			iCryptoIn.iCryptoContextId = iCryptoContextInId;
   484 			iCryptoIn.iCryptoContextId = iCryptoContextInId;
   471 			iCryptoOut.iCryptoContextId =  iCryptoContextOutId;
   485 			iCryptoOut.iCryptoContextId =  iCryptoContextOutId;
   472 			}
   486 			}
   473 		MCEMM_DEBUG_DVALUE( "Updated iCryptoContextOutId", iCryptoIn.iCryptoContextId )
   487 		MCEMM_DEBUG_DVALUE( "Updated iCryptoContextOutId", iCryptoIn.iCryptoContextId )
   474 		MCEMM_DEBUG_DVALUE( "Updated iCryptoContextInId", iCryptoOut.iCryptoContextId )
   488 		MCEMM_DEBUG_DVALUE( "Updated iCryptoContextInId", iCryptoOut.iCryptoContextId )
   475     	if ( iSecureSession.iKeyNeedUpdated )
   489     	if ( iSecureSession.iKeyNeedUpdated  || iRemoteChangeKey )
   476     		{
   490     		{
   477     		UpdateCryptoContextL( iCryptoIn ); 
   491     		UpdateCryptoContextL( iCryptoIn ); 
   478     		storedIgnoreSdpMsg = iGnoreSdpMsg;
   492     		storedIgnoreSdpMsg = iGnoreSdpMsg;
   479     		UpdateCryptoContextL( iCryptoOut ); 
   493     		UpdateCryptoContextL( iCryptoOut ); 
   480     		iGnoreSdpMsg = iGnoreSdpMsg && storedIgnoreSdpMsg;
   494     		iGnoreSdpMsg = iGnoreSdpMsg && storedIgnoreSdpMsg;
   486     	iCryptoOuts->Reset(); 
   500     	iCryptoOuts->Reset(); 
   487     	}
   501     	}
   488     iGnoreSdpMsg = (iCryptoIn.iIfCryptoContextIdSet && 
   502     iGnoreSdpMsg = (iCryptoIn.iIfCryptoContextIdSet && 
   489     				iCryptoOut.iIfCryptoContextIdSet ) &&
   503     				iCryptoOut.iIfCryptoContextIdSet ) &&
   490     				!iGnoreSdpMsg ? EFalse : ETrue;		
   504     				!iGnoreSdpMsg ? EFalse : ETrue;		
       
   505     if ( iWaitingBinding && bindContext )
       
   506     	{
       
   507     	iSecureSession.BindStreamCrypto();
       
   508     	}
   491     	
   509     	
   492     MCEMM_DEBUG("SetCryptoContext(), Exit")
   510     MCEMM_DEBUG("SetCryptoContext(), Exit")
   493     }
   511     }
   494 
   512 
   495 
   513 
   837         	MCEMM_DEBUG("GenerateRandomKeys Key is updated")
   855         	MCEMM_DEBUG("GenerateRandomKeys Key is updated")
   838         	iOldLocalMediaPort = iMediaStream.iLocalMediaPort;
   856         	iOldLocalMediaPort = iMediaStream.iLocalMediaPort;
   839         	}
   857         	}
   840         else
   858         else
   841         	{
   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 				}
   842         	if(iOldLocalMediaPort != iMediaStream.iLocalMediaPort)
   867         	if(iOldLocalMediaPort != iMediaStream.iLocalMediaPort)
   843         		{
   868         		{
   844         	    GenerateRandomKeys( iCryptoOut );
   869         	    GenerateRandomKeys( iCryptoOut );
   845         	    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")
   846         	    iOldLocalMediaPort = iMediaStream.iLocalMediaPort;
   871         	    iOldLocalMediaPort = iMediaStream.iLocalMediaPort;
   850 		aResult.Append( KSpace );
   875 		aResult.Append( KSpace );
   851         GenerateCryptoSuiteLineL( aResult, iCryptoOut );
   876         GenerateCryptoSuiteLineL( aResult, iCryptoOut );
   852         MSG_IGNORE_RETURN()
   877         MSG_IGNORE_RETURN()
   853       	if ( iSecureSession.iLSReadyToBind )
   878       	if ( iSecureSession.iLSReadyToBind )
   854       		{
   879       		{
   855       		SetCryptoContextL();
   880       		SetCryptoContextL( ETrue );
   856             if ( iWaitingBinding )
   881       		iRemoteChangeKey = EFalse;
   857                {
       
   858                iSecureSession.BindStreamCrypto();
       
   859                }
       
   860       		}
   882       		}
   861         MSG_IGNORE_RETURN()
   883         MSG_IGNORE_RETURN()
   862         }
   884         }
   863 	 else
   885 	 else
   864     	{
   886     	{
  1204 	        	{
  1226 	        	{
  1205 	        	keyInfoLen = aSecDec.Length()-keyInfoPos;
  1227 	        	keyInfoLen = aSecDec.Length()-keyInfoPos;
  1206 	        	}
  1228 	        	}
  1207     
  1229     
  1208 	    TPtrC8 keyInfo = aSecDec.Mid(keyInfoPos, keyInfoLen);
  1230 	    TPtrC8 keyInfo = aSecDec.Mid(keyInfoPos, keyInfoLen);
  1209 	    if ( iSecureSession.iKeyNeedUpdated )
       
  1210 	    	{
       
  1211 	    	
  1231 	    	
  1212 		    TBool valid = ValidateSecurityDescriptions( keyInfo );
  1232 	    	
  1213 	   		if ( valid )
  1233 		TBool valid = ValidateSecurityDescriptions( keyInfo );
       
  1234 		if ( valid )
       
  1235 	   		{
       
  1236 		    iRemoteChangeKey = iCryptoIn.iEncodedKey.Compare( keyInfo ) != 0;
       
  1237 	   		if( iSecureSession.iKeyNeedUpdated || iRemoteChangeKey ) 
  1214 	   			{
  1238 	   			{
  1215 	   			
       
  1216 		    	// check keyInfo 
  1239 		    	// check keyInfo 
  1217 			    if (iCryptoOut.iEncodedKey.Compare( keyInfo ) == 0)
  1240 			    if (iCryptoOut.iEncodedKey.Compare( keyInfo ) == 0)
  1218 			    	{
  1241 			    	{
  1219 			    	User::Leave( KErrArgument );
  1242 			    	User::Leave( KErrArgument );
  1220 			    	}
  1243 			    	}
  1224 				DecodeMKLifeTimeL( aSecDec, iCryptoIn );		
  1247 				DecodeMKLifeTimeL( aSecDec, iCryptoIn );		
  1225 					//check sessionparam later
  1248 					//check sessionparam later
  1226 				iCryptoIn.iEncodedKey = keyInfo;
  1249 				iCryptoIn.iEncodedKey = keyInfo;
  1227 				StoreKeys(iCryptoIn.iEncodedKey);
  1250 				StoreKeys(iCryptoIn.iEncodedKey);
  1228 	   			}
  1251 	   			}
  1229 	   		else
  1252 	   		}
  1230 	   			{
  1253 		else
  1231 	   			User::Leave( KErrArgument );
  1254 	   		{
  1232 	   			}
  1255 		    User::Leave( KErrArgument );
  1233 	    	}
  1256 	   		}
  1234 	   	}
  1257 	   	}
  1235  	else
  1258  	else
  1236  		{
  1259  		{
  1237  		User::Leave( KErrArgument );
  1260  		User::Leave( KErrArgument );
  1238  		}
  1261  		}
  1283         TPtrC8 keyInfo = aSecDec.Mid(keyInfoPos, keyInfoLen);
  1306         TPtrC8 keyInfo = aSecDec.Mid(keyInfoPos, keyInfoLen);
  1284         TBool valid = ValidateSecurityDescriptions( keyInfo );
  1307         TBool valid = ValidateSecurityDescriptions( keyInfo );
  1285         
  1308         
  1286         if ( valid )
  1309         if ( valid )
  1287         	{
  1310         	{
  1288         	
  1311         	if( !iSecureSession.iKeyNeedUpdated && 
       
  1312         			iCryptoIn.iEncodedKey.Compare( keyInfo ) != 0 )
       
  1313         		{
       
  1314         	    MCEMM_DEBUG("Remote change the key");
       
  1315         	    iRemoteChangeKey = ETrue;
       
  1316         		}
  1289             //check keyinfo mki 
  1317             //check keyinfo mki 
  1290 		     DecodeMKIValueL( aSecDec, EFalse, crypto );   
  1318 		     DecodeMKIValueL( aSecDec, EFalse, crypto );   
  1291 		     MSG_IGNORE_RETURN()
  1319 		     MSG_IGNORE_RETURN()
  1292 		     //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
  1293 		     // should be the same
  1321 		     // should be the same
  1487 		if ( cryptoOut.iTagLen == aCrypto.iTagLen &&
  1515 		if ( cryptoOut.iTagLen == aCrypto.iTagLen &&
  1488 			 cryptoOut.iEncAlgms == aCrypto.iEncAlgms &&
  1516 			 cryptoOut.iEncAlgms == aCrypto.iEncAlgms &&
  1489 			 cryptoOut.iAuthAlgms == aCrypto.iAuthAlgms &&
  1517 			 cryptoOut.iAuthAlgms == aCrypto.iAuthAlgms &&
  1490 			 cryptoOut.iCryptoSuite.Compare(aCrypto.iCryptoSuite) == 0)
  1518 			 cryptoOut.iCryptoSuite.Compare(aCrypto.iCryptoSuite) == 0)
  1491 			{
  1519 			{
  1492             if(!iCryptoOut.iIfCryptoContextIdSet)
  1520 			//SEtCrypto
  1493                 {  //SEtCrypto
  1521 			iCryptoOut.Copy( cryptoOut );
  1494                 iCryptoOut.Copy( cryptoOut );
       
  1495                 }
       
  1496 			iCryptoIn.iTag = cryptoOut.iTag;
  1522 			iCryptoIn.iTag = cryptoOut.iTag;
  1497 			iCryptoIn.iEncAlgms = cryptoOut.iEncAlgms;
  1523 			iCryptoIn.iEncAlgms = cryptoOut.iEncAlgms;
  1498 			iCryptoIn.iAuthAlgms = cryptoOut.iAuthAlgms;
  1524 			iCryptoIn.iAuthAlgms = cryptoOut.iAuthAlgms;
  1499 			iCryptoIn.iTagLen = cryptoOut.iTagLen;
  1525 			iCryptoIn.iTagLen = cryptoOut.iTagLen;
  1500 			iCryptoIn.iCryptoSuite = cryptoOut.iCryptoSuite ;
  1526 			iCryptoIn.iCryptoSuite = cryptoOut.iCryptoSuite ;
  1682 
  1708 
  1683 	for (TInt i = 0; i < aCopyFrom.iCryptoOuts->Count(); i++)
  1709 	for (TInt i = 0; i < aCopyFrom.iCryptoOuts->Count(); i++)
  1684 		{
  1710 		{
  1685 		iCryptoOuts->AppendL( aCopyFrom.iCryptoOuts->At( i ) );
  1711 		iCryptoOuts->AppendL( aCopyFrom.iCryptoOuts->At( i ) );
  1686 		}
  1712 		}
  1687     iOldLocalMediaPort = aCopyFrom.iOldLocalMediaPort;
  1713 		iOldLocalMediaPort = aCopyFrom.iOldLocalMediaPort;
  1688     iWaitingBinding = aCopyFrom.iWaitingBinding;
       
  1689  	MCEMM_DEBUG( "CMceSecureDesStream::CopyStreamCryptoL Exit" )
  1714  	MCEMM_DEBUG( "CMceSecureDesStream::CopyStreamCryptoL Exit" )
  1690 	}
  1715 	}
  1691 
  1716 
  1692 //-----------------------------------------------------------------------------
  1717 //-----------------------------------------------------------------------------
  1693 // CMceSecureDesStream::Session()
  1718 // CMceSecureDesStream::Session()