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:
parent
8775bd129d
commit
d4d6d12393
@ -51,8 +51,7 @@ public:
|
||||
|
||||
// Keyrings
|
||||
|
||||
status_t AddKeyring(const char* keyring,
|
||||
const BKey& key);
|
||||
status_t AddKeyring(const char* keyring);
|
||||
status_t RemoveKeyring(const char* keyring);
|
||||
|
||||
status_t GetNextKeyring(uint32& cookie,
|
||||
|
@ -57,12 +57,11 @@ remove_password(const char* keyring, const char* identifier,
|
||||
|
||||
|
||||
int
|
||||
add_keyring(const char* keyring, const char* passwordString)
|
||||
add_keyring(const char* keyring)
|
||||
{
|
||||
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) {
|
||||
printf("failed to add keyring: %s\n", strerror(result));
|
||||
return 2;
|
||||
@ -257,9 +256,8 @@ print_usage(const char* name)
|
||||
" [<secondaryIdentifier>]\n", name);
|
||||
printf("\t\tRemoves the specified password from the specified keyring.\n\n");
|
||||
|
||||
printf("\t%s add keyring <name> <password>\n", name);
|
||||
printf("\t\tAdds a new keyring with the specified name, protected by the"
|
||||
" supplied password.\n");
|
||||
printf("\t%s add keyring <name>\n", name);
|
||||
printf("\t\tAdds a new keyring with the specified name.\n");
|
||||
printf("\t%s remove keyring <name>\n", name);
|
||||
printf("\t\tRemoves the specified keyring.\n\n");
|
||||
|
||||
@ -344,10 +342,10 @@ main(int argc, char* argv[])
|
||||
password);
|
||||
}
|
||||
} else if (strcmp(argv[2], "keyring") == 0) {
|
||||
if (argc < 5)
|
||||
if (argc < 4)
|
||||
return print_usage(argv[0]);
|
||||
|
||||
return add_keyring(argv[3], argv[4]);
|
||||
return add_keyring(argv[3]);
|
||||
}
|
||||
} else if (strcmp(argv[1], "remove") == 0) {
|
||||
if (argc < 3)
|
||||
|
@ -187,16 +187,10 @@ BKeyStore::GetNextKey(const char* keyring, BKeyType type, BKeyPurpose purpose,
|
||||
|
||||
|
||||
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);
|
||||
message.AddString("keyring", keyring);
|
||||
message.AddMessage("key", &keyMessage);
|
||||
|
||||
return _SendKeyMessage(message, NULL);
|
||||
}
|
||||
|
||||
|
@ -269,13 +269,12 @@ KeyStoreServer::MessageReceived(BMessage* message)
|
||||
{
|
||||
BMessage keyMessage;
|
||||
BString keyring;
|
||||
if (message->FindString("keyring", &keyring) != B_OK
|
||||
|| message->FindMessage("key", &keyMessage) != B_OK) {
|
||||
if (message->FindString("keyring", &keyring) != B_OK) {
|
||||
result = B_BAD_VALUE;
|
||||
break;
|
||||
}
|
||||
|
||||
result = _AddKeyring(keyring, keyMessage);
|
||||
result = _AddKeyring(keyring);
|
||||
if (result == B_OK)
|
||||
_WriteKeyStoreDatabase();
|
||||
|
||||
@ -681,12 +680,12 @@ KeyStoreServer::_FindKeyring(const BString& name)
|
||||
|
||||
|
||||
status_t
|
||||
KeyStoreServer::_AddKeyring(const BString& name, const BMessage& keyMessage)
|
||||
KeyStoreServer::_AddKeyring(const BString& name)
|
||||
{
|
||||
if (_FindKeyring(name) != NULL)
|
||||
return B_NAME_IN_USE;
|
||||
|
||||
Keyring* keyring = new(std::nothrow) Keyring(name, &keyMessage);
|
||||
Keyring* keyring = new(std::nothrow) Keyring(name);
|
||||
if (keyring == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
|
@ -47,8 +47,7 @@ private:
|
||||
|
||||
Keyring* _FindKeyring(const BString& name);
|
||||
|
||||
status_t _AddKeyring(const BString& name,
|
||||
const BMessage& keyMessage);
|
||||
status_t _AddKeyring(const BString& name);
|
||||
status_t _RemoveKeyring(const BString& name);
|
||||
|
||||
status_t _UnlockKeyring(Keyring& keyring);
|
||||
|
@ -7,14 +7,12 @@
|
||||
#include "Keyring.h"
|
||||
|
||||
|
||||
Keyring::Keyring(const char* name, const BMessage* keyMessage)
|
||||
Keyring::Keyring(const char* name)
|
||||
:
|
||||
fName(name),
|
||||
fUnlocked(false),
|
||||
fModified(false)
|
||||
{
|
||||
if (keyMessage != NULL)
|
||||
Unlock(*keyMessage);
|
||||
}
|
||||
|
||||
|
||||
|
@ -12,8 +12,7 @@
|
||||
|
||||
class Keyring {
|
||||
public:
|
||||
Keyring(const char* name,
|
||||
const BMessage* keyMessage = NULL);
|
||||
Keyring(const char* name);
|
||||
~Keyring();
|
||||
|
||||
const char* Name() const { return fName; }
|
||||
|
Loading…
Reference in New Issue
Block a user