|
1 /* |
|
2 * Copyright (c) 2004 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: X.509 Certificate type |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef CCMSX509Certificate_H |
|
21 #define CCMSX509Certificate_H |
|
22 |
|
23 #include "CCMSX509Signed.h" |
|
24 |
|
25 // FORWARD DECLARATIONS |
|
26 class CCMSX509AlgorithmIdentifier; |
|
27 class CCMSX509SubjectPublicKeyInfo; |
|
28 class CX500DistinguishedName; |
|
29 class CCMSX509Validity; |
|
30 class CX509CertExtension; |
|
31 class CX509Certificate; |
|
32 |
|
33 // Extensions |
|
34 class MCMSX509CertificateExtension; |
|
35 |
|
36 // CLASS DECLARATION |
|
37 /** |
|
38 * X.509 CertificateInfo type module |
|
39 * |
|
40 * ASN.1 definition: |
|
41 * -- basic certificate definition |
|
42 * Certificate ::= |
|
43 * SIGNED |
|
44 * {SEQUENCE {version [0] Version DEFAULT v1, |
|
45 * serialNumber CertificateSerialNumber, |
|
46 * signature AlgorithmIdentifier, |
|
47 * issuer Name, |
|
48 * validity Validity, |
|
49 * subject Name, |
|
50 * subjectPublicKeyInfo SubjectPublicKeyInfo, |
|
51 * issuerUniqueIdentifier [1] IMPLICIT UniqueIdentifier OPTIONAL, |
|
52 * -- if present, version must be v2 or v3 |
|
53 * subjectUniqueIdentifier [2] IMPLICIT UniqueIdentifier OPTIONAL, |
|
54 * -- if present, version must be v2 or v3 |
|
55 * extensions [3] Extensions OPTIONAL |
|
56 * }} -- If present, version must be v3 |
|
57 * |
|
58 * @lib cms.lib |
|
59 * @since 3.0 |
|
60 */ |
|
61 class CCMSX509Certificate : public CCMSX509Signed |
|
62 { |
|
63 |
|
64 private: |
|
65 /** |
|
66 * Container for certificate data |
|
67 */ |
|
68 NONSHARABLE_CLASS( CCertificateData ) : public CBase |
|
69 { |
|
70 public: // destructor |
|
71 ~CCertificateData(); |
|
72 |
|
73 public: // data |
|
74 // version |
|
75 TInt iVersion; |
|
76 |
|
77 // serialNumber, owned |
|
78 HBufC8* iSerialNumber; |
|
79 |
|
80 // signature AlgorithmIdentifier, owned |
|
81 CCMSX509AlgorithmIdentifier* iSignature; |
|
82 |
|
83 // issuer Name, owned |
|
84 CX500DistinguishedName* iIssuer; |
|
85 |
|
86 // validity, owned |
|
87 CCMSX509Validity* iValidity; |
|
88 |
|
89 // subject Name, owned |
|
90 CX500DistinguishedName* iSubject; |
|
91 |
|
92 // subjectPublicKeyInfo, owned |
|
93 CCMSX509SubjectPublicKeyInfo* iSubjectPublicKeyInfo; |
|
94 |
|
95 // issuerUniqueIdentifier UniqueIdentifier ::= BIT STRING, owned |
|
96 HBufC8* iIssuerUniqueIdentifier; |
|
97 |
|
98 // subjectUniqueIdentifier UniqueIdentifier, owned |
|
99 HBufC8* iSubjectUniqueIdentifier; |
|
100 }; |
|
101 |
|
102 public: // Constructors and destructor |
|
103 /** |
|
104 * Two-phased constructor. |
|
105 */ |
|
106 IMPORT_C static CCMSX509Certificate* NewL(); |
|
107 |
|
108 /** |
|
109 * Two-phased constructor. Copies the data from the |
|
110 * CX509Certificate parameter. |
|
111 * |
|
112 * @param aCertificate Certificate from which the data is |
|
113 * copied. |
|
114 */ |
|
115 IMPORT_C static CCMSX509Certificate* NewL( |
|
116 const CX509Certificate& aCertificate ); |
|
117 |
|
118 /** |
|
119 * Two-phased constructor. Copies of the parameters are made. |
|
120 * |
|
121 * @param aSerialNumber CertificateSerialNumber value |
|
122 * @param aSignature AlgorithmIdentifier value |
|
123 * @param aIssuer Name value |
|
124 * @param aValidity Validity value |
|
125 * @param aSubject Name value |
|
126 * @param aSubjectPublicKeyInfo SubjectPublicKeyInfo value |
|
127 * @param aAlgorithmIdentifier identifies the algorithm used in |
|
128 * the signature |
|
129 * @param aEncrypted must be the result of applying a hashing |
|
130 * procedure to the DER-encoded octets of a value of |
|
131 * toBeSigned and then applying an encipherment |
|
132 * procedure to those octets |
|
133 */ |
|
134 IMPORT_C static CCMSX509Certificate* NewL( |
|
135 const TDesC8& aSerialNumber, |
|
136 const CCMSX509AlgorithmIdentifier& aSignature, |
|
137 const CX500DistinguishedName& aIssuer, |
|
138 const CCMSX509Validity& aValidity, |
|
139 const CX500DistinguishedName& aSubject, |
|
140 const CCMSX509SubjectPublicKeyInfo& aSubjectPublicKeyInfo, |
|
141 const CCMSX509AlgorithmIdentifier& aAlgorithmIdentifier, |
|
142 const TDesC8& aEncrypted |
|
143 ); |
|
144 |
|
145 /** |
|
146 * Destructor. |
|
147 */ |
|
148 virtual ~CCMSX509Certificate(); |
|
149 |
|
150 public: // New functions |
|
151 /** |
|
152 * Getter for the version. |
|
153 * @since 3.0 |
|
154 * @return Version |
|
155 */ |
|
156 IMPORT_C TInt Version() const; |
|
157 |
|
158 /** |
|
159 * Getter for the serialNumber. |
|
160 * @since 3.0 |
|
161 * @return CertificateSerialNumber |
|
162 */ |
|
163 IMPORT_C const TDesC8& SerialNumber() const; |
|
164 |
|
165 /** |
|
166 * Getter for the signature. |
|
167 * @since 3.0 |
|
168 * @return AlgorithmIdentifier |
|
169 */ |
|
170 IMPORT_C const CCMSX509AlgorithmIdentifier& Signature() const; |
|
171 |
|
172 /** |
|
173 * Getter for the issuer. |
|
174 * @since 3.0 |
|
175 * @return X.500 DistinguishedName of the issuer of the certificate. |
|
176 */ |
|
177 IMPORT_C const CX500DistinguishedName& Issuer() const; |
|
178 |
|
179 /** |
|
180 * Getter for the validity. |
|
181 * @since 3.0 |
|
182 * @return Validity |
|
183 */ |
|
184 IMPORT_C const CCMSX509Validity& Validity() const; |
|
185 |
|
186 /** |
|
187 * Getter for the subject. |
|
188 * @since 3.0 |
|
189 * @return X.500 DistinguishedName of the subject of the certificate. |
|
190 */ |
|
191 IMPORT_C const CX500DistinguishedName& Subject() const; |
|
192 |
|
193 /** |
|
194 * Getter for the subjectPublicKeyInfo. |
|
195 * @since 3.0 |
|
196 * @return SubjectPublicKeyInfo |
|
197 */ |
|
198 IMPORT_C const CCMSX509SubjectPublicKeyInfo& |
|
199 SubjectPublicKeyInfo() const; |
|
200 |
|
201 /** |
|
202 * Getter for the issuerUniqueIdentifier. |
|
203 * @since 3.0 |
|
204 * @return UniqueIdentifier or NULL |
|
205 */ |
|
206 IMPORT_C const TDesC8* |
|
207 IssuerUniqueIdentifier() const; |
|
208 |
|
209 /** |
|
210 * Getter for the subjectUniqueIdentifier. |
|
211 * @since 3.0 |
|
212 * @return UniqueIdentifier or NULL |
|
213 */ |
|
214 IMPORT_C const TDesC8* |
|
215 SubjectUniqueIdentifier() const; |
|
216 |
|
217 /** |
|
218 * Setter for the version. |
|
219 * @since 3.0 |
|
220 * @param aVersion Version |
|
221 */ |
|
222 IMPORT_C void SetVersion( const TInt aVersion ); |
|
223 |
|
224 /** |
|
225 * Setter for the serialNumber. |
|
226 * @since 3.0 |
|
227 * @param aSerialNumber CertificateSerialNumber |
|
228 */ |
|
229 IMPORT_C void SetSerialNumberL( const TDesC8& aSerialNumber ); |
|
230 |
|
231 /** |
|
232 * Setter for the signature. |
|
233 * @since 3.0 |
|
234 * @param aSignature AlgorithmIdentifier |
|
235 */ |
|
236 IMPORT_C void |
|
237 SetSignatureL( const CCMSX509AlgorithmIdentifier& aSignature ); |
|
238 |
|
239 /** |
|
240 * Setter for the issuer. |
|
241 * @since 3.0 |
|
242 * @param aIssuer The X.500 DistinguishedName of the issuer of |
|
243 * the certificate |
|
244 */ |
|
245 IMPORT_C void |
|
246 SetIssuerL( const CX500DistinguishedName& aIssuer ); |
|
247 |
|
248 /** |
|
249 * Setter for the validity. |
|
250 * @since 3.0 |
|
251 * @param aValidity Validity |
|
252 */ |
|
253 IMPORT_C void |
|
254 SetValidityL( const CCMSX509Validity& aValidity ); |
|
255 |
|
256 /** |
|
257 * Setter for the Subject. |
|
258 * @since 3.0 |
|
259 * @param aSubject X.500 DistinguishedName of the subject of |
|
260 * the certificate |
|
261 */ |
|
262 IMPORT_C void |
|
263 SetSubjectL( const CX500DistinguishedName& aSubject ); |
|
264 |
|
265 /** |
|
266 * Setter for the SubjectPublicKeyInfo. |
|
267 * @since 3.0 |
|
268 * @param aSubjectPublicKeyInfo SubjectPublicKeyInfo |
|
269 */ |
|
270 IMPORT_C void SetSubjectPublicKeyInfoL( |
|
271 const CCMSX509SubjectPublicKeyInfo& aSubjectPublicKeyInfo ); |
|
272 |
|
273 /** |
|
274 * Setter for the issuerUniqueIdentifier. Also makes sure |
|
275 * version is v2 or v3 (integer values 1 and 2). |
|
276 * @since 3.0 |
|
277 * @param aIssuerUniqueIdentifier UniqueIdentifier (BIT STRING) |
|
278 */ |
|
279 IMPORT_C void SetIssuerUniqueIdentifierL( |
|
280 const TDesC8& aIssuerUniqueIdentifier ); |
|
281 |
|
282 /** |
|
283 * Setter for the subjectUniqueIdentifier. Also makes sure |
|
284 * version is v2 or v3 (integer values 1 and 2). |
|
285 * @since 3.0 |
|
286 * @param aSubjectUniqueIdentifier UniqueIdentifier (BIT STRING) |
|
287 */ |
|
288 IMPORT_C void SetSubjectUniqueIdentifierL( |
|
289 const TDesC8& aSubjectUniqueIdentifier ); |
|
290 |
|
291 /** |
|
292 * Returns ASN1 encoder for the ToBeSigned part. |
|
293 * @since 3.0 |
|
294 * @return ASN1 encoder for the ToBeSigned part. |
|
295 */ |
|
296 IMPORT_C CASN1EncBase* ToBeSignedEncoderLC() const; |
|
297 |
|
298 public: // Functions from base classes |
|
299 |
|
300 /** |
|
301 * From MCMSModule |
|
302 * @since 3.0 |
|
303 * @param aRawData raw-data to be parsed in this instance |
|
304 */ |
|
305 void DecodeL( const TDesC8& aRawData ); |
|
306 |
|
307 /** |
|
308 * From MCMSModule |
|
309 * @since 3.0 |
|
310 * @return Returns ASN1 encoder and leaves it in CleanupStack |
|
311 */ |
|
312 CASN1EncBase* EncoderLC() const; |
|
313 |
|
314 protected: // New functions |
|
315 |
|
316 /** |
|
317 * Protected construction to allow derivation |
|
318 */ |
|
319 IMPORT_C void ConstructL( |
|
320 const TDesC8& aSerialNumber, |
|
321 const CCMSX509AlgorithmIdentifier& aSignature, |
|
322 const CX500DistinguishedName& aIssuer, |
|
323 const CCMSX509Validity& aValidity, |
|
324 const CX500DistinguishedName& aSubject, |
|
325 const CCMSX509SubjectPublicKeyInfo& aSubjectPublicKeyInfo, |
|
326 const CCMSX509AlgorithmIdentifier& aAlgorithmIdentifier, |
|
327 const TDesC8& aEncrypted |
|
328 ); |
|
329 |
|
330 /** |
|
331 * Protected construction to allow derivation |
|
332 */ |
|
333 IMPORT_C void ConstructL( ); |
|
334 |
|
335 /** |
|
336 * Protected construction to allow derivation. |
|
337 */ |
|
338 IMPORT_C void ConstructL( const CX509Certificate& aCertificate ); |
|
339 |
|
340 /** |
|
341 * C++ default constructor. |
|
342 */ |
|
343 IMPORT_C CCMSX509Certificate( ); |
|
344 |
|
345 private: // New functions |
|
346 |
|
347 /** |
|
348 * Copies the data from the CX509Certificate object. |
|
349 */ |
|
350 void SetDataL( const CX509Certificate& aCertificate ); |
|
351 |
|
352 private: // Data |
|
353 // Contains the actual data, owned |
|
354 CCertificateData* iData; |
|
355 |
|
356 // Reserved for extensions |
|
357 MCMSX509CertificateExtension* iReserved; |
|
358 |
|
359 }; |
|
360 |
|
361 #endif // CCMSX509Certificate_H |
|
362 |
|
363 // End of File |