xref: /haiku/src/servers/keystore/Keyring.h (revision 13581b3d2a71545960b98fefebc5225b5bf29072)
1 /*
2  * Copyright 2012, Michael Lotz, mmlr@mlotz.ch. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _KEYRING_H
6 #define _KEYRING_H
7 
8 
9 #include <Key.h>
10 #include <Message.h>
11 
12 
13 class Keyring {
14 public:
15 									Keyring();
16 									Keyring(const char* name);
17 									~Keyring();
18 
19 		const char*					Name() const { return fName; }
20 		status_t					ReadFromMessage(const BMessage& message);
21 		status_t					WriteToMessage(BMessage& message);
22 
23 		status_t					Unlock(const BMessage* keyMessage);
24 		void						Lock();
25 		bool						IsUnlocked() const;
26 
27 		bool						HasUnlockKey() const;
28 		const BMessage&				UnlockKey() const;
29 
30 		status_t					SetUnlockKey(const BMessage& keyMessage);
31 		status_t					RemoveUnlockKey();
32 
33 		status_t					GetNextApplication(uint32& cookie,
34 										BString& signature, BString& path);
35 		status_t					FindApplication(const char* signature,
36 										const char* path, BMessage& appMessage);
37 		status_t					AddApplication(const char* signature,
38 										const BMessage& appMessage);
39 		status_t					RemoveApplication(const char* signature,
40 										const char* path);
41 
42 		status_t					FindKey(const BString& identifier,
43 										const BString& secondaryIdentifier,
44 										bool secondaryIdentifierOptional,
45 										BMessage* _foundKeyMessage) const;
46 		status_t					FindKey(BKeyType type, BKeyPurpose purpose,
47 										uint32 index,
48 										BMessage& _foundKeyMessage) const;
49 
50 		status_t					AddKey(const BString& identifier,
51 										const BString& secondaryIdentifier,
52 										const BMessage& keyMessage);
53 		status_t					RemoveKey(const BString& identifier,
54 										const BMessage& keyMessage);
55 
56 static	int							Compare(const Keyring* one,
57 										const Keyring* two);
58 static	int							Compare(const BString* name,
59 										const Keyring* keyring);
60 
61 private:
62 		status_t					_EncryptToFlatBuffer();
63 		status_t					_DecryptFromFlatBuffer();
64 
65 		BString						fName;
66 		BMallocIO					fFlatBuffer;
67 		BMessage					fData;
68 		BMessage					fApplications;
69 		BMessage					fUnlockKey;
70 		bool						fHasUnlockKey;
71 		bool						fUnlocked;
72 		bool						fModified;
73 };
74 
75 
76 #endif // _KEYRING_H
77