mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-21 14:47:03 +01:00
scd: minor cleanup to merge other works.
* scd/iso7816.c (do_generate_keypair): Use const char * for DATA. (iso7816_generate_keypair, iso7816_read_public_key): Likewise. * scd/app-openpgp.c (get_public_key): Follow the change. (do_genkey): Ditto. Use ERR instead of RC. Use u32 for CREATED_AT. -- Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
parent
e0e782b4c6
commit
f1845f25db
@ -1276,12 +1276,10 @@ get_public_key (app_t app, int keyno)
|
|||||||
le_value = 256; /* Use legacy value. */
|
le_value = 256; /* Use legacy value. */
|
||||||
}
|
}
|
||||||
|
|
||||||
err = iso7816_read_public_key
|
err = iso7816_read_public_key (app->slot, exmode,
|
||||||
(app->slot, exmode,
|
(keyno == 0? "\xB6" :
|
||||||
(const unsigned char*)(keyno == 0? "\xB6" :
|
keyno == 1? "\xB8" : "\xA4"),
|
||||||
keyno == 1? "\xB8" : "\xA4"), 2,
|
2, le_value, &buffer, &buflen);
|
||||||
le_value,
|
|
||||||
&buffer, &buflen);
|
|
||||||
if (err)
|
if (err)
|
||||||
{
|
{
|
||||||
log_error (_("reading public key failed: %s\n"), gpg_strerror (err));
|
log_error (_("reading public key failed: %s\n"), gpg_strerror (err));
|
||||||
@ -3534,13 +3532,13 @@ do_genkey (app_t app, ctrl_t ctrl, const char *keynostr, unsigned int flags,
|
|||||||
gpg_error_t (*pincb)(void*, const char *, char **),
|
gpg_error_t (*pincb)(void*, const char *, char **),
|
||||||
void *pincb_arg)
|
void *pincb_arg)
|
||||||
{
|
{
|
||||||
int rc;
|
gpg_error_t err;
|
||||||
char numbuf[30];
|
char numbuf[30];
|
||||||
unsigned char fprbuf[20];
|
unsigned char fprbuf[20];
|
||||||
const unsigned char *keydata, *m, *e;
|
const unsigned char *keydata, *m, *e;
|
||||||
unsigned char *buffer = NULL;
|
unsigned char *buffer = NULL;
|
||||||
size_t buflen, keydatalen, mlen, elen;
|
size_t buflen, keydatalen, mlen, elen;
|
||||||
time_t created_at;
|
u32 created_at;
|
||||||
int keyno = atoi (keynostr) - 1;
|
int keyno = atoi (keynostr) - 1;
|
||||||
int force = (flags & 1);
|
int force = (flags & 1);
|
||||||
time_t start_at;
|
time_t start_at;
|
||||||
@ -3562,9 +3560,9 @@ do_genkey (app_t app, ctrl_t ctrl, const char *keynostr, unsigned int flags,
|
|||||||
app->app_local->pk[keyno].read_done = 0;
|
app->app_local->pk[keyno].read_done = 0;
|
||||||
|
|
||||||
/* Check whether a key already exists. */
|
/* Check whether a key already exists. */
|
||||||
rc = does_key_exist (app, keyno, 1, force);
|
err = does_key_exist (app, keyno, 1, force);
|
||||||
if (rc)
|
if (err)
|
||||||
return rc;
|
return err;
|
||||||
|
|
||||||
/* Because we send the key parameter back via status lines we need
|
/* Because we send the key parameter back via status lines we need
|
||||||
to put a limit on the max. allowed keysize. 2048 bit will
|
to put a limit on the max. allowed keysize. 2048 bit will
|
||||||
@ -3575,8 +3573,8 @@ do_genkey (app_t app, ctrl_t ctrl, const char *keynostr, unsigned int flags,
|
|||||||
return gpg_error (GPG_ERR_TOO_LARGE);
|
return gpg_error (GPG_ERR_TOO_LARGE);
|
||||||
|
|
||||||
/* Prepare for key generation by verifying the Admin PIN. */
|
/* Prepare for key generation by verifying the Admin PIN. */
|
||||||
rc = verify_chv3 (app, pincb, pincb_arg);
|
err = verify_chv3 (app, pincb, pincb_arg);
|
||||||
if (rc)
|
if (err)
|
||||||
goto leave;
|
goto leave;
|
||||||
|
|
||||||
/* Test whether we will need extended length mode. (1900 is an
|
/* Test whether we will need extended length mode. (1900 is an
|
||||||
@ -3597,17 +3595,13 @@ do_genkey (app_t app, ctrl_t ctrl, const char *keynostr, unsigned int flags,
|
|||||||
|
|
||||||
log_info (_("please wait while key is being generated ...\n"));
|
log_info (_("please wait while key is being generated ...\n"));
|
||||||
start_at = time (NULL);
|
start_at = time (NULL);
|
||||||
rc = iso7816_generate_keypair
|
err = iso7816_generate_keypair (app->slot, exmode,
|
||||||
/* # warning key generation temporary replaced by reading an existing key. */
|
(keyno == 0? "\xB6" :
|
||||||
/* rc = iso7816_read_public_key */
|
keyno == 1? "\xB8" : "\xA4"),
|
||||||
(app->slot, exmode,
|
2, le_value, &buffer, &buflen);
|
||||||
(const unsigned char*)(keyno == 0? "\xB6" :
|
if (err)
|
||||||
keyno == 1? "\xB8" : "\xA4"), 2,
|
|
||||||
le_value,
|
|
||||||
&buffer, &buflen);
|
|
||||||
if (rc)
|
|
||||||
{
|
{
|
||||||
rc = gpg_error (GPG_ERR_CARD);
|
err = gpg_error (GPG_ERR_CARD);
|
||||||
log_error (_("generating key failed\n"));
|
log_error (_("generating key failed\n"));
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
@ -3622,7 +3616,7 @@ do_genkey (app_t app, ctrl_t ctrl, const char *keynostr, unsigned int flags,
|
|||||||
keydata = find_tlv (buffer, buflen, 0x7F49, &keydatalen);
|
keydata = find_tlv (buffer, buflen, 0x7F49, &keydatalen);
|
||||||
if (!keydata)
|
if (!keydata)
|
||||||
{
|
{
|
||||||
rc = gpg_error (GPG_ERR_CARD);
|
err = gpg_error (GPG_ERR_CARD);
|
||||||
log_error (_("response does not contain the public key data\n"));
|
log_error (_("response does not contain the public key data\n"));
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
@ -3630,7 +3624,7 @@ do_genkey (app_t app, ctrl_t ctrl, const char *keynostr, unsigned int flags,
|
|||||||
m = find_tlv (keydata, keydatalen, 0x0081, &mlen);
|
m = find_tlv (keydata, keydatalen, 0x0081, &mlen);
|
||||||
if (!m)
|
if (!m)
|
||||||
{
|
{
|
||||||
rc = gpg_error (GPG_ERR_CARD);
|
err = gpg_error (GPG_ERR_CARD);
|
||||||
log_error (_("response does not contain the RSA modulus\n"));
|
log_error (_("response does not contain the RSA modulus\n"));
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
@ -3640,15 +3634,15 @@ do_genkey (app_t app, ctrl_t ctrl, const char *keynostr, unsigned int flags,
|
|||||||
e = find_tlv (keydata, keydatalen, 0x0082, &elen);
|
e = find_tlv (keydata, keydatalen, 0x0082, &elen);
|
||||||
if (!e)
|
if (!e)
|
||||||
{
|
{
|
||||||
rc = gpg_error (GPG_ERR_CARD);
|
err = gpg_error (GPG_ERR_CARD);
|
||||||
log_error (_("response does not contain the RSA public exponent\n"));
|
log_error (_("response does not contain the RSA public exponent\n"));
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
/* log_printhex ("RSA e:", e, elen); */
|
/* log_printhex ("RSA e:", e, elen); */
|
||||||
send_key_data (ctrl, "e", e, elen);
|
send_key_data (ctrl, "e", e, elen);
|
||||||
|
|
||||||
created_at = createtime? createtime : gnupg_get_time ();
|
created_at = (u32)(createtime? createtime : gnupg_get_time ());
|
||||||
sprintf (numbuf, "%lu", (unsigned long)created_at);
|
sprintf (numbuf, "%u", created_at);
|
||||||
send_status_info (ctrl, "KEY-CREATED-AT",
|
send_status_info (ctrl, "KEY-CREATED-AT",
|
||||||
numbuf, (size_t)strlen(numbuf), NULL, 0);
|
numbuf, (size_t)strlen(numbuf), NULL, 0);
|
||||||
|
|
||||||
@ -3657,16 +3651,16 @@ do_genkey (app_t app, ctrl_t ctrl, const char *keynostr, unsigned int flags,
|
|||||||
for (; elen && !*e; elen--, e++) /* strip leading zeroes */
|
for (; elen && !*e; elen--, e++) /* strip leading zeroes */
|
||||||
;
|
;
|
||||||
|
|
||||||
rc = store_fpr (app, keyno, (u32)created_at, fprbuf, PUBKEY_ALGO_RSA,
|
err = store_fpr (app, keyno, created_at, fprbuf, PUBKEY_ALGO_RSA,
|
||||||
m, mlen, e, elen);
|
m, mlen, e, elen);
|
||||||
if (rc)
|
if (err)
|
||||||
goto leave;
|
goto leave;
|
||||||
send_fpr_if_not_null (ctrl, "KEY-FPR", -1, fprbuf);
|
send_fpr_if_not_null (ctrl, "KEY-FPR", -1, fprbuf);
|
||||||
|
|
||||||
|
|
||||||
leave:
|
leave:
|
||||||
xfree (buffer);
|
xfree (buffer);
|
||||||
return rc;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -604,8 +604,7 @@ iso7816_internal_authenticate (int slot, int extended_mode,
|
|||||||
(e.g. 4096 bytes), a value larger 256 used that value. */
|
(e.g. 4096 bytes), a value larger 256 used that value. */
|
||||||
static gpg_error_t
|
static gpg_error_t
|
||||||
do_generate_keypair (int slot, int extended_mode, int read_only,
|
do_generate_keypair (int slot, int extended_mode, int read_only,
|
||||||
const unsigned char *data, size_t datalen,
|
const char *data, size_t datalen, int le,
|
||||||
int le,
|
|
||||||
unsigned char **result, size_t *resultlen)
|
unsigned char **result, size_t *resultlen)
|
||||||
{
|
{
|
||||||
int sw;
|
int sw;
|
||||||
@ -617,7 +616,7 @@ do_generate_keypair (int slot, int extended_mode, int read_only,
|
|||||||
|
|
||||||
sw = apdu_send_le (slot, extended_mode,
|
sw = apdu_send_le (slot, extended_mode,
|
||||||
0x00, CMD_GENERATE_KEYPAIR, read_only? 0x81:0x80, 0,
|
0x00, CMD_GENERATE_KEYPAIR, read_only? 0x81:0x80, 0,
|
||||||
datalen, (const char*)data,
|
datalen, data,
|
||||||
le >= 0 && le < 256? 256:le,
|
le >= 0 && le < 256? 256:le,
|
||||||
result, resultlen);
|
result, resultlen);
|
||||||
if (sw != SW_SUCCESS)
|
if (sw != SW_SUCCESS)
|
||||||
@ -635,7 +634,7 @@ do_generate_keypair (int slot, int extended_mode, int read_only,
|
|||||||
|
|
||||||
gpg_error_t
|
gpg_error_t
|
||||||
iso7816_generate_keypair (int slot, int extended_mode,
|
iso7816_generate_keypair (int slot, int extended_mode,
|
||||||
const unsigned char *data, size_t datalen,
|
const char *data, size_t datalen,
|
||||||
int le,
|
int le,
|
||||||
unsigned char **result, size_t *resultlen)
|
unsigned char **result, size_t *resultlen)
|
||||||
{
|
{
|
||||||
@ -646,7 +645,7 @@ iso7816_generate_keypair (int slot, int extended_mode,
|
|||||||
|
|
||||||
gpg_error_t
|
gpg_error_t
|
||||||
iso7816_read_public_key (int slot, int extended_mode,
|
iso7816_read_public_key (int slot, int extended_mode,
|
||||||
const unsigned char *data, size_t datalen,
|
const char *data, size_t datalen,
|
||||||
int le,
|
int le,
|
||||||
unsigned char **result, size_t *resultlen)
|
unsigned char **result, size_t *resultlen)
|
||||||
{
|
{
|
||||||
|
@ -100,11 +100,11 @@ gpg_error_t iso7816_internal_authenticate (int slot, int extended_mode,
|
|||||||
int le,
|
int le,
|
||||||
unsigned char **result, size_t *resultlen);
|
unsigned char **result, size_t *resultlen);
|
||||||
gpg_error_t iso7816_generate_keypair (int slot, int extended_mode,
|
gpg_error_t iso7816_generate_keypair (int slot, int extended_mode,
|
||||||
const unsigned char *data, size_t datalen,
|
const char *data, size_t datalen,
|
||||||
int le,
|
int le,
|
||||||
unsigned char **result, size_t *resultlen);
|
unsigned char **result, size_t *resultlen);
|
||||||
gpg_error_t iso7816_read_public_key (int slot, int extended_mode,
|
gpg_error_t iso7816_read_public_key (int slot, int extended_mode,
|
||||||
const unsigned char *data, size_t datalen,
|
const char *data, size_t datalen,
|
||||||
int le,
|
int le,
|
||||||
unsigned char **result, size_t *resultlen);
|
unsigned char **result, size_t *resultlen);
|
||||||
gpg_error_t iso7816_get_challenge (int slot,
|
gpg_error_t iso7816_get_challenge (int slot,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user