os/security/cryptoservices/certificateandkeymgmt/inc/wtlsnames.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
#if !defined (__WTLSNAMES_H__)
sl@0
    21
#define __WTLSNAMES_H__
sl@0
    22
sl@0
    23
#include <e32base.h>
sl@0
    24
#include <e32std.h>
sl@0
    25
#include <x500dn.h>
sl@0
    26
sl@0
    27
/**
sl@0
    28
@file
sl@0
    29
This file contains the definition for class CWTLSName.
sl@0
    30
sl@0
    31
@publishedAll
sl@0
    32
@released
sl@0
    33
sl@0
    34
enum { null(0), text(1), binary(2), key_hash_sha(254), x509_name(255)}
sl@0
    35
	IdentifierType;
sl@0
    36
sl@0
    37
We only support text and x509_name as these are the only meaningful identifiers..
sl@0
    38
x509_name is X.500 Distinguished Name, and should use our existing X.500 DN implementation.  
sl@0
    39
sl@0
    40
struct {
sl@0
    41
		IdentifierType identifier_type;
sl@0
    42
		select (identifier_type) {
sl@0
    43
			case null: struct {};
sl@0
    44
			case text:
sl@0
    45
				CharacterSet character_set;
sl@0
    46
				opaque name<1.. 2^8-1>;
sl@0
    47
			case binary: opaque identifier<1..2^8-1>;
sl@0
    48
			case key_hash_sha: opaque key_hash[20];
sl@0
    49
			case x509_name: opaque distinguished_name<1..2^8-1>;
sl@0
    50
		} 
sl@0
    51
		Identifier;
sl@0
    52
sl@0
    53
uint16 CharacterSet;
sl@0
    54
sl@0
    55
This maps on to one of the IANA defined character sets. There are rather a lot
sl@0
    56
of these.  We just support the text type, with either Latin1 or UTF8 encoding.
sl@0
    57
*/
sl@0
    58
sl@0
    59
/**
sl@0
    60
 * Enumerates the types of WTLS certificate name forms/identifiers.
sl@0
    61
 * 
sl@0
    62
 * Only text strings and X.500 Distinguished Names are currently supported.
sl@0
    63
 * 
sl@0
    64
 */
sl@0
    65
enum 
sl@0
    66
	{
sl@0
    67
	/* Null */
sl@0
    68
	EWTLSNull =			0x00,
sl@0
    69
	/* Text string (Latin-1 or Unicode). 
sl@0
    70
	 *
sl@0
    71
	 * A text identifier consists of a 16-bit character set identifier; 
sl@0
    72
	 * this represents the IANA-assigned character set number. */
sl@0
    73
	EWTLSText =			0x01,
sl@0
    74
	/* Binary identifier.
sl@0
    75
	 *
sl@0
    76
	 * Certificates of this type will be rejected.*/
sl@0
    77
	EWTLSBinary =		0x02,
sl@0
    78
	/* Key Hash SHA-1. 
sl@0
    79
	 *
sl@0
    80
	 * Certificates of this type will be rejected.*/
sl@0
    81
	EWTLSKeyHashSha =	0xfe,
sl@0
    82
	/* X.500 Distinguished Name. */
sl@0
    83
	EWTLSX500DN =		0xff
sl@0
    84
	};
sl@0
    85
sl@0
    86
typedef TUint8 TWTLSNameType;
sl@0
    87
sl@0
    88
typedef TInt TWTLSCharSet;
sl@0
    89
sl@0
    90
// MIBenum constants from the IANA list of character sets.
sl@0
    91
// See http://www.iana.org/assignments/character-sets for more info.
sl@0
    92
sl@0
    93
/** MIBenum constant for the Latin1 IANA character set */
sl@0
    94
const TInt KWTLSLatin1CharSet = 4;
sl@0
    95
sl@0
    96
/** MIBenum constant for the UTF-8 IANA character set */
sl@0
    97
const TInt KWTLSUTF8CharSet = 106;
sl@0
    98
sl@0
    99
class CWTLSName : public CBase
sl@0
   100
/**
sl@0
   101
 * Stores the type of a WTLS name and the underlying encoding of the type.
sl@0
   102
 *
sl@0
   103
 */
sl@0
   104
	{
sl@0
   105
public:
sl@0
   106
	/**
sl@0
   107
	 * Creates a new CWTLSName object from the specified buffer containing the binary coded representation.
sl@0
   108
	 *
sl@0
   109
	 * @param aBinaryData	The encoded binary representation.
sl@0
   110
	 * @return				The new CWTLSName object.
sl@0
   111
	 */
sl@0
   112
	IMPORT_C static CWTLSName* NewL(const TDesC8& aBinaryData);
sl@0
   113
sl@0
   114
	/**
sl@0
   115
	 * Creates a new CWTLSName object from the specified buffer containing the binary coded representation,
sl@0
   116
	 * and puts a pointer to it onto the cleanup stack.
sl@0
   117
	 *
sl@0
   118
	 * @param aBinaryData	The encoded binary representation.
sl@0
   119
	 * @return				The new CWTLSName object.
sl@0
   120
	 */
sl@0
   121
	IMPORT_C static CWTLSName* NewLC(const TDesC8& aBinaryData);
sl@0
   122
	
sl@0
   123
	/**
sl@0
   124
	 * Creates a new CWTLSName object from the specified buffer containing the binary coded representation, 
sl@0
   125
	 * starting at the specified offset.
sl@0
   126
	 *
sl@0
   127
	 * @param aBinaryData	The encoded binary representation.
sl@0
   128
	 * @param aPos			The offset position from which to start decoding. It specifies an offset into the descriptor, 
sl@0
   129
	 *						and is updated to the position at the end of the object.
sl@0
   130
	 * @return				The new CWTLSName object.
sl@0
   131
	 */
sl@0
   132
	IMPORT_C static CWTLSName* NewL(const TDesC8& aBinaryData, TInt& aPos);
sl@0
   133
sl@0
   134
	/**
sl@0
   135
	 * Creates a new CWTLSName object from the specified buffer containing the binary coded representation, 
sl@0
   136
	 * starting at the specified offset, and puts a pointer to it onto the cleanup stack.
sl@0
   137
	 *
sl@0
   138
	 * @param aBinaryData	The encoded binary representation.
sl@0
   139
	 * @param aPos			The offset position from which to start decoding. It specifies an offset into the descriptor, 
sl@0
   140
	 *						and is updated to the position at the end of the object.
sl@0
   141
	 * @return				The new CWTLSName object.
sl@0
   142
	 */
sl@0
   143
	IMPORT_C static CWTLSName* NewLC(const TDesC8& aBinaryData, TInt& aPos);
sl@0
   144
sl@0
   145
	/**
sl@0
   146
	 * Creates a new CWTLSName object from an existing one.
sl@0
   147
	 *
sl@0
   148
	 * @param aName	An existing CWTLSName object.
sl@0
   149
	 * @return		The new CWTLSName object.
sl@0
   150
	 */
sl@0
   151
	IMPORT_C static CWTLSName* NewL(const CWTLSName& aName);
sl@0
   152
sl@0
   153
	/**
sl@0
   154
	 * Creates a new CWTLSName object from an existing one, 
sl@0
   155
	 * and puts a pointer to it onto the cleanup stack.
sl@0
   156
	 *
sl@0
   157
	 * @param aName	An existing CWTLSName object.
sl@0
   158
	 * @return		The new CWTLSName object.
sl@0
   159
	 */
sl@0
   160
	IMPORT_C static CWTLSName* NewLC(const CWTLSName& aName);	
sl@0
   161
	
sl@0
   162
	/**
sl@0
   163
	 * Destructor.
sl@0
   164
	 *
sl@0
   165
	 * Frees all resources owned by the object, prior to its destruction.
sl@0
   166
	 */
sl@0
   167
	IMPORT_C ~CWTLSName(); 
sl@0
   168
	
sl@0
   169
	/**
sl@0
   170
	 * Performs a simple byte compare between this WTLS name and a specified WTLS name.
sl@0
   171
	 *
sl@0
   172
	 * Needed for the constructing/validating of certificate chains.
sl@0
   173
	 *
sl@0
   174
	 * @param aName	An existing CWTLSName object.
sl@0
   175
	 * @return		ETrue, if the WTLS names match; EFalse, otherwise.
sl@0
   176
	 */	
sl@0
   177
	IMPORT_C TBool ExactMatchL(const CWTLSName& aName) const;
sl@0
   178
	
sl@0
   179
	/** 
sl@0
   180
	 * Gets the type of the WTLS name.
sl@0
   181
	 *
sl@0
   182
	 * @return	Type of WTLS name form.
sl@0
   183
	 */	
sl@0
   184
	IMPORT_C TWTLSNameType NameType() const;
sl@0
   185
	
sl@0
   186
	/** 
sl@0
   187
	 * Gets the encoding of the underlying type of WTLS name.
sl@0
   188
	 *
sl@0
   189
	 * @return	Pointer descriptor representing the encoding of the WTLS name type.
sl@0
   190
	 */	
sl@0
   191
	IMPORT_C TPtrC8 NameData() const;
sl@0
   192
	
sl@0
   193
	/**
sl@0
   194
	 * Gets the decoded value for the common or organisation name.
sl@0
   195
	 *
sl@0
   196
	 * Provides the functionality required by the CCertificate::IssuerL() and SubjectL() functions.
sl@0
   197
	 *
sl@0
   198
	 * @return A heap descriptor containing the decoded value of the common or organisation name.
sl@0
   199
	 */
sl@0
   200
	IMPORT_C HBufC* DisplayNameL() const;
sl@0
   201
private:
sl@0
   202
	CWTLSName();
sl@0
   203
	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
sl@0
   204
	void ConstructL(const CWTLSName& aName);
sl@0
   205
	void AllocNameDataL(const TDesC8& aBinaryData, TInt& aPos);
sl@0
   206
	void AllocTextDataL(const TDesC8& aBinaryData, TInt& aPos);
sl@0
   207
	TWTLSNameType iNameType;
sl@0
   208
	HBufC8* iNameData;
sl@0
   209
	};
sl@0
   210
sl@0
   211
class CWTLSText : public CBase
sl@0
   212
	{
sl@0
   213
public:
sl@0
   214
	/**
sl@0
   215
	 * Creates a new CWTLSText object from the specified buffer containing the binary coded representation.
sl@0
   216
	 *
sl@0
   217
	 * @param aBinaryData	The encoded binary representation.
sl@0
   218
	 * @return				The new CWTLSText object.
sl@0
   219
	 */
sl@0
   220
	IMPORT_C static CWTLSText* NewL(const TDesC8& aBinaryData);
sl@0
   221
sl@0
   222
	/**
sl@0
   223
	 * Creates a new CWTLSText object from the specified buffer containing the binary coded representation,
sl@0
   224
	 * and puts a pointer to it onto the cleanup stack.
sl@0
   225
	 *
sl@0
   226
	 * @param aBinaryData	The encoded binary representation.
sl@0
   227
	 * @return				The new CWTLSText object.
sl@0
   228
	 */
sl@0
   229
	IMPORT_C static CWTLSText* NewLC(const TDesC8& aBinaryData);
sl@0
   230
sl@0
   231
	/**
sl@0
   232
	 * Creates a new CWTLSText object from the specified buffer containing the binary coded representation, 
sl@0
   233
	 * starting at the specified offset.
sl@0
   234
	 *
sl@0
   235
	 * @param aBinaryData	The encoded binary representation.
sl@0
   236
	 * @param aPos			The offset position from which to start decoding. It specifies an offset into the descriptor, 
sl@0
   237
	 *						and is updated to the position at the end of the object.
sl@0
   238
	 * @return				The new CWTLSText object.
sl@0
   239
	 */
sl@0
   240
	IMPORT_C static CWTLSText* NewL(const TDesC8& aBinaryData, TInt& aPos);
sl@0
   241
sl@0
   242
	/**
sl@0
   243
	 * Creates a new CWTLSText object from the specified buffer containing the binary coded representation, 
sl@0
   244
	 * starting at the specified offset, and puts a pointer to it onto the cleanup stack.
sl@0
   245
	 *
sl@0
   246
	 * @param aBinaryData	The encoded binary representation.
sl@0
   247
	 * @param aPos			The offset position from which to start decoding. It specifies an offset into the descriptor, 
sl@0
   248
	 *						and is updated to the position at the end of the object.
sl@0
   249
	 * @return				The new CWTLSText object.
sl@0
   250
	 */
sl@0
   251
	IMPORT_C static CWTLSText* NewLC(const TDesC8& aBinaryData, TInt& aPos);	
sl@0
   252
	
sl@0
   253
	/**
sl@0
   254
	 * Destructor.
sl@0
   255
	 *
sl@0
   256
	 * Frees all resources owned by the object, prior to its destruction.
sl@0
   257
	 */
sl@0
   258
	IMPORT_C ~CWTLSText(); 	
sl@0
   259
	
sl@0
   260
	/**
sl@0
   261
	 * Performs a simple byte compare between this CWTLSText object and a specified CWTLSText object.
sl@0
   262
	 *
sl@0
   263
	 * There is a subtle difference between this byte-match and CWTLSName::ExactMatchL().
sl@0
   264
	 * As opposed to the latter, this function should successfully match two names that 
sl@0
   265
	 * are the same that were encoded using different character sets.
sl@0
   266
	 *
sl@0
   267
	 * @param aName	An existing CWTLSText object.
sl@0
   268
	 * @return		ETrue, if the CWTLSText objects match; EFalse, otherwise.
sl@0
   269
	 */	
sl@0
   270
	IMPORT_C TBool ExactMatchL(const CWTLSText& aName) const;	
sl@0
   271
	
sl@0
   272
	/**
sl@0
   273
	 * Gets the name of the CWTLSText object.
sl@0
   274
	 *
sl@0
   275
	 * @return A pointer to the name of the CWTLSText object. 
sl@0
   276
	 */
sl@0
   277
	IMPORT_C TPtrC Name() const;
sl@0
   278
	
sl@0
   279
	/**
sl@0
   280
	 * Gets the character set of the CWTLSText object.
sl@0
   281
	 *
sl@0
   282
	 * @return The character set
sl@0
   283
	 */
sl@0
   284
	IMPORT_C TWTLSCharSet CharacterSet() const;
sl@0
   285
protected:
sl@0
   286
	/** 
sl@0
   287
	 * @internalAll
sl@0
   288
	 */
sl@0
   289
	CWTLSText();
sl@0
   290
	/** 
sl@0
   291
	 * @internalAll
sl@0
   292
	 */
sl@0
   293
	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
sl@0
   294
	HBufC* iName;
sl@0
   295
private:
sl@0
   296
	TInt iCharacterSet;
sl@0
   297
	};
sl@0
   298
sl@0
   299
//this class implements the 'structured' variant of the text type defined in the WTLS spec, section 10.5.2:
sl@0
   300
//<servicename>; <organization>; <country>[; <commonname>[; <extension>[; <extension>[ …. ]]]]
sl@0
   301
_LIT(KWTLSCountryName,"C");
sl@0
   302
_LIT(KWTLSOrganizationName,"O");
sl@0
   303
_LIT(KWTLSServiceName,"OU");
sl@0
   304
_LIT(KWTLSTitle,"T");
sl@0
   305
_LIT(KWTLSCommonName,"CN");
sl@0
   306
sl@0
   307
class TWTLSStructuredTextField 
sl@0
   308
	{
sl@0
   309
public:
sl@0
   310
	/** 
sl@0
   311
     * @internalAll
sl@0
   312
     */
sl@0
   313
	TWTLSStructuredTextField(const TDesC& aType, const TDesC& aValue);
sl@0
   314
sl@0
   315
	/**
sl@0
   316
	 *
sl@0
   317
	 * @return	
sl@0
   318
	 */
sl@0
   319
	IMPORT_C TPtrC Type() const;
sl@0
   320
sl@0
   321
	/**
sl@0
   322
	 *
sl@0
   323
	 * @return
sl@0
   324
	 */
sl@0
   325
	IMPORT_C TPtrC Value() const;
sl@0
   326
sl@0
   327
private:
sl@0
   328
	const TPtrC iType;
sl@0
   329
	const TPtrC iValue; 
sl@0
   330
	};
sl@0
   331
sl@0
   332
class CWTLSStructuredText : public CWTLSText
sl@0
   333
	{
sl@0
   334
public:
sl@0
   335
	/**
sl@0
   336
	 * Creates a new CWTLSStructuredText object from the specified buffer containing the binary coded representation.
sl@0
   337
	 *
sl@0
   338
	 * @param aBinaryData	The encoded binary representation.
sl@0
   339
	 * @return				The new CWTLSStructuredText object.
sl@0
   340
	 */
sl@0
   341
	IMPORT_C static CWTLSStructuredText* NewL(const TDesC8& aBinaryData);
sl@0
   342
sl@0
   343
	/**
sl@0
   344
	 * Creates a new CWTLSStructuredText object from the specified buffer containing the binary coded representation,
sl@0
   345
	 * and puts a pointer to it onto the cleanup stack.
sl@0
   346
	 *
sl@0
   347
	 * @param aBinaryData	The encoded binary representation.
sl@0
   348
	 * @return				The new CWTLSStructuredText object.
sl@0
   349
	 */
sl@0
   350
	IMPORT_C static CWTLSStructuredText* NewLC(const TDesC8& aBinaryData);
sl@0
   351
sl@0
   352
	/**
sl@0
   353
	 * Creates a new CWTLSStructuredText object from the specified buffer containing the binary coded representation, 
sl@0
   354
	 * starting at the specified offset.
sl@0
   355
	 *
sl@0
   356
	 * @param aBinaryData	The encoded binary representation.
sl@0
   357
	 * @param aPos			The offset position from which to start decoding. It specifies an offset into the descriptor, 
sl@0
   358
	 *						and is updated to the position at the end of the object.
sl@0
   359
	 * @return				The new CWTLSStructuredText object.
sl@0
   360
	 */
sl@0
   361
	IMPORT_C static CWTLSStructuredText* NewL(const TDesC8& aBinaryData, TInt& aPos);
sl@0
   362
sl@0
   363
	/**
sl@0
   364
	 * Creates a new CWTLSStructuredText object from the specified buffer containing the binary coded representation, 
sl@0
   365
	 * starting at the specified offset, and puts a pointer to it onto the cleanup stack.
sl@0
   366
	 *
sl@0
   367
	 * @param aBinaryData	The encoded binary representation.
sl@0
   368
	 * @param aPos			The offset position from which to start decoding. It specifies an offset into the descriptor, 
sl@0
   369
	 *						and is updated to the position at the end of the object.
sl@0
   370
	 * @return				The new CWTLSStructuredText object.
sl@0
   371
	 */
sl@0
   372
	IMPORT_C static CWTLSStructuredText* NewLC(const TDesC8& aBinaryData, TInt& aPos);
sl@0
   373
	
sl@0
   374
	/**
sl@0
   375
	 * Destructor.
sl@0
   376
	 *
sl@0
   377
	 * Frees all resources owned by the object, prior to its destruction.
sl@0
   378
	 */
sl@0
   379
	IMPORT_C ~CWTLSStructuredText(); 
sl@0
   380
	
sl@0
   381
	/**
sl@0
   382
	 * 
sl@0
   383
	 *
sl@0
   384
	 * @return
sl@0
   385
	 */
sl@0
   386
	IMPORT_C HBufC* DisplayNameL() const;
sl@0
   387
sl@0
   388
	//accessors for defined fields
sl@0
   389
	
sl@0
   390
	/**
sl@0
   391
	 *
sl@0
   392
	 *
sl@0
   393
	 * @return
sl@0
   394
	 */
sl@0
   395
	IMPORT_C TPtrC ServiceName() const;
sl@0
   396
	
sl@0
   397
	/**
sl@0
   398
	 *
sl@0
   399
	 *
sl@0
   400
	 * @return
sl@0
   401
	 */
sl@0
   402
	IMPORT_C TPtrC Organization() const;
sl@0
   403
	
sl@0
   404
	/**
sl@0
   405
	 *
sl@0
   406
	 *
sl@0
   407
	 * @return
sl@0
   408
	 */
sl@0
   409
	IMPORT_C TPtrC Country() const;
sl@0
   410
	
sl@0
   411
	/**
sl@0
   412
	 *
sl@0
   413
	 *
sl@0
   414
	 * @return
sl@0
   415
	 */
sl@0
   416
	IMPORT_C TInt Count() const;
sl@0
   417
sl@0
   418
	
sl@0
   419
	/**
sl@0
   420
	 *
sl@0
   421
	 *
sl@0
   422
	 * Note 
sl@0
   423
	 *
sl@0
   424
	 * @param aType
sl@0
   425
	 * @return	A pointer to a TWTLSStructuredTextField object; NULL if field not found. 
sl@0
   426
	 *			The returned object remains the property of the structured text object
sl@0
   427
	 *			(so don't delete it).
sl@0
   428
	 */
sl@0
   429
	IMPORT_C const TWTLSStructuredTextField* FieldByName(const TDesC& aType) const;
sl@0
   430
	
sl@0
   431
	/**
sl@0
   432
	 *
sl@0
   433
	 *
sl@0
   434
	 * @return
sl@0
   435
	 */
sl@0
   436
	IMPORT_C const TWTLSStructuredTextField& FieldByIndex(TInt aIndex) const;
sl@0
   437
private:
sl@0
   438
	CWTLSStructuredText();
sl@0
   439
	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
sl@0
   440
	void AddFieldValueL(const TDesC& aFieldName, TInt& aPos);
sl@0
   441
	void AddFieldL(TInt& aPos);
sl@0
   442
	TPtrC GetFieldL(TDesC& aString, TInt& aPos);
sl@0
   443
	TBool GetSubFieldL(TDesC& aString, TInt& aPos);
sl@0
   444
	CArrayFixFlat<TWTLSStructuredTextField>* iFields; 
sl@0
   445
	};
sl@0
   446
sl@0
   447
#endif
sl@0
   448
sl@0
   449