williamr@2: /* williamr@2: * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: * All rights reserved. williamr@2: * This component and the accompanying materials are made available williamr@2: * under the terms of the License "Eclipse Public License v1.0" williamr@2: * which accompanies this distribution, and is available williamr@2: * at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@2: * williamr@2: * Initial Contributors: williamr@2: * Nokia Corporation - initial contribution. williamr@2: * williamr@2: * Contributors: williamr@2: * williamr@2: * Description: williamr@2: * williamr@2: */ williamr@2: williamr@2: williamr@2: williamr@2: #if !defined (__WTLSNAMES_H__) williamr@2: #define __WTLSNAMES_H__ williamr@2: williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: williamr@2: /** williamr@2: @file williamr@2: This file contains the definition for class CWTLSName. williamr@2: williamr@4: @publishedAll williamr@4: @released williamr@2: williamr@2: enum { null(0), text(1), binary(2), key_hash_sha(254), x509_name(255)} williamr@2: IdentifierType; williamr@2: williamr@2: We only support text and x509_name as these are the only meaningful identifiers.. williamr@2: x509_name is X.500 Distinguished Name, and should use our existing X.500 DN implementation. williamr@2: williamr@2: struct { williamr@2: IdentifierType identifier_type; williamr@2: select (identifier_type) { williamr@2: case null: struct {}; williamr@2: case text: williamr@2: CharacterSet character_set; williamr@2: opaque name<1.. 2^8-1>; williamr@2: case binary: opaque identifier<1..2^8-1>; williamr@2: case key_hash_sha: opaque key_hash[20]; williamr@2: case x509_name: opaque distinguished_name<1..2^8-1>; williamr@2: } williamr@2: Identifier; williamr@2: williamr@2: uint16 CharacterSet; williamr@2: williamr@2: This maps on to one of the IANA defined character sets. There are rather a lot williamr@2: of these. We just support the text type, with either Latin1 or UTF8 encoding. williamr@2: */ williamr@2: williamr@2: /** williamr@2: * Enumerates the types of WTLS certificate name forms/identifiers. williamr@2: * williamr@2: * Only text strings and X.500 Distinguished Names are currently supported. williamr@2: * williamr@2: */ williamr@2: enum williamr@2: { williamr@2: /* Null */ williamr@2: EWTLSNull = 0x00, williamr@2: /* Text string (Latin-1 or Unicode). williamr@2: * williamr@2: * A text identifier consists of a 16-bit character set identifier; williamr@2: * this represents the IANA-assigned character set number. */ williamr@2: EWTLSText = 0x01, williamr@2: /* Binary identifier. williamr@2: * williamr@2: * Certificates of this type will be rejected.*/ williamr@2: EWTLSBinary = 0x02, williamr@2: /* Key Hash SHA-1. williamr@2: * williamr@2: * Certificates of this type will be rejected.*/ williamr@2: EWTLSKeyHashSha = 0xfe, williamr@2: /* X.500 Distinguished Name. */ williamr@2: EWTLSX500DN = 0xff williamr@2: }; williamr@2: williamr@2: typedef TUint8 TWTLSNameType; williamr@2: williamr@2: typedef TInt TWTLSCharSet; williamr@2: williamr@2: // MIBenum constants from the IANA list of character sets. williamr@2: // See http://www.iana.org/assignments/character-sets for more info. williamr@2: williamr@2: /** MIBenum constant for the Latin1 IANA character set */ williamr@2: const TInt KWTLSLatin1CharSet = 4; williamr@2: williamr@2: /** MIBenum constant for the UTF-8 IANA character set */ williamr@2: const TInt KWTLSUTF8CharSet = 106; williamr@2: williamr@2: class CWTLSName : public CBase williamr@2: /** williamr@2: * Stores the type of a WTLS name and the underlying encoding of the type. williamr@2: * williamr@2: */ williamr@2: { williamr@2: public: williamr@2: /** williamr@2: * Creates a new CWTLSName object from the specified buffer containing the binary coded representation. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @return The new CWTLSName object. williamr@2: */ williamr@2: IMPORT_C static CWTLSName* NewL(const TDesC8& aBinaryData); williamr@2: williamr@2: /** williamr@2: * Creates a new CWTLSName object from the specified buffer containing the binary coded representation, williamr@2: * and puts a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @return The new CWTLSName object. williamr@2: */ williamr@2: IMPORT_C static CWTLSName* NewLC(const TDesC8& aBinaryData); williamr@2: williamr@2: /** williamr@2: * Creates a new CWTLSName object from the specified buffer containing the binary coded representation, williamr@2: * starting at the specified offset. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor, williamr@2: * and is updated to the position at the end of the object. williamr@2: * @return The new CWTLSName object. williamr@2: */ williamr@2: IMPORT_C static CWTLSName* NewL(const TDesC8& aBinaryData, TInt& aPos); williamr@2: williamr@2: /** williamr@2: * Creates a new CWTLSName object from the specified buffer containing the binary coded representation, williamr@2: * starting at the specified offset, and puts a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor, williamr@2: * and is updated to the position at the end of the object. williamr@2: * @return The new CWTLSName object. williamr@2: */ williamr@2: IMPORT_C static CWTLSName* NewLC(const TDesC8& aBinaryData, TInt& aPos); williamr@2: williamr@2: /** williamr@2: * Creates a new CWTLSName object from an existing one. williamr@2: * williamr@2: * @param aName An existing CWTLSName object. williamr@2: * @return The new CWTLSName object. williamr@2: */ williamr@2: IMPORT_C static CWTLSName* NewL(const CWTLSName& aName); williamr@2: williamr@2: /** williamr@2: * Creates a new CWTLSName object from an existing one, williamr@2: * and puts a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * @param aName An existing CWTLSName object. williamr@2: * @return The new CWTLSName object. williamr@2: */ williamr@2: IMPORT_C static CWTLSName* NewLC(const CWTLSName& aName); williamr@2: williamr@2: /** williamr@2: * Destructor. williamr@2: * williamr@2: * Frees all resources owned by the object, prior to its destruction. williamr@2: */ williamr@2: IMPORT_C ~CWTLSName(); williamr@2: williamr@2: /** williamr@2: * Performs a simple byte compare between this WTLS name and a specified WTLS name. williamr@2: * williamr@2: * Needed for the constructing/validating of certificate chains. williamr@2: * williamr@2: * @param aName An existing CWTLSName object. williamr@2: * @return ETrue, if the WTLS names match; EFalse, otherwise. williamr@2: */ williamr@2: IMPORT_C TBool ExactMatchL(const CWTLSName& aName) const; williamr@2: williamr@2: /** williamr@2: * Gets the type of the WTLS name. williamr@2: * williamr@2: * @return Type of WTLS name form. williamr@2: */ williamr@2: IMPORT_C TWTLSNameType NameType() const; williamr@2: williamr@2: /** williamr@2: * Gets the encoding of the underlying type of WTLS name. williamr@2: * williamr@2: * @return Pointer descriptor representing the encoding of the WTLS name type. williamr@2: */ williamr@2: IMPORT_C TPtrC8 NameData() const; williamr@2: williamr@2: /** williamr@2: * Gets the decoded value for the common or organisation name. williamr@2: * williamr@2: * Provides the functionality required by the CCertificate::IssuerL() and SubjectL() functions. williamr@2: * williamr@2: * @return A heap descriptor containing the decoded value of the common or organisation name. williamr@2: */ williamr@2: IMPORT_C HBufC* DisplayNameL() const; williamr@2: private: williamr@2: CWTLSName(); williamr@2: void ConstructL(const TDesC8& aBinaryData, TInt& aPos); williamr@2: void ConstructL(const CWTLSName& aName); williamr@2: void AllocNameDataL(const TDesC8& aBinaryData, TInt& aPos); williamr@2: void AllocTextDataL(const TDesC8& aBinaryData, TInt& aPos); williamr@2: TWTLSNameType iNameType; williamr@2: HBufC8* iNameData; williamr@2: }; williamr@2: williamr@2: class CWTLSText : public CBase williamr@2: { williamr@2: public: williamr@2: /** williamr@2: * Creates a new CWTLSText object from the specified buffer containing the binary coded representation. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @return The new CWTLSText object. williamr@2: */ williamr@2: IMPORT_C static CWTLSText* NewL(const TDesC8& aBinaryData); williamr@2: williamr@2: /** williamr@2: * Creates a new CWTLSText object from the specified buffer containing the binary coded representation, williamr@2: * and puts a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @return The new CWTLSText object. williamr@2: */ williamr@2: IMPORT_C static CWTLSText* NewLC(const TDesC8& aBinaryData); williamr@2: williamr@2: /** williamr@2: * Creates a new CWTLSText object from the specified buffer containing the binary coded representation, williamr@2: * starting at the specified offset. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor, williamr@2: * and is updated to the position at the end of the object. williamr@2: * @return The new CWTLSText object. williamr@2: */ williamr@2: IMPORT_C static CWTLSText* NewL(const TDesC8& aBinaryData, TInt& aPos); williamr@2: williamr@2: /** williamr@2: * Creates a new CWTLSText object from the specified buffer containing the binary coded representation, williamr@2: * starting at the specified offset, and puts a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor, williamr@2: * and is updated to the position at the end of the object. williamr@2: * @return The new CWTLSText object. williamr@2: */ williamr@2: IMPORT_C static CWTLSText* NewLC(const TDesC8& aBinaryData, TInt& aPos); williamr@2: williamr@2: /** williamr@2: * Destructor. williamr@2: * williamr@2: * Frees all resources owned by the object, prior to its destruction. williamr@2: */ williamr@2: IMPORT_C ~CWTLSText(); williamr@2: williamr@2: /** williamr@2: * Performs a simple byte compare between this CWTLSText object and a specified CWTLSText object. williamr@2: * williamr@2: * There is a subtle difference between this byte-match and CWTLSName::ExactMatchL(). williamr@2: * As opposed to the latter, this function should successfully match two names that williamr@2: * are the same that were encoded using different character sets. williamr@2: * williamr@2: * @param aName An existing CWTLSText object. williamr@2: * @return ETrue, if the CWTLSText objects match; EFalse, otherwise. williamr@2: */ williamr@2: IMPORT_C TBool ExactMatchL(const CWTLSText& aName) const; williamr@2: williamr@2: /** williamr@2: * Gets the name of the CWTLSText object. williamr@2: * williamr@2: * @return A pointer to the name of the CWTLSText object. williamr@2: */ williamr@2: IMPORT_C TPtrC Name() const; williamr@2: williamr@2: /** williamr@2: * Gets the character set of the CWTLSText object. williamr@2: * williamr@2: * @return The character set williamr@2: */ williamr@2: IMPORT_C TWTLSCharSet CharacterSet() const; williamr@2: protected: williamr@2: /** williamr@2: * @internalAll williamr@2: */ williamr@2: CWTLSText(); williamr@2: /** williamr@2: * @internalAll williamr@2: */ williamr@2: void ConstructL(const TDesC8& aBinaryData, TInt& aPos); williamr@2: HBufC* iName; williamr@2: private: williamr@2: TInt iCharacterSet; williamr@2: }; williamr@2: williamr@2: //this class implements the 'structured' variant of the text type defined in the WTLS spec, section 10.5.2: williamr@2: //; ; [; [; [; [ …. ]]]] williamr@2: _LIT(KWTLSCountryName,"C"); williamr@2: _LIT(KWTLSOrganizationName,"O"); williamr@2: _LIT(KWTLSServiceName,"OU"); williamr@2: _LIT(KWTLSTitle,"T"); williamr@2: _LIT(KWTLSCommonName,"CN"); williamr@2: williamr@2: class TWTLSStructuredTextField williamr@2: { williamr@2: public: williamr@2: /** williamr@2: * @internalAll williamr@2: */ williamr@2: TWTLSStructuredTextField(const TDesC& aType, const TDesC& aValue); williamr@2: williamr@2: /** williamr@2: * williamr@2: * @return williamr@2: */ williamr@2: IMPORT_C TPtrC Type() const; williamr@2: williamr@2: /** williamr@2: * williamr@2: * @return williamr@2: */ williamr@2: IMPORT_C TPtrC Value() const; williamr@2: williamr@2: private: williamr@2: const TPtrC iType; williamr@2: const TPtrC iValue; williamr@2: }; williamr@2: williamr@2: class CWTLSStructuredText : public CWTLSText williamr@2: { williamr@2: public: williamr@2: /** williamr@2: * Creates a new CWTLSStructuredText object from the specified buffer containing the binary coded representation. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @return The new CWTLSStructuredText object. williamr@2: */ williamr@2: IMPORT_C static CWTLSStructuredText* NewL(const TDesC8& aBinaryData); williamr@2: williamr@2: /** williamr@2: * Creates a new CWTLSStructuredText object from the specified buffer containing the binary coded representation, williamr@2: * and puts a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @return The new CWTLSStructuredText object. williamr@2: */ williamr@2: IMPORT_C static CWTLSStructuredText* NewLC(const TDesC8& aBinaryData); williamr@2: williamr@2: /** williamr@2: * Creates a new CWTLSStructuredText object from the specified buffer containing the binary coded representation, williamr@2: * starting at the specified offset. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor, williamr@2: * and is updated to the position at the end of the object. williamr@2: * @return The new CWTLSStructuredText object. williamr@2: */ williamr@2: IMPORT_C static CWTLSStructuredText* NewL(const TDesC8& aBinaryData, TInt& aPos); williamr@2: williamr@2: /** williamr@2: * Creates a new CWTLSStructuredText object from the specified buffer containing the binary coded representation, williamr@2: * starting at the specified offset, and puts a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor, williamr@2: * and is updated to the position at the end of the object. williamr@2: * @return The new CWTLSStructuredText object. williamr@2: */ williamr@2: IMPORT_C static CWTLSStructuredText* NewLC(const TDesC8& aBinaryData, TInt& aPos); williamr@2: williamr@2: /** williamr@2: * Destructor. williamr@2: * williamr@2: * Frees all resources owned by the object, prior to its destruction. williamr@2: */ williamr@2: IMPORT_C ~CWTLSStructuredText(); williamr@2: williamr@2: /** williamr@2: * williamr@2: * williamr@2: * @return williamr@2: */ williamr@2: IMPORT_C HBufC* DisplayNameL() const; williamr@2: williamr@2: //accessors for defined fields williamr@2: williamr@2: /** williamr@2: * williamr@2: * williamr@2: * @return williamr@2: */ williamr@2: IMPORT_C TPtrC ServiceName() const; williamr@2: williamr@2: /** williamr@2: * williamr@2: * williamr@2: * @return williamr@2: */ williamr@2: IMPORT_C TPtrC Organization() const; williamr@2: williamr@2: /** williamr@2: * williamr@2: * williamr@2: * @return williamr@2: */ williamr@2: IMPORT_C TPtrC Country() const; williamr@2: williamr@2: /** williamr@2: * williamr@2: * williamr@2: * @return williamr@2: */ williamr@2: IMPORT_C TInt Count() const; williamr@2: williamr@2: williamr@2: /** williamr@2: * williamr@2: * williamr@2: * Note williamr@2: * williamr@2: * @param aType williamr@2: * @return A pointer to a TWTLSStructuredTextField object; NULL if field not found. williamr@2: * The returned object remains the property of the structured text object williamr@2: * (so don't delete it). williamr@2: */ williamr@2: IMPORT_C const TWTLSStructuredTextField* FieldByName(const TDesC& aType) const; williamr@2: williamr@2: /** williamr@2: * williamr@2: * williamr@2: * @return williamr@2: */ williamr@2: IMPORT_C const TWTLSStructuredTextField& FieldByIndex(TInt aIndex) const; williamr@2: private: williamr@2: CWTLSStructuredText(); williamr@2: void ConstructL(const TDesC8& aBinaryData, TInt& aPos); williamr@2: void AddFieldValueL(const TDesC& aFieldName, TInt& aPos); williamr@2: void AddFieldL(TInt& aPos); williamr@2: TPtrC GetFieldL(TDesC& aString, TInt& aPos); williamr@2: TBool GetSubFieldL(TDesC& aString, TInt& aPos); williamr@2: CArrayFixFlat* iFields; williamr@2: }; williamr@2: williamr@2: #endif williamr@4: williamr@4: