Don't require a key when creating a new keyring.

There will be key setting/removal functions so the step of adding the
keyring and setting a key on it can be done individually.
This commit is contained in:
Michael Lotz
2013-03-05 11:04:53 -05:00
committed by Ryan Leavengood
parent 8775bd129d
commit d4d6d12393
7 changed files with 15 additions and 29 deletions
+1 -2
View File
@@ -51,8 +51,7 @@ public:
// Keyrings // Keyrings
status_t AddKeyring(const char* keyring, status_t AddKeyring(const char* keyring);
const BKey& key);
status_t RemoveKeyring(const char* keyring); status_t RemoveKeyring(const char* keyring);
status_t GetNextKeyring(uint32& cookie, status_t GetNextKeyring(uint32& cookie,
+6 -8
View File
@@ -57,12 +57,11 @@ remove_password(const char* keyring, const char* identifier,
int int
add_keyring(const char* keyring, const char* passwordString) add_keyring(const char* keyring)
{ {
BKeyStore keyStore; BKeyStore keyStore;
BPasswordKey password(passwordString, B_KEY_PURPOSE_KEYRING, NULL);
status_t result = keyStore.AddKeyring(keyring, password); status_t result = keyStore.AddKeyring(keyring);
if (result != B_OK) { if (result != B_OK) {
printf("failed to add keyring: %s\n", strerror(result)); printf("failed to add keyring: %s\n", strerror(result));
return 2; return 2;
@@ -257,9 +256,8 @@ print_usage(const char* name)
" [<secondaryIdentifier>]\n", name); " [<secondaryIdentifier>]\n", name);
printf("\t\tRemoves the specified password from the specified keyring.\n\n"); printf("\t\tRemoves the specified password from the specified keyring.\n\n");
printf("\t%s add keyring <name> <password>\n", name); printf("\t%s add keyring <name>\n", name);
printf("\t\tAdds a new keyring with the specified name, protected by the" printf("\t\tAdds a new keyring with the specified name.\n");
" supplied password.\n");
printf("\t%s remove keyring <name>\n", name); printf("\t%s remove keyring <name>\n", name);
printf("\t\tRemoves the specified keyring.\n\n"); printf("\t\tRemoves the specified keyring.\n\n");
@@ -344,10 +342,10 @@ main(int argc, char* argv[])
password); password);
} }
} else if (strcmp(argv[2], "keyring") == 0) { } else if (strcmp(argv[2], "keyring") == 0) {
if (argc < 5) if (argc < 4)
return print_usage(argv[0]); return print_usage(argv[0]);
return add_keyring(argv[3], argv[4]); return add_keyring(argv[3]);
} }
} else if (strcmp(argv[1], "remove") == 0) { } else if (strcmp(argv[1], "remove") == 0) {
if (argc < 3) if (argc < 3)
+1 -7
View File
@@ -187,16 +187,10 @@ BKeyStore::GetNextKey(const char* keyring, BKeyType type, BKeyPurpose purpose,
status_t status_t
BKeyStore::AddKeyring(const char* keyring, const BKey& key) BKeyStore::AddKeyring(const char* keyring)
{ {
BMessage keyMessage;
if (key.Flatten(keyMessage) != B_OK)
return B_BAD_VALUE;
BMessage message(KEY_STORE_ADD_KEYRING); BMessage message(KEY_STORE_ADD_KEYRING);
message.AddString("keyring", keyring); message.AddString("keyring", keyring);
message.AddMessage("key", &keyMessage);
return _SendKeyMessage(message, NULL); return _SendKeyMessage(message, NULL);
} }
+4 -5
View File
@@ -269,13 +269,12 @@ KeyStoreServer::MessageReceived(BMessage* message)
{ {
BMessage keyMessage; BMessage keyMessage;
BString keyring; BString keyring;
if (message->FindString("keyring", &keyring) != B_OK if (message->FindString("keyring", &keyring) != B_OK) {
|| message->FindMessage("key", &keyMessage) != B_OK) {
result = B_BAD_VALUE; result = B_BAD_VALUE;
break; break;
} }
result = _AddKeyring(keyring, keyMessage); result = _AddKeyring(keyring);
if (result == B_OK) if (result == B_OK)
_WriteKeyStoreDatabase(); _WriteKeyStoreDatabase();
@@ -681,12 +680,12 @@ KeyStoreServer::_FindKeyring(const BString& name)
status_t status_t
KeyStoreServer::_AddKeyring(const BString& name, const BMessage& keyMessage) KeyStoreServer::_AddKeyring(const BString& name)
{ {
if (_FindKeyring(name) != NULL) if (_FindKeyring(name) != NULL)
return B_NAME_IN_USE; return B_NAME_IN_USE;
Keyring* keyring = new(std::nothrow) Keyring(name, &keyMessage); Keyring* keyring = new(std::nothrow) Keyring(name);
if (keyring == NULL) if (keyring == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
+1 -2
View File
@@ -47,8 +47,7 @@ private:
Keyring* _FindKeyring(const BString& name); Keyring* _FindKeyring(const BString& name);
status_t _AddKeyring(const BString& name, status_t _AddKeyring(const BString& name);
const BMessage& keyMessage);
status_t _RemoveKeyring(const BString& name); status_t _RemoveKeyring(const BString& name);
status_t _UnlockKeyring(Keyring& keyring); status_t _UnlockKeyring(Keyring& keyring);
+1 -3
View File
@@ -7,14 +7,12 @@
#include "Keyring.h" #include "Keyring.h"
Keyring::Keyring(const char* name, const BMessage* keyMessage) Keyring::Keyring(const char* name)
: :
fName(name), fName(name),
fUnlocked(false), fUnlocked(false),
fModified(false) fModified(false)
{ {
if (keyMessage != NULL)
Unlock(*keyMessage);
} }
+1 -2
View File
@@ -12,8 +12,7 @@
class Keyring { class Keyring {
public: public:
Keyring(const char* name, Keyring(const char* name);
const BMessage* keyMessage = NULL);
~Keyring(); ~Keyring();
const char* Name() const { return fName; } const char* Name() const { return fName; }