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