xref: /haiku/src/servers/keystore/Keyring.h (revision bec02d0c2f483a804eb0b833d099b85b3660cdb0)
195eee1a3SMichael Lotz /*
295eee1a3SMichael Lotz  * Copyright 2012, Michael Lotz, mmlr@mlotz.ch. All Rights Reserved.
395eee1a3SMichael Lotz  * Distributed under the terms of the MIT License.
495eee1a3SMichael Lotz  */
595eee1a3SMichael Lotz #ifndef _KEYRING_H
695eee1a3SMichael Lotz #define _KEYRING_H
795eee1a3SMichael Lotz 
895eee1a3SMichael Lotz 
995eee1a3SMichael Lotz #include <Key.h>
1095eee1a3SMichael Lotz #include <Message.h>
1195eee1a3SMichael Lotz 
1295eee1a3SMichael Lotz 
1395eee1a3SMichael Lotz class Keyring {
1495eee1a3SMichael Lotz public:
15*bec02d0cSMichael Lotz 									Keyring();
16d4d6d123SMichael Lotz 									Keyring(const char* name);
1795eee1a3SMichael Lotz 									~Keyring();
1895eee1a3SMichael Lotz 
1995eee1a3SMichael Lotz 		const char*					Name() const { return fName; }
201b3bb46aSMichael Lotz 		status_t					ReadFromMessage(const BMessage& message);
211b3bb46aSMichael Lotz 		status_t					WriteToMessage(BMessage& message);
2295eee1a3SMichael Lotz 
23c8ae843fSMichael Lotz 		status_t					Unlock(const BMessage& keyMessage);
24c8ae843fSMichael Lotz 		void						Lock();
25c8ae843fSMichael Lotz 		bool						IsUnlocked() const;
261dd765c9SMichael Lotz 		const BMessage&				KeyMessage() const;
2795eee1a3SMichael Lotz 
280778e147SMichael Lotz 		status_t					GetNextApplication(uint32& cookie,
290778e147SMichael Lotz 										BString& signature, BString& path);
30d389650aSMichael Lotz 		status_t					FindApplication(const char* signature,
31d389650aSMichael Lotz 										const char* path, BMessage& appMessage);
32d389650aSMichael Lotz 		status_t					AddApplication(const char* signature,
33d389650aSMichael Lotz 										const BMessage& appMessage);
34d389650aSMichael Lotz 		status_t					RemoveApplication(const char* signature,
35d389650aSMichael Lotz 										const char* path);
36d389650aSMichael Lotz 
3795eee1a3SMichael Lotz 		status_t					FindKey(const BString& identifier,
3895eee1a3SMichael Lotz 										const BString& secondaryIdentifier,
3995eee1a3SMichael Lotz 										bool secondaryIdentifierOptional,
401dd765c9SMichael Lotz 										BMessage* _foundKeyMessage) const;
4195eee1a3SMichael Lotz 		status_t					FindKey(BKeyType type, BKeyPurpose purpose,
4295eee1a3SMichael Lotz 										uint32 index,
431dd765c9SMichael Lotz 										BMessage& _foundKeyMessage) const;
4495eee1a3SMichael Lotz 
4595eee1a3SMichael Lotz 		status_t					AddKey(const BString& identifier,
4695eee1a3SMichael Lotz 										const BString& secondaryIdentifier,
4795eee1a3SMichael Lotz 										const BMessage& keyMessage);
4895eee1a3SMichael Lotz 		status_t					RemoveKey(const BString& identifier,
4995eee1a3SMichael Lotz 										const BMessage& keyMessage);
5095eee1a3SMichael Lotz 
5195eee1a3SMichael Lotz static	int							Compare(const Keyring* one,
5295eee1a3SMichael Lotz 										const Keyring* two);
5395eee1a3SMichael Lotz static	int							Compare(const BString* name,
5495eee1a3SMichael Lotz 										const Keyring* keyring);
5595eee1a3SMichael Lotz 
5695eee1a3SMichael Lotz private:
571b3bb46aSMichael Lotz 		status_t					_EncryptToFlatBuffer();
581b3bb46aSMichael Lotz 		status_t					_DecryptFromFlatBuffer();
591b3bb46aSMichael Lotz 
6095eee1a3SMichael Lotz 		BString						fName;
611b3bb46aSMichael Lotz 		BMallocIO					fFlatBuffer;
6295eee1a3SMichael Lotz 		BMessage					fData;
631b3bb46aSMichael Lotz 		BMessage					fApplications;
641dd765c9SMichael Lotz 		BMessage					fKeyMessage;
65c8ae843fSMichael Lotz 		bool						fUnlocked;
666ef5917dSMichael Lotz 		bool						fModified;
6795eee1a3SMichael Lotz };
6895eee1a3SMichael Lotz 
6995eee1a3SMichael Lotz 
7095eee1a3SMichael Lotz #endif // _KEYRING_H
71