First public contribution.
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.
15 * X509 certificate chain and the validation status implementations
26 #ifndef __X509CERTCHAIN_H__
27 #define __X509CERTCHAIN_H__
33 class TValidationStatus
34 /** The validation status.
36 * Some errors cannot be blamed on any single certificate, in which case the
37 * iCert value is meaningless. The same structure is used for errors and for
43 /** Creates a validation status object.
45 * @param aError The error type that occurred when validating the certificate chain.
46 * @param aCert The index number identifying the certificate that gave rise to
48 IMPORT_C TValidationStatus(const TValidationError aError, const TInt aCert);
50 /** The reason for the error. */
51 TValidationError iReason;
53 /** The index number identifying the certificate that gave rise to the error. */
57 class CX509CertChain : public CBase
58 /** Abstract base class for X.509 certificate chain validation;
59 * derive from this to suit your profile.
64 /** Gets the number of certificates in the chain.
66 * @return The number of certificates in the chain. */
67 IMPORT_C TInt Count() const;
69 /** Gets the certificate identified by the specified index.
70 * Note that Cert(Count()) corresponds to the root (if any)
71 * whilst Cert(0) corresponds to the outmost certificate in the chain.
73 * @param aIndex The ordinal number representing the position of the certificate
75 * @return The X.509 certificate at the specified index. */
76 IMPORT_C const CX509Certificate& Cert(TInt aIndex) const;
78 /** Decodes the individual elements of the signed data to construct the certificates.
80 * @param aBinaryData The encoded binary representation.
81 * @return The certificate objects. */
82 IMPORT_C CArrayPtrFlat<CX509Certificate>* DecodeCertsL(const TDesC8& aBinaryData);
86 * Frees all resources owned by the object, prior to its destruction. */
87 IMPORT_C ~CX509CertChain();
89 /** Tests whether the specified X.509 certificate chain is equal to this X.509
92 * @param aOther The X.509 certificate chain to be compared.
93 * @return ETrue, if the certificate chains are equal;EFalse, otherwise. */
94 IMPORT_C TBool IsEqualL(const CX509CertChain& aOther) const;
97 CArrayPtrFlat<CX509Certificate>* iChain;
99 static void CleanupCertArray(TAny* aArray);
102 class CCertificateValidationWarnings : public CBase
103 /** Encapsulates the critical extensions encountered and any warnings found
104 * for a particular certificate in the chain during the process of validation.
109 /** Creates an instance of CCertificateValidationWarnings.
111 * @param aIndex The index of aCert in the certificate chain.
112 * @return A pointer to the new CCertificateWarning object. */
113 IMPORT_C static CCertificateValidationWarnings* NewL(TInt aIndex);
115 /** Creates an instance of CCertificateValidationWarnings.
117 * @param aIndex The index of aCert in the certificate chain.
118 * @return A pointer to the new CCertificateWarning object. */
119 IMPORT_C static CCertificateValidationWarnings* NewLC(TInt aIndex);
121 /** Gets a list of critical extension OIDs found in the certificate.
123 * @return An array of critical extensions found. */
124 IMPORT_C const RPointerArray<TDesC>& CriticalExtensionsFound() const;
126 /** Gets a list of warnings generated by the certificate.
128 * @return An array of warnings generated. */
129 IMPORT_C const RArray<TValidationStatus>& Warnings() const;
131 /** Gets the index of the certificate in the chain.
133 * @return The certificate index number. */
134 IMPORT_C TInt CertIndex() const;
136 /** Externalises an object of this class to a write stream.
138 * The presence of this function means that the standard templated operator<<()
139 * can be used to externalise objects of this class.
141 * @param aStream Stream to which the object should be externalised. */
142 IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
144 /** Internalises an object of this class from a read stream.
146 * The presence of this function means that the standard templated operator>>()
147 * can be used to internalise objects of this class.
149 * Note that this function has assignment semantics: it replaces the old value
150 * of the object with a new value read from the read stream.
152 * @param aStream Stream from which the object should be internalised.
153 * @return A pointer to the new CCertificateWarning object. */
154 IMPORT_C static CCertificateValidationWarnings* InternalizeL(RReadStream& aStream);
158 * Frees all resources owned by the object. */
159 IMPORT_C ~CCertificateValidationWarnings();
165 IMPORT_C void AppendWarningL(TValidationStatus aWarning);
167 /** Adds a critical extension OID warning.
170 IMPORT_C void AppendCriticalExtensionWarningL(TDesC& aCriticalExt);
173 CCertificateValidationWarnings(TInt aIndex);
177 RPointerArray<TDesC> iCriticalExtsFound;
178 RArray<TValidationStatus> iWarnings;