Skip to content
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

sc-hsm-tool: Add options for public key authentication #1711

Closed
wants to merge 23 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
sc-hsm-tool: improve argument checks
  • Loading branch information
Frank Braun committed Oct 29, 2019
commit 6c69699fc6c0751cae625992fbaafeda439bbefd
22 changes: 18 additions & 4 deletions src/tools/sc-hsm-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ static void print_info(sc_card_t *card, sc_file_t *file)



static int initialize(sc_card_t *card, const char *so_pin, const char *user_pin, int retry_counter, const char *bio1, const char *bio2, int dkek_shares, int num_of_pub_keys, int required_pub_keys, const char *label)
static int initialize(sc_card_t *card, const char *so_pin, const char *user_pin, int retry_counter, const char *bio1, const char *bio2, int dkek_shares, signed char num_of_pub_keys, u8 required_pub_keys, const char *label)
{
sc_cardctl_sc_hsm_init_param_t param;
size_t len;
Expand Down Expand Up @@ -680,8 +680,8 @@ static int initialize(sc_card_t *card, const char *so_pin, const char *user_pin,
}

param.dkek_shares = (char)dkek_shares;
param.num_of_pub_keys = (char)num_of_pub_keys;
param.required_pub_keys = (u8)required_pub_keys;
param.num_of_pub_keys = num_of_pub_keys;
param.required_pub_keys = required_pub_keys;
param.label = (char *)label;

r = sc_card_ctl(card, SC_CARDCTL_SC_HSM_INITIALIZE, (void *)&param);
Expand Down Expand Up @@ -1998,6 +1998,8 @@ int main(int argc, char *argv[])
int opt_password_shares_total = -1;
int opt_force = 0;
int opt_iter = 10000000;
signed char num_of_pub_keys = -1;
u8 required_pub_keys = 1;
sc_context_param_t ctx_param;
sc_context_t *ctx = NULL;
sc_card_t *card = NULL;
Expand Down Expand Up @@ -2114,6 +2116,18 @@ int main(int argc, char *argv[])
fprintf(stderr, "Option -n (--required-pub-keys) requires option -X\n");
exit(1);
}
if (opt_num_of_pub_keys != -1) {
if (opt_num_of_pub_keys < 1 || opt_num_of_pub_keys > 90) {
fprintf(stderr, "Argument to option -K (--public-key-auth) must be between 1 and 90 \n");
exit(1);
}
if (opt_required_pub_keys < 1 || opt_required_pub_keys > opt_num_of_pub_keys) {
fprintf(stderr, "Argument to option -n (--required-pub-keys) must be between 1 and %d\n", opt_num_of_pub_keys);
exit(1);
}
num_of_pub_keys = (signed char)opt_num_of_pub_keys;
required_pub_keys = (u8)opt_required_pub_keys;
}
if (do_initialize && do_export_key) {
fprintf(stderr, "Option -e (--export-for-pub-key-auth) excludes option -X\n");
exit(1);
Expand Down Expand Up @@ -2203,7 +2217,7 @@ int main(int argc, char *argv[])
goto fail;
}

if (do_initialize && initialize(card, opt_so_pin, opt_pin, opt_retry_counter, opt_bio1, opt_bio2, opt_dkek_shares, opt_num_of_pub_keys, opt_required_pub_keys, opt_label))
if (do_initialize && initialize(card, opt_so_pin, opt_pin, opt_retry_counter, opt_bio1, opt_bio2, opt_dkek_shares, num_of_pub_keys, required_pub_keys, opt_label))
goto fail;

if (do_create_dkek_share && create_dkek_share(card, opt_filename, opt_iter, opt_password, opt_password_shares_threshold, opt_password_shares_total))
Expand Down