|
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 "osinterface.h" |
|
22 |
|
23 void Options::DisplayError (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 EInvalidFile: |
|
33 msg = "Invalid file specified "; |
|
34 break; |
|
35 case ECannotOpenFile: |
|
36 msg = "Cannot open file or file does'nt exist"; |
|
37 break; |
|
38 case ENotAPermanentFileStore: |
|
39 msg = "Not a Permanent File Store"; |
|
40 break; |
|
41 case EInvalidCertificateChain: |
|
42 msg = "Invalid Certificate Chain"; |
|
43 break; |
|
44 default: |
|
45 msg = "unknown error"; |
|
46 break; |
|
47 } |
|
48 cerr << CommandName () << ": Error in command: " << msg << endl; |
|
49 } |
|
50 |
|
51 void Options::DisplayUsage () |
|
52 { |
|
53 cout << "Usage: DumpSWICertstoreTool [-v][-h][-i][-c] [-y] [-d] datfile directory \n" \ |
|
54 " -v specifies the version of the tool. \n" \ |
|
55 " -h Prints the help message.\n" \ |
|
56 " -i Output licence information \n" \ |
|
57 " -c Extracts the certificate. \n" \ |
|
58 " -y(Deprecated) hidden option which dumps the certificates in pem format \n\t\talong with their capabilities and mandatory status \n" \ |
|
59 " -d hidden option which dumps the certificates in pem format \n\t\talong with details of capabilities and mandatory status \n" \ |
|
60 " datfile swicertstore.dat(ROM Based). \n" \ |
|
61 " directory directory where writable certstore files exists. \n \n" <<flush; |
|
62 } |
|
63 |
|
64 void Options::DisplayVersion() |
|
65 { |
|
66 cout << "\nDumpSWICertstore Utility Version " << KMajorVersion << '.' \ |
|
67 << setw(2) << KMinorVersion << setfill('0') << "\nCopyright (c) 2005-2006 Symbian Software Limited . All rights reserved.\n\n" << flush; |
|
68 } |
|
69 |
|
70 |
|
71 Options::Options (int argc, char** argv) |
|
72 :iVersion (false), |
|
73 iHelpFlag (false), |
|
74 iROMCertstore (false), |
|
75 iCBasedCertstore (false), |
|
76 iNoOfDirectories (0), |
|
77 iCertificate (false), |
|
78 iCreateCCI (false), |
|
79 iCreateDetailCCI (false) |
|
80 { |
|
81 int isDat = 0; |
|
82 bool ssl = false; |
|
83 while (--argc > 0) |
|
84 { |
|
85 argv++; |
|
86 if ((**argv == '-') || (**argv == '/')) |
|
87 { |
|
88 const char* optPtr = *argv; |
|
89 while (*++optPtr) |
|
90 { |
|
91 switch (*optPtr) |
|
92 { |
|
93 case 'h': |
|
94 case 'H': |
|
95 case '?': |
|
96 { |
|
97 iHelpFlag = true; |
|
98 DisplayUsage(); |
|
99 break; |
|
100 } |
|
101 case 'v': |
|
102 case 'V': |
|
103 { |
|
104 iVersion = true; |
|
105 DisplayVersion(); |
|
106 break; |
|
107 } |
|
108 case 'i' : |
|
109 case 'I' : |
|
110 { |
|
111 ssl = true; |
|
112 break; |
|
113 } |
|
114 case 'c': |
|
115 case 'C': |
|
116 iCertificate = true; |
|
117 break; |
|
118 case 'y': |
|
119 case 'Y': |
|
120 iCreateCCI = true; |
|
121 break; |
|
122 case 'd': |
|
123 case 'D': |
|
124 iCreateDetailCCI = true; |
|
125 break; |
|
126 default: |
|
127 throw EUnknownOption; |
|
128 } |
|
129 } |
|
130 } |
|
131 else |
|
132 { |
|
133 string fileName = *argv; |
|
134 //checks whether it is a file or directory |
|
135 if(OSInterface::CheckIfDirectory(fileName.c_str())) |
|
136 { |
|
137 iNoOfDirectories++; |
|
138 iCBasedCertstore = true; |
|
139 int pos = fileName.find_last_of("\\" ,fileName.length()); |
|
140 if(pos == (fileName.length()-1)) |
|
141 { |
|
142 fileName.replace(pos,1,""); |
|
143 } |
|
144 |
|
145 iDirFiles = OSInterface::ExtractFilesFromDirectory(fileName); |
|
146 } |
|
147 else |
|
148 { |
|
149 iROMCertstore = true; |
|
150 iROMCertstoreFileName = fileName.c_str(); |
|
151 } |
|
152 } |
|
153 } |
|
154 |
|
155 //displays OpenSSL copyright notice. |
|
156 if (ssl) |
|
157 { |
|
158 for (int index = 0; index < (sizeof(openSSLLicenseString)/sizeof(openSSLLicenseString[0])); ++index) |
|
159 { |
|
160 cout << openSSLLicenseString [index] << endl; |
|
161 } |
|
162 } |
|
163 |
|
164 if(iNoOfDirectories > 1) |
|
165 { |
|
166 throw EUnknownOption; |
|
167 } |
|
168 } |
|
169 |
|
170 |
|
171 Options::~Options() |
|
172 { |
|
173 } |