summaryrefslogtreecommitdiff
path: root/keystore/include
diff options
context:
space:
mode:
authorJanis Danisevskis <jdanis@google.com>2017-11-21 12:30:15 -0800
committerJanis Danisevskis <jdanis@google.com>2017-11-22 13:59:40 -0800
commit8f737ad2c452d589a6670decaed52b00043d6785 (patch)
tree5e3419d80af940645fcd3af79daf783f61c67e42 /keystore/include
parent4a182800b14326134f5c4e4ec2795f8686aff1f4 (diff)
downloadsecurity-8f737ad2c452d589a6670decaed52b00043d6785.tar.gz
Fixed auth_token_table tests
auth_token_table tests did not make the transition to hidle types and were broken. Noww they use the hidle types as well. Also this patch fixes an awkward ownership transfer of an object referred to by a const pointer and reduses the use of the type hw_auth_token. Test: Ran all keystore CTS test as well as the fixed auth_token_table tests Bug: 68149839 Change-Id: Ia69a80fad12edc134646a7b340f8e27ea4da2210
Diffstat (limited to 'keystore/include')
-rw-r--r--keystore/include/keystore/keymaster_tags.h1
-rw-r--r--keystore/include/keystore/keystore_hidl_support.h33
2 files changed, 33 insertions, 1 deletions
diff --git a/keystore/include/keystore/keymaster_tags.h b/keystore/include/keystore/keymaster_tags.h
index 05a33cd9..1b3e71be 100644
--- a/keystore/include/keystore/keymaster_tags.h
+++ b/keystore/include/keystore/keymaster_tags.h
@@ -60,7 +60,6 @@
*/
#include <android/hardware/keymaster/3.0/IHwKeymasterDevice.h>
-#include <hardware/hw_auth_token.h>
#include <type_traits>
namespace keystore {
diff --git a/keystore/include/keystore/keystore_hidl_support.h b/keystore/include/keystore/keystore_hidl_support.h
index 3c64d2af..2a4d1eb4 100644
--- a/keystore/include/keystore/keystore_hidl_support.h
+++ b/keystore/include/keystore/keystore_hidl_support.h
@@ -19,6 +19,7 @@
#define KEYSTORE_KEYSTORE_HIDL_SUPPORT_H_
#include <android/hardware/keymaster/3.0/IKeymasterDevice.h>
+#include <hardware/hw_auth_token.h>
#include <hidl/Status.h>
#include <keystore/keymaster_tags.h>
#include <ostream>
@@ -121,6 +122,38 @@ inline static hidl_vec<uint8_t> authToken2HidlVec(const HardwareAuthToken& token
return result;
}
+template <typename T, typename InIter>
+inline static InIter copy_bytes_from_iterator(T* value, InIter src) {
+ uint8_t* value_ptr = reinterpret_cast<uint8_t*>(value);
+ std::copy(src, src + sizeof(value), value_ptr);
+ return src + sizeof(value);
+}
+
+inline static HardwareAuthToken hidlVec2AuthToken(const hidl_vec<uint8_t>& buffer) {
+ HardwareAuthToken token;
+ static_assert(
+ std::is_same<decltype(token.hmac), ::android::hardware::hidl_array<uint8_t, 32>>::value,
+ "This function assumes token HMAC is 32 bytes, but it might not be.");
+ static_assert(1 /* version size */ + sizeof(token.challenge) + sizeof(token.userId) +
+ sizeof(token.authenticatorId) + sizeof(token.authenticatorType) +
+ sizeof(token.timestamp) + 32 /* HMAC size */
+ == sizeof(hw_auth_token_t),
+ "HardwareAuthToken content size does not match hw_auth_token_t size");
+
+ if (buffer.size() != sizeof(hw_auth_token_t)) return {};
+
+ auto pos = buffer.begin();
+ ++pos; // skip first byte
+ pos = copy_bytes_from_iterator(&token.challenge, pos);
+ pos = copy_bytes_from_iterator(&token.userId, pos);
+ pos = copy_bytes_from_iterator(&token.authenticatorId, pos);
+ pos = copy_bytes_from_iterator(&token.authenticatorType, pos);
+ pos = copy_bytes_from_iterator(&token.timestamp, pos);
+ pos = std::copy(pos, pos + token.hmac.size(), &token.hmac[0]);
+
+ return token;
+}
+
inline std::string hidlVec2String(const hidl_vec<uint8_t>& value) {
return std::string(reinterpret_cast<const std::string::value_type*>(&value[0]), value.size());
}