os/security/cryptoservices/certificateandkeymgmt/inc/x509certchain.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 * X509 certificate chain and the validation status implementations
    16 *
    17 */
    18 
    19 
    20 /**
    21  @file 
    22  @publishedAll
    23  @released
    24 */
    25  
    26 #ifndef __X509CERTCHAIN_H__
    27 #define __X509CERTCHAIN_H__
    28 
    29 #include <e32std.h>
    30 #include <x509cert.h>
    31 #include <ct.h>
    32 
    33 class TValidationStatus
    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 
    38 * warnings. 
    39 * 
    40 * @since v6.0 */
    41 	{
    42 public:
    43 	/** Creates a validation status object.	
    44 	* 
    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 
    47 	* 				the error. */
    48 	IMPORT_C TValidationStatus(const TValidationError aError, const TInt aCert);
    49 	
    50 	/** The reason for the error. */
    51 	TValidationError iReason;
    52 	
    53 	/** The index number identifying the certificate that gave rise to the error. */
    54 	TInt iCert;
    55 	};
    56 
    57 class CX509CertChain : public CBase
    58 /** Abstract base class for X.509 certificate chain validation; 
    59 * derive from this to suit your profile.
    60 * 
    61 * @since v6.0 */
    62 	{
    63 public:
    64 	/** Gets the number of certificates in the chain.	
    65 	* 
    66 	* @return	The number of certificates in the chain. */
    67 	IMPORT_C TInt Count() const;
    68 	
    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.
    72 	*
    73 	* @param aIndex	The ordinal number representing the position of the certificate 
    74 	* 				within the chain.
    75 	* @return		The X.509 certificate at the specified index. */
    76 	IMPORT_C const CX509Certificate& Cert(TInt aIndex) const;
    77 	
    78 	/** Decodes the individual elements of the signed data to construct the certificates.
    79 	* 
    80 	* @param aBinaryData	The encoded binary representation.
    81 	* @return				The certificate objects. */
    82 	IMPORT_C CArrayPtrFlat<CX509Certificate>* DecodeCertsL(const TDesC8& aBinaryData);
    83 	
    84 	/** Destructor.
    85 	* 
    86 	* Frees all resources owned by the object, prior to its destruction. */
    87 	IMPORT_C ~CX509CertChain();
    88 
    89 	/** Tests whether the specified X.509 certificate chain is equal to this X.509 
    90 	* certificate chain.
    91 	* 
    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;
    95 protected:
    96 	//certificate chain
    97 	CArrayPtrFlat<CX509Certificate>* iChain;
    98 private:
    99 	static void CleanupCertArray(TAny* aArray);
   100 	};
   101 	
   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.
   105 	* 
   106 	* @since v9.5 */
   107 		{
   108 	public:
   109 		/** Creates an instance of CCertificateValidationWarnings.
   110 		* 
   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);
   114 
   115 		/** Creates an instance of CCertificateValidationWarnings.
   116 		* 
   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);		
   120 		
   121 		/** Gets a list of critical extension OIDs found in the certificate.
   122 		* 
   123 		* @return	An array of critical extensions found. */		
   124 		IMPORT_C const RPointerArray<TDesC>& CriticalExtensionsFound() const;
   125 		
   126 		/** Gets a list of warnings generated by the certificate.
   127 		* 
   128 		* @return	An array of warnings generated. */	
   129 		IMPORT_C const RArray<TValidationStatus>& Warnings() const;
   130 		
   131 		/** Gets the index of the certificate in the chain.
   132 		* 
   133 		* @return	The certificate index number. */		
   134 		IMPORT_C TInt CertIndex() const;
   135 		
   136 		/** Externalises an object of this class to a write stream.
   137 		* 
   138 		* The presence of this function means that the standard templated operator<<() 
   139 		* can be used to externalise objects of this class.
   140 		* 
   141 		* @param aStream    Stream to which the object should be externalised. */
   142 		IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
   143 		
   144 		/** Internalises an object of this class from a read stream.
   145 		* 
   146 		* The presence of this function means that the standard templated operator>>() 
   147 		* can be used to internalise objects of this class.
   148 		* 
   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. 
   151 		* 
   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);
   155 		
   156 		/** The destructor.
   157 		* 
   158 		* Frees all resources owned by the object. */
   159 		IMPORT_C ~CCertificateValidationWarnings();
   160 		
   161 	public:
   162 		/** Adds a warning.
   163 		* 
   164 	    */
   165 		IMPORT_C void AppendWarningL(TValidationStatus aWarning);
   166 		
   167 		/** Adds a critical extension OID warning.
   168 		* 
   169 		*/
   170 		IMPORT_C void AppendCriticalExtensionWarningL(TDesC& aCriticalExt);
   171 		
   172 	private:
   173 		CCertificateValidationWarnings(TInt aIndex);
   174 	
   175 	private:
   176 		TInt iCertIndex;
   177 		RPointerArray<TDesC> iCriticalExtsFound;
   178 		RArray<TValidationStatus> iWarnings;
   179 		};
   180 
   181 #endif
   182 
   183