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