|
1 /* |
|
2 * Copyright (c) 1998-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 * X.509 key classes and utility classes for key encoding/decoding. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 /** |
|
23 @file |
|
24 @internalTechnology |
|
25 */ |
|
26 |
|
27 #if !defined (__X509KEYS_H__) |
|
28 #define __X509KEYS_H__ |
|
29 |
|
30 #include <e32base.h> |
|
31 #include <e32std.h> |
|
32 #include <asymmetrickeys.h> |
|
33 #include <asymmetric.h> |
|
34 #include <hash.h> |
|
35 #include <bigint.h> |
|
36 #include <signed.h> |
|
37 |
|
38 // Forward declarations |
|
39 class CASN1EncBase; |
|
40 class CASN1EncContainer; |
|
41 class CASN1EncSequence; |
|
42 class CASN1EncBitString; |
|
43 |
|
44 class CX509RSAPublicKey : public CRSAPublicKey |
|
45 /** Adds the capability to decode DER-encoded RSA public keys. |
|
46 * |
|
47 * Adds a commitment to a specific encoding scheme allowing X.509 RSA public key |
|
48 * superclasses to remain encoding-independent. |
|
49 * |
|
50 * @publishedAll |
|
51 * @released |
|
52 * |
|
53 * @since v6.0 |
|
54 */ |
|
55 { |
|
56 public: |
|
57 /** Creates a new RSA Public key object from the specified buffer containing the |
|
58 * encoded binary representation. |
|
59 * |
|
60 * Initialises the object from its encoded binary form into an internal representation. |
|
61 * |
|
62 * @param aBinaryData The encoded binary representation. |
|
63 * @return A pointer to the new CX509RSAPublicKey object. */ |
|
64 IMPORT_C static CX509RSAPublicKey* NewL(const TDesC8& aBinaryData); |
|
65 |
|
66 /** Creates a new RSA Public Key object from the specified buffer containing the |
|
67 * encoded binary representation, and puts a pointer to it onto the cleanup stack. |
|
68 * |
|
69 * @param aBinaryData The encoded binary representation. |
|
70 * @return A pointer to the new CX509RSAPublicKey object. */ |
|
71 IMPORT_C static CX509RSAPublicKey* NewLC(const TDesC8& aBinaryData); |
|
72 |
|
73 /** Creates a new RSA Public key object from the specified buffer containing the |
|
74 * encoded binary representation, starting at the specified offset. |
|
75 * |
|
76 * @param aBinaryData The encoded binary representation. |
|
77 * @param aPos The offset position from which to start decoding. |
|
78 * @return A pointer to the new CX509RSAPublicKey object. */ |
|
79 IMPORT_C static CX509RSAPublicKey* NewL(const TDesC8& aBinaryData, TInt& aPos); |
|
80 |
|
81 /** Creates a new RSA Public key object from the specified buffer containing the |
|
82 * encoded binary representation, starting at the specified offset, and puts |
|
83 * a pointer to it onto the cleanup stack. |
|
84 * |
|
85 * @param aBinaryData The encoded binary representation. |
|
86 * @param aPos The offset position from which to start decoding. |
|
87 * @return A pointer to the new CX509RSAPublicKey object. */ |
|
88 IMPORT_C static CX509RSAPublicKey* NewLC(const TDesC8& aBinaryData, TInt& aPos); |
|
89 private: |
|
90 void ConstructL(const TDesC8& aBinaryData, TInt& aPos); |
|
91 CX509RSAPublicKey(); |
|
92 }; |
|
93 |
|
94 class TASN1EncRSAPublicKey |
|
95 /** |
|
96 * Class for encoding RSA public keys to ASN.1 encoding. |
|
97 * |
|
98 * @publishedAll |
|
99 * @released |
|
100 * @since v8.0 |
|
101 */ |
|
102 { |
|
103 public: |
|
104 /** |
|
105 * Encodes the supplied public key into buffer in DER format ASN.1: |
|
106 * @code |
|
107 * SEQUENCE-OF |
|
108 * INTEGER modulus |
|
109 * INTEGER exponent |
|
110 * @endcode |
|
111 * |
|
112 * @param aKey Key to encode. |
|
113 * @return Allocated buffer containing DER encoding of |
|
114 * the supplied key aKey. |
|
115 */ |
|
116 IMPORT_C HBufC8* EncodeDERL(const CRSAPublicKey& aKey) const; |
|
117 }; |
|
118 |
|
119 class TASN1DecRSAPublicKey |
|
120 /** |
|
121 * Class for decoding RSA public keys from ASN.1 DER encoding. |
|
122 * |
|
123 * @publishedAll |
|
124 * @released |
|
125 * @since v8.0 |
|
126 */ |
|
127 { |
|
128 public: |
|
129 /** |
|
130 * Decodes an RSA key from the supplied buffer starting at the |
|
131 * specified position. |
|
132 * |
|
133 * @param aDER Buffer containing DER ASN.1 encoding of the key. |
|
134 * @param aPos Starting position in the buffer (updated on exit). |
|
135 * @return A pointer to the new CRSAPublicKey object. |
|
136 */ |
|
137 IMPORT_C CRSAPublicKey* DecodeDERL(const TDesC8& aDER, TInt& aPos) const; |
|
138 }; |
|
139 |
|
140 class TASN1DecRSAKeyPair |
|
141 /** |
|
142 * Class for decoding RSA key pairs from ASN.1 DER encoding. |
|
143 * |
|
144 * @publishedAll |
|
145 * @released |
|
146 * @since v8.0 |
|
147 */ |
|
148 { |
|
149 public: |
|
150 /** |
|
151 * Decodes an RSA key pair from buffer containing ASN.1 |
|
152 * DER-encoded private key. The encoding of a private key |
|
153 * contains public key components as well. |
|
154 * |
|
155 * @param aDER DER-encoded private key. |
|
156 * @param aPos Position in the buffer to start decoding |
|
157 * (updated on exit). |
|
158 * @param aPublicKey On return, the RSA public key object |
|
159 * @param aPrivateKey On return, the RSA private key object |
|
160 * @param aKeyType Key type, default is @c EStandardCRT |
|
161 */ |
|
162 IMPORT_C void DecodeDERL(const TDesC8& aDER, TInt& aPos, |
|
163 CRSAPublicKey*& aPublicKey, |
|
164 CRSAPrivateKey*& aPrivateKey, |
|
165 TRSAPrivateKeyType aKeyType = EStandardCRT); |
|
166 }; |
|
167 |
|
168 class CX509DSAPublicKey : public CDSAPublicKey |
|
169 /** Encapsulates the X.509 DSA public key. |
|
170 * |
|
171 * Adds a commitment to a specific encoding scheme allowing superclasses to remain |
|
172 * encoding-independent. |
|
173 * |
|
174 * @publishedAll |
|
175 * @released |
|
176 * @since v6.0 |
|
177 */ |
|
178 // DSA public key, params, signature. |
|
179 { |
|
180 public: |
|
181 /** Creates a new X.509 DSA public key object. |
|
182 * |
|
183 * @param aParamsData A non-modifiable descriptor representing the entire encoding. |
|
184 * @param aBinaryData The encoded binary representation. |
|
185 * @return A pointer to the new CX509DSAPublicKey object. */ |
|
186 IMPORT_C static CX509DSAPublicKey* NewL(const TDesC8& aParamsData, const TDesC8& aBinaryData); |
|
187 |
|
188 /** Creates a new X.509 DSA public key object, and puts a pointer to it onto the cleanup stack. |
|
189 * |
|
190 * @param aParamsData A non-modifiable descriptor representing the entire encoding. |
|
191 * @param aBinaryData The encoded binary representation. |
|
192 * @return A pointer to the new CX509DSAPublicKey object. */ |
|
193 IMPORT_C static CX509DSAPublicKey* NewLC(const TDesC8& aParamsData, const TDesC8& aBinaryData); |
|
194 |
|
195 /** Creates a new X.509 DSA public key object. |
|
196 * |
|
197 * @param aParams The DSA parameters. |
|
198 * @param aBinaryData The encoded binary representation. |
|
199 * @return A pointer to the new CX509DSAPublicKey object. */ |
|
200 IMPORT_C static CX509DSAPublicKey* NewL(const CDSAParameters& aParams, const TDesC8& aBinaryData); |
|
201 |
|
202 /** Creates a new X.509 DSA public key object, and puts a pointer to it onto the cleanup stack. |
|
203 * |
|
204 * @param aParams The DSA parameters. |
|
205 * @param aBinaryData The encoded binary representation. |
|
206 * @return A pointer to the new CX509DSAPublicKey object. */ |
|
207 IMPORT_C static CX509DSAPublicKey* NewLC(const CDSAParameters& aParams, const TDesC8& aBinaryData); |
|
208 |
|
209 /** Creates a new X.509 DSA public key object. |
|
210 * |
|
211 * @param aParamsData A non-modifiable descriptor representing the entire encoding. |
|
212 * @param aBinaryData The encoded binary representation. |
|
213 * @param aPos The position from which to start decoding. |
|
214 * @return A pointer to the new CX509DSAPublicKey object. */ |
|
215 IMPORT_C static CX509DSAPublicKey* NewL(const TDesC8& aParamsData, const TDesC8& aBinaryData,TInt& aPos); |
|
216 |
|
217 /** Creates a new X.509 DSA public key object, and puts a pointer to it onto the cleanup stack. |
|
218 * |
|
219 * @param aParamsData A non-modifiable descriptor representing the entire encoding. |
|
220 * @param aBinaryData The encoded binary representation. |
|
221 * @param aPos The position from which to start decoding. |
|
222 * @return A pointer to the new CX509DSAPublicKey object. */ |
|
223 IMPORT_C static CX509DSAPublicKey* NewLC(const TDesC8& aParamsData, const TDesC8& aBinaryData, TInt& aPos); |
|
224 |
|
225 /** Creates a new X.509 DSA public key object. |
|
226 * |
|
227 * @param aParams The DSA parameters. |
|
228 * @param aBinaryData The encoded binary representation. |
|
229 * @param aPos The position from which to start decoding. |
|
230 * @return A pointer to the new CX509DSAPublicKey object. */ |
|
231 IMPORT_C static CX509DSAPublicKey* NewL(const CDSAParameters& aParams, const TDesC8& aBinaryData, TInt& aPos); |
|
232 |
|
233 /** Creates a new X.509 DSA public key object, and puts a pointer to it onto the cleanup stack. |
|
234 * |
|
235 * @param aParams The DSA parameters. |
|
236 * @param aBinaryData The encoded binary representation. |
|
237 * @param aPos The position from which to start decoding. |
|
238 * @return A pointer to the new CX509DSAPublicKey object. */ |
|
239 IMPORT_C static CX509DSAPublicKey* NewLC(const CDSAParameters& aParams, const TDesC8& aBinaryData, TInt& aPos); |
|
240 public: |
|
241 /** Gets the DSA parameters from the encoding key. |
|
242 * |
|
243 * @param aParamsData A non-modifiable descriptor representing the entire encoding. |
|
244 * @return The DSA parameters. */ |
|
245 IMPORT_C static CDSAParameters* DSAParametersL(const TDesC8& aParamsData); |
|
246 protected: |
|
247 /** @internalComponent */ |
|
248 void ConstructL(const TDesC8& aParamsData, const TDesC8& aBinaryData, TInt& aPos); |
|
249 /** @internalComponent */ |
|
250 void ConstructL(const CDSAParameters& aParams, const TDesC8& aBinaryData, TInt& aPos); |
|
251 /** @internalComponent */ |
|
252 CX509DSAPublicKey(); |
|
253 }; |
|
254 |
|
255 class TASN1DecDSAKeyPair |
|
256 /** |
|
257 * Class for decoding DSA key pairs from ASN.1 DER encoding. |
|
258 * |
|
259 * @publishedAll |
|
260 * @released |
|
261 * @since v8.0 |
|
262 */ |
|
263 { |
|
264 public: |
|
265 /** |
|
266 * Decodes a DSA key pair from a buffer containing an ASN.1 |
|
267 * DER-encoded private key. |
|
268 * |
|
269 * The encoding of the private key contains public key components as well. |
|
270 * |
|
271 * The DER encoding has the following format: |
|
272 * @verbatim |
|
273 * SEQUENCE-OF |
|
274 * INTEGER version (==0, ignored) |
|
275 * INTEGER p (public prime) |
|
276 * INTEGER q (160-bit public subprime, q | p-1) |
|
277 * INTEGER g (public generator of subgroup) |
|
278 * INTEGER x (private key) |
|
279 * INTEGER y (public key y=g^x) |
|
280 * @endverbatim |
|
281 * |
|
282 * @param aDER DER-encoded private key. |
|
283 * @param aPos Position in the buffer to start decoding |
|
284 * (updated on exit). |
|
285 * @param aPublicKey On return, the DSA public key object |
|
286 * @param aPrivateKey On return, the DSA private key object |
|
287 */ |
|
288 IMPORT_C void DecodeDERL(const TDesC8& aDER, TInt& aPos, |
|
289 CDSAPublicKey*& aPublicKey, CDSAPrivateKey*& aPrivateKey); |
|
290 }; |
|
291 |
|
292 /** |
|
293 * Class for encoding DSA public keys to ASN.1 encoding. |
|
294 * |
|
295 * @publishedAll |
|
296 * @released |
|
297 * @since v8.0 |
|
298 */ |
|
299 class TASN1EncDSAPublicKey |
|
300 { |
|
301 public: |
|
302 /** |
|
303 * Encodes the supplied public key into a buffer in DER format. |
|
304 * |
|
305 * Note that the encoding has the following format: |
|
306 * @code |
|
307 * SEQUENCE-OF |
|
308 * SEQUENCE-OF |
|
309 * INTEGER p |
|
310 * INTEGER q |
|
311 * INTEGER g |
|
312 * BIT STRING (encoded INTEGER public value) |
|
313 * @endcode |
|
314 * |
|
315 * @param aKey Key to encode. |
|
316 * @return Sequence containing public key information. |
|
317 */ |
|
318 IMPORT_C CASN1EncSequence* EncodeDERL(const CDSAPublicKey& aKey) const; |
|
319 |
|
320 /** |
|
321 * Encodes DSA parameters into an ASN.1 encoding structure suitable for |
|
322 * inclusion into other objects, like a PKCS#10 certificate request. |
|
323 * |
|
324 * Note that the encoding has the following form: |
|
325 * @code |
|
326 * SEQUENCE-OF |
|
327 * INTEGER p |
|
328 * INTEGER q |
|
329 * INTEGER g |
|
330 * @endcode |
|
331 * |
|
332 * @param aKey DSA public key. |
|
333 * @return ASN.1 encoding structure on the cleanup stack. |
|
334 */ |
|
335 IMPORT_C CASN1EncSequence* EncodeParamsLC(const CDSAPublicKey& aKey) const; |
|
336 |
|
337 /** |
|
338 * Encodes a public key as a bit string. |
|
339 * |
|
340 * @param aKey DSA public key. |
|
341 * @return ASN.1 bit string (public key). This is left on the cleanup stack. |
|
342 */ |
|
343 |
|
344 IMPORT_C CASN1EncBitString* EncodePublicValueLC(const CDSAPublicKey& aKey) const; |
|
345 }; |
|
346 |
|
347 class CX509DSASignature : public CDSASignature |
|
348 /** Encapsulates the X.509 DSA signature. |
|
349 * |
|
350 * Adds a commitment to a specific encoding scheme allowing superclasses to remain |
|
351 * encoding-independent. |
|
352 * |
|
353 * @publishedAll |
|
354 * @released |
|
355 * @since v6.0 */ |
|
356 { |
|
357 public: |
|
358 /** Creates a new DSA Signature object from the specified buffer containing the |
|
359 * encoded binary representation. |
|
360 * |
|
361 * @param aBinaryData The encoded binary representation. |
|
362 * @return A pointer to the new CX509DSASignature object. */ |
|
363 IMPORT_C static CX509DSASignature* NewL(const TDesC8& aBinaryData); |
|
364 |
|
365 /** Creates a new DSA Signature object from the specified buffer containing the |
|
366 * encoded binary representation, and puts a pointer to it onto the cleanup stack. |
|
367 * |
|
368 * @param aBinaryData The encoded binary representation. |
|
369 * @return A pointer to the new CX509DSASignature object. */ |
|
370 IMPORT_C static CX509DSASignature* NewLC(const TDesC8& aBinaryData); |
|
371 |
|
372 /** Creates a new DSA Signature object from the specified buffer containing the |
|
373 * encoded binary representation, starting at the specified offset. |
|
374 * |
|
375 * @param aBinaryData The encoded binary representation. |
|
376 * @param aPos The offset position from which to start decoding. |
|
377 * @return A pointer to the new CX509DSASignature object. */ |
|
378 IMPORT_C static CX509DSASignature* NewL(const TDesC8& aBinaryData, TInt& aPos); |
|
379 |
|
380 /** Creates a new DSA Signature object from the specified buffer containing the |
|
381 * encoded binary representation, starting at the specified offset, and puts |
|
382 * a pointer to it onto the cleanup stack. |
|
383 * |
|
384 * @param aBinaryData The encoded binary representation. |
|
385 * @param aPos The offset position from which to start decoding. |
|
386 * @return A pointer to the new CX509DSASignature object. */ |
|
387 IMPORT_C static CX509DSASignature* NewLC(const TDesC8& aBinaryData, TInt& aPos); |
|
388 private: |
|
389 void ConstructL(const TDesC8& aBinaryData, TInt& aPos); |
|
390 CX509DSASignature(); |
|
391 }; |
|
392 |
|
393 class CX509DHPublicKey : public CDHPublicKey |
|
394 /** Provides clients with the information they need for Diffie-Hellman key exchange |
|
395 * within a protocol. |
|
396 * |
|
397 * @publishedAll |
|
398 * @released |
|
399 * @since v6.0 */ |
|
400 { |
|
401 public: |
|
402 /** Creates a new CX509DHPublicKey object from the specified buffer containing the encoded |
|
403 * binary representation. |
|
404 * |
|
405 * @param aParamsData A non-modifiable descriptor representing the entire encoding. |
|
406 * @param aKeyData |
|
407 * @return A pointer to the new CX509DHPublicKey object.*/ |
|
408 IMPORT_C static CX509DHPublicKey* NewL(const TDesC8& aParamsData, const TDesC8& aKeyData); |
|
409 |
|
410 /** Creates a new CX509DHPublicKey object from the specified buffer containing the encoded |
|
411 * binary representation, and puts a pointer to it onto the cleanup stack. |
|
412 * |
|
413 * @param aParamsData A non-modifiable descriptor representing the entire encoding. |
|
414 * @param aKeyData |
|
415 * @return A pointer to the new CX509DHPublicKey object.*/ |
|
416 IMPORT_C static CX509DHPublicKey* NewLC(const TDesC8& aParamsData, const TDesC8& aKeyData); |
|
417 public: |
|
418 /** Destructor. |
|
419 * |
|
420 * Frees all resources owned by the object, prior to its destruction. */ |
|
421 IMPORT_C virtual ~CX509DHPublicKey(); |
|
422 protected: |
|
423 /** @internalComponent */ |
|
424 CX509DHPublicKey(); |
|
425 /** @internalComponent */ |
|
426 void ConstructL(const TDesC8& aParamsData, const TDesC8& aKeyData); |
|
427 }; |
|
428 |
|
429 class CX509DHKeyPair : public CDHKeyPair |
|
430 /** This class represents the Diffie-Hellman Key Pair. |
|
431 * |
|
432 * @publishedAll |
|
433 * @released |
|
434 * @since v8.0 */ |
|
435 { |
|
436 public: |
|
437 /** Creates a new DH key pair object from the specified buffer containing |
|
438 * the encoded binary representation . |
|
439 * |
|
440 * @param aParamsData A non-modifiable descriptor representing the entire encoding. |
|
441 * @return A pointer to the new CX509DHKeyPair object. |
|
442 */ |
|
443 IMPORT_C static CX509DHKeyPair* NewL(const TDesC8& aParamsData); |
|
444 |
|
445 /** Creates a new DH Key Pair object from the specified buffer containing the encoded binary |
|
446 * representation, and puts a pointer to it onto the cleanup stack. |
|
447 * |
|
448 * @param aParamsData A non-modifiable descriptor representing the entire encoding. |
|
449 * @return A pointer to the new CX509DHKeyPair object. |
|
450 */ |
|
451 IMPORT_C static CX509DHKeyPair* NewLC(const TDesC8& aParamsData); |
|
452 public: |
|
453 |
|
454 /** Virtual Destructor. |
|
455 * Frees all resources owned by the object, prior to its destruction. |
|
456 * |
|
457 */ |
|
458 IMPORT_C virtual ~CX509DHKeyPair(); |
|
459 protected: |
|
460 /** @internalComponent */ |
|
461 CX509DHKeyPair(); |
|
462 /** @internalComponent */ |
|
463 void ConstructL(const TDesC8& aParamsData); |
|
464 }; |
|
465 |
|
466 class CX509DHValidationParams : public CBase |
|
467 /** Validates Diffie-Hellman (DH) Domain parameters. |
|
468 * |
|
469 * Provides access to the DH Validation Parameters, which are used to determine |
|
470 * if the DH Public Key has been generated in conformance with the algorithm |
|
471 * specified in ESDH (see RFC 2631). |
|
472 * |
|
473 * @publishedAll |
|
474 * @released |
|
475 * @since v6.0 */ |
|
476 { |
|
477 public: |
|
478 /** Creates a new DH Validation parameters object from the specified buffer containing |
|
479 * the encoded binary representation. |
|
480 * |
|
481 * @param aBinaryData The encoded binary representation. |
|
482 * @return A pointer to the new CX509DHValidationParams object. */ |
|
483 IMPORT_C static CX509DHValidationParams* NewL(const TDesC8& aBinaryData); |
|
484 |
|
485 /** Creates a new DH Validation parameters object from the specified buffer containing |
|
486 * the encoded binary representation, and puts a pointer to it onto the cleanup stack. |
|
487 * |
|
488 * @param aBinaryData The encoded binary representation. |
|
489 * @return A pointer to the new CX509DHValidationParams object. */ |
|
490 IMPORT_C static CX509DHValidationParams* NewLC(const TDesC8& aBinaryData); |
|
491 |
|
492 /** Creates a new DH Validation parameters object from the specified buffer containing |
|
493 * the encoded binary representation, starting at the specified offset. |
|
494 * |
|
495 * @param aBinaryData The encoded binary representation. |
|
496 * @param aPos The offset position from which to start decoding. |
|
497 * @return A pointer to the new CX509DHValidationParams object. */ |
|
498 IMPORT_C static CX509DHValidationParams* NewL(const TDesC8& aBinaryData, TInt& aPos); |
|
499 |
|
500 /** Creates a new DH Validation parameters object from the specified buffer containing |
|
501 * the encoded binary representation, starting at the specified offset, and puts |
|
502 * a pointer to it onto the cleanup stack. |
|
503 * |
|
504 * @param aBinaryData The encoded binary representation. |
|
505 * @param aPos The offset position from which to start decoding. |
|
506 * @return A pointer to the new CX509DHValidationParams object. */ |
|
507 IMPORT_C static CX509DHValidationParams* NewLC(const TDesC8& aBinaryData, TInt& aPos); |
|
508 |
|
509 /** Gets a DSA prime generation seed. |
|
510 * |
|
511 * @return The bit string parameter used as the seed. */ |
|
512 IMPORT_C const TPtrC8 Seed() const; |
|
513 |
|
514 /** Gets the output from a DSA prime generation counter. |
|
515 * |
|
516 * @return The integer value output. */ |
|
517 IMPORT_C const TInteger& PGenCounter() const; |
|
518 |
|
519 /** Destructor. |
|
520 * |
|
521 * Frees all resources owned by the object, prior to its destruction. */ |
|
522 virtual ~CX509DHValidationParams(); |
|
523 protected: |
|
524 /** @internalComponent */ |
|
525 CX509DHValidationParams(); |
|
526 /** @internalComponent */ |
|
527 void ConstructL(const TDesC8& aBinaryData, TInt& aPos); |
|
528 HBufC8* iSeed; |
|
529 RInteger iPGenCounter; |
|
530 }; |
|
531 |
|
532 class CX509DHDomainParams : public CBase |
|
533 /** Encapsulates the compulsory Diffie-Hellman domain parameter values P and G |
|
534 * (See RFC 2459). |
|
535 * |
|
536 * @publishedAll |
|
537 * @released |
|
538 * @since v6.0 */ |
|
539 { |
|
540 public: |
|
541 /** Creates a new DH Domain parameters object from the specified buffer containing |
|
542 * the encoded binary representation. |
|
543 * |
|
544 * @param aBinaryData The encoded binary representation. |
|
545 * @return A pointer to the new CX509DHDomainParams object. */ |
|
546 IMPORT_C static CX509DHDomainParams* NewL(const TDesC8& aBinaryData); |
|
547 |
|
548 /** Creates a new DH Domain parameters object from the specified buffer containing |
|
549 * the encoded binary representation, and puts a pointer to it onto the cleanup stack. |
|
550 * |
|
551 * @param aBinaryData The encoded binary representation. |
|
552 * @return A pointer to the new CX509DHDomainParams object. */ |
|
553 IMPORT_C static CX509DHDomainParams* NewLC(const TDesC8& aBinaryData); |
|
554 |
|
555 /** Creates a new DH Domain parameters object from the specified buffer containing |
|
556 * the encoded binary representation, starting at the specified offset. |
|
557 * |
|
558 * @param aBinaryData The encoded binary representation. |
|
559 * @param aPos The offset position from which to start decoding. |
|
560 * @return A pointer to the new CX509DHDomainParams object. */ |
|
561 IMPORT_C static CX509DHDomainParams* NewL(const TDesC8& aBinaryData, TInt& aPos); |
|
562 |
|
563 /** Creates a new DH Domain parameters object from the specified buffer containing |
|
564 * the encoded binary representation, starting at the specified offset, and puts |
|
565 * a pointer to it onto the cleanup stack. |
|
566 * |
|
567 * @param aBinaryData The encoded binary representation. |
|
568 * @param aPos The offset position from which to start decoding. |
|
569 * @return A pointer to the new CX509DHDomainParams object. */ |
|
570 IMPORT_C static CX509DHDomainParams* NewLC(const TDesC8& aBinaryData, TInt& aPos); |
|
571 |
|
572 /** Gets the compulsory parameter value P. |
|
573 * |
|
574 * @return The compulsory parameter value P. */ |
|
575 IMPORT_C const TInteger& P() const; |
|
576 |
|
577 /** Gets the compulsory parameter value G. |
|
578 * |
|
579 * @return The compulsory parameter value G. */ |
|
580 IMPORT_C const TInteger& G() const; |
|
581 |
|
582 //the next 3 members are optional, in which case NULL is returned |
|
583 //the returned objects remain the property of this object |
|
584 |
|
585 //N.B. according to RFC 2459 the Q member is *not* optional, |
|
586 //however it is not essential for doing DH, and empirical studies |
|
587 //suggest it doesn't get included much, so I'm relaxing the spec here |
|
588 //to permit DomainParams objects which contain no Q. |
|
589 |
|
590 /** Gets the optional value Q. |
|
591 * |
|
592 * @return The optional value Q. */ |
|
593 IMPORT_C const TInteger& Q() const; |
|
594 |
|
595 /** Gets the optional value J. |
|
596 * |
|
597 * @return The optional value J. */ |
|
598 IMPORT_C const TInteger& J() const; |
|
599 |
|
600 /** Gets the optional validation parameters. |
|
601 * |
|
602 * @return The optional validation parameters. */ |
|
603 IMPORT_C const CX509DHValidationParams* ValidationParams() const; |
|
604 |
|
605 /** Destructor. |
|
606 * |
|
607 * Frees all resources owned by the object, prior to its destruction. */ |
|
608 virtual ~CX509DHDomainParams(); |
|
609 protected: |
|
610 /** @internalComponent */ |
|
611 CX509DHDomainParams(); |
|
612 /** @internalComponent */ |
|
613 void ConstructL(const TDesC8& aBinaryData, TInt& aPos); |
|
614 RInteger iP; |
|
615 RInteger iG; |
|
616 RInteger iQ; |
|
617 RInteger iJ; |
|
618 CX509DHValidationParams* iValidationParams; |
|
619 }; |
|
620 |
|
621 class TX509KeyEncoder |
|
622 /** |
|
623 * Abstract class that is the base class for RSA and DSA key encoder classes. |
|
624 * These classes are used to encode the X509 ASN.1 types AlgorithmIdentifier and |
|
625 * SubjectPublicKeyInfo. |
|
626 * |
|
627 * This class is part of the pkcs10 API, and will be changed or removed in a |
|
628 * future release. You should not use it. |
|
629 * |
|
630 * @internalTechnology |
|
631 */ |
|
632 { |
|
633 public: |
|
634 /** |
|
635 * Constructor that takes an algorithm identifier and saves it into the |
|
636 * corresponding member variable. It is then used in the |
|
637 * EncodeSignatureAlgorithm() function. |
|
638 * |
|
639 * @param aDigestAlg Digest algorithm to use. Currently the following |
|
640 * algorithms are supported: MD2, MD5, and SHA-1. |
|
641 */ |
|
642 IMPORT_C TX509KeyEncoder(TAlgorithmId aDigestAlg); |
|
643 |
|
644 /** |
|
645 * Produces the SubjectPublicKeyInfo encoding. |
|
646 * |
|
647 * The encoding has the following ASN.1 format: |
|
648 * @code |
|
649 * SubjectPublicKeyInfo {ALGORITHM : IOSet} ::= SEQUENCE { |
|
650 * algorithm AlgorithmIdentifier {{IOSet}}, |
|
651 * subjectPublicKey BIT STRING |
|
652 * } |
|
653 * @endcode |
|
654 */ |
|
655 IMPORT_C virtual CASN1EncBase* EncodeKeyLC() const = 0; |
|
656 |
|
657 /** |
|
658 * Produces the AlgorithmIdentifier encoding. |
|
659 * |
|
660 * @return ASN.1 sequence containing signature algorithm |
|
661 */ |
|
662 IMPORT_C virtual CASN1EncSequence* EncodeSignatureAlgorithmLC() const = 0; |
|
663 |
|
664 /** |
|
665 * Produces the DigestAlgorithmIdentifier encoder. |
|
666 * |
|
667 * The encoding has the following ASN.1 format |
|
668 * @code |
|
669 * DigestAlgorithmIdentifier ::= SEQUENCE { |
|
670 * algorithm AlgorithmIdentifier, |
|
671 * parameters ANY DEFINED BY algorithm OPTIONAL } |
|
672 * |
|
673 * AlgorithmIdentifier ::= OBJECT IDENTIFIER |
|
674 * @endcode |
|
675 * |
|
676 * @return Appropriate ASN.1 sequence of type <code>DigestAlgorithmIdentifier</code> |
|
677 */ |
|
678 IMPORT_C virtual CASN1EncSequence* EncodeDigestAlgorithmLC() const; |
|
679 |
|
680 protected: |
|
681 /** Digest algorithm to use. */ |
|
682 TAlgorithmId iDigestAlg; |
|
683 }; |
|
684 |
|
685 class TX509RSAKeyEncoder : public TX509KeyEncoder |
|
686 /** |
|
687 * Subclasses TC509KeyEncoder to provides key encoding capability for RSA public keys. |
|
688 * |
|
689 * This class is part of the pkcs10 API, and will be changed or removed in a |
|
690 * future release. You should not use it. |
|
691 * |
|
692 * @internalTechnology |
|
693 */ |
|
694 { |
|
695 public: |
|
696 /** |
|
697 * Constructs a RSA key pair encoder, saving reference to the passed |
|
698 * key pair in the member variable. |
|
699 * |
|
700 * @param aPublicKey RSA public key to use for encoding. |
|
701 * @param aDigestAlg Digest algorithm to use. |
|
702 */ |
|
703 IMPORT_C TX509RSAKeyEncoder(const CRSAPublicKey& aPublicKey, TAlgorithmId aDigestAlg); |
|
704 |
|
705 /** |
|
706 * Produces the SubjectPublicKeyInfo encoding. |
|
707 * |
|
708 * The resulting encoding has the following form: |
|
709 * @code |
|
710 * SEQUENCE-OF |
|
711 * SEQUENCE-OF |
|
712 * OID of the encryption algorithm (KRSA) |
|
713 * NULL |
|
714 * BIT STRING encoded public key. |
|
715 * @endcode |
|
716 * |
|
717 * @return DER-encoded public key information, placed on the cleanup stack. |
|
718 */ |
|
719 IMPORT_C virtual CASN1EncBase* EncodeKeyLC() const; |
|
720 |
|
721 /** |
|
722 * Produces the AlgorithmIdentifier encoding. |
|
723 * |
|
724 * This has the following form: |
|
725 * @code |
|
726 * SEQUENCE-OF |
|
727 * OID signature-algorithm |
|
728 * NULL |
|
729 * @endcode |
|
730 * |
|
731 * @return ASN.1 sequence containing signature algorithm encoding, |
|
732 * placed on the cleanup stack. |
|
733 */ |
|
734 IMPORT_C virtual CASN1EncSequence* EncodeSignatureAlgorithmLC() const; |
|
735 |
|
736 private: |
|
737 /** |
|
738 * Saved reference to the RSA public key to be used for encoding. |
|
739 */ |
|
740 const CRSAPublicKey& iPublicKey; |
|
741 }; |
|
742 |
|
743 class TX509DSAKeyEncoder : public TX509KeyEncoder |
|
744 /** |
|
745 * Provides key encoding and signing capability using a DSA public key. |
|
746 * |
|
747 * This class is part of the pkcs10 API, and will be changed or removed in a |
|
748 * future release. You should not use it. |
|
749 * |
|
750 * @internalTechnology |
|
751 */ |
|
752 { |
|
753 public: |
|
754 /** |
|
755 * Constructs a DSA key pair encoder, saving reference to the passed |
|
756 * public key in the member variable. |
|
757 * |
|
758 * @param aKeyPublic DSA public key to use for encoding. |
|
759 * @param aDigestAlg Digest algorithm to use. |
|
760 */ |
|
761 IMPORT_C TX509DSAKeyEncoder(const CDSAPublicKey& aKeyPublic, |
|
762 TAlgorithmId aDigestAlg); |
|
763 |
|
764 /** |
|
765 * Produces the SubjectPublicKeyInfo encoding. |
|
766 * |
|
767 * The ASN.1 encoding of a DSA key has the following form: |
|
768 * @code |
|
769 * SEQUENCE-OF |
|
770 * SEQUENCE-OF |
|
771 * OID dsa (1.2.840.10040.4.1) |
|
772 * SEQUENCE-OF |
|
773 * INTEGER p |
|
774 * INTEGER q |
|
775 * INTEGER g |
|
776 * BIT STRING |
|
777 * INTEGER public value (y) |
|
778 * @endcode |
|
779 * |
|
780 * @return DER-encoded public key information, placed on the cleanup stack. |
|
781 */ |
|
782 IMPORT_C virtual CASN1EncBase* EncodeKeyLC() const; |
|
783 |
|
784 /** |
|
785 * Produces the AlgorithmIdentifier encoding. |
|
786 * |
|
787 * This has the following form: |
|
788 * @code |
|
789 * SEQUENCE-OF |
|
790 * OID dsa-signature-oid |
|
791 * SEQUENCE-OF dsa-params |
|
792 * INTEGER p |
|
793 * INTEGER q |
|
794 * INTEGER g |
|
795 * @endcode |
|
796 * |
|
797 * @return ASN.1 sequence containing signature algorithm encoding, |
|
798 * placed on the cleanup stack. |
|
799 */ |
|
800 IMPORT_C virtual CASN1EncSequence* EncodeSignatureAlgorithmLC() const; |
|
801 |
|
802 private: |
|
803 /** |
|
804 * Saved reference to the DSA public key to be used for encoding. |
|
805 */ |
|
806 const CDSAPublicKey& iPublicKey; |
|
807 }; |
|
808 |
|
809 #endif |