Closed bitfehler closed 1 year ago
Digging a little deeper, I see that that the unarmoring is done via a regex, which seems to fail here:
script:
import pgpy
with open('hamcha.pgp', "rb") as f:
key = f.read()
print("%r" % pgpy.PGPKey.ascii_unarmor(key))
output:
{'magic': None, 'headers': None, 'body': bytearray(b'-----BEGIN PGP PUBLIC KEY BLOCK-----\r\nComment: User-ID:\tHamcha <hamcha@<redacted>>\r\nComment: Created:\t09/09/2021 15:19\r\nComment: Expires:\t09/09/2025 12:00\r\nComment: Type:\t256-bit EdDSA (secret key available)\r\nComment: Usage:\tSigning, Encryption, Certifying User-IDs, SSH Authentication\r\nComment: Fingerprint:\t21FC21B51DE174BD41BF2FDA1669C533B8CF6D89\r\n\r\n\r\nmDMEYToJzhYJKwYBBAHaRw8BAQdAREp4tSfFbLTvRDf54KwW+hIuK7WfbFmyke2I\r\nF4bUn7m0HUhhbWNoYSA8aGFtY2hhQGNydW5jaHkucm9ja3M+iJYEExYIAD4WIQQh\r\n/CG1HeF0vUG/L9oWacUzuM9tiQUCYToJzgIbIwUJB4Xw0gULCQgHAgYVCgkICwIE\r\nFgIDAQIeAQIXgAAKCRAWacUzuM9tiQpPAP4yk/88CmEqz3vmTztXk70hDYefScOg\r\ngFyYyx4LCGg6AwD+L0o423dq1yMnFchj5cRMG6Prud2xfVnz0NMag+BwAgi4OARh\r\nOgnOEgorBgEEAZdVAQUBAQdAl7zONuTCOZTccZPqnoZtLOUjnqWoNDYcE1zcT/91\r\nSFQDAQgHiH4EGBYIACYWIQQh/CG1HeF0vUG/L9oWacUzuM9tiQUCYToJzgIbDAUJ\r\nB4Xw0gAKCRAWacUzuM9tiRkhAQDkaEDFNhmEjqigWqbwDKv9ndWbl81AFN7zi7EQ\r\nsg2jnAEAhy+n7KaJ6nM/BG+vuArxdfuD2HnKhino6q96MJOc/gU=\r\n=wlZE\r\n-----END PGP PUBLIC KEY BLOCK-----\n'), 'crc': None}
which certainly doesn't seem right. I'll keep digging, but if anyone more knowledgeable has any hints...
Okay, so it turns out this is because the regular expression that checks if the input is ASCII does not allow tabs.
Given the following key:
and this minimal script:
The script fails:
However, simply removing all the armor headers (and one of the blank the lines) from the input key makes it work just fine:
I also tried removing all but one headers or such, but to no avail.
Both GnuPG and go-openpgp handle the key file with headers just fine.