15 * Implements CFileKeyData and CFileKeyDataManager |
15 * Implements CFileKeyData and CFileKeyDataManager |
16 * |
16 * |
17 */ |
17 */ |
18 |
18 |
19 |
19 |
20 |
|
21 |
|
22 /** |
20 /** |
23 @file |
21 @file |
24 @internalTechnology |
22 @internalTechnology |
25 */ |
23 */ |
26 |
24 |
27 #ifndef __CKEYDATAMANAGER_H__ |
25 #ifndef __CKEYDATAMANAGER_H__ |
28 #define __CKEYDATAMANAGER_H__ |
26 #define __CKEYDATAMANAGER_H__ |
29 |
27 |
30 #include <s32file.h> |
28 #include <s32file.h> |
31 #include <tcttokenobjecthandle.h> |
29 #include <ct/tcttokenobjecthandle.h> |
32 #include <ct.h> |
30 #include <ct.h> |
33 |
31 |
34 class CKeyInfo; |
32 class CKeyInfo; |
35 class CPassphraseManager; |
33 class CPassphraseManager; |
36 class CPassphrase; |
34 class CPassphrase; |
|
35 |
|
36 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
37 #include <authserver/authtypes.h> |
|
38 #include <e32property.h> |
|
39 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
40 |
|
41 #ifdef KEYTOOL |
|
42 #include <authserver/authtypes.h> |
|
43 #include <e32property.h> |
|
44 #endif // KEYTOOL |
37 |
45 |
38 /** |
46 /** |
39 * Server side in-memory representation of a key for file key store management |
47 * Server side in-memory representation of a key for file key store management |
40 * purposes. Objects of this type are stored in an in-memory array for quick |
48 * purposes. Objects of this type are stored in an in-memory array for quick |
41 * keystore lookup. |
49 * keystore lookup. |
46 /// Create a new key data object |
54 /// Create a new key data object |
47 static CFileKeyData* NewLC(TInt aObjectId, const TDesC& aLabel, TStreamId aInfoData, |
55 static CFileKeyData* NewLC(TInt aObjectId, const TDesC& aLabel, TStreamId aInfoData, |
48 TStreamId aPassphraseId, TStreamId aPublicData, TStreamId aPrivateData); |
56 TStreamId aPassphraseId, TStreamId aPublicData, TStreamId aPrivateData); |
49 /// Read a key data object from a stream |
57 /// Read a key data object from a stream |
50 static CFileKeyData* NewL(RStoreReadStream& aReadStream); |
58 static CFileKeyData* NewL(RStoreReadStream& aReadStream); |
|
59 |
|
60 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
61 static CFileKeyData* NewLC( TInt aObjectId, const TDesC& aLabel, |
|
62 TStreamId aInfoData, TStreamId aPublicData, |
|
63 TStreamId aPrivateData, AuthServer::TIdentityId aIdentityId); |
|
64 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
65 |
|
66 #ifdef KEYTOOL |
|
67 static CFileKeyData* CreateOldKeyL(RStoreReadStream& aReadStream); |
|
68 #endif // KEYTOOL |
51 public: |
69 public: |
52 ~CFileKeyData(); |
70 ~CFileKeyData(); |
53 public: |
71 public: |
54 /// Write out the key data to a stream |
72 /// Write out the key data to a stream |
55 void ExternalizeL(RWriteStream&) const; |
73 void ExternalizeL(RWriteStream&) const; |
|
74 #ifdef KEYTOOL |
|
75 void ExternalizeWithAuthL(RWriteStream& aWriteStream) ; |
|
76 #endif // KEYTOOL |
56 public: |
77 public: |
57 inline const TDesC& Label() const; |
78 inline const TDesC& Label() const; |
58 inline TInt32 Handle() const; |
79 inline TInt32 Handle() const; |
59 inline TStreamId InfoDataStreamId() const; |
80 inline TStreamId InfoDataStreamId() const; |
60 inline TStreamId PassphraseStreamId() const; |
81 inline TStreamId PassphraseStreamId() const; |
61 inline TStreamId PublicDataStreamId() const; |
82 inline TStreamId PublicDataStreamId() const; |
62 inline TStreamId PrivateDataStreamId() const; |
83 inline TStreamId PrivateDataStreamId() const; |
|
84 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
85 inline AuthServer::TIdentityId Identity() const; |
|
86 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
87 #ifdef KEYTOOL |
|
88 inline void SetInfoDataStreamId( TStreamId& aInfoDataStreamId ); |
|
89 inline void SetPublicDataStreamId( TStreamId& aPublicDataStreamId ); |
|
90 inline void SetPrivateDataStreamId( TStreamId& aPrivateDataStreamId ); |
|
91 inline AuthServer::TIdentityId Identity() const; |
|
92 #endif // KEYTOOL |
63 private: |
93 private: |
64 CFileKeyData(TInt aObjectId, TStreamId aInfoData, TStreamId aPassphraseId, |
94 CFileKeyData(TInt aObjectId, TStreamId aInfoData, TStreamId aPassphraseId, |
65 TStreamId aPublicData, TStreamId aPrivateData); |
95 TStreamId aPublicData, TStreamId aPrivateData); |
|
96 |
|
97 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
98 CFileKeyData( TInt aObjectId, TStreamId aInfoData, |
|
99 TStreamId aPublicData, TStreamId aPrivateData, |
|
100 AuthServer::TIdentityId aIdentityId); |
|
101 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
102 |
|
103 #ifdef KEYTOOL |
|
104 CFileKeyData( TInt aObjectId, TStreamId aInfoData, |
|
105 TStreamId aPublicData, TStreamId aPrivateData, |
|
106 AuthServer::TIdentityId aIdentityId); |
|
107 #endif // KEYTOOL |
|
108 |
66 CFileKeyData(); |
109 CFileKeyData(); |
67 void ConstructL(const TDesC& aLabel); |
110 void ConstructL(const TDesC& aLabel); |
68 void InternalizeL(RReadStream&); |
111 void InternalizeL(RReadStream&); |
|
112 #ifdef KEYTOOL |
|
113 void InternalizeOldKeyL(RReadStream& aReadStream); |
|
114 #endif // KEYTOOL |
|
115 |
69 private: |
116 private: |
70 TInt iObjectId; ///< Data to identify the key |
117 TInt iObjectId; ///< Data to identify the key |
71 TStreamId iInfoData; ///< ID of stream holding publicly available data for key |
118 TStreamId iInfoData; ///< ID of stream holding publicly available data for key |
72 TStreamId iPassphraseId; ///< ID of stream holding passphrase data (not currently used) |
119 TStreamId iPassphraseId; ///< ID of stream holding passphrase data (not currently used) |
73 TStreamId iPublicKeyData; ///< ID of stream holding public key data |
120 TStreamId iPublicKeyData; ///< ID of stream holding public key data |
74 TStreamId iPrivateKeyData; ///< ID of stream holding private key data |
121 TStreamId iPrivateKeyData; ///< ID of stream holding private key data |
75 HBufC* iLabel; ///< Key label data |
122 HBufC* iLabel; ///< Key label data |
|
123 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
124 AuthServer::TIdentityId iIdentityId; |
|
125 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
126 #ifdef KEYTOOL |
|
127 AuthServer::TIdentityId iIdentityId; |
|
128 #endif // KEYTOOL |
76 }; |
129 }; |
77 |
130 |
78 inline const TDesC& CFileKeyData::Label() const |
131 inline const TDesC& CFileKeyData::Label() const |
79 { |
132 { |
80 return *iLabel; |
133 return *iLabel; |
103 inline TStreamId CFileKeyData::PrivateDataStreamId() const |
156 inline TStreamId CFileKeyData::PrivateDataStreamId() const |
104 { |
157 { |
105 return iPrivateKeyData; |
158 return iPrivateKeyData; |
106 } |
159 } |
107 |
160 |
|
161 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
162 inline AuthServer::TIdentityId CFileKeyData::Identity() const |
|
163 { |
|
164 return iIdentityId; |
|
165 } |
|
166 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
167 |
|
168 #ifdef KEYTOOL |
|
169 inline void CFileKeyData::SetInfoDataStreamId( TStreamId& aInfoDataStreamId ) |
|
170 { |
|
171 iInfoData = aInfoDataStreamId; |
|
172 } |
|
173 |
|
174 inline void CFileKeyData::SetPublicDataStreamId( TStreamId& aPublicDataStreamId ) |
|
175 { |
|
176 iPublicKeyData = aPublicDataStreamId; |
|
177 } |
|
178 |
|
179 inline void CFileKeyData::SetPrivateDataStreamId( TStreamId& aPrivateDataStreamId ) |
|
180 { |
|
181 iPrivateKeyData = aPrivateDataStreamId; |
|
182 } |
|
183 |
|
184 #endif // KEYTOOL |
108 /** |
185 /** |
109 * Access the server file store of all keys and key data. The only class to |
186 * Access the server file store of all keys and key data. The only class to |
110 * access the store, which maintains store integrity When a new key is created, |
187 * access the store, which maintains store integrity When a new key is created, |
111 * it is represented by a CFileKeyData object and added to the array. |
188 * it is represented by a CFileKeyData object and added to the array. |
112 */ |
189 */ |
117 ~CFileKeyDataManager(); |
194 ~CFileKeyDataManager(); |
118 public: |
195 public: |
119 CPassphraseManager* CreatePassphraseManagerLC(); |
196 CPassphraseManager* CreatePassphraseManagerLC(); |
120 void AddL(const CFileKeyData*); |
197 void AddL(const CFileKeyData*); |
121 void RemoveL(TInt aObjectId); |
198 void RemoveL(TInt aObjectId); |
|
199 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
200 TBool IsKeyAlreadyInStore(const TDesC& aKeyLabel, AuthServer::TIdentityId aIdentity) const; |
|
201 #else |
122 TBool IsKeyAlreadyInStore(const TDesC& aKeyLabel) const; |
202 TBool IsKeyAlreadyInStore(const TDesC& aKeyLabel) const; |
|
203 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
123 public: |
204 public: |
124 /// Get the id of the default passphrase, or KNullStreamId if it doesn't exist yet. |
205 /// Get the id of the default passphrase, or KNullStreamId if it doesn't exist yet. |
125 TStreamId DefaultPassphraseId() const; |
206 TStreamId DefaultPassphraseId() const; |
126 /// Create a new key data object for a key create/import and leave it one the cleanup stack |
207 /// Create a new key data object for a key create/import and leave it one the cleanup stack |
127 const CFileKeyData* CreateKeyDataLC(const TDesC& aLabel, TStreamId aPassphrase); |
208 const CFileKeyData* CreateKeyDataLC(const TDesC& aLabel, TStreamId aPassphrase); |
|
209 |
|
210 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
211 const CFileKeyData* CreateKeyDataLC(const TDesC& aLabel, AuthServer::TIdentityId aIdentity); |
|
212 TUint32 CachedIdentity(); |
|
213 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
214 |
128 /// Reads the info data for a given key, returning a new CKeyInfo that's on the cleanup stack |
215 /// Reads the info data for a given key, returning a new CKeyInfo that's on the cleanup stack |
129 CKeyInfo* ReadKeyInfoLC(const CFileKeyData& aKeyData) const; |
216 CKeyInfo* ReadKeyInfoLC(const CFileKeyData& aKeyData) const; |
|
217 |
130 /// Writes key info data for a key |
218 /// Writes key info data for a key |
131 void WriteKeyInfoL(const CFileKeyData& aKeyData, const CKeyInfo& aKeyInfo); |
219 void WriteKeyInfoL(const CFileKeyData& aKeyData, const CKeyInfo& aKeyInfo); |
132 /// Writes key info data and reverts changes to the store if if leaves |
220 /// Writes key info data and reverts changes to the store if if leaves |
133 void SafeWriteKeyInfoL(const CFileKeyData& aKeyData, const CKeyInfo& aKeyInfo); |
221 void SafeWriteKeyInfoL(const CFileKeyData& aKeyData, const CKeyInfo& aKeyInfo); |
134 // Methods for opening data streams for a key |
222 // Methods for opening data streams for a key |
135 void OpenPublicDataStreamLC(const CFileKeyData& aKeyData, RStoreWriteStream& aStream); |
223 void OpenPublicDataStreamLC(const CFileKeyData& aKeyData, RStoreWriteStream& aStream); |
136 void OpenPublicDataStreamLC(const CFileKeyData& aKeyData, RStoreReadStream& aStream) const; |
224 void OpenPublicDataStreamLC(const CFileKeyData& aKeyData, RStoreReadStream& aStream) const; |
|
225 void OpenPrivateDataStreamLC(const CFileKeyData& aKeyData, CPassphrase& aPassphrase, RStoreReadStream& aStream); |
|
226 |
|
227 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
228 void OpenPrivateDataStreamLC(const CFileKeyData& aKeyData, RStoreWriteStream& aStream); |
|
229 void OpenPrivateDataStreamLC(const CFileKeyData& aKeyData, RStoreReadStream& aStream) const; |
|
230 #else |
137 void OpenPrivateDataStreamLC(const CFileKeyData& aKeyData, CPassphrase& aPassphrase, RStoreWriteStream& aStream); |
231 void OpenPrivateDataStreamLC(const CFileKeyData& aKeyData, CPassphrase& aPassphrase, RStoreWriteStream& aStream); |
138 void OpenPrivateDataStreamLC(const CFileKeyData& aKeyData, CPassphrase& aPassphrase, RStoreReadStream& aStream); |
232 |
139 |
233 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
234 |
140 /* |
235 /* |
141 * not currently implemented, but might be someday |
236 * not currently implemented, but might be someday |
142 /// Create a new passphrase by prompting the user and pass back its id. |
237 /// Create a new passphrase by prompting the user and pass back its id. |
143 void CreatePassphrase(CPassphraseManager& aPassMan, TStreamId& aIdOut, TRequestStatus& aStatus); |
238 void CreatePassphrase(CPassphraseManager& aPassMan, TStreamId& aIdOut, TRequestStatus& aStatus); |
144 /// Remove an existing passphrase. Leaves if the passphrase is used by any key. |
239 /// Remove an existing passphrase. Leaves if the passphrase is used by any key. |
166 void CreateStoreInFileL(const TDesC& aFile); |
261 void CreateStoreInFileL(const TDesC& aFile); |
167 private: |
262 private: |
168 void OpenInfoDataStreamLC(const CFileKeyData& aKeyData, RStoreWriteStream&); |
263 void OpenInfoDataStreamLC(const CFileKeyData& aKeyData, RStoreWriteStream&); |
169 static void RevertStore(TAny* aStore); // Cleanupitem |
264 static void RevertStore(TAny* aStore); // Cleanupitem |
170 void WriteKeysToStoreL(); |
265 void WriteKeysToStoreL(); |
|
266 void UpdateStoreL(); |
171 TStreamId CreateWriteStreamL(); |
267 TStreamId CreateWriteStreamL(); |
172 void ReadPassphraseTimeoutL(); |
268 void ReadPassphraseTimeoutL(); |
173 void WritePassphraseTimeoutL(); |
269 void WritePassphraseTimeoutL(); |
174 void CompactStore(); |
270 void CompactStore(); |
|
271 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
272 const HBufC8* DecryptKey(const TDesC8& aEncryptedKey); |
|
273 void WriteAuthDetailsL( RStoreWriteStream& aInfoStream, const CKeyInfo& aKeyInfo ); |
|
274 void ReadAuthDetailsL( RStoreReadStream& aInfoStream, CKeyInfo& aKeyInfo ) const; |
|
275 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
276 |
175 private: |
277 private: |
176 RFile iFile; |
278 RFile iFile; |
177 RFs iFs; |
279 RFs iFs; |
178 CPermanentFileStore* iFileStore; |
280 CPermanentFileStore* iFileStore; |
179 TStreamId iRootStreamId; ///< Root of the store |
281 TStreamId iRootStreamId; ///< Root of the store |
180 TStreamId iInfoStreamId; ///< Stream that contains list of key data |
282 TStreamId iInfoStreamId; ///< Stream that contains list of key data |
|
283 |
|
284 #ifdef SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
285 RProperty iIdentityId; |
|
286 #else |
181 TStreamId iPassStreamId; ///< Stream for the default passphrase |
287 TStreamId iPassStreamId; ///< Stream for the default passphrase |
182 TStreamId iTimeoutStreamId; ///< Stream for timeout data |
288 TStreamId iTimeoutStreamId; ///< Stream for timeout data |
|
289 #endif // SYMBIAN_KEYSTORE_USE_AUTH_SERVER |
|
290 |
183 private: |
291 private: |
184 TInt iKeyIdentifier; |
292 TInt iKeyIdentifier; |
185 RPointerArray<const CFileKeyData> iKeys; ///< In memory representation of keys in the store |
293 RPointerArray<const CFileKeyData> iKeys; ///< In memory representation of keys in the store |
186 TInt iTimeout; ///< The passphrase timeout |
294 TInt iTimeout; ///< The passphrase timeout |
|
295 |
187 }; |
296 }; |
188 |
297 |
189 #endif |
298 #endif |