sl@0: /* sl@0: * Copyright (c) 2008-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: * sl@0: */ sl@0: sl@0: sl@0: #include "goodconfigwriter.h" sl@0: #include sl@0: #include sl@0: #include sl@0: #include "tcertapp_good.h" sl@0: sl@0: // Array for the StatCA- holds all relevant details sl@0: const char *swicertemu_array[]= sl@0: { sl@0: "X509", sl@0: "c7014670ad9c8ac296c2ae665c4e78f3d4df4a99" sl@0: }; sl@0: sl@0: const char *cert_array[]= sl@0: { sl@0: "X509", sl@0: "ca", sl@0: "7ce306295116207214d425affd185b6d5e48af6f", sl@0: "", sl@0: "1" sl@0: }; sl@0: sl@0: // uids required for cacerts sl@0: const char *emu_cacertsUid[]= sl@0: { sl@0: "268452523", sl@0: "268478646" sl@0: }; sl@0: sl@0: sl@0: /** sl@0: Class required to create files to write data sl@0: */ sl@0: GoodConfigWriter::GoodConfigWriter(const std::stringstream &aFileName) sl@0: { sl@0: std::string name = aFileName.str(); sl@0: iFile.open(name.c_str(), std::ios_base::trunc | std::ios_base::out); sl@0: if(iFile.fail()) sl@0: { sl@0: std::cout << "Failed to open '" << name.c_str()<< "' for output!" << std::endl; sl@0: exit(-1); sl@0: } sl@0: } sl@0: sl@0: GoodConfigWriter::~GoodConfigWriter() sl@0: { sl@0: iFile.close(); sl@0: } sl@0: sl@0: /** sl@0: Class definition for creating cacerts config files sl@0: */ sl@0: FileCertStoreConfigWriter::FileCertStoreConfigWriter(const std::stringstream &aFileName) sl@0: : GoodConfigWriter(aFileName), iEntryCount(0) sl@0: { sl@0: iFile << "StartCertStoreEntries" << std::endl; sl@0: } sl@0: sl@0: FileCertStoreConfigWriter::~FileCertStoreConfigWriter() sl@0: { sl@0: iFile << "EndCertStoreEntries" << std::endl; sl@0: } sl@0: sl@0: void FileCertStoreConfigWriter::WriteExtraFileEntry() sl@0: { sl@0: iFile << "\tStartEntry " << "\"AugmentData\"" << std::endl; sl@0: iFile << "\t\tDeletable " << "\"true\"" << std::endl; sl@0: iFile << "\t\tFormat " << "\"EX509Certificate\"" << std::endl; sl@0: iFile << "\t\tCertOwnerType " << "\"ECACertificate\"" << std::endl; sl@0: iFile << "\t\tSubjectKeyId " << "auto" << std::endl; sl@0: iFile << "\t\tIssuerKeyId " << "auto" << std::endl; sl@0: iFile << "\t\tStartApplicationList" << std::endl; sl@0: iFile << "\t\t\t#Entry 1" << std::endl; sl@0: iFile << "\t\t\t\tApplication " << "\"0x100042ab\"" << std::endl; sl@0: iFile << "\t\t\t\tApplication " << "\"0x1000a8b6\"" << std::endl; sl@0: iFile << "\t\tEndApplicationList" << std::endl; sl@0: iFile << "\t\tTrusted " << "\"true\"" << std::endl; sl@0: iFile << "\t\tDataFileName " << "\"cert0.der\"" << std::endl; sl@0: iFile <<"\tEndEntry" <=0) sl@0: { sl@0: iIniFileName = aFileName.str().substr(0,last_dot); sl@0: iIniFileName.append(".ini"); sl@0: iIniFile.open(iIniFileName.c_str(), std::ios_base::trunc | std::ios_base::out); sl@0: if(iIniFile.fail()) sl@0: { sl@0: std::cout << "Failed to open '" << iIniFileName.c_str()<< "' for output!" << std::endl; sl@0: exit(-1); sl@0: } sl@0: } sl@0: } sl@0: sl@0: ScriptAndIniGeneration::~ScriptAndIniGeneration() sl@0: { sl@0: iIniFile.close(); sl@0: } sl@0: sl@0: void ScriptAndIniGeneration::WriteTestCaseToScript(const std::stringstream &aTestCaseType,int &aTestIndex,const char *aTestActionName,const char *aTestActionType,bool aHasActionBody) sl@0: { sl@0: // set test case ID string sl@0: char testCaseIndexBuffer[6]; sl@0: sprintf(testCaseIndexBuffer, "-%04d", aTestIndex); sl@0: sl@0: iFile << "START_TESTCASE " << aTestCaseType.str() << testCaseIndexBuffer << std::endl; sl@0: iFile << "//! @SYMTestCaseID " << aTestCaseType.str() << testCaseIndexBuffer << std::endl; sl@0: iFile << "//! @SYMTestCaseDesc " << aTestActionName << std::endl; sl@0: iFile << "RUN_TEST_STEP -1\tCTestHandler\t" << aTestActionType; sl@0: if(aHasActionBody) sl@0: { sl@0: iFile << "\t" << iIniFileName << "\t" << aTestCaseType.str() << testCaseIndexBuffer << "-001"; sl@0: iIniFile << "[" << aTestCaseType.str() << testCaseIndexBuffer << "-001" << "]" << std::endl; sl@0: } sl@0: iFile << std::endl; sl@0: iFile << "END_TESTCASE " << aTestCaseType.str() << testCaseIndexBuffer << std::endl; sl@0: iFile << std::endl; sl@0: } sl@0: sl@0: sl@0: FileStoreScriptGeneration::FileStoreScriptGeneration(const std::stringstream &aFileName) sl@0: : ScriptAndIniGeneration(aFileName) sl@0: { sl@0: sl@0: } sl@0: sl@0: FileStoreScriptGeneration::~FileStoreScriptGeneration() sl@0: { sl@0: } sl@0: sl@0: void FileStoreScriptGeneration:: WriteInitialiseCert(const char *aMode, const std::stringstream &aTestCaseType, int &aTestIndex) sl@0: { sl@0: const char *testcasename = "Initializing a CUnifiedCertStore"; sl@0: const char *testcasetype = "init"; sl@0: WriteTestCaseToScript(aTestCaseType, ++aTestIndex, testcasename, testcasetype); sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "\t" << aMode << "" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << std::endl; sl@0: } sl@0: sl@0: sl@0: sl@0: void FileStoreScriptGeneration::WriteListcert(const char *aGoodOwnerType, const std::stringstream &aTestCaseType, int &aTestIndex) sl@0: { sl@0: const char *testcasename = "Get the list of certificates"; sl@0: const char *testcasetype = "listcert"; sl@0: WriteTestCaseToScript(aTestCaseType, ++aTestIndex, testcasename, testcasetype); sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "\t" << std::endl; sl@0: iIniFile << "\t\t" << aGoodOwnerType << "" << std::endl; sl@0: iIniFile << "\t" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: for(int z =0; z<6; z++) sl@0: { sl@0: iIniFile << "\t" << std::endl; sl@0: } sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << std::endl; sl@0: } sl@0: sl@0: void FileStoreScriptGeneration::WriteGetCertificateDetails(const char *label, const std::stringstream &aTestCaseType, int &aTestIndex) sl@0: { sl@0: const char *testcasename = "Get certificate details"; sl@0: const char *testcasetype = "listcert"; sl@0: WriteTestCaseToScript(aTestCaseType, ++aTestIndex, testcasename, testcasetype); sl@0: int i = 0; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "\t" << std::endl; sl@0: iIniFile << "\t\t" << std::endl; sl@0: iIniFile << "\t\t" << cert_array[i++]<< "" << std::endl; sl@0: iIniFile << "\t\t" << cert_array[i++] << "" << std::endl; sl@0: iIniFile << "\t\t" << cert_array[i++] << "" << std::endl; sl@0: iIniFile << "\t\t" <" << std::endl; sl@0: iIniFile << "\t\t" << cert_array[i++] << "" << std::endl; sl@0: iIniFile << "\t" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "\t" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << std::endl; sl@0: } sl@0: sl@0: sl@0: void FileStoreScriptGeneration::WriteGetTrust(const char *label, const char *trust, const std::stringstream &aTestCaseType, int &aTestIndex) sl@0: { sl@0: const char *testcasename = "Get Trust certificate"; sl@0: const char *testcasetype = "gettrusters"; sl@0: WriteTestCaseToScript(aTestCaseType, ++aTestIndex, testcasename, testcasetype); sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "\t" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "\t" << trust << "" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << std::endl; sl@0: } sl@0: sl@0: sl@0: void FileStoreScriptGeneration::WriteGetApplications(const char *label, const std::stringstream &aTestCaseType, int &aTestIndex) sl@0: { sl@0: const char *testcasename = "Get applications"; sl@0: const char *testcasetype = "getapplications"; sl@0: WriteTestCaseToScript(aTestCaseType, ++aTestIndex, testcasename, testcasetype); sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "\t" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "\t"; sl@0: for(int j = 0; j<2; j++) sl@0: { sl@0: iIniFile << emu_cacertsUid[j] << " "; sl@0: } sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << std::endl; sl@0: } sl@0: sl@0: sl@0: void FileStoreScriptGeneration::WriteRetrieveCerts(const char *label, const std::stringstream &aTestCaseType, int &aTestIndex) sl@0: { sl@0: const char *testcasename = "Retrieve Certificate"; sl@0: const char *testcasetype = "retrieve"; sl@0: WriteTestCaseToScript(aTestCaseType, ++aTestIndex, testcasename, testcasetype); sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "\t" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << std::endl; sl@0: } sl@0: sl@0: sl@0: sl@0: //Swi store script generator for emulator tests sl@0: SWIStoreScriptGeneration::SWIStoreScriptGeneration(const std::stringstream &aFileName) sl@0: : ScriptAndIniGeneration(aFileName) sl@0: { sl@0: sl@0: } sl@0: sl@0: SWIStoreScriptGeneration::~SWIStoreScriptGeneration() sl@0: { sl@0: } sl@0: sl@0: void SWIStoreScriptGeneration:: WriteInitialiseCert(const std::stringstream &aTestCaseType, int &aTestIndex) sl@0: { sl@0: const char *testcasename = "Initialise a SWICertStore"; sl@0: const char *testcasetype = "initswicertstore"; sl@0: WriteTestCaseToScript(aTestCaseType, ++aTestIndex, testcasename, testcasetype, false); sl@0: } sl@0: sl@0: sl@0: void SWIStoreScriptGeneration::WriteListcert(const char *aGoodOwnerType, const std::stringstream &aTestCaseType, int &aTestIndex) sl@0: { sl@0: const char *testcasename = "Get the list of certificates"; sl@0: const char *testcasetype = "listcert"; sl@0: WriteTestCaseToScript(aTestCaseType, ++aTestIndex, testcasename, testcasetype); sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "\t" << std::endl; sl@0: iIniFile << "\t\t" << aGoodOwnerType << "" << std::endl; sl@0: iIniFile << "\t" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: for(int i =0; i<6; i++) sl@0: { sl@0: iIniFile << "\tTrue" << std::endl; sl@0: } sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << std::endl; sl@0: } sl@0: sl@0: void SWIStoreScriptGeneration::WriteGetSystemUpgrade(const char *label, const char *aSystemUpgrade, const std::stringstream &aTestCaseType, int &aTestIndex) sl@0: { sl@0: const char *testcasename = "Get the systemupgrade flag"; sl@0: const char *testcasetype = "getsystemupgrade"; sl@0: WriteTestCaseToScript(aTestCaseType, ++aTestIndex, testcasename, testcasetype); sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "\t" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "\t" << aSystemUpgrade << "" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << std::endl; sl@0: } sl@0: sl@0: sl@0: void SWIStoreScriptGeneration::WriteRetrieveCerts(const char *label, const std::stringstream &aTestCaseType, int &aTestIndex) sl@0: { sl@0: const char *testcasename = "Retrieve Certificate"; sl@0: const char *testcasetype = "retrieve"; sl@0: WriteTestCaseToScript(aTestCaseType, ++aTestIndex, testcasename, testcasetype); sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "\t" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << std::endl; sl@0: } sl@0: sl@0: sl@0: sl@0: void SWIStoreScriptGeneration::WriteGetApplications(const char *label, const std::stringstream &aTestCaseType, int &aTestIndex) sl@0: { sl@0: const char *testcasename = "Get applications"; sl@0: const char *testcasetype = "getapplications"; sl@0: WriteTestCaseToScript(aTestCaseType, ++aTestIndex, testcasename, testcasetype); sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "\t" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "\t"; sl@0: for(int j = 0; j<2; j++) sl@0: { sl@0: iIniFile << emu_cacertsUid[j] << " "; sl@0: } sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << std::endl; sl@0: } sl@0: sl@0: sl@0: void SWIStoreScriptGeneration::WriteGetTrust(const char *label, const char *trust, const std::stringstream &aTestCaseType, int &aTestIndex) sl@0: { sl@0: const char *testcasename = "Get Trust certificate"; sl@0: const char *testcasetype = "gettrusters"; sl@0: WriteTestCaseToScript(aTestCaseType, ++aTestIndex, testcasename, testcasetype); sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "\t" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "\t" << trust << "" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << std::endl; sl@0: } sl@0: sl@0: sl@0: sl@0: void SWIStoreScriptGeneration::WriteGetCapabilities(const char *label, const std::stringstream &aTestCaseType, int &aTestIndex) sl@0: { sl@0: const char *testcasename = "Get the capabilities"; sl@0: const char *testcasetype = "getcapabilities"; sl@0: WriteTestCaseToScript(aTestCaseType, ++aTestIndex, testcasename, testcasetype); sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "\t" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: for(int i=0; i<20; i++) sl@0: { sl@0: iIniFile << "\t" << goodCapabilitySets[i] << "" << std::endl; sl@0: } sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << std::endl; sl@0: } sl@0: sl@0: sl@0: void SWIStoreScriptGeneration::WriteGetMandatoryFlag(const char *label, const char *aMandatory, const std::stringstream &aTestCaseType, int &aTestIndex) sl@0: { sl@0: const char *testcasename = "Get the mandatory flag"; sl@0: const char *testcasetype = "getmandatory"; sl@0: WriteTestCaseToScript(aTestCaseType, ++aTestIndex, testcasename, testcasetype); sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "\t" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "\t" << aMandatory << "" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << std::endl; sl@0: } sl@0: sl@0: sl@0: //Cert client script generator sl@0: CertClientsStoreScriptGeneration::CertClientsStoreScriptGeneration(const std::stringstream &aFileName) sl@0: : ScriptAndIniGeneration(aFileName) sl@0: { sl@0: } sl@0: sl@0: CertClientsStoreScriptGeneration::~CertClientsStoreScriptGeneration() sl@0: { sl@0: } sl@0: sl@0: void CertClientsStoreScriptGeneration::WriteInitialiseCertClient(const std::stringstream &aTestCaseType, int &aTestIndex) sl@0: { sl@0: const char *testcasename = "Initialise a CertClientStore"; sl@0: const char *testcasetype = "InitManager"; sl@0: WriteTestCaseToScript(aTestCaseType, ++aTestIndex, testcasename, testcasetype, false); sl@0: } sl@0: sl@0: void CertClientsStoreScriptGeneration::WriteGetCount(const int aApp_uidIndex, const std::stringstream &aTestCaseType, int &aTestIndex) sl@0: { sl@0: const char *testcasename = "Get Count of Applications"; sl@0: const char *testcasetype = "AppCount"; sl@0: WriteTestCaseToScript(aTestCaseType, ++aTestIndex, testcasename, testcasetype); sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "\t" << aApp_uidIndex << "" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << std::endl; sl@0: } sl@0: sl@0: sl@0: void CertClientsStoreScriptGeneration::WriteGetApplicationsList(const std::stringstream &aTestCaseType, int &aTestIndex) sl@0: { sl@0: const char *testcasename = "Getting the application list"; sl@0: const char *testcasetype = "GetApplications"; sl@0: WriteTestCaseToScript(aTestCaseType, ++aTestIndex, testcasename, testcasetype); sl@0: iIniFile << "" << std::endl; sl@0: for(int i = 0 ; i<4 ; i++) sl@0: { sl@0: iIniFile << "\t" << gooddecimalUid_array[i] << ""<<"" << goodcertclient_array[i] << "" << std::endl; sl@0: } sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << std::endl; sl@0: } sl@0: sl@0: sl@0: void CertClientsStoreScriptGeneration::WriteGetAppWithUid(const char *goodlabel,const char *uid,const std::stringstream &aTestCaseType,int &aTestIndex) sl@0: { sl@0: const char *testcasename = "Get application with given id"; sl@0: const char *testcasetype = "GetApp"; sl@0: WriteTestCaseToScript(aTestCaseType, ++aTestIndex, testcasename, testcasetype); sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << "\t" << uid << "" << std::endl; sl@0: iIniFile << "\t" << goodlabel << "" << std::endl; sl@0: iIniFile << "" << std::endl; sl@0: iIniFile << std::endl; sl@0: } sl@0: sl@0: sl@0: void CertClientsStoreScriptGeneration::WriteDestroyManager(const std::stringstream &aTestCaseType, int &aTestIndex) sl@0: { sl@0: const char *testcasename = "Destroy the manager"; sl@0: const char *testcasetype = "DestroyManager"; sl@0: WriteTestCaseToScript(aTestCaseType, ++aTestIndex, testcasename, testcasetype, false); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Class definition for creating cacerts sl@0: */ sl@0: EmptyFileConfigWriter::EmptyFileConfigWriter(const std::stringstream &aFileName) sl@0: : GoodConfigWriter(aFileName) sl@0: { sl@0: iFile << "StartCertStoreEntries" << std::endl; sl@0: } sl@0: sl@0: EmptyFileConfigWriter::~EmptyFileConfigWriter() sl@0: { sl@0: iFile << "EndCertStoreEntries" << std::endl; sl@0: } sl@0: sl@0: // End of file sl@0: