terminalsecurity/SCP/SCPServer/src/SCPConfiguration.cpp
branchRCL_3
changeset 13 86979fe66c4c
parent 0 b497e44ab2fc
child 24 13d7c31c74e0
equal deleted inserted replaced
12:9e9792ae22e3 13:86979fe66c4c
    25 
    25 
    26 #include "SCPConfiguration.h"
    26 #include "SCPConfiguration.h"
    27 #include "SCPServer.h"
    27 #include "SCPServer.h"
    28 #include <featmgr.h>
    28 #include <featmgr.h>
    29 
    29 
       
    30 #include <dmencryptionutil.h>
    30 // ================= MEMBER FUNCTIONS =======================
    31 // ================= MEMBER FUNCTIONS =======================
    31 	    
    32 	    
    32         
    33         
    33 // C++ default constructor can NOT contain any code, that
    34 // C++ default constructor can NOT contain any code, that
    34 // might leave.
    35 // might leave.
    80 		if( errf != KErrNone )
    81 		if( errf != KErrNone )
    81 		{
    82 		{
    82 			User::Leave(errf);
    83 			User::Leave(errf);
    83 		}
    84 		}
    84 		TInt result = KErrNone;
    85 		TInt result = KErrNone;
    85 		
    86         TAny* KParameters[KTotalParamIDs];
    86 		TAny* KParameters[7];
    87         TInt KParamIDs[KTotalParamIDs];
    87 		TInt KParamIDs[7];
    88         TSCPParamType KSCPParamTypes[KTotalParamIDs];
    88 		TSCPParamType KSCPParamTypes[7];
       
    89 		TInt KNumParams;
    89 		TInt KNumParams;
    90 		
    90 		
    91 		
    91 		
    92 		if(FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
    92 		if(FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
    93 		{
    93 		{
   153                { 
   153                { 
   154                ret = params->Get( KParamIDs[i], *(reinterpret_cast<TDes*>( KParameters[i] )) );
   154                ret = params->Get( KParamIDs[i], *(reinterpret_cast<TDes*>( KParameters[i] )) );
   155                break;
   155                break;
   156                } 
   156                } 
   157                
   157                
       
   158         case ( EParTypeBool ):
       
   159                { 
       
   160                ret = params->Get( KParamIDs[i], *(reinterpret_cast<TBool*>( KParameters[i] )) );
       
   161                break;
       
   162                }        
       
   163                
   158            default:               
   164            default:               
   159                 // No implementation needed           
   165                 // No implementation needed           
   160                 break;
   166                 break;
   161            } // switch                 
   167            } // switch                 
   162         
   168         
   170     CleanupStack::PopAndDestroy( params ); 
   176     CleanupStack::PopAndDestroy( params ); 
   171     
   177     
   172     // Decrypt the ISA security code
   178     // Decrypt the ISA security code
   173     TSCPSecCode cryptBuf;
   179     TSCPSecCode cryptBuf;
   174     cryptBuf.Copy( iSecCode );
   180     cryptBuf.Copy( iSecCode );
   175     TransformStringL( EFalse, cryptBuf, iSecCode );
   181     Dprint( (_L("--> TSCPConfiguration::ReadSetupL NativeTransform iCryptoCode= %S "), &iCryptoCode ));
       
   182     if(EFalse == NativeTransform(EFalse, iCryptoCode, iSecCode))
       
   183     {
       
   184         Dprint( (_L("--> TSCPConfiguration::ReadSetupL NativeTransform returned false") ));
       
   185         // If ECOM decrypt fails after modifying iSecCode. 
       
   186         iSecCode.Copy(cryptBuf);
       
   187         TransformStringL( EFalse, cryptBuf, iSecCode );        
       
   188     }
       
   189     else
       
   190     {
       
   191         Dprint( (_L("--> TSCPConfiguration::ReadSetupL NativeTransform returned true") ));
       
   192         Dprint( (_L("--> TSCPConfiguration::ReadSetupL NativeTransform iCryptoCode= %S "), &iCryptoCode ));
       
   193         //Dummy code to be written of KSCPCodeMaxLen size, if plugin exist.
       
   194        // Dprint((_L("iSecCode.Copy(iCryptoCode.Ptr(), KSCPCodeMaxLen);")));
       
   195        // iSecCode.Copy(iCryptoCode.Ptr(), KSCPCodeMaxLen);        
       
   196     }
   176     iSecCode.SetLength( KSCPCodeMaxLen ); // Remove the suffix
   197     iSecCode.SetLength( KSCPCodeMaxLen ); // Remove the suffix
   177        
   198        
   178     FeatureManager::UnInitializeLib();
   199     FeatureManager::UnInitializeLib();
   179     return result;       
   200     return result;       
   180     }
   201     }
   198 		}
   219 		}
   199 		TInt result = KErrNone;
   220 		TInt result = KErrNone;
   200 		
   221 		
   201 		
   222 		
   202 		
   223 		
   203 		TAny* KParameters[7];
   224         TAny* KParameters[KTotalParamIDs];
   204 		TInt KParamIDs[7];
   225         TInt KParamIDs[KTotalParamIDs];
   205 		TSCPParamType KSCPParamTypes[7];
   226         TSCPParamType KSCPParamTypes[KTotalParamIDs];
   206 		TInt KNumParams;
   227 		TInt KNumParams;
   207 		
   228 		
   208 		
   229 		
   209 		if(FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
   230 		if(FeatureManager::FeatureSupported(KFeatureIdSapDeviceLockEnhancements))
   210 		{
   231 		{
   243     
   264     
   244     // Encrypt the ISA security code
   265     // Encrypt the ISA security code
   245     TSCPSecCode cryptBuf;
   266     TSCPSecCode cryptBuf;
   246     cryptBuf.Copy( iSecCode );
   267     cryptBuf.Copy( iSecCode );
   247     cryptBuf.Append( KSCPCryptSuffix ); // 5 chars for the code + suffix
   268     cryptBuf.Append( KSCPCryptSuffix ); // 5 chars for the code + suffix
   248     TransformStringL( ETrue, cryptBuf, iSecCode );
   269     if(EFalse == NativeTransform(ETrue, cryptBuf, iCryptoCode)) 
   249     
   270     {
       
   271         cryptBuf.FillZ();
       
   272         cryptBuf.Zero();
       
   273         cryptBuf.Copy( iSecCode );
       
   274         cryptBuf.Append( KSCPCryptSuffix ); // 5 chars for the code + suffix
       
   275         Dprint( (_L("--> TSCPConfiguration::WriteSetupL NativeTransform returned false") ));
       
   276         TransformStringL( ETrue, cryptBuf, iSecCode );
       
   277         
       
   278     }
       
   279     else
       
   280     {
       
   281         iSecCode.FillZ();
       
   282         iSecCode.Zero();
       
   283         
       
   284         Dprint( (_L("--> TSCPConfiguration::WriteSetupL NativeTransform returned true") ));
       
   285         Dprint( (_L("--> TSCPConfiguration::WriteSetupL NativeTransform iCryptoCode= %S "), &iCryptoCode ));
       
   286     }
   250     TInt ret = KErrNone;    
   287     TInt ret = KErrNone;    
   251     for ( TInt i = 0; i < KNumParams; i++ )
   288     for ( TInt i = 0; i < KNumParams; i++ )
   252         { 
   289         { 
   253         // Set the value according to the type
   290         // Set the value according to the type
   254         switch ( KSCPParamTypes[i] )
   291         switch ( KSCPParamTypes[i] )
   260                }
   297                }
   261                                
   298                                
   262 		   case ( EParTypeDesc ):
   299 		   case ( EParTypeDesc ):
   263                { 
   300                { 
   264                ret = params->Set( KParamIDs[i], *(reinterpret_cast<TDes*>( KParameters[i] )) );
   301                ret = params->Set( KParamIDs[i], *(reinterpret_cast<TDes*>( KParameters[i] )) );
       
   302                break;
       
   303                } 
       
   304                
       
   305                case ( EParTypeBool ):
       
   306                { 
       
   307                ret = params->Set( KParamIDs[i], *(reinterpret_cast<TBool*>( KParameters[i] )) );
   265                break;
   308                break;
   266                } 
   309                } 
   267                
   310                
   268            default:               
   311            default:               
   269                 // No implementation needed           
   312                 // No implementation needed           
   395         
   438         
   396 #ifdef UNICODE
   439 #ifdef UNICODE
   397     aOutput.SetLength( outputData.Length() / 2 );
   440     aOutput.SetLength( outputData.Length() / 2 );
   398 #endif // UNICODE       
   441 #endif // UNICODE       
   399     }
   442     }
   400 
   443 // ---------------------------------------------------------
   401 
   444 // TSCPConfiguration::NativeTransform (TBool aEncrypt, TDes& aInput, TDes& aOutput)
       
   445 // Transforms the given aInput buffer using the plugin Encryption/Decryption,
       
   446 // and stores the result to aOutput
       
   447 // 
       
   448 // Status : New
       
   449 // ---------------------------------------------------------
       
   450 //
       
   451 TBool TSCPConfiguration::NativeTransform (TBool aEncrypt, TDes& aInput, TDes& aOutput)
       
   452 {
       
   453     Dprint( (_L("--> TSCPConfiguration::NativeTransform()") ));
       
   454     TInt err(KErrNone);
       
   455     TBool result(ETrue);
       
   456 
       
   457 
       
   458         CDMEncryptionUtil* eUtil;
       
   459         Dprint( (_L("TSCPConfiguration::NativeTransform(), calling TRAP(err, eUtil = CDMEncryptionUtil::NewL());  ") ));
       
   460 
       
   461         TRAP(err, eUtil = CDMEncryptionUtil::NewL());
       
   462         Dprint( (_L("TSCPConfiguration::NativeTransform(), after TRAP(err, eUtil = CDMEncryptionUtil::NewL());  err= %d"), err ));
       
   463         if(err)
       
   464         {
       
   465             result = EFalse;
       
   466             return result;
       
   467         }
       
   468         CleanupStack::PushL(eUtil);
       
   469         if(aEncrypt)
       
   470         {
       
   471             Dprint( (_L(" TSCPConfiguration::NativeTransform()Encrypting...") ));            
       
   472             TRAP(err, eUtil->EncryptL( aInput, aOutput));
       
   473             Dprint( (_L("TSCPConfiguration::NativeTransform(), after Encrypting err= %d"), err ));
       
   474         }
       
   475         else
       
   476         {
       
   477             Dprint( (_L(" TSCPConfiguration::NativeTransform()Decrypting...") ));            
       
   478             TRAP(err, eUtil->DecryptL( aInput, aOutput));            
       
   479             Dprint( (_L("TSCPConfiguration::NativeTransform(), after Decrypting err= %d"), err ));
       
   480         }
       
   481         CleanupStack::PopAndDestroy(); //eUtil
       
   482         if(err)
       
   483         {
       
   484             Dprint( (_L(" TSCPConfiguration::NativeTransform() CDMEncryptionUtil::ListImplementationsL failed") ));
       
   485             result = EFalse;  
       
   486         }
       
   487         else
       
   488         {
       
   489             Dprint( (_L(" TSCPConfiguration::NativeTransform() CDMEncryptionUtil::ListImplementationsL success") ));
       
   490             result = ETrue;            
       
   491         }
       
   492 
       
   493     Dprint( (_L("TSCPConfiguration::NativeTransform(): result = %d"), result ));
       
   494     Dprint( (_L("<-- TSCPConfiguration::NativeTransform()") ));
       
   495     return result;
       
   496 }
   402 
   497 
   403 //  End of File  
   498 //  End of File  
   404 
   499