xref: /haiku/src/servers/keystore/Keyring.h (revision 25a7b01d15612846f332751841da3579db313082)
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:
15bec02d0cSMichael Lotz 									Keyring();
16d4d6d123SMichael Lotz 									Keyring(const char* name);
1795eee1a3SMichael Lotz 									~Keyring();
1895eee1a3SMichael Lotz 
Name()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 
23*a82011ffSMichael Lotz 		status_t					Unlock(const BMessage* keyMessage);
24c8ae843fSMichael Lotz 		void						Lock();
25c8ae843fSMichael Lotz 		bool						IsUnlocked() const;
26*a82011ffSMichael Lotz 
27*a82011ffSMichael Lotz 		bool						HasUnlockKey() const;
28*a82011ffSMichael Lotz 		const BMessage&				UnlockKey() const;
29*a82011ffSMichael Lotz 
30*a82011ffSMichael Lotz 		status_t					SetUnlockKey(const BMessage& keyMessage);
31*a82011ffSMichael Lotz 		status_t					RemoveUnlockKey();
3295eee1a3SMichael Lotz 
330778e147SMichael Lotz 		status_t					GetNextApplication(uint32& cookie,
340778e147SMichael Lotz 										BString& signature, BString& path);
35d389650aSMichael Lotz 		status_t					FindApplication(const char* signature,
36d389650aSMichael Lotz 										const char* path, BMessage& appMessage);
37d389650aSMichael Lotz 		status_t					AddApplication(const char* signature,
38d389650aSMichael Lotz 										const BMessage& appMessage);
39d389650aSMichael Lotz 		status_t					RemoveApplication(const char* signature,
40d389650aSMichael Lotz 										const char* path);
41d389650aSMichael Lotz 
4295eee1a3SMichael Lotz 		status_t					FindKey(const BString& identifier,
4395eee1a3SMichael Lotz 										const BString& secondaryIdentifier,
4495eee1a3SMichael Lotz 										bool secondaryIdentifierOptional,
451dd765c9SMichael Lotz 										BMessage* _foundKeyMessage) const;
4695eee1a3SMichael Lotz 		status_t					FindKey(BKeyType type, BKeyPurpose purpose,
4795eee1a3SMichael Lotz 										uint32 index,
481dd765c9SMichael Lotz 										BMessage& _foundKeyMessage) const;
4995eee1a3SMichael Lotz 
5095eee1a3SMichael Lotz 		status_t					AddKey(const BString& identifier,
5195eee1a3SMichael Lotz 										const BString& secondaryIdentifier,
5295eee1a3SMichael Lotz 										const BMessage& keyMessage);
5395eee1a3SMichael Lotz 		status_t					RemoveKey(const BString& identifier,
5495eee1a3SMichael Lotz 										const BMessage& keyMessage);
5595eee1a3SMichael Lotz 
5695eee1a3SMichael Lotz static	int							Compare(const Keyring* one,
5795eee1a3SMichael Lotz 										const Keyring* two);
5895eee1a3SMichael Lotz static	int							Compare(const BString* name,
5995eee1a3SMichael Lotz 										const Keyring* keyring);
6095eee1a3SMichael Lotz 
6195eee1a3SMichael Lotz private:
621b3bb46aSMichael Lotz 		status_t					_EncryptToFlatBuffer();
631b3bb46aSMichael Lotz 		status_t					_DecryptFromFlatBuffer();
641b3bb46aSMichael Lotz 
6595eee1a3SMichael Lotz 		BString						fName;
661b3bb46aSMichael Lotz 		BMallocIO					fFlatBuffer;
6795eee1a3SMichael Lotz 		BMessage					fData;
681b3bb46aSMichael Lotz 		BMessage					fApplications;
69*a82011ffSMichael Lotz 		BMessage					fUnlockKey;
70*a82011ffSMichael Lotz 		bool						fHasUnlockKey;
71c8ae843fSMichael Lotz 		bool						fUnlocked;
726ef5917dSMichael Lotz 		bool						fModified;
7395eee1a3SMichael Lotz };
7495eee1a3SMichael Lotz 
7595eee1a3SMichael Lotz 
7695eee1a3SMichael Lotz #endif // _KEYRING_H
77