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
Show file tree
Hide file tree
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: Initialize card with public key auth
  • Loading branch information
Frank Braun committed Oct 29, 2019
commit ccdbc6d3bcd8b7883eaf231cde26ca1846c37e6b
12 changes: 10 additions & 2 deletions src/libopensc/card-sc-hsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Driver for the SmartCard-HSM, a light-weight hardware security module
*
* Copyright (C) 2012 Andreas Schwier, CardContact, Minden, Germany, and others
* Copyright (C) 2018 GSMK - Gesellschaft für Sichere Mobile Kommunikation mbH
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -1235,7 +1236,7 @@ static int sc_hsm_initialize(sc_card_t *card, sc_cardctl_sc_hsm_init_param_t *pa
int r;
size_t tilen;
sc_apdu_t apdu;
u8 ibuff[64+0xFF], *p;
u8 ibuff[68+0xFF], *p;

LOG_FUNC_CALLED(card->ctx);

Expand Down Expand Up @@ -1268,6 +1269,13 @@ static int sc_hsm_initialize(sc_card_t *card, sc_cardctl_sc_hsm_init_param_t *pa
*p++ = (u8)params->dkek_shares;
}

if (params->num_of_pub_keys > 0) {
*p++ = 0x93; // Use public key authentication
*p++ = 0x02;
*p++ = params->num_of_pub_keys; // Total number of public keys used for public authentication
*p++ = params->required_pub_keys; // Number of public keys required for authentication
}

if (params->bio1.len) {
*p++ = 0x95;
*p++ = params->bio1.len;
Expand All @@ -1279,7 +1287,7 @@ static int sc_hsm_initialize(sc_card_t *card, sc_cardctl_sc_hsm_init_param_t *pa
*p++ = params->bio2.len;
memcpy(p, params->bio2.value, params->bio2.len);
p += params->bio2.len;
}
}
frankbraun marked this conversation as resolved.
Show resolved Hide resolved

sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x50, 0x00, 0x00);
apdu.cla = 0x80;
Expand Down
3 changes: 3 additions & 0 deletions src/libopensc/cardctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* cardctl.h: card_ctl command numbers
*
* Copyright (C) 2003 Olaf Kirch <[email protected]>
* Copyright (C) 2018 GSMK - Gesellschaft für Sichere Mobile Kommunikation mbH
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -1021,6 +1022,8 @@ typedef struct sc_cardctl_sc_hsm_init_param {
struct sc_aid bio2; /* AID of biometric server for template 2 */
u8 options[2]; /* Initialization options */
signed char dkek_shares; /* Number of DKEK shares, 0 for card generated, -1 for none */
signed char num_of_pub_keys; /* Total number of public keys used for public authentication (if > 0) */
u8 required_pub_keys; /* Number of public keys required for authentication (if public auth. is used) */
char *label; /* Token label to be set in EF.TokenInfo (2F03) */
} sc_cardctl_sc_hsm_init_param_t;

Expand Down
6 changes: 4 additions & 2 deletions src/tools/sc-hsm-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,15 +573,15 @@ static int initialize(sc_card_t *card, const char *so_pin, const char *user_pin,
char *_so_pin = NULL, *_user_pin = NULL;
int r;

if (num_of_pub_keys != 1 && num_of_pub_keys < 1) {
if (num_of_pub_keys != -1 && num_of_pub_keys < 1) {
fprintf(stderr, "Total number of public keys for authentication must be > 0\n");
return -1;
}
if (required_pub_keys < 1) {
fprintf(stderr, "Number of public keys required for authentication must be > 0\n");
return -1;
}
if (required_pub_keys > num_of_pub_keys) {
if (num_of_pub_keys != -1 && required_pub_keys > num_of_pub_keys) {
fprintf(stderr, "Required public keys must be <= total number of public keys\n");
return -1;
}
Expand Down Expand Up @@ -673,6 +673,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;
frankbraun marked this conversation as resolved.
Show resolved Hide resolved
param.label = (char *)label;

r = sc_card_ctl(card, SC_CARDCTL_SC_HSM_INITIALIZE, (void *)&param);
Expand Down