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.
25 #ifndef __WTLSCERTCHAIN_H__
26 #define __WTLSCERTCHAIN_H__
29 #include <unifiedcertstore.h>
31 #include <wtlsnames.h>
33 class TWTLSValidationStatus
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 warnings.
42 /** Creates a validation status object.
44 * @param aError The error type that occurred when validating the certificate chain.
45 * @param aCert The index number for the certificate that gave rise to the error. */
46 IMPORT_C TWTLSValidationStatus(const TValidationError aError, const TInt aCert);
48 /** The reason for the error. */
49 TValidationError iReason;
51 /** The index number for the certificate that gave rise to the error. */
55 class CWTLSValidationResult : public CBase
56 /** Encapsulates the results of the validation process.
58 * It is returned to client code, which can examine it. Client code takes ownership of it.
63 /** Creates a new CWTLSValidationResult object and puts a pointer to it on the
66 * @return The new WTLS Validation Result object. */
67 IMPORT_C static CWTLSValidationResult* NewLC();
69 /** Creates a new CWTLSValidationResult object.
71 * @return The new WTLS Validation Result object. */
72 IMPORT_C static CWTLSValidationResult* NewL();
76 * Frees all resources owned by the object, prior to its destruction. */
77 IMPORT_C ~CWTLSValidationResult();
79 /** Gets the error status of the operation.
81 * Any errors here are considered fatal: validation has failed.
83 * @return The error status of the operation. */
84 IMPORT_C const TWTLSValidationStatus Error() const;
86 /** Gets an array of any warnings generated.
88 * The warnings may or may not be fatal, depending on the context, which the
89 * client is expected to provide.
91 * @return An array of any warnings generated. */
92 IMPORT_C const CArrayFixFlat<TWTLSValidationStatus>& Warnings() const;
94 /** Resets the validation result object to its default values.
101 * @param aError The error type that occurred when validating the certificate chain.
102 * @param aCert The index number for the certificate that gave rise to the error.
105 void SetError(const TValidationError aError, const TInt aCert);
107 /** Adds a warning to the validation.
109 * @param aWarning The validation status object to be added.
112 void AppendWarningL(TWTLSValidationStatus aWarning);
115 CWTLSValidationResult();
117 TWTLSValidationStatus iError;
118 CArrayFixFlat<TWTLSValidationStatus>* iWarnings;
121 class CWTLSRootCerts;
122 class CWTLSCertChainAO;
124 class CWTLSCertChain : public CBase
125 /** Implements a WTLS certificate chain.
129 friend class CWTLSCertChainAO;
132 /** Creates a certificate chain using the binary data in aEncodedCerts.
134 * @param aFs An open file server session.
135 * @param aEncodedCerts One or more concatenated DER encoded WTLS certificates.
136 * The first certificate will be interpreted as the end entity
137 * certificate to be validated; subsequent certificates may be
138 * in any order and may be used by the chain as intermediate
139 * certificates, but not root certificates.
140 * @param aClient The uid of the client. It is a value identifying the application
141 * to the chain; this will be used to select a subset of stored
142 * certificates to use as candidate root certificates. */
143 IMPORT_C static CWTLSCertChain* NewL(RFs& aFs, const TPtrC8& aEncodedCerts,
146 /** Creates a certificate chain using the binary data in aEncodedCerts and puts
147 * a pointer to the new object onto the cleanup stack.
149 * @param aFs An open file server session
150 * @param aEncodedCerts One or more concatenated DER encoded WTLS certificates.
151 * The first certificate will be interpreted as the end entity
152 * certificate to be validated; subsequent certificates may be
153 * in any order and may be used by the chain as intermediate
154 * certificates, but not root certificates.
155 * @param aClient The uid of the client. It is a value identifying the application
156 * to the chain; this will be used to select a subset of stored
157 * certificates to use as candidate root certificates. */
158 IMPORT_C static CWTLSCertChain* NewLC(RFs& aFs, const TPtrC8& aEncodedCerts,
161 /** Creates a certificate chain using the binary data in aEncodedCerts.
163 * @param aFs An open file server session.
164 * @param aEncodedCerts One or more concatenated DER encoded WTLS certificates.
165 * The first certificate will be interpreted as the end entity
166 * certificate to be validated; subsequent certificates may be
167 * in any order and may be used by the chain as intermediate
168 * certificates, but not root certificates. Any self signed
169 * certificates supplied here after the first one will be
170 * discarded, as self signed certificates cannot by definition
171 * be intermediate certificates.
172 * @param aRootCerts An array of certificates which the chain will treat as
173 * candidate root certificates. If one of these overloads is
174 * used, the chain will not look in stores for root certificates,
175 * but will only use the certificates supplied here. */
176 IMPORT_C static CWTLSCertChain* NewL(RFs& aFs, const TPtrC8& aEncodedCerts,
177 const CArrayPtr<CWTLSCertificate>& aRootCerts);
179 /** Creates a certificate chain using the binary data in aEncodedCerts and puts
180 * a pointer to the new object onto the cleanup stack.
182 * @param aFs An open file server session.
183 * @param aEncodedCerts One or more concatenated DER encoded WTLS certificates.
184 * The first certificate will be interpreted as the end entity
185 * certificate to be validated; subsequent certificates may be
186 * in any order and may be used by the chain as intermediate
187 * certificates, but not root certificates. Any self signed
188 * certificates supplied here after the first one will be
189 * discarded as self signed certificates cannot by definition
190 * be intermediate certificates.
191 * @param aRootCerts An array of certificates which the chain will treat as
192 * candidate root certificates. If one of these overloads is
193 * used, the chain will not look in stores for root certificates,
194 * but will only use the certificates supplied here. */
195 IMPORT_C static CWTLSCertChain* NewLC(RFs& aFs, const TPtrC8& aEncodedCerts,
196 const CArrayPtr<CWTLSCertificate>& aRootCerts);
200 * Frees all resources owned by the object. */
201 IMPORT_C ~CWTLSCertChain();
203 /** Validates the chain.
205 * @param aValidationResult On completion, this contains the result of the validation.
206 * @param aValidationTime The time for which validation should be performed, usually
208 * @param aStatus An asynchronous request status object. */
209 IMPORT_C void ValidateL(CWTLSValidationResult& aValidationResult,
210 const TTime& aValidationTime, TRequestStatus& aStatus);
212 /** Gets the number of WTLS certificates in the chain.
214 * @return The number of WTLS certificates in the chain. */
215 IMPORT_C TInt Count() const;
217 /** Gets the certificate at the specified index.
219 * @param aIndex The ordinal number representing the position of the certificate
221 * @return The WTLS certificate at the specified index. */
222 IMPORT_C const CWTLSCertificate& Cert(TInt aIndex) const;
224 /** Tests whether the root certificate of the chain is locatable.
226 * Note that the value is only significant after a successfull call to ValidateL().
228 * @return ETrue if the chain has a root; EFalse, otherwise. */
229 IMPORT_C TBool ChainHasRoot() const;
231 /** Appends the specified encoded certificate to the chain.
233 * @param aEncodedCerts One or more concatenated DER encoded WTLS certificates.
234 * These certificates will be used as candidates. The first
235 * certificate will be interpreted as the end entity certificate
236 * to be validated; subsequent certificates may be in any order
237 * and may be used by the chain as intermediate certificates,
238 * but not root certificates. */
239 IMPORT_C void AppendCertsL(const TPtrC8& aEncodedCerts);
242 CWTLSCertChain(RFs& aFs);
243 void ConstructL(const TPtrC8& aEncodedCerts, const TUid aClient);
244 void ConstructL(const TPtrC8& aEncodedCerts, const CArrayPtr<CWTLSCertificate>& aRootCerts);
245 void DoConstructL(const TPtrC8& aEncodedCerts);
249 CWTLSCertChainAO* iActiveObject;
250 CArrayPtrFlat<CWTLSCertificate>* iChain;