From 03a84249b537ecfe55fee6a35c0d0557235ce405 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Sun, 24 Jun 2012 14:56:35 +0200 Subject: [PATCH] Add app enumeration and removal to the keystore cli tool. --- src/bin/keystore/keystore.cpp | 68 +++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 3 deletions(-) diff --git a/src/bin/keystore/keystore.cpp b/src/bin/keystore/keystore.cpp index 9699cf4c28..865f433a98 100644 --- a/src/bin/keystore/keystore.cpp +++ b/src/bin/keystore/keystore.cpp @@ -191,6 +191,46 @@ remove_keyring_from_master(const char* keyring) } +int +list_applications(const char* keyring) +{ + BKeyStore keyStore; + uint32 cookie = 0; + + while (true) { + BString signature; + status_t result = keyStore.GetNextApplication(keyring, + cookie, signature); + if (result == B_ENTRY_NOT_FOUND) + break; + + if (result != B_OK) { + printf("failed to get next application: %s\n", strerror(result)); + return 2; + } + + printf("application: \"%s\"\n", signature.String()); + } + + return 0; +} + + +int +remove_application(const char* keyring, const char* signature) +{ + BKeyStore keyStore; + + status_t result = keyStore.RemoveApplication(keyring, signature); + if (result != B_OK) { + printf("failed to remove application: %s\n", strerror(result)); + return 3; + } + + return 0; +} + + int print_usage(const char* name) { @@ -199,7 +239,10 @@ print_usage(const char* name) printf("\t\tLists all passwords of the specified keyring or from the" " master keyring if none is supplied.\n"); printf("\t%s list keyrings\n", name); - printf("\t\tLists all keyrings.\n\n"); + printf("\t\tLists all keyrings.\n"); + printf("\t%s list applications []\n", name); + printf("\t\tLists the applications that have been granted permanent access" + " to a keyring once it is unlocked.\n\n"); printf("\t%s add password [] " "\n", name); @@ -216,8 +259,7 @@ print_usage(const char* name) printf("\t%s add keyring \n", name); printf("\t\tAdds a new keyring with the specified name, protected by the" - " supplied password.\n\n"); - + " supplied password.\n"); printf("\t%s remove keyring \n", name); printf("\t\tRemoves the specified keyring.\n\n"); @@ -237,6 +279,13 @@ print_usage(const char* name) printf("\t\tRemove the access key for the specified keyring from the" " master keyring.\n\n"); + printf("\t%s remove application \n", name); + printf("\t\tRemove permanent access for the application with the given" + " signature from the master keyring.\n"); + printf("\t%s remove application from \n", name); + printf("\t\tRemove permanent access for the application with the given" + " signature from the specified keyring.\n"); + return 1; } @@ -257,6 +306,8 @@ main(int argc, char* argv[]) return list_passwords(argc > 3 ? argv[3] : NULL); if (strcmp(argv[2], "keyrings") == 0) return list_keyrings(); + if (strcmp(argv[2], "applications") == 0) + return list_applications(argc > 3 ? argv[3] : NULL); } else if (strcmp(argv[1], "add") == 0) { if (argc < 3) return print_usage(argv[0]); @@ -327,6 +378,17 @@ main(int argc, char* argv[]) } else if (strcmp(argv[2], "keyring") == 0) { if (argc == 4) return remove_keyring(argv[3]); + } else if (strcmp(argv[2], "application") == 0) { + const char* keyring = NULL; + const char* signature = NULL; + if (argc == 6 && strcmp(argv[3], "from") == 0) { + keyring = argv[4]; + signature = argv[5]; + } else if (argc == 4) + signature = argv[3]; + + if (signature != NULL) + return remove_application(keyring, signature); } } else if (strcmp(argv[1], "status") == 0) { if (argc != 2 && argc != 3)