-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug fixes #75
Bug fixes #75
Changes from all commits
12cc2cd
2058d5e
7e9274c
2d7dcdb
e0fe9bf
3850de9
210aaea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,37 @@ const struct signature_type_info signature_type_list[] = { | |
static uint8_t append[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; | ||
static uint8_t replace[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; | ||
|
||
/* | ||
* check it whether given variable is trustedcadb | ||
*/ | ||
bool is_trustedcadb_variable(const char *variable_name) | ||
{ | ||
int len = strlen(variable_name); | ||
|
||
if (memcmp(variable_name, TRUSTEDCADB_VARIABLE, len) == 0) | ||
return true; | ||
|
||
return false; | ||
} | ||
|
||
void print_timestamp(timestamp_t t) | ||
{ | ||
printf("%04d-%02d-%02d %02d:%02d:%02d UTC\n", t.year, t.month, t.day, t.hour, t.minute, | ||
t.second); | ||
} | ||
|
||
void read_timestamp(const uint8_t *esl_data) | ||
{ | ||
timestamp_t timestamp; | ||
|
||
if (esl_data == NULL) | ||
return; | ||
|
||
memcpy(×tamp, esl_data + 1, TIMESTAMP_LEN - 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we skip the first byte of the timestamp here? Also, since this function does not do any check on the size of the buffer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the structure of the plpks_get_variable under linux/arch/powerpc/platforms/pseries/plpks-secvar.c, it seems the esl_data size will always be fixed to align with timestamp_len, my question is that do we support variable key sizes for the secure variables? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't warrant a comment as per my understanding because we have used TIMESTAMP_LEN at multiple places and I don't think there can be a scenario where we will get esl_data_size less than the TIMESTAMP_LEN. |
||
printf("\tTimestamp: "); | ||
print_timestamp(timestamp); | ||
} | ||
|
||
/* | ||
* creates the append header using append flag | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,7 @@ static int update_variable(const char *variable_name, const uint8_t *auth_data, | |
prlog(PR_INFO, "\tappend update: %s\n\n", (append_update ? "True" : "False")); | ||
|
||
if (*new_esl_data != NULL) { | ||
read_timestamp(*new_esl_data); | ||
rc = print_esl_buffer((*new_esl_data + TIMESTAMP_LEN), | ||
(*new_esl_data_size - TIMESTAMP_LEN), variable_name); | ||
if (rc != SUCCESS) | ||
|
@@ -91,8 +92,10 @@ static int get_current_esl_data(const uint8_t *esl_file, uint8_t **current_esl_d | |
size_t buffer_size = 0; | ||
uint8_t *buffer = NULL; | ||
|
||
if (is_file((char *)esl_file) != SUCCESS) | ||
if (is_file((char *)esl_file) != SUCCESS) { | ||
prlog(PR_ERR, "ERROR: %s is not a valid file\n", (char *)esl_file); | ||
return INVALID_FILE; | ||
} | ||
|
||
buffer = (uint8_t *)get_data_from_file((char *)esl_file, SIZE_MAX, &buffer_size); | ||
if (buffer != NULL) { | ||
|
@@ -101,15 +104,17 @@ static int get_current_esl_data(const uint8_t *esl_file, uint8_t **current_esl_d | |
free(buffer); | ||
buffer = NULL; | ||
buffer_size = 0; | ||
} else if (buffer_size != TIMESTAMP_LEN) { | ||
} else { | ||
if (verbose >= PR_INFO) | ||
read_timestamp(buffer); | ||
rc = validate_esl(buffer + TIMESTAMP_LEN, buffer_size - TIMESTAMP_LEN); | ||
if (rc != SUCCESS) { | ||
free(buffer); | ||
return rc; | ||
} | ||
} | ||
} else | ||
return INVALID_FILE; | ||
prlog(PR_WARNING, "WARNING: %s file does not have data\n", (char *)esl_file); | ||
Comment on lines
-112
to
+117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we not returning an error code here? It seems like this can only be reached if we fail to allocate memory for the file, or fail to read from the file ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additional note: it appears There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Acknowledged, we should return INVALID_FILE in this case as it will avoid unnecessary operations at a later stage. |
||
|
||
*current_esl_data = buffer; | ||
*current_esl_data_size = buffer_size; | ||
|
@@ -127,8 +132,10 @@ static int get_auth_data(const char *auth_file, uint8_t **auth_data, size_t *aut | |
size_t buffer_size = 0; | ||
uint8_t *buffer = NULL; | ||
|
||
if (is_file((char *)auth_file) != SUCCESS) | ||
if (is_file((char *)auth_file) != SUCCESS) { | ||
prlog(PR_ERR, "ERROR: %s is not a valid file\n", (char *)auth_file); | ||
return INVALID_FILE; | ||
} | ||
|
||
buffer = (uint8_t *)get_data_from_file((char *)auth_file, SIZE_MAX, &buffer_size); | ||
if (buffer != NULL) { | ||
|
@@ -137,8 +144,10 @@ static int get_auth_data(const char *auth_file, uint8_t **auth_data, size_t *aut | |
free(buffer); | ||
return rc; | ||
} | ||
} else | ||
} else { | ||
prlog(PR_WARNING, "WARNING: %s file does not have data\n", (char *)auth_file); | ||
return INVALID_FILE; | ||
} | ||
|
||
*append_update = extract_append_header(buffer, buffer_size); | ||
*auth_data = buffer; | ||
|
@@ -463,17 +472,17 @@ int validate_variables_arguments(struct verify_args *args) | |
"<var_name 1> <var_auth_file 1>" | ||
"...<var_name N> <var_auth_file N>\n"); | ||
return ARG_PARSE_FAIL; | ||
} else if (args->current_variable_size != 0 && args->current_variable_size % 2) { | ||
prlog(PR_ERR, "ERROR: current variable argument should be like -c " | ||
"<var_name 1> <var_ESL_file 1>...<var_name N> <var_ESL_file N>\n"); | ||
return ARG_PARSE_FAIL; | ||
} | ||
|
||
if (args->current_variable_size != 0) { | ||
if ((args->update_variable_size && args->variable_path == NULL) || | ||
args->current_variable_size != 0) { | ||
if (args->write_flag) { | ||
prlog(PR_ERR, "ERROR: cannot update files if current variable " | ||
"files are given. remove -w\n"); | ||
return ARG_PARSE_FAIL; | ||
} else if (args->current_variable_size % 2) { | ||
prlog(PR_ERR, "ERROR: current variable argument should be like -c " | ||
"<var_name 1> <var_ESL_file 1>" | ||
"...<var_name N> <var_ESL_file N>\n"); | ||
prlog(PR_ERR, | ||
"ERROR: cannot update files. remove -w. it is available when you use -u with -p\n"); | ||
return ARG_PARSE_FAIL; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,7 +126,12 @@ static int read_cert(const uint8_t *cert_data, const size_t cert_data_len, const | |
rc = validate_x509_certificate(x509); | ||
if (rc) | ||
prlog(PR_ERR, "ERROR: x509 certificate is invalid (%d)\n", rc); | ||
else | ||
else if (is_trustedcadb_variable(variable_name)) { | ||
if (!crypto_x509_is_CA(x509)) { | ||
prlog(PR_ERR, "ERROR: it is not CA certificate\n"); | ||
rc = CERT_FAIL; | ||
} | ||
} else | ||
rc = print_cert_info(x509); | ||
|
||
crypto_x509_free(x509); | ||
|
@@ -261,12 +266,11 @@ static int read_path(const char *path, const int is_print_raw, const char *varia | |
if (rc == SUCCESS) { | ||
if (is_print_raw || esl_data_size == DEFAULT_PK_LEN) | ||
print_raw((char *)esl_data, esl_data_size); | ||
else if (esl_data_size >= TIMESTAMP_LEN) | ||
else if (esl_data_size >= TIMESTAMP_LEN) { | ||
read_timestamp(esl_data); | ||
rc = print_esl_buffer(esl_data + TIMESTAMP_LEN, | ||
esl_data_size - TIMESTAMP_LEN, variable_name); | ||
else | ||
prlog(PR_WARNING, "WARNING: The %s database is empty.\n", | ||
variable_name); | ||
Comment on lines
-267
to
-269
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a little unclear on the change to the conditionals here. I assume a variable will be completely empty if it hadn't yet stored data or freshly reset, but otherwise it should at least contain a data size of It seems like there are four conditions:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note this appears again later in the function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think conditions 2 and 4 can ever occur? We can remove the esl_data_size != -1 check here. |
||
} | ||
|
||
if (esl_data != NULL) | ||
free(esl_data); | ||
|
@@ -289,13 +293,12 @@ static int read_path(const char *path, const int is_print_raw, const char *varia | |
(esl_data_size == DEFAULT_PK_LEN && | ||
strcmp(defined_sb_variables[i], PK_VARIABLE) == 0)) | ||
print_raw((char *)esl_data, esl_data_size); | ||
else if (esl_data_size >= TIMESTAMP_LEN) | ||
else if (esl_data_size >= TIMESTAMP_LEN) { | ||
read_timestamp(esl_data); | ||
rc = print_esl_buffer(esl_data + TIMESTAMP_LEN, | ||
esl_data_size - TIMESTAMP_LEN, | ||
defined_sb_variables[i]); | ||
else | ||
prlog(PR_WARNING, "WARNING: The %s database is empty.\n", | ||
defined_sb_variables[i]); | ||
} | ||
|
||
if (esl_data != NULL) | ||
free(esl_data); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Acknowledged.