Bug 3050

Summary: "Bits has bad value 99999 (too large)" and "key bits exceeds maximum 16384"
Product: Portable OpenSSH Reporter: zaomir
Component: ssh-keygenAssignee: Assigned to nobody <unassigned-bugs>
Status: CLOSED FIXED    
Severity: enhancement CC: djm, dtucker
Priority: P5    
Version: 7.9p1   
Hardware: All   
OS: Mac OS X   
Bug Depends on:    
Bug Blocks: 2988    
Attachments:
Description Flags
Defer bit size tests to key-specific check none

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