IMPSengine/engsrv/src/impsdigestbytes.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Class for imps digest.
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 #include <hash.h>
       
    20 #include <imcvcodc.h>
       
    21 #include "impsdigestbytes.h"
       
    22 #include "impskey.h"
       
    23 #include "impsdataaccessor.h"
       
    24 
       
    25 const TInt KDbLength = 200;     // 24
       
    26 const TInt KAolDbLength = 200;  // 32
       
    27 const TInt KMaxPwdLength = 50;
       
    28 const TInt KMaxKeyLength = 50;
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // ImpsDigestBytes::TImpsDigestBytes
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 TImpsDigestBytes::TImpsDigestBytes()
       
    35     {
       
    36     }
       
    37 // -----------------------------------------------------------------------------
       
    38 // ImpsDigestBytes::CreateDigestBytesL
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 void TImpsDigestBytes::CreateDigestBytesL ( MImpsDataAccessor* aAc,
       
    42                                             TImpsDigestSchema /*aSchema*/,
       
    43                                             const TDesC& aPassword,
       
    44                                             const TDesC8& aNonce )
       
    45     {
       
    46     TInt size = KMaxPwdLength + aNonce.Length();
       
    47     HBufC8* str = HBufC8::NewL( size );
       
    48     CleanupStack::PushL( str );  // <<< str
       
    49     TPtr8 strPtr = str->Des();
       
    50     strPtr.Append( aNonce );
       
    51     strPtr.Append( aPassword );
       
    52 
       
    53     CMD5* md5 = CMD5::NewL();
       
    54     CleanupStack::PushL( md5 );  // <<< md5
       
    55     TPtrC8 digestBytes = md5->Hash( *str );
       
    56 
       
    57     HBufC8* str2 = HBufC8::NewL( KDbLength );
       
    58     CleanupStack::PushL( str2 );  // <<< str2
       
    59     TPtr8 strPtr2 = str2->Des();
       
    60     TImCodecB64 codec;
       
    61     ( void )codec.Encode( digestBytes, strPtr2 );
       
    62     CImpsKey* myKey = CImpsKey::NewLC();  // <<< myKey
       
    63     myKey->AddL( CREATEKEY( EImpsKeySession, 0 ) );
       
    64     myKey->AddL( CREATEKEY( EImpsKeyTransaction, 0 ) );
       
    65     myKey->AddL( CREATEKEY( EImpsKeyTransactionContent, 0 ) );
       
    66     myKey->AddL( CREATEKEY( EImpsKeyLogin_Request, 0 ) );
       
    67     myKey->AddL( CREATEKEY( EImpsKeyDigestBytes, 0 ) );
       
    68     aAc->StoreDesc8L( myKey, strPtr2 );
       
    69 
       
    70     CleanupStack::PopAndDestroy( 4 );
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // ImpsDigestBytes::CreateAolDigestBytesL
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 void TImpsDigestBytes::CreateAolDigestBytesL ( MImpsDataAccessor* aAc,
       
    78                                                TImpsDigestSchema /*aSchema*/,
       
    79                                                const TDesC& aPassword,
       
    80                                                const TDesC8& aNonce,
       
    81                                                const TDesC& aClientId,
       
    82                                                HBufC* aKey1,
       
    83                                                HBufC* aKey2 )
       
    84     {
       
    85     // nonce, password, privateKey1
       
    86     TInt length = aNonce.Length() + KMaxPwdLength + KMaxKeyLength;
       
    87     HBufC8* str = HBufC8::NewL( length );
       
    88     CleanupStack::PushL( str );             // <<< str
       
    89     TPtr8 p1 = str->Des();
       
    90     p1.Append( aNonce );
       
    91     p1.Append( aPassword );
       
    92     p1.Append( aKey1->Des() );
       
    93     CMD5* md51 = CMD5::NewL();
       
    94     CleanupStack::PushL( md51 );             // <<< md51
       
    95     TPtrC8 bytes = md51->Hash( *str );
       
    96 
       
    97 
       
    98     HBufC8* digestBytes = HBufC8::NewL( KAolDbLength );
       
    99     CleanupStack::PushL( digestBytes );     // <<< digestBytes
       
   100     TPtr8 db = digestBytes->Des();
       
   101     db.Append( bytes );
       
   102 
       
   103     // nonce, normalized password, privateKey1
       
   104     HBufC8* pwd = HBufC8::NewL( KMaxPwdLength );
       
   105     CleanupStack::PushL( pwd );             // <<< pwd
       
   106     TPtr8 passw = pwd->Des();
       
   107     for ( TInt j = 0; j < aPassword.Length(); j++ )
       
   108         {
       
   109         passw.Append( TChar( aPassword[j] ) );
       
   110         }
       
   111     passw.TrimAll();
       
   112     for ( TInt k = 0; k < passw.Length(); k++ )
       
   113         {
       
   114         TChar in = passw[k];
       
   115         if ( in.IsSpace() )
       
   116             passw.Delete( k, 1 );
       
   117         }
       
   118     passw.LowerCase();
       
   119     HBufC8* str2 = HBufC8::NewL( length );
       
   120     CleanupStack::PushL( str2 );            // <<< str2
       
   121     TPtr8 p2 = str2->Des();
       
   122     p2.Append( aNonce );
       
   123     p2.Append( passw );
       
   124     p2.Append( aKey1->Des() );
       
   125     CMD5* md52 = CMD5::NewL();
       
   126     CleanupStack::PushL( md52 );             // <<< md52
       
   127     TPtrC8 bytes2 = md52->Hash( *str2 );
       
   128     db.Append( bytes2 );
       
   129 
       
   130     // nonce, clientId, privateKey2
       
   131     length = aNonce.Length() + KMaxPwdLength + KMaxKeyLength;
       
   132     HBufC8* str3 = HBufC8::NewL( length );
       
   133     CleanupStack::PushL( str3 );            // <<< str3
       
   134     TPtr8 p3 = str3->Des();
       
   135     p3.Append( aNonce );
       
   136     p3.Append( aClientId );
       
   137     p3.Append( aKey2->Des() );
       
   138     CMD5* md53 = CMD5::NewL();
       
   139     CleanupStack::PushL( md53 );             // <<< md53
       
   140     TPtrC8 bytes3 = md53->Hash( *str3 );
       
   141     db.Append( bytes3 );
       
   142 
       
   143     HBufC8* hex = HBufC8::NewL( KAolDbLength );
       
   144     CleanupStack::PushL( hex );     // <<< hex
       
   145     TPtr8 hexPtr = hex->Des();
       
   146     for ( TInt i = 0; i < db.Length(); i++ )
       
   147         {
       
   148         TChar in = db[i];
       
   149         hexPtr.AppendNumFixedWidth( in, EHex, 2 );
       
   150         }
       
   151     CImpsKey* myKey = CImpsKey::NewLC();    // <<< myKey
       
   152     myKey->AddL( CREATEKEY( EImpsKeySession, 0 ) );
       
   153     myKey->AddL( CREATEKEY( EImpsKeyTransaction, 0 ) );
       
   154     myKey->AddL( CREATEKEY( EImpsKeyTransactionContent, 0 ) );
       
   155     myKey->AddL( CREATEKEY( EImpsKeyLogin_Request, 0 ) );
       
   156     myKey->AddL( CREATEKEY( EImpsKeyDigestBytes, 0 ) );
       
   157     aAc->StoreDesc8L( myKey, hexPtr );
       
   158 
       
   159     CleanupStack::PopAndDestroy( 10 );
       
   160 
       
   161     }
       
   162 
       
   163 //  End of File
       
   164