mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-03 12:11:33 +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. -- Backport of master commit: f1845f25dbea79c191427710fa56ed01e63a045b Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
parent
68d3e461f6
commit
88556386a6
@ -1210,12 +1210,10 @@ get_public_key (app_t app, int keyno)
|
||||
le_value = 256; /* Use legacy value. */
|
||||
}
|
||||
|
||||
err = iso7816_read_public_key
|
||||
(app->slot, exmode,
|
||||
(const unsigned char*)(keyno == 0? "\xB6" :
|
||||
keyno == 1? "\xB8" : "\xA4"), 2,
|
||||
le_value,
|
||||
&buffer, &buflen);
|
||||
err = iso7816_read_public_key (app->slot, exmode,
|
||||
(keyno == 0? "\xB6" :
|
||||
keyno == 1? "\xB8" : "\xA4"),
|
||||
2, le_value, &buffer, &buflen);
|
||||
if (err)
|
||||
{
|
||||
log_error (_("reading public key failed: %s\n"), gpg_strerror (err));
|
||||
@ -2999,13 +2997,13 @@ do_genkey (app_t app, ctrl_t ctrl, const char *keynostr, unsigned int flags,
|
||||
gpg_error_t (*pincb)(void*, const char *, char **),
|
||||
void *pincb_arg)
|
||||
{
|
||||
int rc;
|
||||
gpg_error_t err;
|
||||
char numbuf[30];
|
||||
unsigned char fprbuf[20];
|
||||
const unsigned char *keydata, *m, *e;
|
||||
unsigned char *buffer = NULL;
|
||||
size_t buflen, keydatalen, mlen, elen;
|
||||
time_t created_at;
|
||||
u32 created_at;
|
||||
int keyno = atoi (keynostr) - 1;
|
||||
int force = (flags & 1);
|
||||
time_t start_at;
|
||||
@ -3027,9 +3025,9 @@ do_genkey (app_t app, ctrl_t ctrl, const char *keynostr, unsigned int flags,
|
||||
app->app_local->pk[keyno].read_done = 0;
|
||||
|
||||
/* Check whether a key already exists. */
|
||||
rc = does_key_exist (app, keyno, 1, force);
|
||||
if (rc)
|
||||
return rc;
|
||||
err = does_key_exist (app, keyno, 1, force);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
/* Because we send the key parameter back via status lines we need
|
||||
to put a limit on the max. allowed keysize. 2048 bit will
|
||||
@ -3040,8 +3038,8 @@ do_genkey (app_t app, ctrl_t ctrl, const char *keynostr, unsigned int flags,
|
||||
return gpg_error (GPG_ERR_TOO_LARGE);
|
||||
|
||||
/* Prepare for key generation by verifying the Admin PIN. */
|
||||
rc = verify_chv3 (app, pincb, pincb_arg);
|
||||
if (rc)
|
||||
err = verify_chv3 (app, pincb, pincb_arg);
|
||||
if (err)
|
||||
goto leave;
|
||||
|
||||
/* Test whether we will need extended length mode. (1900 is an
|
||||
@ -3062,17 +3060,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"));
|
||||
start_at = time (NULL);
|
||||
rc = iso7816_generate_keypair
|
||||
/* # warning key generation temporary replaced by reading an existing key. */
|
||||
/* rc = iso7816_read_public_key */
|
||||
(app->slot, exmode,
|
||||
(const unsigned char*)(keyno == 0? "\xB6" :
|
||||
keyno == 1? "\xB8" : "\xA4"), 2,
|
||||
le_value,
|
||||
&buffer, &buflen);
|
||||
if (rc)
|
||||
err = iso7816_generate_keypair (app->slot, exmode,
|
||||
(keyno == 0? "\xB6" :
|
||||
keyno == 1? "\xB8" : "\xA4"),
|
||||
2, le_value, &buffer, &buflen);
|
||||
if (err)
|
||||
{
|
||||
rc = gpg_error (GPG_ERR_CARD);
|
||||
err = gpg_error (GPG_ERR_CARD);
|
||||
log_error (_("generating key failed\n"));
|
||||
goto leave;
|
||||
}
|
||||
@ -3082,7 +3076,7 @@ do_genkey (app_t app, ctrl_t ctrl, const char *keynostr, unsigned int flags,
|
||||
keydata = find_tlv (buffer, buflen, 0x7F49, &keydatalen);
|
||||
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"));
|
||||
goto leave;
|
||||
}
|
||||
@ -3090,7 +3084,7 @@ do_genkey (app_t app, ctrl_t ctrl, const char *keynostr, unsigned int flags,
|
||||
m = find_tlv (keydata, keydatalen, 0x0081, &mlen);
|
||||
if (!m)
|
||||
{
|
||||
rc = gpg_error (GPG_ERR_CARD);
|
||||
err = gpg_error (GPG_ERR_CARD);
|
||||
log_error (_("response does not contain the RSA modulus\n"));
|
||||
goto leave;
|
||||
}
|
||||
@ -3100,28 +3094,28 @@ do_genkey (app_t app, ctrl_t ctrl, const char *keynostr, unsigned int flags,
|
||||
e = find_tlv (keydata, keydatalen, 0x0082, &elen);
|
||||
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"));
|
||||
goto leave;
|
||||
}
|
||||
/* log_printhex ("RSA e:", e, elen); */
|
||||
send_key_data (ctrl, "e", e, elen);
|
||||
|
||||
created_at = createtime? createtime : gnupg_get_time ();
|
||||
sprintf (numbuf, "%lu", (unsigned long)created_at);
|
||||
created_at = (u32)(createtime? createtime : gnupg_get_time ());
|
||||
sprintf (numbuf, "%u", created_at);
|
||||
send_status_info (ctrl, "KEY-CREATED-AT",
|
||||
numbuf, (size_t)strlen(numbuf), NULL, 0);
|
||||
|
||||
rc = store_fpr (app, keyno, (u32)created_at,
|
||||
err = store_fpr (app, keyno, (u32)created_at,
|
||||
m, mlen, e, elen, fprbuf, app->card_version);
|
||||
if (rc)
|
||||
if (err)
|
||||
goto leave;
|
||||
send_fpr_if_not_null (ctrl, "KEY-FPR", -1, fprbuf);
|
||||
|
||||
|
||||
leave:
|
||||
xfree (buffer);
|
||||
return rc;
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
@ -603,9 +603,8 @@ iso7816_internal_authenticate (int slot, int extended_mode,
|
||||
returned. In that case a value of -1 uses a large default
|
||||
(e.g. 4096 bytes), a value larger 256 used that value. */
|
||||
static gpg_error_t
|
||||
do_generate_keypair (int slot, int extended_mode, int readonly,
|
||||
const unsigned char *data, size_t datalen,
|
||||
int le,
|
||||
do_generate_keypair (int slot, int extended_mode, int read_only,
|
||||
const char *data, size_t datalen, int le,
|
||||
unsigned char **result, size_t *resultlen)
|
||||
{
|
||||
int sw;
|
||||
@ -616,8 +615,8 @@ do_generate_keypair (int slot, int extended_mode, int readonly,
|
||||
*resultlen = 0;
|
||||
|
||||
sw = apdu_send_le (slot, extended_mode,
|
||||
0x00, CMD_GENERATE_KEYPAIR, readonly? 0x81:0x80, 0,
|
||||
datalen, (const char*)data,
|
||||
0x00, CMD_GENERATE_KEYPAIR, read_only? 0x81:0x80, 0,
|
||||
datalen, data,
|
||||
le >= 0 && le < 256? 256:le,
|
||||
result, resultlen);
|
||||
if (sw != SW_SUCCESS)
|
||||
@ -635,7 +634,7 @@ do_generate_keypair (int slot, int extended_mode, int readonly,
|
||||
|
||||
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,
|
||||
unsigned char **result, size_t *resultlen)
|
||||
{
|
||||
@ -646,7 +645,7 @@ iso7816_generate_keypair (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,
|
||||
unsigned char **result, size_t *resultlen)
|
||||
{
|
||||
|
@ -100,11 +100,11 @@ gpg_error_t iso7816_internal_authenticate (int slot, int extended_mode,
|
||||
int le,
|
||||
unsigned char **result, size_t *resultlen);
|
||||
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,
|
||||
unsigned char **result, size_t *resultlen);
|
||||
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,
|
||||
unsigned char **result, size_t *resultlen);
|
||||
gpg_error_t iso7816_get_challenge (int slot,
|
||||
|
Loading…
x
Reference in New Issue
Block a user