omaprovisioning/pnputil/src/PnpUtilImpl.cpp
changeset 2 5594fba90824
parent 0 b497e44ab2fc
child 25 b183ec05bd8c
equal deleted inserted replaced
1:a9c0ce913924 2:5594fba90824
    33 // CONSTANTS
    33 // CONSTANTS
    34 
    34 
    35 const TInt KMaxModulusLength = 300;
    35 const TInt KMaxModulusLength = 300;
    36 const TInt KMaxPublicExponentLength = 10;
    36 const TInt KMaxPublicExponentLength = 10;
    37 
    37 
    38 _LIT8(K3DesKey, "111111111111111111111111");
       
    39 
       
    40 // Default token validity time
    38 // Default token validity time
    41 const TInt KTokenValidityTime = 600;
    39 const TInt KTokenValidityTime = 600;
    42 const TInt KTokenLength = 4;
    40 const TInt KTokenLength = 4;
    43 // C3DESEncryptor and C3DESDecryptor require the buffer to be more than 4 characters
    41 // C3DESEncryptor and C3DESDecryptor require the buffer to be more than 4 characters
    44 // (8 characters seems to be enough)
    42 // (8 characters seems to be enough)
    45 const TInt KTokenLengthDuringStorage = 8;
    43 const TInt KTokenLengthDuringStorage = 8;
       
    44 
       
    45 const TInt KEncryptionKeyLength = 24;
    46 
    46 
    47 // -----------------------------------------------------------------------------
    47 // -----------------------------------------------------------------------------
    48 // CPnpUtilImpl::ConstructL
    48 // CPnpUtilImpl::ConstructL
    49 // -----------------------------------------------------------------------------
    49 // -----------------------------------------------------------------------------
    50 //
    50 //
    62 
    62 
    63     LOGSTRING( "CPnpUtilImpl::ConstructL() 5" );
    63     LOGSTRING( "CPnpUtilImpl::ConstructL() 5" );
    64 
    64 
    65     iRepository = CRepository::NewL( KCRUidPnpUtil );
    65     iRepository = CRepository::NewL( KCRUidPnpUtil );
    66 
    66 
       
    67     TBuf8<KEncryptionKeyLength> encryptkey;
       
    68     CreateEncryptionKeyL(encryptkey);
       
    69     
       
    70 
    67 #ifndef __WINS__ // calling C3DESEncryptor::NewL crashes emulator
    71 #ifndef __WINS__ // calling C3DESEncryptor::NewL crashes emulator
    68     iEncryptor = C3DESEncryptor::NewL( K3DesKey );
    72     iEncryptor = C3DESEncryptor::NewL( encryptkey );
    69     iDecryptor = C3DESDecryptor::NewL( K3DesKey );
    73     iDecryptor = C3DESDecryptor::NewL( encryptkey );
    70 #endif 
    74 #endif 
    71 
    75 
    72     LOGSTRING( "Exit from CPnpUtilImpl::ConstructL()" );
    76     LOGSTRING( "Exit from CPnpUtilImpl::ConstructL()" );
    73     }
    77     }
    74 
    78 
  1061 void CPnpUtilImpl::RESERVED_FUNC()
  1065 void CPnpUtilImpl::RESERVED_FUNC()
  1062     {
  1066     {
  1063     LOGSTRING("RESERVED_FUNC")
  1067     LOGSTRING("RESERVED_FUNC")
  1064     }
  1068     }
  1065 
  1069 
       
  1070 // -----------------------------------------------------------------------------
       
  1071 // CPnpUtilImpl::CreateEncryptionKeyL
       
  1072 // -----------------------------------------------------------------------------
       
  1073 //
       
  1074 void CPnpUtilImpl::CreateEncryptionKeyL(TDes8& aEncryptionKey)
       
  1075    {
       
  1076    TBuf8<KEncryptionKeyLength> keystorage;
       
  1077    User::LeaveIfError( iRepository->Get( KPnPUtilsEncryptionKey, keystorage) );
       
  1078     
       
  1079    if(keystorage.Compare(KNullDesC8()))
       
  1080    {
       
  1081      LOGSTRING("CPnpUtilImpl::CreateEncryptionKey- Compare visited");
       
  1082      aEncryptionKey.Copy(keystorage);
       
  1083      LOGTEXT( aEncryptionKey);
       
  1084      return;
       
  1085    }
       
  1086 
       
  1087 
       
  1088    LOGSTRING("CPnpUtilImpl::CreateEncryptionKey");
       
  1089     if( aEncryptionKey.MaxLength() < KEncryptionKeyLength)
       
  1090         {
       
  1091         User::Leave( KErrArgument );
       
  1092         }
       
  1093 
       
  1094     TBuf8<KEncryptionKeyLength> buffer;
       
  1095 
       
  1096     TTime time;
       
  1097     time.HomeTime();
       
  1098     TInt64 seed = time.Int64();
       
  1099     for( TInt i(0); i < KEncryptionKeyLength ; i++ )
       
  1100         {
       
  1101         TChar character( RandomCharacter( seed ) );
       
  1102         buffer.Append( character );
       
  1103         }
       
  1104 
       
  1105     LOGSTRING("New Encryption Key:");
       
  1106     LOGTEXT( buffer );
       
  1107     aEncryptionKey.Copy( buffer );
       
  1108 
       
  1109  
       
  1110     // Save the nonce
       
  1111     User::LeaveIfError( iRepository->Set( KPnPUtilsEncryptionKey, buffer ) );
       
  1112 
       
  1113     LOGSTRING("CPnpUtilImpl::CreateEncryptionKey- done");
       
  1114 
       
  1115    }
       
  1116 
  1066 //  End of File  
  1117 //  End of File