os/security/cryptoservices/certificateandkeymgmt/inc/wtlscertchain.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 *
    16 */
    17 
    18 
    19 /**
    20  @file 
    21  @publishedAll
    22  @released
    23 */
    24  
    25 #ifndef __WTLSCERTCHAIN_H__
    26 #define __WTLSCERTCHAIN_H__
    27 
    28 #include <e32std.h>
    29 #include <unifiedcertstore.h>
    30 #include <wtlscert.h>
    31 #include <wtlsnames.h>
    32 
    33 class TWTLSValidationStatus
    34 /** The validation status.
    35 *
    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. 
    38 *
    39 */
    40 	{
    41 public:
    42 	/** Creates a validation status object.
    43 	* 
    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);
    47 	
    48 	/** The reason for the error. */
    49 	TValidationError iReason;
    50 	
    51 	/** The index number for the certificate that gave rise to the error. */
    52 	TInt iCert;
    53 	};
    54 
    55 class CWTLSValidationResult : public CBase
    56 /** Encapsulates the results of the validation process.
    57 * 
    58 * It is returned to client code, which can examine it. Client code takes ownership of it. 
    59 *
    60 */
    61 	{
    62 public:
    63 	/** Creates a new CWTLSValidationResult object and puts a pointer to it on the 
    64 	* cleanup stack.
    65 	* 
    66 	* @return	The new WTLS Validation Result object. */
    67 	IMPORT_C static CWTLSValidationResult* NewLC();
    68 	
    69 	/** Creates a new CWTLSValidationResult object.
    70 	* 
    71 	* @return	The new WTLS Validation Result object. */
    72 	IMPORT_C static CWTLSValidationResult* NewL();
    73 	
    74 	/** Destructor.
    75 	* 
    76 	* Frees all resources owned by the object, prior to its destruction. */
    77 	IMPORT_C ~CWTLSValidationResult();
    78 	
    79 	/** Gets the error status of the operation.
    80 	* 
    81 	* Any errors here are considered fatal: validation has failed.
    82 	* 
    83 	* @return	The error status of the operation. */
    84 	IMPORT_C const TWTLSValidationStatus Error() const;
    85 	
    86 	/** Gets an array of any warnings generated.
    87 	* 
    88 	* The warnings may or may not be fatal, depending on the context, which the 
    89 	* client is expected to provide.
    90 	* 
    91 	* @return	An array of any warnings generated. */
    92 	IMPORT_C const CArrayFixFlat<TWTLSValidationStatus>& Warnings() const;
    93 	
    94 	/** Resets the validation result object to its default values. 
    95 	 * @internalAll
    96 	 */
    97 	void Reset();
    98 	
    99 	/** Sets the error.
   100 	* 
   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. 
   103 	* @internalAll
   104 	*/
   105 	void SetError(const TValidationError aError, const TInt aCert);
   106 	
   107 	/** Adds a warning to the validation.
   108 	* 
   109 	* @param aWarning	The validation status object to be added. 
   110 	* @internalAll
   111 	*/
   112 	void AppendWarningL(TWTLSValidationStatus aWarning);
   113 
   114 private:
   115 	CWTLSValidationResult();
   116 	void ConstructL();
   117 	TWTLSValidationStatus iError;
   118 	CArrayFixFlat<TWTLSValidationStatus>* iWarnings;
   119 	};
   120 
   121 class CWTLSRootCerts;
   122 class CWTLSCertChainAO;
   123 
   124 class CWTLSCertChain : public CBase
   125 /** Implements a WTLS certificate chain. 
   126 *
   127 */
   128 	{
   129 	friend class CWTLSCertChainAO;
   130 
   131 public:
   132 	/** Creates a certificate chain using the binary data in aEncodedCerts.
   133 	* 
   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, 
   144 		const TUid aClient);
   145 	
   146 	/** Creates a certificate chain using the binary data in aEncodedCerts and puts 
   147 	* a pointer to the new object onto the cleanup stack.
   148 	* 
   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,
   159 		const TUid aClient);
   160 	
   161 	/** Creates a certificate chain using the binary data in aEncodedCerts.
   162 	* 
   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);
   178 	
   179 	/** Creates a certificate chain using the binary data in aEncodedCerts and puts 
   180 	* a pointer to the new object onto the cleanup stack.
   181 	* 
   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);
   197 	
   198 	/** Destructor.
   199 	* 
   200 	* Frees all resources owned by the object. */
   201 	IMPORT_C ~CWTLSCertChain();
   202 	
   203 	/** Validates the chain.
   204 	* 
   205 	* @param aValidationResult	On completion, this contains the result of the validation.
   206 	* @param aValidationTime	The time for which validation should be performed, usually 
   207 	* 							the current time.
   208 	* @param aStatus			An asynchronous request status object. */
   209 	IMPORT_C void ValidateL(CWTLSValidationResult& aValidationResult, 
   210 		const TTime& aValidationTime, TRequestStatus& aStatus);
   211 	
   212 	/** Gets the number of WTLS certificates in the chain.
   213 	* 
   214 	* @return	The number of WTLS certificates in the chain. */
   215 	IMPORT_C TInt Count() const;
   216 	
   217 	/** Gets the certificate at the specified index.
   218 	* 
   219 	* @param aIndex	The ordinal number representing the position of the certificate 
   220 	* 				within the chain.
   221 	* @return		The WTLS certificate at the specified index. */
   222 	IMPORT_C const CWTLSCertificate& Cert(TInt aIndex) const;
   223 	
   224 	/** Tests whether the root certificate of the chain is locatable.
   225 	* 
   226 	* Note that the value is only significant after a successfull call to ValidateL().
   227 	* 
   228 	* @return	ETrue if the chain has a root; EFalse, otherwise. */
   229 	IMPORT_C TBool ChainHasRoot() const;
   230 	
   231 	/** Appends the specified encoded certificate to the chain.
   232 	* 
   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);
   240 
   241 private:
   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);
   246 		
   247 private:
   248 	RFs& iFs;
   249 	CWTLSCertChainAO* iActiveObject;
   250 	CArrayPtrFlat<CWTLSCertificate>* iChain;
   251 	TBool iChainHasRoot;
   252 	};
   253 
   254 #endif
   255