os/security/cryptomgmtlibs/cryptotokenfw/inc_interfaces/CCTCertInfo_v2.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptomgmtlibs/cryptotokenfw/inc_interfaces/CCTCertInfo_v2.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,377 @@
     1.4 +/*
     1.5 +* Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +* CCTCertInfo.H
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 +/**
    1.24 + @file 
    1.25 + @publishedAll
    1.26 + @released
    1.27 +*/
    1.28 + 
    1.29 +#ifndef __CCTCERTINFO_H__
    1.30 +#define __CCTCERTINFO_H__
    1.31 +
    1.32 +#include <e32base.h>
    1.33 +#include <s32strm.h>
    1.34 +
    1.35 +#include <securitydefs.h>
    1.36 +#include <ct/mcttokentype.h>
    1.37 +#include <ct/mcttoken.h>
    1.38 +#include <ct/mcttokenobject.h>
    1.39 +
    1.40 +#ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
    1.41 +
    1.42 +/** Mask constants used for serializing iDeletable and iFormat attributes 
    1.43 +*/
    1.44 +const TUint KReadOnlyFlagMask = 128;
    1.45 +const TUint KFormatMask = 127;
    1.46 +
    1.47 +/** The UID of a CertInfo MCTTokenObject. */
    1.48 +const TInt KCTObjectCertInfo = 0x101F50E6;
    1.49 +
    1.50 +#endif
    1.51 +
    1.52 +/** The maximum length of a certificate label. */
    1.53 +const TUint32 KMaxCertLabelLength = 64;
    1.54 +
    1.55 +/** Defines a modifiable buffer descriptor to contain a human-readable certificate label. 
    1.56 +*
    1.57 +*/
    1.58 +typedef TBuf<KMaxCertLabelLength> TCertLabel;
    1.59 +
    1.60 +/**
    1.61 + * Mix-in class representnig data about a stored certificate.  Provides
    1.62 + * implementation of serialization.
    1.63 + * 
    1.64 + * Note that for backward compatibility reasons, the issuer hash is not serialised.
    1.65 + *
    1.66 + */
    1.67 +class MCertInfo
    1.68 +	{
    1.69 + public:
    1.70 +	// Internalization/Externalization
    1.71 +	// Externalize. Writes the data out to a stream
    1.72 +	
    1.73 +  /** Externalises an object of this class to a write stream.
    1.74 +	* 
    1.75 +	* The presence of this function means that the standard templated operator<<() 
    1.76 +	* can be used to externalise objects of this class.
    1.77 +	* 
    1.78 +	* @param aStream	Stream to which the object should be externalised. */
    1.79 +	IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
    1.80 +
    1.81 +	// Internalize. Reads the data from a stream 
    1.82 +	/** Internalises an object of this class from a read stream.
    1.83 +	* 
    1.84 +	* The presence of this function means that the standard templated operator>>() 
    1.85 +	* can be used to internalise objects of this class.
    1.86 +	* 
    1.87 +	* Note that this function has assignment semantics: it replaces the old value 
    1.88 +	* of the object with a new value read from the read stream.	
    1.89 +	* 
    1.90 +	* @param aStream	Stream from which the object should be internalised. */
    1.91 +	IMPORT_C void InternalizeL(RReadStream& aStream);
    1.92 +	
    1.93 + protected:
    1.94 +	IMPORT_C MCertInfo();
    1.95 +	IMPORT_C MCertInfo(const TDesC& aLabel,
    1.96 +					   TCertificateFormat aFormat,
    1.97 +					   TCertificateOwnerType aCertificateOwnerType, 
    1.98 +					   TInt aSize,
    1.99 +					   const TKeyIdentifier* aSubjectKeyId,
   1.100 +					   const TKeyIdentifier* aIssuerKeyId, 
   1.101 +					   TInt aCertificateId,
   1.102 +					   TBool aDeletable);
   1.103 +	IMPORT_C MCertInfo(const MCertInfo& aOther);
   1.104 +	IMPORT_C ~MCertInfo();
   1.105 +
   1.106 +	IMPORT_C void ConstructL(const TDesC8* aIssuerHash);
   1.107 +
   1.108 +	const TDesC8* IssuerHash() const;
   1.109 +
   1.110 + private:
   1.111 +	TBool Valid() const;
   1.112 +	const MCertInfo& operator=(const MCertInfo& aOther);
   1.113 +
   1.114 + protected:
   1.115 +	TCertLabel iLabel;
   1.116 +	TInt iCertificateId;
   1.117 +	TCertificateFormat iFormat;
   1.118 +	TCertificateOwnerType iCertificateOwnerType;
   1.119 +	TInt iSize;
   1.120 +	TKeyIdentifier iSubjectKeyId;
   1.121 +	TKeyIdentifier iIssuerKeyId;
   1.122 +	TBool iDeletable;
   1.123 +
   1.124 + private:
   1.125 +	HBufC8* iIssuerHash;
   1.126 +	};
   1.127 +
   1.128 +/** Encapsulates information about a stored certificate.
   1.129 + * 
   1.130 + * Objects of this type are usually returned by a certificate store, to allow 
   1.131 + * a client to query the contents of the store.
   1.132 + * 
   1.133 + * Note that these objects are normally constructed by certificate stores, not 
   1.134 + * by clients. 
   1.135 + *
   1.136 + */
   1.137 +class CCTCertInfo : protected CBase, public MCTTokenObject, public MCertInfo
   1.138 +	{
   1.139 +public:
   1.140 +	/** Construction -- Note that these objects are normally constructed by certificate stores, not by clients. */
   1.141 +
   1.142 +	/** 
   1.143 +	*
   1.144 +	* Creates the certificate information object by copying from an existing object.
   1.145 +	* 
   1.146 +	* @param aCertInfo			The source certificate information.
   1.147 +	* @return					A pointer to the new certificate information object.
   1.148 +	* @leave KErrNoMemory	There is no memory to construct it. */
   1.149 +	IMPORT_C static CCTCertInfo* NewL(const CCTCertInfo& aCertInfo);
   1.150 +
   1.151 +	/** 
   1.152 +	*
   1.153 +	* Creates the certificate information object by copying from an existing object, 
   1.154 +	* and puts a pointer to the new object onto the cleanup stack.
   1.155 +	* 
   1.156 +	* @param aCertInfo			The source certificate information.
   1.157 +	* @return					A pointer to the new certificate information object.
   1.158 +	* @leave KErrNoMemory	There is no memory to construct it. */
   1.159 +	IMPORT_C static CCTCertInfo* NewLC(const CCTCertInfo& aCertInfo);
   1.160 +
   1.161 +	/** 
   1.162 +	*
   1.163 +	* Creates the certificate information object from its constituent parts.
   1.164 +	* 
   1.165 +	* @param aLabel					The certificate's label.
   1.166 +	* @param aFormat				The certificate's format.
   1.167 +	* @param aCertificateOwnerType	The owner type.
   1.168 +	* @param aSize					The size of the certificate.
   1.169 +	* @param aSubjectKeyId			The subject key ID.
   1.170 +	* @param aIssuerKeyId			The issuer key ID.
   1.171 +	* @param aToken					The token that the certificate is within.
   1.172 +	* @param aCertificateId			The ID within the object handle.
   1.173 +	* @param aDeletable				The certificate is deletable.
   1.174 +	* @param aIssuerHash			The hash of the DN of the issuer.
   1.175 +	* @return						A pointer to the new certificate information object. 
   1.176 +	* @leave KErrNoMemory		There is no memory to construct it.*/
   1.177 +	IMPORT_C static CCTCertInfo* NewL(const TDesC& aLabel, TCertificateFormat aFormat,
   1.178 +		TCertificateOwnerType aCertificateOwnerType, TInt aSize,
   1.179 +		const TKeyIdentifier* aSubjectKeyId, const TKeyIdentifier* aIssuerKeyId,
   1.180 +		MCTToken& aToken, TInt aCertificateId, TBool aDeletable, 
   1.181 +									  const TDesC8* aIssuerHash = NULL);
   1.182 +
   1.183 +	/** 
   1.184 +	*
   1.185 +	* Creates the certificate information object from its constituent parts.	
   1.186 +	* 
   1.187 +	* @param aLabel					The certificate's label.
   1.188 +	* @param aFormat 				The certificate's format.
   1.189 +	* @param aCertificateOwnerType	The owner type.
   1.190 +	* @param aSize					The size of the certificate.
   1.191 +	* @param aSubjectKeyId			The subject key ID.
   1.192 +	* @param aIssuerKeyId			The issuer key ID.
   1.193 +	* @param aToken					The token that the certificate is within.
   1.194 +	* @param aCertificateId			The ID within the object handle.
   1.195 +	* @return 						A pointer to the new certificate information object.
   1.196 +	* @leave KErrNoMemory		There is no memory to construct it.*/
   1.197 +	IMPORT_C static CCTCertInfo* NewL(const TDesC& aLabel, TCertificateFormat aFormat,
   1.198 +		TCertificateOwnerType aCertificateOwnerType, TInt aSize,
   1.199 +		const TKeyIdentifier* aSubjectKeyId, const TKeyIdentifier* aIssuerKeyId,
   1.200 +		MCTToken& aToken, TInt aCertificateId);
   1.201 +
   1.202 +	/** 
   1.203 +	* 
   1.204 +	* Creates the certificate information object from its constituent parts, 
   1.205 +	* and puts a pointer to the new object onto the cleanup stack.
   1.206 +	* 
   1.207 +	* @param aLabel					The certificate's label.
   1.208 +	* @param aFormat				The certificate's format.
   1.209 +	* @param aCertificateOwnerType	The owner type.
   1.210 +	* @param aSize					The size of the certificate.
   1.211 +	* @param aSubjectKeyId			The subject key ID.
   1.212 +	* @param aIssuerKeyId			The issuer key ID.
   1.213 +	* @param aToken					The token that the certificate is within.
   1.214 +	* @param aCertificateId			The ID within the object handle.
   1.215 +	* @param aDeletable				The certificate is deletable.
   1.216 +	* @param aIssuerHash			The hash of the issuer's DN.
   1.217 +	* @return						A pointer to the new certificate information object. 
   1.218 +	* @leave KErrNoMemory		There is no memory to construct it.*/
   1.219 +	IMPORT_C static CCTCertInfo* NewLC(const TDesC& aLabel, TCertificateFormat aFormat,
   1.220 +		TCertificateOwnerType aCertificateOwnerType, TInt aSize,
   1.221 +		const TKeyIdentifier* aSubjectKeyId, const TKeyIdentifier* aIssuerKeyId,
   1.222 +		MCTToken& aToken, TInt aCertificateId, TBool aDeletable, 
   1.223 +									   const TDesC8* aIssuerHash = NULL);
   1.224 +
   1.225 +	/**
   1.226 +	*
   1.227 +	* Creates the certificate information object from its constituent parts, and puts 
   1.228 +	* a pointer to the new object onto the cleanup stack.
   1.229 +	* 
   1.230 +	* @param aLabel					The certificate's label.
   1.231 +	* @param aFormat				The certificate's format.
   1.232 +	* @param aCertificateOwnerType	The owner type.
   1.233 +	* @param aSize					The size of the certificate.
   1.234 +	* @param aSubjectKeyId			The subject key ID.
   1.235 +	* @param aIssuerKeyId			The issuer key ID.
   1.236 +	* @param aToken					The token that the certificate is within.
   1.237 +	* @param aCertificateId			The ID within the object handle.
   1.238 +	* @return						A pointer to the new certificate information object.
   1.239 +	* @leave KErrNoMemory		There is no memory to construct it.*/
   1.240 +	IMPORT_C static CCTCertInfo* NewLC(const TDesC& aLabel, TCertificateFormat aFormat,
   1.241 +		TCertificateOwnerType aCertificateOwnerType, TInt aSize,
   1.242 +		const TKeyIdentifier* aSubjectKeyId, const TKeyIdentifier* aIssuerKeyId,
   1.243 +		MCTToken& aToken, TInt aCertificateId);
   1.244 +
   1.245 +	/** 
   1.246 +	* 
   1.247 +	* Creates the certificate information object by internalising a previously externalised 
   1.248 +	* one.
   1.249 +	* 
   1.250 +	* @param aStream			The stream from which the object is to be internalised.
   1.251 +	* @param aToken				The token that it is within.
   1.252 +	* @return					A pointer to the new certificate information object. 
   1.253 +	* @leave KErrNoMemory	There is no memory to construct it.
   1.254 +	* @see ExternalizeL
   1.255 +	* @see InternalizeL */
   1.256 +	IMPORT_C static CCTCertInfo* NewL(RReadStream& aStream, MCTToken& aToken);
   1.257 +
   1.258 +	/** 
   1.259 +	* 
   1.260 +	* Creates the certificate information object, by internalising a previously externalised 
   1.261 +	* one, and puts a pointer to the new object onto the cleanup stack.	
   1.262 +	* 
   1.263 +	* @param aStream			The stream from which the object is to be internalised.
   1.264 +	* @param aToken				The token that it is within.
   1.265 +	* @return					A pointer to the new certificate information object. 
   1.266 +	* @leave KErrNoMemory	There is no memory to construct it.
   1.267 +	* @see ExternalizeL
   1.268 +	* @see InternalizeL */
   1.269 +	IMPORT_C static CCTCertInfo* NewLC(RReadStream& aStream, MCTToken& aToken);
   1.270 +
   1.271 +	/** Gets the subject key ID.	
   1.272 +	* 
   1.273 +	* @return A reference to a key identifier object. */
   1.274 +	IMPORT_C const TKeyIdentifier& SubjectKeyId() const;
   1.275 +
   1.276 +	/** Gets the issuer key ID.
   1.277 +	* 
   1.278 +	* @return A reference to a key identifier object. */
   1.279 +	IMPORT_C const TKeyIdentifier& IssuerKeyId() const;
   1.280 +
   1.281 +	/** Gets the certificate format.
   1.282 +	* 
   1.283 +	* @return The certificate format. */
   1.284 +	IMPORT_C TCertificateFormat CertificateFormat() const;
   1.285 +
   1.286 +	/** Gets the owner type.
   1.287 +	* 
   1.288 +	* @return The owner type. */
   1.289 +	IMPORT_C TCertificateOwnerType CertificateOwnerType() const;
   1.290 +
   1.291 +	/** Gets the size of the certificate.
   1.292 +	* 
   1.293 +	* Note that this function must be called so that the correct size of descriptor 
   1.294 +	* can be allocated when retrieving the certificate (with MCertStore::Retrieve()).
   1.295 +	* 
   1.296 +	* @return The size of the certificate. */
   1.297 +	IMPORT_C TInt Size() const;
   1.298 +
   1.299 +	/** Gets a handle for the object.
   1.300 +	* 
   1.301 +	* The primary purpose of the handle is to allow token objects to be 'passed' 
   1.302 +	* between processes.
   1.303 +	* 
   1.304 +	* @return	A handle for the object. 
   1.305 +	* @see TCTTokenObjectHandle */
   1.306 +	IMPORT_C TCTTokenObjectHandle Handle() const;
   1.307 +
   1.308 +	/** Whether the certificate is deletable.
   1.309 +	* 
   1.310 +	* @return	ETrue if it is possible to delete the certificate; EFalse, otherwise. */
   1.311 +	IMPORT_C TBool IsDeletable() const;
   1.312 +
   1.313 +	/** Gets the hash of the issuer's DN.
   1.314 +	* 
   1.315 +	* @return	The hash of the issuer's DN, or NULL if not known. */
   1.316 +	IMPORT_C const TDesC8* IssuerHash() const;
   1.317 +
   1.318 + public:	
   1.319 +  // from MCTTokenObject
   1.320 +	/** Gets the object's human-readable label.
   1.321 +	* 
   1.322 +	* @return	The object's human-readable label.
   1.323 +	* @see MCTTokenObject::Label()*/
   1.324 +	virtual const TDesC& Label() const;
   1.325 +
   1.326 +	/** Gets a reference to the associated token.
   1.327 +	* 
   1.328 +	* @return	A reference to the associated token.
   1.329 +	* @see MCTTokenObject::Token()*/
   1.330 +	virtual MCTToken& Token() const;
   1.331 +
   1.332 +	/** Gets a UID representing the type of the token object.
   1.333 +	* 
   1.334 +	* The function overrides MCTTokenObject::Type().
   1.335 +	* 
   1.336 +	* The meanings of possible UIDs should be documented in the documentation for 
   1.337 +	* the interface that returns them.
   1.338 +	* 
   1.339 +	* @return	A UID representing the type of the token object; this implementation 
   1.340 +	* 			returns KCTObjectCertInfo.
   1.341 +	* @see MCTTokenObject::Type() */
   1.342 +	virtual TUid Type() const;
   1.343 +	
   1.344 +	// Compares 2 cert infos
   1.345 +	/** Compares this certificate information object with a specified Certificate 
   1.346 +	* Information object for equality.
   1.347 +	* 
   1.348 +	* @param aCertInfo	The certificate information object to be compared.
   1.349 +	* @return			ETrue, if they are the same; EFalse, otherwise. */
   1.350 +	IMPORT_C TBool operator ==(const CCTCertInfo& aCertInfo) const;
   1.351 +
   1.352 +	/** Sets the certificate Id.
   1.353 +	* 
   1.354 +	* @param aCertId The certificate Id.*/
   1.355 +	IMPORT_C void SetCertificateId(TInt aCertId);
   1.356 +
   1.357 + protected:
   1.358 +	IMPORT_C virtual ~CCTCertInfo();
   1.359 +	
   1.360 + private:
   1.361 +	CCTCertInfo(MCTToken& aToken);
   1.362 +	CCTCertInfo(const TDesC& aLabel, TCertificateFormat aFormat,
   1.363 +				TCertificateOwnerType aCertificateOwnerType, 
   1.364 +				TInt aSize,
   1.365 +				const TKeyIdentifier* aSubjectKeyId,
   1.366 +				const TKeyIdentifier* aIssuerKeyId,
   1.367 +				MCTToken& aToken, TInt aCertificateId,
   1.368 +				TBool aDeletable);
   1.369 +	CCTCertInfo(const CCTCertInfo& aCertInfo);
   1.370 +	void ConstructL(RReadStream& aStream);
   1.371 +	void ConstructL(const TDesC8* aIssuerHash);
   1.372 +	
   1.373 + private:
   1.374 +	const CCTCertInfo& operator=(const CCTCertInfo& aOther);
   1.375 +	
   1.376 + private:	
   1.377 +	MCTToken& iToken;
   1.378 +	};
   1.379 +
   1.380 +#endif