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