Add generic unlock key setting and removal.

* Replace {Set|Remove}MasterKey() by generic {Set|Remove}UnlockKey()
  that works on a keyring.
* Implement {Set|Remove}MasterUnlockKey() on top of that.
* Rename the commands and constants accrodingly.
* Implement setting and removing keyring unlock keys.
This commit is contained in:
Michael Lotz
2013-03-05 11:04:57 -05:00
committed by Ryan Leavengood
parent a82011ff96
commit 4a0460a9bc
4 changed files with 72 additions and 23 deletions
+7 -3
View File
@@ -57,10 +57,14 @@ public:
status_t GetNextKeyring(uint32& cookie, status_t GetNextKeyring(uint32& cookie,
BString& keyring); BString& keyring);
// Master key status_t SetUnlockKey(const char* keyring,
const BKey& key);
status_t RemoveUnlockKey(const char* keyring);
status_t SetMasterKey(const BKey& key); // Master keyring
status_t RemoveMasterKey();
status_t SetMasterUnlockKey(const BKey& key);
status_t RemoveMasterUnlockKey();
status_t AddKeyringToMaster(const char* keyring); status_t AddKeyringToMaster(const char* keyring);
status_t RemoveKeyringFromMaster(const char* keyring); status_t RemoveKeyringFromMaster(const char* keyring);
+2 -2
View File
@@ -30,8 +30,8 @@ enum {
KEY_STORE_ADD_KEYRING = 'KaKR', KEY_STORE_ADD_KEYRING = 'KaKR',
KEY_STORE_REMOVE_KEYRING = 'KrKR', KEY_STORE_REMOVE_KEYRING = 'KrKR',
KEY_STORE_GET_NEXT_KEYRING = 'KnKR', KEY_STORE_GET_NEXT_KEYRING = 'KnKR',
KEY_STORE_SET_MASTER_KEY = 'KsMK', KEY_STORE_SET_UNLOCK_KEY = 'KsuK',
KEY_STORE_REMOVE_MASTER_KEY = 'KrMK', KEY_STORE_REMOVE_UNLOCK_KEY = 'KruK',
KEY_STORE_ADD_KEYRING_TO_MASTER = 'KarM', KEY_STORE_ADD_KEYRING_TO_MASTER = 'KarM',
KEY_STORE_REMOVE_KEYRING_FROM_MASTER = 'KrrM', KEY_STORE_REMOVE_KEYRING_FROM_MASTER = 'KrrM',
KEY_STORE_GET_NEXT_MASTER_KEYRING = 'KnrM', KEY_STORE_GET_NEXT_MASTER_KEYRING = 'KnrM',
+23 -7
View File
@@ -223,17 +223,15 @@ BKeyStore::GetNextKeyring(uint32& cookie, BString& keyring)
} }
// #pragma mark - Master key
status_t status_t
BKeyStore::SetMasterKey(const BKey& key) BKeyStore::SetUnlockKey(const char* keyring, const BKey& key)
{ {
BMessage keyMessage; BMessage keyMessage;
if (key.Flatten(keyMessage) != B_OK) if (key.Flatten(keyMessage) != B_OK)
return B_BAD_VALUE; return B_BAD_VALUE;
BMessage message(KEY_STORE_SET_MASTER_KEY); BMessage message(KEY_STORE_SET_UNLOCK_KEY);
message.AddString("keyring", keyring);
message.AddMessage("key", &keyMessage); message.AddMessage("key", &keyMessage);
return _SendKeyMessage(message, NULL); return _SendKeyMessage(message, NULL);
@@ -241,13 +239,31 @@ BKeyStore::SetMasterKey(const BKey& key)
status_t status_t
BKeyStore::RemoveMasterKey() BKeyStore::RemoveUnlockKey(const char* keyring)
{ {
BMessage message(KEY_STORE_REMOVE_MASTER_KEY); BMessage message(KEY_STORE_REMOVE_UNLOCK_KEY);
message.AddString("keyring", keyring);
return _SendKeyMessage(message, NULL); return _SendKeyMessage(message, NULL);
} }
// #pragma mark - Master key
status_t
BKeyStore::SetMasterUnlockKey(const BKey& key)
{
return SetUnlockKey(NULL, key);
}
status_t
BKeyStore::RemoveMasterUnlockKey()
{
return RemoveUnlockKey(NULL);
}
status_t status_t
BKeyStore::AddKeyringToMaster(const char* keyring) BKeyStore::AddKeyringToMaster(const char* keyring)
{ {
+40 -11
View File
@@ -39,8 +39,8 @@ static const uint32 kFlagRemoveKey = 0x0008;
static const uint32 kFlagAddKeyring = 0x0010; static const uint32 kFlagAddKeyring = 0x0010;
static const uint32 kFlagRemoveKeyring = 0x0020; static const uint32 kFlagRemoveKeyring = 0x0020;
static const uint32 kFlagEnumerateKeyrings = 0x0040; static const uint32 kFlagEnumerateKeyrings = 0x0040;
static const uint32 kFlagSetMasterKey = 0x0080; static const uint32 kFlagSetUnlockKey = 0x0080;
static const uint32 kFlagRemoveMasterKey = 0x0100; static const uint32 kFlagRemoveUnlockKey = 0x0100;
static const uint32 kFlagAddKeyringsToMaster = 0x0200; static const uint32 kFlagAddKeyringsToMaster = 0x0200;
static const uint32 kFlagRemoveKeyringsFromMaster = 0x0400; static const uint32 kFlagRemoveKeyringsFromMaster = 0x0400;
static const uint32 kFlagEnumerateMasterKeyrings = 0x0800; static const uint32 kFlagEnumerateMasterKeyrings = 0x0800;
@@ -51,7 +51,7 @@ static const uint32 kFlagRemoveApplications = 0x8000;
static const uint32 kDefaultAppFlags = kFlagGetKey | kFlagEnumerateKeys static const uint32 kDefaultAppFlags = kFlagGetKey | kFlagEnumerateKeys
| kFlagAddKey | kFlagRemoveKey | kFlagAddKeyring | kFlagRemoveKeyring | kFlagAddKey | kFlagRemoveKey | kFlagAddKeyring | kFlagRemoveKeyring
| kFlagEnumerateKeyrings | kFlagSetMasterKey | kFlagRemoveMasterKey | kFlagEnumerateKeyrings | kFlagSetUnlockKey | kFlagRemoveUnlockKey
| kFlagAddKeyringsToMaster | kFlagRemoveKeyringsFromMaster | kFlagAddKeyringsToMaster | kFlagRemoveKeyringsFromMaster
| kFlagEnumerateMasterKeyrings | kFlagQueryLockState | kFlagLockKeyring | kFlagEnumerateMasterKeyrings | kFlagQueryLockState | kFlagLockKeyring
| kFlagEnumerateApplications | kFlagRemoveApplications; | kFlagEnumerateApplications | kFlagRemoveApplications;
@@ -123,6 +123,8 @@ KeyStoreServer::MessageReceived(BMessage* message)
case KEY_STORE_REMOVE_KEY: case KEY_STORE_REMOVE_KEY:
case KEY_STORE_IS_KEYRING_UNLOCKED: case KEY_STORE_IS_KEYRING_UNLOCKED:
case KEY_STORE_LOCK_KEYRING: case KEY_STORE_LOCK_KEYRING:
case KEY_STORE_SET_UNLOCK_KEY:
case KEY_STORE_REMOVE_UNLOCK_KEY:
case KEY_STORE_ADD_KEYRING_TO_MASTER: case KEY_STORE_ADD_KEYRING_TO_MASTER:
case KEY_STORE_REMOVE_KEYRING_FROM_MASTER: case KEY_STORE_REMOVE_KEYRING_FROM_MASTER:
case KEY_STORE_GET_NEXT_APPLICATION: case KEY_STORE_GET_NEXT_APPLICATION:
@@ -145,6 +147,8 @@ KeyStoreServer::MessageReceived(BMessage* message)
case KEY_STORE_GET_NEXT_KEY: case KEY_STORE_GET_NEXT_KEY:
case KEY_STORE_ADD_KEY: case KEY_STORE_ADD_KEY:
case KEY_STORE_REMOVE_KEY: case KEY_STORE_REMOVE_KEY:
case KEY_STORE_SET_UNLOCK_KEY:
case KEY_STORE_REMOVE_UNLOCK_KEY:
case KEY_STORE_ADD_KEYRING_TO_MASTER: case KEY_STORE_ADD_KEYRING_TO_MASTER:
case KEY_STORE_GET_NEXT_APPLICATION: case KEY_STORE_GET_NEXT_APPLICATION:
case KEY_STORE_REMOVE_APPLICATION: case KEY_STORE_REMOVE_APPLICATION:
@@ -333,6 +337,31 @@ KeyStoreServer::MessageReceived(BMessage* message)
break; break;
} }
case KEY_STORE_SET_UNLOCK_KEY:
{
BMessage keyMessage;
if (message->FindMessage("key", &keyMessage) != B_OK) {
result = B_BAD_VALUE;
break;
}
result = keyring->SetUnlockKey(keyMessage);
if (result == B_OK)
_WriteKeyStoreDatabase();
// TODO: Update the key in the master if this keyring was added.
break;
}
case KEY_STORE_REMOVE_UNLOCK_KEY:
{
result = keyring->RemoveUnlockKey();
if (result == B_OK)
_WriteKeyStoreDatabase();
break;
}
case KEY_STORE_ADD_KEYRING_TO_MASTER: case KEY_STORE_ADD_KEYRING_TO_MASTER:
case KEY_STORE_REMOVE_KEYRING_FROM_MASTER: case KEY_STORE_REMOVE_KEYRING_FROM_MASTER:
{ {
@@ -520,10 +549,10 @@ KeyStoreServer::_AccessFlagsFor(uint32 command) const
return kFlagRemoveKeyring; return kFlagRemoveKeyring;
case KEY_STORE_GET_NEXT_KEYRING: case KEY_STORE_GET_NEXT_KEYRING:
return kFlagEnumerateKeyrings; return kFlagEnumerateKeyrings;
case KEY_STORE_SET_MASTER_KEY: case KEY_STORE_SET_UNLOCK_KEY:
return kFlagSetMasterKey; return kFlagSetUnlockKey;
case KEY_STORE_REMOVE_MASTER_KEY: case KEY_STORE_REMOVE_UNLOCK_KEY:
return kFlagRemoveMasterKey; return kFlagRemoveUnlockKey;
case KEY_STORE_ADD_KEYRING_TO_MASTER: case KEY_STORE_ADD_KEYRING_TO_MASTER:
return kFlagAddKeyringsToMaster; return kFlagAddKeyringsToMaster;
case KEY_STORE_REMOVE_KEYRING_FROM_MASTER: case KEY_STORE_REMOVE_KEYRING_FROM_MASTER:
@@ -562,10 +591,10 @@ KeyStoreServer::_AccessStringFor(uint32 accessFlag) const
return "Remove keyrings."; return "Remove keyrings.";
case kFlagEnumerateKeyrings: case kFlagEnumerateKeyrings:
return "Enumerate the available keyrings."; return "Enumerate the available keyrings.";
case kFlagSetMasterKey: case kFlagSetUnlockKey:
return "Set the master key."; return "Set the unlock key of the keyring.";
case kFlagRemoveMasterKey: case kFlagRemoveUnlockKey:
return "Remove the master key."; return "Remove the unlock key of the keyring.";
case kFlagAddKeyringsToMaster: case kFlagAddKeyringsToMaster:
return "Add the keyring key to the master keyring."; return "Add the keyring key to the master keyring.";
case kFlagRemoveKeyringsFromMaster: case kFlagRemoveKeyringsFromMaster: