gitea: key exhange negotiation failed though client and server share some protocols
Gitea Version
1.15.3
Git Version
2.33.0
Operating System
CentOS 7
How are you running Gitea?
After a openssh client upgrade, push to gitea
Database
SQLite
Can you reproduce the bug on the Gitea demo site?
No
Log Gist
No response
Description
using built-in SSH server with below config:
[server]
SSH_SERVER_CIPHERS = aes128-ctr aes192-ctr aes256-ctr aes128-gcm@openssh.com arcfour256 arcfour128
SSH_SERVER_KEY_EXCHANGES = curve25519-sha256 diffie-hellman-group1-sha1 diffie-hellman-group14-sha1 ecdh-sha2-nistp256 ecdh-sha2-nistp384 ecdh-sha2-nistp521 curve25519-sha256@libssh.org ssh-rsa
both client and server have common algorithm, but report no common algorithm for key exchange
2021/09/29 10:46:19 modules/ssh/ssh.go:259:sshConnectionFailed() [W] Failed connection from 10.118.13.125:50358 with error: ssh: no common algorithm for key exchange;
client offered: [curve25519-sha256 curve25519-sha256@libssh.org ecdh-sha2-nistp256 ecdh-sha2-nistp384 ecdh-sha2-nistp521 diffie-hellman-group-exchange-sha256 diffie-hellman-group16-sha512 diffie-hellman-group18-sha512 diffie-hellman-group14-sha256 ext-info-c],
server offered: [curve25519-sha256 diffie-hellman-group1-sha1 diffie-hellman-group14-sha1 ecdh-sha2-nistp256 ecdh-sha2-nistp384 ecdh-sha2-nistp521 curve25519-sha256@libssh.org]
Screenshots
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 2
- Comments: 20 (6 by maintainers)
Commits related to this issue
- Offer rsa-sha2-512 and rsa-sha2-256 algorithms in internal SSH There is a subtle bug in the SSH library x/crypto/ssh which makes the incorrect assumption that the public key type is the same as the s... — committed to zeripath/gitea by zeripath 3 years ago
- Offer rsa-sha2-512 and rsa-sha2-256 algorithms in internal SSH (#17281) * Offer rsa-sha2-512 and rsa-sha2-256 algorithms in internal SSH There is a subtle bug in the SSH library x/crypto/ssh which... — committed to go-gitea/gitea by zeripath 3 years ago
- Offer rsa-sha2-512 and rsa-sha2-256 algorithms in internal SSH (#17281) Backport #17281 There is a subtle bug in the SSH library x/crypto/ssh which makes the incorrect assumption that the public key... — committed to zeripath/gitea by zeripath 3 years ago
- Offer rsa-sha2-512 and rsa-sha2-256 algorithms in internal SSH (#17281) (#17376) Backport #17281 There is a subtle bug in the SSH library x/crypto/ssh which makes the incorrect assumption that th... — committed to go-gitea/gitea by zeripath 3 years ago
- Offer rsa-sha2-512 and rsa-sha2-256 algorithms in internal SSH (#17281) * Offer rsa-sha2-512 and rsa-sha2-256 algorithms in internal SSH There is a subtle bug in the SSH library x/crypto/ssh which... — committed to Chianina/gitea by zeripath 3 years ago
I’m not sure if it’s related but after the upgrade I started getting:
I’m also using built-in SSH server and I didn’t configure neither
SSH_SERVER_KEY_EXCHANGESnorSSH_SERVER_CIPHERSpreviously, so I suppose it uses defaults.Workaround is to specify SSH parameter in
~/.ssh/config:For anyone who ends up here, here is how you can easily switch over to ed25519.
Use ed25519 on the gitea side
Add
SSH_SERVER_HOST_KEYS = ssh/gitea.ed25519to yourapp.ini:Don’t bother setting
SSH_SERVER_CIPHERS,SSH_SERVER_KEY_EXCHANGESandSSH_SERVER_MACS, that is not necessary. However, in case you find it necessary to do so, please consultman sshd_configandssh -Q cipher|key|key-sig.In case the keys don’t get generated automatically, move to the
sshdirectory in your gitea data dir and generate the keys manually:Then restart gitea, and look for the following entry in the log
Perhaps the gitea config cheat sheet is useful, if the above stated suggestions don’t work for you and you need to dive deeper into the configuration options.
Force ssh to use ed25519 for your gitea server
In my case the above stated steps were enough to fix the issue. If for some reason, you ssh needs to be forced to use ed25519, then see the following template for your
~/.ssh/configfileUpdate
Addendum: Friend of mine reported,
giteawill generate a rsa key by default, so it looks like it’s mandatory to generate the keys manuallyApparently
ssh-rsahost key algorithm (and apparently also the signature algorithm) was declared deprecation a year ago and it finally has an effect.Also to add insult to injury, it seems like gitea’s internal ssh server is hard-coded to only generate
ssh-rsakeys so I can’t easily force it intorsa-sha2-*or other key types/algorithms, and the easiest workaround seems to be enablingssh-rsaback as @nougad suggested.For people looking for a workaround way to fix this on their server without people having to make changes to
~/.ssh/configon the client end: If you manually generate and ED25519 keypairssh-keygen -t ed25519and reference them with theSSH_SERVER_HOST_KEYSsetting inapp.iniit will force a better signature algorithm based on said key type.IMO, it’s worth looking at moving to ED25519 or another elliptic curve algorithm as the default for Gitea, as RSA is getting closer to being totally broken all the time.
I’m having the same issue as @synaptiko above. Adding
HostkeyAlgorithms ssh-rsato my~/.ssh/configfor the host fixed the host key type problem, but my keys don’t work. Seems like the internal ssh server just isn’t working as it used to.EDIT: Turns out I’m running gitea 1.14.5, so nevermind, I should probably be running the freshest code before complaining 😄 Worked around it personally by just switching to the system’s ssh server instead of gitea’s internal one.
My company’s entire ed25519 keys stopped working lmao Why is everything set to RSA? it’s not 2010…
<del>>SSH_SERVER_HOST_KEYS: ssh/gitea.rsa, ssh/gogs.rsa: For the built-in SSH server, choose the keypairs to offer as the host key. The private key should be at SSH_SERVER_HOST_KEY and the public SSH_SERVER_HOST_KEY.pub. Relative paths are made absolute relative to the APP_DATA_PATH. If no key exists a 4096 bit RSA key will be created for you.</del>
<del>uhh what, anyone able to tell me what to do to just get ed25519 keys going? idc about any other ones. </del>
nvm all you need to do is generate a new ed25519 key and set it with SSH_SERVER_HOST_KEYS as the guy above said… can’t believe you guys are using RSA key lmao…
also running the via the binary (not docker) @zeripath but seems you figured it out (using the gitea internal SSH server… I run openSSH server already and have no issues there, as I’ve used ed25519 for several years.)
@dogtopus
The easiest solution is just generating an ed25519 and pointing to it, takes <10 seconds
FWIW to gitea devs https://pkg.go.dev/crypto/ed25519
Yes but if you got a bunch of different clients connected to the server it would be a PITA to update them all to use the new public key. Although adding back RSA SHA1 on every machine is not ideal either.
@Poyoman39 the attached PR will solve the issue.
Oh damn - this is going to be annoying and difficult to fix.
Fundamentally there is a problem in the way that Go’s x/crypto/ssh library does the handshake.