linklayerprotocols/pppnif/SPPP/chapmd5.cpp
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Authentication Protocol with MD5 (CHAP with MD5) - RFC 1994.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @brief Source file for the implementation of PPP Challenge Handshake
       
    21  @internalComponent
       
    22 */
       
    23 
       
    24 #include "chapmd5.h"
       
    25 // use CMD5
       
    26 #include <hash.h>
       
    27 #include "PPPConfig.h"
       
    28 
       
    29 CPppChapMd5::CPppChapMd5()
       
    30 /**
       
    31    Constructor. 
       
    32    @internalComponent
       
    33 */
       
    34 	{
       
    35 	}
       
    36 
       
    37 CPppChapMd5::~CPppChapMd5()
       
    38 /**
       
    39    Destructor.
       
    40    @internalComponent
       
    41 */
       
    42 	{
       
    43 #ifdef _UNICODE
       
    44 	delete iUserName;
       
    45 #endif
       
    46 
       
    47 	delete iMd5;
       
    48 	}
       
    49 
       
    50 
       
    51 void CPppChapMd5::InitL(CPppLcp* aLcp)
       
    52 /**
       
    53    @copydoc CPppChap::InitL(CPppLcp*)
       
    54    @see CPppChap::InitL(CPppLcp*)
       
    55    @internalComponent
       
    56 */
       
    57 	{
       
    58 	CPppChap::InitL(aLcp);
       
    59 	iMd5 = CMD5::NewL();
       
    60 	}
       
    61 
       
    62 
       
    63 void CPppChapMd5::MakeResponseL(TUint8 /*aChallengeId*/, 
       
    64 				const TDesC8& aChallengeValue, 
       
    65 				TPtrC8& aResponseValue, 
       
    66 				TPtrC8& aResponseName)
       
    67 /**
       
    68    @copydoc CPppChap::MakeResponseL(TUint8, const TDesC8&, TPtrC8&,
       
    69    TPtrC8&)
       
    70    @see CPppChap::MakeResponseL(TUint8, const TDesC8&, TPtrC8&,
       
    71    TPtrC8&)
       
    72    @internalComponent
       
    73 */
       
    74 	{
       
    75 	ASSERT(aChallengeValue.Length() >= KPppChapMinValueSize);
       
    76 
       
    77     const CCredentialsConfig* credentials = iPppLcp->GetCredentials();
       
    78 	const TDesC& username = credentials->GetUserName();
       
    79 
       
    80 	__ASSERT_ALWAYS(username.Length() <= 
       
    81 				KMaxTInt16 - 
       
    82 				KPppChapCodeFieldSize -
       
    83 				KPppChapIdFieldSize - 
       
    84 				KPppChapLengthFieldSize -
       
    85 				KPppChapValueSizeFieldSize -
       
    86 				aResponseValue.Length(), 
       
    87 			User::Leave(KErrTooBig));
       
    88 
       
    89 #ifdef _UNICODE
       
    90 	delete iUserName;
       
    91 	iUserName=0;
       
    92 	iUserName = HBufC8::NewL(username.Length());
       
    93 	iUserName->Des().Copy(username);
       
    94  	aResponseName.Set(*iUserName);
       
    95 
       
    96 	const TDesC& pwd=credentials->GetPassword();
       
    97 	HBufC8& password = *HBufC8::NewLC(pwd.Length());
       
    98  	password.Des().Copy(pwd);
       
    99 #else //! _UNICODE
       
   100 	aResponseName.Set(username);
       
   101 	const TDesC& password = credentials->GetPassword();
       
   102 #endif //! _UNICODE
       
   103 
       
   104 	iMd5->Update(TPtrC8(&iCurrentId, KPppChapIdFieldSize));
       
   105 	iMd5->Update(password);
       
   106 	aResponseValue.Set(iMd5->Final(aChallengeValue));
       
   107 
       
   108 #ifdef _UNICODE
       
   109 	CleanupStack::PopAndDestroy(&password);
       
   110 #endif // _UNICODE
       
   111 
       
   112 	ASSERT(aResponseValue.Length() == KPppChapMd5ValueSize);
       
   113 	ASSERT(aResponseName.Length() >= KPppChapMinNameSize &&
       
   114 		   aResponseName.Length() <= 
       
   115 		   KMaxTInt16 - 
       
   116 		   KPppChapCodeFieldSize -
       
   117 		   KPppChapIdFieldSize - 
       
   118 		   KPppChapLengthFieldSize -
       
   119 		   KPppChapValueSizeFieldSize -
       
   120 		   aResponseValue.Length());
       
   121 	}