|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "options.h" |
|
20 #include "openssllicense.h" |
|
21 #include "capabilities.h" |
|
22 using namespace std; |
|
23 |
|
24 /** |
|
25 * Command Line Exception Messages |
|
26 */ |
|
27 |
|
28 void Options::DisplayError (const Exceptions& aErr) |
|
29 { |
|
30 const char* msg; |
|
31 switch (aErr) |
|
32 { |
|
33 case EUnknownOption: |
|
34 msg = "Unknown option specified"; |
|
35 DisplayUsage (); |
|
36 break; |
|
37 case EMissingDATFile: |
|
38 msg = "Dat file input not specified "; |
|
39 DisplayUsage (); |
|
40 break; |
|
41 case ESupportingExeError: |
|
42 msg = "Unable to execute supporting executable"; |
|
43 break; |
|
44 case EMissingSISFile: |
|
45 msg = "SIS file input not specified "; |
|
46 DisplayUsage (); |
|
47 break; |
|
48 case EUnableToOpenFile: |
|
49 msg = "Unable to open file "; |
|
50 break; |
|
51 case ECorruptCCIFile: |
|
52 msg = "File containing signing chain information is corrupted " ; |
|
53 break; |
|
54 case EErrorExecutingSupportingExeDumpsis: |
|
55 msg = "Error while executing supporting \nexecutable dumpsis.exe"; |
|
56 break; |
|
57 case EErrorExecutingSupportingExeSignsis: |
|
58 msg = "Error while executing supporting \nexecutable signsis.exe"; |
|
59 break; |
|
60 case EErrorExecutingSupportingDumpSwiCertstoreExe: |
|
61 msg = "Error while executing supporting \nexecutable dumpswicertstore.exe"; |
|
62 break; |
|
63 case ENotADerBitString: |
|
64 msg = "Error reading a DER encoded ASN.1 Bit String Type ."; |
|
65 break; |
|
66 case ENotADerSequence: |
|
67 msg = "Error reading a DER Encoded ASN.1 Sequence Type." ; |
|
68 break; |
|
69 case ENotADerInteger: |
|
70 msg = "Error reading a DER Encoded ASN.1 Integer Type." ; |
|
71 break; |
|
72 case ENotADerUtf8String: |
|
73 msg = "Error reading a DER Encoded ASN.1 UTF8 String." ; |
|
74 break; |
|
75 default: |
|
76 msg = "Unknown error"; |
|
77 break; |
|
78 } |
|
79 cerr << CommandName () << ": Error in command: " << msg << endl; |
|
80 } |
|
81 |
|
82 |
|
83 void Options::DisplayVersion() const |
|
84 { |
|
85 cout << "\nDumpInstallFileStatus Utility Version " << KMajorVersion << '.' \ |
|
86 << setw(2) << KMinorVersion << setfill('0') << "\nCopyright (c) 2005-2006 Symbian Software Limited . All rights reserved.\n\n" << flush; |
|
87 } |
|
88 |
|
89 void Options::DisplayUsage() |
|
90 { |
|
91 cout <<"Usage:DumpInstallFileStatusTool [-v][-h][-i] SISFile DATFile Directory Capabilities \n\n" \ |
|
92 " -v Specifies the version of the tool. \n" \ |
|
93 " -h Prints the help message. \n" \ |
|
94 " -i Output licence information \n" \ |
|
95 " SISFile Signed SIS File.\n" \ |
|
96 " DATFile ROM Based SWICertstore.dat.OPTIONAL, if Directory is specified.\n" \ |
|
97 " Directory Writable SWICertstore.OPTIONAL,if swicertstore.dat is specified.\n" \ |
|
98 " Capabilities List of capabilities to be specified by user(OPTIONAL).\n" \ |
|
99 " All Inputs must be specified in the same order as mentioned above.\n\n" <<flush; |
|
100 } |
|
101 |
|
102 |
|
103 Options::Options (int argc, char** argv) |
|
104 :iVersion (false), |
|
105 iHelpFlag (false), |
|
106 iDATFileSpecified (false), |
|
107 iSISFileSpecified (false), |
|
108 iDirectorySpecified (false), |
|
109 iUserCapabilities(0) |
|
110 { |
|
111 StringVector userCapabilities; |
|
112 unsigned char stage = 0; |
|
113 bool ssl = false; |
|
114 string fileInput; |
|
115 while (--argc > 0) |
|
116 { |
|
117 argv++; |
|
118 if ((**argv == '-') || (**argv == '/')) |
|
119 { |
|
120 const char* optPtr = *argv; |
|
121 while (*++optPtr) |
|
122 { |
|
123 switch (*optPtr) |
|
124 { |
|
125 case 'h': |
|
126 case 'H': |
|
127 case '?': |
|
128 { |
|
129 iHelpFlag = true; |
|
130 DisplayUsage(); |
|
131 break; |
|
132 } |
|
133 case 'v': |
|
134 case 'V': |
|
135 { |
|
136 iVersion = true; |
|
137 DisplayVersion(); |
|
138 break; |
|
139 } |
|
140 case 'i' : |
|
141 case 'I' : |
|
142 { |
|
143 ssl = true; |
|
144 break; |
|
145 } |
|
146 |
|
147 default: |
|
148 throw EUnknownOption; |
|
149 } |
|
150 } |
|
151 } |
|
152 |
|
153 else |
|
154 { |
|
155 switch(stage) |
|
156 { |
|
157 case 0: |
|
158 { |
|
159 iSisFile = *argv; |
|
160 iSISFileSpecified = true; |
|
161 break; |
|
162 } |
|
163 case 1: |
|
164 { |
|
165 iDATFile = *argv; |
|
166 iDATFileSpecified = true; |
|
167 break; |
|
168 } |
|
169 |
|
170 default: |
|
171 { |
|
172 string fileInput = *argv; |
|
173 if(PathIsDirectory(fileInput.c_str())) |
|
174 { |
|
175 iCertstore = fileInput; |
|
176 iDirectorySpecified = true; |
|
177 } |
|
178 else if(fileInput.find(".")== string::npos) |
|
179 { |
|
180 string capabilities = fileInput; |
|
181 userCapabilities.push_back(capabilities); |
|
182 } |
|
183 else |
|
184 { |
|
185 throw EUnknownOption; |
|
186 } |
|
187 break; |
|
188 } |
|
189 } |
|
190 stage++; |
|
191 } |
|
192 } |
|
193 |
|
194 //displays OpenSSL copyright notice. |
|
195 if (ssl) |
|
196 { |
|
197 for (int index = 0; index < (sizeof(openSSLLicenseString)/sizeof(openSSLLicenseString[0])); ++index) |
|
198 { |
|
199 cout << openSSLLicenseString [index] << endl; |
|
200 } |
|
201 } |
|
202 |
|
203 //if user capabilities specified. |
|
204 if(userCapabilities.size()) |
|
205 { |
|
206 iUserCapabilities = ConvertUserCapsToInt(userCapabilities); |
|
207 } |
|
208 |
|
209 if(iDirectorySpecified && iDATFileSpecified) |
|
210 { |
|
211 iCertstore.append(" "); |
|
212 iCertstore.append(iDATFile); |
|
213 } |
|
214 |
|
215 if(iDATFileSpecified && !iDirectorySpecified) |
|
216 { |
|
217 iCertstore = iDATFile; |
|
218 } |
|
219 |
|
220 //if only -h or -v is specified,display and exit. |
|
221 if(!iDATFileSpecified && !iDirectorySpecified && !iSISFileSpecified) |
|
222 { |
|
223 exit(0); |
|
224 } |
|
225 |
|
226 if (!iDATFileSpecified && !iDirectorySpecified) |
|
227 { |
|
228 throw EMissingDATFile; |
|
229 } |
|
230 |
|
231 if(!iSISFileSpecified) |
|
232 { |
|
233 throw EMissingSISFile; |
|
234 } |
|
235 } |
|
236 |
|
237 const int Options::ConvertUserCapsToInt(vector <string>& aUserCapabilities) |
|
238 { |
|
239 string listOfCapabilities[KNumberOfCaps]; |
|
240 int userCaps = 0; |
|
241 if(aUserCapabilities.size()) |
|
242 { |
|
243 for(StringVector::iterator userCapsIter = aUserCapabilities.begin(); userCapsIter != aUserCapabilities.end(); ++userCapsIter) |
|
244 { |
|
245 string capabilities = *userCapsIter; |
|
246 //convert each user capability to uppercase. |
|
247 for(int j = 0 ; j < capabilities.length() ; j++) |
|
248 { |
|
249 capabilities[j] = ::toupper(capabilities[j]); |
|
250 } |
|
251 |
|
252 //convert the predefined CapabilityList into uppercase. |
|
253 for(int k = 0 ; k < KNumberOfCaps ; k++) |
|
254 { |
|
255 listOfCapabilities[k] = CapabilityList[k]; |
|
256 for(int j = 0 ; j < listOfCapabilities[k].length() ; j++) |
|
257 { |
|
258 listOfCapabilities[k][j] = ::toupper(listOfCapabilities[k][j]); |
|
259 } |
|
260 } |
|
261 |
|
262 for (int i = 0; i < KNumberOfCaps; i++) |
|
263 { |
|
264 if(capabilities.compare(listOfCapabilities[i])==0) |
|
265 { |
|
266 userCaps += pow(2,i); |
|
267 } |
|
268 } |
|
269 } |
|
270 } |
|
271 return userCaps; |
|
272 } |
|
273 |
|
274 Options::~Options() |
|
275 { |
|
276 } |
|
277 |
|
278 |
|
279 |