"Import OpenPGP public from URL" fails with "Can't read public key file." if the file contains additional newlines
Categories
(MailNews Core :: Security: OpenPGP, defect)
Tracking
(thunderbird_esr128 affected, thunderbird136 affected)
People
(Reporter: bugzilla_mozilla, Assigned: KaiE)
References
Details
Attachments
(2 files)
User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0
Steps to reproduce:
I tried to import a PGP public key into my keyring, but it failed. I isolated the issue to the existance of two newlines both [a] before and [b] after the ASCII armored PGP public key text.
To reproduce, let's use the Debian 12 release signing key https://ftp-master.debian.org/keys/release-12.asc
- Output the key to a file with two newlines before and after it
cat << EOF > /tmp/debian12.asc
-----BEGIN PGP PUBLIC KEY BLOCK-----
mDMEY865UxYJKwYBBAHaRw8BAQdAd7Z0srwuhlB6JKFkcf4HU4SSS/xcRfwEQWzr
crf6AEq0SURlYmlhbiBTdGFibGUgUmVsZWFzZSBLZXkgKDEyL2Jvb2t3b3JtKSA8
ZGViaWFuLXJlbGVhc2VAbGlzdHMuZGViaWFuLm9yZz6IlgQTFggAPhYhBE1k/sEZ
wgKQZ9bnkfjSWFuHg9SBBQJjzrlTAhsDBQkPCZwABQsJCAcCBhUKCQgLAgQWAgMB
Ah4BAheAAAoJEPjSWFuHg9SBSgwBAP9qpeO5z1s5m4D4z3TcqDo1wez6DNya27QW
WoG/4oBsAQCEN8Z00DXagPHbwrvsY2t9BCsT+PgnSn9biobwX7bDDg==
=5NZE
-----END PGP PUBLIC KEY BLOCK-----
EOF
-
In thunderbird, go to Tools -> Open PGP Key Manager
-
File -> Import Keys from URL
-
Type "file:///tmp/debian12.asc"
-
See error
Actual results:
The UI opens a pop-up window with error message:
Can't read public key file.
Expected results:
The key should have been imported into the keyring.
Comment 1•1 year ago
|
||
That file import fine for me on Daily.
Comment 2•1 year ago
|
||
I checked it as well - after download from the ftp key file contains two empty lines after the BEGIN PGP... in LF format, and one before the END PGP... (which is something expected), and is imported fine to RNP.
If you see two empty lines this could be probably related to the ftp software.
| Reporter | ||
Comment 3•1 year ago
|
||
Hi,
To be clear, I added 4 newlines to the file after download.
- Two newlines added before the
-----BEGIN PGP PUBLIC KEY BLOCK----- - Two newlines after the
-----END PGP PUBLIC KEY BLOCK-----
Did you try the command in the steps-to-reproduce?
cat << EOF > /tmp/debian12.asc
-----BEGIN PGP PUBLIC KEY BLOCK-----
mDMEY865UxYJKwYBBAHaRw8BAQdAd7Z0srwuhlB6JKFkcf4HU4SSS/xcRfwEQWzr
crf6AEq0SURlYmlhbiBTdGFibGUgUmVsZWFzZSBLZXkgKDEyL2Jvb2t3b3JtKSA8
ZGViaWFuLXJlbGVhc2VAbGlzdHMuZGViaWFuLm9yZz6IlgQTFggAPhYhBE1k/sEZ
wgKQZ9bnkfjSWFuHg9SBBQJjzrlTAhsDBQkPCZwABQsJCAcCBhUKCQgLAgQWAgMB
Ah4BAheAAAoJEPjSWFuHg9SBSgwBAP9qpeO5z1s5m4D4z3TcqDo1wez6DNya27QW
WoG/4oBsAQCEN8Z00DXagPHbwrvsY2t9BCsT+PgnSn9biobwX7bDDg==
=5NZE
-----END PGP PUBLIC KEY BLOCK-----
EOF
| Reporter | ||
Comment 4•1 year ago
|
||
hexdump shows unexpected results. Let's try this. I'll attach the file to this ticket, then you can download it and try to import it.
Comment 5•1 year ago
|
||
Yes that imports fine at least on Daily.
Comment 6•1 year ago
|
||
Thanks for the details, they explain things. If RNP doesn't hit EOF while importing keys from armored file, it attempts to initialize a next pass of armored data reading, as sometimes multiple armored chunks are pasted together in the single file. And this fails, as no more armored input follows.
I created the issue on RNP tracker here: https://github.com/rnpgp/rnp/issues/2308
Not sure whether this behaviour is standard-compliant, but would definitely imporve users convenience.
Updated•1 year ago
|
| Reporter | ||
Comment 7•1 year ago
|
||
Thanks. In the meantime, can we get a better error other than "Can't read public key file."
Comment 8•1 year ago
|
||
Why does it work for me?
| Reporter | ||
Comment 9•1 year ago
|
||
Maybe something about carriage returns? I'm using Debian 12. What system are you using?
Comment 10•1 year ago
|
||
Ubuntu 24.04
Comment 11•1 year ago
|
||
Function importKeyAsync from keyRing.sys.mjs calls EnigmailArmor.locateArmoredBlock which seems to strip extra data out from the input stream. Not sure whether it is the case, and when this was added, but remember (if I'm not mistaken) that there were some ticket talks about stripping extra spaces during the armored keys import. But, again, I'm not sure about it.
| Reporter | ||
Comment 12•1 year ago
|
||
Not sure whether this behaviour is standard-compliant, but would definitely imporve users convenience.
Just to add some additional context info: I encountered this issue when copying a PGP public key block from a website, and I had copied some newlines at the end of the block to the clipboard.
When I did "import from clipboard", thunderbird choked on it.
When I pasted the same clipboard contents into gpg --import, it worked fine.
It took me a long time to figure out that the newlines were an issue for thunderbird but not for gpg because the error wasn't very helpful.
| Assignee | ||
Comment 13•1 year ago
|
||
(In reply to Magnus Melin [:mkmelin] from comment #5)
Yes that imports fine at least on Daily.
Did you use "menu, edit, import from url" ?
| Assignee | ||
Comment 14•1 year ago
|
||
I can reproduce the error when using "import from url".
I cannot reproduce when using "import from file".
| Assignee | ||
Updated•1 year ago
|
| Assignee | ||
Comment 15•1 year ago
|
||
(In reply to Michael Altfield from comment #7)
Thanks. In the meantime, can we get a better error other than "Can't read public key file."
If the code isn't prepared for a specific scneario, then the code has to fall back to a generic error message.
Showing a better error message would require that the code understands exactly what's going on. But if it does, and there isn't a reason for aborting the operation, the code could be fixed to do the right thing instead.
So, I don't think it's worthwhile writing code to detect this new scenario and simply show a better error message. We probably should fix the scenario and avoid the error.
| Assignee | ||
Updated•1 year ago
|
| Assignee | ||
Comment 16•1 year ago
|
||
Updated•1 year ago
|
| Assignee | ||
Updated•1 year ago
|
Updated•1 year ago
|
Comment 17•1 year ago
|
||
Pushed by mkmelin@iki.fi:
https://hg.mozilla.org/comm-central/rev/6bcd7a563adc
Ingore whitespace around OpenPGP public key when importing from URL or clipboard. r=mkmelin
Description
•