mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-03 22:56:33 +02:00
scd:p15: Support signing with CardOS 5 cards.
* scd/app-help.c (app_help_get_keygrip_string_pk): Add optional arg r_pkey and change all callers. (app_help_get_keygrip_string): Ditto. * scd/app-p15.c (struct cdf_object_s): Use bit flags (struct aodf_object_s): Ditto. Add field 'fid'. (struct prkdf_object_s): Ditto. Add fields keygrip, keyalgo, and keynbits. (parse_certid): Allow a keygrip instead of a certid aka keyref. (read_ef_aodf): Store the FID. (keygripstr_from_prkdf): Rename to ... (keygrip_from_prkdf): this. Remove arg r_gripstr and implement cache. Change callers to directly use the values from the object. Also store the algo and length of the key ion the object. (keyref_from_keyinfo): New. Factored out code. (do_sign): Support SHA-256 and >2048 bit RSA keys. common/scd:p15: Support signing with CardOS 5 cards. * common/util.h (KEYGRIP_LEN): New. -- This has been tested with a D-Trust card featuring 3072 bit keys. Note that non-repudiation key for a qualified signature does not yet work because we do not yet support rsaPSS padding. Thus a gpgsm --learn shows a couple of Bad Signature errors for this key. Signed-off-by: Werner Koch <wk@gnupg.org> Back ported from master: - Removed do_with_keygrip - Added KEYGRIP_LEN - app_help_get_keygrip_string_pk actually added. - Move keygrip_from_prkdf in do_sign before the verification. It used to work in master only because there it is implictly called prior to signing by do_with_keygrip Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
368f006a28
commit
e730444e7b
6 changed files with 289 additions and 100 deletions
|
@ -52,26 +52,24 @@ app_help_count_bits (const unsigned char *a, size_t len)
|
|||
}
|
||||
|
||||
|
||||
/* Return the KEYGRIP for the certificate CERT as an hex encoded
|
||||
string in the user provided buffer HEXKEYGRIP which must be of at
|
||||
least 41 bytes. */
|
||||
/* Return the KEYGRIP for the canonical encoded public key (PK,PKLEN)
|
||||
* as an hex encoded string in the user provided buffer HEXKEYGRIP
|
||||
* which must be of at least 41 bytes. If R_PKEY is not NULL and the
|
||||
* function succeeded, the S-expression representing the key is
|
||||
* stored there. The caller needs to call gcry_sexp_release on
|
||||
* that. */
|
||||
gpg_error_t
|
||||
app_help_get_keygrip_string (ksba_cert_t cert, char *hexkeygrip)
|
||||
app_help_get_keygrip_string_pk (const void *pk, size_t pklen, char *hexkeygrip,
|
||||
gcry_sexp_t *r_pkey)
|
||||
{
|
||||
gpg_error_t err;
|
||||
gcry_sexp_t s_pkey;
|
||||
ksba_sexp_t p;
|
||||
size_t n;
|
||||
unsigned char array[20];
|
||||
unsigned char array[KEYGRIP_LEN];
|
||||
|
||||
p = ksba_cert_get_public_key (cert);
|
||||
if (!p)
|
||||
return gpg_error (GPG_ERR_BUG);
|
||||
n = gcry_sexp_canon_len (p, 0, NULL, NULL);
|
||||
if (!n)
|
||||
return gpg_error (GPG_ERR_INV_SEXP);
|
||||
err = gcry_sexp_sscan (&s_pkey, NULL, (char*)p, n);
|
||||
xfree (p);
|
||||
if (r_pkey)
|
||||
*r_pkey = NULL;
|
||||
|
||||
err = gcry_sexp_sscan (&s_pkey, NULL, pk, pklen);
|
||||
if (err)
|
||||
return err; /* Can't parse that S-expression. */
|
||||
if (!gcry_pk_get_keygrip (s_pkey, array))
|
||||
|
@ -79,14 +77,45 @@ app_help_get_keygrip_string (ksba_cert_t cert, char *hexkeygrip)
|
|||
gcry_sexp_release (s_pkey);
|
||||
return gpg_error (GPG_ERR_GENERAL); /* Failed to calculate the keygrip.*/
|
||||
}
|
||||
gcry_sexp_release (s_pkey);
|
||||
|
||||
bin2hex (array, 20, hexkeygrip);
|
||||
if (r_pkey)
|
||||
*r_pkey = s_pkey;
|
||||
else
|
||||
gcry_sexp_release (s_pkey);
|
||||
|
||||
bin2hex (array, KEYGRIP_LEN, hexkeygrip);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Return the KEYGRIP for the certificate CERT as an hex encoded
|
||||
* string in the user provided buffer HEXKEYGRIP which must be of at
|
||||
* least 41 bytes. If R_PKEY is not NULL and the function succeeded,
|
||||
* the S-expression representing the key is stored there. The caller
|
||||
* needs to call gcry_sexp_release on that. */
|
||||
gpg_error_t
|
||||
app_help_get_keygrip_string (ksba_cert_t cert, char *hexkeygrip,
|
||||
gcry_sexp_t *r_pkey)
|
||||
{
|
||||
gpg_error_t err;
|
||||
ksba_sexp_t p;
|
||||
size_t n;
|
||||
|
||||
if (r_pkey)
|
||||
*r_pkey = NULL;
|
||||
|
||||
p = ksba_cert_get_public_key (cert);
|
||||
if (!p)
|
||||
return gpg_error (GPG_ERR_BUG);
|
||||
n = gcry_sexp_canon_len (p, 0, NULL, NULL);
|
||||
if (!n)
|
||||
return gpg_error (GPG_ERR_INV_SEXP);
|
||||
err = app_help_get_keygrip_string_pk ((void*)p, n, hexkeygrip, r_pkey);
|
||||
ksba_free (p);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
/* Given the SLOT and the File ID FID, return the length of the
|
||||
certificate contained in that file. Returns 0 if the file does not
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue