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 1751ab46a8SMichael Lotz status_t GetKey(BKeyType type, const char* identifier, 1851ab46a8SMichael Lotz BKey& key); 1951ab46a8SMichael Lotz status_t GetKey(BKeyType type, const char* identifier, 203b3884d9SMichael Lotz const char* secondaryIdentifier, BKey& key); 2151ab46a8SMichael Lotz status_t GetKey(BKeyType type, const char* identifier, 223b3884d9SMichael Lotz const char* secondaryIdentifier, 233b3884d9SMichael Lotz bool secondaryIdentifierOptional, 243b3884d9SMichael Lotz BKey& key); 253b3884d9SMichael Lotz 26dc1acef8SMichael Lotz status_t GetKey(const char* keyring, 2751ab46a8SMichael Lotz BKeyType type, const char* identifier, 2851ab46a8SMichael Lotz BKey& key); 29dc1acef8SMichael Lotz status_t GetKey(const char* keyring, 3051ab46a8SMichael Lotz BKeyType type, const char* identifier, 313b3884d9SMichael Lotz const char* secondaryIdentifier, BKey& key); 32dc1acef8SMichael Lotz status_t GetKey(const char* keyring, 3351ab46a8SMichael Lotz BKeyType type, const char* identifier, 343b3884d9SMichael Lotz const char* secondaryIdentifier, 353b3884d9SMichael Lotz bool secondaryIdentifierOptional, 363b3884d9SMichael Lotz BKey& key); 373b3884d9SMichael Lotz 38b7398289SMichael Lotz status_t AddKey(const BKey& key); 39b7398289SMichael Lotz status_t AddKey(const char* keyring, const BKey& key); 40b7398289SMichael Lotz status_t RemoveKey(const BKey& key); 41b7398289SMichael Lotz status_t RemoveKey(const char* keyring, const BKey& key); 423b3884d9SMichael Lotz 43dc1acef8SMichael Lotz status_t GetNextKey(uint32& cookie, BKey& key); 44dc1acef8SMichael Lotz status_t GetNextKey(BKeyType type, BKeyPurpose purpose, 453b3884d9SMichael Lotz uint32& cookie, BKey& key); 46dc1acef8SMichael Lotz status_t GetNextKey(const char* keyring, 473b3884d9SMichael Lotz uint32& cookie, BKey& key); 48dc1acef8SMichael Lotz status_t GetNextKey(const char* keyring, 49dc1acef8SMichael Lotz BKeyType type, BKeyPurpose purpose, 50dc1acef8SMichael Lotz uint32& cookie, BKey& key); 513b3884d9SMichael Lotz 523b3884d9SMichael Lotz // Keyrings 533b3884d9SMichael Lotz 54d4d6d123SMichael Lotz status_t AddKeyring(const char* keyring); 55b7398289SMichael Lotz status_t RemoveKeyring(const char* keyring); 563b3884d9SMichael Lotz 573b3884d9SMichael Lotz status_t GetNextKeyring(uint32& cookie, 583b3884d9SMichael Lotz BString& keyring); 593b3884d9SMichael Lotz 60*4a0460a9SMichael Lotz status_t SetUnlockKey(const char* keyring, 61*4a0460a9SMichael Lotz const BKey& key); 62*4a0460a9SMichael Lotz status_t RemoveUnlockKey(const char* keyring); 633b3884d9SMichael Lotz 64*4a0460a9SMichael Lotz // Master keyring 65*4a0460a9SMichael Lotz 66*4a0460a9SMichael Lotz status_t SetMasterUnlockKey(const BKey& key); 67*4a0460a9SMichael Lotz status_t RemoveMasterUnlockKey(); 683b3884d9SMichael Lotz 693b3884d9SMichael Lotz status_t AddKeyringToMaster(const char* keyring); 703b3884d9SMichael Lotz status_t RemoveKeyringFromMaster(const char* keyring); 713b3884d9SMichael Lotz 723b3884d9SMichael Lotz status_t GetNextMasterKeyring(uint32& cookie, 733b3884d9SMichael Lotz BString& keyring); 743b3884d9SMichael Lotz 75c8ae843fSMichael Lotz // Locking 763b3884d9SMichael Lotz 77c8ae843fSMichael Lotz bool IsKeyringUnlocked(const char* keyring); 78c8ae843fSMichael Lotz status_t LockKeyring(const char* keyring); 79c8ae843fSMichael Lotz status_t LockMasterKeyring(); 803b3884d9SMichael Lotz 81dc1acef8SMichael Lotz // Applications 82dc1acef8SMichael Lotz 83f8ccc323SMichael Lotz status_t GetNextApplication(uint32& cookie, 8464ca113fSMichael Lotz BString& signature) const; 85f8ccc323SMichael Lotz status_t GetNextApplication(const char* keyring, 86f8ccc323SMichael Lotz uint32& cookie, BString& signature) const; 87f8ccc323SMichael Lotz status_t RemoveApplication(const char* signature); 8864ca113fSMichael Lotz status_t RemoveApplication(const char* keyring, 89f8ccc323SMichael Lotz const char* signature); 90dc1acef8SMichael Lotz 913b3884d9SMichael Lotz // Service functions 923b3884d9SMichael Lotz 93dc1acef8SMichael Lotz status_t GeneratePassword(BPasswordKey& password, 94dc1acef8SMichael Lotz size_t length, uint32 flags); 95dc1acef8SMichael Lotz float PasswordStrength(const char* password); 961c399649SMichael Lotz 971c399649SMichael Lotz private: 981c399649SMichael Lotz status_t _SendKeyMessage(BMessage& message, 991c399649SMichael Lotz BMessage* reply) const; 1003b3884d9SMichael Lotz }; 1013b3884d9SMichael Lotz 1023b3884d9SMichael Lotz 1033b3884d9SMichael Lotz #endif // _KEY_STORE_H 104