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.
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
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
/**
sl@0
    20
 @file 
sl@0
    21
 @publishedAll
sl@0
    22
 @released
sl@0
    23
*/
sl@0
    24
 
sl@0
    25
#ifndef __WTLSCERTCHAIN_H__
sl@0
    26
#define __WTLSCERTCHAIN_H__
sl@0
    27
sl@0
    28
#include <e32std.h>
sl@0
    29
#include <unifiedcertstore.h>
sl@0
    30
#include <wtlscert.h>
sl@0
    31
#include <wtlsnames.h>
sl@0
    32
sl@0
    33
class TWTLSValidationStatus
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 warnings. 
sl@0
    38
*
sl@0
    39
*/
sl@0
    40
	{
sl@0
    41
public:
sl@0
    42
	/** Creates a validation status object.
sl@0
    43
	* 
sl@0
    44
	* @param aError	The error type that occurred when validating the certificate chain.
sl@0
    45
	* @param aCert	The index number for the certificate that gave rise to the error. */
sl@0
    46
	IMPORT_C TWTLSValidationStatus(const TValidationError aError, const TInt aCert);
sl@0
    47
	
sl@0
    48
	/** The reason for the error. */
sl@0
    49
	TValidationError iReason;
sl@0
    50
	
sl@0
    51
	/** The index number for the certificate that gave rise to the error. */
sl@0
    52
	TInt iCert;
sl@0
    53
	};
sl@0
    54
sl@0
    55
class CWTLSValidationResult : public CBase
sl@0
    56
/** Encapsulates the results of the validation process.
sl@0
    57
* 
sl@0
    58
* It is returned to client code, which can examine it. Client code takes ownership of it. 
sl@0
    59
*
sl@0
    60
*/
sl@0
    61
	{
sl@0
    62
public:
sl@0
    63
	/** Creates a new CWTLSValidationResult object and puts a pointer to it on the 
sl@0
    64
	* cleanup stack.
sl@0
    65
	* 
sl@0
    66
	* @return	The new WTLS Validation Result object. */
sl@0
    67
	IMPORT_C static CWTLSValidationResult* NewLC();
sl@0
    68
	
sl@0
    69
	/** Creates a new CWTLSValidationResult object.
sl@0
    70
	* 
sl@0
    71
	* @return	The new WTLS Validation Result object. */
sl@0
    72
	IMPORT_C static CWTLSValidationResult* NewL();
sl@0
    73
	
sl@0
    74
	/** Destructor.
sl@0
    75
	* 
sl@0
    76
	* Frees all resources owned by the object, prior to its destruction. */
sl@0
    77
	IMPORT_C ~CWTLSValidationResult();
sl@0
    78
	
sl@0
    79
	/** Gets the error status of the operation.
sl@0
    80
	* 
sl@0
    81
	* Any errors here are considered fatal: validation has failed.
sl@0
    82
	* 
sl@0
    83
	* @return	The error status of the operation. */
sl@0
    84
	IMPORT_C const TWTLSValidationStatus Error() const;
sl@0
    85
	
sl@0
    86
	/** Gets an array of any warnings generated.
sl@0
    87
	* 
sl@0
    88
	* The warnings may or may not be fatal, depending on the context, which the 
sl@0
    89
	* client is expected to provide.
sl@0
    90
	* 
sl@0
    91
	* @return	An array of any warnings generated. */
sl@0
    92
	IMPORT_C const CArrayFixFlat<TWTLSValidationStatus>& Warnings() const;
sl@0
    93
	
sl@0
    94
	/** Resets the validation result object to its default values. 
sl@0
    95
	 * @internalAll
sl@0
    96
	 */
sl@0
    97
	void Reset();
sl@0
    98
	
sl@0
    99
	/** Sets the error.
sl@0
   100
	* 
sl@0
   101
	* @param aError	The error type that occurred when validating the certificate chain.
sl@0
   102
	* @param aCert	The index number for the certificate that gave rise to the error. 
sl@0
   103
	* @internalAll
sl@0
   104
	*/
sl@0
   105
	void SetError(const TValidationError aError, const TInt aCert);
sl@0
   106
	
sl@0
   107
	/** Adds a warning to the validation.
sl@0
   108
	* 
sl@0
   109
	* @param aWarning	The validation status object to be added. 
sl@0
   110
	* @internalAll
sl@0
   111
	*/
sl@0
   112
	void AppendWarningL(TWTLSValidationStatus aWarning);
sl@0
   113
sl@0
   114
private:
sl@0
   115
	CWTLSValidationResult();
sl@0
   116
	void ConstructL();
sl@0
   117
	TWTLSValidationStatus iError;
sl@0
   118
	CArrayFixFlat<TWTLSValidationStatus>* iWarnings;
sl@0
   119
	};
sl@0
   120
sl@0
   121
class CWTLSRootCerts;
sl@0
   122
class CWTLSCertChainAO;
sl@0
   123
sl@0
   124
class CWTLSCertChain : public CBase
sl@0
   125
/** Implements a WTLS certificate chain. 
sl@0
   126
*
sl@0
   127
*/
sl@0
   128
	{
sl@0
   129
	friend class CWTLSCertChainAO;
sl@0
   130
sl@0
   131
public:
sl@0
   132
	/** Creates a certificate chain using the binary data in aEncodedCerts.
sl@0
   133
	* 
sl@0
   134
	* @param aFs			An open file server session.
sl@0
   135
	* @param aEncodedCerts	One or more concatenated DER encoded WTLS certificates. 
sl@0
   136
	* 						The first certificate will be interpreted as the end entity 
sl@0
   137
	* 						certificate to be validated; subsequent certificates may be 
sl@0
   138
	* 						in any order and may be used by the chain as intermediate 
sl@0
   139
	* 						certificates, but not root certificates.
sl@0
   140
	* @param aClient		The uid of the client. It is a value identifying the application 
sl@0
   141
	* 						to the chain; this will be used to select a subset of stored 
sl@0
   142
	* 						certificates to use as candidate root certificates. */
sl@0
   143
	IMPORT_C static CWTLSCertChain* NewL(RFs& aFs, const TPtrC8& aEncodedCerts, 
sl@0
   144
		const TUid aClient);
sl@0
   145
	
sl@0
   146
	/** Creates a certificate chain using the binary data in aEncodedCerts and puts 
sl@0
   147
	* a pointer to the new object onto the cleanup stack.
sl@0
   148
	* 
sl@0
   149
	* @param aFs			An open file server session
sl@0
   150
	* @param aEncodedCerts	One or more concatenated DER encoded WTLS certificates. 
sl@0
   151
	* 						The first certificate will be interpreted as the end entity 
sl@0
   152
	* 						certificate to be validated; subsequent certificates may be 
sl@0
   153
	* 						in any order and may be used by the chain as intermediate 
sl@0
   154
	* 						certificates, but not root certificates.
sl@0
   155
	* @param aClient		The uid of the client. It is a value identifying the application 
sl@0
   156
	* 						to the chain; this will be used to select a subset of stored 
sl@0
   157
	* 						certificates to use as candidate root certificates. */
sl@0
   158
	IMPORT_C static CWTLSCertChain* NewLC(RFs& aFs, const TPtrC8& aEncodedCerts,
sl@0
   159
		const TUid aClient);
sl@0
   160
	
sl@0
   161
	/** Creates a certificate chain using the binary data in aEncodedCerts.
sl@0
   162
	* 
sl@0
   163
	* @param aFs			An open file server session.
sl@0
   164
	* @param aEncodedCerts	One or more concatenated DER encoded WTLS certificates. 
sl@0
   165
	* 						The first certificate will be interpreted as the end entity 
sl@0
   166
	* 						certificate to be validated; subsequent certificates may be 
sl@0
   167
	* 						in any order and may be used by the chain as intermediate 
sl@0
   168
	* 						certificates, but not root certificates. Any self signed 
sl@0
   169
	* 						certificates supplied here after the first one will be 
sl@0
   170
	* 						discarded, as self signed certificates cannot by definition 
sl@0
   171
	* 						be intermediate certificates.
sl@0
   172
	* @param aRootCerts		An array of certificates which the chain will treat as 
sl@0
   173
	* 						candidate root certificates. If one of these overloads is 
sl@0
   174
	* 						used, the chain will not look in stores for root certificates, 
sl@0
   175
	* 						but will only use the certificates supplied here. */
sl@0
   176
	IMPORT_C static CWTLSCertChain* NewL(RFs& aFs, const TPtrC8& aEncodedCerts,
sl@0
   177
		const CArrayPtr<CWTLSCertificate>& aRootCerts);
sl@0
   178
	
sl@0
   179
	/** Creates a certificate chain using the binary data in aEncodedCerts and puts 
sl@0
   180
	* a pointer to the new object onto the cleanup stack.
sl@0
   181
	* 
sl@0
   182
	* @param aFs			An open file server session.
sl@0
   183
	* @param aEncodedCerts	One or more concatenated DER encoded WTLS certificates. 
sl@0
   184
	* 						The first certificate will be interpreted as the end entity 
sl@0
   185
	* 						certificate to be validated; subsequent certificates may be 
sl@0
   186
	* 						in any order and may be used by the chain as intermediate 
sl@0
   187
	* 						certificates, but not root certificates. Any self signed 
sl@0
   188
	* 						certificates supplied here after the first one will be 
sl@0
   189
	* 						discarded as self signed certificates cannot by definition 
sl@0
   190
	* 						be intermediate certificates.
sl@0
   191
	* @param aRootCerts		An array of certificates which the chain will treat as 
sl@0
   192
	* 						candidate root certificates. If one of these overloads is 
sl@0
   193
	* 						used, the chain will not look in stores for root certificates, 
sl@0
   194
	* 						but will only use the certificates supplied here. */
sl@0
   195
	IMPORT_C static CWTLSCertChain* NewLC(RFs& aFs, const TPtrC8& aEncodedCerts,
sl@0
   196
		const CArrayPtr<CWTLSCertificate>& aRootCerts);
sl@0
   197
	
sl@0
   198
	/** Destructor.
sl@0
   199
	* 
sl@0
   200
	* Frees all resources owned by the object. */
sl@0
   201
	IMPORT_C ~CWTLSCertChain();
sl@0
   202
	
sl@0
   203
	/** Validates the chain.
sl@0
   204
	* 
sl@0
   205
	* @param aValidationResult	On completion, this contains the result of the validation.
sl@0
   206
	* @param aValidationTime	The time for which validation should be performed, usually 
sl@0
   207
	* 							the current time.
sl@0
   208
	* @param aStatus			An asynchronous request status object. */
sl@0
   209
	IMPORT_C void ValidateL(CWTLSValidationResult& aValidationResult, 
sl@0
   210
		const TTime& aValidationTime, TRequestStatus& aStatus);
sl@0
   211
	
sl@0
   212
	/** Gets the number of WTLS certificates in the chain.
sl@0
   213
	* 
sl@0
   214
	* @return	The number of WTLS certificates in the chain. */
sl@0
   215
	IMPORT_C TInt Count() const;
sl@0
   216
	
sl@0
   217
	/** Gets the certificate at the specified index.
sl@0
   218
	* 
sl@0
   219
	* @param aIndex	The ordinal number representing the position of the certificate 
sl@0
   220
	* 				within the chain.
sl@0
   221
	* @return		The WTLS certificate at the specified index. */
sl@0
   222
	IMPORT_C const CWTLSCertificate& Cert(TInt aIndex) const;
sl@0
   223
	
sl@0
   224
	/** Tests whether the root certificate of the chain is locatable.
sl@0
   225
	* 
sl@0
   226
	* Note that the value is only significant after a successfull call to ValidateL().
sl@0
   227
	* 
sl@0
   228
	* @return	ETrue if the chain has a root; EFalse, otherwise. */
sl@0
   229
	IMPORT_C TBool ChainHasRoot() const;
sl@0
   230
	
sl@0
   231
	/** Appends the specified encoded certificate to the chain.
sl@0
   232
	* 
sl@0
   233
	* @param aEncodedCerts	One or more concatenated DER encoded WTLS certificates. 
sl@0
   234
	* 						These certificates will be used as candidates. The first 
sl@0
   235
	* 						certificate will be interpreted as the end entity certificate 
sl@0
   236
	* 						to be validated; subsequent certificates may be in any order 
sl@0
   237
	* 						and may be used by the chain as intermediate certificates, 
sl@0
   238
	* 						but not root certificates. */
sl@0
   239
	IMPORT_C void AppendCertsL(const TPtrC8& aEncodedCerts);
sl@0
   240
sl@0
   241
private:
sl@0
   242
	CWTLSCertChain(RFs& aFs);
sl@0
   243
	void ConstructL(const TPtrC8& aEncodedCerts, const TUid aClient);
sl@0
   244
	void ConstructL(const TPtrC8& aEncodedCerts, const CArrayPtr<CWTLSCertificate>& aRootCerts);
sl@0
   245
	void DoConstructL(const TPtrC8& aEncodedCerts);
sl@0
   246
		
sl@0
   247
private:
sl@0
   248
	RFs& iFs;
sl@0
   249
	CWTLSCertChainAO* iActiveObject;
sl@0
   250
	CArrayPtrFlat<CWTLSCertificate>* iChain;
sl@0
   251
	TBool iChainHasRoot;
sl@0
   252
	};
sl@0
   253
sl@0
   254
#endif
sl@0
   255