Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
2 * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
32 #include <securitydefs.h>
39 /** Enumerates the identity of the algorithm.
46 /** An RSA algorithm. */
48 /** A DSA algorithm. */
50 /** A DH algorithm. */
52 /** A MD2 algorithm. */
54 /** A MD5 algorithm. */
56 /** A SHA-1 algorithm. */
60 class CValidityPeriod : public CBase
61 /** The period for which the certificate is valid.
68 /** Tests whether the specified date and time is within the validity period.
70 * @param aTime The date and time to be tested.
71 * @return ETrue, if the date and time is within the validity period;
72 * EFalse, otherwise. */
73 IMPORT_C TBool Valid(const TTime& aTime) const;
75 /** Gets the start of the validity period.
77 * @return The start date and time. */
78 IMPORT_C const TTime& Start() const;
80 /** Gets the end of the validity period.
82 * @return The end date and time. */
83 IMPORT_C const TTime& Finish() const;
87 * @param aValidityPeriod The validity period object to be copied. */
88 IMPORT_C CValidityPeriod(const CValidityPeriod& aValidityPeriod);
91 /** Default constructor. */
92 IMPORT_C CValidityPeriod();
94 /** The start time of the validity period. */
97 /** The end time of the validity period. */
101 class CAlgorithmIdentifier : public CBase
102 /** Contains an algorithm ID and any encoded parameters required by that algorithm.
104 * An object of this type creates and owns a heap descriptor to contain the encoded
112 /** Creates a new algorithm ID object copied from an existing object.
114 * @param aAlgorithmIdentifier The algorithm ID object to be copied.
115 * @return A pointer to the new algorithm ID object. */
116 IMPORT_C static CAlgorithmIdentifier* NewL(const CAlgorithmIdentifier& aAlgorithmIdentifier);
118 /** Creates a new algorithm ID object copied from an existing object, and puts
119 * a pointer to the new object onto the cleanup stack.
121 * @param aAlgorithmIdentifier The algorithm ID object to be copied.
122 * @return A pointer to the new algorithm ID object. */
123 IMPORT_C static CAlgorithmIdentifier* NewLC(const CAlgorithmIdentifier& aAlgorithmIdentifier);
125 /** Creates a new algorithm ID object.
127 * @param aAlgorithmId The algorithm ID.
128 * @param aEncodedParams The encoded parameters.
129 * @return A pointer to the new algorithm ID object. */
130 IMPORT_C static CAlgorithmIdentifier* NewL(TAlgorithmId& aAlgorithmId, const TDesC8& aEncodedParams);
132 /** Creates a new algorithm ID object, and puts a pointer to the new object onto
135 * @param aAlgorithmId The algorithm ID.
136 * @param aEncodedParams The encoded parameters.
137 * @return A pointer to the new algorithm ID object. */
138 IMPORT_C static CAlgorithmIdentifier* NewLC(TAlgorithmId& aAlgorithmId, const TDesC8& aEncodedParams);
140 /** Tests whether this algorithm identifier object is equal to the specified algorithm
143 * @param aAlgorithmIdentifier The algorithm identifier object to be compared.
144 * @return ETrue, if this algorithm identifier object is equal to the specified
145 * algorithm identifier object; EFalse otherwise. */
146 IMPORT_C TBool operator == (const CAlgorithmIdentifier& aAlgorithmIdentifier) const;
148 /** Gets the algorithm identifier.
150 * @return The algorithm identifier. */
151 IMPORT_C TAlgorithmId Algorithm() const; //ID for the algorithm
153 /** Gets the encoded parameters for the algorithm identifier.
155 * Note that this object owns the heap descriptor that owns the encoded parameters.
157 * @return The encoded parameters. */
158 IMPORT_C TPtrC8 EncodedParams() const; //the encoded parameters
162 * Frees all resources owned by the object. */
163 IMPORT_C ~CAlgorithmIdentifier();
166 /** Default constructor. */
167 IMPORT_C CAlgorithmIdentifier();
169 /** Constructor taking the specified parameters.
171 * @param aAlgorithmId The algorithm ID. */
172 IMPORT_C CAlgorithmIdentifier(TAlgorithmId& aAlgorithmId);
174 /** Second-phase constructor taking an existing algorithm identifier object.
176 * @param aAlgorithmIdentifier The algorithm identifier object. */
177 IMPORT_C virtual void ConstructL(const CAlgorithmIdentifier& aAlgorithmIdentifier);
179 /** Second-phase constructor taking encoded parameters.
181 * @param aEncodedParams The encoded parameters. */
182 IMPORT_C virtual void ConstructL(const TDesC8& aEncodedParams);
184 /** The algorithm ID. */
185 TAlgorithmId iAlgorithmId;
187 /** The encoded parameters for the algorithm ID. */
188 HBufC8* iEncodedParams;
191 class CSigningAlgorithmIdentifier : public CBase
192 /** Contains two CAlgorithmIdentifier objects for comparison purposes.
194 * Implements an equality operator.
201 /** Constructs a new Signing Algorithm Identifier object, copying an existing Signing
202 * Algorithm Identifier object.
204 * @param aSigningAlgorithmIdentifier The Signing Algorithm Identifier object.
205 * @return The new Signing Algorithm Identifier object. */
206 IMPORT_C static CSigningAlgorithmIdentifier* NewL(const CSigningAlgorithmIdentifier& aSigningAlgorithmIdentifier);
208 /** Constructs a new Signing Algorithm Identifier object, copying an existing Signing
209 * Algorithm Identifier object, and puts a pointer to it onto the cleanup stack.
211 * @param aSigningAlgorithmIdentifier The Signing Algorithm Identifier object.
212 * @return The new Signing Algorithm Identifier object. */
213 IMPORT_C static CSigningAlgorithmIdentifier* NewLC(const CSigningAlgorithmIdentifier& aSigningAlgorithmIdentifier);
215 /** Tests whether the Signing Algorithm Identifier object is equal to the specified
216 * Signing Algorithm Identifier object.
218 * @param aSigningAlgorithmIdentifier The Signing Algorithm Identifier object to be compared.
219 * @return ETrue, if this object's Signing Algorithm Identifier value
220 * is equal to the specified Signing Algorithm Identifier
221 * object's value; EFalse, otherwise. */
222 IMPORT_C TBool operator == (const CSigningAlgorithmIdentifier& aSigningAlgorithmIdentifier) const;
224 /** Gets the signature ID of the asymmetric algorithm.
226 * @return The signature ID of the asymmetric algorithm. */
227 IMPORT_C const CAlgorithmIdentifier& AsymmetricAlgorithm() const;
229 /** Gets the signature ID of the digest algorithm.
231 * @return The signature ID of the digest algorithm. */
232 IMPORT_C const CAlgorithmIdentifier& DigestAlgorithm() const;
236 * Frees all resources owned by the object, prior to its destruction. */
237 IMPORT_C ~CSigningAlgorithmIdentifier();
240 /** Second-phase constructor.
243 void ConstructL(const CSigningAlgorithmIdentifier& aSigningAlgorithmIdentifier);
245 /** The signature ID of the asymmetric algorithm. */
246 CAlgorithmIdentifier* iAsymmetricAlgorithm;
248 /** The signature ID of the digest algorithm. */
249 CAlgorithmIdentifier* iDigestAlgorithm;
252 class CSubjectPublicKeyInfo : public CBase
253 /** A base class for a container that holds information about a subject public key.
255 * It contains the algorithm ID, the encoded public key and the encoded parameters.
261 //algorithm ID + encoded public key + encoded parameters
264 /** Creates a new subject public key object copied from an existing object.
266 * @param aSubjectPublicKeyInfo The subject public key object to be copied.
267 * @return A pointer to the new public key object. */
268 IMPORT_C static CSubjectPublicKeyInfo* NewL(const CSubjectPublicKeyInfo& aSubjectPublicKeyInfo);
270 /** Creates a new subject public key object copied from an existing object and
271 * puts a pointer to the new object onto the cleanup stack.
273 * @param aSubjectPublicKeyInfo The subject public key object to be copied.
274 * @return A pointer to the new public key object. */
275 IMPORT_C static CSubjectPublicKeyInfo* NewLC(const CSubjectPublicKeyInfo& aSubjectPublicKeyInfo);
277 /** Gets the algorithm ID.
279 * @return The algorithm ID. */
280 IMPORT_C TAlgorithmId AlgorithmId() const;
282 /** Gets the encoded parameters required by the algorithm.
284 * @return A non-modifiable pointer descriptor representing the encoded parameters. */
285 IMPORT_C const TPtrC8 EncodedParams() const;
287 /** Gets the encoded public key data.
289 * @return A non-modifiable pointer descriptor representing the encoded public
291 IMPORT_C const TPtrC8 KeyData() const;
295 * Frees all resources owned by the object. */
296 IMPORT_C ~CSubjectPublicKeyInfo();
298 /** Second-phase constructor.
300 * @param aSubjectPublicKeyInfo The subject public key object to be copied. */
301 IMPORT_C virtual void ConstructL(const CSubjectPublicKeyInfo& aSubjectPublicKeyInfo);
303 /** The algorithm ID. */
304 CAlgorithmIdentifier* iAlgId;
306 /** A heap descriptor representing the encoded key data. */
307 HBufC8* iEncodedKeyData;
310 class CRSASignatureResult : public CBase
311 /** The RSA public key algorithm signature result.
314 * @li CWTLSRSASignatureResult
315 * @li CPKCS1SignatureResult.
317 * @see TKeyFactory::RSASignatureResultL()
324 /** Tests whether the signature result is valid.
326 * @param aResult The signature result.
327 * @return ETrue if the signature result is valid, otherwise EFalse. */
328 IMPORT_C virtual TBool VerifyL(const TDesC8& aResult) = 0;
332 * Frees all resources owned by the object. */
333 IMPORT_C ~CRSASignatureResult();
335 /** Compares this RSA Signature Result object with the specified RSA Signature
336 * Result object for equality.
338 * @param aResult The RSA Signature Result object to be compared.
339 * @return ETrue, if they are the same; EFalse, otherwise. */
340 IMPORT_C TBool operator == (const CRSASignatureResult& aResult) const;
342 /** The digest algorithm ID. */
343 CAlgorithmIdentifier* iDigestAlgorithm;
345 /** A heap descriptor representing the digest algorithm. */
351 /** Constructs the public key objects used for signature verification from their
352 * encoded binary form.
359 /** Gets the RSA public key.
361 * @param aEncoding A non-modifiable descriptor representing the entire encoding.
362 * @return The RSA Public key. */
363 virtual CRSAPublicKey* RSAPublicKeyL(const TDesC8& aEncoding) const = 0;
365 /** Gets the RSA signature result.
367 * @param aDigestAlgorithm The algorithm ID.
368 * @param aDigest A non-modifiable descriptor representing the digest algorithm.
369 * @return The RSA signature result. */
370 virtual CRSASignatureResult* RSASignatureResultL(const CAlgorithmIdentifier& aDigestAlgorithm, TDesC8& aDigest) const = 0;
372 /** Gets the DSA public key.
374 * @param aParams The DSA parameters
375 * @param aEncoding A non-modifiable descriptor representing the entire encoding.
376 * @return The DSA public key. */
377 virtual CDSAPublicKey* DSAPublicKeyL(const CDSAParameters& aParams, const TDesC8& aEncoding) const = 0;
379 /** Gets the digital DSA signature given an encoding key.
381 * @param aEncoding A non-modifiable descriptor representing the entire encoding.
382 * @return The DSA signature. */
383 virtual CDSASignature* DSASignatureL(const TDesC8& aEncoding) const = 0;
385 /** Gets the DSA parameters.
387 * @param aEncoding A non-modifiable descriptor representing the entire encoding.
388 * @return The DSA parameters. */
389 virtual CDSAParameters* DSAParametersL(const TDesC8& aEncoding) const = 0;
390 // New function for TKeyFactory API
391 virtual CDSAPublicKey* DSAPublicKeyL(const TDesC8& aParamsEncoding, const TDesC8& aEncoding) const = 0;
394 class CSigningKeyParameters : public CBase
395 /** Contains the parameter information required by some signing algorithms.
397 * The DSA signing algorithm needs parameters as well as a key. Currently, this
398 * class only contains DSA parameters.
405 /** Creates a new signing key parameters object.
407 * @return A pointer to the new signing key parameters object. */
408 IMPORT_C static CSigningKeyParameters* NewL();
410 /** Creates a new signing key parameters object and puts a pointer to the new object
411 * onto the cleanup stack.
413 * @return A pointer to the new signing key parameters object. */
414 IMPORT_C static CSigningKeyParameters* NewLC();
416 /** Creates a new signing key parameters object copied from an existing object.
418 * @param aParameters The signing key parameters object to be copied.
419 * @return A pointer to the new parameters object. */
420 IMPORT_C static CSigningKeyParameters* NewL(const CSigningKeyParameters& aParameters);
422 /** Creates a new signing key parameters object copied from an existing object
423 * and puts a pointer to the new object onto the cleanup stack.
425 * @param aParameters The signing key parameters object to be copied.
426 * @return A pointer to the new signing key parameters object. */
427 IMPORT_C static CSigningKeyParameters* NewLC(const CSigningKeyParameters& aParameters);
431 * Frees all resources owned by the object. */
432 IMPORT_C ~CSigningKeyParameters();
434 /** Sets the DSA parameters.
436 * @param aParams The DSA parameters. */
437 IMPORT_C void SetDSAParamsL(const CDSAParameters& aParams);
439 /** Gets the DSA parameters.
441 * @return The DSA parameters.
444 const CDSAParameters* DSAParams() const;
446 CSigningKeyParameters();
447 void ConstructL(const CSigningKeyParameters& aParameters);
448 CDSAParameters* iDSAParams;
452 class CSignedObject : public CBase
453 /** Base class for certificates.
460 /** Verifies a signature using the specified encoded key.
462 * @param aEncodedKey The encoded key.
463 * @return ETrue if the signature is valid, otherwise EFalse. */
464 IMPORT_C TBool VerifySignatureL(const TDesC8& aEncodedKey) const;
466 /** Verifies a signature using the specified encoded key and hash.
468 * @param aEncodedKey The encoded key.
469 * @param aHash The hash of the data to be validated.
470 * @return ETrue if the signature is valid, otherwise EFalse. */
471 IMPORT_C TBool VerifySignatureL(const TDesC8& aEncodedKey, const TDesC8& aHash) const;
473 /** Gets the digital signature.
475 * @return A non-modifiable pointer descriptor representing the digital signature. */
476 IMPORT_C const TPtrC8 Signature() const;
478 /** Gets the signed data.
480 * @return A non-modifiable pointer descriptor representing the signed data. */
481 IMPORT_C virtual const TPtrC8 SignedDataL() const = 0;
483 /** Gets the fingerprint.
485 * The fingerprint returned is the SHA1 hash of the encoding of the entire object.
487 * @return A non-modifiable pointer descriptor representing the finger print. */
488 IMPORT_C const TPtrC8 Fingerprint() const;
490 /** Gets the entire encoding.
492 * @return A non-modifiable pointer descriptor representing the entire encoding. */
493 IMPORT_C const TPtrC8 Encoding() const;
495 /** Gets the signing algorithm ID used.
497 * @return The signing algorithm ID. */
498 IMPORT_C const CSigningAlgorithmIdentifier& SigningAlgorithm() const;
500 /** Externalises the encoding of the entire object to a write stream.
502 * The fingerprint and the signed data can be regenerated after restoration.
504 * The presence of this function means that the standard templated operator<<()
505 * can be used to externalise objects of this class.
507 * @param aStream Stream to which the object should be externalised. */
508 IMPORT_C virtual void ExternalizeL(RWriteStream& aStream) const;
510 /** Internalises the encoded object from a read stream.
512 * The class makes use of a specification-specific parser class for extracting
513 * the various elements, that is provided by a subclass of CSignedObject. For
514 * this reason this function is pure virtual.
516 * The presence of this function means that the standard templated operator>>()
517 * can be used to internalise objects of this class.
519 * @param aStream Stream from which the contents of the field should be internalised. */
520 IMPORT_C virtual void InternalizeL(RReadStream& aStream) = 0;
522 /** Sets the signing key parameters.
524 * @param aParameters The signing key parameters. */
525 IMPORT_C void SetParametersL(const CSigningKeyParameters& aParameters);
527 /** Gets the encoded data for the specified encoded data element, in the (to be
528 * signed) tbsCertificate data structure, of the signed object.
530 * @param aIndex The encoded data element position in the tbsCertificate data
531 * structure. See the enumeration: CX509Certificate::Anonymous.
532 * @return The encoded data for the specified data element of the signed object. */
533 IMPORT_C virtual const TPtrC8* DataElementEncoding(const TUint aIndex) const = 0;
537 * Frees all resources owned by the object. */
538 IMPORT_C ~CSignedObject();
541 /** Verifies a RSA signature using the specified encoded key.
543 * @param aEncodedKey The encoded key.
544 * @return ETrue if the signature is valid, otherwise EFalse.
547 TBool VerifyRSASignatureL(const TDesC8& aEncodedKey) const;
550 TBool VerifyRSASignatureL(const TDesC8& aEncodedKey, const TDesC8& aHash) const;
552 /** A pointer to a key factory object. */
553 TKeyFactory* iKeyFactory;
555 /** A heap descriptor representing the entire encoding. */
558 /** The digital signature. */
563 * The SHA1 hash of the encoding of the entire object. */
564 HBufC8* iFingerprint;
566 /** The signing key parameters */
567 CSigningKeyParameters* iParameters;
569 /** The signing algorithm ID. */
570 CSigningAlgorithmIdentifier* iSigningAlgorithm;
573 class CCertificate : public CSignedObject
574 /** A data structure that binds a public key to a given individual.
576 * A certificate is a signed object, and adds a serial number, a validity period
577 * and a subject public key.
579 * This is a base class for classes that implement certificates of particular types.
588 * Frees all resources owned by the object. */
589 IMPORT_C ~CCertificate();
591 /** Gets the subject public key information.
593 * @return The subject public key information. */
594 IMPORT_C const CSubjectPublicKeyInfo& PublicKey() const;
596 /** Gets the serial number.
598 * @return A non-modifiable pointer descriptor representing the serial number. */
599 IMPORT_C const TPtrC8 SerialNumber() const;
601 /** Gets the validity period.
603 * @return The validity period. */
604 IMPORT_C const CValidityPeriod& ValidityPeriod() const;
606 /** Tests whether a certificate is self-signed.
608 * @return ETrue, if it is self-signed; EFalse, otherwise. */
609 IMPORT_C virtual TBool IsSelfSignedL() const = 0;
611 /** Gets the subject.
613 * @return A heap descriptor representing the subject. */
614 IMPORT_C virtual HBufC* SubjectL() const = 0;
618 * @return A heap descriptor representing the issuer. */
619 IMPORT_C virtual HBufC* IssuerL() const = 0;
621 /** Gets the key identifier.
623 * @return The key identifier. */
624 IMPORT_C virtual TKeyIdentifier KeyIdentifierL() const;
627 /** The serial number. */
628 HBufC8* iSerialNumber;
630 /** The validity period. */
631 CValidityPeriod* iValidityPeriod;
633 /** The subject public key information. */
634 CSubjectPublicKeyInfo* iSubjectPublicKeyInfo;