Skip to content

Commit

Permalink
Code optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
aveenismail committed Sep 5, 2024
1 parent aa61d73 commit 6bae4cb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
1 change: 1 addition & 0 deletions common/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ bool read_public_key(uint8_t *buf, size_t len, yh_algorithm *algo,
}

if(BIO_write(bio, buf, len) <= 0) {
BIO_free_all(bio);
return false;
}

Expand Down
6 changes: 2 additions & 4 deletions src/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,6 @@ int yh_com_get_pubkey(yubihsm_context *ctx, Argument *argv, cmd_format in_fmt,
if (BIO_flush(bio) != 1) {
fprintf(stderr, "Unable to flush BIO\n");
BIO_free_all(b64);
BIO_free_all(bio);
error = true;
goto getpk_base64_cleanup;
}
Expand Down Expand Up @@ -1269,7 +1268,6 @@ int yh_com_get_device_pubkey(yubihsm_context *ctx, Argument *argv,
if (BIO_flush(bio) != 1) {
fprintf(stderr, "Unable to flush BIO\n");
BIO_free_all(b64);
BIO_free_all(bio);
error = true;
goto getdpk_base64_cleanup;
}
Expand Down Expand Up @@ -3098,7 +3096,6 @@ int yh_com_sign_ssh_certificate(yubihsm_context *ctx, Argument *argv,

uint8_t data[YH_MSG_BUF_SIZE + 1024] = {0};
size_t response_len = sizeof(data);
size_t in_len = 4 + 256; // 4 bytes time stamp + 256 bytes signature

if (argv[4].len > YH_MSG_BUF_SIZE) {
fprintf(stderr, "Failed to sign ssh certificate: %s\n",
Expand Down Expand Up @@ -3135,7 +3132,8 @@ int yh_com_sign_ssh_certificate(yubihsm_context *ctx, Argument *argv,

int ret = 0;
(void) BIO_set_flags(bio, BIO_FLAGS_BASE64_NO_NL);
if (BIO_write(bio, data + in_len, argv[4].len + response_len - in_len) <= 0) {
if (BIO_write(bio, data + 4 + 256, argv[4].len + response_len - 4 - 256) <=
0) { // TODO(adma): FIXME, unmagify
fprintf(stderr, "Failed to sign SSH certificate.\n");
ret = -1;
goto clean_bio;
Expand Down

0 comments on commit 6bae4cb

Please sign in to comment.