From e206028bb2d1a2c9f472778e8429ca87e8ad3ac2 Mon Sep 17 00:00:00 2001 From: Matthew Shyu Date: Thu, 04 Jan 2018 07:57:03 +0000 Subject: gatekeeper: fix com.android.cts.devicepolicy.DeviceOwnerTest#testKeyManagement [1/2] PD# 158086 Soft gatekeeper should calculate valid hmac based on default key Signed-off-by: Matthew Shyu Change-Id: I5d796d611f2871c2d054122170e91b54c61f1b1d --- diff --git a/soft/SoftGateKeeper.h b/soft/SoftGateKeeper.h index f646f70..ddd0cff 100644 --- a/soft/SoftGateKeeper.h +++ b/soft/SoftGateKeeper.h @@ -21,6 +21,7 @@ extern "C" { #include #include +#include #include } @@ -32,6 +33,8 @@ extern "C" { #include #include +#define HMAC_SHA_256_KEY_SIZE 32 + namespace gatekeeper { struct fast_hash_t { @@ -92,9 +95,15 @@ public: } virtual void ComputeSignature(uint8_t *signature, uint32_t signature_length, - const uint8_t *, uint32_t, const uint8_t *, const uint32_t) const { + const uint8_t *key, uint32_t key_length, const uint8_t *message, const uint32_t length) const { if (signature == NULL) return; + uint8_t buf[HMAC_SHA_256_KEY_SIZE]; + size_t buf_len; + HMAC(EVP_sha256(), key, key_length, message, length, buf, (unsigned int *)&buf_len); + size_t to_write = buf_len; + if (buf_len > signature_length) to_write = signature_length; memset(signature, 0, signature_length); + memcpy(signature, buf, to_write); } virtual uint64_t GetMillisecondsSinceBoot() const { -- cgit