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.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
* X509 certificate chain and the validation status implementations
sl@0
    16
*
sl@0
    17
*/
sl@0
    18
sl@0
    19
sl@0
    20
/**
sl@0
    21
 @file 
sl@0
    22
 @publishedAll
sl@0
    23
 @released
sl@0
    24
*/
sl@0
    25
 
sl@0
    26
#ifndef __X509CERTCHAIN_H__
sl@0
    27
#define __X509CERTCHAIN_H__
sl@0
    28
sl@0
    29
#include <e32std.h>
sl@0
    30
#include <x509cert.h>
sl@0
    31
#include <ct.h>
sl@0
    32
sl@0
    33
class TValidationStatus
sl@0
    34
/** The validation status.
sl@0
    35
* 
sl@0
    36
* Some errors cannot be blamed on any single certificate, in which case the 
sl@0
    37
* iCert value is meaningless. The same structure is used for errors and for 
sl@0
    38
* warnings. 
sl@0
    39
* 
sl@0
    40
* @since v6.0 */
sl@0
    41
	{
sl@0
    42
public:
sl@0
    43
	/** Creates a validation status object.	
sl@0
    44
	* 
sl@0
    45
	* @param aError	The error type that occurred when validating the certificate chain.
sl@0
    46
	* @param aCert	The index number identifying the certificate that gave rise to 
sl@0
    47
	* 				the error. */
sl@0
    48
	IMPORT_C TValidationStatus(const TValidationError aError, const TInt aCert);
sl@0
    49
	
sl@0
    50
	/** The reason for the error. */
sl@0
    51
	TValidationError iReason;
sl@0
    52
	
sl@0
    53
	/** The index number identifying the certificate that gave rise to the error. */
sl@0
    54
	TInt iCert;
sl@0
    55
	};
sl@0
    56
sl@0
    57
class CX509CertChain : public CBase
sl@0
    58
/** Abstract base class for X.509 certificate chain validation; 
sl@0
    59
* derive from this to suit your profile.
sl@0
    60
* 
sl@0
    61
* @since v6.0 */
sl@0
    62
	{
sl@0
    63
public:
sl@0
    64
	/** Gets the number of certificates in the chain.	
sl@0
    65
	* 
sl@0
    66
	* @return	The number of certificates in the chain. */
sl@0
    67
	IMPORT_C TInt Count() const;
sl@0
    68
	
sl@0
    69
	/** Gets the certificate identified by the specified index.
sl@0
    70
	* Note that Cert(Count()) corresponds to the root (if any)
sl@0
    71
	* whilst Cert(0) corresponds to the outmost certificate in the chain.
sl@0
    72
	*
sl@0
    73
	* @param aIndex	The ordinal number representing the position of the certificate 
sl@0
    74
	* 				within the chain.
sl@0
    75
	* @return		The X.509 certificate at the specified index. */
sl@0
    76
	IMPORT_C const CX509Certificate& Cert(TInt aIndex) const;
sl@0
    77
	
sl@0
    78
	/** Decodes the individual elements of the signed data to construct the certificates.
sl@0
    79
	* 
sl@0
    80
	* @param aBinaryData	The encoded binary representation.
sl@0
    81
	* @return				The certificate objects. */
sl@0
    82
	IMPORT_C CArrayPtrFlat<CX509Certificate>* DecodeCertsL(const TDesC8& aBinaryData);
sl@0
    83
	
sl@0
    84
	/** Destructor.
sl@0
    85
	* 
sl@0
    86
	* Frees all resources owned by the object, prior to its destruction. */
sl@0
    87
	IMPORT_C ~CX509CertChain();
sl@0
    88
sl@0
    89
	/** Tests whether the specified X.509 certificate chain is equal to this X.509 
sl@0
    90
	* certificate chain.
sl@0
    91
	* 
sl@0
    92
	* @param aOther	The X.509 certificate chain to be compared.
sl@0
    93
	* @return		ETrue, if the certificate chains are equal;EFalse, otherwise. */
sl@0
    94
	IMPORT_C TBool IsEqualL(const CX509CertChain& aOther) const;
sl@0
    95
protected:
sl@0
    96
	//certificate chain
sl@0
    97
	CArrayPtrFlat<CX509Certificate>* iChain;
sl@0
    98
private:
sl@0
    99
	static void CleanupCertArray(TAny* aArray);
sl@0
   100
	};
sl@0
   101
	
sl@0
   102
class CCertificateValidationWarnings : public CBase
sl@0
   103
	/** Encapsulates the critical extensions encountered and any warnings found
sl@0
   104
	* for a particular certificate in the chain during the process of validation.
sl@0
   105
	* 
sl@0
   106
	* @since v9.5 */
sl@0
   107
		{
sl@0
   108
	public:
sl@0
   109
		/** Creates an instance of CCertificateValidationWarnings.
sl@0
   110
		* 
sl@0
   111
		* @param aIndex	The index of aCert in the certificate chain.
sl@0
   112
		* @return	A pointer to the new CCertificateWarning object. */	
sl@0
   113
		IMPORT_C static CCertificateValidationWarnings* NewL(TInt aIndex);
sl@0
   114
sl@0
   115
		/** Creates an instance of CCertificateValidationWarnings.
sl@0
   116
		* 
sl@0
   117
		* @param aIndex	The index of aCert in the certificate chain.
sl@0
   118
		* @return	A pointer to the new CCertificateWarning object. */	
sl@0
   119
		IMPORT_C static CCertificateValidationWarnings* NewLC(TInt aIndex);		
sl@0
   120
		
sl@0
   121
		/** Gets a list of critical extension OIDs found in the certificate.
sl@0
   122
		* 
sl@0
   123
		* @return	An array of critical extensions found. */		
sl@0
   124
		IMPORT_C const RPointerArray<TDesC>& CriticalExtensionsFound() const;
sl@0
   125
		
sl@0
   126
		/** Gets a list of warnings generated by the certificate.
sl@0
   127
		* 
sl@0
   128
		* @return	An array of warnings generated. */	
sl@0
   129
		IMPORT_C const RArray<TValidationStatus>& Warnings() const;
sl@0
   130
		
sl@0
   131
		/** Gets the index of the certificate in the chain.
sl@0
   132
		* 
sl@0
   133
		* @return	The certificate index number. */		
sl@0
   134
		IMPORT_C TInt CertIndex() const;
sl@0
   135
		
sl@0
   136
		/** Externalises an object of this class to a write stream.
sl@0
   137
		* 
sl@0
   138
		* The presence of this function means that the standard templated operator<<() 
sl@0
   139
		* can be used to externalise objects of this class.
sl@0
   140
		* 
sl@0
   141
		* @param aStream    Stream to which the object should be externalised. */
sl@0
   142
		IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
sl@0
   143
		
sl@0
   144
		/** Internalises an object of this class from a read stream.
sl@0
   145
		* 
sl@0
   146
		* The presence of this function means that the standard templated operator>>() 
sl@0
   147
		* can be used to internalise objects of this class.
sl@0
   148
		* 
sl@0
   149
		* Note that this function has assignment semantics: it replaces the old value 
sl@0
   150
		* of the object with a new value read from the read stream. 
sl@0
   151
		* 
sl@0
   152
		* @param aStream    Stream from which the object should be internalised. 
sl@0
   153
		* @return A pointer to the new CCertificateWarning object. */
sl@0
   154
		IMPORT_C static CCertificateValidationWarnings* InternalizeL(RReadStream& aStream);
sl@0
   155
		
sl@0
   156
		/** The destructor.
sl@0
   157
		* 
sl@0
   158
		* Frees all resources owned by the object. */
sl@0
   159
		IMPORT_C ~CCertificateValidationWarnings();
sl@0
   160
		
sl@0
   161
	public:
sl@0
   162
		/** Adds a warning.
sl@0
   163
		* 
sl@0
   164
	    */
sl@0
   165
		IMPORT_C void AppendWarningL(TValidationStatus aWarning);
sl@0
   166
		
sl@0
   167
		/** Adds a critical extension OID warning.
sl@0
   168
		* 
sl@0
   169
		*/
sl@0
   170
		IMPORT_C void AppendCriticalExtensionWarningL(TDesC& aCriticalExt);
sl@0
   171
		
sl@0
   172
	private:
sl@0
   173
		CCertificateValidationWarnings(TInt aIndex);
sl@0
   174
	
sl@0
   175
	private:
sl@0
   176
		TInt iCertIndex;
sl@0
   177
		RPointerArray<TDesC> iCriticalExtsFound;
sl@0
   178
		RArray<TValidationStatus> iWarnings;
sl@0
   179
		};
sl@0
   180
sl@0
   181
#endif
sl@0
   182
sl@0
   183