1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-05-31 22:18:03 +02:00

gpg: Fix algo string parsing of --quick-addkey.

* g10/keygen.c (parse_key_parameter_string): Fix handling of PART==1.
(parse_key_parameter_part): Use default key size if only "rsa", "dsa",
or "elg" is given.
--

The first change is the actual fix.  The second change avoids the
error "Invalid Curve" when only "rsa" instead of RSA2048 is given.

Fixes-commit: ce29272e24
Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2016-12-12 09:55:48 +01:00
parent d568a15616
commit 522e6f798d
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
2 changed files with 19 additions and 10 deletions

View File

@ -2871,7 +2871,7 @@ parse_key_parameter_part (char *string, int for_subkey,
char const **r_curve) char const **r_curve)
{ {
char *flags; char *flags;
int algo = 0; int algo;
char *endp; char *endp;
const char *curve = NULL; const char *curve = NULL;
int ecdh_or_ecdsa = 0; int ecdh_or_ecdsa = 0;
@ -2887,7 +2887,8 @@ parse_key_parameter_part (char *string, int for_subkey,
if (flags) if (flags)
*flags++ = 0; *flags++ = 0;
if (strlen (string) > 3 && digitp (string+3)) algo = 0;
if (strlen (string) >= 3 && (digitp (string+3) || !string[3]))
{ {
if (!ascii_memcasecmp (string, "rsa", 3)) if (!ascii_memcasecmp (string, "rsa", 3))
algo = PUBKEY_ALGO_RSA; algo = PUBKEY_ALGO_RSA;
@ -2898,9 +2899,14 @@ parse_key_parameter_part (char *string, int for_subkey,
} }
if (algo) if (algo)
{ {
size = strtoul (string+3, &endp, 10); if (!string[3])
if (size < 512 || size > 16384 || *endp) size = get_keysize_range (algo, NULL, NULL);
return gpg_error (GPG_ERR_INV_VALUE); else
{
size = strtoul (string+3, &endp, 10);
if (size < 512 || size > 16384 || *endp)
return gpg_error (GPG_ERR_INV_VALUE);
}
} }
else if ((curve = openpgp_is_curve_supported (string, &algo, &size))) else if ((curve = openpgp_is_curve_supported (string, &algo, &size)))
{ {
@ -3080,8 +3086,9 @@ parse_key_parameter_part (char *string, int for_subkey,
* used: * used:
* -1 := Both parts * -1 := Both parts
* 0 := Only the part of the primary key * 0 := Only the part of the primary key
* 1 := Only the part of the secondary key is parsed but returned * 1 := If there is one part parse that one, if there are
* in the args for the primary key (R_ALGO,....) * two parts parse the second part. Always return
* in the args for the primary key (R_ALGO,....).
* *
*/ */
gpg_error_t gpg_error_t
@ -3133,8 +3140,10 @@ parse_key_parameter_string (const char *string, int part,
} }
else if (part == 1) else if (part == 1)
{ {
err = parse_key_parameter_part (secondary, 1, r_algo, r_size, /* If we have SECONDARY, use that part. If there is only one
r_keyuse, r_curve); * part consider this to be the subkey algo. */
err = parse_key_parameter_part (secondary? secondary : primary, 1,
r_algo, r_size, r_keyuse, r_curve);
} }
xfree (primary); xfree (primary);

View File

@ -3050,7 +3050,7 @@ parse_mdc (IOBUF inp, int pkttype, unsigned long pktlen,
/* /*
* This packet is internally generated by us (ibn armor.c) to transfer * This packet is internally generated by us (in armor.c) to transfer
* some information to the lower layer. To make sure that this packet * some information to the lower layer. To make sure that this packet
* is really a GPG faked one and not one coming from outside, we * is really a GPG faked one and not one coming from outside, we
* first check that there is a unique tag in it. * first check that there is a unique tag in it.