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

Repository.Push fails with You're using an RSA key with SHA-1 even if ssh key works ok from CLI #516

Closed
shaftoe opened this issue Apr 13, 2022 · 10 comments

Comments

@shaftoe
Copy link

shaftoe commented Apr 13, 2022

We recently migrated all our codebase from GitLab to GitHub and one of our internal tools (go v1.18) suddenly stopped working.

This example should help to better describe and reproduce the issue: https://github.com/plato-app/alex-test-gitpush/blob/master/main.go

This is the output running go run main.go on my Macbook Air M1:

FATA[2022-04-13T09:02:51-04:00] unknown error: ERROR: You're using an RSA key with SHA-1, which is no longer allowed. Please use a newer client or a different key type.

The commit gets created correclty, only the push fails, but pushing the very same commit from Git CLI (git version 2.32.0 (Apple Git-132)) it works correctly:

Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 279 bytes | 279.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To github.com:plato-app/alex-test-gitpush.git
   b7ab13c..3045da8  master -> master

SSH key loaded via SSH agent, ssh-key -l shows 4092 SHA256:PZfI8AJp6diTWnUZ1jh[cut...] (RSA)

@shaftoe
Copy link
Author

shaftoe commented Apr 13, 2022

I'm gathering feedback from other colleagues and this seems to be another error:

FATA[2022-04-13T17:11:30+04:00] ssh: handshake failed: knownhosts: key mismatch

Please note that the ssh key is properly loaded in the ssh agent and Git CLI works correctly

@smveloso
Copy link

I'm gathering feedback from other colleagues and this seems to be another error:

FATA[2022-04-13T17:11:30+04:00] ssh: handshake failed: knownhosts: key mismatch

Please note that the ssh key is properly loaded in the ssh agent and Git CLI works correctly

Maybe you are facing this issue: #411

Hope it helps.

@shaftoe
Copy link
Author

shaftoe commented Apr 19, 2022

@smveloso thanks a lot, it appears to help indeed. For the records this seems to be the actual magic trick:

ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
ssh-keyscan -t ecdsa github.com >> ~/.ssh/known_hosts

@robnester-rh
Copy link

I'm running into the same issue, but trying the suggested fixes of:

ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
ssh-keyscan -t ecdsa github.com >> ~/.ssh/known_hosts

doesn't seem to work for me. Is anyone else seeing this and, if so, have you found a workaround?

@manno
Copy link

manno commented Aug 5, 2022

Since go-git is using x/crypto/ssh via github.com/gliderlabs/ssh, I think it is affected by golang/go#49952
Which means it doesn't use the strongest possible cipher with older keys.

@juicemia
Copy link

Hello everybody,

I'm seeing this happen on clones as well.

Just doing a plain clone like this:

				_, err := git.PlainClone(cloneDir, false, &git.CloneOptions{
					URL: repo.URL,
				})

Results in this error:

unknown error: ERROR: You're using an RSA key with SHA-1, which is no longer allowed. Please use a newer client or a different key type.

This SSH key was created using this command:

ssh-keygen -t rsa -b 2048 -f ~/.ssh/github

@juicemia
Copy link

juicemia commented Aug 12, 2022

Just got the following working as a workaround.

# Generate an ECDSA key since it doesn't seem to be affected by this SHA-1 RSA thing.
ssh-keygen -t ecdsa -f /path/to/github/ecdsa/key

Then in my code:

auth, err := ssh.NewPublicKeysFromFile("git", "/path/to/github/ecdsa/key", "")
if err != nil {
        // handle it
}

_, err = git.PlainClone(cloneDir, false, &git.CloneOptions{
	Auth: auth,
	URL:  repo.URL,
})

@bk2204
Copy link

bk2204 commented Nov 29, 2022

I believe this will be fixed if you upgrade golang.org/x/crypto to v0.3.0. I've just tested a test program with that version against GitHub with an RSA key and it appears to work correctly.

If folks want, I can even send a PR with that change.

@pjbgf
Copy link
Member

pjbgf commented Nov 30, 2022

#620 already updates golang.org/x/crypto to v0.3.0, once that gets merged folks could try again using the version from master. Alternatively, the replace directive can be used on your go.mod to force the use of golang.org/x/crypto@v0.3.0.

@pjbgf
Copy link
Member

pjbgf commented Mar 5, 2023

Fixed as per #620 merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants