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