|
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 using namespace std; |
|
22 |
|
23 void Options::DisplayError (const Exceptions& aErr) |
|
24 { |
|
25 const char* msg; |
|
26 switch (aErr) |
|
27 { |
|
28 case EUnknownOption: |
|
29 msg = "unknown option specified" ; |
|
30 DisplayUsage (); |
|
31 break; |
|
32 case EMissingDATFile: |
|
33 msg = "Dat File Input not specified "; |
|
34 DisplayUsage (); |
|
35 break; |
|
36 case EMissingSISFile: |
|
37 msg = "SIS File Input not specified "; |
|
38 DisplayUsage (); |
|
39 break; |
|
40 case EUnableToOpenFile: |
|
41 msg = "Unable to open file " ; |
|
42 break; |
|
43 case ESupportingExeError: |
|
44 msg = "Unable to execute Supporting Executable.Set Environment PATH" ; |
|
45 DisplayUsage (); |
|
46 break; |
|
47 case ECorruptCCIFile: |
|
48 msg = "File containing signing chain information is corrupted " ; |
|
49 break; |
|
50 case EErrorExecutingSupportingExeSignsis: |
|
51 msg = "Error while Executing Supporting \nExecutable SignSIS.exe.Either SIS File is Unsigned or does not exist in the specified path" ; |
|
52 break; |
|
53 case EErrorExecutingSupportingDumpSwiCertstoreExe: |
|
54 msg = "Error while Executing Supporting \nExecutable DumpSWICertstoreTool.exe" ; |
|
55 break; |
|
56 case ENotADerBitString: |
|
57 msg = "Error reading a DER encoded ASN.1 Bit String Type ."; |
|
58 break; |
|
59 case ENotADerSequence: |
|
60 msg = "Error reading a DER Encoded ASN.1 Sequence Type." ; |
|
61 break; |
|
62 case ENotADerInteger: |
|
63 msg = "Error reading a DER Encoded ASN.1 Integer Type." ; |
|
64 break; |
|
65 case ENotADerUtf8String: |
|
66 msg = "Error reading a DER Encoded ASN.1 UTF8 String." ; |
|
67 break; |
|
68 default: |
|
69 msg = "unknown error"; |
|
70 break; |
|
71 } |
|
72 cerr << CommandName () << ": Error in command: " << msg << std::endl <<std::endl; |
|
73 } |
|
74 |
|
75 |
|
76 void Options::DisplayVersion() const |
|
77 { |
|
78 cout << "\nDumpChainValidity Utility Version " << KMajorVersion << '.' \ |
|
79 << setw(2) << KMinorVersion << setfill('0') << "\nCopyright (c) 2005-2006 Symbian Software Limited . All rights reserved.\n\n" << flush; |
|
80 } |
|
81 |
|
82 |
|
83 void Options::DisplayUsage() |
|
84 { |
|
85 cout << "Usage: DumpChainValidityTool [-v][-h][-i][-l] Signed_SIS_Input DAT_Input Directory \n\n" \ |
|
86 " -v specifies the version of the tool \n" \ |
|
87 " -h Prints the help message\n" \ |
|
88 " -i Output licence information \n" \ |
|
89 " -l Displays unified capabilities list of the validated chains \n" \ |
|
90 "DAT_Input ROM Based SWICertstore.dat.Optional if Directory is specified \n" \ |
|
91 "Directory Writable SWICertstore.Optional if swicertstore.dat is specified\n" \ |
|
92 "SIS_Input Signed SIS File\n" \ |
|
93 "All inputs must be specified in the same order as mentioned above.\n\n" << flush; |
|
94 } |
|
95 |
|
96 |
|
97 Options::Options (int argc, char** argv) |
|
98 :iList(false), |
|
99 iVersion (false), |
|
100 iHelpFlag (false), |
|
101 iDATFileSpecified (false), |
|
102 iSISFileSpecified (false), |
|
103 iDirectorySpecified (false) |
|
104 { |
|
105 iDATFile.empty(); |
|
106 iCertstore.empty(); |
|
107 iSISFile.empty(); |
|
108 unsigned char stage = 0; |
|
109 bool ssl = false; |
|
110 int argCount = argc; |
|
111 while (--argc > 0) |
|
112 { |
|
113 argv++; |
|
114 if ((**argv == '-') || (**argv == '/')) |
|
115 { |
|
116 const char* optPtr = *argv; |
|
117 while (*++optPtr) |
|
118 { |
|
119 switch (*optPtr) |
|
120 { |
|
121 case 'h': |
|
122 case 'H': |
|
123 case '?': |
|
124 { |
|
125 iHelpFlag = true; |
|
126 DisplayUsage(); |
|
127 break; |
|
128 } |
|
129 case 'v': |
|
130 case 'V': |
|
131 { |
|
132 iVersion = true; |
|
133 DisplayVersion(); |
|
134 break; |
|
135 } |
|
136 case 'i' : |
|
137 case 'I' : |
|
138 { |
|
139 ssl = true; |
|
140 break; |
|
141 } |
|
142 case 'l': |
|
143 case 'L': |
|
144 iList = true; |
|
145 break; |
|
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 case 2: |
|
170 { |
|
171 iCertstore = *argv; |
|
172 iDirectorySpecified = true; |
|
173 break; |
|
174 } |
|
175 default: |
|
176 throw EUnknownOption; |
|
177 } |
|
178 stage++; |
|
179 } |
|
180 } |
|
181 |
|
182 //displays OpenSSL copyright notice. |
|
183 if (ssl) |
|
184 { |
|
185 for (int index = 0; index < (sizeof(openSSLLicenseString)/sizeof(openSSLLicenseString[0])); ++index) |
|
186 { |
|
187 cout << openSSLLicenseString [index] << endl; |
|
188 } |
|
189 } |
|
190 |
|
191 CheckCmdLineExceptions(); |
|
192 } |
|
193 |
|
194 void Options::CheckCmdLineExceptions() |
|
195 { |
|
196 if(iDirectorySpecified && iDATFileSpecified) |
|
197 { |
|
198 iCertstore.append(" "); |
|
199 iCertstore.append(iDATFile); |
|
200 } |
|
201 |
|
202 |
|
203 if(iDATFileSpecified && !iDirectorySpecified) |
|
204 { |
|
205 iCertstore=iDATFile; |
|
206 } |
|
207 |
|
208 //if only -h or -v or both are specified |
|
209 if(!iDATFileSpecified && !iDirectorySpecified && !iSISFileSpecified ) |
|
210 { |
|
211 exit(0); |
|
212 } |
|
213 |
|
214 //Neither dat file nor directory is specified |
|
215 if (!iDATFileSpecified && !iDirectorySpecified ) |
|
216 { |
|
217 throw EMissingDATFile; |
|
218 } |
|
219 |
|
220 //no sis file specified |
|
221 if(!iSISFileSpecified) |
|
222 { |
|
223 throw EMissingSISFile; |
|
224 } |
|
225 } |
|
226 |
|
227 Options::~Options() |
|
228 { |
|
229 } |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |