Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support @openssh.com ciphers for ssh keys #8964

Open
novasharper opened this issue Jan 6, 2023 · 17 comments
Open

Support @openssh.com ciphers for ssh keys #8964

novasharper opened this issue Jan 6, 2023 · 17 comments

Comments

@novasharper
Copy link
Contributor

Overview

Cannot add password-protected ed25519 key

Steps to Reproduce

  1. Generate ed25519 key with password
  2. Add key entry with password set
  3. Click Add to agent button

Expected Behavior

Private keyfile is accepted

Actual Behavior

Error popup Unknown cipher: aes-256gcm@openssh.com
image

Context

KeePassXC - Version 2.7.4
Revision: 63b2394

Operating System: Linux
Desktop Env: Gnome
Windowing System: Wayland

@novasharper novasharper added the bug label Jan 6, 2023
@droidmonkey
Copy link
Member

How exactly did you generate the key?

@novasharper
Copy link
Contributor Author

I used ssh-keygen -t ed25519

@droidmonkey
Copy link
Member

I just did that and everything worked fine

@novasharper
Copy link
Contributor Author

Yeah. I tried with a test key that I freshly generated and did not run into the issue. I think that the problem is that I was importing the key after exporting it from 1password. I am not sure how to debug what about the export with password process resulted in this issue.

@droidmonkey
Copy link
Member

It isn't something we would fix because the error shown is likely due to a key format error. You will probably have to convert the key into a proper format to be used in KeePassXC.

@novasharper
Copy link
Contributor Author

The key I exported from 1password worked when I directly used it with openssh, though.

@novasharper
Copy link
Contributor Author

novasharper commented Jan 7, 2023

@droidmonkey I took a look at the base64-encoded data and saw that the key I had generated was encrypted with aes256-ctr.

When I looked at the manpage for ssh-keygen, it indicated that I should use ssh -Q ciphers to get the list of valid cipers to use. It looks like for aes(128|256)-gcm, the cipher name has the @openssh.com tacked on to the end.

$ ssh -Q ciphers
3des-cbc
aes128-cbc
aes192-cbc
aes256-cbc
aes128-ctr
aes192-ctr
aes256-ctr
aes128-gcm@openssh.com
aes256-gcm@openssh.com
chacha20-poly1305@openssh.com

I also saw this when looking at the list of ciphers in the openssh source code. When I tried doing ssh-keygen -t ed25519 -Z aes256-gcm -f test, it indicated that aes256-gcm was an invalid cipher. I needed to specify the cipher name as aes256-gcm@openssh.com (this was then embedded in the key data).

@droidmonkey
Copy link
Member

@hifi

@droidmonkey droidmonkey changed the title Cannot add ed25519 key to ssh agent Support @openssh.com ciphers for ssh keys Jan 7, 2023
@droidmonkey droidmonkey reopened this Jan 7, 2023
@novasharper
Copy link
Contributor Author

Also, after I modified the cipher detection to use startsWith when checking for aes256-gcm, it ran into an error that the buffer size was not a multiple of the granularity (botan:src/lib/modes/aead/gcm/gcm.cpp)

size_t GCM_Decryption::process(uint8_t buf[], size_t sz)
   {
   BOTAN_ARG_CHECK(sz % update_granularity() == 0, "Invalid buffer size");
   m_ghash->update(buf, sz);
   m_ctr->cipher(buf, buf, sz);
   return sz;
   }

@droidmonkey
Copy link
Member

Likely because this is some custom format that openssh invented because why do standards right?

@novasharper
Copy link
Contributor Author

novasharper commented Jan 7, 2023

It looks like this is an official standard. Or at least, there is a spec/doc from NIST on the GCM mode for AES.

https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf

And Intel + Microsoft have support for it in some of their APIs.

@droidmonkey
Copy link
Member

GCM is a standard, but clearly it's "special" in openssh land

@hifi
Copy link
Member

hifi commented Jan 7, 2023

I suppose this depends on how easy it is to support this with botan.

@novasharper
Copy link
Contributor Author

It looks like this will require botan changes first. There would need to be some way of telling it to just use block size as the update granularity instead of multiplying by max(2, BOTAN_BLOCK_CIPHER_PAR_MULT) where BOTAN_BLOCK_CIPHER_PAR_MULT = 4 by default.

@novasharper
Copy link
Contributor Author

randombit/botan#3168 just merged, so botan has the necessary fixes. However, the changes will be in 3.0, so the full fix would have to wait (at least) until it is released.

@droidmonkey
Copy link
Member

Nice!

@droidmonkey droidmonkey reopened this Jan 29, 2023
@droidmonkey
Copy link
Member

Woops closed through PR merge

dmaslenko pushed a commit to dmaslenko/keepassxc that referenced this issue Jan 30, 2023
* Fix detecting AES-256/GCM cipher, fixes keepassxreboot#8964 

When you generate a ssh key using the aes-256/gcm cipher, the cipher name in the keyfile includes an @openssh.com at the end.

* Use separate iv length for getting iv data, the assumption that the block size and iv size are equal does not hold for every cipher mode (e.g., GCM)

* Disable AES-256/GCM for now in ssh keys 

Currently, the granularity for the botan gcm implementation is too large. To fix a problem with another algorithm in the library, they are multiplying
the blocksize, so by default the granularity is 64. This causes issues since the encrypted data in the key is only guaranteed to have a length that is a multiple of the block size (16).
pull bot pushed a commit to tigerwill90/keepassxc that referenced this issue Jan 30, 2023
* Fix detecting AES-256/GCM cipher, fixes keepassxreboot#8964 

When you generate a ssh key using the aes-256/gcm cipher, the cipher name in the keyfile includes an @openssh.com at the end.

* Use separate iv length for getting iv data, the assumption that the block size and iv size are equal does not hold for every cipher mode (e.g., GCM)

* Disable AES-256/GCM for now in ssh keys 

Currently, the granularity for the botan gcm implementation is too large. To fix a problem with another algorithm in the library, they are multiplying
the blocksize, so by default the granularity is 64. This causes issues since the encrypted data in the key is only guaranteed to have a length that is a multiple of the block size (16).
pull bot pushed a commit to contropist/keepassxc that referenced this issue Jan 30, 2023
* Fix detecting AES-256/GCM cipher, fixes keepassxreboot#8964 

When you generate a ssh key using the aes-256/gcm cipher, the cipher name in the keyfile includes an @openssh.com at the end.

* Use separate iv length for getting iv data, the assumption that the block size and iv size are equal does not hold for every cipher mode (e.g., GCM)

* Disable AES-256/GCM for now in ssh keys 

Currently, the granularity for the botan gcm implementation is too large. To fix a problem with another algorithm in the library, they are multiplying
the blocksize, so by default the granularity is 64. This causes issues since the encrypted data in the key is only guaranteed to have a length that is a multiple of the block size (16).
droidmonkey pushed a commit that referenced this issue Feb 18, 2023
* Fix detecting AES-256/GCM cipher, fixes #8964 

When you generate a ssh key using the aes-256/gcm cipher, the cipher name in the keyfile includes an @openssh.com at the end.

* Use separate iv length for getting iv data, the assumption that the block size and iv size are equal does not hold for every cipher mode (e.g., GCM)

* Disable AES-256/GCM for now in ssh keys 

Currently, the granularity for the botan gcm implementation is too large. To fix a problem with another algorithm in the library, they are multiplying
the blocksize, so by default the granularity is 64. This causes issues since the encrypted data in the key is only guaranteed to have a length that is a multiple of the block size (16).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants