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

Pad GPG Key ID with preceding zeroes #20878

Merged
merged 3 commits into from
Aug 21, 2022

Conversation

zeripath
Copy link
Contributor

The go crypto library does not pad keyIDs to 16 characters with preceding zeroes. This
is a somewhat confusing thing for most users who expect these to have preceding zeroes.

This PR prefixes any sub 16 length KeyID with preceding zeroes and removes preceding
zeroes from KeyIDs inputted on the API.

Fix #20876

Signed-off-by: Andrew Thornton art27@cantab.net

The go crypto library does not pad keyIDs to 16 characters with preceding zeroes. This
is a somewhat confusing thing for most users who expect these to have preceding zeroes.

This PR prefixes any sub 16 length KeyID with preceding zeroes and removes preceding
zeroes from KeyIDs inputted on the API.

Fix go-gitea#20876

Signed-off-by: Andrew Thornton <art27@cantab.net>
@GiteaBot GiteaBot added the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Aug 20, 2022
@@ -177,6 +178,12 @@ func VerifyUserGPGKey(ctx *context.APIContext) {
token := asymkey_model.VerificationToken(ctx.Doer, 1)
lastToken := asymkey_model.VerificationToken(ctx.Doer, 0)

form.KeyID = strings.TrimLeft(form.KeyID, "0")
Copy link
Member

Choose a reason for hiding this comment

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

Can keys start with zeros, or is a leading zero always seen as padding?
Because if it is the former, this will probably produce a lot of problems in the future…

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Take a look at pubkey.KeyIDString()

The trimming is to fix potential issues relating to that

@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 Aug 20, 2022
@ghost
Copy link

ghost commented Aug 21, 2022

I have another question. Why is the first line of GPG public key displayed on Gitea (/user.gpg) different from the one I pasted? GitHub will be consistent with the original text

@techknowlogick techknowlogick merged commit 11bae50 into go-gitea:main Aug 21, 2022
@zeripath zeripath deleted the fix-20876-pad-gpg-key-ids branch August 21, 2022 08:07
zeripath added a commit to zeripath/gitea that referenced this pull request Aug 21, 2022
Backport go-gitea#20878

The go crypto library does not pad keyIDs to 16 characters with preceding zeroes. This
is a somewhat confusing thing for most users who expect these to have preceding zeroes.

This PR prefixes any sub 16 length KeyID with preceding zeroes and removes preceding
zeroes from KeyIDs inputted on the API.

Fix go-gitea#20876

Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath zeripath added the backport/done All backports for this PR have been created label Aug 21, 2022
@zeripath
Copy link
Contributor Author

I have another question. Why is the first line of GPG public key displayed on Gitea (/user.gpg) different from the one I pasted? GitHub will be consistent with the original text

I'm afraid I don't understand what you're talking about. Open a new issue with an example.

zjjhot added a commit to zjjhot/gitea that referenced this pull request Aug 22, 2022
* giteaofficial/main:
  update current stable version
  [skip ci] Updated translations via Crowdin
  Fix mirror address setting not working (go-gitea#20850)
  Support Proxy protocol (go-gitea#12527)
  Fix SQL Query for `SearchTeam` (go-gitea#20844)
  Double check CloneURL is acceptable (go-gitea#20869)
  Fix graceful doc (go-gitea#20883)
  Pad GPG Key ID with preceding zeroes (go-gitea#20878)
  [skip ci] Updated translations via Crowdin
  call builtinUnused() if internal SSH is disabled (go-gitea#20877)
  Don't open new page for ext wiki on same repository (go-gitea#20725)
  [skip ci] Updated translations via Crowdin
  Fix the mode of custom dir to 0700 in docker-rootless (go-gitea#20861)
  Fix UI mis-align for PR commit history (go-gitea#20845)
zeripath added a commit that referenced this pull request Aug 22, 2022
Backport #20878

The go crypto library does not pad keyIDs to 16 characters with preceding zeroes. This
is a somewhat confusing thing for most users who expect these to have preceding zeroes.

This PR prefixes any sub 16 length KeyID with preceding zeroes and removes preceding
zeroes from KeyIDs inputted on the API.

Fix #20876

Signed-off-by: Andrew Thornton <art27@cantab.net>
vsysoev pushed a commit to IntegraSDL/gitea that referenced this pull request Aug 28, 2022
@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created 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.

Mirrored commits omitting leading zero from GPG Key ID
4 participants