Rename keyring "access/revoke" to "unlock/lock".

The unlock/lock concept just seems easier to grasp and is used in
various similar tools as well.
This commit is contained in:
Michael Lotz
2013-03-05 11:04:30 -05:00
committed by Ryan Leavengood
parent f17ddab827
commit c8ae843f3d
8 changed files with 76 additions and 77 deletions
+4 -4
View File
@@ -71,11 +71,11 @@ public:
status_t GetNextMasterKeyring(uint32& cookie, status_t GetNextMasterKeyring(uint32& cookie,
BString& keyring); BString& keyring);
// Access // Locking
bool IsKeyringAccessible(const char* keyring); bool IsKeyringUnlocked(const char* keyring);
status_t RevokeAccess(const char* keyring); status_t LockKeyring(const char* keyring);
status_t RevokeMasterAccess(); status_t LockMasterKeyring();
// Applications // Applications
+2 -2
View File
@@ -35,8 +35,8 @@ enum {
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',
KEY_STORE_IS_KEYRING_ACCESSIBLE = 'KiaR', KEY_STORE_IS_KEYRING_UNLOCKED = 'KuKR',
KEY_STORE_REVOKE_ACCESS = 'KvaR', KEY_STORE_LOCK_KEYRING = 'KlKR',
KEY_STORE_GET_NEXT_APPLICATION = 'KnKA', KEY_STORE_GET_NEXT_APPLICATION = 'KnKA',
KEY_STORE_REMOVE_APPLICATION = 'KrKA', KEY_STORE_REMOVE_APPLICATION = 'KrKA',
}; };
+11 -11
View File
@@ -140,19 +140,19 @@ int
show_status(const char* keyring) show_status(const char* keyring)
{ {
BKeyStore keyStore; BKeyStore keyStore;
printf("keyring \"%s\" is %saccessible\n", keyring, printf("keyring \"%s\" is %slocked\n", keyring,
keyStore.IsKeyringAccessible(keyring) ? "" : "not "); keyStore.IsKeyringUnlocked(keyring) ? "un" : "");
return 0; return 0;
} }
int int
revoke_access(const char* keyring) lock_keyring(const char* keyring)
{ {
BKeyStore keyStore; BKeyStore keyStore;
status_t result = keyStore.RevokeAccess(keyring); status_t result = keyStore.LockKeyring(keyring);
if (result != B_OK) { if (result != B_OK) {
printf("failed to revoke access to keyring \"%s\": %s\n", keyring, printf("failed to lock keyring \"%s\": %s\n", keyring,
strerror(result)); strerror(result));
return 2; return 2;
} }
@@ -222,12 +222,12 @@ print_usage(const char* name)
printf("\t\tRemoves the specified keyring.\n\n"); printf("\t\tRemoves the specified keyring.\n\n");
printf("\t%s status [<keyring>]\n", name); printf("\t%s status [<keyring>]\n", name);
printf("\t\tShows the access status of the specified keyring, or the" printf("\t\tShows the lock state of the specified keyring, or the"
" default keyring if none is supplied.\n\n"); " default keyring if none is supplied.\n\n");
printf("\t%s revoke [<keyring>]\n", name); printf("\t%s lock [<keyring>]\n", name);
printf("\t\tRevoke access to the specified keyring, or to the default" printf("\t\tLock the specified keyring, or the default keyring if none is"
" keyring if none is supplied.\n\n"); " supplied.\n\n");
printf("\t%s master add <keyring>\n", name); printf("\t%s master add <keyring>\n", name);
printf("\t\tAdd the access key for the specified keyring to the default" printf("\t\tAdd the access key for the specified keyring to the default"
@@ -333,11 +333,11 @@ main(int argc, char* argv[])
return print_usage(argv[0]); return print_usage(argv[0]);
return show_status(argc == 3 ? argv[2] : ""); return show_status(argc == 3 ? argv[2] : "");
} else if (strcmp(argv[1], "revoke") == 0) { } else if (strcmp(argv[1], "lock") == 0) {
if (argc != 2 && argc != 3) if (argc != 2 && argc != 3)
return print_usage(argv[0]); return print_usage(argv[0]);
return revoke_access(argc == 3 ? argv[2] : ""); return lock_keyring(argc == 3 ? argv[2] : "");
} else if (strcmp(argv[1], "master") == 0) { } else if (strcmp(argv[1], "master") == 0) {
if (argc != 4) if (argc != 4)
return print_usage(argv[0]); return print_usage(argv[0]);
+10 -10
View File
@@ -291,40 +291,40 @@ BKeyStore::GetNextMasterKeyring(uint32& cookie, BString& keyring)
} }
// #pragma mark - Access // #pragma mark - Locking
bool bool
BKeyStore::IsKeyringAccessible(const char* keyring) BKeyStore::IsKeyringUnlocked(const char* keyring)
{ {
BMessage message(KEY_STORE_IS_KEYRING_ACCESSIBLE); BMessage message(KEY_STORE_IS_KEYRING_UNLOCKED);
message.AddString("keyring", keyring); message.AddString("keyring", keyring);
BMessage reply; BMessage reply;
if (_SendKeyMessage(message, &reply) != B_OK) if (_SendKeyMessage(message, &reply) != B_OK)
return false; return false;
bool accessible; bool unlocked;
if (reply.FindBool("accessible", &accessible) != B_OK) if (reply.FindBool("unlocked", &unlocked) != B_OK)
return false; return false;
return accessible; return unlocked;
} }
status_t status_t
BKeyStore::RevokeAccess(const char* keyring) BKeyStore::LockKeyring(const char* keyring)
{ {
BMessage message(KEY_STORE_REVOKE_ACCESS); BMessage message(KEY_STORE_LOCK_KEYRING);
message.AddString("keyring", keyring); message.AddString("keyring", keyring);
return _SendKeyMessage(message, NULL); return _SendKeyMessage(message, NULL);
} }
status_t status_t
BKeyStore::RevokeMasterAccess() BKeyStore::LockMasterKeyring()
{ {
return RevokeAccess(NULL); return LockKeyring(NULL);
} }
+27 -28
View File
@@ -41,8 +41,8 @@ static const uint32 kFlagRemoveMasterKey = 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;
static const uint32 kFlagQueryAccessibility = 0x1000; static const uint32 kFlagQueryLockState = 0x1000;
static const uint32 kFlagRevokeAccess = 0x2000; static const uint32 kFlagLockKeyring = 0x2000;
static const uint32 kFlagEnumerateApplications = 0x4000; static const uint32 kFlagEnumerateApplications = 0x4000;
static const uint32 kFlagRemoveApplications = 0x8000; static const uint32 kFlagRemoveApplications = 0x8000;
@@ -50,9 +50,8 @@ static const uint32 kDefaultAppFlags = kFlagGetKey | kFlagEnumerateKeys
| kFlagAddKey | kFlagRemoveKey | kFlagAddKeyring | kFlagRemoveKeyring | kFlagAddKey | kFlagRemoveKey | kFlagAddKeyring | kFlagRemoveKeyring
| kFlagEnumerateKeyrings | kFlagSetMasterKey | kFlagRemoveMasterKey | kFlagEnumerateKeyrings | kFlagSetMasterKey | kFlagRemoveMasterKey
| kFlagAddKeyringsToMaster | kFlagRemoveKeyringsFromMaster | kFlagAddKeyringsToMaster | kFlagRemoveKeyringsFromMaster
| kFlagEnumerateMasterKeyrings | kFlagQueryAccessibility | kFlagEnumerateMasterKeyrings | kFlagQueryLockState | kFlagLockKeyring
| kFlagQueryAccessibility | kFlagRevokeAccess | kFlagEnumerateApplications | kFlagEnumerateApplications | kFlagRemoveApplications;
| kFlagRemoveApplications;
KeyStoreServer::KeyStoreServer() KeyStoreServer::KeyStoreServer()
@@ -117,8 +116,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_IS_KEYRING_ACCESSIBLE: case KEY_STORE_IS_KEYRING_UNLOCKED:
case KEY_STORE_REVOKE_ACCESS: case KEY_STORE_LOCK_KEYRING:
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:
@@ -146,10 +145,10 @@ KeyStoreServer::MessageReceived(BMessage* message)
case KEY_STORE_REMOVE_APPLICATION: case KEY_STORE_REMOVE_APPLICATION:
{ {
// These need keyring access to do anything. // These need keyring access to do anything.
while (!keyring->IsAccessible()) { while (!keyring->IsUnlocked()) {
status_t accessResult = _AccessKeyring(*keyring); status_t unlockResult = _UnlockKeyring(*keyring);
if (accessResult != B_OK) { if (unlockResult != B_OK) {
result = accessResult; result = unlockResult;
message->what = 0; message->what = 0;
break; break;
} }
@@ -320,16 +319,16 @@ KeyStoreServer::MessageReceived(BMessage* message)
break; break;
} }
case KEY_STORE_IS_KEYRING_ACCESSIBLE: case KEY_STORE_IS_KEYRING_UNLOCKED:
{ {
reply.AddBool("accessible", keyring->IsAccessible()); reply.AddBool("unlocked", keyring->IsUnlocked());
result = B_OK; result = B_OK;
break; break;
} }
case KEY_STORE_REVOKE_ACCESS: case KEY_STORE_LOCK_KEYRING:
{ {
keyring->RevokeAccess(); keyring->Lock();
result = B_OK; result = B_OK;
break; break;
} }
@@ -338,10 +337,10 @@ KeyStoreServer::MessageReceived(BMessage* message)
case KEY_STORE_REMOVE_KEYRING_FROM_MASTER: case KEY_STORE_REMOVE_KEYRING_FROM_MASTER:
{ {
// We also need access to the default keyring. // We also need access to the default keyring.
while (!fDefaultKeyring->IsAccessible()) { while (!fDefaultKeyring->IsUnlocked()) {
status_t accessResult = _AccessKeyring(*fDefaultKeyring); status_t unlockResult = _UnlockKeyring(*fDefaultKeyring);
if (accessResult != B_OK) { if (unlockResult != B_OK) {
result = accessResult; result = unlockResult;
message->what = 0; message->what = 0;
break; break;
} }
@@ -528,10 +527,10 @@ KeyStoreServer::_AccessFlagsFor(uint32 command) const
return kFlagRemoveKeyringsFromMaster; return kFlagRemoveKeyringsFromMaster;
case KEY_STORE_GET_NEXT_MASTER_KEYRING: case KEY_STORE_GET_NEXT_MASTER_KEYRING:
return kFlagEnumerateMasterKeyrings; return kFlagEnumerateMasterKeyrings;
case KEY_STORE_IS_KEYRING_ACCESSIBLE: case KEY_STORE_IS_KEYRING_UNLOCKED:
return kFlagQueryAccessibility; return kFlagQueryLockState;
case KEY_STORE_REVOKE_ACCESS: case KEY_STORE_LOCK_KEYRING:
return kFlagRevokeAccess; return kFlagLockKeyring;
case KEY_STORE_GET_NEXT_APPLICATION: case KEY_STORE_GET_NEXT_APPLICATION:
return kFlagEnumerateApplications; return kFlagEnumerateApplications;
case KEY_STORE_REMOVE_APPLICATION: case KEY_STORE_REMOVE_APPLICATION:
@@ -673,16 +672,16 @@ KeyStoreServer::_RemoveKeyring(const BString& name)
status_t status_t
KeyStoreServer::_AccessKeyring(Keyring& keyring) KeyStoreServer::_UnlockKeyring(Keyring& keyring)
{ {
// If we are accessing a keyring that has been added to master access we // If we are accessing a keyring that has been added to master access we
// get the key from the default keyring and unlock with that. // get the key from the default keyring and unlock with that.
BMessage keyMessage; BMessage keyMessage;
if (&keyring != fDefaultKeyring && fDefaultKeyring->IsAccessible()) { if (&keyring != fDefaultKeyring && fDefaultKeyring->IsUnlocked()) {
if (fDefaultKeyring->FindKey(kKeyringKeysIdentifier, keyring.Name(), if (fDefaultKeyring->FindKey(kKeyringKeysIdentifier, keyring.Name(),
false, &keyMessage) == B_OK) { false, &keyMessage) == B_OK) {
// We found a key for this keyring, try to access with it. // We found a key for this keyring, try to unlock with it.
if (keyring.Access(keyMessage) == B_OK) if (keyring.Unlock(keyMessage) == B_OK)
return B_OK; return B_OK;
} }
} }
@@ -692,7 +691,7 @@ KeyStoreServer::_AccessKeyring(Keyring& keyring)
if (result != B_OK) if (result != B_OK)
return result; return result;
return keyring.Access(keyMessage); return keyring.Unlock(keyMessage);
} }
+1 -1
View File
@@ -49,7 +49,7 @@ private:
const BMessage& keyMessage); const BMessage& keyMessage);
status_t _RemoveKeyring(const BString& name); status_t _RemoveKeyring(const BString& name);
status_t _AccessKeyring(Keyring& keyring); status_t _UnlockKeyring(Keyring& keyring);
status_t _RequestKey(const BString& keyringName, status_t _RequestKey(const BString& keyringName,
BMessage& keyMessage); BMessage& keyMessage);
+17 -17
View File
@@ -10,11 +10,11 @@
Keyring::Keyring(const char* name, const BMessage* keyMessage) Keyring::Keyring(const char* name, const BMessage* keyMessage)
: :
fName(name), fName(name),
fAccessible(false), fUnlocked(false),
fModified(false) fModified(false)
{ {
if (keyMessage != NULL) if (keyMessage != NULL)
Access(*keyMessage); Unlock(*keyMessage);
} }
@@ -59,7 +59,7 @@ Keyring::WriteToMessage(BMessage& message)
status_t status_t
Keyring::Access(const BMessage& keyMessage) Keyring::Unlock(const BMessage& keyMessage)
{ {
fKeyMessage = keyMessage; fKeyMessage = keyMessage;
@@ -69,15 +69,15 @@ Keyring::Access(const BMessage& keyMessage)
return result; return result;
} }
fAccessible = true; fUnlocked = true;
return B_OK; return B_OK;
} }
void void
Keyring::RevokeAccess() Keyring::Lock()
{ {
if (!fAccessible) if (!fUnlocked)
return; return;
_EncryptToFlatBuffer(); _EncryptToFlatBuffer();
@@ -85,14 +85,14 @@ Keyring::RevokeAccess()
fKeyMessage.MakeEmpty(); fKeyMessage.MakeEmpty();
fData.MakeEmpty(); fData.MakeEmpty();
fApplications.MakeEmpty(); fApplications.MakeEmpty();
fAccessible = false; fUnlocked = false;
} }
bool bool
Keyring::IsAccessible() const Keyring::IsUnlocked() const
{ {
return fAccessible; return fUnlocked;
} }
@@ -131,7 +131,7 @@ status_t
Keyring::FindApplication(const char* signature, const char* path, Keyring::FindApplication(const char* signature, const char* path,
BMessage& appMessage) BMessage& appMessage)
{ {
if (!fAccessible) if (!fUnlocked)
return B_NOT_ALLOWED; return B_NOT_ALLOWED;
int32 count; int32 count;
@@ -159,7 +159,7 @@ Keyring::FindApplication(const char* signature, const char* path,
status_t status_t
Keyring::AddApplication(const char* signature, const BMessage& appMessage) Keyring::AddApplication(const char* signature, const BMessage& appMessage)
{ {
if (!fAccessible) if (!fUnlocked)
return B_NOT_ALLOWED; return B_NOT_ALLOWED;
status_t result = fApplications.AddMessage(signature, &appMessage); status_t result = fApplications.AddMessage(signature, &appMessage);
@@ -174,7 +174,7 @@ Keyring::AddApplication(const char* signature, const BMessage& appMessage)
status_t status_t
Keyring::RemoveApplication(const char* signature, const char* path) Keyring::RemoveApplication(const char* signature, const char* path)
{ {
if (!fAccessible) if (!fUnlocked)
return B_NOT_ALLOWED; return B_NOT_ALLOWED;
if (path == NULL) { if (path == NULL) {
@@ -216,7 +216,7 @@ status_t
Keyring::FindKey(const BString& identifier, const BString& secondaryIdentifier, Keyring::FindKey(const BString& identifier, const BString& secondaryIdentifier,
bool secondaryIdentifierOptional, BMessage* _foundKeyMessage) const bool secondaryIdentifierOptional, BMessage* _foundKeyMessage) const
{ {
if (!fAccessible) if (!fUnlocked)
return B_NOT_ALLOWED; return B_NOT_ALLOWED;
int32 count; int32 count;
@@ -262,7 +262,7 @@ status_t
Keyring::FindKey(BKeyType type, BKeyPurpose purpose, uint32 index, Keyring::FindKey(BKeyType type, BKeyPurpose purpose, uint32 index,
BMessage& _foundKeyMessage) const BMessage& _foundKeyMessage) const
{ {
if (!fAccessible) if (!fUnlocked)
return B_NOT_ALLOWED; return B_NOT_ALLOWED;
for (int32 keyIndex = 0;; keyIndex++) { for (int32 keyIndex = 0;; keyIndex++) {
@@ -327,7 +327,7 @@ status_t
Keyring::AddKey(const BString& identifier, const BString& secondaryIdentifier, Keyring::AddKey(const BString& identifier, const BString& secondaryIdentifier,
const BMessage& keyMessage) const BMessage& keyMessage)
{ {
if (!fAccessible) if (!fUnlocked)
return B_NOT_ALLOWED; return B_NOT_ALLOWED;
// Check for collisions. // Check for collisions.
@@ -348,7 +348,7 @@ status_t
Keyring::RemoveKey(const BString& identifier, Keyring::RemoveKey(const BString& identifier,
const BMessage& keyMessage) const BMessage& keyMessage)
{ {
if (!fAccessible) if (!fUnlocked)
return B_NOT_ALLOWED; return B_NOT_ALLOWED;
int32 count; int32 count;
@@ -397,7 +397,7 @@ Keyring::_EncryptToFlatBuffer()
if (!fModified) if (!fModified)
return B_OK; return B_OK;
if (!fAccessible) if (!fUnlocked)
return B_NOT_ALLOWED; return B_NOT_ALLOWED;
BMessage container; BMessage container;
+4 -4
View File
@@ -20,9 +20,9 @@ public:
status_t ReadFromMessage(const BMessage& message); status_t ReadFromMessage(const BMessage& message);
status_t WriteToMessage(BMessage& message); status_t WriteToMessage(BMessage& message);
status_t Access(const BMessage& keyMessage); status_t Unlock(const BMessage& keyMessage);
void RevokeAccess(); void Lock();
bool IsAccessible() const; bool IsUnlocked() const;
const BMessage& KeyMessage() const; const BMessage& KeyMessage() const;
status_t GetNextApplication(uint32& cookie, status_t GetNextApplication(uint32& cookie,
@@ -62,7 +62,7 @@ private:
BMessage fData; BMessage fData;
BMessage fApplications; BMessage fApplications;
BMessage fKeyMessage; BMessage fKeyMessage;
bool fAccessible; bool fUnlocked;
bool fModified; bool fModified;
}; };