Skip to content

Commit

Permalink
[BugFix][ca_traid_test]: Simplify the tool
Browse files Browse the repository at this point in the history
[Desc]:
1. initlize store to false
2. ca_triad_tool only provision data into TEE protected storage,
using set_model if write datas in AP.
2. aligin with webkit codestyle.

Signed-off-by: pengyinjie <[email protected]>
  • Loading branch information
XMPengYinjie committed Dec 27, 2024
1 parent 79e6f83 commit 9cbbe2e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 71 deletions.
71 changes: 1 addition & 70 deletions ca/triad/triad_ca_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@
#include <stdio.h>
#include <string.h>

#if defined(CONFIG_LIB_TEEC)
#include <tee_client_api.h>
#include <teec_trace.h>
#endif

#include <triad_ta.h>

#if defined(CONFIG_LIB_TEEC)
int triad_store_did(uint8_t* did, uint16_t len)
{
TEEC_Result res = TEEC_ERROR_GENERIC;
Expand Down Expand Up @@ -430,70 +427,4 @@ int triad_get_hmac(uint8_t* input, uint16_t inlen,
TEEC_FinalizeContext(&ctx);
exit:
return res;
}
#else /* !CONFIG_LIB_TEEC */
static int load_data(const char* filename, uint8_t* data, uint16_t len)
{
ssize_t bytes_read;
int fd;

fd = open(filename, O_RDONLY);
if (fd == -1) {
return -1;
}

memset(data, 0, len);
bytes_read = read(fd, data, len);
if (bytes_read == -1) {
close(fd);
return -1;
}

close(fd);
return 0;
}

static int store_data(const char* filename, uint8_t* data, uint16_t len)
{
ssize_t bytes_write;
int fd;

fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd == -1) {
return -1;
}

bytes_write = write(fd, data, len);
if (bytes_write < -1) {
close(fd);
return -1;
}

close(fd);
return 0;
}

int triad_store_did(uint8_t* did, uint16_t len)
{
const char* filename = "/data/triad_did.txt";
return store_data(filename, did, len);
}

int triad_load_did(uint8_t* did, uint16_t len)
{
const char* filename = "/data/triad_did.txt";
return load_data(filename, did, len);
}

int triad_store_key(uint8_t* key, uint16_t len)
{
const char* filename = "/data/triad_key.txt";
return store_data(filename, key, len);
}

int triad_load_key(uint8_t* key, uint16_t len)
{
const char* filename = "/data/triad_key.txt";
return load_data(filename, key, len);
}
#endif
}
2 changes: 1 addition & 1 deletion ca/triad/triad_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int main(int argc, FAR char* argv[])
return -1;
}

bool store;
bool store = false;
if (argc == 2) {
if (strcmp(argv[1], "store") == 0) {
store = true;
Expand Down
1 change: 1 addition & 0 deletions ca/triad/triad_tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
static void usage(void)
{
printf("usage:\n"
"\tATTENTION: ca_triad_tool ONLY provision data into TEE protected storage.\n"
"\tca_triad_tool set did <did_string> \n"
"\tca_triad_tool get did \n"
"\tca_triad_tool set key <key_string> \n"
Expand Down

0 comments on commit 9cbbe2e

Please sign in to comment.