summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorFiras Sammoura <fsammoura@google.com>2022-09-15 20:35:02 +0000
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-09-22 21:16:46 +0000
commit2e07bb2896cdc4b905fb8b1463fffe1749bfb025 (patch)
treea46a06a77a413e391a1efe693b4141710c9b4e1c /test
parent053e7446850e3898390916a3b37b5ae188e0894a (diff)
downloadchrome-ec-2e07bb2896cdc4b905fb8b1463fffe1749bfb025.tar.gz
test: Add test for rollback_get_secret
Add tests for rollback_get_secret when the get_latest_rollback fails, returns a trivial secret, and returns a real secret. BRANCH=None BUG=b:242720910 TEST=make run-rollback_secret TEST=make runhosttests Signed-off-by: Firas Sammoura <fsammoura@google.com> Change-Id: I992daf7af3e80dcc4b20412037f792e125866af7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3900486 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Reviewed-by: Bobby Casey <bobbycasey@google.com>
Diffstat (limited to 'test')
-rw-r--r--test/build.mk2
-rw-r--r--test/rollback_secret.c79
-rw-r--r--test/rollback_secret.mocklist7
-rw-r--r--test/rollback_secret.tasklist9
-rw-r--r--test/test_config.h9
5 files changed, 106 insertions, 0 deletions
diff --git a/test/build.mk b/test/build.mk
index 9ab2cf0f7a..73a67a0bb1 100644
--- a/test/build.mk
+++ b/test/build.mk
@@ -83,6 +83,7 @@ test-list-host += power_button
test-list-host += printf
test-list-host += queue
test-list-host += rgb_keyboard
+test-list-host += rollback_secret
test-list-host += rsa
test-list-host += rsa3
test-list-host += rtc
@@ -223,6 +224,7 @@ printf-y=printf.o
queue-y=queue.o
rollback-y=rollback.o
rollback_entropy-y=rollback_entropy.o
+rollback_secret-y=rollback_secret.o
rsa-y=rsa.o
rsa3-y=rsa.o
rtc-y=rtc.o
diff --git a/test/rollback_secret.c b/test/rollback_secret.c
new file mode 100644
index 0000000000..c3e23e4d11
--- /dev/null
+++ b/test/rollback_secret.c
@@ -0,0 +1,79 @@
+/* Copyright 2020 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <stdint.h>
+
+#include "mock/rollback_latest_mock.h"
+#include "rollback.h"
+#include "rollback_private.h"
+#include "string.h"
+#include "system.h"
+#include "test_util.h"
+
+extern int get_latest_rollback(struct rollback_data *data);
+
+test_static int test_get_rollback_secret_latest_rollback_fail(void)
+{
+ struct rollback_data test_data;
+ uint8_t secret[32] = { 0 };
+
+ mock_ctrl_latest_rollback.output_type = GET_LATEST_ROLLBACK_FAIL;
+ TEST_ASSERT(get_latest_rollback(&test_data) == -5);
+
+ TEST_ASSERT(rollback_get_secret(secret) == EC_ERROR_UNKNOWN);
+
+ return EC_SUCCESS;
+}
+
+test_static int test_get_rollback_secret_latest_rollback_secret_zeros(void)
+{
+ struct rollback_data test_data;
+ uint8_t secret[32];
+ const uint8_t zeros_secret[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ };
+
+ mock_ctrl_latest_rollback.output_type = GET_LATEST_ROLLBACK_ZEROS;
+ TEST_ASSERT(get_latest_rollback(&test_data) == EC_SUCCESS);
+ TEST_ASSERT_ARRAY_EQ(test_data.secret, zeros_secret,
+ sizeof(zeros_secret));
+
+ TEST_ASSERT(rollback_get_secret(secret) == EC_ERROR_UNKNOWN);
+
+ return EC_SUCCESS;
+}
+
+test_static int test_get_rollback_secret_latest_rollback_secret_succeed(void)
+{
+ struct rollback_data test_data;
+ uint8_t secret[32];
+ const uint8_t real_secret[] = {
+ 0xcf, 0xe3, 0x23, 0x76, 0x35, 0x04, 0xc2, 0x0f,
+ 0x0d, 0xb6, 0x02, 0xa9, 0x68, 0xba, 0x2a, 0x61,
+ 0x86, 0x2a, 0x85, 0xd1, 0xca, 0x09, 0x54, 0x8a,
+ 0x6b, 0xe2, 0xe3, 0x38, 0xde, 0x5d, 0x59, 0x14,
+ };
+
+ mock_ctrl_latest_rollback.output_type = GET_LATEST_ROLLBACK_REAL;
+ TEST_ASSERT(get_latest_rollback(&test_data) == EC_SUCCESS);
+ TEST_ASSERT_ARRAY_EQ(test_data.secret, real_secret,
+ sizeof(real_secret));
+
+ TEST_ASSERT(rollback_get_secret(secret) == EC_SUCCESS);
+ TEST_ASSERT_ARRAY_EQ(secret, test_data.secret, sizeof(secret));
+
+ return EC_SUCCESS;
+}
+
+void run_test(int argc, const char **argv)
+{
+ RUN_TEST(test_get_rollback_secret_latest_rollback_fail);
+ RUN_TEST(test_get_rollback_secret_latest_rollback_secret_zeros);
+ RUN_TEST(test_get_rollback_secret_latest_rollback_secret_succeed);
+ test_print_result();
+}
diff --git a/test/rollback_secret.mocklist b/test/rollback_secret.mocklist
new file mode 100644
index 0000000000..1a22d1d4b2
--- /dev/null
+++ b/test/rollback_secret.mocklist
@@ -0,0 +1,7 @@
+/* Copyright 2020 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#define CONFIG_TEST_MOCK_LIST \
+ MOCK(ROLLBACK_LATEST)
diff --git a/test/rollback_secret.tasklist b/test/rollback_secret.tasklist
new file mode 100644
index 0000000000..844ddb6c10
--- /dev/null
+++ b/test/rollback_secret.tasklist
@@ -0,0 +1,9 @@
+/* Copyright 2019 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ * See CONFIG_TASK_LIST in config.h for details.
+ */
+#define CONFIG_TEST_TASK_LIST
diff --git a/test/test_config.h b/test/test_config.h
index d72a078434..e113024163 100644
--- a/test/test_config.h
+++ b/test/test_config.h
@@ -112,6 +112,15 @@
#define CONFIG_SHA256
#endif
+#ifdef TEST_ROLLBACK_SECRET
+#define CONFIG_ROLLBACK
+#define CONFIG_ROLLBACK_SECRET_SIZE 32
+#define CONFIG_ROLLBACK_OFF 1
+#define CONFIG_ROLLBACK_SIZE 2
+#undef CONFIG_ROLLBACK_UPDATE
+#define FP_CONTEXT_TPM_BYTES 32
+#endif
+
#ifdef TEST_MOTION_SENSE_FIFO
#define CONFIG_ACCEL_FIFO
#define CONFIG_ACCEL_FIFO_SIZE 256