sl@0: /* sl@0: * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * crypto plugins loader implementation sl@0: * crypto spi state implementation sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: */ sl@0: #include "cryptopluginsloader.h" sl@0: #include sl@0: #include sl@0: #include "cryptospiproperty.h" sl@0: #include sl@0: sl@0: using namespace CryptoSpi; sl@0: sl@0: _LIT(KPluginDir, "z:\\sys\\bin\\"); sl@0: sl@0: HBufC *GetConfigFileNameL(); sl@0: sl@0: // sl@0: // Implementation of TCharacteristicsDll sl@0: // sl@0: TCharacteristicsDll::TCharacteristicsDll(const TAny* aCharacteristics, TInt aIndex) sl@0: :iCharacteristics(aCharacteristics), iDllIndex(aIndex) sl@0: { sl@0: } sl@0: sl@0: void TCharacteristicsDll::ExternalizeL(RWriteStream& aStream) sl@0: { sl@0: const TCommonCharacteristics* common=reinterpret_cast(iCharacteristics); sl@0: switch (common->iInterfaceUID) sl@0: { sl@0: case KHashInterface: sl@0: case KAsyncHashInterface: sl@0: { sl@0: const THashCharacteristics* characteristics=reinterpret_cast(iCharacteristics); sl@0: characteristics->ExternalizeL(aStream); sl@0: } sl@0: break; sl@0: case KRandomInterface: sl@0: case KAsyncRandomInterface: sl@0: { sl@0: const TRandomCharacteristics* characteristics=reinterpret_cast(iCharacteristics); sl@0: characteristics->ExternalizeL(aStream); sl@0: } sl@0: break; sl@0: sl@0: case KSymmetricCipherInterface: sl@0: case KAsyncSymmetricCipherInterface: sl@0: { sl@0: const TSymmetricCipherCharacteristics* characteristics=reinterpret_cast(iCharacteristics); sl@0: characteristics->ExternalizeL(aStream); sl@0: } sl@0: break; sl@0: sl@0: case KAsymmetricCipherInterface: sl@0: case KAsyncAsymmetricCipherInterface: sl@0: { sl@0: const TAsymmetricCipherCharacteristics* characteristics=reinterpret_cast(iCharacteristics); sl@0: characteristics->ExternalizeL(aStream); sl@0: } sl@0: break; sl@0: sl@0: case KSignerInterface: sl@0: case KVerifierInterface: sl@0: case KAsyncSignerInterface: sl@0: case KAsyncVerifierInterface: sl@0: { sl@0: const TAsymmetricSignatureCharacteristics* characteristics=reinterpret_cast(iCharacteristics); sl@0: characteristics->ExternalizeL(aStream); sl@0: } sl@0: break; sl@0: sl@0: case KKeyAgreementInterface: sl@0: case KAsyncKeyAgreementInterface: sl@0: { sl@0: const TKeyAgreementCharacteristics* characteristics=reinterpret_cast(iCharacteristics); sl@0: characteristics->ExternalizeL(aStream); sl@0: } sl@0: break; sl@0: sl@0: case KKeypairGeneratorInterface: sl@0: case KAsyncKeypairGeneratorInterface: sl@0: { sl@0: const TAsymmetricKeypairGeneratorCharacteristics* characteristics=reinterpret_cast(iCharacteristics); sl@0: characteristics->ExternalizeL(aStream); sl@0: } sl@0: break; sl@0: #ifdef SYMBIAN_SDP_IPSEC_VOIP_SUPPORT sl@0: case KMacInterface: sl@0: case KAsyncMacInterface: sl@0: { sl@0: const TMacCharacteristics* characteristics=reinterpret_cast(iCharacteristics); sl@0: characteristics->ExternalizeL(aStream); sl@0: } sl@0: break; sl@0: #endif sl@0: default: sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: sl@0: aStream.WriteInt8L(iDllIndex); sl@0: } sl@0: sl@0: // sl@0: // Implementation of CCharacteristicDllIndexList sl@0: // sl@0: CCharacteristicDllIndexList* CCharacteristicDllIndexList::NewL() sl@0: { sl@0: CCharacteristicDllIndexList* self=new(ELeave) CCharacteristicDllIndexList(); sl@0: return self; sl@0: } sl@0: sl@0: CCharacteristicDllIndexList* CCharacteristicDllIndexList::NewLC() sl@0: { sl@0: CCharacteristicDllIndexList* self=new(ELeave) CCharacteristicDllIndexList(); sl@0: CleanupStack::PushL(self); sl@0: return self; sl@0: } sl@0: sl@0: CCharacteristicDllIndexList::CCharacteristicDllIndexList() sl@0: { sl@0: } sl@0: sl@0: CCharacteristicDllIndexList::~CCharacteristicDllIndexList() sl@0: { sl@0: iCharacteristicList.Close(); sl@0: } sl@0: sl@0: void CCharacteristicDllIndexList::ExternalizeL(RWriteStream& aStream) sl@0: { sl@0: TInt count=iCharacteristicList.Count(); sl@0: aStream.WriteInt16L(count); sl@0: for (TInt i=0;iConstructL(); sl@0: return self; sl@0: } sl@0: sl@0: CCryptoPluginsLoader::CCryptoPluginsLoader() sl@0: { sl@0: } sl@0: sl@0: CCryptoPluginsLoader::~CCryptoPluginsLoader() sl@0: { sl@0: //Destroy the characteristic map sl@0: THashMapIter it(iInterfaceCharacteristicsMap); sl@0: it.NextValue(); sl@0: while (it.CurrentValue()) sl@0: { sl@0: delete *it.CurrentValue(); sl@0: it.NextValue(); sl@0: } sl@0: iInterfaceCharacteristicsMap.Close(); sl@0: sl@0: //Unload the plugin DLLs and release the array sl@0: TInt dllCount=iPluginDllList.Count(); sl@0: for (TInt i=0;iDes()); sl@0: sl@0: RFs fs; sl@0: User::LeaveIfError(fs.Connect()); sl@0: CleanupClosePushL(fs); sl@0: sl@0: RFile file; sl@0: User::LeaveIfError(file.Open(fs, configFile, KEntryAttNormal)); sl@0: CleanupClosePushL(file); sl@0: sl@0: TFileText ft; sl@0: ft.Set(file); sl@0: TFileName line; sl@0: sl@0: User::LeaveIfError(ft.Read(line)); sl@0: sl@0: //Load all the plugins sl@0: do sl@0: { sl@0: TFileName filename; sl@0: filename.Append(KPluginDir); sl@0: filename.Append(line); sl@0: sl@0: //Load... sl@0: RLibrary plugin; sl@0: TInt err=plugin.Load(filename); sl@0: if (err==KErrNone) sl@0: { sl@0: CleanupClosePushL(plugin); sl@0: iPluginDllList.AppendL(plugin); sl@0: CleanupStack::Pop(&plugin); sl@0: iPluginNames.AppendL(line); sl@0: } sl@0: } sl@0: while(ft.Read(line) == KErrNone); sl@0: sl@0: sl@0: CleanupStack::PopAndDestroy(&file); sl@0: CleanupStack::PopAndDestroy(&fs); sl@0: CleanupStack::PopAndDestroy(configFileBuf); sl@0: sl@0: BuildPluginCharacteristicsL(); sl@0: } sl@0: sl@0: void CCryptoPluginsLoader::BuildPluginCharacteristicsL() sl@0: { sl@0: TInt dllCount=iPluginDllList.Count(); sl@0: TInt interfaceCount=sizeof(KInterfacesUids)/sizeof(KInterfacesUids[0]); sl@0: for (TInt i=0;iiCharacteristicList.AppendL(temp); sl@0: } sl@0: p++; sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CCryptoPluginsLoader::CreatePluginConfigPropertyL() sl@0: { sl@0: RProcess thisProcess; sl@0: // sanity check that feature property category in common header equals SID of this process sl@0: ASSERT(KCryptoSpiPropertyCat == thisProcess.SecureId()); sl@0: TSecurityPolicy readPolicy(TSecurityPolicy::EAlwaysPass); sl@0: TSecurityPolicy writePolicy(thisProcess.SecureId()); sl@0: sl@0: TInt count=iPluginNames.Count(); sl@0: TInt publishResult=KErrNone; sl@0: for (TInt i=0;iDes()); sl@0: RDesWriteStream dws(bufPtr); sl@0: dws<Des()); sl@0: RDesWriteStream dws(bufPtr); sl@0: dws.WriteInt32L(ss.Size()); sl@0: DoCreateInterfacePropertyL(dws, aInterface); sl@0: dws.CommitL(); sl@0: User::LeaveIfError(RProperty::Set(KCryptoSpiPropertyCat, aInterface, bufPtr)); sl@0: CleanupStack::PopAndDestroy(buf); sl@0: } sl@0: sl@0: void CCryptoPluginsLoader::DoCreateInterfacePropertyL(RWriteStream& aStream, TInt32 aInterface) sl@0: { sl@0: RProcess thisProcess; sl@0: // sanity check that feature property category in common header equals SID of this process sl@0: ASSERT(KCryptoSpiPropertyCat == thisProcess.SecureId()); sl@0: TSecurityPolicy readPolicy(TSecurityPolicy::EAlwaysPass); sl@0: TSecurityPolicy writePolicy(thisProcess.SecureId()); sl@0: sl@0: TInt publishResult = RProperty::Define(aInterface, RProperty::ELargeByteArray, readPolicy, writePolicy); sl@0: if ((publishResult == KErrNone) || (publishResult == KErrAlreadyExists)) sl@0: { sl@0: CCharacteristicDllIndexList** charsListPtr=iInterfaceCharacteristicsMap.Find(aInterface); sl@0: if (charsListPtr) sl@0: { sl@0: (*charsListPtr)->ExternalizeL(aStream); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: User::Leave(publishResult); sl@0: } sl@0: } sl@0: sl@0: // sl@0: // Implementation of TSizeStream sl@0: // sl@0: void TSizeStream::DoWriteL(const TAny* /* aPtr */, TInt aLength) sl@0: { sl@0: iSize += aLength; sl@0: } sl@0: sl@0: _LIT(KPluginConfigFile, "z:\\resource\\cryptospi\\plug-ins.txt"); sl@0: HBufC *GetConfigFileNameL() sl@0: { sl@0: // Check the command line. It should be empty or a single decimal digit sl@0: TInt argsLen = User::CommandLineLength(); sl@0: sl@0: if(argsLen == 0) sl@0: { sl@0: // No arguments so return the default config file name sl@0: return KPluginConfigFile().AllocL(); sl@0: } sl@0: sl@0: // We only support a single digit argument sl@0: if(argsLen != 1) sl@0: { sl@0: User::Leave(KErrArgument); sl@0: } sl@0: sl@0: sl@0: // Read the single char command line sl@0: TBuf<1> argsBuf; sl@0: User::CommandLine(argsBuf); sl@0: sl@0: // Check if it is a digit sl@0: TChar ch(argsBuf[0]); sl@0: if(!ch.IsDigit()) sl@0: { sl@0: User::Leave(KErrArgument); sl@0: } sl@0: sl@0: // Create buffer for config file name, inc space to append the digit sl@0: HBufC *configFileBuf = HBufC::NewL(KPluginConfigFile().Length()+1); sl@0: TPtr configFile(configFileBuf->Des()); sl@0: sl@0: // Initialise it to the default file name sl@0: configFile = KPluginConfigFile; sl@0: sl@0: // Append the digit to the config file name sl@0: configFile.Append(ch); sl@0: sl@0: return configFileBuf; sl@0: } sl@0: sl@0: // End of file