diff -r 352850cbed81 -r 9f4e37332ce5 vpnengine/ikev1lib/src/ikev1trans.cpp --- a/vpnengine/ikev1lib/src/ikev1trans.cpp Mon Jun 21 16:49:56 2010 +0300 +++ b/vpnengine/ikev1lib/src/ikev1trans.cpp Thu Aug 19 10:54:34 2010 +0300 @@ -1,5 +1,5 @@ /* -* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). +* Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of "Eclipse Public License v1.0" @@ -36,11 +36,17 @@ #include "ikev1crack.h" #include "ikev1isakmpstream.h" #include "ikev1crypto.h" +#include "credentialcache.h" + const TUint8 XAUTH_VID_DATA[8] = {0x09, 0x00, 0x26, 0x89, 0xdf, 0xd6, 0xb7, 0x12}; const TUint8 CISCO_UNITY_VID_DATA[16] = {0x12, 0xf5, 0xf2, 0x8c, 0x45, 0x71, 0x68, 0xa9, 0x70, 0x2d, 0x9f, 0xe2, 0x74, 0xcc, 0x01, 0x00}; +const TInt KCredentialTypeUnknown = 0; +const TInt KCredentialTypeNew = 1; +const TInt KCredentialTypeCached = 2; + CTransNegotiation::CTransNegotiation( TInt aGranularity, TBool aUseXauth, @@ -93,8 +99,9 @@ delete iInternalAddr; delete iDialog; delete iDialogInfo; - delete iUserName; - + delete iUserName; + delete iCache; + for ( TInt i = 0; i < Count(); i++ ) { delete At(i); @@ -114,8 +121,7 @@ { User::Leave(KErrArgument); } - - DEBUG_LOG(_L("Transaction exchange object constructed")); + if ( !iUseXauth ) { iXauthCompleted = ETrue; @@ -126,7 +132,14 @@ if ( !iUseCfgMode ) iCfgModeCompleted = ETrue; DEBUG_LOG(_L("Starting to Wait XAUTH request")); - } + } + + if( EFalse != iPluginSession->IkeData().iUseCache ) + { + iCache = CCredentialCache::NewL( iDebug ); + } + + DEBUG_LOG(_L("Transaction exchange object constructed")); } /**------------------------------------------------------------------- @@ -283,7 +296,12 @@ iUserName = HBufC8::New(aDialogInfo->iUsername->Length() + 16); // 16 bytes space for padding if ( iUserName ) { iUserName->Des().Copy(aDialogInfo->iUsername->Des()); - } + } + + if( iCache && KCredentialTypeNew == iCredentialType ) + { + iCache->SetUserName( *aDialogInfo->iUsername ); + } } if ( aDialogInfo->iSecret ) { @@ -308,9 +326,12 @@ break; default: + if( iCache && KCredentialTypeNew == iCredentialType ) + { + iCache->SetSecret( *aDialogInfo->iSecret ); + } break; - - } + } AddAttributeData(attr_ptr, AttrType, aDialogInfo->iSecret->Length(), (TUint8*)aDialogInfo->iSecret->Ptr()); } @@ -800,9 +821,7 @@ // // User name/Password authentication required // - iDialog = CIkev1Dialog::NewL(iPluginSession, iPluginSession->DialogAnchor(), iDebug); - iDialogInfo = new(ELeave) CAuthDialogInfo(iPluginSession, XAUTH_DIALOG_ID, iNegotiation->SAId(), iCurrExchange->iMessageId); - iDialog->GetAsyncUNPWDialogL(iDialogInfo, (MIkeDialogComplete*)this); + GetCredentialsL(); break; case ( (1 << (ATTR_USER_NAME - ATTR_XAUTH_TYPE)) | (1 << (ATTR_PASSCODE - ATTR_XAUTH_TYPE))): @@ -841,7 +860,6 @@ } return status; - } /**------------------------------------------------------------------- @@ -856,12 +874,13 @@ TBuf8<16> attributes; TInt status = TRANSACTION_CONTINUE; TInt16 attr_status; - + while ( aLth > 0 ) { aLth = aLth - aAttr->Size(); if ( aLth < 0 ) { DEBUG_LOG(_L("XAUTH SET ERROR (Length mismatch in the attibutes)")); + iCredentialType = KCredentialTypeUnknown; return TRANSACTION_FAILED; } @@ -901,14 +920,19 @@ if ( status == TRANSACTION_SUCCESS ) { DEBUG_LOG(_L("XAUTH authentication succeeded!")); iXauthCompleted = ETrue; + + if( iCache && KCredentialTypeNew == iCredentialType ) + { + iCache->Store( iPluginSession->VpnIapId() ); + } + if ( iUserName ) { - // // Cache user name into user name file - // CIkev1Dialog* Dialog = CIkev1Dialog::NewL(iPluginSession, iPluginSession->DialogAnchor(), iDebug); CleanupStack::PushL(Dialog); TInt err(KErrNone); TRAP(err, Dialog->StoreUserNameL(iUserName->Des())); + #ifdef _DEBUG if (err == KErrNone) DEBUG_LOG(_L("User Name caching succeeded")); @@ -918,13 +942,16 @@ } } else { + if( iCache ) + { + iCache->Clear(); + } DEBUG_LOG(_L("XAUTH authentication failed!")); - // Dialog object shall be delete in Dialog->RunL when dialog completed - CIkev1Dialog* Dialog = CIkev1Dialog::NewL(iPluginSession, iPluginSession->DialogAnchor(), iDebug); - Dialog->ShowErrorDialogL(TVpnNoteDialog::EKmdAuthenticationFailed, NULL, NULL); } } - + + iCredentialType = KCredentialTypeUnknown; + return status; } @@ -980,7 +1007,6 @@ *--------------------------------------------------------------------*/ TInt CTransNegotiation::BuildConfigRequestL() { - TBuf8<16> attributes; TUint32 message_id = iNegotiation->RandomMessageId(); @@ -998,8 +1024,6 @@ DEBUG_LOG(_L("CONFIG-MODE started, request xmitted!")); return TRANSACTION_CONTINUE; - - } /**------------------------------------------------------------------- @@ -1114,8 +1138,8 @@ // // The implementation for class MIkeDialogComplete virtual function // -TInt CTransNegotiation::DialogCompleteL(CIkev1Dialog* /*aDialog*/, TAny* aUserInfo, - HBufC8* aUsername, HBufC8* aSecret, HBufC8* aDomain) +TInt CTransNegotiation::DialogCompleteL( + TAny* aUserInfo, HBufC8* aUsername, HBufC8* aSecret) { /*--------------------------------------------------------------------------- * @@ -1129,7 +1153,7 @@ *-------------------------------------------------------------------------*/ TUint32 obj_id = 1; CAuthDialogInfo* info = (CAuthDialogInfo*)aUserInfo; - DEBUG_LOG1(_L("CIKECRACKNegotiation::DialogCompleteL(), aUserInfo = %x"), aUserInfo); + DEBUG_LOG1(_L("CTransNegotiation::DialogCompleteL(), aUserInfo=%x"), aUserInfo); if ( info ) { @@ -1137,12 +1161,56 @@ DEBUG_LOG1(_L("Preparing to call AuthDialogCompletedL(), ObjId = %x"), obj_id); if ( obj_id == XAUTH_DIALOG_ID ) { - info->iUsername = aUsername; - info->iSecret = aSecret; - info->iDomain = aDomain; + info->SetUserName( aUsername ); + info->SetSecret( aSecret ); obj_id = info->PluginSession()->AuthDialogCompletedL(info); - } + } } return obj_id; } + + +void CTransNegotiation::GetCredentialsL() +{ + DEBUG_LOG( _L( "CTransNegotiation::GetCredentialsL" ) ); + + TInt ret = KErrNotFound; + + delete iDialogInfo; iDialogInfo = NULL; + + iDialogInfo = new (ELeave) CAuthDialogInfo( + iPluginSession, + XAUTH_DIALOG_ID, + iNegotiation->SAId(), + iCurrExchange->iMessageId ); + + if( iCache && KCredentialTypeUnknown == iCredentialType ) + { + ret = iCache->GetCredentials( + iPluginSession->VpnIapId(), + iDialogInfo->iUsername, + iDialogInfo->iSecret + ); + } + + if( KErrNone == ret ) + { + iCredentialType = KCredentialTypeCached; + TUint32 id = iPluginSession->AuthDialogCompletedL( iDialogInfo ); + } + else + { + iCredentialType = KCredentialTypeNew; + + delete iDialog; iDialog = NULL; + + iDialog = CIkev1Dialog::NewL( + iPluginSession, iPluginSession->DialogAnchor(), iDebug ); + + iDialog->GetAsyncUNPWDialogL( iDialogInfo, (MIkeDialogComplete*)this ); + } +} + + +/***/