williamr@2: /* williamr@2: * Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: * All rights reserved. williamr@2: * This component and the accompanying materials are made available williamr@2: * under the terms of the License "Eclipse Public License v1.0" williamr@2: * which accompanies this distribution, and is available williamr@2: * at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@2: * williamr@2: * Initial Contributors: williamr@2: * Nokia Corporation - initial contribution. williamr@2: * williamr@2: * Contributors: williamr@2: * williamr@2: * Description: williamr@2: * CCTCertInfo.H williamr@2: * williamr@2: */ williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: /** williamr@2: @file williamr@2: @internalTechnology williamr@2: */ williamr@2: williamr@2: #ifndef __CCTCERTINFO_H__ williamr@2: #define __CCTCERTINFO_H__ williamr@2: williamr@2: #include williamr@2: #include williamr@2: williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: williamr@2: /** Mask constants used for serializing iDeletable and iFormat attributes williamr@2: */ williamr@2: const TUint KReadOnlyFlagMask = 128; williamr@2: const TUint KFormatMask = 127; williamr@2: williamr@2: /** The UID of a CertInfo MCTTokenObject. */ williamr@2: const TInt KCTObjectCertInfo = 0x101F50E6; williamr@2: williamr@2: /** The maximum length of a certificate label. */ williamr@2: const TUint32 KMaxCertLabelLength = 64; williamr@2: williamr@2: /** Defines a modifiable buffer descriptor to contain a human-readable certificate label. williamr@2: * williamr@2: * @publishedAll williamr@2: * @released */ williamr@2: typedef TBuf TCertLabel; williamr@2: williamr@2: /** williamr@2: * Mix-in class representnig data about a stored certificate. Provides williamr@2: * implementation of serialization. williamr@2: * williamr@2: * Note that for backward compatibility reasons, the issuer hash is not serialised. williamr@2: * williamr@2: * @internalTechnology williamr@2: */ williamr@2: class MCertInfo williamr@2: { williamr@2: public: williamr@2: // Internalization/Externalization williamr@2: // Externalize. Writes the data out to a stream williamr@2: williamr@2: /** Externalises an object of this class to a write stream. williamr@2: * williamr@2: * The presence of this function means that the standard templated operator<<() williamr@2: * can be used to externalise objects of this class. williamr@2: * williamr@2: * @param aStream Stream to which the object should be externalised. */ williamr@2: IMPORT_C void ExternalizeL(RWriteStream& aStream) const; williamr@2: williamr@2: // Internalize. Reads the data from a stream williamr@2: /** Internalises an object of this class from a read stream. williamr@2: * williamr@2: * The presence of this function means that the standard templated operator>>() williamr@2: * can be used to internalise objects of this class. williamr@2: * williamr@2: * Note that this function has assignment semantics: it replaces the old value williamr@2: * of the object with a new value read from the read stream. williamr@2: * williamr@2: * @param aStream Stream from which the object should be internalised. */ williamr@2: IMPORT_C void InternalizeL(RReadStream& aStream); williamr@2: williamr@2: protected: williamr@2: IMPORT_C MCertInfo(); williamr@2: IMPORT_C MCertInfo(const TDesC& aLabel, williamr@2: TCertificateFormat aFormat, williamr@2: TCertificateOwnerType aCertificateOwnerType, williamr@2: TInt aSize, williamr@2: const TKeyIdentifier* aSubjectKeyId, williamr@2: const TKeyIdentifier* aIssuerKeyId, williamr@2: TInt aCertificateId, williamr@2: TBool aDeletable); williamr@2: IMPORT_C MCertInfo(const MCertInfo& aOther); williamr@2: IMPORT_C ~MCertInfo(); williamr@2: williamr@2: IMPORT_C void ConstructL(const TDesC8* aIssuerHash); williamr@2: williamr@2: const TDesC8* IssuerHash() const; williamr@2: williamr@2: private: williamr@2: TBool Valid() const; williamr@2: const MCertInfo& operator=(const MCertInfo& aOther); williamr@2: williamr@2: protected: williamr@2: TCertLabel iLabel; williamr@2: TInt iCertificateId; williamr@2: TCertificateFormat iFormat; williamr@2: TCertificateOwnerType iCertificateOwnerType; williamr@2: TInt iSize; williamr@2: TKeyIdentifier iSubjectKeyId; williamr@2: TKeyIdentifier iIssuerKeyId; williamr@2: TBool iDeletable; williamr@2: williamr@2: private: williamr@2: HBufC8* iIssuerHash; williamr@2: }; williamr@2: williamr@2: /** Encapsulates information about a stored certificate. williamr@2: * williamr@2: * Objects of this type are usually returned by a certificate store, to allow williamr@2: * a client to query the contents of the store. williamr@2: * williamr@2: * Note that these objects are normally constructed by certificate stores, not williamr@2: * by clients. williamr@2: * williamr@2: * @publishedAll williamr@2: * @released williamr@2: */ williamr@2: class CCTCertInfo : protected CBase, public MCTTokenObject, public MCertInfo williamr@2: { williamr@2: public: williamr@2: /** Construction -- Note that these objects are normally constructed by certificate stores, not by clients. */ williamr@2: williamr@2: /** williamr@2: * @publishedPartner williamr@2: * @released williamr@2: * williamr@2: * Creates the certificate information object by copying from an existing object. williamr@2: * williamr@2: * @param aCertInfo The source certificate information. williamr@2: * @return A pointer to the new certificate information object. williamr@2: * @leave KErrNoMemory There is no memory to construct it. */ williamr@2: IMPORT_C static CCTCertInfo* NewL(const CCTCertInfo& aCertInfo); williamr@2: williamr@2: /** williamr@2: * @publishedPartner williamr@2: * @released williamr@2: * williamr@2: * Creates the certificate information object by copying from an existing object, williamr@2: * and puts a pointer to the new object onto the cleanup stack. williamr@2: * williamr@2: * @param aCertInfo The source certificate information. williamr@2: * @return A pointer to the new certificate information object. williamr@2: * @leave KErrNoMemory There is no memory to construct it. */ williamr@2: IMPORT_C static CCTCertInfo* NewLC(const CCTCertInfo& aCertInfo); williamr@2: williamr@2: /** williamr@2: * @publishedPartner williamr@2: * @released williamr@2: * williamr@2: * Creates the certificate information object from its constituent parts. williamr@2: * williamr@2: * @param aLabel The certificate's label. williamr@2: * @param aFormat The certificate's format. williamr@2: * @param aCertificateOwnerType The owner type. williamr@2: * @param aSize The size of the certificate. williamr@2: * @param aSubjectKeyId The subject key ID. williamr@2: * @param aIssuerKeyId The issuer key ID. williamr@2: * @param aToken The token that the certificate is within. williamr@2: * @param aCertificateId The ID within the object handle. williamr@2: * @param aDeletable The certificate is deletable. williamr@2: * @param aIssuerHash The hash of the DN of the issuer. williamr@2: * @return A pointer to the new certificate information object. williamr@2: * @leave KErrNoMemory There is no memory to construct it.*/ williamr@2: IMPORT_C static CCTCertInfo* NewL(const TDesC& aLabel, TCertificateFormat aFormat, williamr@2: TCertificateOwnerType aCertificateOwnerType, TInt aSize, williamr@2: const TKeyIdentifier* aSubjectKeyId, const TKeyIdentifier* aIssuerKeyId, williamr@2: MCTToken& aToken, TInt aCertificateId, TBool aDeletable, williamr@2: const TDesC8* aIssuerHash = NULL); williamr@2: williamr@2: /** williamr@2: * @publishedPartner williamr@2: * @released williamr@2: * williamr@2: * Creates the certificate information object from its constituent parts. williamr@2: * williamr@2: * @param aLabel The certificate's label. williamr@2: * @param aFormat The certificate's format. williamr@2: * @param aCertificateOwnerType The owner type. williamr@2: * @param aSize The size of the certificate. williamr@2: * @param aSubjectKeyId The subject key ID. williamr@2: * @param aIssuerKeyId The issuer key ID. williamr@2: * @param aToken The token that the certificate is within. williamr@2: * @param aCertificateId The ID within the object handle. williamr@2: * @return A pointer to the new certificate information object. williamr@2: * @leave KErrNoMemory There is no memory to construct it.*/ williamr@2: IMPORT_C static CCTCertInfo* NewL(const TDesC& aLabel, TCertificateFormat aFormat, williamr@2: TCertificateOwnerType aCertificateOwnerType, TInt aSize, williamr@2: const TKeyIdentifier* aSubjectKeyId, const TKeyIdentifier* aIssuerKeyId, williamr@2: MCTToken& aToken, TInt aCertificateId); williamr@2: williamr@2: /** williamr@2: * @publishedPartner williamr@2: * @released williamr@2: * williamr@2: * Creates the certificate information object from its constituent parts, williamr@2: * and puts a pointer to the new object onto the cleanup stack. williamr@2: * williamr@2: * @param aLabel The certificate's label. williamr@2: * @param aFormat The certificate's format. williamr@2: * @param aCertificateOwnerType The owner type. williamr@2: * @param aSize The size of the certificate. williamr@2: * @param aSubjectKeyId The subject key ID. williamr@2: * @param aIssuerKeyId The issuer key ID. williamr@2: * @param aToken The token that the certificate is within. williamr@2: * @param aCertificateId The ID within the object handle. williamr@2: * @param aDeletable The certificate is deletable. williamr@2: * @param aIssuerHash The hash of the issuer's DN. williamr@2: * @return A pointer to the new certificate information object. williamr@2: * @leave KErrNoMemory There is no memory to construct it.*/ williamr@2: IMPORT_C static CCTCertInfo* NewLC(const TDesC& aLabel, TCertificateFormat aFormat, williamr@2: TCertificateOwnerType aCertificateOwnerType, TInt aSize, williamr@2: const TKeyIdentifier* aSubjectKeyId, const TKeyIdentifier* aIssuerKeyId, williamr@2: MCTToken& aToken, TInt aCertificateId, TBool aDeletable, williamr@2: const TDesC8* aIssuerHash = NULL); williamr@2: williamr@2: /** williamr@2: * @publishedPartner williamr@2: * @released williamr@2: * williamr@2: * Creates the certificate information object from its constituent parts, and puts williamr@2: * a pointer to the new object onto the cleanup stack. williamr@2: * williamr@2: * @param aLabel The certificate's label. williamr@2: * @param aFormat The certificate's format. williamr@2: * @param aCertificateOwnerType The owner type. williamr@2: * @param aSize The size of the certificate. williamr@2: * @param aSubjectKeyId The subject key ID. williamr@2: * @param aIssuerKeyId The issuer key ID. williamr@2: * @param aToken The token that the certificate is within. williamr@2: * @param aCertificateId The ID within the object handle. williamr@2: * @return A pointer to the new certificate information object. williamr@2: * @leave KErrNoMemory There is no memory to construct it.*/ williamr@2: IMPORT_C static CCTCertInfo* NewLC(const TDesC& aLabel, TCertificateFormat aFormat, williamr@2: TCertificateOwnerType aCertificateOwnerType, TInt aSize, williamr@2: const TKeyIdentifier* aSubjectKeyId, const TKeyIdentifier* aIssuerKeyId, williamr@2: MCTToken& aToken, TInt aCertificateId); williamr@2: williamr@2: /** williamr@2: * @publishedPartner williamr@2: * @released williamr@2: * williamr@2: * Creates the certificate information object by internalising a previously externalised williamr@2: * one. williamr@2: * williamr@2: * @param aStream The stream from which the object is to be internalised. williamr@2: * @param aToken The token that it is within. williamr@2: * @return A pointer to the new certificate information object. williamr@2: * @leave KErrNoMemory There is no memory to construct it. williamr@2: * @see ExternalizeL williamr@2: * @see InternalizeL */ williamr@2: IMPORT_C static CCTCertInfo* NewL(RReadStream& aStream, MCTToken& aToken); williamr@2: williamr@2: /** williamr@2: * @publishedPartner williamr@2: * @released williamr@2: * williamr@2: * Creates the certificate information object, by internalising a previously externalised williamr@2: * one, and puts a pointer to the new object onto the cleanup stack. williamr@2: * williamr@2: * @param aStream The stream from which the object is to be internalised. williamr@2: * @param aToken The token that it is within. williamr@2: * @return A pointer to the new certificate information object. williamr@2: * @leave KErrNoMemory There is no memory to construct it. williamr@2: * @see ExternalizeL williamr@2: * @see InternalizeL */ williamr@2: IMPORT_C static CCTCertInfo* NewLC(RReadStream& aStream, MCTToken& aToken); williamr@2: williamr@2: /** Gets the subject key ID. williamr@2: * williamr@2: * @return A reference to a key identifier object. */ williamr@2: IMPORT_C const TKeyIdentifier& SubjectKeyId() const; williamr@2: williamr@2: /** Gets the issuer key ID. williamr@2: * williamr@2: * @return A reference to a key identifier object. */ williamr@2: IMPORT_C const TKeyIdentifier& IssuerKeyId() const; williamr@2: williamr@2: /** Gets the certificate format. williamr@2: * williamr@2: * @return The certificate format. */ williamr@2: IMPORT_C TCertificateFormat CertificateFormat() const; williamr@2: williamr@2: /** Gets the owner type. williamr@2: * williamr@2: * @return The owner type. */ williamr@2: IMPORT_C TCertificateOwnerType CertificateOwnerType() const; williamr@2: williamr@2: /** Gets the size of the certificate. williamr@2: * williamr@2: * Note that this function must be called so that the correct size of descriptor williamr@2: * can be allocated when retrieving the certificate (with MCertStore::Retrieve()). williamr@2: * williamr@2: * @return The size of the certificate. */ williamr@2: IMPORT_C TInt Size() const; williamr@2: williamr@2: /** Gets a handle for the object. williamr@2: * williamr@2: * The primary purpose of the handle is to allow token objects to be 'passed' williamr@2: * between processes. williamr@2: * williamr@2: * @return A handle for the object. williamr@2: * @see TCTTokenObjectHandle */ williamr@2: IMPORT_C TCTTokenObjectHandle Handle() const; williamr@2: williamr@2: /** Whether the certificate is deletable. williamr@2: * williamr@2: * @return ETrue if it is possible to delete the certificate; EFalse, otherwise. */ williamr@2: IMPORT_C TBool IsDeletable() const; williamr@2: williamr@2: /** Gets the hash of the issuer's DN. williamr@2: * williamr@2: * @return The hash of the issuer's DN, or NULL if not known. */ williamr@2: IMPORT_C const TDesC8* IssuerHash() const; williamr@2: williamr@2: public: williamr@2: // from MCTTokenObject williamr@2: /** Gets the object's human-readable label. williamr@2: * williamr@2: * @return The object's human-readable label. williamr@2: * @see MCTTokenObject::Label()*/ williamr@2: virtual const TDesC& Label() const; williamr@2: williamr@2: /** Gets a reference to the associated token. williamr@2: * williamr@2: * @return A reference to the associated token. williamr@2: * @see MCTTokenObject::Token()*/ williamr@2: virtual MCTToken& Token() const; williamr@2: williamr@2: /** Gets a UID representing the type of the token object. williamr@2: * williamr@2: * The function overrides MCTTokenObject::Type(). williamr@2: * williamr@2: * The meanings of possible UIDs should be documented in the documentation for williamr@2: * the interface that returns them. williamr@2: * williamr@2: * @return A UID representing the type of the token object; this implementation williamr@2: * returns KCTObjectCertInfo. williamr@2: * @see MCTTokenObject::Type() */ williamr@2: virtual TUid Type() const; williamr@2: williamr@2: // Compares 2 cert infos williamr@2: /** Compares this certificate information object with a specified Certificate williamr@2: * Information object for equality. williamr@2: * williamr@2: * @param aCertInfo The certificate information object to be compared. williamr@2: * @return ETrue, if they are the same; EFalse, otherwise. */ williamr@2: IMPORT_C TBool operator ==(const CCTCertInfo& aCertInfo) const; williamr@2: williamr@2: /** Sets the certificate Id. williamr@2: * williamr@2: * @param aCertId The certificate Id.*/ williamr@2: IMPORT_C void SetCertificateId(TInt aCertId); williamr@2: williamr@2: protected: williamr@2: IMPORT_C virtual ~CCTCertInfo(); williamr@2: williamr@2: private: williamr@2: CCTCertInfo(MCTToken& aToken); williamr@2: CCTCertInfo(const TDesC& aLabel, TCertificateFormat aFormat, williamr@2: TCertificateOwnerType aCertificateOwnerType, williamr@2: TInt aSize, williamr@2: const TKeyIdentifier* aSubjectKeyId, williamr@2: const TKeyIdentifier* aIssuerKeyId, williamr@2: MCTToken& aToken, TInt aCertificateId, williamr@2: TBool aDeletable); williamr@2: CCTCertInfo(const CCTCertInfo& aCertInfo); williamr@2: void ConstructL(RReadStream& aStream); williamr@2: void ConstructL(const TDesC8* aIssuerHash); williamr@2: williamr@2: private: williamr@2: const CCTCertInfo& operator=(const CCTCertInfo& aOther); williamr@2: williamr@2: private: williamr@2: MCTToken& iToken; williamr@2: }; williamr@2: williamr@2: #endif