os/security/securityanddataprivacytools/securitytools/certapp/test/tcertapp/badconfigwriter.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/securityanddataprivacytools/securitytools/certapp/test/tcertapp/badconfigwriter.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,324 @@
1.4 +/*
1.5 +* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include "badconfigwriter.h"
1.23 +#include <iostream>
1.24 +#include <sstream>
1.25 +#include "tcertapp_bad.h"
1.26 +
1.27 +// Array for the StatCA- contains all relevant details
1.28 +const char *badstatCA_array[]=
1.29 + {
1.30 + "X576",
1.31 + "TEst",
1.32 + "9b843cbfXXXXXXXXX5a87ce5f6da5ec",
1.33 + "",
1.34 + "!!!",
1.35 + "Junk"
1.36 + };
1.37 +
1.38 +// Array for the Root5CA- contains all relevant details
1.39 +const char *badroot5CA_array[]=
1.40 + {
1.41 + "!@##",
1.42 + "T@$%$%Est",
1.43 + "@#$b843#%3cbfXXXXXXXXX5a87ce5f6da5ec",
1.44 + "",
1.45 + "!!!",
1.46 + "J&u$n%k"
1.47 + };
1.48 +
1.49 +// Array for the SymbianTestDSACA- contains all relevant details
1.50 +const char *badsymbianTestDSACA_array[]=
1.51 + {
1.52 + "X576",
1.53 + "TEst",
1.54 + "9b843cbfXXXXXXXXX5a87ce5f6da5ec",
1.55 + "",
1.56 + "!!!",
1.57 + "J&u$n%k"
1.58 + };
1.59 +
1.60 +// Array for the SymbianTestRSACA- contains all relevant details
1.61 +const char *badsymbianTestRSACA_array[]=
1.62 + {
1.63 + "X509",
1.64 + "ca",
1.65 + "7ac99da26d384fcf6ffd0578c4f50b549ffb2032",
1.66 + "",
1.67 + "584",
1.68 + "EFalse"
1.69 + };
1.70 +
1.71 +// uids required for cacerts
1.72 +const char *bademu_cacertsUid[]=
1.73 + {
1.74 + "26QWERER23",
1.75 + "5555555555"
1.76 + };
1.77 +
1.78 +//Capabilities required for stataca
1.79 +const char *aBadCapabilities_statca[]=
1.80 +{
1.81 + "TCB",
1.82 + "CommDD",
1.83 + "#&%^&%^&",
1.84 + "MultimediaDD",
1.85 + "ReadDeviceData",
1.86 + "WriteDeviceData",
1.87 + "DRM",
1.88 + "TrustedUI",
1.89 + "ProtServ",
1.90 + "@$%%#$%$#",
1.91 + "NetworkControl",
1.92 + "XXXXXXX",
1.93 + "SwEvent",
1.94 + "NetworkServices",
1.95 + "LocalServices",
1.96 + "ReadUserData",
1.97 + "#&%^&%^&",
1.98 + "Location",
1.99 + "SurroundingsDD",
1.100 + "UserEnvironment"
1.101 +};
1.102 +
1.103 +
1.104 +//Capabilities required for root5ca
1.105 +const char *aBadCapabilities_root5ca[]=
1.106 +{
1.107 + "SurroundingsDD",
1.108 + "XXXXXXX",
1.109 + "WriteDeviceData",
1.110 + " ",
1.111 + "A#$2l%#4lF$%^iles"
1.112 +};
1.113 +
1.114 +
1.115 +//Capabilities required for SymbianTestDSACA
1.116 +const char *aBadCapabilities_symbianTestDSACA[]=
1.117 +{
1.118 + "NetworkServices",
1.119 + " ",
1.120 + "%#^$$&$"
1.121 +};
1.122 +
1.123 +//Capabilities required for SymbianTestRSACA
1.124 +const char *aBadCapabilities_symbianTestRSACA[]=
1.125 +{
1.126 + " ",
1.127 + "%#^$$&$"
1.128 +};
1.129 +
1.130 +
1.131 +/**
1.132 +Bad store writer
1.133 +*/
1.134 +BadConfigWriter::BadConfigWriter(const std::stringstream &aFileName)
1.135 +{
1.136 + std::string name = aFileName.str();
1.137 + iFile.open(name.c_str(), std::ios_base::trunc | std::ios_base::out);
1.138 + if(iFile.fail())
1.139 + {
1.140 + std::cout << "Failed to open '" << name.c_str()<< "' for output!" << std::endl;
1.141 + exit(-1);
1.142 + }
1.143 +}
1.144 +
1.145 +BadConfigWriter::~BadConfigWriter()
1.146 +{
1.147 + iFile.close();
1.148 +}
1.149 +
1.150 +/**
1.151 +Class definition for creating cacerts
1.152 +*/
1.153 +FileBadCertStoreConfigWriter::FileBadCertStoreConfigWriter(const std::stringstream &aFileName)
1.154 + : BadConfigWriter(aFileName), iEntryCount(0)
1.155 +{
1.156 + iFile << "StartCertStoreEntries" << std::endl;
1.157 +}
1.158 +
1.159 +FileBadCertStoreConfigWriter::~FileBadCertStoreConfigWriter()
1.160 +{
1.161 + iFile << "EndCertStoreEntries" << std::endl;
1.162 +}
1.163 +
1.164 +void FileBadCertStoreConfigWriter::WriteFileEntry(const char *aBadLabel,
1.165 + const char *aBadDeletable,
1.166 + const char *aBadFormat,
1.167 + const char *aBadCertOwnerType,
1.168 + const char *aBadSubjectKeyId,
1.169 + const char *aBadIssuerKeyId,
1.170 + const char *aBadApplication,
1.171 + const char *aBadTrusted,
1.172 + const char *aBadInvalidPath)
1.173 +{
1.174 + ++iEntryCount;
1.175 + // Setup default values
1.176 + std::stringstream certName;
1.177 + certName << "cert" << iEntryCount << ".der";
1.178 +
1.179 + if(!aBadLabel) aBadLabel = "\"TestLabel\"";
1.180 + if(!aBadDeletable) aBadDeletable = "\"true\"";
1.181 + if(!aBadFormat) aBadFormat = "\"EX509Certificate\"";
1.182 + if(!aBadCertOwnerType) aBadCertOwnerType = "\"ECACertificate\"";
1.183 + if(!aBadSubjectKeyId) aBadSubjectKeyId = "auto";
1.184 + if(!aBadIssuerKeyId) aBadIssuerKeyId = "auto";
1.185 + if(!aBadTrusted) aBadTrusted = "\"true\"";
1.186 + if(!aBadInvalidPath) aBadInvalidPath = "cert0.der";
1.187 +
1.188 + iFile << "\t# Entry " << iEntryCount << std::endl;
1.189 + iFile << "\tStartEntry " << aBadLabel << std::endl;
1.190 + iFile << "\t\tDeletable " << aBadDeletable << std::endl;
1.191 + iFile << "\t\tFormat " << aBadFormat << std::endl;
1.192 + iFile << "\t\tCertOwnerType " << aBadCertOwnerType << std::endl;
1.193 + iFile << "\t\tSubjectKeyId " << aBadSubjectKeyId << std::endl;
1.194 + iFile << "\t\tIssuerKeyId " << aBadIssuerKeyId << std::endl;
1.195 + iFile << "\t\tStartApplicationList" << std::endl;
1.196 + // write down the applications
1.197 + for(int i = 0; i<2; i++)
1.198 + {
1.199 + iFile << "\t\t\t# Entry " << i << std::endl;
1.200 + if(!aBadApplication)
1.201 + {
1.202 + iFile << "\t\t\t\tApplication " << appNames[i]<< std::endl;
1.203 + }
1.204 + else
1.205 + {
1.206 + iFile << "\t\t\t\tApplication " << badApplications[i]<< std::endl;
1.207 + }
1.208 + }
1.209 +
1.210 + iFile << "\t\tEndApplicationList" << std::endl;
1.211 + iFile << "\t\tTrusted " << aBadTrusted << std::endl;
1.212 + iFile << "\t\tDataFileName " << aBadInvalidPath << std::endl;
1.213 + iFile << "\tEndEntry " <<std::endl;
1.214 + iFile <<std::endl;
1.215 +}
1.216 +
1.217 +
1.218 +/**
1.219 +Class definition for generating certclient files
1.220 +*/
1.221 +FileBadCertClientConfigWriter::FileBadCertClientConfigWriter(const std::stringstream &aFileName)
1.222 + : BadConfigWriter(aFileName)
1.223 +{
1.224 + iFile << "StartClientInfo" << std::endl;
1.225 +}
1.226 +
1.227 +FileBadCertClientConfigWriter::~FileBadCertClientConfigWriter()
1.228 +{
1.229 + iFile << "EndClientInfo" << std::endl;
1.230 +}
1.231 +
1.232 +void FileBadCertClientConfigWriter::WriteCertClientName(const char *aBadAppName)
1.233 +{
1.234 + iFile << "\tName "<< aBadAppName << std::endl;
1.235 +
1.236 +}
1.237 +
1.238 +void FileBadCertClientConfigWriter::WriteCertClientUid(const char *aBadUid)
1.239 +{
1.240 + iFile << "\tUid "<< aBadUid << std::endl;
1.241 +}
1.242 +
1.243 +
1.244 +/**
1.245 +Swi certstore writer
1.246 +*/
1.247 +SwiBadCertStoreConfigWriter::SwiBadCertStoreConfigWriter(const std::stringstream &aFileName)
1.248 + : BadConfigWriter(aFileName), iEntryCount(0)
1.249 +{
1.250 + iFile <<"StartSwiCertStoreEntries" << std::endl;
1.251 +}
1.252 +
1.253 +SwiBadCertStoreConfigWriter::~SwiBadCertStoreConfigWriter()
1.254 +{
1.255 + iFile << "EndSwiCertStoreEntries" << std::endl;
1.256 +}
1.257 +
1.258 +void SwiBadCertStoreConfigWriter::WriteSwiEntry(const char *aBadLabel,
1.259 + const char *aBadFormat,
1.260 + const char *aBadCertOwnerType,
1.261 + const char *aBadSubjectKeyId,
1.262 + const char *aBadIssuerKeyId,
1.263 + const char *aBadApplication,
1.264 + const char *aBadTrusted,
1.265 + const char *aBadDatafilePath,
1.266 + const char *aBadCapabilitySets,
1.267 + const char *aBadMandatory,
1.268 + const char *aBadSystemUpgrade)
1.269 +{
1.270 + ++iEntryCount;
1.271 +
1.272 + if(!aBadLabel) aBadLabel = "TestLabel";
1.273 + if(!aBadFormat) aBadFormat = "EX509Certificate";
1.274 + if(!aBadCertOwnerType) aBadCertOwnerType = "ECACertificate";
1.275 + if(!aBadSubjectKeyId) aBadSubjectKeyId = "auto";
1.276 + if(!aBadIssuerKeyId) aBadIssuerKeyId = "auto";
1.277 + if(!aBadTrusted) aBadTrusted = "\"true\"";
1.278 + if(!aBadDatafilePath) aBadDatafilePath = "\"swicertstore_cert0.der\"";
1.279 + if(!aBadMandatory) aBadMandatory = "\"true\"";
1.280 + if(!aBadSystemUpgrade) aBadSystemUpgrade = "\"true\"";
1.281 +
1.282 + iFile << "\t#Entry " << iEntryCount << std::endl;
1.283 + iFile << "\tStartEntry " << aBadLabel << std::endl;
1.284 + iFile << "\t\tFormat " << aBadFormat << std::endl;
1.285 + iFile << "\t\tCertOwnerType " << aBadCertOwnerType << std::endl;
1.286 + iFile << "\t\tSubjectKeyId " << aBadSubjectKeyId << std::endl;
1.287 + iFile << "\t\tIssuerKeyId " << aBadIssuerKeyId << std::endl;
1.288 + iFile << "\t\tStartApplicationList" << std::endl;
1.289 + //write application
1.290 + for(int k = 0; k<2; k++)
1.291 + {
1.292 + iFile << "\t\t\t# Entry " << k << std::endl;
1.293 + if(!aBadApplication)
1.294 + {
1.295 + iFile << "\t\t\t\tApplication " << appNames[k]<< std::endl;
1.296 + }
1.297 + else
1.298 + {
1.299 + iFile << "\t\t\t\tApplication " << badApplications[k]<< std::endl;
1.300 + }
1.301 + }
1.302 + iFile << "\t\tEndApplicationList" << std::endl;
1.303 + iFile << "\t\tTrusted " << aBadTrusted << std::endl;
1.304 + iFile << "\t\tDataFileName " << aBadDatafilePath << std::endl;
1.305 + iFile << "\t\tCapabilitySet " << "{ ";
1.306 + for(int i = 0; i< 5; i++)
1.307 + {
1.308 + if(!aBadCapabilitySets)
1.309 + {
1.310 + iFile << capabilitySets[i];
1.311 + }
1.312 + else
1.313 + {
1.314 + iFile << badCapabilitySets[i];
1.315 + }
1.316 + iFile <<" ";
1.317 + }
1.318 +
1.319 + iFile <<"}" <<std::endl;
1.320 + iFile << "\t\tMandatory " << aBadMandatory << std::endl;
1.321 + iFile << "\t\tSystemUpgrade " << aBadSystemUpgrade << std::endl;
1.322 + iFile << "\tEndEntry " <<std::endl;
1.323 + iFile <<std::endl;
1.324 +}
1.325 +
1.326 +// End of file
1.327 +