1.1 --- a/epoc32/include/wtlsnames.h Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/wtlsnames.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,470 @@
1.4 -wtlsnames.h
1.5 +/*
1.6 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.7 +* All rights reserved.
1.8 +* This component and the accompanying materials are made available
1.9 +* under the terms of the License "Eclipse Public License v1.0"
1.10 +* which accompanies this distribution, and is available
1.11 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.12 +*
1.13 +* Initial Contributors:
1.14 +* Nokia Corporation - initial contribution.
1.15 +*
1.16 +* Contributors:
1.17 +*
1.18 +* Description:
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +
1.24 +#if !defined (__WTLSNAMES_H__)
1.25 +#define __WTLSNAMES_H__
1.26 +
1.27 +#include <e32base.h>
1.28 +#include <e32std.h>
1.29 +#include <x500dn.h>
1.30 +
1.31 +/**
1.32 +@file
1.33 +This file contains the definition for class CWTLSName.
1.34 +
1.35 +@internalAll
1.36 +
1.37 +enum { null(0), text(1), binary(2), key_hash_sha(254), x509_name(255)}
1.38 + IdentifierType;
1.39 +
1.40 +We only support text and x509_name as these are the only meaningful identifiers..
1.41 +x509_name is X.500 Distinguished Name, and should use our existing X.500 DN implementation.
1.42 +
1.43 +struct {
1.44 + IdentifierType identifier_type;
1.45 + select (identifier_type) {
1.46 + case null: struct {};
1.47 + case text:
1.48 + CharacterSet character_set;
1.49 + opaque name<1.. 2^8-1>;
1.50 + case binary: opaque identifier<1..2^8-1>;
1.51 + case key_hash_sha: opaque key_hash[20];
1.52 + case x509_name: opaque distinguished_name<1..2^8-1>;
1.53 + }
1.54 + Identifier;
1.55 +
1.56 +uint16 CharacterSet;
1.57 +
1.58 +This maps on to one of the IANA defined character sets. There are rather a lot
1.59 +of these. We just support the text type, with either Latin1 or UTF8 encoding.
1.60 +*/
1.61 +
1.62 +/**
1.63 + * Enumerates the types of WTLS certificate name forms/identifiers.
1.64 + *
1.65 + * Only text strings and X.500 Distinguished Names are currently supported.
1.66 + *
1.67 + * @publishedAll
1.68 + * @released
1.69 + */
1.70 +enum
1.71 + {
1.72 + /* Null */
1.73 + EWTLSNull = 0x00,
1.74 + /* Text string (Latin-1 or Unicode).
1.75 + *
1.76 + * A text identifier consists of a 16-bit character set identifier;
1.77 + * this represents the IANA-assigned character set number. */
1.78 + EWTLSText = 0x01,
1.79 + /* Binary identifier.
1.80 + *
1.81 + * Certificates of this type will be rejected.*/
1.82 + EWTLSBinary = 0x02,
1.83 + /* Key Hash SHA-1.
1.84 + *
1.85 + * Certificates of this type will be rejected.*/
1.86 + EWTLSKeyHashSha = 0xfe,
1.87 + /* X.500 Distinguished Name. */
1.88 + EWTLSX500DN = 0xff
1.89 + };
1.90 +
1.91 +/**
1.92 + * @publishedAll
1.93 + * @released
1.94 + */
1.95 +typedef TUint8 TWTLSNameType;
1.96 +
1.97 +/**
1.98 + * @publishedAll
1.99 + * @released
1.100 + */
1.101 +typedef TInt TWTLSCharSet;
1.102 +
1.103 +// MIBenum constants from the IANA list of character sets.
1.104 +// See http://www.iana.org/assignments/character-sets for more info.
1.105 +
1.106 +/** MIBenum constant for the Latin1 IANA character set */
1.107 +const TInt KWTLSLatin1CharSet = 4;
1.108 +
1.109 +/** MIBenum constant for the UTF-8 IANA character set */
1.110 +const TInt KWTLSUTF8CharSet = 106;
1.111 +
1.112 +class CWTLSName : public CBase
1.113 +/**
1.114 + * Stores the type of a WTLS name and the underlying encoding of the type.
1.115 + *
1.116 + * @publishedAll
1.117 + * @released
1.118 + */
1.119 + {
1.120 +public:
1.121 + /**
1.122 + * Creates a new CWTLSName object from the specified buffer containing the binary coded representation.
1.123 + *
1.124 + * @param aBinaryData The encoded binary representation.
1.125 + * @return The new CWTLSName object.
1.126 + */
1.127 + IMPORT_C static CWTLSName* NewL(const TDesC8& aBinaryData);
1.128 +
1.129 + /**
1.130 + * Creates a new CWTLSName object from the specified buffer containing the binary coded representation,
1.131 + * and puts a pointer to it onto the cleanup stack.
1.132 + *
1.133 + * @param aBinaryData The encoded binary representation.
1.134 + * @return The new CWTLSName object.
1.135 + */
1.136 + IMPORT_C static CWTLSName* NewLC(const TDesC8& aBinaryData);
1.137 +
1.138 + /**
1.139 + * Creates a new CWTLSName object from the specified buffer containing the binary coded representation,
1.140 + * starting at the specified offset.
1.141 + *
1.142 + * @param aBinaryData The encoded binary representation.
1.143 + * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor,
1.144 + * and is updated to the position at the end of the object.
1.145 + * @return The new CWTLSName object.
1.146 + */
1.147 + IMPORT_C static CWTLSName* NewL(const TDesC8& aBinaryData, TInt& aPos);
1.148 +
1.149 + /**
1.150 + * Creates a new CWTLSName object from the specified buffer containing the binary coded representation,
1.151 + * starting at the specified offset, and puts a pointer to it onto the cleanup stack.
1.152 + *
1.153 + * @param aBinaryData The encoded binary representation.
1.154 + * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor,
1.155 + * and is updated to the position at the end of the object.
1.156 + * @return The new CWTLSName object.
1.157 + */
1.158 + IMPORT_C static CWTLSName* NewLC(const TDesC8& aBinaryData, TInt& aPos);
1.159 +
1.160 + /**
1.161 + * Creates a new CWTLSName object from an existing one.
1.162 + *
1.163 + * @param aName An existing CWTLSName object.
1.164 + * @return The new CWTLSName object.
1.165 + */
1.166 + IMPORT_C static CWTLSName* NewL(const CWTLSName& aName);
1.167 +
1.168 + /**
1.169 + * Creates a new CWTLSName object from an existing one,
1.170 + * and puts a pointer to it onto the cleanup stack.
1.171 + *
1.172 + * @param aName An existing CWTLSName object.
1.173 + * @return The new CWTLSName object.
1.174 + */
1.175 + IMPORT_C static CWTLSName* NewLC(const CWTLSName& aName);
1.176 +
1.177 + /**
1.178 + * Destructor.
1.179 + *
1.180 + * Frees all resources owned by the object, prior to its destruction.
1.181 + */
1.182 + IMPORT_C ~CWTLSName();
1.183 +
1.184 + /**
1.185 + * Performs a simple byte compare between this WTLS name and a specified WTLS name.
1.186 + *
1.187 + * Needed for the constructing/validating of certificate chains.
1.188 + *
1.189 + * @param aName An existing CWTLSName object.
1.190 + * @return ETrue, if the WTLS names match; EFalse, otherwise.
1.191 + */
1.192 + IMPORT_C TBool ExactMatchL(const CWTLSName& aName) const;
1.193 +
1.194 + /**
1.195 + * Gets the type of the WTLS name.
1.196 + *
1.197 + * @return Type of WTLS name form.
1.198 + */
1.199 + IMPORT_C TWTLSNameType NameType() const;
1.200 +
1.201 + /**
1.202 + * Gets the encoding of the underlying type of WTLS name.
1.203 + *
1.204 + * @return Pointer descriptor representing the encoding of the WTLS name type.
1.205 + */
1.206 + IMPORT_C TPtrC8 NameData() const;
1.207 +
1.208 + /**
1.209 + * Gets the decoded value for the common or organisation name.
1.210 + *
1.211 + * Provides the functionality required by the CCertificate::IssuerL() and SubjectL() functions.
1.212 + *
1.213 + * @return A heap descriptor containing the decoded value of the common or organisation name.
1.214 + */
1.215 + IMPORT_C HBufC* DisplayNameL() const;
1.216 +private:
1.217 + CWTLSName();
1.218 + void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
1.219 + void ConstructL(const CWTLSName& aName);
1.220 + void AllocNameDataL(const TDesC8& aBinaryData, TInt& aPos);
1.221 + void AllocTextDataL(const TDesC8& aBinaryData, TInt& aPos);
1.222 + TWTLSNameType iNameType;
1.223 + HBufC8* iNameData;
1.224 + };
1.225 +
1.226 +/**
1.227 + * @publishedAll
1.228 + * @released
1.229 + */
1.230 +class CWTLSText : public CBase
1.231 + {
1.232 +public:
1.233 + /**
1.234 + * Creates a new CWTLSText object from the specified buffer containing the binary coded representation.
1.235 + *
1.236 + * @param aBinaryData The encoded binary representation.
1.237 + * @return The new CWTLSText object.
1.238 + */
1.239 + IMPORT_C static CWTLSText* NewL(const TDesC8& aBinaryData);
1.240 +
1.241 + /**
1.242 + * Creates a new CWTLSText object from the specified buffer containing the binary coded representation,
1.243 + * and puts a pointer to it onto the cleanup stack.
1.244 + *
1.245 + * @param aBinaryData The encoded binary representation.
1.246 + * @return The new CWTLSText object.
1.247 + */
1.248 + IMPORT_C static CWTLSText* NewLC(const TDesC8& aBinaryData);
1.249 +
1.250 + /**
1.251 + * Creates a new CWTLSText object from the specified buffer containing the binary coded representation,
1.252 + * starting at the specified offset.
1.253 + *
1.254 + * @param aBinaryData The encoded binary representation.
1.255 + * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor,
1.256 + * and is updated to the position at the end of the object.
1.257 + * @return The new CWTLSText object.
1.258 + */
1.259 + IMPORT_C static CWTLSText* NewL(const TDesC8& aBinaryData, TInt& aPos);
1.260 +
1.261 + /**
1.262 + * Creates a new CWTLSText object from the specified buffer containing the binary coded representation,
1.263 + * starting at the specified offset, and puts a pointer to it onto the cleanup stack.
1.264 + *
1.265 + * @param aBinaryData The encoded binary representation.
1.266 + * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor,
1.267 + * and is updated to the position at the end of the object.
1.268 + * @return The new CWTLSText object.
1.269 + */
1.270 + IMPORT_C static CWTLSText* NewLC(const TDesC8& aBinaryData, TInt& aPos);
1.271 +
1.272 + /**
1.273 + * Destructor.
1.274 + *
1.275 + * Frees all resources owned by the object, prior to its destruction.
1.276 + */
1.277 + IMPORT_C ~CWTLSText();
1.278 +
1.279 + /**
1.280 + * Performs a simple byte compare between this CWTLSText object and a specified CWTLSText object.
1.281 + *
1.282 + * There is a subtle difference between this byte-match and CWTLSName::ExactMatchL().
1.283 + * As opposed to the latter, this function should successfully match two names that
1.284 + * are the same that were encoded using different character sets.
1.285 + *
1.286 + * @param aName An existing CWTLSText object.
1.287 + * @return ETrue, if the CWTLSText objects match; EFalse, otherwise.
1.288 + */
1.289 + IMPORT_C TBool ExactMatchL(const CWTLSText& aName) const;
1.290 +
1.291 + /**
1.292 + * Gets the name of the CWTLSText object.
1.293 + *
1.294 + * @return A pointer to the name of the CWTLSText object.
1.295 + */
1.296 + IMPORT_C TPtrC Name() const;
1.297 +
1.298 + /**
1.299 + * Gets the character set of the CWTLSText object.
1.300 + *
1.301 + * @return The character set
1.302 + */
1.303 + IMPORT_C TWTLSCharSet CharacterSet() const;
1.304 +protected:
1.305 + /**
1.306 + * @internalAll
1.307 + */
1.308 + CWTLSText();
1.309 + /**
1.310 + * @internalAll
1.311 + */
1.312 + void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
1.313 + HBufC* iName;
1.314 +private:
1.315 + TInt iCharacterSet;
1.316 + };
1.317 +
1.318 +//this class implements the 'structured' variant of the text type defined in the WTLS spec, section 10.5.2:
1.319 +//<servicename>; <organization>; <country>[; <commonname>[; <extension>[; <extension>[ …. ]]]]
1.320 +_LIT(KWTLSCountryName,"C");
1.321 +_LIT(KWTLSOrganizationName,"O");
1.322 +_LIT(KWTLSServiceName,"OU");
1.323 +_LIT(KWTLSTitle,"T");
1.324 +_LIT(KWTLSCommonName,"CN");
1.325 +
1.326 +/**
1.327 + * @publishedAll
1.328 + * @released
1.329 + */
1.330 +class TWTLSStructuredTextField
1.331 + {
1.332 +public:
1.333 + /**
1.334 + * @internalAll
1.335 + */
1.336 + TWTLSStructuredTextField(const TDesC& aType, const TDesC& aValue);
1.337 +
1.338 + /**
1.339 + *
1.340 + * @return
1.341 + */
1.342 + IMPORT_C TPtrC Type() const;
1.343 +
1.344 + /**
1.345 + *
1.346 + * @return
1.347 + */
1.348 + IMPORT_C TPtrC Value() const;
1.349 +
1.350 +private:
1.351 + const TPtrC iType;
1.352 + const TPtrC iValue;
1.353 + };
1.354 +
1.355 +/**
1.356 + * @publishedAll
1.357 + * @released
1.358 + */
1.359 +class CWTLSStructuredText : public CWTLSText
1.360 + {
1.361 +public:
1.362 + /**
1.363 + * Creates a new CWTLSStructuredText object from the specified buffer containing the binary coded representation.
1.364 + *
1.365 + * @param aBinaryData The encoded binary representation.
1.366 + * @return The new CWTLSStructuredText object.
1.367 + */
1.368 + IMPORT_C static CWTLSStructuredText* NewL(const TDesC8& aBinaryData);
1.369 +
1.370 + /**
1.371 + * Creates a new CWTLSStructuredText object from the specified buffer containing the binary coded representation,
1.372 + * and puts a pointer to it onto the cleanup stack.
1.373 + *
1.374 + * @param aBinaryData The encoded binary representation.
1.375 + * @return The new CWTLSStructuredText object.
1.376 + */
1.377 + IMPORT_C static CWTLSStructuredText* NewLC(const TDesC8& aBinaryData);
1.378 +
1.379 + /**
1.380 + * Creates a new CWTLSStructuredText object from the specified buffer containing the binary coded representation,
1.381 + * starting at the specified offset.
1.382 + *
1.383 + * @param aBinaryData The encoded binary representation.
1.384 + * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor,
1.385 + * and is updated to the position at the end of the object.
1.386 + * @return The new CWTLSStructuredText object.
1.387 + */
1.388 + IMPORT_C static CWTLSStructuredText* NewL(const TDesC8& aBinaryData, TInt& aPos);
1.389 +
1.390 + /**
1.391 + * Creates a new CWTLSStructuredText object from the specified buffer containing the binary coded representation,
1.392 + * starting at the specified offset, and puts a pointer to it onto the cleanup stack.
1.393 + *
1.394 + * @param aBinaryData The encoded binary representation.
1.395 + * @param aPos The offset position from which to start decoding. It specifies an offset into the descriptor,
1.396 + * and is updated to the position at the end of the object.
1.397 + * @return The new CWTLSStructuredText object.
1.398 + */
1.399 + IMPORT_C static CWTLSStructuredText* NewLC(const TDesC8& aBinaryData, TInt& aPos);
1.400 +
1.401 + /**
1.402 + * Destructor.
1.403 + *
1.404 + * Frees all resources owned by the object, prior to its destruction.
1.405 + */
1.406 + IMPORT_C ~CWTLSStructuredText();
1.407 +
1.408 + /**
1.409 + *
1.410 + *
1.411 + * @return
1.412 + */
1.413 + IMPORT_C HBufC* DisplayNameL() const;
1.414 +
1.415 + //accessors for defined fields
1.416 +
1.417 + /**
1.418 + *
1.419 + *
1.420 + * @return
1.421 + */
1.422 + IMPORT_C TPtrC ServiceName() const;
1.423 +
1.424 + /**
1.425 + *
1.426 + *
1.427 + * @return
1.428 + */
1.429 + IMPORT_C TPtrC Organization() const;
1.430 +
1.431 + /**
1.432 + *
1.433 + *
1.434 + * @return
1.435 + */
1.436 + IMPORT_C TPtrC Country() const;
1.437 +
1.438 + /**
1.439 + *
1.440 + *
1.441 + * @return
1.442 + */
1.443 + IMPORT_C TInt Count() const;
1.444 +
1.445 +
1.446 + /**
1.447 + *
1.448 + *
1.449 + * Note
1.450 + *
1.451 + * @param aType
1.452 + * @return A pointer to a TWTLSStructuredTextField object; NULL if field not found.
1.453 + * The returned object remains the property of the structured text object
1.454 + * (so don't delete it).
1.455 + */
1.456 + IMPORT_C const TWTLSStructuredTextField* FieldByName(const TDesC& aType) const;
1.457 +
1.458 + /**
1.459 + *
1.460 + *
1.461 + * @return
1.462 + */
1.463 + IMPORT_C const TWTLSStructuredTextField& FieldByIndex(TInt aIndex) const;
1.464 +private:
1.465 + CWTLSStructuredText();
1.466 + void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
1.467 + void AddFieldValueL(const TDesC& aFieldName, TInt& aPos);
1.468 + void AddFieldL(TInt& aPos);
1.469 + TPtrC GetFieldL(TDesC& aString, TInt& aPos);
1.470 + TBool GetSubFieldL(TDesC& aString, TInt& aPos);
1.471 + CArrayFixFlat<TWTLSStructuredTextField>* iFields;
1.472 + };
1.473 +
1.474 +#endif