os/security/cryptoservices/certificateandkeymgmt/inc/X509gn.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) 1998-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 * X509 general name class
    16 *
    17 */
    18 
    19 
    20 /**
    21  @file 
    22  @publishedAll
    23  @released
    24 */
    25 
    26 #ifndef __X509GN_H__
    27 #define __X509GN_H__
    28 
    29 #include <e32std.h>
    30 #include <badesca.h>
    31 
    32 /** A general name type.
    33  * 
    34  * @publishedAll
    35  * @released
    36  */
    37 typedef TUint TGNType;
    38 
    39 /**
    40  * @publishedAll
    41  * @released
    42  */
    43 enum 
    44 	{
    45 	EX509RFC822Name = 1,
    46 	EX509DNSName = 2,
    47 	EX509DirectoryName = 4,
    48 	EX509URI = 6,
    49 	EX509IPAddress = 7
    50 	};
    51 //specific name forms we support...
    52 //we should probably put these in a file of their own,
    53 //but they can stay here for now
    54 
    55 //superclass
    56 
    57 class CX509DomainName : public CBase
    58 /** An X.509 domain name.
    59 * 
    60 * Base class for email address and DNS names. 
    61 * 
    62 * @publishedAll
    63 * @released
    64 * @since v6.0 */
    65 	{
    66 public:
    67 	/** Destructor.
    68 	* 
    69 	* Frees all resources owned by the object, prior to its destruction. */
    70 	IMPORT_C ~CX509DomainName();
    71 	
    72 	/** Tests whether every sub domain in the specified domain name is the same as 
    73 	* the corresponding sub domain in this object, starting at the end.
    74 	* 
    75 	* For example, 'john.doe@symbian.com' is within the subtree 'symbian.com' but 
    76 	* is not within the subtree 'john' or 'symbian'.
    77 	* 
    78 	* @param aName	The domain name.
    79 	* @return		ETrue, if every sub domain in the specified domain name is the same 
    80 					as the corresponding sub domain in this object; EFalse, otherwise. */
    81 	IMPORT_C TBool IsWithinSubtree(const CX509DomainName& aName) const;
    82 	
    83 	/** Gets the full domain name.
    84 	* 
    85 	* @return	A pointer descriptor representing the full domain name. */
    86 	IMPORT_C TPtrC Name() const;
    87 protected:
    88 	/** Adds a domain by its subdomains to an array of pointer descriptors.
    89 	* 
    90 	* @param aPos	The position within the domain name.
    91 	* @return		ETrue if the domain has been added; EFalse, otherwise. 
    92 	* @internalAll
    93 	*/
    94 	TBool AddDomainL(TInt& aPos);
    95 	
    96 	/** Adds a subdomain to an array of pointer descriptors.
    97 	* 
    98 	* @param aPos	The position within the domain name.
    99 	* @return		ETrue if the subdomain has been added; EFalse, otherwise. 
   100 	* @internalAll
   101 	*/
   102 	TBool AddSubdomainL(TInt& aPos);
   103 	
   104 	/** Adds a subdomain separator after each subdomain entry in an array of pointer 
   105 	* descriptors that represent the subdomains of the domain name.
   106 	* 
   107 	* @param aPos	The position within the domain name.
   108 	* @return		ETrue if the subdomain separator has been added; EFalse, otherwise. 
   109 	* @internalAll
   110 	*/
   111 	TBool AddSubdomainSeparatorL(TInt& aPos);
   112 	
   113 	/** Validates a string.
   114 	* 
   115 	* @param aStr	The string to be verified.
   116 	* @return		ETrue if the string is valid; EFalse, otherwise.*/
   117 	virtual TBool IsValidString(const TDesC& aStr) const;
   118 	
   119 	/** Validates a character.
   120 	* 
   121 	* @param aChar	The character to be validated.
   122 	* @return		ETrue if the character is valid; EFalse, otherwise. */
   123 	virtual TBool IsValidChar(const TChar& aChar) const;
   124 	
   125 	/** Tests whether a character is a letter or a numeral.
   126 	* 
   127 	* @param aChar	The character to be tested.
   128 	* @return		ETrue if the character is a letter or a numeral; EFalse, otherwise. 
   129 	* @internalAll
   130 	*/
   131 	TBool IsAlphaOrNum(const TChar& aChar) const;
   132 	
   133 	/** Tests whether the character is a letter.
   134 	* 
   135 	* @param aChar	The character to be tested.
   136 	* @return		ETrue if the character is a letter; EFalse, otherwise. 
   137 	* @internalAll
   138 	*/
   139 	TBool IsAlpha(const TChar& aChar) const;
   140 	
   141 	/** Default constructor. 
   142 	 * @internalAll
   143 	 */
   144 	CX509DomainName();
   145 protected:
   146 	/** An array of pointer descriptors representing the subdomains of the DSN name. */
   147 	RArray<TPtrC> iRep;
   148 	/** A heap descriptor representing the full domain name. */
   149 	HBufC* iName;
   150 	};
   151 
   152 //rfc822 email address has the form localpart@domain
   153 
   154 class CX509RFC822NameSubtree : public CX509DomainName
   155 /** A full or partial RFC 822 email address.
   156 * 
   157 * The address may not contain the local host name as this is optional.
   158 * 
   159 * The object is initialised with 8-bit encoded binary data, which is parsed 
   160 * into a series of sub domains and an optional local host. 
   161 *
   162 * @publishedAll
   163 * @released */
   164 	{
   165 public:
   166 	/** Creates an RFC 822 email address object from the specified buffer containing 
   167 	* the binary coded representation.
   168 	* 
   169 	* The data is parsed into a series of sub domains and an optional local host.
   170 	* 
   171 	* @param aBinaryData	The encoded binary representation.
   172 	* @return				The new RFC 822 email address object. */
   173 	IMPORT_C static CX509RFC822NameSubtree* NewL(const TDesC8& aBinaryData);
   174 	
   175 	/** Creates an RFC 822 email address object from the specified buffer containing 
   176 	* the binary coded representation, and puts a pointer to it onto the cleanup stack.
   177 	* The data is parsed into a series of sub domains and an optional local host.
   178 	* 
   179 	* @param aBinaryData	The encoded binary representation.
   180 	* @return				The new RFC 822 email address object. */
   181 	IMPORT_C static CX509RFC822NameSubtree* NewLC(const TDesC8& aBinaryData);
   182 	
   183 	/** Gets a reference to the array of pointer descriptors representing the subdomains 
   184 	* of the RFC 822 email address.
   185 	* 
   186 	* @return	The array of pointer descriptors. */
   187 	IMPORT_C const RArray<TPtrC>& Rep() const;
   188 
   189 protected:
   190 	/** Second-phase constructor.
   191 	* 
   192 	* @param aBinaryData	The encoded binary representation. */
   193 	virtual void ConstructL(const TDesC8& aBinaryData);
   194 	
   195 	/** Adds a local host.
   196 	* 
   197 	* @param aPos	The position from which to start decoding.
   198 	* @return		ETrue, if the host has been found and added; EFalse, otherwise. 
   199 	* @internalAll
   200 	*/
   201 	TBool AddLocalHostL(TInt& aPos);
   202 	
   203 	/** Tests whether the character is valid.
   204 	* 
   205 	* @param aChar	The character to be tested.
   206 	* @return		ETrue, if the character is valid; EFalse, otherwise. 
   207 	* @internalAll
   208 	*/
   209 	TBool IsValidChar(const TChar& aChar) const;
   210 	};
   211 
   212 class CX509RFC822Name : public CX509RFC822NameSubtree
   213 /** A full RFC 822 email address.
   214 * 
   215 * Exactly as subtree, but requires local host and full domain name. 
   216 *
   217 * @publishedAll
   218 * @released */
   219 	{
   220 public:
   221 	/** Creates a full RFC 822 email address object from the specified buffer containing 
   222 	* the binary coded representation.
   223 	* 
   224 	* The data is parsed into a series of sub domains.
   225 	* 
   226 	* The data must represent a full RFC 822 email address, otherwise this function leaves.
   227 	* 
   228 	* @param aBinaryData	The encoded binary representation.
   229 	* @return				The new full RFC 822 email address object. */
   230 	IMPORT_C static CX509RFC822Name* NewL(const TDesC8& aBinaryData);
   231 	
   232 	/** Creates a full RFC 822 email address object from the specified buffer containing 
   233 	* the binary coded representation, and puts a pointer to it onto the cleanup stack.
   234 	* 
   235 	* The data is parsed into a series of sub domains.
   236 	* 
   237 	* The data must represent a full RFC 822 email address, otherwise this function leaves.
   238 	* 
   239 	* @param aBinaryData	The encoded binary representation.
   240 	* @return				The new full RFC 822 email address object. */
   241 	IMPORT_C static CX509RFC822Name* NewLC(const TDesC8& aBinaryData);
   242 private:
   243 	virtual void ConstructL(const TDesC8& aBinaryData);
   244 	};
   245 
   246 class CX509DNSNameSubtree : public CX509DomainName
   247 /** A Domain Name System (DNS) name subtree.
   248 * 
   249 * Initialised with 8-bit encoded binary data, which is parsed into a series 
   250 * of sub domains.
   251 * 
   252 * Because it is a subtree it may start with a period. For example, '.symbian.com', 
   253 * indicating that 'symbian.com' does not lie within the subtree. 
   254 *
   255 * @publishedAll
   256 * @released */
   257 	{
   258 public:
   259 	/** Creates a DNS name object from the specified buffer containing the binary coded 
   260 	* representation.
   261 	* 
   262 	* The data is parsed into a series of sub domains.
   263 	* 
   264 	* @param aBinaryData	The encoded binary representation.
   265 	* @return				The new DNS name object. */
   266 	IMPORT_C static CX509DNSNameSubtree* NewL(const TDesC8& aBinaryData);
   267 	
   268 	/** Creates a DNS name object from the specified buffer containing the binary coded 
   269 	* representation, and puts a pointer to it onto the cleanup stack.
   270 	* 
   271 	* The data is parsed into a series of sub domains.
   272 	* 
   273 	* @param aBinaryData	The encoded binary representation.
   274 	* @return				The new DNS name object. */
   275 	IMPORT_C static CX509DNSNameSubtree* NewLC(const TDesC8& aBinaryData);
   276 
   277 //	IMPORT_C static CX509DNSNameSubtree* NewL(const CX509DNSNameSubtree& aName);
   278 //	IMPORT_C static CX509DNSNameSubtree* NewLC(const CX509DNSNameSubtree& aName);
   279 	
   280 	/** Gets a reference to the array of pointer descriptors representing the subdomains 
   281 	* of the DSN name.
   282 	* 
   283 	* @return	The array of pointer descriptors. */
   284 	IMPORT_C const RArray<TPtrC>& Rep() const;
   285 	
   286 private:
   287 	void ConstructL(const CX509DNSNameSubtree& aName);
   288 	void ConstructL(const TDesC8& aBinaryData);
   289 	TBool IsValidString(const TDesC& aStr) const;
   290 	};
   291 
   292 class CX509DNSName : public CX509DNSNameSubtree
   293 /** A Domain Name System (DNS) name.
   294 * 
   295 * The name must begin with a valid sub domain and not a period. 
   296 *
   297 * @publishedAll
   298 * @released */
   299 	{
   300 public:
   301 	/** Creates a DNS name object from the specified buffer containing the binary coded 
   302 	* representation.
   303 	* 
   304 	* @param aBinaryData	The encoded binary representation.
   305 	* @return				The new DNS name object. */
   306 	IMPORT_C static CX509DNSName* NewL(const TDesC8& aBinaryData);
   307 	
   308 	/** Creates a DNS name object from the specified buffer containing the binary coded 
   309 	* representation, and puts a pointer to it onto the cleanup stack.
   310 	* 
   311 	* @param aBinaryData	The encoded binary representation.
   312 	* @return				The new DSN name object. */
   313 	IMPORT_C static CX509DNSName* NewLC(const TDesC8& aBinaryData);
   314 	
   315 	/** Creates a new DSN name object from an existing object.
   316 	* 
   317 	* This is equivalent to a copy constructor.
   318 	* 
   319 	* @param aName	The DSN name object to be copied.
   320 	* @return		The DSN name object. */
   321 	IMPORT_C static CX509DNSName* NewL(const CX509DNSName& aName);
   322 	
   323 	/** Creates a new DSN name object from an existing object, and puts a pointer to 
   324 	* it onto the clean up stack.
   325 	* 
   326 	* This is equivalent to a copy constructor.
   327 	* 
   328 	* @param aName	The DNS name object to be copied.
   329 	* @return		The new DSN name object. */
   330 	IMPORT_C static CX509DNSName* NewLC(const CX509DNSName& aName);
   331 	
   332 	/** Constructs a new DSN name object from a name string.
   333 	* 
   334 	* @param aNameString	The name string.
   335 	* @return				The new DSN name object. */
   336 	IMPORT_C static CX509DNSName* NewL(const TDesC& aNameString);
   337 	
   338 	/** Creates a DSN name object from a name string, and puts a pointer to it onto 
   339 	* the cleanup stack.
   340 	* 
   341 	* @param aNameString	The name string.
   342 	* @return				The new DSN name object. */
   343 	IMPORT_C static CX509DNSName* NewLC(const TDesC& aNameString);
   344 private:
   345 	void ConstructL(const TDesC8& aBinaryData);
   346 	void ConstructL(const TDesC& aNameString);
   347 	void ConstructL(const CX509DNSName& aName);
   348 	void ParseNameL();
   349 	};
   350 
   351 class CX509IPBasedURI : public CBase
   352 /** A URI.
   353 * 
   354 * The class extracts a DNS name, i.e. the host part of the URI.
   355 * 
   356 * Note that it must be of 'ip-based' form (see RFC 1738 section 3.1) and contain 
   357 * a domain name (not an IP address). 
   358 *
   359 * @publishedAll
   360 * @released */
   361 	{
   362 public:
   363 	/** Creates an IP based URI name object from the specified buffer containing the 
   364 	* binary coded representation.
   365 	* 
   366 	* @param aBinaryData	The encoded binary representation.
   367 	* @return				The new URI name object. */
   368 	IMPORT_C static CX509IPBasedURI* NewL(const TDesC8& aBinaryData);
   369 	
   370 	/** Creates a URI name object from the specified buffer containing the binary coded 
   371 	* representation, and puts a pointer to it onto the clean up stack.
   372 	* 
   373 	* @param aBinaryData	The encoded binary representation.
   374 	* @return				The new URI name object. */
   375 	IMPORT_C static CX509IPBasedURI* NewLC(const TDesC8& aBinaryData);
   376 	
   377 	/** Destructor.
   378 	* 
   379 	* Frees all resources owned by the object, prior to its destruction. */
   380 	IMPORT_C ~CX509IPBasedURI();
   381 	
   382 	/** Gets the host part.
   383 	* 
   384 	* @return	The host part. */
   385 	IMPORT_C const CX509DNSName& Host() const;
   386 	
   387 	/** Gets the whole name.
   388 	* 
   389 	* @return	A pointer descriptor representing the whole name. */
   390 	IMPORT_C TPtrC Name() const;
   391 	
   392 	/** Default constructor.
   393 	 * @internalAll
   394 	 */
   395 	CX509IPBasedURI();
   396 private:
   397 	void ConstructL(const TDesC8& aBinaryData);
   398 	TPtrC ExtractHostNameL() const;
   399 	CX509DNSName* iHost;
   400 	HBufC* iName;
   401 	};
   402 
   403 class CX509IPSubnetMask : public CBase
   404 /** An IP subnet mask.
   405 * 
   406 * Input data is parsed into an 8-bit base address and an 8-bit mask. 
   407 *
   408 * @publishedAll
   409 * @released */
   410 	{
   411 	friend class CX509IPAddress;
   412 public:
   413 	/** Creates an IP subnet mask object from the specified buffer containing the binary 
   414 	* coded representation.
   415 	* 
   416 	* The data is parsed into an 8-bit base address and an 8-bit mask.
   417 	* 
   418 	* @param aBinaryData	The encoded binary representation.
   419 	* @return				The new IP subnet mask object. */
   420 	IMPORT_C static CX509IPSubnetMask* NewL(const TDesC8& aBinaryData);
   421 	
   422 	/** Creates an IP subnet mask object from the specified buffer containing the binary 
   423 	* coded representation, and puts a pointer to it onto the cleanup stack.
   424 	* 
   425 	* The data is parsed into an 8-bit base address and an 8-bit mask.
   426 	* 
   427 	* @param aBinaryData	The encoded binary representation.
   428 	* @return				The new IP subnet mask object. */
   429 	IMPORT_C static CX509IPSubnetMask* NewLC(const TDesC8& aBinaryData);
   430 	
   431 	/** Destructor.
   432 	* 
   433 	* Frees all resources owned by the object, prior to its destruction. */
   434 	IMPORT_C ~CX509IPSubnetMask();
   435 	
   436 	/** Gets the base IP address.
   437 	* 
   438 	* @return	A pointer descriptor representing the base IP address. */
   439 	IMPORT_C TPtrC8 BaseAddress() const;
   440 	
   441 	/** Gets the subnet mask.
   442 	* 
   443 	* @return	A pointer descriptor representing the subnet mask. */
   444 	IMPORT_C TPtrC8 Mask() const;
   445 	
   446 	/** Constructor. 
   447 	 * @internalAll
   448 	 */
   449 	CX509IPSubnetMask();
   450 private:
   451 	void ConstructL(const TDesC8& aBinaryData);
   452 	HBufC8* iName;
   453 	};
   454 
   455 class CX509IPAddress : public CBase
   456 /** A single IP address. 
   457 *
   458 * @publishedAll
   459 * @released */
   460 	{
   461 public:
   462 	/** Creates a single IP address object from the specified buffer containing the 
   463 	* binary coded representation.
   464 	* 
   465 	* @param aBinaryData	The encoded binary representation.
   466 	* @return				The new single IP addres. */
   467 	IMPORT_C static CX509IPAddress* NewL(const TDesC8& aBinaryData);
   468 	
   469 	/** Creates a single IP address object from the specified buffer containing the 
   470 	* binary coded representation, and puts a pointer to it onto the cleanup stack.
   471 	* 
   472 	* @param aBinaryData	The encoded binary representation.
   473 	* @return				The new single IP addres object. */
   474 	IMPORT_C static CX509IPAddress* NewLC(const TDesC8& aBinaryData);
   475 	
   476 	/** Tests whether the IP address lies within the specified subnet address.
   477 	* 
   478 	* @param aName	The subnet mask name.
   479 	* @return		ETrue, if the IP address lies within the specified subnet address; 
   480 	* EFalse, otherwise. */
   481 	IMPORT_C TBool IsWithinSubtree(const CX509IPSubnetMask& aName) const;
   482 	
   483 	/** Destructor.
   484 	* 
   485 	* Frees all resources owned by the object, prior to its destruction. */
   486 	IMPORT_C ~CX509IPAddress();
   487 	
   488 	/** Gets the IP address.
   489 	* 
   490 	* @return	A pointer descriptor representing the single IP address. */
   491 	IMPORT_C TPtrC8 Address() const;
   492 	
   493 	/** Constructor. 
   494 	 * @internalAll
   495 	 */
   496 	CX509IPAddress();
   497 private:
   498 	void ConstructL(const TDesC8& aBinaryData);
   499 	HBufC8* iName;//4 octets for v4, 16 for v6
   500 	};
   501 
   502 //general name...
   503 
   504 class CX509GeneralName : public CBase
   505 /** Defines a general name.
   506 * 
   507 * The class contains a tag and a name whose form depends on the value of that tag.
   508 * 
   509 * When a General Name is included as part of a Name Constraints Extension, the 
   510 * values need not be complete names but may be simply subtrees.
   511 * 
   512 * For example, 'symbian.com' instead of john.doe@symbian.com'. Both names are 
   513 * valid subtrees but only the second is a valid RFC822 name. 
   514 *
   515 * @publishedAll
   516 * @released */
   517 	{
   518 public:
   519 	/** Creates a new general name object from the specified buffer containing the 
   520 	* binary coded representation.	
   521 	* 
   522 	* @param aBinaryData	The encoded binary representation.
   523 	* @return				The new general name object. */
   524 	IMPORT_C static CX509GeneralName* NewL(const TDesC8& aBinaryData);
   525 	
   526 	/** Creates a new general name object from the specified buffer containing the 
   527 	* binary coded representation, and puts a pointer to it onto the cleanup stack.
   528 	* 
   529 	* Initialises the object from its encoded binary form into an internal representation.
   530 	* 
   531 	* @param aBinaryData	The encoded binary representation.
   532 	* @return				The new general name object. */
   533 	IMPORT_C static CX509GeneralName* NewLC(const TDesC8& aBinaryData);
   534 	
   535 	/** Creates a new general name object from the specified buffer containing the 
   536 	* binary coded representation,starting at the specified offset.
   537 	* 
   538 	* @param aBinaryData	The encoded binary representation.
   539 	* @param aPos			The offset position from which to start decoding.
   540 	* @return				The new general name object. */
   541 	IMPORT_C static CX509GeneralName* NewL(const TDesC8& aBinaryData, TInt& aPos);
   542 	
   543 	/** Creates a new general name object from the specified buffer containing the 
   544 	* binary coded representation, starting at the specified offset, and puts a 
   545 	* pointer to it onto the cleanup stack.
   546 	* 
   547 	* Initialises the object from its encoded binary form into an internal representation.
   548 	* 
   549 	* @param aBinaryData	The encoded binary representation.
   550 	* @param aPos			The offset position from which to start decoding.
   551 	* @return				The new general name object. */
   552 	IMPORT_C static CX509GeneralName* NewLC(const TDesC8& aBinaryData, TInt& aPos);
   553 
   554 	/** Creates a new general name object from an existing object.
   555 	* 
   556 	* This is equivalent to a copy constructor.
   557 	* 
   558 	* @param aName			The general name object to be copied.
   559 	* @return				The new general name object. */
   560 	IMPORT_C static CX509GeneralName* NewL(const CX509GeneralName& aName);
   561 	
   562 	/** Creates a new general name object from an existing object, and puts a pointer 
   563 	* to it onto the cleanup stack.
   564 	* 
   565 	* This is equivalent to a copy constructor.
   566 	* 
   567 	* @param aName			The general name object to be copied.
   568 	* @return				The new general name object. */
   569 	IMPORT_C static CX509GeneralName* NewLC(const CX509GeneralName& aName);
   570 
   571 	/** Gets the type tag.
   572 	* 
   573 	* @return	The type tag. */
   574 	IMPORT_C TGNType Tag() const;
   575 	
   576 	/** Gets the name.
   577 	* 
   578 	* @return	A pointer descriptor representing the name. */
   579 	IMPORT_C TPtrC8 Data() const;
   580 	
   581 	/** Destructor.
   582 	* 
   583 	* Frees all resources owned by the object, prior to its destruction. */
   584 	IMPORT_C ~CX509GeneralName(); 
   585 	
   586 	/** Dummy Function which always returns EFalse.
   587 	* @param aName	The general name object to be copied.
   588 	* @return		EFalse.
   589 	*/
   590 	IMPORT_C TBool ExactMatch(const CX509GeneralName& aName) const;
   591 private:
   592 	CX509GeneralName();
   593 	CX509GeneralName(TGNType aType);
   594 	void ConstructL();
   595 	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
   596 	void ConstructL(const TDesC8& aData);
   597 	TGNType iTag;
   598 	HBufC8* iData;
   599 	};
   600 
   601 #endif