os/security/cryptoservices/certificateandkeymgmt/tadditionalstores/test1certstore.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) 1998-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  @internalTechnology
    22 */
    23 
    24 #ifndef __TEST1CERTSTORE_H__
    25 #define __TEST1CERTSTORE_H__
    26 
    27 #include <s32file.h>
    28 #include <e32std.h>
    29 #include <ct.h>
    30 #include <mctwritablecertstore.h>
    31 #include <unifiedkeystore.h>
    32 
    33 #include "test1certstoretoken.h"
    34 
    35 #define CACERTS2 0
    36 
    37 class CFileCertStoreMapping;
    38 class CFileCertStoreMappings;
    39 
    40 /**
    41  * This class implements a certificate store which is stored on a file on the device.
    42  *
    43  * CTest1CertStore initialization.
    44  * NewL and NewLC call the constructor and ConstructL. The constructor does nothing
    45  * except initializing to 0. ConstructL connects to fs, then calls
    46  * OpenStoreL, then RestoreL and then sets the values of iStoreInfo.
    47  * OpenStoreL opens the store ad copies it from the ROM if necessary.
    48  * RestoreL() 
    49  */
    50 class CTest1CertStore : public CActive, public MCTWritableCertStore
    51 	{
    52 public:
    53 	static CTest1CertStore* NewL(RFs& aFs, CTest1CertStoreToken& aToken, 
    54 		const TDesC& aFileName,	TFileMode aMode);
    55 
    56 public:	// from MCTTokenInterface
    57 	virtual MCTToken& Token();
    58 protected:	// from MCTTokenInterface
    59 	virtual void DoRelease();
    60 
    61 
    62 public:	// from MCTCertStore
    63 	virtual void List(RMPointerArray<CCTCertInfo>& aCerts, 
    64 		const CCertAttributeFilter& aFilter, TRequestStatus& aStatus);
    65 	virtual void CancelList();
    66 	virtual void GetCert(CCTCertInfo*& aCertInfo, const TCTTokenObjectHandle& aHandle,
    67 		TRequestStatus& aStatus);
    68 	virtual void CancelGetCert();
    69 	virtual void Applications(const CCTCertInfo& aCertInfo, RArray<TUid>& aApplications,
    70 		TRequestStatus& aStatus); 
    71 	virtual void CancelApplications();
    72 	virtual void IsApplicable(const CCTCertInfo& aCertInfo, TUid aApplication, 
    73 		TBool& aIsApplicable, TRequestStatus& aStatus);
    74 	virtual void CancelIsApplicable();
    75 	virtual void Trusted(const CCTCertInfo& aCertInfo, TBool& aTrusted, 
    76 		TRequestStatus& aStatus);
    77 	virtual void CancelTrusted();
    78 
    79 	// this could be asynch or sync depending on state of compile flag CERTSTORE_SOFTWARE_ASYNCH
    80 	virtual void Retrieve(const CCTCertInfo& aCertInfo, TDes8& aEncodedCert,
    81 		TRequestStatus& aStatus);
    82 	virtual void CancelRetrieve();
    83 	virtual void Capabilities(const CCTCertInfo& aCertInfo, TCapabilitySet& aCapbilitiesOut,
    84 							  TRequestStatus& aStatus);
    85 	virtual void CancelCapabilities();
    86 	virtual void IsMandatory(const CCTCertInfo& aCertInfo, TBool& aMandatoryOut,
    87 							 TRequestStatus& aStatus);
    88 	virtual void CancelIsMandatory();
    89 
    90 public:	// from MCTWritableCertStore
    91 	virtual void Add(const TDesC& aLabel, TCertificateFormat aFormat,
    92 		TCertificateOwnerType aCertificateOwnerType, 
    93 		const TKeyIdentifier* aSubjectKeyId, const TKeyIdentifier* aIssuerKeyId,
    94 		const TDesC8& aCert, TRequestStatus& aStatus);
    95 	virtual void CancelAdd();
    96 	virtual void Remove(const CCTCertInfo& aCertInfo, TRequestStatus& aStatus);
    97 	virtual void CancelRemove();
    98 	virtual void SetApplicability(const CCTCertInfo& aCertInfo, 
    99 		const RArray<TUid>& aApplications, TRequestStatus &aStatus);
   100 	virtual void CancelSetApplicability();
   101 	virtual void SetTrust(const CCTCertInfo& aCertInfo, TBool aTrusted, 
   102 		TRequestStatus& aStatus);
   103 	virtual void CancelSetTrust();
   104 	virtual void SetCapabilities(const CCTCertInfo& aCertInfo, const TCapabilitySet& aCapabilities, 
   105 								 TRequestStatus& aStatus);
   106 	virtual void CancelSetCapabilities();
   107 	virtual void SetMandatory(const CCTCertInfo& aCertInfo, TBool aMandatory,
   108 							  TRequestStatus& aStatus);
   109 	virtual void CancelSetMandatory();
   110 
   111 private:
   112 	virtual ~CTest1CertStore();
   113 	void DoSetApplicabilityL(const CCTCertInfo& aCertInfo, 
   114 		const RArray<TUid>& aApplications);
   115 	void DoSetTrustL(const CCTCertInfo& aCertInfo, 
   116 		TBool aTrusted);
   117 	CTest1CertStore(CTest1CertStoreToken& aToken, RFs& aFs);
   118 	void ConstructL(const TDesC& aFileName, TFileMode aMode);
   119 	static void RevertStore(TAny* aStore);
   120 	static void DeleteFile(TAny* aThis);
   121 	void RestoreL();
   122 	CPermanentFileStore* OpenStoreL(const TDesC& aFileName, TFileMode aMode);
   123 	CPermanentFileStore* OpenStoreLC(const TDesC& aFileName, TFileMode aMode);
   124 
   125 
   126 	//
   127 //	void AddCACertL(const CCertificate& aCert, const TDesC& aLabel, TCertificateFormat aFormat);
   128 //	void AddUserCertL(const CCertificate& aCert, const TDesC& aLabel, TCertificateFormat aFormat, 
   129 //		const TKeyIdentifier& aIssuerKeyHash, const TKeyIdentifier& aSubjectKeyHash);
   130 	void AddUserCertURLL(const TDesC8& aCert, const TDesC& aLabel,
   131 		const TKeyIdentifier& aIssuerKeyHash, const TKeyIdentifier& aSubjectKeyHash);
   132 //	void AddCertL(CCTCertInfo* aCertInfo, const CCertificate& aCert, CFileCertStoreMappings& aMappings);
   133 	void AddCertL(CCTCertInfo* aCertInfo, const TDesC8& aCert, CFileCertStoreMappings& aMappings);
   134 	void DoRemoveL(const CCTCertInfo& aCertInfo);
   135 	void DoLoadL(TDes8& aCertificate, CFileCertStoreMapping& aMapping) const;
   136 	void DoGetUserCertsL(RPointerArray<CCTCertInfo>& aCertInfos,
   137 		const CCertAttributeFilter& aFilter) const;
   138 	void UpdateStoreL();
   139 	void DoAddL(const TDesC& aLabel, TCertificateFormat aFormat,
   140 		TCertificateOwnerType aCertificateOwnerType, const TKeyIdentifier* aSubjectKeyId,
   141 		const TKeyIdentifier* aIssuerKeyId,const TDesC8& aCert);
   142 
   143 	// perform the retrieval synchronously
   144 	void RetrieveNow(const CCTCertInfo& aCertInfo,TDes8& aCertificate,TRequestStatus& aStatus);
   145 
   146 private:
   147 	void RunL();
   148 	void DoCancel();
   149 
   150 private:
   151 	enum TState
   152 		{
   153 		EGetKeyInfos,
   154 		EList,
   155 		ERetrieve
   156 		};
   157 
   158 	//
   159 private:
   160 	CTest1CertStoreToken& iToken;
   161 
   162 	RFile iFile;
   163 	RFs& iFs;
   164 	CPermanentFileStore* iStore;
   165 
   166 	/**
   167 	 * The list of certificates contained in the store.
   168 	 */
   169 	CFileCertStoreMappings* iCerts;
   170 
   171 	TState iState;
   172 	TRequestStatus* iOriginalRequestStatus;
   173 	RPointerArray<CCTCertInfo>* iCertInfos;
   174 	const CCertAttributeFilter* iFilter;
   175 	TCTKeyAttributeFilter iKeyFilter;
   176 	RMPointerArray<CCTKeyInfo> iKeyInfos;
   177 	CUnifiedKeyStore* iUnifiedKeyStore;
   178 	
   179 	// used for asynchronous certificate retrieval
   180 	const CCTCertInfo* iAsynchCertInfo;
   181 	TDes8* iAsynchCertificate;
   182 	};
   183 
   184 #endif