os/security/cryptoservices/certificateandkeymgmt/inc/wtlscert.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  @file 
    21  @publishedAll
    22  @released
    23 */
    24 
    25 #ifndef __WTLSCERT_H__
    26 #define __WTLSCERT_H__
    27 
    28 #include <e32base.h>
    29 #include <e32std.h>
    30 #include <s32std.h>
    31 #include <signed.h>
    32 #include <unifiedcertstore.h>
    33 #include <wtlsnames.h>
    34 
    35 
    36 class CRSAPublicKey;
    37 class CDSAPublicKey;
    38 class CDSASignature;
    39 class CDSAParameters;
    40 
    41 const TInt KWTLSCertMaxDataElements = 6;
    42 
    43 class CWTLSRSASignatureResult : public CRSASignatureResult
    44 	{
    45 public:
    46 	IMPORT_C static CWTLSRSASignatureResult* NewL(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest);
    47 	IMPORT_C static CWTLSRSASignatureResult* NewLC(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest);
    48 	IMPORT_C virtual TBool VerifyL(const TDesC8& aResult);
    49 private:
    50 	void ConstructL(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest);
    51 	};
    52 
    53 class TWTLSKeyFactory : public TKeyFactory
    54 	{
    55 public:
    56 	virtual CRSAPublicKey* RSAPublicKeyL(const TDesC8& aEncoding) const;
    57 	virtual CRSASignatureResult* RSASignatureResultL(const CAlgorithmIdentifier& aDigestAlgorithm, TDesC8& aDigest) const;
    58 	virtual CDSAPublicKey* DSAPublicKeyL(const CDSAParameters& aParams, const TDesC8& aEncoding) const;
    59 	virtual CDSASignature* DSASignatureL(const TDesC8& aEncoding) const;
    60 	virtual CDSAParameters* DSAParametersL(const TDesC8& aEncoding) const;
    61 	virtual CDSAPublicKey* DSAPublicKeyL(const TDesC8& aParamsEncoding, const TDesC8& aEncoding) const;
    62 	};
    63 
    64 class CWTLSValidityPeriod : public CValidityPeriod
    65 	{
    66 public:
    67 	IMPORT_C static CWTLSValidityPeriod* NewL(const TDesC8& aBinaryData);
    68 	IMPORT_C static CWTLSValidityPeriod* NewLC(const TDesC8& aBinaryData);
    69 	IMPORT_C static CWTLSValidityPeriod* NewL(const TDesC8& aBinaryData, TInt& aPos);
    70 	IMPORT_C static CWTLSValidityPeriod* NewLC(const TDesC8& aBinaryData, TInt& aPos);
    71 private:
    72 	CWTLSValidityPeriod();
    73 	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
    74 	};
    75 
    76 class CWTLSAlgorithmIdentifier : public CAlgorithmIdentifier
    77 	{
    78 public:
    79 	IMPORT_C static CWTLSAlgorithmIdentifier* NewL(const TDesC8& aBinaryData);
    80 	IMPORT_C static CWTLSAlgorithmIdentifier* NewLC(const TDesC8& aBinaryData);
    81 	IMPORT_C static CWTLSAlgorithmIdentifier* NewL(const TDesC8& aBinaryData, TInt& aPos);
    82 	IMPORT_C static CWTLSAlgorithmIdentifier* NewLC(const TDesC8& aBinaryData, TInt& aPos);
    83 private:
    84 	CWTLSAlgorithmIdentifier();
    85 	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
    86 	};
    87 
    88 class CWTLSSigningAlgorithmIdentifier : public CSigningAlgorithmIdentifier
    89 	{
    90 public:
    91 	IMPORT_C static CWTLSSigningAlgorithmIdentifier* NewL(const TDesC8& aBinaryData);
    92 	IMPORT_C static CWTLSSigningAlgorithmIdentifier* NewLC(const TDesC8& aBinaryData);
    93 	IMPORT_C static CWTLSSigningAlgorithmIdentifier* NewL(const TDesC8& aBinaryData, TInt& aPos);
    94 	IMPORT_C static CWTLSSigningAlgorithmIdentifier* NewLC(const TDesC8& aBinaryData, TInt& aPos);
    95 private:
    96 	CWTLSSigningAlgorithmIdentifier();
    97 	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
    98 	};
    99 
   100 class CWTLSSubjectPublicKeyInfo : public CSubjectPublicKeyInfo
   101 	{
   102 public:
   103 	IMPORT_C static CWTLSSubjectPublicKeyInfo* NewL(const TDesC8& aBinaryData);
   104 	IMPORT_C static CWTLSSubjectPublicKeyInfo* NewLC(const TDesC8& aBinaryData);
   105 	IMPORT_C static CWTLSSubjectPublicKeyInfo* NewL(const TDesC8& aBinaryData, TInt& aPos);
   106 	IMPORT_C static CWTLSSubjectPublicKeyInfo* NewLC(const TDesC8& aBinaryData, TInt& aPos);
   107 private:
   108 	CWTLSSubjectPublicKeyInfo();
   109 	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
   110 	};
   111 
   112 _LIT(KWTLSTCAType, " T");
   113 _LIT(KWTLSTCAValue, "ca");
   114 
   115 class CWTLSCertificate : public CCertificate
   116 	{
   117 public:
   118 	enum	//enum values for encoded data element positions in tbsCert data structure
   119 		{	//these values are to be used as params to DataElementEncoding() function
   120 		EVersionNumber = 0,
   121 		EAlgorithmId = 1,
   122 		EIssuerName = 2,
   123 		EValidityPeriod = 3,
   124 		ESubjectName = 4,
   125 		ESubjectPublicKeyInfo = 5,
   126 		};
   127 		
   128 	/**
   129 	 * Creates a new CWTLSCertificate object from the specified buffer containing the binary coded representation.
   130 	 *
   131 	 * @param aBinaryData	The encoded binary representation.
   132 	 * @return				The new CWTLSCertificate object.
   133 	 */	
   134 	IMPORT_C static CWTLSCertificate* NewL(const TDesC8& aBinaryData);
   135 
   136 	/**
   137 	 * Creates a new CWTLSCertificate object from the specified buffer containing the binary coded representation,
   138 	 * and puts a pointer to it onto the cleanup stack.
   139 	 *
   140 	 * @param aBinaryData	The encoded binary representation.
   141 	 * @return				The new CWTLSCertificate object.
   142 	 */	
   143 	IMPORT_C static CWTLSCertificate* NewLC(const TDesC8& aBinaryData);
   144 
   145 	/**
   146 	 * Creates a new CWTLSCertificate object from the specified buffer containing the binary coded representation.
   147 	 *
   148 	 * @param aBinaryData	The encoded binary representation.
   149 	 * @param aPos			An offset into the descriptor, and is updated to the position at the end of the object.
   150 	 * @return				The new CWTLSCertificate object.
   151 	 */	
   152 	IMPORT_C static CWTLSCertificate* NewL(const TDesC8& aBinaryData, TInt& aPos);
   153 
   154 	/**
   155 	 * Creates a new CWTLSCertificate object from the specified buffer containing the binary coded representation,
   156 	 * and puts a pointer to it onto the cleanup stack.
   157 	 *
   158 	 * @param aBinaryData	The encoded binary representation.
   159 	 * @param aPos			An offset into the descriptor, and is updated to the position at the end of the object.
   160 	 * @return				The new CWTLSCertificate object.
   161 	 */	
   162 	IMPORT_C static CWTLSCertificate* NewLC(const TDesC8& aBinaryData, TInt& aPos);
   163 
   164 	/**
   165 	 * Creates a new CWTLSCertificate object from a stream.
   166 	 *
   167 	 * The stream must have been written using the corresponding ExternalizeL() function.
   168 	 *
   169 	 * @param aStream	The stream to be used as input.
   170 	 * @return			The new CWTLSCertificate object.
   171 	 */	
   172 	IMPORT_C static CWTLSCertificate* NewL(RReadStream& aStream);
   173 
   174 	/**
   175 	 * Creates a new CWTLSCertificate object from a stream,
   176 	 * and puts a pointer to it onto the cleanup stack.
   177 	 *
   178 	 * The stream must have been written using the corresponding ExternalizeL() function.
   179 	 *
   180 	 * @param aStream	The stream to be used as input.
   181 	 * @return			The new CWTLSCertificate object.
   182 	 */	
   183 	IMPORT_C static CWTLSCertificate* NewLC(RReadStream& aStream);
   184 
   185 	/**
   186 	 * Creates a new CWTLSCertificate object from an existing one in the certificate store.
   187 	 *
   188 	 * @param aCert	The certificate to be copied.
   189 	 * @return		The new CWTLSCertificate object.
   190 	 */	
   191 	IMPORT_C static CWTLSCertificate* NewL(const CWTLSCertificate& aCert);
   192 
   193 	/**
   194 	 * Creates a new CWTLSCertificate object from an existing one in the certificate store,
   195 	 * and puts a pointer to it onto the cleanup stack.
   196 	 *
   197 	 * @param aCert	The certificate to be copied.
   198 	 * @return		The new CWTLSCertificate object.
   199 	 */	
   200 	IMPORT_C static CWTLSCertificate* NewLC(const CWTLSCertificate& aCert);
   201 
   202 	/**
   203 	 * Destructor.
   204 	 *
   205 	 * Frees all resources owned by the object, prior to its destruction.
   206 	 */
   207 	IMPORT_C ~CWTLSCertificate();
   208 	
   209 	/**
   210 	* Tests whether this WTLS certificate is the same as the specified WTLS certificate.
   211 	*
   212 	* This is not a simple as it sounds. For X.509 certificates equality means that the issuer name 
   213 	* and serial number fields are the same. This guarantees equality since a CA must ensure that every 
   214 	* certificate it issues has a unique serial number. But WTLS certificates do not include serial numbers, 
   215 	* so there seems to be no definition of equality. This function uses a byte-for-byte comparison of the 
   216 	* signatures on the certificates: this should not result in any false positives, but may give false 
   217 	* negatives if CAs do naughty things like recertifying the same key (which they have been known to do).
   218 	*
   219 	* @param aCert	A WTLS certificate
   220 	* @return		ETrue, if the parameter is the same certificate; EFalse, otherwise.
   221 	*/
   222 	IMPORT_C TBool IsEqualL(const CWTLSCertificate& aCert) const;
   223 	
   224 	//extra accessors
   225 	
   226 	/**
   227 	 * Gets the version number of the WTLS certificate.
   228 	 *
   229 	 * @return	The version number of the certificate. Always returns 1.
   230 	 */
   231 	IMPORT_C TInt Version() const;
   232 	
   233 	/**
   234 	 * Gets the name of the WTLS certificate's issuing authority.
   235 	 *
   236 	 * @return	A WTLS name:
   237 	 *			@li	If the name is an X.500 DN, then if the name contains a Common name, that will be returned. 
   238 	 * 				Otherwise, if the name contains an Organization name, that will be returned. Otherwise an empty 
   239 	 * 				string will be returned. 
   240 	 *			@li	If the name is of type text, then if the name is not a 'structured' name the entire string will 
   241 	 *				be returned, otherwise the same procedure will be followed as for X.509 certificates.
   242 	 * 			@li	If the name is null an empty string will be returned. 
   243 	 */
   244 	 // Unsupported -- If the name is a key hash or binary value the entire contents will be returned.
   245 	IMPORT_C const CWTLSName& IssuerName() const;
   246 	
   247 	/**
   248 	* Gets the name of the owner of the public key the WTLS certificate contains.
   249 	*
   250 	* @return A WTLS name.
   251 	*/
   252 	IMPORT_C const CWTLSName& SubjectName() const;
   253 	IMPORT_C virtual TBool IsSelfSignedL() const;
   254 	IMPORT_C virtual HBufC* SubjectL() const;
   255 	IMPORT_C virtual HBufC* IssuerL() const;
   256 	
   257 	/**
   258 	* Initialises the certificate from a stream. 
   259 	*
   260 	* This should not be called by client code; instead the static factory function above should be used. 
   261 	* If a client is using the certstore component for storage then it should use CCertStore::AddL() for 
   262 	* externalizing and CWTLSCert::NewL(CCertStore& aStore, const CCertStoreEntry& aEntry); for restoring.
   263 	*
   264 	* @param aStream 
   265 	*/
   266 	IMPORT_C void InternalizeL(RReadStream& aStream);
   267 	
   268 	/**
   269 	* Gets the certificate's signed data.
   270 	*
   271 	* @return	A non-modifiable pointer descriptor representing the certificate's signed data.
   272 	*/
   273 	IMPORT_C const TPtrC8 SignedDataL() const;
   274 	
   275 	/**
   276 	* Gets the encoding for a data element at the specified index.
   277 	*
   278 	* @param aIndex	The position of the encoded data element.
   279 	*/
   280 	IMPORT_C virtual const TPtrC8* DataElementEncoding(const TUint aIndex) const;
   281 	
   282 	/**
   283 	* Tests whether a non-selfsigned certificate can be used to sign others.
   284 	* 
   285 	* Currently this only supports structured text variety of WTLS certificates.  
   286 	* Other certificate types will return EFalse.
   287 	*
   288 	* @return	ETrue, if the certificate is capable of signing other certificates; otherwise, EFalse. 
   289 	*/
   290 	IMPORT_C TBool IsTCAL() const;
   291 private:
   292 	CWTLSCertificate();
   293 	void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
   294 	void ConstructL(const CWTLSCertificate& aCertificate);
   295 	void ConstructCertL(const TDesC8& aBinaryData, TInt& aPos);
   296 	void InitEncodedDataElementsL();
   297 	//private data
   298 	TInt iVersion;
   299 	CWTLSName* iIssuerName;
   300 	CWTLSName* iSubjectName;
   301 	TFixedArray<TPtrC8*, KWTLSCertMaxDataElements>* iDataElements;
   302 	};
   303 
   304 #endif