Bug 3050 - "Bits has bad value 99999 (too large)" and "key bits exceeds maximum 16384"
Summary: "Bits has bad value 99999 (too large)" and "key bits exceeds maximum 16384"
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: ssh-keygen (show other bugs)
Version: 7.9p1
Hardware: All Mac OS X
: P5 enhancement
Assignee: Assigned to nobody
URL:
Keywords:
Depends on:
Blocks: V_8_1
  Show dependency treegraph
 
Reported: 2019-08-03 18:40 AEST by zaomir
Modified: 2023-01-13 13:26 AEDT (History)
2 users (show)

See Also:


Attachments
Defer bit size tests to key-specific check (1.68 KB, patch)
2019-08-04 10:56 AEST, Darren Tucker
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description zaomir 2019-08-03 18:40:39 AEST
libres-MacBook:~ libre$ ssh-keygen -b 99999
Bits has bad value 99999 (too large)
libres-MacBook:~ libre$ ssh-keygen -b 32768
key bits exceeds maximum 16384


Why are these two error messages in different formats?
Comment 1 Darren Tucker 2019-08-04 10:33:27 AEST
(In reply to zaomir from comment #0)
> Why are these two error messages in different formats?

They're different because they're getting caught be different checks.

> libres-MacBook:~ libre$ ssh-keygen -b 99999
> Bits has bad value 99999 (too large)

This is the general sanity check in the getopt parsing:

    bits = (u_int32_t)strtonum(optarg, 10, 32768, &errstr);
    if (errstr)
        fatal("Bits has bad value %s (%s)",
            optarg, errstr);

> libres-MacBook:~ libre$ ssh-keygen -b 32768
> key bits exceeds maximum 16384

This one is in the key-specific checks (type_bits_valid()), and these limits are imposed by the build of OpenSSL:

   maxbits = (type == KEY_DSA) ?
       OPENSSL_DSA_MAX_MODULUS_BITS : OPENSSL_RSA_MAX_MODULUS_BITS;
   if (*bitsp > maxbits)
      fatal("key bits exceeds maximum %d", maxbits);
Comment 2 Darren Tucker 2019-08-04 10:56:09 AEST
Created attachment 3308 [details]
Defer bit size tests to key-specific check

Without change:
$ ssh-keygen -b 99999  -t rsa -f /tmp/t
Bits has bad value 99999 (too large)

With change:
$ ssh-keygen/obj/ssh-keygen -b 99999  -t rsa -f /tmp/t
Invalid RSA key length: maximum is 16384 bits
Comment 3 Darren Tucker 2019-08-08 20:15:48 AEST
This has been fixed (up to the size allowed by the underlying type, anyway):

$ ./ssh-keygen -b 99999999
Invalid RSA key length: maximum is 16384 bits

If you want RSA keys larger than 16k you'll need to compile OpenSSL with the larger limit then compile OpenSSH against that.  It'll probably be an interop hassle, though.
Comment 4 Damien Miller 2021-04-23 15:09:59 AEST
closing resolved bugs as of 8.6p1 release