Page MenuHome GnuPG

"Invalid option" with utf-16 config files (windows)
Open, NormalPublic

Description

If you create a config file as utf-16 (easy to do unwittingly, e.g. with output
redirection in powershell) then gnupg programs will throw "invalid option".

I discovered this with gpg-agent when trying to add "enable-putty-support" to
gpg-agent.conf. If I edit the file (previously nonexistent) in notepad++, it is
saved by default as ASCII and there is no problem. If I create it using `echo
enable-putty-support > gpg-agent.conf`, then it gets created as utf-16 and is
unparseable.

utf-16 is the default encoding for many programs in Windows. gnupg on Windows
should either parse utf-16, or failing that throw an error clearly stating that
utf-16 config files are not supported.

Details

Version
2.1.15

Event Timeline

Any suggestion on how to detect utf-16 easily?

Werner Koch <wk@gnupg.org> added the comment:

Any suggestion on how to detect utf-16 easily?

Yes, the BOM can be used as a magic number. It will appear either as the byte sequence "0xFF,0xFE", or "0xFE,0xFF", depending on endianness.

It might also be worth detecting UTF8 the same way, by the magic number "0xEF,0xBB,0xBF" - although you may wish to silently drop the magic number and carry on parsing in that case because 7-bit clean UTF8 is often found in the wild and is otherwise identical to ASCII...

See https://en.m.wikipedia.org/wiki/Byte_order_mark

A

It seems that editing a pre-created revocation certificate on Windows with Notepad doesn't let Kleopatra detect this correctly as OpenPGP file and thus refuses to import. Works on the command line but needs more testing.

ikloecker added a subscriber: ikloecker.

It seems that editing a pre-created revocation certificate on Windows with Notepad doesn't let Kleopatra detect this correctly as OpenPGP file and thus refuses to import. Works on the command line but needs more testing.

I have created the separate task T6298: Kleopatra: Possible problem when trying to import UTF-16 encoded files for the unrelated issue Kleopatra seems to have with UTF-16 encoded files.

This task is about GnuPG having issue with UTF-16 encoded config files. If this was fixed in the meantime then please close it.

Won't be backported to 2.2 once we got something in 2.4.