summaryrefslogtreecommitdiff
path: root/tests/vboot_api_kernel5_tests.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/vboot_api_kernel5_tests.c')
-rw-r--r--tests/vboot_api_kernel5_tests.c75
1 files changed, 45 insertions, 30 deletions
diff --git a/tests/vboot_api_kernel5_tests.c b/tests/vboot_api_kernel5_tests.c
index 04ee7669..d752f6b7 100644
--- a/tests/vboot_api_kernel5_tests.c
+++ b/tests/vboot_api_kernel5_tests.c
@@ -10,10 +10,14 @@
#include <stdlib.h>
#include <string.h>
+#include "2sysincludes.h"
+#include "2common.h"
+#include "2rsa.h"
#include "gbb_header.h"
#include "host_common.h"
#include "load_kernel_fw.h"
#include "test_common.h"
+#include "vb2_common.h"
#include "vboot_api.h"
#include "vboot_common.h"
#include "vboot_kernel.h"
@@ -31,8 +35,7 @@ static uint8_t kernel_buffer[80000];
static int key_block_verify_fail; /* 0=ok, 1=sig, 2=hash */
static int preamble_verify_fail;
static int verify_data_fail;
-static RSAPublicKey *mock_data_key;
-static int mock_data_key_allocated;
+static int unpack_key_fail;
static VbNvContext vnc;
static VbKeyBlockHeader kbh;
@@ -69,9 +72,6 @@ static void ResetMocks(void)
preamble_verify_fail = 0;
verify_data_fail = 0;
- mock_data_key = (RSAPublicKey *)"TestDataKey";
- mock_data_key_allocated = 0;
-
memset(&kbh, 0, sizeof(kbh));
kbh.data_key.key_version = 2;
kbh.key_block_flags = -1;
@@ -96,53 +96,68 @@ static void copy_kbh(void)
}
/* Mocks */
-int KeyBlockVerify(const VbKeyBlockHeader *block, uint64_t size,
- const VbPublicKey *key, int hash_only) {
- hash_only_check = hash_only;
+int vb2_unpack_key(struct vb2_public_key *key,
+ const uint8_t *buf,
+ uint32_t size)
+{
+ if (--unpack_key_fail == 0)
+ return VB2_ERROR_MOCK;
+
+ return VB2_SUCCESS;
+}
+
+int vb2_verify_keyblock(struct vb2_keyblock *block,
+ uint32_t size,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb)
+{
+ hash_only_check = 0;
if (key_block_verify_fail)
- return VBERROR_SIMULATED;
+ return VB2_ERROR_MOCK;
/* Use this as an opportunity to override the key block */
memcpy((void *)block, &kbh, sizeof(kbh));
- return VBERROR_SUCCESS;
+ return VB2_SUCCESS;
}
-RSAPublicKey *PublicKeyToRSA(const VbPublicKey *key)
+int vb2_verify_keyblock_hash(const struct vb2_keyblock *block,
+ uint32_t size,
+ const struct vb2_workbuf *wb)
{
- TEST_EQ(mock_data_key_allocated, 0, " mock data key not allocated");
-
- if (mock_data_key)
- mock_data_key_allocated++;
+ hash_only_check = 1;
- return mock_data_key;
-}
+ if (key_block_verify_fail)
+ return VB2_ERROR_MOCK;
-void RSAPublicKeyFree(RSAPublicKey* key)
-{
- TEST_EQ(mock_data_key_allocated, 1, " mock data key allocated");
- TEST_PTR_EQ(key, mock_data_key, " data key ptr");
- mock_data_key_allocated--;
+ /* Use this as an opportunity to override the key block */
+ memcpy((void *)block, &kbh, sizeof(kbh));
+ return VB2_SUCCESS;
}
-int VerifyKernelPreamble(const VbKernelPreambleHeader *preamble,
- uint64_t size, const RSAPublicKey *key)
+int vb2_verify_kernel_preamble(struct vb2_kernel_preamble *preamble,
+ uint32_t size,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb)
{
if (preamble_verify_fail)
- return VBERROR_SIMULATED;
+ return VB2_ERROR_MOCK;
/* Use this as an opportunity to override the preamble */
memcpy((void *)preamble, &kph, sizeof(kph));
- return VBERROR_SUCCESS;
+ return VB2_SUCCESS;
}
-int VerifyData(const uint8_t *data, uint64_t size, const VbSignature *sig,
- const RSAPublicKey *key)
+int vb2_verify_data(const uint8_t *data,
+ uint32_t size,
+ struct vb2_signature *sig,
+ const struct vb2_public_key *key,
+ const struct vb2_workbuf *wb)
{
if (verify_data_fail)
- return VBERROR_SIMULATED;
+ return VB2_ERROR_MOCK;
- return VBERROR_SUCCESS;
+ return VB2_SUCCESS;
}
VbError_t VbExNvStorageRead(uint8_t *buf)