Remove broken support for PEM-encoded SSH public keys #3655

Closed
opened 2025-11-02 05:20:41 -06:00 by GiteaMirror · 3 comments
Owner

Originally created by @silverwind on GitHub (Jul 23, 2019).

Trying to add a PEM-encoded public SSH key like

-----BEGIN RSA PUBLIC KEY-----
MIIBigKCAYEA7lqx/TJQQBSbMRNrwp+uAnBo2wTB/8Awb63Z8GwvDAH12Jz9JWYy
SE5ZglIw/JZ9h1zAK3F/ka8w0brLrzlQWyumjN1Rso4esl4yEOKbOdEDrA/rGyxJ
7wlUO8krU4Wd+BDo5yp/n+ugM6kEbrYSDKgFk/1g13kBiW3aLj5rlMYUJiy6hZkn
tSSVJ8w6zY6yj23UAgc2JmeAzSzutAx5NHeDdTeYl98nhu44JGNKkxHBCrAUizp0
FcNhMoApzONhStKJ2EhbXic2aasMTb91EzRW/7flJBJVtQLxOoQUYmzKKQGJJCkw
KJQuOj9GqtDDvV2v3meBUoTJE86j4Uu3TBAAhnH9XUGvploI6WrLm3n+Jp9Y/XJI
S65fqu9xBCoEl64jLf4dFSuCMRK02MAQV2siIRyIui3M4O5K5UEOwaReuVOOWzMj
vRoGeXYhMfuBA432qQTAtC6gBIn9UcejPdk2f5KErOhJeYGue3pHOagx3l7NWfZt
fEFyGifkl9k/AgMBAAE=
-----END RSA PUBLIC KEY-----

on a user or repo results in this weird error coming from here:

extractTypeFromBase64Key: invalid key format: not enough length 813826442

This has probably been broken for years.

Originally created by @silverwind on GitHub (Jul 23, 2019). Trying to add a PEM-encoded public SSH key like ```` -----BEGIN RSA PUBLIC KEY----- MIIBigKCAYEA7lqx/TJQQBSbMRNrwp+uAnBo2wTB/8Awb63Z8GwvDAH12Jz9JWYy SE5ZglIw/JZ9h1zAK3F/ka8w0brLrzlQWyumjN1Rso4esl4yEOKbOdEDrA/rGyxJ 7wlUO8krU4Wd+BDo5yp/n+ugM6kEbrYSDKgFk/1g13kBiW3aLj5rlMYUJiy6hZkn tSSVJ8w6zY6yj23UAgc2JmeAzSzutAx5NHeDdTeYl98nhu44JGNKkxHBCrAUizp0 FcNhMoApzONhStKJ2EhbXic2aasMTb91EzRW/7flJBJVtQLxOoQUYmzKKQGJJCkw KJQuOj9GqtDDvV2v3meBUoTJE86j4Uu3TBAAhnH9XUGvploI6WrLm3n+Jp9Y/XJI S65fqu9xBCoEl64jLf4dFSuCMRK02MAQV2siIRyIui3M4O5K5UEOwaReuVOOWzMj vRoGeXYhMfuBA432qQTAtC6gBIn9UcejPdk2f5KErOhJeYGue3pHOagx3l7NWfZt fEFyGifkl9k/AgMBAAE= -----END RSA PUBLIC KEY----- ```` on a user or repo results in this weird error coming from [here](https://github.com/go-gitea/gitea/blob/bcbc9f33d73393c47b27793ac91b8f9faf98d349/models/ssh_key.go#L91): ```` extractTypeFromBase64Key: invalid key format: not enough length 813826442 ```` This has probably been broken for years.
Author
Owner

@zeripath commented on GitHub (Jul 24, 2019):

OK so there appear to be two different type of keys here - neither of which appear to work.

There is the SSH2 key type which I think is what this code is supposed to work for - but doesn't because they start with ---- BEGIN not -----BEGIN.

And there is the PEM type which is what you've tried here.

@zeripath commented on GitHub (Jul 24, 2019): OK so there appear to be two different type of keys here - neither of which appear to work. There is the SSH2 key type which I think is what this code is supposed to work for - but doesn't because they start with `---- BEGIN` not `-----BEGIN`. And there is the PEM type which is what you've tried here.
Author
Owner

@silverwind commented on GitHub (Jul 24, 2019):

Yeah, it looks like the code is meant for this format:

---- BEGIN SSH2 PUBLIC KEY ----
Comment: "rsa-key-20160816"
AAAAB3NzaC1yc2EAAAABJQAAAQEApoYJFnGDNis/2oCT6/h9Lzz2y0BVHLv8joXM
s4SYcYUVwBxNzqJsDWbikBn/h32AC36qAW24Bft+suGMtJGS3oSX53qR7ozsXs/D
lCO5FzRxi4JodStiYaz/pPK24WFOb4sLXr758tz2u+ZP2lfDfzn9nLxregZvO9m+
zpToLCWlXrzjZxDesJOcfh/eszU9KUKXfXn6Jsey7ej8TYqB2DgYCfv8jGm+oLVe
UOLEl7fxzjgcDdiLaXbqq7dFoOsHUABBV6kaXyE9LmkbXZB9lQ==
---- END SSH2 PUBLIC KEY ----

The way the fences are written there will not match our check for -----BEGIN which I added assuming it was for above format. I guess since no one complained about these keys not being supported, I guess we may as well opt to drop support for them given that they can easily be converted to the OpenSSH format.

I also just tested on GitHub and they only support the OpenSSH format.

@silverwind commented on GitHub (Jul 24, 2019): Yeah, it looks like the code is meant for this format: ```` ---- BEGIN SSH2 PUBLIC KEY ---- Comment: "rsa-key-20160816" AAAAB3NzaC1yc2EAAAABJQAAAQEApoYJFnGDNis/2oCT6/h9Lzz2y0BVHLv8joXM s4SYcYUVwBxNzqJsDWbikBn/h32AC36qAW24Bft+suGMtJGS3oSX53qR7ozsXs/D lCO5FzRxi4JodStiYaz/pPK24WFOb4sLXr758tz2u+ZP2lfDfzn9nLxregZvO9m+ zpToLCWlXrzjZxDesJOcfh/eszU9KUKXfXn6Jsey7ej8TYqB2DgYCfv8jGm+oLVe UOLEl7fxzjgcDdiLaXbqq7dFoOsHUABBV6kaXyE9LmkbXZB9lQ== ---- END SSH2 PUBLIC KEY ---- ```` The way the fences are written there will not match our check for `-----BEGIN` which I added assuming it was for above format. I guess since no one complained about these keys not being supported, I guess we may as well opt to drop support for them given that they can easily be converted to the OpenSSH format. I also just tested on GitHub and they only support the OpenSSH format.
Author
Owner

@zeripath commented on GitHub (Jul 24, 2019):

So #7600 should fix this.

@zeripath commented on GitHub (Jul 24, 2019): So #7600 should fix this.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#3655