xref: /haiku/headers/os/app/KeyStore.h (revision f8ccc323268f9ad9f2925d06ac5bf281395ca26a)
13b3884d9SMichael Lotz /*
23b3884d9SMichael Lotz  * Copyright 2011, Haiku, Inc.
33b3884d9SMichael Lotz  * Distributed under the terms of the MIT License.
43b3884d9SMichael Lotz  */
53b3884d9SMichael Lotz #ifndef _KEY_STORE_H
63b3884d9SMichael Lotz #define _KEY_STORE_H
73b3884d9SMichael Lotz 
83b3884d9SMichael Lotz 
93b3884d9SMichael Lotz #include <Key.h>
103b3884d9SMichael Lotz 
113b3884d9SMichael Lotz 
123b3884d9SMichael Lotz class BKeyStore {
133b3884d9SMichael Lotz public:
143b3884d9SMichael Lotz 								BKeyStore();
153b3884d9SMichael Lotz 	virtual						~BKeyStore();
163b3884d9SMichael Lotz 
173b3884d9SMichael Lotz // TODO: -> GetNextPassword() - there can always be more than one key
183b3884d9SMichael Lotz // with the same identifier/secondaryIdentifier (ie. different username)
1951ab46a8SMichael Lotz 			status_t			GetKey(BKeyType type, const char* identifier,
2051ab46a8SMichael Lotz 									BKey& key);
2151ab46a8SMichael Lotz 			status_t			GetKey(BKeyType type, const char* identifier,
223b3884d9SMichael Lotz 									const char* secondaryIdentifier, BKey& key);
2351ab46a8SMichael Lotz 			status_t			GetKey(BKeyType type, const char* identifier,
243b3884d9SMichael Lotz 									const char* secondaryIdentifier,
253b3884d9SMichael Lotz 									bool secondaryIdentifierOptional,
263b3884d9SMichael Lotz 									BKey& key);
273b3884d9SMichael Lotz 
28dc1acef8SMichael Lotz 			status_t			GetKey(const char* keyring,
2951ab46a8SMichael Lotz 									BKeyType type, const char* identifier,
3051ab46a8SMichael Lotz 									BKey& key);
31dc1acef8SMichael Lotz 			status_t			GetKey(const char* keyring,
3251ab46a8SMichael Lotz 									BKeyType type, const char* identifier,
333b3884d9SMichael Lotz 									const char* secondaryIdentifier, BKey& key);
34dc1acef8SMichael Lotz 			status_t			GetKey(const char* keyring,
3551ab46a8SMichael Lotz 									BKeyType type, const char* identifier,
363b3884d9SMichael Lotz 									const char* secondaryIdentifier,
373b3884d9SMichael Lotz 									bool secondaryIdentifierOptional,
383b3884d9SMichael Lotz 									BKey& key);
393b3884d9SMichael Lotz 
40b7398289SMichael Lotz 			status_t			AddKey(const BKey& key);
41b7398289SMichael Lotz 			status_t			AddKey(const char* keyring, const BKey& key);
42b7398289SMichael Lotz 			status_t			RemoveKey(const BKey& key);
43b7398289SMichael Lotz 			status_t			RemoveKey(const char* keyring, const BKey& key);
443b3884d9SMichael Lotz 
45dc1acef8SMichael Lotz 			status_t			GetNextKey(uint32& cookie, BKey& key);
46dc1acef8SMichael Lotz 			status_t			GetNextKey(BKeyType type, BKeyPurpose purpose,
473b3884d9SMichael Lotz 									uint32& cookie, BKey& key);
48dc1acef8SMichael Lotz 			status_t			GetNextKey(const char* keyring,
493b3884d9SMichael Lotz 									uint32& cookie, BKey& key);
50dc1acef8SMichael Lotz 			status_t			GetNextKey(const char* keyring,
51dc1acef8SMichael Lotz 									BKeyType type, BKeyPurpose purpose,
52dc1acef8SMichael Lotz 									uint32& cookie, BKey& key);
533b3884d9SMichael Lotz 
543b3884d9SMichael Lotz 			// Keyrings
553b3884d9SMichael Lotz 
56b7398289SMichael Lotz 			status_t			AddKeyring(const char* keyring,
573b3884d9SMichael Lotz 									const BKey& key);
58b7398289SMichael Lotz 			status_t			RemoveKeyring(const char* keyring);
593b3884d9SMichael Lotz 
603b3884d9SMichael Lotz 			status_t			GetNextKeyring(uint32& cookie,
613b3884d9SMichael Lotz 									BString& keyring);
623b3884d9SMichael Lotz 
633b3884d9SMichael Lotz 			// Master key
643b3884d9SMichael Lotz 
65dc1acef8SMichael Lotz 			status_t			SetMasterKey(const BKey& key);
66dc1acef8SMichael Lotz 			status_t			RemoveMasterKey();
673b3884d9SMichael Lotz 
683b3884d9SMichael Lotz 			status_t			AddKeyringToMaster(const char* keyring);
693b3884d9SMichael Lotz 			status_t			RemoveKeyringFromMaster(const char* keyring);
703b3884d9SMichael Lotz 
713b3884d9SMichael Lotz 			status_t			GetNextMasterKeyring(uint32& cookie,
723b3884d9SMichael Lotz 									BString& keyring);
733b3884d9SMichael Lotz 
74c8ae843fSMichael Lotz 			// Locking
753b3884d9SMichael Lotz 
76c8ae843fSMichael Lotz 			bool				IsKeyringUnlocked(const char* keyring);
77c8ae843fSMichael Lotz 			status_t			LockKeyring(const char* keyring);
78c8ae843fSMichael Lotz 			status_t			LockMasterKeyring();
793b3884d9SMichael Lotz 
80dc1acef8SMichael Lotz 			// Applications
81dc1acef8SMichael Lotz 
82*f8ccc323SMichael Lotz 			status_t			GetNextApplication(uint32& cookie,
8364ca113fSMichael Lotz 									BString& signature) const;
84*f8ccc323SMichael Lotz 			status_t			GetNextApplication(const char* keyring,
85*f8ccc323SMichael Lotz 									uint32& cookie, BString& signature) const;
86*f8ccc323SMichael Lotz 			status_t			RemoveApplication(const char* signature);
8764ca113fSMichael Lotz 			status_t			RemoveApplication(const char* keyring,
88*f8ccc323SMichael Lotz 									const char* signature);
89dc1acef8SMichael Lotz 
903b3884d9SMichael Lotz 			// Service functions
913b3884d9SMichael Lotz 
92dc1acef8SMichael Lotz 			status_t			GeneratePassword(BPasswordKey& password,
93dc1acef8SMichael Lotz 									size_t length, uint32 flags);
94dc1acef8SMichael Lotz 			float				PasswordStrength(const char* password);
951c399649SMichael Lotz 
961c399649SMichael Lotz private:
971c399649SMichael Lotz 			status_t			_SendKeyMessage(BMessage& message,
981c399649SMichael Lotz 									BMessage* reply) const;
993b3884d9SMichael Lotz };
1003b3884d9SMichael Lotz 
1013b3884d9SMichael Lotz 
1023b3884d9SMichael Lotz #endif	// _KEY_STORE_H
103