KeyStore and Key interface/stubs draft per Axel Dörfler.

A draft API and (mostly) stubs to back it up. Initial import of yet
unmodified sources.
This commit is contained in:
Michael Lotz
2013-03-05 10:59:41 -05:00
committed by Ryan Leavengood
parent fa392c2a24
commit 3b3884d9ee
5 changed files with 685 additions and 0 deletions
+93
View File
@@ -0,0 +1,93 @@
/*
* Copyright 2011, Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _KEY_H
#define _KEY_H
#include <DataIO.h>
#include <Message.h>
#include <ObjectList.h>
#include <String.h>
enum BPasswordType {
B_WEB_PASSWORD,
B_NETWORK_PASSWORD,
B_VOLUME_PASSWORD,
B_GENERIC_PASSWORD
};
class BKey {
public:
BKey();
BKey(BPasswordType type,
const char* identifier,
const char* password);
BKey(BPasswordType type,
const char* identifier,
const char* secondaryIdentifier,
const char* password);
BKey(BKey& other);
virtual ~BKey();
void Unset();
status_t SetTo(BPasswordType type,
const char* identifier,
const char* password);
status_t SetTo(BPasswordType type,
const char* identifier,
const char* secondaryIdentifier,
const char* password);
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 SetIdentifier(const char* identifier);
const char* Identifier() const;
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;
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;
BString fIdentifier;
BString fSecondaryIdentifier;
BString fOwner;
BMessage fData;
bigtime_t fCreationTime;
BPasswordType fType;
BObjectList<BString> fApplications;
bool fRegistered;
};
#endif // _KEY_H
+94
View File
@@ -0,0 +1,94 @@
/*
* Copyright 2011, Haiku, Inc.
* Distributed under the terms of the MIT License.
*/
#ifndef _KEY_STORE_H
#define _KEY_STORE_H
#include <Key.h>
class BKeyStore {
public:
BKeyStore();
virtual ~BKeyStore();
// TODO: -> GetNextPassword() - there can always be more than one key
// with the same identifier/secondaryIdentifier (ie. different username)
status_t GetPassword(BPasswordType type,
const char* identifier, BKey& key);
status_t GetPassword(BPasswordType type,
const char* identifier,
const char* secondaryIdentifier, BKey& key);
status_t GetPassword(BPasswordType type,
const char* identifier,
const char* secondaryIdentifier,
bool secondaryIdentifierOptional,
BKey& key);
status_t GetPassword(const char* keyring,
BPasswordType type,
const char* identifier, BKey& key);
status_t GetPassword(const char* keyring,
BPasswordType type,
const char* identifier,
const char* secondaryIdentifier, BKey& key);
status_t GetPassword(const char* keyring,
BPasswordType type,
const char* identifier,
const char* secondaryIdentifier,
bool secondaryIdentifierOptional,
BKey& key);
status_t RegisterPassword(const BKey& key);
status_t RegisterPassword(const char* keyring,
const BKey& key);
status_t UnregisterPassword(const BKey& key);
status_t UnregisterPassword(const char* keyring,
const BKey& key);
status_t GetNextPassword(uint32& cookie, BKey& key);
status_t GetNextPassword(BPasswordType type,
uint32& cookie, BKey& key);
status_t GetNextPassword(const char* keyring,
uint32& cookie, BKey& key);
status_t GetNextPassword(const char* keyring,
BPasswordType type, uint32& cookie,
BKey& key);
// Keyrings
status_t RegisterKeyring(const char* keyring,
const BKey& key);
status_t UnregisterKeyring(const char* keyring);
status_t GetNextKeyring(uint32& cookie,
BString& keyring);
// Master key
status_t SetMasterPassword(const BKey& key);
status_t RemoveMasterPassword();
status_t AddKeyringToMaster(const char* keyring);
status_t RemoveKeyringFromMaster(const char* keyring);
status_t GetNextMasterKeyring(uint32& cookie,
BString& keyring);
// Access
bool IsKeyringAccessible(const char* keyring);
status_t RevokeAccess(const char* keyring);
status_t RevokeMasterAccess();
// Service functions
status_t GeneratePassword(BKey& key, size_t length,
uint32 flags);
float PasswordStrength(const char* key);
};
#endif // _KEY_STORE_H