|
1 /* |
|
2 * Copyright (c) 2002 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 "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: Extracts relevant certificate information to be shown to user. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef X509CERTNAMEPARSER_H |
|
21 #define X509CERTNAMEPARSER_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32std.h> |
|
25 #include <x509gn.h> // TGNType |
|
26 //------------------------------------------------------------------------------ |
|
27 // CONSTANTS |
|
28 _LIT(KX509CNPComma,", "); |
|
29 |
|
30 // FORWARD DECLARATIONS |
|
31 class CX509Certificate; |
|
32 class CX500DistinguishedName; |
|
33 class CX509CertExtension; |
|
34 class CX509AltNameExt; |
|
35 |
|
36 |
|
37 //------------------------------------------------------------------------------ |
|
38 // |
|
39 // CLASS DECLARATION |
|
40 |
|
41 /** |
|
42 * Static class CX509CertNameParser provides functions that extract relevant |
|
43 * information for user from x.509 certificate. CX509CertNameParser |
|
44 * extracts the most important name info and tries to guarantee uniqueness |
|
45 * in a list of certificates. |
|
46 * @lib X509CertNameParser.dll |
|
47 * @since Series60_2.0 |
|
48 */ |
|
49 class X509CertNameParser |
|
50 { |
|
51 public: // Constructors and destructor |
|
52 |
|
53 |
|
54 public: // New functions |
|
55 |
|
56 /** |
|
57 * PrimaryAndSecondaryNameL_description. PrimaryAndSecondaryNameL |
|
58 * member function is used to collect Primary and Secondsry Name data of |
|
59 * certificate information. The first found non-empty naming element and |
|
60 * not equal with label is Primary Name. |
|
61 * The second available information element not equal with label is |
|
62 * Secondary Name. |
|
63 * @since Series60_2.0 |
|
64 * @param aCertificate Certificate where the information is extracted. |
|
65 * @param aPrimaryName IN null pointer, OUT first found name element |
|
66 * according to name element order or KNulDesC if Primary Name isn't |
|
67 * found. |
|
68 * @param aSecondaryName IN null pointer, OUT second found name element |
|
69 * according to name element order or KNullDesC if Secondary Name isn't found. |
|
70 * @param aLabel Label of the certificate. Found elements are compared to |
|
71 * label to make sure that aPrimaryName and aSecondaryName differ from |
|
72 * label. If label doesn't exist, this can be left away. |
|
73 * @return status, at the moment always KErrNone |
|
74 */ |
|
75 IMPORT_C static TInt PrimaryAndSecondaryNameL( |
|
76 const CX509Certificate& aCertificate, |
|
77 HBufC*& aPrimaryName, |
|
78 HBufC*& aSecondaryName, |
|
79 const TDesC& aLabel =KNullDesC ); |
|
80 |
|
81 /** |
|
82 * SubjectFullNameL_description. SubjectFullNameL member function is |
|
83 * used to collect all relevant subject information from the subject |
|
84 * and from the subject alternative name extension of the certificate. |
|
85 * @since Series60_2.0 |
|
86 * @param aCertificate Certificate where the information is extracted. |
|
87 * @param aSubjectName IN null pointer, OUT Full subject name of the |
|
88 * certificate or KNullDesC if nothing is found. |
|
89 * @param aLabel Label of the certificate. Found elements are compared to |
|
90 * label to make sure that aPrimaryName and aSecondaryName differ from |
|
91 * label. If label doesn't exist, this can be left away. |
|
92 * @return status, at the moment always KErrNone |
|
93 */ |
|
94 IMPORT_C static TInt SubjectFullNameL( |
|
95 const CX509Certificate& aCertificate, |
|
96 HBufC*& aSubjectName, |
|
97 const TDesC& aLabel = KNullDesC ); |
|
98 |
|
99 /** |
|
100 * IssuerFullNameL_description. IssuerFullNameL member function is |
|
101 * used to collect all the relevant Issuer information from the Issuer |
|
102 * and from the Issuer alternative name extension of the certificate. |
|
103 * @since Series60_2.0 |
|
104 * @param aCertificate Certificate where the information is extracted. |
|
105 * @param aIssuerName IN null pointer, OUT Full issuer name of the |
|
106 * certificate or KNullDesC if nothing is found.. |
|
107 * @return status, at the moment always KErrNone |
|
108 */ |
|
109 IMPORT_C static TInt IssuerFullNameL( |
|
110 const CX509Certificate& aCertificate, |
|
111 HBufC*& aIssuerName ); |
|
112 |
|
113 public: // Functions from base classes |
|
114 |
|
115 protected: // New functions |
|
116 |
|
117 protected: // Functions from base classes |
|
118 |
|
119 private: //Private data types |
|
120 |
|
121 /** |
|
122 * enum TX509CNPNameType declaration. |
|
123 * |
|
124 */ |
|
125 enum TX509CNPNameType |
|
126 { |
|
127 EX509CNPPrimAndSecond, |
|
128 EX509CNPFullName |
|
129 }; |
|
130 |
|
131 /** |
|
132 * enum TX509CNPNameElement declaration. |
|
133 * This enum defines the naming element order that can be changed by |
|
134 * chancing the order of enum's members. |
|
135 */ |
|
136 enum TX509CNPNameElement |
|
137 { // DN = Distinguish name, Alt = Alternative name |
|
138 EDNCommonName = 1, // common name of the subject |
|
139 ECritAltRFC822Name, // rfc822Name of the critical subject alternative name |
|
140 EDNOrganizationName, // OrganizationName of the subject |
|
141 EDNOrganizationalUnitName, // OrganizationalUnitName of the subject |
|
142 ECritAltDNSName, // dNSName of the critical subject alternative name |
|
143 ECritAltURI, // URI of the critical subject alternative name |
|
144 ECritAltDirectoryName, // directoryName of the critical subject alternative name |
|
145 ECritAltIPAddress, // iPAddress of the critical subject alternative name |
|
146 EAltRFC822Name, // rfc822Name of the subject alternative name |
|
147 EAltDNSName, // dNSName of the subject alternative name |
|
148 EAltURI, // URI of the subject alternative name |
|
149 EDNCountryName, // countryName of the subject |
|
150 EDNStateOrProvinceName, // stateOrProvinceName of the subject |
|
151 EDNLocalityName, // localityName of the subject |
|
152 EAltDirectoryName, // directoryName of the subject alternative name |
|
153 EAltIPAddress // iPAddress of the subject alternative name |
|
154 }; |
|
155 |
|
156 private: |
|
157 |
|
158 /** |
|
159 * C++ default constructor. |
|
160 */ |
|
161 X509CertNameParser(); |
|
162 |
|
163 |
|
164 private: //New functions |
|
165 |
|
166 /** |
|
167 * GetFullNameL_description. |
|
168 * Common function for FullName functions. |
|
169 * @since Series60_2.0 |
|
170 * @param aDN Distinguished name |
|
171 * @param aExtension Pointer to Extension |
|
172 * @param aSubjectName IN null pointer, OUT Full subject name of the |
|
173 * certificate or KNullDesC if nothing is found. |
|
174 * @return TInt type value. |
|
175 */ |
|
176 static TInt GetFullNameL( |
|
177 const CX500DistinguishedName& aDN, |
|
178 const CX509CertExtension* aExtension, |
|
179 HBufC*& aName, |
|
180 const TDesC& aLabel = KNullDesC ); |
|
181 |
|
182 |
|
183 /** |
|
184 * GetNamePartsL_description. |
|
185 * Collects all the name parts of the certificate to array. One name element |
|
186 * is placed to one element of array. |
|
187 * @since Series60_2.0 |
|
188 * @param aDN Distinguished name |
|
189 * @param aExtension Pointer to Extension |
|
190 * @param aNameArray Found name elements are appended to this array. |
|
191 * @param aNameType EX509CNPPrimAndSecond or EX509CNPFullName |
|
192 * @return TInt type value. |
|
193 */ |
|
194 static TInt GetNamePartsL( |
|
195 const CX500DistinguishedName& aDN, |
|
196 const CX509CertExtension* aExtension, |
|
197 CDesCArray& aNameArray, |
|
198 TX509CNPNameType aNameType ); |
|
199 |
|
200 /** |
|
201 * GetDNPartL_description. |
|
202 * Gets one name element of the DN identified by OID. |
|
203 * @since Series60_2.0 |
|
204 * @param aDN Distinguished name |
|
205 * @param aSubPartOID OID of the distinguished name subpart |
|
206 * @param aNameArray Found name element is appended to this array. |
|
207 * @return void |
|
208 */ |
|
209 static void GetDNPartL( |
|
210 const CX500DistinguishedName& aDN, |
|
211 const TDesC& aSubPartOID, |
|
212 CDesCArray& aNameArray ); |
|
213 |
|
214 /** |
|
215 * GetDNPartAllL_description. |
|
216 * Gets all name elements of the DN identified by one OID. |
|
217 * @since Series60_2.0 |
|
218 * @param aDN Distinguished name |
|
219 * @param aSubPartOID OID of the distinguished name subpart |
|
220 * @param aNameArray Found name elements are appended to this array. |
|
221 * @return void |
|
222 */ |
|
223 static void GetDNPartAllL( |
|
224 const CX500DistinguishedName& aDN, |
|
225 const TDesC& aSubPartOID, |
|
226 CDesCArray& aNameArray ); |
|
227 |
|
228 /** |
|
229 * GetAltNamePartL_description. |
|
230 * Gets all elements of alternative name identified by one OID. |
|
231 * @since Series60_2.0 |
|
232 * @param aAltName Alternative name extension |
|
233 * @param aSubPartType Type of the alternative name subpart |
|
234 * @param aNameArray Found name elements are appended to this array. |
|
235 * @return void |
|
236 */ |
|
237 static void GetAltNamePartL( |
|
238 const CX509AltNameExt& aAltName, |
|
239 const TGNType& aSubPartType, |
|
240 CDesCArray& aNameArray ); |
|
241 |
|
242 /** |
|
243 * HandleAltNameL_description. |
|
244 * Handles error. If error is KErrNone, KErrArgument or KErrNotSupported, it just |
|
245 * returns aError, otherwise it leaves with aError. |
|
246 * @since Series60_2.0 |
|
247 * @param aError Error |
|
248 * @return TInt aError |
|
249 */ |
|
250 static TInt AddAltNameToArrayL( |
|
251 TInt aError, |
|
252 CX509DomainName* aDomainName, |
|
253 CDesCArray& aNameArray ); |
|
254 |
|
255 /** |
|
256 * CompareAndAddNameL_description. |
|
257 * Adds proposal to array if none of the elements of array isn't equal |
|
258 * with proposal. |
|
259 * @since Series60_2.0 |
|
260 * @param aProposal |
|
261 * @param aNameArray |
|
262 * @return void. |
|
263 */ |
|
264 static void CompareAndAddNameL( |
|
265 const TDesC& aProposal, |
|
266 CDesCArray& aNameArray ); |
|
267 |
|
268 /** |
|
269 * AddToBufLC_description. |
|
270 * Appends aName to aBuf. If aBuf isn't NULL, first aBuf is deleted and |
|
271 * memory is allocated for existing data and for aName. |
|
272 * @since Series60_2.0 |
|
273 * @param aName Desciptor that is appended to aBuf |
|
274 * @param aBuf IN Null pointer or buffer |
|
275 * @return void. |
|
276 */ |
|
277 static void AddToBufLD( const TDesC& aName, HBufC*& aBuf ); |
|
278 |
|
279 /** |
|
280 * HandleErrorL_description. |
|
281 * Handles error. If error is KErrNone, KErrArgument or KErrNotSupported, it just |
|
282 * returns aError, otherwise it leaves with aError. |
|
283 * @since Series60_2.0 |
|
284 * @param aError Error |
|
285 * @return TInt aError |
|
286 */ |
|
287 static TInt HandleErrorL( TInt aError ); |
|
288 |
|
289 }; |
|
290 |
|
291 #endif // X509CERTNAMEPARSER_H |
|
292 |
|
293 // End of File |