summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Hsieh <victorhsieh@google.com>2019-10-02 14:08:43 -0700
committerandroid-build-merger <android-build-merger@google.com>2019-10-02 14:08:43 -0700
commit96308c7c84f6ad51297ba13f6d92cce25abb80f9 (patch)
treebdcd16c0a69733f7eb0e4c8a31ea4eabe491588f
parent471e961567c52afc5a00370452e5f1b4f3cab8cd (diff)
parent3f903ce42208f1f03b007c33ede1ee70e5856a7d (diff)
downloadsecurity-96308c7c84f6ad51297ba13f6d92cce25abb80f9.tar.gz
Merge "New APIs for a keystore client to list and get keys" am: e7dc464319
am: 3f903ce422 Change-Id: I9b341880e8610795e1fffc477f89a2467a9ba01d
-rw-r--r--keystore/include/keystore/keystore_client.h9
-rw-r--r--keystore/include/keystore/keystore_client_impl.h4
-rw-r--r--keystore/keystore_client_impl.cpp16
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_++;
}