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