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

Use ErrKeyUnableToVerify if fail to calc fingerprint in ssh-keygen #10863

Merged
merged 4 commits into from
Mar 28, 2020

Conversation

zeripath
Copy link
Contributor

Fix #3985

Signed-off-by: Andrew Thornton [email protected]

@zeripath zeripath added this to the 1.12.0 milestone Mar 28, 2020
Copy link
Member

@sapk sapk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me but would be better with a new test case here:

{"ecdsa-384", "SHA256:4qfJOgJDtUd8BrEjyVNdI8IgjiZKouztVde43aDhe1E", "ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBINmioV+XRX1Fm9Qk2ehHXJ2tfVxW30ypUWZw670Zyq5GQfBAH6xjygRsJ5wWsHXBsGYgFUXIHvMKVAG1tpw7s6ax9oA+dJOJ7tj+vhn8joFqT+sg3LYHgZkHrfqryRasQ== nocomment"},

and even better with an integration test using :
https://github.com/go-gitea/gitea/blob/f9f2c163b12f60a6bf9c3652cdc4bdf59e3d53c4/integrations/api_helper_for_declarative_test.go#L140:6

@GiteaBot GiteaBot added the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Mar 28, 2020
@zeripath
Copy link
Contributor Author

unfortunately I don't have an example otherwise I'd have done the tests

@zeripath
Copy link
Contributor Author

I found one in https://github.com/Ganapati/RsaCtfTool/blob/master/examples/weak_public.pub#L1

@sapk
Copy link
Member

sapk commented Mar 28, 2020

@zeripath I have created a rsa 1023 bit public key

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgFSbX7pXBc5xW5ByF4RB6Lr8HbfW0/LXq90UjWpRSR6z+HEfN/4m8jRF5Vl/GCtu86YSi9au1TeZ0kHgTTCgQIv5vc+zZJkx4mbzpQ+WzEYB9SET4W3AZBv3diJVXQX6KuMICgq30PeVB4PsZoyBasjSS422pCCgFDpH/l6JgYlJ

@sapk
Copy link
Member

sapk commented Mar 28, 2020

I have just seen your message and you can use either.
I have tested the key I provided with ssh-keygen:

ssh-keygen -lf rsa_test.pub
rsa_test.pub is not a public key file.

@codecov-io
Copy link

Codecov Report

Merging #10863 into master will increase coverage by 0.01%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10863      +/-   ##
==========================================
+ Coverage   43.42%   43.43%   +0.01%     
==========================================
  Files         593      593              
  Lines       83262    83268       +6     
==========================================
+ Hits        36155    36168      +13     
+ Misses      42615    42614       -1     
+ Partials     4492     4486       -6     
Impacted Files Coverage Δ
models/ssh_key.go 50.64% <0.00%> (-0.22%) ⬇️
routers/user/setting/keys.go 12.38% <0.00%> (-0.34%) ⬇️
modules/queue/workerpool.go 56.93% <0.00%> (-2.14%) ⬇️
modules/git/repo.go 48.11% <0.00%> (+0.83%) ⬆️
modules/git/command.go 89.56% <0.00%> (+2.60%) ⬆️
services/pull/check.go 53.04% <0.00%> (+3.04%) ⬆️
modules/process/manager.go 78.31% <0.00%> (+3.61%) ⬆️
modules/git/utils.go 70.14% <0.00%> (+4.47%) ⬆️
modules/indexer/stats/db.go 59.37% <0.00%> (+9.37%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f9f2c16...b5d799f. Read the comment docs.

@zeripath
Copy link
Contributor Author

OK so the issue is that calcFingerprintNative will happily parse both of those keys but calcFingerprintSSHKeygen will not.

@zeripath
Copy link
Contributor Author

Happily however, testing with both those keys has shown to me that I missed passing up the error upstream.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 28, 2020
@zeripath
Copy link
Contributor Author

zeripath commented Mar 28, 2020

So I've discovered that CheckPublicKeyString doesn't seem actually checking the length correctly. - that's because it's not set on by default!

@zeripath
Copy link
Contributor Author

Ah, if we have Native SSH key gen we should probably have the minimum key sizes set by default to at least what they are in ssh keygen

@sapk
Copy link
Member

sapk commented Mar 28, 2020

@zeripath yes the standard go lib for rsa is not restricting size (we should check it).
That how I generate the rsa for the test.

@lafriks lafriks merged commit ea67e56 into go-gitea:master Mar 28, 2020
@zeripath zeripath deleted the fix-3985 branch March 28, 2020 18:02
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide more meaningful error message when adding SSH keys fails
5 participants