diff options
author | Victor Hsieh <victorhsieh@google.com> | 2019-09-05 14:27:38 -0700 |
---|---|---|
committer | Victor Hsieh <victorhsieh@google.com> | 2019-09-25 09:32:55 -0700 |
commit | 8b3b6fc1f72f14fbb25c6892f63430a279cb3ccf (patch) | |
tree | 8e1269a5b4bdec3be9b9583c536e4c0e82033a91 | |
parent | aad4f6ed19d739da43bfdfa94407c43b90ef48a8 (diff) | |
download | security-8b3b6fc1f72f14fbb25c6892f63430a279cb3ccf.tar.gz |
New APIs for a keystore client to list and get keys
Test: client is able to list and get keys given sepolicy
Bug: 112038744
Change-Id: Ib7e2e9cc7cff6bdf4e4aba2499b9bf16a6db1d4f
-rw-r--r-- | keystore/include/keystore/keystore_client.h | 9 | ||||
-rw-r--r-- | keystore/include/keystore/keystore_client_impl.h | 4 | ||||
-rw-r--r-- | keystore/keystore_client_impl.cpp | 16 |
3 files changed, 28 insertions, 1 deletions
diff --git a/keystore/include/keystore/keystore_client.h b/keystore/include/keystore/keystore_client.h index d6a48076..d8e63c4b 100644 --- a/keystore/include/keystore/keystore_client.h +++ b/keystore/include/keystore/keystore_client.h @@ -15,6 +15,8 @@ #ifndef KEYSTORE_KEYSTORE_CLIENT_H_ #define KEYSTORE_KEYSTORE_CLIENT_H_ +#include <memory> +#include <optional> #include <set> #include <string> #include <vector> @@ -173,6 +175,13 @@ class KeystoreClient { // caller's key store starting with |prefix|. Returns true on success. virtual bool listKeys(const std::string& prefix, std::vector<std::string>* key_name_list) = 0; + // Provides a |key_name_list| containing all existing key names in the + // caller's key store starting with |prefix|. Returns true on success. + virtual bool listKeysOfUid(const std::string& prefix, int uid, + std::vector<std::string>* key_name_list) = 0; + + virtual std::optional<std::vector<uint8_t>> getKey(const std::string& alias, int uid) = 0; + private: DISALLOW_COPY_AND_ASSIGN(KeystoreClient); }; diff --git a/keystore/include/keystore/keystore_client_impl.h b/keystore/include/keystore/keystore_client_impl.h index 0bcef98c..6726fe56 100644 --- a/keystore/include/keystore/keystore_client_impl.h +++ b/keystore/include/keystore/keystore_client_impl.h @@ -19,6 +19,7 @@ #include <future> #include <map> +#include <optional> #include <string> #include <vector> @@ -81,6 +82,9 @@ class KeystoreClientImpl : public KeystoreClient { KeyStoreNativeReturnCode abortOperation(uint64_t handle) override; bool doesKeyExist(const std::string& key_name) override; bool listKeys(const std::string& prefix, std::vector<std::string>* key_name_list) override; + bool listKeysOfUid(const std::string& prefix, int uid, + std::vector<std::string>* key_name_list) override; + std::optional<std::vector<uint8_t>> getKey(const std::string& alias, int uid) override; private: // Returns an available virtual operation handle. diff --git a/keystore/keystore_client_impl.cpp b/keystore/keystore_client_impl.cpp index b9a142e5..3fca4c9d 100644 --- a/keystore/keystore_client_impl.cpp +++ b/keystore/keystore_client_impl.cpp @@ -17,6 +17,7 @@ #include "keystore/keystore_client_impl.h" #include <future> +#include <optional> #include <string> #include <vector> @@ -441,9 +442,14 @@ bool KeystoreClientImpl::doesKeyExist(const std::string& key_name) { bool KeystoreClientImpl::listKeys(const std::string& prefix, std::vector<std::string>* key_name_list) { + return listKeysOfUid(prefix, kDefaultUID, key_name_list); +} + +bool KeystoreClientImpl::listKeysOfUid(const std::string& prefix, int uid, + std::vector<std::string>* key_name_list) { String16 prefix16(prefix.data(), prefix.size()); std::vector<::android::String16> matches; - auto binder_result = keystore_->list(prefix16, kDefaultUID, &matches); + auto binder_result = keystore_->list(prefix16, uid, &matches); if (!binder_result.isOk()) return false; for (const auto& match : matches) { @@ -453,6 +459,14 @@ bool KeystoreClientImpl::listKeys(const std::string& prefix, return true; } +std::optional<std::vector<uint8_t>> KeystoreClientImpl::getKey(const std::string& alias, int uid) { + String16 alias16(alias.data(), alias.size()); + std::vector<uint8_t> output; + auto binder_result = keystore_->get(alias16, uid, &output); + if (!binder_result.isOk()) return std::nullopt; + return output; +} + uint64_t KeystoreClientImpl::getNextVirtualHandle() { return next_virtual_handle_++; } |