os/security/cryptomgmtlibs/cryptotokenfw/inc_interfaces/CCTCertInfo_v2.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2001-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 * CCTCertInfo.H
    16 *
    17 */
    18 
    19 
    20 /**
    21  @file 
    22  @publishedAll
    23  @released
    24 */
    25  
    26 #ifndef __CCTCERTINFO_H__
    27 #define __CCTCERTINFO_H__
    28 
    29 #include <e32base.h>
    30 #include <s32strm.h>
    31 
    32 #include <securitydefs.h>
    33 #include <ct/mcttokentype.h>
    34 #include <ct/mcttoken.h>
    35 #include <ct/mcttokenobject.h>
    36 
    37 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
    38 
    39 /** Mask constants used for serializing iDeletable and iFormat attributes 
    40 */
    41 const TUint KReadOnlyFlagMask = 128;
    42 const TUint KFormatMask = 127;
    43 
    44 /** The UID of a CertInfo MCTTokenObject. */
    45 const TInt KCTObjectCertInfo = 0x101F50E6;
    46 
    47 #endif
    48 
    49 /** The maximum length of a certificate label. */
    50 const TUint32 KMaxCertLabelLength = 64;
    51 
    52 /** Defines a modifiable buffer descriptor to contain a human-readable certificate label. 
    53 *
    54 */
    55 typedef TBuf<KMaxCertLabelLength> TCertLabel;
    56 
    57 /**
    58  * Mix-in class representnig data about a stored certificate.  Provides
    59  * implementation of serialization.
    60  * 
    61  * Note that for backward compatibility reasons, the issuer hash is not serialised.
    62  *
    63  */
    64 class MCertInfo
    65 	{
    66  public:
    67 	// Internalization/Externalization
    68 	// Externalize. Writes the data out to a stream
    69 	
    70   /** Externalises an object of this class to a write stream.
    71 	* 
    72 	* The presence of this function means that the standard templated operator<<() 
    73 	* can be used to externalise objects of this class.
    74 	* 
    75 	* @param aStream	Stream to which the object should be externalised. */
    76 	IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
    77 
    78 	// Internalize. Reads the data from a stream 
    79 	/** Internalises an object of this class from a read stream.
    80 	* 
    81 	* The presence of this function means that the standard templated operator>>() 
    82 	* can be used to internalise objects of this class.
    83 	* 
    84 	* Note that this function has assignment semantics: it replaces the old value 
    85 	* of the object with a new value read from the read stream.	
    86 	* 
    87 	* @param aStream	Stream from which the object should be internalised. */
    88 	IMPORT_C void InternalizeL(RReadStream& aStream);
    89 	
    90  protected:
    91 	IMPORT_C MCertInfo();
    92 	IMPORT_C MCertInfo(const TDesC& aLabel,
    93 					   TCertificateFormat aFormat,
    94 					   TCertificateOwnerType aCertificateOwnerType, 
    95 					   TInt aSize,
    96 					   const TKeyIdentifier* aSubjectKeyId,
    97 					   const TKeyIdentifier* aIssuerKeyId, 
    98 					   TInt aCertificateId,
    99 					   TBool aDeletable);
   100 	IMPORT_C MCertInfo(const MCertInfo& aOther);
   101 	IMPORT_C ~MCertInfo();
   102 
   103 	IMPORT_C void ConstructL(const TDesC8* aIssuerHash);
   104 
   105 	const TDesC8* IssuerHash() const;
   106 
   107  private:
   108 	TBool Valid() const;
   109 	const MCertInfo& operator=(const MCertInfo& aOther);
   110 
   111  protected:
   112 	TCertLabel iLabel;
   113 	TInt iCertificateId;
   114 	TCertificateFormat iFormat;
   115 	TCertificateOwnerType iCertificateOwnerType;
   116 	TInt iSize;
   117 	TKeyIdentifier iSubjectKeyId;
   118 	TKeyIdentifier iIssuerKeyId;
   119 	TBool iDeletable;
   120 
   121  private:
   122 	HBufC8* iIssuerHash;
   123 	};
   124 
   125 /** Encapsulates information about a stored certificate.
   126  * 
   127  * Objects of this type are usually returned by a certificate store, to allow 
   128  * a client to query the contents of the store.
   129  * 
   130  * Note that these objects are normally constructed by certificate stores, not 
   131  * by clients. 
   132  *
   133  */
   134 class CCTCertInfo : protected CBase, public MCTTokenObject, public MCertInfo
   135 	{
   136 public:
   137 	/** Construction -- Note that these objects are normally constructed by certificate stores, not by clients. */
   138 
   139 	/** 
   140 	*
   141 	* Creates the certificate information object by copying from an existing object.
   142 	* 
   143 	* @param aCertInfo			The source certificate information.
   144 	* @return					A pointer to the new certificate information object.
   145 	* @leave KErrNoMemory	There is no memory to construct it. */
   146 	IMPORT_C static CCTCertInfo* NewL(const CCTCertInfo& aCertInfo);
   147 
   148 	/** 
   149 	*
   150 	* Creates the certificate information object by copying from an existing object, 
   151 	* and puts a pointer to the new object onto the cleanup stack.
   152 	* 
   153 	* @param aCertInfo			The source certificate information.
   154 	* @return					A pointer to the new certificate information object.
   155 	* @leave KErrNoMemory	There is no memory to construct it. */
   156 	IMPORT_C static CCTCertInfo* NewLC(const CCTCertInfo& aCertInfo);
   157 
   158 	/** 
   159 	*
   160 	* Creates the certificate information object from its constituent parts.
   161 	* 
   162 	* @param aLabel					The certificate's label.
   163 	* @param aFormat				The certificate's format.
   164 	* @param aCertificateOwnerType	The owner type.
   165 	* @param aSize					The size of the certificate.
   166 	* @param aSubjectKeyId			The subject key ID.
   167 	* @param aIssuerKeyId			The issuer key ID.
   168 	* @param aToken					The token that the certificate is within.
   169 	* @param aCertificateId			The ID within the object handle.
   170 	* @param aDeletable				The certificate is deletable.
   171 	* @param aIssuerHash			The hash of the DN of the issuer.
   172 	* @return						A pointer to the new certificate information object. 
   173 	* @leave KErrNoMemory		There is no memory to construct it.*/
   174 	IMPORT_C static CCTCertInfo* NewL(const TDesC& aLabel, TCertificateFormat aFormat,
   175 		TCertificateOwnerType aCertificateOwnerType, TInt aSize,
   176 		const TKeyIdentifier* aSubjectKeyId, const TKeyIdentifier* aIssuerKeyId,
   177 		MCTToken& aToken, TInt aCertificateId, TBool aDeletable, 
   178 									  const TDesC8* aIssuerHash = NULL);
   179 
   180 	/** 
   181 	*
   182 	* Creates the certificate information object from its constituent parts.	
   183 	* 
   184 	* @param aLabel					The certificate's label.
   185 	* @param aFormat 				The certificate's format.
   186 	* @param aCertificateOwnerType	The owner type.
   187 	* @param aSize					The size of the certificate.
   188 	* @param aSubjectKeyId			The subject key ID.
   189 	* @param aIssuerKeyId			The issuer key ID.
   190 	* @param aToken					The token that the certificate is within.
   191 	* @param aCertificateId			The ID within the object handle.
   192 	* @return 						A pointer to the new certificate information object.
   193 	* @leave KErrNoMemory		There is no memory to construct it.*/
   194 	IMPORT_C static CCTCertInfo* NewL(const TDesC& aLabel, TCertificateFormat aFormat,
   195 		TCertificateOwnerType aCertificateOwnerType, TInt aSize,
   196 		const TKeyIdentifier* aSubjectKeyId, const TKeyIdentifier* aIssuerKeyId,
   197 		MCTToken& aToken, TInt aCertificateId);
   198 
   199 	/** 
   200 	* 
   201 	* Creates the certificate information object from its constituent parts, 
   202 	* and puts a pointer to the new object onto the cleanup stack.
   203 	* 
   204 	* @param aLabel					The certificate's label.
   205 	* @param aFormat				The certificate's format.
   206 	* @param aCertificateOwnerType	The owner type.
   207 	* @param aSize					The size of the certificate.
   208 	* @param aSubjectKeyId			The subject key ID.
   209 	* @param aIssuerKeyId			The issuer key ID.
   210 	* @param aToken					The token that the certificate is within.
   211 	* @param aCertificateId			The ID within the object handle.
   212 	* @param aDeletable				The certificate is deletable.
   213 	* @param aIssuerHash			The hash of the issuer's DN.
   214 	* @return						A pointer to the new certificate information object. 
   215 	* @leave KErrNoMemory		There is no memory to construct it.*/
   216 	IMPORT_C static CCTCertInfo* NewLC(const TDesC& aLabel, TCertificateFormat aFormat,
   217 		TCertificateOwnerType aCertificateOwnerType, TInt aSize,
   218 		const TKeyIdentifier* aSubjectKeyId, const TKeyIdentifier* aIssuerKeyId,
   219 		MCTToken& aToken, TInt aCertificateId, TBool aDeletable, 
   220 									   const TDesC8* aIssuerHash = NULL);
   221 
   222 	/**
   223 	*
   224 	* Creates the certificate information object from its constituent parts, and puts 
   225 	* a pointer to the new object onto the cleanup stack.
   226 	* 
   227 	* @param aLabel					The certificate's label.
   228 	* @param aFormat				The certificate's format.
   229 	* @param aCertificateOwnerType	The owner type.
   230 	* @param aSize					The size of the certificate.
   231 	* @param aSubjectKeyId			The subject key ID.
   232 	* @param aIssuerKeyId			The issuer key ID.
   233 	* @param aToken					The token that the certificate is within.
   234 	* @param aCertificateId			The ID within the object handle.
   235 	* @return						A pointer to the new certificate information object.
   236 	* @leave KErrNoMemory		There is no memory to construct it.*/
   237 	IMPORT_C static CCTCertInfo* NewLC(const TDesC& aLabel, TCertificateFormat aFormat,
   238 		TCertificateOwnerType aCertificateOwnerType, TInt aSize,
   239 		const TKeyIdentifier* aSubjectKeyId, const TKeyIdentifier* aIssuerKeyId,
   240 		MCTToken& aToken, TInt aCertificateId);
   241 
   242 	/** 
   243 	* 
   244 	* Creates the certificate information object by internalising a previously externalised 
   245 	* one.
   246 	* 
   247 	* @param aStream			The stream from which the object is to be internalised.
   248 	* @param aToken				The token that it is within.
   249 	* @return					A pointer to the new certificate information object. 
   250 	* @leave KErrNoMemory	There is no memory to construct it.
   251 	* @see ExternalizeL
   252 	* @see InternalizeL */
   253 	IMPORT_C static CCTCertInfo* NewL(RReadStream& aStream, MCTToken& aToken);
   254 
   255 	/** 
   256 	* 
   257 	* Creates the certificate information object, by internalising a previously externalised 
   258 	* one, and puts a pointer to the new object onto the cleanup stack.	
   259 	* 
   260 	* @param aStream			The stream from which the object is to be internalised.
   261 	* @param aToken				The token that it is within.
   262 	* @return					A pointer to the new certificate information object. 
   263 	* @leave KErrNoMemory	There is no memory to construct it.
   264 	* @see ExternalizeL
   265 	* @see InternalizeL */
   266 	IMPORT_C static CCTCertInfo* NewLC(RReadStream& aStream, MCTToken& aToken);
   267 
   268 	/** Gets the subject key ID.	
   269 	* 
   270 	* @return A reference to a key identifier object. */
   271 	IMPORT_C const TKeyIdentifier& SubjectKeyId() const;
   272 
   273 	/** Gets the issuer key ID.
   274 	* 
   275 	* @return A reference to a key identifier object. */
   276 	IMPORT_C const TKeyIdentifier& IssuerKeyId() const;
   277 
   278 	/** Gets the certificate format.
   279 	* 
   280 	* @return The certificate format. */
   281 	IMPORT_C TCertificateFormat CertificateFormat() const;
   282 
   283 	/** Gets the owner type.
   284 	* 
   285 	* @return The owner type. */
   286 	IMPORT_C TCertificateOwnerType CertificateOwnerType() const;
   287 
   288 	/** Gets the size of the certificate.
   289 	* 
   290 	* Note that this function must be called so that the correct size of descriptor 
   291 	* can be allocated when retrieving the certificate (with MCertStore::Retrieve()).
   292 	* 
   293 	* @return The size of the certificate. */
   294 	IMPORT_C TInt Size() const;
   295 
   296 	/** Gets a handle for the object.
   297 	* 
   298 	* The primary purpose of the handle is to allow token objects to be 'passed' 
   299 	* between processes.
   300 	* 
   301 	* @return	A handle for the object. 
   302 	* @see TCTTokenObjectHandle */
   303 	IMPORT_C TCTTokenObjectHandle Handle() const;
   304 
   305 	/** Whether the certificate is deletable.
   306 	* 
   307 	* @return	ETrue if it is possible to delete the certificate; EFalse, otherwise. */
   308 	IMPORT_C TBool IsDeletable() const;
   309 
   310 	/** Gets the hash of the issuer's DN.
   311 	* 
   312 	* @return	The hash of the issuer's DN, or NULL if not known. */
   313 	IMPORT_C const TDesC8* IssuerHash() const;
   314 
   315  public:	
   316   // from MCTTokenObject
   317 	/** Gets the object's human-readable label.
   318 	* 
   319 	* @return	The object's human-readable label.
   320 	* @see MCTTokenObject::Label()*/
   321 	virtual const TDesC& Label() const;
   322 
   323 	/** Gets a reference to the associated token.
   324 	* 
   325 	* @return	A reference to the associated token.
   326 	* @see MCTTokenObject::Token()*/
   327 	virtual MCTToken& Token() const;
   328 
   329 	/** Gets a UID representing the type of the token object.
   330 	* 
   331 	* The function overrides MCTTokenObject::Type().
   332 	* 
   333 	* The meanings of possible UIDs should be documented in the documentation for 
   334 	* the interface that returns them.
   335 	* 
   336 	* @return	A UID representing the type of the token object; this implementation 
   337 	* 			returns KCTObjectCertInfo.
   338 	* @see MCTTokenObject::Type() */
   339 	virtual TUid Type() const;
   340 	
   341 	// Compares 2 cert infos
   342 	/** Compares this certificate information object with a specified Certificate 
   343 	* Information object for equality.
   344 	* 
   345 	* @param aCertInfo	The certificate information object to be compared.
   346 	* @return			ETrue, if they are the same; EFalse, otherwise. */
   347 	IMPORT_C TBool operator ==(const CCTCertInfo& aCertInfo) const;
   348 
   349 	/** Sets the certificate Id.
   350 	* 
   351 	* @param aCertId The certificate Id.*/
   352 	IMPORT_C void SetCertificateId(TInt aCertId);
   353 
   354  protected:
   355 	IMPORT_C virtual ~CCTCertInfo();
   356 	
   357  private:
   358 	CCTCertInfo(MCTToken& aToken);
   359 	CCTCertInfo(const TDesC& aLabel, TCertificateFormat aFormat,
   360 				TCertificateOwnerType aCertificateOwnerType, 
   361 				TInt aSize,
   362 				const TKeyIdentifier* aSubjectKeyId,
   363 				const TKeyIdentifier* aIssuerKeyId,
   364 				MCTToken& aToken, TInt aCertificateId,
   365 				TBool aDeletable);
   366 	CCTCertInfo(const CCTCertInfo& aCertInfo);
   367 	void ConstructL(RReadStream& aStream);
   368 	void ConstructL(const TDesC8* aIssuerHash);
   369 	
   370  private:
   371 	const CCTCertInfo& operator=(const CCTCertInfo& aOther);
   372 	
   373  private:	
   374 	MCTToken& iToken;
   375 	};
   376 
   377 #endif