vpnengine/ikev1lib/src/ikev1trans.cpp
branchRCL_3
changeset 40 473321461bba
parent 38 9f4e37332ce5
child 41 e06095241a65
equal deleted inserted replaced
38:9f4e37332ce5 40:473321461bba
    34 #include "ikev1payload.h"
    34 #include "ikev1payload.h"
    35 #include "ikev1timeout.h"
    35 #include "ikev1timeout.h"
    36 #include "ikev1crack.h"
    36 #include "ikev1crack.h"
    37 #include "ikev1isakmpstream.h"
    37 #include "ikev1isakmpstream.h"
    38 #include "ikev1crypto.h"
    38 #include "ikev1crypto.h"
    39 #include "credentialcache.h"
       
    40 
       
    41 
    39 
    42 const TUint8  XAUTH_VID_DATA[8] = {0x09, 0x00, 0x26, 0x89, 0xdf, 0xd6, 0xb7, 0x12};
    40 const TUint8  XAUTH_VID_DATA[8] = {0x09, 0x00, 0x26, 0x89, 0xdf, 0xd6, 0xb7, 0x12};
    43 const TUint8  CISCO_UNITY_VID_DATA[16] = {0x12, 0xf5, 0xf2, 0x8c, 0x45, 0x71, 0x68, 0xa9,
    41 const TUint8  CISCO_UNITY_VID_DATA[16] = {0x12, 0xf5, 0xf2, 0x8c, 0x45, 0x71, 0x68, 0xa9,
    44                                           0x70, 0x2d, 0x9f, 0xe2, 0x74, 0xcc, 0x01, 0x00};
    42                                           0x70, 0x2d, 0x9f, 0xe2, 0x74, 0xcc, 0x01, 0x00};
    45                                           
    43                                           
    46 const TInt KCredentialTypeUnknown = 0;
       
    47 const TInt KCredentialTypeNew     = 1;
       
    48 const TInt KCredentialTypeCached  = 2;
       
    49 
       
    50                                           
    44                                           
    51 CTransNegotiation::CTransNegotiation( TInt aGranularity,
    45 CTransNegotiation::CTransNegotiation( TInt aGranularity,
    52                                       TBool aUseXauth,
    46                                       TBool aUseXauth,
    53                                       TBool aUseCfgMode, 
    47                                       TBool aUseCfgMode, 
    54                                       CIkev1PluginSession* aPluginSession,
    48                                       CIkev1PluginSession* aPluginSession,
    97     DEBUG_LOG(_L("Transaction exchange object deleted"));  
    91     DEBUG_LOG(_L("Transaction exchange object deleted"));  
    98         
    92         
    99     delete iInternalAddr;
    93     delete iInternalAddr;
   100     delete iDialog;
    94     delete iDialog;
   101     delete iDialogInfo;
    95     delete iDialogInfo;
   102 	delete iUserName;
    96 	delete iUserName; 	
   103 	delete iCache;
    97             
   104 
       
   105     for ( TInt i = 0; i < Count(); i++ )
    98     for ( TInt i = 0; i < Count(); i++ )
   106     {
    99     {
   107         delete At(i);
   100         delete At(i);
   108     }
   101     }
   109 }
   102 }
   119 {
   112 {
   120     if ( !iPluginSession || !iNegotiation || (!iUseXauth && !iUseCfgMode)) 
   113     if ( !iPluginSession || !iNegotiation || (!iUseXauth && !iUseCfgMode)) 
   121     {
   114     {
   122         User::Leave(KErrArgument);   
   115         User::Leave(KErrArgument);   
   123     }
   116     }
   124     
   117        
       
   118     DEBUG_LOG(_L("Transaction exchange object constructed"));  
   125     if ( !iUseXauth ) 
   119     if ( !iUseXauth ) 
   126     {
   120     {
   127        iXauthCompleted = ETrue;
   121        iXauthCompleted = ETrue;
   128        iNegotiation->iTimer->Cancel();  // Stop retransmission timer   
   122        iNegotiation->iTimer->Cancel();  // Stop retransmission timer   
   129     }
   123     }
   130     else 
   124     else 
   131     {
   125     {
   132        if ( !iUseCfgMode ) 
   126        if ( !iUseCfgMode ) 
   133            iCfgModeCompleted = ETrue;
   127            iCfgModeCompleted = ETrue;
   134        DEBUG_LOG(_L("Starting to Wait XAUTH request"));  
   128        DEBUG_LOG(_L("Starting to Wait XAUTH request"));  
   135     }
   129     }    
   136 
       
   137     if( EFalse != iPluginSession->IkeData().iUseCache )
       
   138     {
       
   139         iCache = CCredentialCache::NewL( iDebug );
       
   140     }
       
   141 
       
   142     DEBUG_LOG(_L("Transaction exchange object constructed"));  
       
   143 }
   130 }
   144 
   131 
   145 /**-------------------------------------------------------------------
   132 /**-------------------------------------------------------------------
   146  *
   133  *
   147  * Method GetAuthMethod()
   134  * Method GetAuthMethod()
   294 	      //
   281 	      //
   295 		  delete iUserName; // Delete old user name buffer for sure
   282 		  delete iUserName; // Delete old user name buffer for sure
   296   	      iUserName = HBufC8::New(aDialogInfo->iUsername->Length() + 16); // 16 bytes space for padding
   283   	      iUserName = HBufC8::New(aDialogInfo->iUsername->Length() + 16); // 16 bytes space for padding
   297 		  if ( iUserName ) {
   284 		  if ( iUserName ) {
   298 		     iUserName->Des().Copy(aDialogInfo->iUsername->Des()); 
   285 		     iUserName->Des().Copy(aDialogInfo->iUsername->Des()); 
   299 		  }
   286 		  } 	   
   300 		  
       
   301 		  if( iCache && KCredentialTypeNew == iCredentialType )
       
   302 		  {
       
   303 		      iCache->SetUserName( *aDialogInfo->iUsername );
       
   304 		  }
       
   305        }
   287        }
   306 
   288 
   307        if ( aDialogInfo->iSecret ) {
   289        if ( aDialogInfo->iSecret ) {
   308           //
   290           //
   309           // Add either password, passcode or next pin attribute.
   291           // Add either password, passcode or next pin attribute.
   324               case (1 << (ATTR_NEXT_PIN - ATTR_XAUTH_TYPE)):
   306               case (1 << (ATTR_NEXT_PIN - ATTR_XAUTH_TYPE)):
   325                   AttrType = ATTR_NEXT_PIN;
   307                   AttrType = ATTR_NEXT_PIN;
   326                   break;
   308                   break;
   327 
   309 
   328               default:
   310               default:
   329                   if( iCache && KCredentialTypeNew == iCredentialType )
       
   330                   {
       
   331                       iCache->SetSecret( *aDialogInfo->iSecret );
       
   332                   }
       
   333                   break;
   311                   break;
   334           }
   312                    
       
   313           }   
   335           AddAttributeData(attr_ptr, AttrType, aDialogInfo->iSecret->Length(),
   314           AddAttributeData(attr_ptr, AttrType, aDialogInfo->iSecret->Length(),
   336                           (TUint8*)aDialogInfo->iSecret->Ptr());           
   315                           (TUint8*)aDialogInfo->iSecret->Ptr());           
   337        }
   316        }
   338        
   317        
   339        BuildAndSendMessageL(attr_ptr, ISAKMP_CFG_REPLY);
   318        BuildAndSendMessageL(attr_ptr, ISAKMP_CFG_REPLY);
   694  *
   673  *
   695  *--------------------------------------------------------------------*/
   674  *--------------------------------------------------------------------*/
   696 TInt CTransNegotiation::ProcessXauthRequestL(TDataISAKMP* aAttr, TInt aLth)
   675 TInt CTransNegotiation::ProcessXauthRequestL(TDataISAKMP* aAttr, TInt aLth)
   697 {
   676 {
   698     TInt     status        = TRANSACTION_CONTINUE;
   677     TInt     status        = TRANSACTION_CONTINUE;
   699     TUint16  xauth_type    = ATTR_XAUTH_GENERIC;
       
   700     TUint32  request_flags = 0;
   678     TUint32  request_flags = 0;
   701     TPtr8    challenge(NULL, 0);
   679     TPtr8    challenge(NULL, 0);
   702 	TUint16  attr_type;
   680 	TUint16  attr_type;
   703 	
   681 	
   704     while ( aLth > 0 ) {
   682     while ( aLth > 0 ) {
   819 
   797 
   820         case ( (1 << (ATTR_USER_NAME - ATTR_XAUTH_TYPE)) | (1 << (ATTR_PASSWORD - ATTR_XAUTH_TYPE))):
   798         case ( (1 << (ATTR_USER_NAME - ATTR_XAUTH_TYPE)) | (1 << (ATTR_PASSWORD - ATTR_XAUTH_TYPE))):
   821             //
   799             //
   822             //  User name/Password authentication required
   800             //  User name/Password authentication required
   823             //
   801             //
   824 			GetCredentialsL();
   802 			iDialog     = CIkev1Dialog::NewL(iPluginSession, iPluginSession->DialogAnchor(), iDebug);			
       
   803             iDialogInfo = new(ELeave) CAuthDialogInfo(iPluginSession, XAUTH_DIALOG_ID, iNegotiation->SAId(), iCurrExchange->iMessageId);
       
   804             iDialog->GetAsyncUNPWDialogL(iDialogInfo, (MIkeDialogComplete*)this);          
   825             break;
   805             break;
   826 
   806 
   827         case ( (1 << (ATTR_USER_NAME - ATTR_XAUTH_TYPE)) | (1 << (ATTR_PASSCODE - ATTR_XAUTH_TYPE))):
   807         case ( (1 << (ATTR_USER_NAME - ATTR_XAUTH_TYPE)) | (1 << (ATTR_PASSCODE - ATTR_XAUTH_TYPE))):
   828             //
   808             //
   829             //  User name/Secure ID authentication required
   809             //  User name/Secure ID authentication required
   840 			iDialog     = CIkev1Dialog::NewL(iPluginSession, iPluginSession->DialogAnchor(), iDebug);			
   820 			iDialog     = CIkev1Dialog::NewL(iPluginSession, iPluginSession->DialogAnchor(), iDebug);			
   841 			iDialogInfo = new(ELeave) CAuthDialogInfo(iPluginSession, XAUTH_DIALOG_ID, iNegotiation->SAId(), iCurrExchange->iMessageId);
   821 			iDialogInfo = new(ELeave) CAuthDialogInfo(iPluginSession, XAUTH_DIALOG_ID, iNegotiation->SAId(), iCurrExchange->iMessageId);
   842             iDialog->GetAsyncSecureNextPinDialogL(iDialogInfo, (MIkeDialogComplete*)this);
   822             iDialog->GetAsyncSecureNextPinDialogL(iDialogInfo, (MIkeDialogComplete*)this);
   843             break;
   823             break;
   844 
   824 
   845         case ( (1 << (ATTR_CHALLENGE - ATTR_XAUTH_TYPE)) ):
       
   846             //
       
   847             //  User Challenge response dialog
       
   848             //
       
   849             if ( xauth_type == ATTR_XAUTH_RADIUS_CHAP )
       
   850 			{
       
   851 				iDialog     = CIkev1Dialog::NewL(iPluginSession, iPluginSession->DialogAnchor(), iDebug);			
       
   852 				iDialogInfo = new(ELeave) CAuthDialogInfo(iPluginSession, XAUTH_DIALOG_ID, iNegotiation->SAId(), iCurrExchange->iMessageId);
       
   853                 iDialog->GetAsyncRespDialog(challenge, iDialogInfo, (MIkeDialogComplete*)this);
       
   854             }   
       
   855             break;
       
   856 
       
   857         default:
   825         default:
   858             break;
   826             break;
   859 
   827 
   860     }   
   828     }   
   861     
   829     
   862     return status;
   830     return status;
       
   831 
   863 }
   832 }
   864 
   833 
   865 /**-------------------------------------------------------------------
   834 /**-------------------------------------------------------------------
   866  *
   835  *
   867  * Method ProcessXauthStatus()
   836  * Method ProcessXauthStatus()
   872 TInt CTransNegotiation::ProcessXauthStatusL(TDataISAKMP* aAttr, TInt aLth)
   841 TInt CTransNegotiation::ProcessXauthStatusL(TDataISAKMP* aAttr, TInt aLth)
   873 {
   842 {
   874     TBuf8<16> attributes;    
   843     TBuf8<16> attributes;    
   875     TInt      status = TRANSACTION_CONTINUE;
   844     TInt      status = TRANSACTION_CONTINUE;
   876     TInt16    attr_status;
   845     TInt16    attr_status;
   877 
   846     
   878     while ( aLth > 0 ) {
   847     while ( aLth > 0 ) {
   879         
   848         
   880         aLth = aLth - aAttr->Size();
   849         aLth = aLth - aAttr->Size();
   881         if ( aLth < 0 ) {
   850         if ( aLth < 0 ) {
   882            DEBUG_LOG(_L("XAUTH SET ERROR (Length mismatch in the attibutes)"));
   851            DEBUG_LOG(_L("XAUTH SET ERROR (Length mismatch in the attibutes)"));
   883            iCredentialType = KCredentialTypeUnknown;
       
   884            return TRANSACTION_FAILED;
   852            return TRANSACTION_FAILED;
   885         }
   853         }
   886 
   854 
   887         switch ( aAttr->Type() ) {
   855         switch ( aAttr->Type() ) {
   888 
   856 
   918        AddAttributeData(attributes, AttrType, 2, (TUint8*)&attr_status);
   886        AddAttributeData(attributes, AttrType, 2, (TUint8*)&attr_status);
   919        BuildAndSendMessageL(attributes, ISAKMP_CFG_ACK);
   887        BuildAndSendMessageL(attributes, ISAKMP_CFG_ACK);
   920        if ( status == TRANSACTION_SUCCESS ) {
   888        if ( status == TRANSACTION_SUCCESS ) {
   921           DEBUG_LOG(_L("XAUTH authentication succeeded!"));
   889           DEBUG_LOG(_L("XAUTH authentication succeeded!"));
   922           iXauthCompleted = ETrue;
   890           iXauthCompleted = ETrue;
   923 
       
   924           if( iCache && KCredentialTypeNew == iCredentialType )
       
   925           {
       
   926               iCache->Store( iPluginSession->VpnIapId() );
       
   927           }
       
   928 
       
   929 		  if ( iUserName ) {
   891 		  if ( iUserName ) {
       
   892 		     //
   930     		 // Cache user name into user name file
   893     		 // Cache user name into user name file
       
   894 			 //
   931 		     CIkev1Dialog* Dialog = CIkev1Dialog::NewL(iPluginSession, iPluginSession->DialogAnchor(), iDebug);
   895 		     CIkev1Dialog* Dialog = CIkev1Dialog::NewL(iPluginSession, iPluginSession->DialogAnchor(), iDebug);
   932              CleanupStack::PushL(Dialog);
   896              CleanupStack::PushL(Dialog);
   933 			 TInt err(KErrNone);
   897 			 TInt err(KErrNone);
   934 			 TRAP(err, Dialog->StoreUserNameL(iUserName->Des()));
   898 			 TRAP(err, Dialog->StoreUserNameL(iUserName->Des()));
   935 			 
       
   936 #ifdef _DEBUG			 
   899 #ifdef _DEBUG			 
   937 			 if (err == KErrNone)
   900 			 if (err == KErrNone)
   938 			     DEBUG_LOG(_L("User Name caching succeeded"));
   901 			     DEBUG_LOG(_L("User Name caching succeeded"));
   939 			 else DEBUG_LOG(_L("User Name caching failed"));
   902 			 else DEBUG_LOG(_L("User Name caching failed"));
   940 #endif // _DEBUG			 
   903 #endif // _DEBUG			 
   941 			 CleanupStack::PopAndDestroy();					 
   904 			 CleanupStack::PopAndDestroy();					 
   942 		  }	   
   905 		  }	   
   943        }            
   906        }            
   944        else {
   907        else {
   945           if( iCache )
       
   946           {
       
   947               iCache->Clear(); 
       
   948           }
       
   949           DEBUG_LOG(_L("XAUTH authentication failed!"));
   908           DEBUG_LOG(_L("XAUTH authentication failed!"));
       
   909 	   // Dialog object shall be delete in Dialog->RunL when dialog completed				  
       
   910           CIkev1Dialog* Dialog  = CIkev1Dialog::NewL(iPluginSession, iPluginSession->DialogAnchor(), iDebug);		  
       
   911           Dialog->ShowErrorDialogL(TVpnNoteDialog::EKmdAuthenticationFailed, NULL, NULL);
   950        }
   912        }
   951     }
   913     }
   952 
   914     
   953     iCredentialType = KCredentialTypeUnknown;
       
   954 
       
   955     return status;
   915     return status;
   956 }
   916 }
   957 
   917 
   958 /**--------------------------------------------------------------------------------
   918 /**--------------------------------------------------------------------------------
   959  *
   919  *
  1005  * -- DNS address(es) in secure network   = INTERNAL_IP4_DNS  
   965  * -- DNS address(es) in secure network   = INTERNAL_IP4_DNS  
  1006  *
   966  *
  1007  *--------------------------------------------------------------------*/
   967  *--------------------------------------------------------------------*/
  1008 TInt CTransNegotiation::BuildConfigRequestL()
   968 TInt CTransNegotiation::BuildConfigRequestL()
  1009 {
   969 {
       
   970 
  1010     TBuf8<16> attributes;
   971     TBuf8<16> attributes;
  1011     
   972     
  1012     TUint32  message_id = iNegotiation->RandomMessageId();
   973     TUint32  message_id = iNegotiation->RandomMessageId();
  1013 
   974 
  1014     iCurrExchange = AddExchangeL(message_id, INITIATOR); //Add a new transaction exchange
   975     iCurrExchange = AddExchangeL(message_id, INITIATOR); //Add a new transaction exchange
  1022 	
   983 	
  1023     BuildAndSendMessageL(attributes, ISAKMP_CFG_REQUEST);
   984     BuildAndSendMessageL(attributes, ISAKMP_CFG_REQUEST);
  1024     DEBUG_LOG(_L("CONFIG-MODE started, request xmitted!")); 
   985     DEBUG_LOG(_L("CONFIG-MODE started, request xmitted!")); 
  1025 
   986 
  1026     return TRANSACTION_CONTINUE;
   987     return TRANSACTION_CONTINUE;
       
   988 
       
   989     
  1027 }
   990 }
  1028 
   991 
  1029 /**-------------------------------------------------------------------
   992 /**-------------------------------------------------------------------
  1030  *
   993  *
  1031  * Method AddAttributeData()
   994  * Method AddAttributeData()
  1136 }
  1099 }
  1137 
  1100 
  1138 //
  1101 //
  1139 // The implementation for class MIkeDialogComplete virtual function
  1102 // The implementation for class MIkeDialogComplete virtual function
  1140 //
  1103 //
  1141 TInt CTransNegotiation::DialogCompleteL(
  1104 TInt CTransNegotiation::DialogCompleteL(CIkev1Dialog* /*aDialog*/, TAny* aUserInfo,
  1142     TAny* aUserInfo, HBufC8* aUsername, HBufC8* aSecret)
  1105 								        HBufC8* aUsername, HBufC8* aSecret, HBufC8* aDomain)
  1143 {
  1106 {
  1144 /*---------------------------------------------------------------------------
  1107 /*---------------------------------------------------------------------------
  1145  *  
  1108  *  
  1146  *  A response received from client user (through asynchronous dialog)
  1109  *  A response received from client user (through asynchronous dialog)
  1147  *  This method is introduced as a TUserCallback for CGetIKEPassword dialog
  1110  *  This method is introduced as a TUserCallback for CGetIKEPassword dialog
  1151  *  entry  
  1114  *  entry  
  1152  *  
  1115  *  
  1153  *-------------------------------------------------------------------------*/
  1116  *-------------------------------------------------------------------------*/
  1154 	TUint32 obj_id = 1;
  1117 	TUint32 obj_id = 1;
  1155 	CAuthDialogInfo* info = (CAuthDialogInfo*)aUserInfo;
  1118 	CAuthDialogInfo* info = (CAuthDialogInfo*)aUserInfo;
  1156 	DEBUG_LOG1(_L("CTransNegotiation::DialogCompleteL(), aUserInfo=%x"), aUserInfo);
  1119 	DEBUG_LOG1(_L("CIKECRACKNegotiation::DialogCompleteL(), aUserInfo =  %x"), aUserInfo);
  1157 
  1120 
  1158 	if ( info )
  1121 	if ( info )
  1159 	{
  1122 	{
  1160 		obj_id = info->GetObjId();
  1123 		obj_id = info->GetObjId();
  1161 		DEBUG_LOG1(_L("Preparing to call AuthDialogCompletedL(), ObjId = %x"), obj_id);
  1124 		DEBUG_LOG1(_L("Preparing to call AuthDialogCompletedL(), ObjId = %x"), obj_id);
  1162 		if ( obj_id == XAUTH_DIALOG_ID )
  1125 		if ( obj_id == XAUTH_DIALOG_ID )
  1163 		{
  1126 		{
  1164 			info->SetUserName( aUsername );
  1127 			info->iUsername = aUsername;
  1165 			info->SetSecret( aSecret );
  1128 			info->iSecret   = aSecret;
       
  1129 			info->iDomain   = aDomain;
  1166 			obj_id = info->PluginSession()->AuthDialogCompletedL(info);
  1130 			obj_id = info->PluginSession()->AuthDialogCompletedL(info);
  1167 		}
  1131 		}   
  1168 	}
  1132 	}
  1169 
  1133 
  1170 	return obj_id;
  1134 	return obj_id;
  1171 }
  1135 }
  1172 
       
  1173 
       
  1174 void CTransNegotiation::GetCredentialsL()
       
  1175 {
       
  1176     DEBUG_LOG( _L( "CTransNegotiation::GetCredentialsL" ) );
       
  1177 
       
  1178     TInt ret = KErrNotFound;
       
  1179 
       
  1180     delete iDialogInfo;  iDialogInfo = NULL;
       
  1181 
       
  1182     iDialogInfo = new (ELeave) CAuthDialogInfo(
       
  1183         iPluginSession,
       
  1184         XAUTH_DIALOG_ID,
       
  1185         iNegotiation->SAId(),
       
  1186         iCurrExchange->iMessageId );
       
  1187 
       
  1188     if( iCache && KCredentialTypeUnknown == iCredentialType )
       
  1189     {
       
  1190         ret = iCache->GetCredentials(
       
  1191             iPluginSession->VpnIapId(),
       
  1192             iDialogInfo->iUsername,
       
  1193             iDialogInfo->iSecret
       
  1194         );
       
  1195     }
       
  1196 
       
  1197     if( KErrNone == ret )
       
  1198     {
       
  1199         iCredentialType = KCredentialTypeCached;
       
  1200         TUint32 id = iPluginSession->AuthDialogCompletedL( iDialogInfo );
       
  1201     }
       
  1202     else
       
  1203     {
       
  1204         iCredentialType = KCredentialTypeNew;
       
  1205 
       
  1206         delete iDialog;  iDialog = NULL;
       
  1207 
       
  1208         iDialog = CIkev1Dialog::NewL(
       
  1209             iPluginSession, iPluginSession->DialogAnchor(), iDebug );
       
  1210 
       
  1211         iDialog->GetAsyncUNPWDialogL( iDialogInfo, (MIkeDialogComplete*)this );
       
  1212     }
       
  1213 }
       
  1214 
       
  1215 
       
  1216 /***/