os/security/securityanddataprivacytools/securitytools/certapp/test/tcertapp/badconfigwriter.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include "badconfigwriter.h"
sl@0
    20
#include <iostream>
sl@0
    21
#include <sstream>
sl@0
    22
#include "tcertapp_bad.h"
sl@0
    23
sl@0
    24
// Array for the StatCA- contains all relevant details
sl@0
    25
const char *badstatCA_array[]=
sl@0
    26
	{
sl@0
    27
	"X576",
sl@0
    28
	"TEst",
sl@0
    29
	"9b843cbfXXXXXXXXX5a87ce5f6da5ec",
sl@0
    30
	"",
sl@0
    31
	"!!!",
sl@0
    32
	"Junk"
sl@0
    33
	};
sl@0
    34
sl@0
    35
// Array for the Root5CA- contains all relevant details
sl@0
    36
const char *badroot5CA_array[]=
sl@0
    37
	{
sl@0
    38
	"!@##",
sl@0
    39
	"T@$%$%Est",
sl@0
    40
	"@#$b843#%3cbfXXXXXXXXX5a87ce5f6da5ec",
sl@0
    41
	"",
sl@0
    42
	"!!!",
sl@0
    43
	"J&u$n%k"
sl@0
    44
	};
sl@0
    45
sl@0
    46
// Array for the SymbianTestDSACA- contains all relevant details
sl@0
    47
const char *badsymbianTestDSACA_array[]=
sl@0
    48
	{
sl@0
    49
	"X576",
sl@0
    50
	"TEst",
sl@0
    51
	"9b843cbfXXXXXXXXX5a87ce5f6da5ec",
sl@0
    52
	"",
sl@0
    53
	"!!!",
sl@0
    54
	"J&u$n%k"
sl@0
    55
	};
sl@0
    56
sl@0
    57
// Array for the SymbianTestRSACA- contains all relevant details
sl@0
    58
const char *badsymbianTestRSACA_array[]=
sl@0
    59
	{
sl@0
    60
	"X509",
sl@0
    61
	"ca",
sl@0
    62
	"7ac99da26d384fcf6ffd0578c4f50b549ffb2032",
sl@0
    63
	"",
sl@0
    64
	"584",
sl@0
    65
	"EFalse"
sl@0
    66
	};
sl@0
    67
sl@0
    68
// uids required for cacerts
sl@0
    69
const char *bademu_cacertsUid[]=
sl@0
    70
	{
sl@0
    71
	"26QWERER23",
sl@0
    72
	"5555555555"
sl@0
    73
	};
sl@0
    74
sl@0
    75
//Capabilities required for stataca
sl@0
    76
const char *aBadCapabilities_statca[]=
sl@0
    77
{
sl@0
    78
	"TCB",
sl@0
    79
	"CommDD",
sl@0
    80
	"#&%^&%^&",
sl@0
    81
	"MultimediaDD",
sl@0
    82
	"ReadDeviceData",
sl@0
    83
	"WriteDeviceData",
sl@0
    84
	"DRM",
sl@0
    85
	"TrustedUI",
sl@0
    86
	"ProtServ",
sl@0
    87
	"@$%%#$%$#",
sl@0
    88
	"NetworkControl",
sl@0
    89
	"XXXXXXX",
sl@0
    90
	"SwEvent",
sl@0
    91
	"NetworkServices",
sl@0
    92
	"LocalServices",
sl@0
    93
	"ReadUserData",
sl@0
    94
	"#&%^&%^&",
sl@0
    95
	"Location",
sl@0
    96
	"SurroundingsDD",
sl@0
    97
	"UserEnvironment"
sl@0
    98
};
sl@0
    99
sl@0
   100
sl@0
   101
//Capabilities required for root5ca
sl@0
   102
const char *aBadCapabilities_root5ca[]=
sl@0
   103
{
sl@0
   104
	"SurroundingsDD",	
sl@0
   105
	"XXXXXXX",
sl@0
   106
	"WriteDeviceData",
sl@0
   107
	"   ",
sl@0
   108
	"A#$2l%#4lF$%^iles"
sl@0
   109
};
sl@0
   110
sl@0
   111
sl@0
   112
//Capabilities required for SymbianTestDSACA
sl@0
   113
const char *aBadCapabilities_symbianTestDSACA[]=
sl@0
   114
{
sl@0
   115
	"NetworkServices",
sl@0
   116
	"  ",
sl@0
   117
	"%#^$$&$"
sl@0
   118
};
sl@0
   119
sl@0
   120
//Capabilities required for SymbianTestRSACA
sl@0
   121
const char *aBadCapabilities_symbianTestRSACA[]=
sl@0
   122
{
sl@0
   123
	"  ",
sl@0
   124
	"%#^$$&$"
sl@0
   125
};
sl@0
   126
sl@0
   127
sl@0
   128
/**
sl@0
   129
Bad store writer
sl@0
   130
*/
sl@0
   131
BadConfigWriter::BadConfigWriter(const std::stringstream &aFileName)
sl@0
   132
{
sl@0
   133
	std::string name = aFileName.str();
sl@0
   134
	iFile.open(name.c_str(), std::ios_base::trunc | std::ios_base::out);
sl@0
   135
	if(iFile.fail())
sl@0
   136
		{
sl@0
   137
		std::cout << "Failed to open '" << name.c_str()<< "' for output!" << std::endl;
sl@0
   138
		exit(-1);
sl@0
   139
		}
sl@0
   140
}
sl@0
   141
sl@0
   142
BadConfigWriter::~BadConfigWriter()
sl@0
   143
{
sl@0
   144
	iFile.close();
sl@0
   145
}
sl@0
   146
sl@0
   147
/**
sl@0
   148
Class definition for creating cacerts
sl@0
   149
*/
sl@0
   150
FileBadCertStoreConfigWriter::FileBadCertStoreConfigWriter(const std::stringstream &aFileName)
sl@0
   151
	: BadConfigWriter(aFileName), iEntryCount(0)
sl@0
   152
{
sl@0
   153
	iFile << "StartCertStoreEntries" << std::endl;
sl@0
   154
}
sl@0
   155
sl@0
   156
FileBadCertStoreConfigWriter::~FileBadCertStoreConfigWriter()
sl@0
   157
{
sl@0
   158
	iFile << "EndCertStoreEntries" << std::endl;
sl@0
   159
}
sl@0
   160
sl@0
   161
void FileBadCertStoreConfigWriter::WriteFileEntry(const char *aBadLabel,
sl@0
   162
										   const char *aBadDeletable,
sl@0
   163
										   const char *aBadFormat,
sl@0
   164
										   const char *aBadCertOwnerType,
sl@0
   165
										   const char *aBadSubjectKeyId,
sl@0
   166
										   const char *aBadIssuerKeyId,
sl@0
   167
										   const char *aBadApplication,
sl@0
   168
										   const char *aBadTrusted,
sl@0
   169
										   const char *aBadInvalidPath)
sl@0
   170
{
sl@0
   171
	++iEntryCount;
sl@0
   172
	// Setup default values
sl@0
   173
	std::stringstream certName;
sl@0
   174
	certName << "cert" << iEntryCount << ".der";
sl@0
   175
sl@0
   176
	if(!aBadLabel) aBadLabel = "\"TestLabel\"";
sl@0
   177
	if(!aBadDeletable) aBadDeletable = "\"true\"";
sl@0
   178
	if(!aBadFormat) aBadFormat = "\"EX509Certificate\"";
sl@0
   179
	if(!aBadCertOwnerType) aBadCertOwnerType = "\"ECACertificate\"";
sl@0
   180
	if(!aBadSubjectKeyId) aBadSubjectKeyId = "auto";
sl@0
   181
	if(!aBadIssuerKeyId) aBadIssuerKeyId = "auto";
sl@0
   182
	if(!aBadTrusted) aBadTrusted = "\"true\"";
sl@0
   183
	if(!aBadInvalidPath) aBadInvalidPath = "cert0.der";
sl@0
   184
sl@0
   185
	iFile << "\t# Entry " << iEntryCount << std::endl;
sl@0
   186
	iFile << "\tStartEntry " << aBadLabel << std::endl;
sl@0
   187
	iFile << "\t\tDeletable " << aBadDeletable << std::endl;
sl@0
   188
	iFile << "\t\tFormat " << aBadFormat << std::endl;
sl@0
   189
	iFile << "\t\tCertOwnerType " << aBadCertOwnerType << std::endl;
sl@0
   190
	iFile << "\t\tSubjectKeyId " << aBadSubjectKeyId << std::endl;
sl@0
   191
	iFile << "\t\tIssuerKeyId " << aBadIssuerKeyId << std::endl;
sl@0
   192
	iFile << "\t\tStartApplicationList" << std::endl;
sl@0
   193
	// write down the applications
sl@0
   194
	for(int i = 0; i<2; i++)
sl@0
   195
		{
sl@0
   196
		iFile << "\t\t\t# Entry " << i << std::endl;
sl@0
   197
		if(!aBadApplication)
sl@0
   198
			{
sl@0
   199
			iFile << "\t\t\t\tApplication " << appNames[i]<< std::endl;
sl@0
   200
			}
sl@0
   201
		else
sl@0
   202
			{
sl@0
   203
			iFile << "\t\t\t\tApplication " << badApplications[i]<< std::endl;
sl@0
   204
			}
sl@0
   205
		}
sl@0
   206
sl@0
   207
	iFile << "\t\tEndApplicationList" << std::endl;
sl@0
   208
	iFile << "\t\tTrusted " << aBadTrusted << std::endl;
sl@0
   209
	iFile << "\t\tDataFileName " << aBadInvalidPath << std::endl;
sl@0
   210
	iFile << "\tEndEntry " <<std::endl;
sl@0
   211
	iFile <<std::endl;
sl@0
   212
}
sl@0
   213
sl@0
   214
sl@0
   215
/**
sl@0
   216
Class definition for generating certclient files
sl@0
   217
*/
sl@0
   218
FileBadCertClientConfigWriter::FileBadCertClientConfigWriter(const std::stringstream &aFileName)
sl@0
   219
	: BadConfigWriter(aFileName)
sl@0
   220
{
sl@0
   221
	iFile << "StartClientInfo" << std::endl;
sl@0
   222
}
sl@0
   223
sl@0
   224
FileBadCertClientConfigWriter::~FileBadCertClientConfigWriter()
sl@0
   225
{
sl@0
   226
	iFile << "EndClientInfo" << std::endl;
sl@0
   227
}
sl@0
   228
sl@0
   229
void FileBadCertClientConfigWriter::WriteCertClientName(const char *aBadAppName)
sl@0
   230
{
sl@0
   231
	iFile << "\tName "<< aBadAppName << std::endl;
sl@0
   232
	
sl@0
   233
}
sl@0
   234
sl@0
   235
void FileBadCertClientConfigWriter::WriteCertClientUid(const char *aBadUid)
sl@0
   236
{
sl@0
   237
	iFile << "\tUid "<< aBadUid << std::endl;
sl@0
   238
}
sl@0
   239
sl@0
   240
sl@0
   241
/**
sl@0
   242
Swi certstore writer
sl@0
   243
*/
sl@0
   244
SwiBadCertStoreConfigWriter::SwiBadCertStoreConfigWriter(const std::stringstream &aFileName)
sl@0
   245
	: BadConfigWriter(aFileName), iEntryCount(0)
sl@0
   246
{
sl@0
   247
	iFile <<"StartSwiCertStoreEntries" << std::endl;
sl@0
   248
}
sl@0
   249
sl@0
   250
SwiBadCertStoreConfigWriter::~SwiBadCertStoreConfigWriter()
sl@0
   251
{
sl@0
   252
	iFile << "EndSwiCertStoreEntries" << std::endl;
sl@0
   253
}
sl@0
   254
sl@0
   255
void SwiBadCertStoreConfigWriter::WriteSwiEntry(const char *aBadLabel,
sl@0
   256
										   const char *aBadFormat,
sl@0
   257
										   const char *aBadCertOwnerType,
sl@0
   258
										   const char *aBadSubjectKeyId,
sl@0
   259
										   const char *aBadIssuerKeyId,
sl@0
   260
										   const char *aBadApplication,
sl@0
   261
										   const char *aBadTrusted,
sl@0
   262
										   const char *aBadDatafilePath,
sl@0
   263
										   const char *aBadCapabilitySets,
sl@0
   264
										   const char *aBadMandatory,
sl@0
   265
										   const char *aBadSystemUpgrade)
sl@0
   266
{
sl@0
   267
	++iEntryCount;
sl@0
   268
	
sl@0
   269
	if(!aBadLabel) aBadLabel = "TestLabel";
sl@0
   270
	if(!aBadFormat) aBadFormat = "EX509Certificate";
sl@0
   271
	if(!aBadCertOwnerType) aBadCertOwnerType = "ECACertificate";
sl@0
   272
	if(!aBadSubjectKeyId) aBadSubjectKeyId = "auto";
sl@0
   273
	if(!aBadIssuerKeyId) aBadIssuerKeyId = "auto";
sl@0
   274
	if(!aBadTrusted) aBadTrusted = "\"true\"";
sl@0
   275
	if(!aBadDatafilePath) aBadDatafilePath = "\"swicertstore_cert0.der\"";
sl@0
   276
	if(!aBadMandatory) aBadMandatory = "\"true\"";
sl@0
   277
	if(!aBadSystemUpgrade) aBadSystemUpgrade = "\"true\"";
sl@0
   278
sl@0
   279
	iFile << "\t#Entry " << iEntryCount << std::endl;
sl@0
   280
	iFile << "\tStartEntry " << aBadLabel << std::endl;
sl@0
   281
	iFile << "\t\tFormat " << aBadFormat << std::endl;
sl@0
   282
	iFile << "\t\tCertOwnerType " << aBadCertOwnerType << std::endl;
sl@0
   283
	iFile << "\t\tSubjectKeyId " << aBadSubjectKeyId << std::endl;
sl@0
   284
	iFile << "\t\tIssuerKeyId " << aBadIssuerKeyId << std::endl;
sl@0
   285
	iFile << "\t\tStartApplicationList" << std::endl;
sl@0
   286
	//write application
sl@0
   287
	for(int k = 0; k<2; k++)
sl@0
   288
		{
sl@0
   289
		iFile << "\t\t\t# Entry " << k << std::endl;
sl@0
   290
		if(!aBadApplication)
sl@0
   291
			{
sl@0
   292
			iFile << "\t\t\t\tApplication " << appNames[k]<< std::endl;
sl@0
   293
			}
sl@0
   294
		else
sl@0
   295
			{
sl@0
   296
			iFile << "\t\t\t\tApplication " << badApplications[k]<< std::endl;
sl@0
   297
			}
sl@0
   298
		}
sl@0
   299
	iFile << "\t\tEndApplicationList" << std::endl;
sl@0
   300
	iFile << "\t\tTrusted " << aBadTrusted << std::endl;
sl@0
   301
	iFile << "\t\tDataFileName " << aBadDatafilePath << std::endl;
sl@0
   302
	iFile << "\t\tCapabilitySet " << "{ ";
sl@0
   303
	for(int i = 0; i< 5; i++)
sl@0
   304
		{
sl@0
   305
		if(!aBadCapabilitySets)
sl@0
   306
			{
sl@0
   307
			iFile << capabilitySets[i];
sl@0
   308
			}
sl@0
   309
		else
sl@0
   310
			{
sl@0
   311
			iFile << badCapabilitySets[i];
sl@0
   312
			}
sl@0
   313
		iFile <<" ";
sl@0
   314
		}
sl@0
   315
sl@0
   316
	iFile <<"}" <<std::endl;
sl@0
   317
	iFile << "\t\tMandatory " << aBadMandatory << std::endl;
sl@0
   318
	iFile << "\t\tSystemUpgrade " << aBadSystemUpgrade << std::endl;
sl@0
   319
	iFile << "\tEndEntry " <<std::endl;
sl@0
   320
	iFile <<std::endl;
sl@0
   321
}
sl@0
   322
sl@0
   323
// End of file
sl@0
   324