Flesh out the API and implement stubs.
* Modified the API greatly to be based on BKey* instead of BPassword*. * Added BKeyPurpose and used it instead of BKeyType. It is supposed to indicate the purpose of a key so that an app can look up keys on a more granular level. The BKeyType on the other hand actually identifies the type (i.e. subclass of BKey) so an app knows how to handle a given key or may only enumerate/use keys it is compatible with. * Made everything based on a raw data buffer for now, only BPasswordKey is implemented yet which stores the (0 terminated) string into that data buffer. * Removed the additional data BMessage as I don't yet see where it fits in. While I could imagine adding meta data to a key may be nice it might be an interoperability concern when keys are shared by different apps. * Moved the app functions to the keystore as per the TODO, but not sure how to actually implement them.
This commit is contained in:
committed by
Ryan Leavengood
parent
3b3884d9ee
commit
dc1acef865
+52
-37
@@ -12,44 +12,46 @@
|
||||
#include <String.h>
|
||||
|
||||
|
||||
enum BPasswordType {
|
||||
B_WEB_PASSWORD,
|
||||
B_NETWORK_PASSWORD,
|
||||
B_VOLUME_PASSWORD,
|
||||
B_GENERIC_PASSWORD
|
||||
enum BKeyPurpose {
|
||||
B_KEY_PURPOSE_ANY,
|
||||
B_KEY_PURPOSE_GENERIC,
|
||||
B_KEY_PURPOSE_WEB,
|
||||
B_KEY_PURPOSE_NETWORK,
|
||||
B_KEY_PURPOSE_VOLUME
|
||||
};
|
||||
|
||||
|
||||
enum BKeyType {
|
||||
B_KEY_TYPE_ANY,
|
||||
B_KEY_TYPE_GENERIC,
|
||||
B_KEY_TYPE_PASSWORD,
|
||||
B_KEY_TYPE_CERTIFICATE
|
||||
};
|
||||
|
||||
|
||||
class BKey {
|
||||
public:
|
||||
BKey();
|
||||
BKey(BPasswordType type,
|
||||
BKey(BKeyPurpose purpose,
|
||||
const char* identifier,
|
||||
const char* password);
|
||||
BKey(BPasswordType type,
|
||||
const char* identifier,
|
||||
const char* secondaryIdentifier,
|
||||
const char* password);
|
||||
const char* secondaryIdentifier = NULL,
|
||||
const uint8* data = NULL,
|
||||
size_t length = 0);
|
||||
BKey(BKey& other);
|
||||
virtual ~BKey();
|
||||
|
||||
virtual BKeyType Type() const { return B_KEY_TYPE_GENERIC; };
|
||||
|
||||
void Unset();
|
||||
|
||||
status_t SetTo(BPasswordType type,
|
||||
status_t SetTo(BKeyPurpose purpose,
|
||||
const char* identifier,
|
||||
const char* password);
|
||||
status_t SetTo(BPasswordType type,
|
||||
const char* identifier,
|
||||
const char* secondaryIdentifier,
|
||||
const char* password);
|
||||
const char* secondaryIdentifier = NULL,
|
||||
const uint8* data = NULL,
|
||||
size_t length = 0);
|
||||
|
||||
status_t SetPassword(const char* password);
|
||||
const char* Password() const;
|
||||
|
||||
status_t SetKey(const uint8* data, size_t length);
|
||||
size_t KeyLength() const;
|
||||
status_t GetKey(uint8* buffer,
|
||||
size_t bufferLength) const;
|
||||
void SetPurpose(BKeyPurpose purpose);
|
||||
BKeyPurpose Purpose() const;
|
||||
|
||||
void SetIdentifier(const char* identifier);
|
||||
const char* Identifier() const;
|
||||
@@ -57,37 +59,50 @@ public:
|
||||
void SetSecondaryIdentifier(const char* identifier);
|
||||
const char* SecondaryIdentifier() const;
|
||||
|
||||
void SetType(BPasswordType type);
|
||||
BPasswordType Type() const;
|
||||
|
||||
void SetData(const BMessage& data);
|
||||
const BMessage& Data() const;
|
||||
status_t SetData(const uint8* data, size_t length);
|
||||
size_t DataLength() const;
|
||||
const uint8* Data() const;
|
||||
status_t GetData(uint8* buffer, size_t bufferSize) const;
|
||||
|
||||
const char* Owner() const;
|
||||
bigtime_t CreationTime() const;
|
||||
bool IsRegistered() const;
|
||||
|
||||
// TODO: move to BKeyStore
|
||||
status_t GetNextApplication(uint32& cookie,
|
||||
BString& signature) const;
|
||||
status_t RemoveApplication(const char* signature);
|
||||
|
||||
BKey& operator=(const BKey& other);
|
||||
|
||||
bool operator==(const BKey& other) const;
|
||||
bool operator!=(const BKey& other) const;
|
||||
|
||||
private:
|
||||
mutable BMallocIO fPassword;
|
||||
BKeyPurpose fPurpose;
|
||||
BString fIdentifier;
|
||||
BString fSecondaryIdentifier;
|
||||
BString fOwner;
|
||||
BMessage fData;
|
||||
bigtime_t fCreationTime;
|
||||
BPasswordType fType;
|
||||
mutable BMallocIO fData;
|
||||
BObjectList<BString> fApplications;
|
||||
bool fRegistered;
|
||||
};
|
||||
|
||||
|
||||
class BPasswordKey : public BKey {
|
||||
public:
|
||||
BPasswordKey();
|
||||
BPasswordKey(const char* password,
|
||||
BKeyPurpose purpose, const char* identifier,
|
||||
const char* secondaryIdentifier = NULL);
|
||||
BPasswordKey(BPasswordKey& other);
|
||||
virtual ~BPasswordKey();
|
||||
|
||||
virtual BKeyType Type() const { return B_KEY_TYPE_PASSWORD; };
|
||||
|
||||
status_t SetTo(const char* password,
|
||||
BKeyPurpose purpose,
|
||||
const char* identifier,
|
||||
const char* secondaryIdentifier = NULL);
|
||||
|
||||
status_t SetPassword(const char* password);
|
||||
const char* Password() const;
|
||||
};
|
||||
|
||||
#endif // _KEY_H
|
||||
|
||||
+31
-24
@@ -16,46 +16,46 @@ public:
|
||||
|
||||
// TODO: -> GetNextPassword() - there can always be more than one key
|
||||
// with the same identifier/secondaryIdentifier (ie. different username)
|
||||
status_t GetPassword(BPasswordType type,
|
||||
status_t GetKey(BKeyType type, BKeyPurpose purpose,
|
||||
const char* identifier, BKey& key);
|
||||
status_t GetPassword(BPasswordType type,
|
||||
status_t GetKey(BKeyType type, BKeyPurpose purpose,
|
||||
const char* identifier,
|
||||
const char* secondaryIdentifier, BKey& key);
|
||||
status_t GetPassword(BPasswordType type,
|
||||
status_t GetKey(BKeyType type, BKeyPurpose purpose,
|
||||
const char* identifier,
|
||||
const char* secondaryIdentifier,
|
||||
bool secondaryIdentifierOptional,
|
||||
BKey& key);
|
||||
|
||||
status_t GetPassword(const char* keyring,
|
||||
BPasswordType type,
|
||||
status_t GetKey(const char* keyring,
|
||||
BKeyType type, BKeyPurpose purpose,
|
||||
const char* identifier, BKey& key);
|
||||
status_t GetPassword(const char* keyring,
|
||||
BPasswordType type,
|
||||
status_t GetKey(const char* keyring,
|
||||
BKeyType type, BKeyPurpose purpose,
|
||||
const char* identifier,
|
||||
const char* secondaryIdentifier, BKey& key);
|
||||
status_t GetPassword(const char* keyring,
|
||||
BPasswordType type,
|
||||
status_t GetKey(const char* keyring,
|
||||
BKeyType type, BKeyPurpose purpose,
|
||||
const char* identifier,
|
||||
const char* secondaryIdentifier,
|
||||
bool secondaryIdentifierOptional,
|
||||
BKey& key);
|
||||
|
||||
status_t RegisterPassword(const BKey& key);
|
||||
status_t RegisterPassword(const char* keyring,
|
||||
status_t RegisterKey(const BKey& key);
|
||||
status_t RegisterKey(const char* keyring,
|
||||
const BKey& key);
|
||||
status_t UnregisterPassword(const BKey& key);
|
||||
status_t UnregisterPassword(const char* keyring,
|
||||
status_t UnregisterKey(const BKey& key);
|
||||
status_t UnregisterKey(const char* keyring,
|
||||
const BKey& key);
|
||||
|
||||
status_t GetNextPassword(uint32& cookie, BKey& key);
|
||||
status_t GetNextPassword(BPasswordType type,
|
||||
status_t GetNextKey(uint32& cookie, BKey& key);
|
||||
status_t GetNextKey(BKeyType type, BKeyPurpose purpose,
|
||||
uint32& cookie, BKey& key);
|
||||
status_t GetNextPassword(const char* keyring,
|
||||
status_t GetNextKey(const char* keyring,
|
||||
uint32& cookie, BKey& key);
|
||||
status_t GetNextKey(const char* keyring,
|
||||
BKeyType type, BKeyPurpose purpose,
|
||||
uint32& cookie, BKey& key);
|
||||
status_t GetNextPassword(const char* keyring,
|
||||
BPasswordType type, uint32& cookie,
|
||||
BKey& key);
|
||||
|
||||
// Keyrings
|
||||
|
||||
@@ -68,8 +68,8 @@ public:
|
||||
|
||||
// Master key
|
||||
|
||||
status_t SetMasterPassword(const BKey& key);
|
||||
status_t RemoveMasterPassword();
|
||||
status_t SetMasterKey(const BKey& key);
|
||||
status_t RemoveMasterKey();
|
||||
|
||||
status_t AddKeyringToMaster(const char* keyring);
|
||||
status_t RemoveKeyringFromMaster(const char* keyring);
|
||||
@@ -83,11 +83,18 @@ public:
|
||||
status_t RevokeAccess(const char* keyring);
|
||||
status_t RevokeMasterAccess();
|
||||
|
||||
// Applications
|
||||
|
||||
status_t GetNextApplication(const BKey& key,
|
||||
uint32& cookie, BString& signature) const;
|
||||
status_t RemoveApplication(const BKey& key,
|
||||
const char* signature);
|
||||
|
||||
// Service functions
|
||||
|
||||
status_t GeneratePassword(BKey& key, size_t length,
|
||||
uint32 flags);
|
||||
float PasswordStrength(const char* key);
|
||||
status_t GeneratePassword(BPasswordKey& password,
|
||||
size_t length, uint32 flags);
|
||||
float PasswordStrength(const char* password);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user