epoc32/include/wtlscert.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) 1997-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 __WTLSCERT_H__
williamr@2
    26
#define __WTLSCERT_H__
williamr@2
    27
williamr@2
    28
#include <e32base.h>
williamr@2
    29
#include <e32std.h>
williamr@2
    30
#include <s32std.h>
williamr@2
    31
#include <signed.h>
williamr@2
    32
#include <unifiedcertstore.h>
williamr@2
    33
#include <wtlsnames.h>
williamr@2
    34
williamr@2
    35
williamr@2
    36
class CRSAPublicKey;
williamr@2
    37
class CDSAPublicKey;
williamr@2
    38
class CDSASignature;
williamr@2
    39
class CDSAParameters;
williamr@2
    40
williamr@2
    41
const TInt KWTLSCertMaxDataElements = 6;
williamr@2
    42
williamr@2
    43
class CWTLSRSASignatureResult : public CRSASignatureResult
williamr@2
    44
	{
williamr@2
    45
public:
williamr@2
    46
	IMPORT_C static CWTLSRSASignatureResult* NewL(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest);
williamr@2
    47
	IMPORT_C static CWTLSRSASignatureResult* NewLC(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest);
williamr@2
    48
	IMPORT_C virtual TBool VerifyL(const TDesC8& aResult);
williamr@2
    49
private:
williamr@2
    50
	void ConstructL(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest);
williamr@2
    51
	};
williamr@2
    52
williamr@2
    53
class TWTLSKeyFactory : public TKeyFactory
williamr@2
    54
	{
williamr@2
    55
public:
williamr@2
    56
	virtual CRSAPublicKey* RSAPublicKeyL(const TDesC8& aEncoding) const;
williamr@2
    57
	virtual CRSASignatureResult* RSASignatureResultL(const CAlgorithmIdentifier& aDigestAlgorithm, TDesC8& aDigest) const;
williamr@2
    58
	virtual CDSAPublicKey* DSAPublicKeyL(const CDSAParameters& aParams, const TDesC8& aEncoding) const;
williamr@2
    59
	virtual CDSASignature* DSASignatureL(const TDesC8& aEncoding) const;
williamr@2
    60
	virtual CDSAParameters* DSAParametersL(const TDesC8& aEncoding) const;
williamr@2
    61
	virtual CDSAPublicKey* DSAPublicKeyL(const TDesC8& aParamsEncoding, const TDesC8& aEncoding) const;
williamr@2
    62
	};
williamr@2
    63
williamr@2
    64
class CWTLSValidityPeriod : public CValidityPeriod
williamr@2
    65
	{
williamr@2
    66
public:
williamr@2
    67
	IMPORT_C static CWTLSValidityPeriod* NewL(const TDesC8& aBinaryData);
williamr@2
    68
	IMPORT_C static CWTLSValidityPeriod* NewLC(const TDesC8& aBinaryData);
williamr@2
    69
	IMPORT_C static CWTLSValidityPeriod* NewL(const TDesC8& aBinaryData, TInt& aPos);
williamr@2
    70
	IMPORT_C static CWTLSValidityPeriod* NewLC(const TDesC8& aBinaryData, TInt& aPos);
williamr@2
    71
private:
williamr@2
    72
	CWTLSValidityPeriod();
williamr@2
    73
	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
williamr@2
    74
	};
williamr@2
    75
williamr@2
    76
class CWTLSAlgorithmIdentifier : public CAlgorithmIdentifier
williamr@2
    77
	{
williamr@2
    78
public:
williamr@2
    79
	IMPORT_C static CWTLSAlgorithmIdentifier* NewL(const TDesC8& aBinaryData);
williamr@2
    80
	IMPORT_C static CWTLSAlgorithmIdentifier* NewLC(const TDesC8& aBinaryData);
williamr@2
    81
	IMPORT_C static CWTLSAlgorithmIdentifier* NewL(const TDesC8& aBinaryData, TInt& aPos);
williamr@2
    82
	IMPORT_C static CWTLSAlgorithmIdentifier* NewLC(const TDesC8& aBinaryData, TInt& aPos);
williamr@2
    83
private:
williamr@2
    84
	CWTLSAlgorithmIdentifier();
williamr@2
    85
	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
williamr@2
    86
	};
williamr@2
    87
williamr@2
    88
class CWTLSSigningAlgorithmIdentifier : public CSigningAlgorithmIdentifier
williamr@2
    89
	{
williamr@2
    90
public:
williamr@2
    91
	IMPORT_C static CWTLSSigningAlgorithmIdentifier* NewL(const TDesC8& aBinaryData);
williamr@2
    92
	IMPORT_C static CWTLSSigningAlgorithmIdentifier* NewLC(const TDesC8& aBinaryData);
williamr@2
    93
	IMPORT_C static CWTLSSigningAlgorithmIdentifier* NewL(const TDesC8& aBinaryData, TInt& aPos);
williamr@2
    94
	IMPORT_C static CWTLSSigningAlgorithmIdentifier* NewLC(const TDesC8& aBinaryData, TInt& aPos);
williamr@2
    95
private:
williamr@2
    96
	CWTLSSigningAlgorithmIdentifier();
williamr@2
    97
	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
williamr@2
    98
	};
williamr@2
    99
williamr@2
   100
class CWTLSSubjectPublicKeyInfo : public CSubjectPublicKeyInfo
williamr@2
   101
	{
williamr@2
   102
public:
williamr@2
   103
	IMPORT_C static CWTLSSubjectPublicKeyInfo* NewL(const TDesC8& aBinaryData);
williamr@2
   104
	IMPORT_C static CWTLSSubjectPublicKeyInfo* NewLC(const TDesC8& aBinaryData);
williamr@2
   105
	IMPORT_C static CWTLSSubjectPublicKeyInfo* NewL(const TDesC8& aBinaryData, TInt& aPos);
williamr@2
   106
	IMPORT_C static CWTLSSubjectPublicKeyInfo* NewLC(const TDesC8& aBinaryData, TInt& aPos);
williamr@2
   107
private:
williamr@2
   108
	CWTLSSubjectPublicKeyInfo();
williamr@2
   109
	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
williamr@2
   110
	};
williamr@2
   111
williamr@2
   112
_LIT(KWTLSTCAType, " T");
williamr@2
   113
_LIT(KWTLSTCAValue, "ca");
williamr@2
   114
williamr@2
   115
class CWTLSCertificate : public CCertificate
williamr@2
   116
	{
williamr@2
   117
public:
williamr@2
   118
	enum	//enum values for encoded data element positions in tbsCert data structure
williamr@2
   119
		{	//these values are to be used as params to DataElementEncoding() function
williamr@2
   120
		EVersionNumber = 0,
williamr@2
   121
		EAlgorithmId = 1,
williamr@2
   122
		EIssuerName = 2,
williamr@2
   123
		EValidityPeriod = 3,
williamr@2
   124
		ESubjectName = 4,
williamr@2
   125
		ESubjectPublicKeyInfo = 5,
williamr@2
   126
		};
williamr@2
   127
		
williamr@2
   128
	/**
williamr@2
   129
	 * Creates a new CWTLSCertificate object from the specified buffer containing the binary coded representation.
williamr@2
   130
	 *
williamr@2
   131
	 * @param aBinaryData	The encoded binary representation.
williamr@2
   132
	 * @return				The new CWTLSCertificate object.
williamr@2
   133
	 */	
williamr@2
   134
	IMPORT_C static CWTLSCertificate* NewL(const TDesC8& aBinaryData);
williamr@2
   135
williamr@2
   136
	/**
williamr@2
   137
	 * Creates a new CWTLSCertificate object from the specified buffer containing the binary coded representation,
williamr@2
   138
	 * and puts a pointer to it onto the cleanup stack.
williamr@2
   139
	 *
williamr@2
   140
	 * @param aBinaryData	The encoded binary representation.
williamr@2
   141
	 * @return				The new CWTLSCertificate object.
williamr@2
   142
	 */	
williamr@2
   143
	IMPORT_C static CWTLSCertificate* NewLC(const TDesC8& aBinaryData);
williamr@2
   144
williamr@2
   145
	/**
williamr@2
   146
	 * Creates a new CWTLSCertificate object from the specified buffer containing the binary coded representation.
williamr@2
   147
	 *
williamr@2
   148
	 * @param aBinaryData	The encoded binary representation.
williamr@2
   149
	 * @param aPos			An offset into the descriptor, and is updated to the position at the end of the object.
williamr@2
   150
	 * @return				The new CWTLSCertificate object.
williamr@2
   151
	 */	
williamr@2
   152
	IMPORT_C static CWTLSCertificate* NewL(const TDesC8& aBinaryData, TInt& aPos);
williamr@2
   153
williamr@2
   154
	/**
williamr@2
   155
	 * Creates a new CWTLSCertificate object from the specified buffer containing the binary coded representation,
williamr@2
   156
	 * and puts a pointer to it onto the cleanup stack.
williamr@2
   157
	 *
williamr@2
   158
	 * @param aBinaryData	The encoded binary representation.
williamr@2
   159
	 * @param aPos			An offset into the descriptor, and is updated to the position at the end of the object.
williamr@2
   160
	 * @return				The new CWTLSCertificate object.
williamr@2
   161
	 */	
williamr@2
   162
	IMPORT_C static CWTLSCertificate* NewLC(const TDesC8& aBinaryData, TInt& aPos);
williamr@2
   163
williamr@2
   164
	/**
williamr@2
   165
	 * Creates a new CWTLSCertificate object from a stream.
williamr@2
   166
	 *
williamr@2
   167
	 * The stream must have been written using the corresponding ExternalizeL() function.
williamr@2
   168
	 *
williamr@2
   169
	 * @param aStream	The stream to be used as input.
williamr@2
   170
	 * @return			The new CWTLSCertificate object.
williamr@2
   171
	 */	
williamr@2
   172
	IMPORT_C static CWTLSCertificate* NewL(RReadStream& aStream);
williamr@2
   173
williamr@2
   174
	/**
williamr@2
   175
	 * Creates a new CWTLSCertificate object from a stream,
williamr@2
   176
	 * and puts a pointer to it onto the cleanup stack.
williamr@2
   177
	 *
williamr@2
   178
	 * The stream must have been written using the corresponding ExternalizeL() function.
williamr@2
   179
	 *
williamr@2
   180
	 * @param aStream	The stream to be used as input.
williamr@2
   181
	 * @return			The new CWTLSCertificate object.
williamr@2
   182
	 */	
williamr@2
   183
	IMPORT_C static CWTLSCertificate* NewLC(RReadStream& aStream);
williamr@2
   184
williamr@2
   185
	/**
williamr@2
   186
	 * Creates a new CWTLSCertificate object from an existing one in the certificate store.
williamr@2
   187
	 *
williamr@2
   188
	 * @param aCert	The certificate to be copied.
williamr@2
   189
	 * @return		The new CWTLSCertificate object.
williamr@2
   190
	 */	
williamr@2
   191
	IMPORT_C static CWTLSCertificate* NewL(const CWTLSCertificate& aCert);
williamr@2
   192
williamr@2
   193
	/**
williamr@2
   194
	 * Creates a new CWTLSCertificate object from an existing one in the certificate store,
williamr@2
   195
	 * and puts a pointer to it onto the cleanup stack.
williamr@2
   196
	 *
williamr@2
   197
	 * @param aCert	The certificate to be copied.
williamr@2
   198
	 * @return		The new CWTLSCertificate object.
williamr@2
   199
	 */	
williamr@2
   200
	IMPORT_C static CWTLSCertificate* NewLC(const CWTLSCertificate& aCert);
williamr@2
   201
williamr@2
   202
	/**
williamr@2
   203
	 * Destructor.
williamr@2
   204
	 *
williamr@2
   205
	 * Frees all resources owned by the object, prior to its destruction.
williamr@2
   206
	 */
williamr@2
   207
	IMPORT_C ~CWTLSCertificate();
williamr@2
   208
	
williamr@2
   209
	/**
williamr@2
   210
	* Tests whether this WTLS certificate is the same as the specified WTLS certificate.
williamr@2
   211
	*
williamr@2
   212
	* This is not a simple as it sounds. For X.509 certificates equality means that the issuer name 
williamr@2
   213
	* and serial number fields are the same. This guarantees equality since a CA must ensure that every 
williamr@2
   214
	* certificate it issues has a unique serial number. But WTLS certificates do not include serial numbers, 
williamr@2
   215
	* so there seems to be no definition of equality. This function uses a byte-for-byte comparison of the 
williamr@2
   216
	* signatures on the certificates: this should not result in any false positives, but may give false 
williamr@2
   217
	* negatives if CAs do naughty things like recertifying the same key (which they have been known to do).
williamr@2
   218
	*
williamr@2
   219
	* @param aCert	A WTLS certificate
williamr@2
   220
	* @return		ETrue, if the parameter is the same certificate; EFalse, otherwise.
williamr@2
   221
	*/
williamr@2
   222
	IMPORT_C TBool IsEqualL(const CWTLSCertificate& aCert) const;
williamr@2
   223
	
williamr@2
   224
	//extra accessors
williamr@2
   225
	
williamr@2
   226
	/**
williamr@2
   227
	 * Gets the version number of the WTLS certificate.
williamr@2
   228
	 *
williamr@2
   229
	 * @return	The version number of the certificate. Always returns 1.
williamr@2
   230
	 */
williamr@2
   231
	IMPORT_C TInt Version() const;
williamr@2
   232
	
williamr@2
   233
	/**
williamr@2
   234
	 * Gets the name of the WTLS certificate's issuing authority.
williamr@2
   235
	 *
williamr@2
   236
	 * @return	A WTLS name:
williamr@2
   237
	 *			@li	If the name is an X.500 DN, then if the name contains a Common name, that will be returned. 
williamr@2
   238
	 * 				Otherwise, if the name contains an Organization name, that will be returned. Otherwise an empty 
williamr@2
   239
	 * 				string will be returned. 
williamr@2
   240
	 *			@li	If the name is of type text, then if the name is not a 'structured' name the entire string will 
williamr@2
   241
	 *				be returned, otherwise the same procedure will be followed as for X.509 certificates.
williamr@2
   242
	 * 			@li	If the name is null an empty string will be returned. 
williamr@2
   243
	 */
williamr@2
   244
	 // Unsupported -- If the name is a key hash or binary value the entire contents will be returned.
williamr@2
   245
	IMPORT_C const CWTLSName& IssuerName() const;
williamr@2
   246
	
williamr@2
   247
	/**
williamr@2
   248
	* Gets the name of the owner of the public key the WTLS certificate contains.
williamr@2
   249
	*
williamr@2
   250
	* @return A WTLS name.
williamr@2
   251
	*/
williamr@2
   252
	IMPORT_C const CWTLSName& SubjectName() const;
williamr@2
   253
	IMPORT_C virtual TBool IsSelfSignedL() const;
williamr@2
   254
	IMPORT_C virtual HBufC* SubjectL() const;
williamr@2
   255
	IMPORT_C virtual HBufC* IssuerL() const;
williamr@2
   256
	
williamr@2
   257
	/**
williamr@2
   258
	* Initialises the certificate from a stream. 
williamr@2
   259
	*
williamr@2
   260
	* This should not be called by client code; instead the static factory function above should be used. 
williamr@2
   261
	* If a client is using the certstore component for storage then it should use CCertStore::AddL() for 
williamr@2
   262
	* externalizing and CWTLSCert::NewL(CCertStore& aStore, const CCertStoreEntry& aEntry); for restoring.
williamr@2
   263
	*
williamr@2
   264
	* @param aStream 
williamr@2
   265
	*/
williamr@2
   266
	IMPORT_C void InternalizeL(RReadStream& aStream);
williamr@2
   267
	
williamr@2
   268
	/**
williamr@2
   269
	* Gets the certificate's signed data.
williamr@2
   270
	*
williamr@2
   271
	* @return	A non-modifiable pointer descriptor representing the certificate's signed data.
williamr@2
   272
	*/
williamr@2
   273
	IMPORT_C const TPtrC8 SignedDataL() const;
williamr@2
   274
	
williamr@2
   275
	/**
williamr@2
   276
	* Gets the encoding for a data element at the specified index.
williamr@2
   277
	*
williamr@2
   278
	* @param aIndex	The position of the encoded data element.
williamr@2
   279
	*/
williamr@2
   280
	IMPORT_C virtual const TPtrC8* DataElementEncoding(const TUint aIndex) const;
williamr@2
   281
	
williamr@2
   282
	/**
williamr@2
   283
	* Tests whether a non-selfsigned certificate can be used to sign others.
williamr@2
   284
	* 
williamr@2
   285
	* Currently this only supports structured text variety of WTLS certificates.  
williamr@2
   286
	* Other certificate types will return EFalse.
williamr@2
   287
	*
williamr@2
   288
	* @return	ETrue, if the certificate is capable of signing other certificates; otherwise, EFalse. 
williamr@2
   289
	*/
williamr@2
   290
	IMPORT_C TBool IsTCAL() const;
williamr@2
   291
private:
williamr@2
   292
	CWTLSCertificate();
williamr@2
   293
	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
williamr@2
   294
	void ConstructL(const CWTLSCertificate& aCertificate);
williamr@2
   295
	void ConstructCertL(const TDesC8& aBinaryData, TInt& aPos);
williamr@2
   296
	void InitEncodedDataElementsL();
williamr@2
   297
	//private data
williamr@2
   298
	TInt iVersion;
williamr@2
   299
	CWTLSName* iIssuerName;
williamr@2
   300
	CWTLSName* iSubjectName;
williamr@2
   301
	TFixedArray<TPtrC8*, KWTLSCertMaxDataElements>* iDataElements;
williamr@2
   302
	};
williamr@2
   303
williamr@2
   304
#endif