From a7f3965da63b8f43945f19b7823e26db2aab4098 Mon Sep 17 00:00:00 2001 From: kxtzownsu Date: Sat, 7 Dec 2024 13:50:19 -0500 Subject: [PATCH] start of tpm2 api --- include/arg_checks.h | 10 +++++++++- include/hex_utils.h | 8 +++++++- include/sysinfo.h | 17 +++++++++++++++-- include/tpm.h | 9 ++++++++- include/ui.h | 6 +++--- src/KVS/tpm.c | 25 +++++++++++++++++++++++-- src/KVS/ui.c | 6 +++--- 7 files changed, 68 insertions(+), 13 deletions(-) diff --git a/include/arg_checks.h b/include/arg_checks.h index 1e22c5e..9428402 100644 --- a/include/arg_checks.h +++ b/include/arg_checks.h @@ -1,5 +1,11 @@ // credit to Hannah / ZegLol for making this! +#ifndef ARG_CHECKS_H +#define ARG_CHECKS_H + +#include + + int gargc; char **gargv; @@ -29,4 +35,6 @@ char *fequals(const char *arg) } return ""; -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/include/hex_utils.h b/include/hex_utils.h index 925c851..da3733a 100644 --- a/include/hex_utils.h +++ b/include/hex_utils.h @@ -1,5 +1,9 @@ +#ifndef HEX_UTILS_H +#define HEX_UTILS_H + #include #include +#include uint32_t convert_to_uint32(const char *str) { char *endptr; @@ -25,4 +29,6 @@ void print_hex(const uint8_t *data, uint32_t size) { for (uint32_t i = 0; i < size; i++) { printf("%02x ", data[i]); } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/include/sysinfo.h b/include/sysinfo.h index c3c20f0..0718a79 100644 --- a/include/sysinfo.h +++ b/include/sysinfo.h @@ -1,3 +1,11 @@ +#ifndef SYSINFO_H +#define SYSINFO_H + +#include +#include + +#include "tpm.h" + void trim_newline(char* str) { size_t len = strlen(str); if (len > 0 && str[len - 1] == '\n') { @@ -16,7 +24,7 @@ const char* getFirmwareVersion(){ if (fptr == NULL) { printf("Error reading Firmware Version \n"); printf("Please report as a bug at https://github.com/kxtzownsu/KVS-private\n"); - + sleep(86400); // sleep for 1d if error return "Error!"; } @@ -26,4 +34,9 @@ const char* getFirmwareVersion(){ trim_newline(firmwareVersion); return firmwareVersion; -} \ No newline at end of file +} + +// uint32_t getKernelVersion(){ +// } + +#endif \ No newline at end of file diff --git a/include/tpm.h b/include/tpm.h index e23d8d9..25960ca 100644 --- a/include/tpm.h +++ b/include/tpm.h @@ -1 +1,8 @@ -void tpm_write(char* index, char* bytes); \ No newline at end of file +#ifndef TPM_H +#define TPM_H +#include + +int tpm_nvwrite(char* index, char* bytes, char* offset, char* authType, char* indexPassword); +int tpm_nvread(char* index, char* size, char* offset, char* authType, char* indexPassword); + +#endif \ No newline at end of file diff --git a/include/ui.h b/include/ui.h index 97d6f9b..bfe8efb 100644 --- a/include/ui.h +++ b/include/ui.h @@ -1,7 +1,7 @@ -#ifndef KVS2_UI_H -#define KVS2_UI_H +#ifndef UI_H +#define UI_H void ui_flash(char* flashtype); -void ui_header(char* fwver, char* kernver, char* tpmver, char* fwmp, char* gscver, char* gsctype); +void ui_header(const char* fwver, char* kernver, char* tpmver, char* fwmp, char* gscver, char* gsctype); #endif \ No newline at end of file diff --git a/src/KVS/tpm.c b/src/KVS/tpm.c index e59c818..7af7788 100644 --- a/src/KVS/tpm.c +++ b/src/KVS/tpm.c @@ -1,5 +1,26 @@ #include -void tpm_write(char* index, char* bytes){ - printf("wip, index: %s, bytes: %s", index, bytes); + +/* ARGS: +index = that what TPM2 index to read from, e.g: "0x1008" +size = how many bytes should we read +offset = how far into the index should we start reading +authType = either owner, index, or platform +indexPassword = if index authType is chosen, enter your indexPassword, otherwise pass nothing +*/ +int tpm_nvwrite(char* index, char* bytes, char* offset, char* authType, char* indexPassword){ + printf ("wip, index: %s, bytes: '%s', offset: %s, authType: %s, indexPassword: %s", index, bytes, offset, authType, indexPassword); + return 0; +} + + +/* ARGS: +index = that what TPM2 index to read from, e.g: "0x1008" +size = how many bytes should we read +offset = how far into the index should we start reading +authType = either owner, index, or platform +indexPassword = if index authType is chosen, enter your indexPassword, otherwise pass nothing +*/ +int tpm_nvread(char* index, char* size, char* offset, char* authType, char* indexPassword){ + printf ("wip, index: %s, size: '%s', offset: %s, authType: %s, indexPassword: %s", index, size, offset, authType, indexPassword); } \ No newline at end of file diff --git a/src/KVS/ui.c b/src/KVS/ui.c index 9aace05..a628218 100644 --- a/src/KVS/ui.c +++ b/src/KVS/ui.c @@ -66,16 +66,16 @@ void ui_flash(char* flashtype) { if (flashtype == "tpm0"){ if (!strcmp(structtype, "v0")) { - tpm_write("0x1008", kvgout_v0); + tpm_nvwrite("0x1008", kvgout_v0, "0", "platform", ""); } else if (!strcmp(structtype, "v1")) { - tpm_write("0x1008", kvgout_v1); + tpm_nvwrite("0x1008", kvgout_v1, "0", "platform", ""); } } else if (flashtype == "rmasmoke"){ printf("using rmasmoke\n"); } } -void ui_header(char* fwver, char* kernver, char* tpmver, char* fwmp, char* gscver, char* gsctype){ +void ui_header(const char* fwver, char* kernver, char* tpmver, char* fwmp, char* gscver, char* gsctype){ printf("KVS: Kernel Version Switcher (codename Maglev, bid: 2.0.0))\n"); printf("FW Version: %s\n", fwver); printf("Kernel Version: %s\n", kernver);