Page MenuHome GnuPG

Console output failure with no-unicode font: GnuPG 2.2.28 is not working with »encrypt-to« in gpg.conf without specifying another recipient.
Closed, ResolvedPublic

Description

Since GnuPG 2.2.28 the command: »gpg -e File.txt« (not with »-r 0x1234567890ABCDEF«) doesn't work.

My long GPG-ID (example here) has been stored in the »gpg.conf« [encrypt-to 0x1234567890ABCDEF].

After input of the »gpg -e« command, the following error message appears:

Y:\>gpg -e File.zip
gpg: Fatal: WriteConsole failed: Ein an das System angeschlossenes Gerät funktioniert nicht.

GnuPG 2.2.27 works perfect with »gpg -e« in combination with "encrypt-to 0x1234567890ABCDEF" in gpg.conf.

In GnuPG 2.2.28 (and V2.3.1) I have to state myself as the recipient. That was not the case in the previous version.
I am now using the previous version (GnuPG 2.2.27) again.

Details

Version
GnuPG 2.2.28

Event Timeline

werner added a subscriber: werner.

Are you using Powershell or another non-standard shell? Which windows version are you using? Do you use default-key in gpg.conf? Do you have a smartcard inserted?

Hello Mr. Koch,

I using the normal CMD ([DE] Eingabeaufforderung) in Windows 8.1 x64 (German) and do not use a Smartcard.
I have redirected my GPG-home-directory to "C:\Tools\GPG_HOME\gnupg" about the Windows registry.

Now, I have installed my GPG-Test-Key. Here are the results in the command prompt - step-by-step:

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. Alle Rechte vorbehalten.

Y:\>gpg --version
gpg (GnuPG) 2.2.28
libgcrypt 1.8.8
Copyright (C) 2021 g10 Code GmbH
License GNU GPL-3.0-or-later https://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Home: C:/Tools/GPG_HOME/gnupg
Unterstützte Verfahren:
Öff. Schlüssel: RSA, ELG, DSA, ECDH, ECDSA, EDDSA
Verschlü.: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH, CAMELLIA128, CAMELLIA192, CAMELLIA256
Hash: SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Komprimierung: nicht komprimiert, ZIP, ZLIB, BZIP2

Y:\>type C:\Tools\GPG_HOME\gnupg\gpg.conf
default-key 0xFBB66A599D7B7A40
encrypt-to 0xFBB66A599D7B7A40

Y:\>gpg --keyid-format 0xlong -K
C:/Tools/GPG_HOME/gnupg/pubring.kbx

sec rsa2048/0xFBB66A599D7B7A40 2018-01-15 [SC]
57C1C60A5FA849E4285CD6F4FBB66A599D7B7A40
uid [unbekannt] Testx Testy <test@test.de>
ssb rsa2048/0xF215744F9398D662 2018-01-15 [E]

Y:\>gpg -e FILE.zip
gpg: Fatal: WriteConsole failed: Ein an das System angeschlossenes Gerät funktioniert nicht.

P.S. I had to adjust the formatting because headings were inserted in the result.

Best regard, Reiner.

Please run

chcp

and

gpgconf --show-versions

and paste the output. Also try your original command again after having run

chcp 65501

Hello Mr. Koch,

Here, the result of the command prompt.
Signing works, but not encryption in combination with »gpg.conf«.

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. Alle Rechte vorbehalten.

Y:\>chcp
Aktive Codepage: 850.

Y:\>gpgconf --show-versions

MingW32
Windows 6.3 build 9600

version:1.8.8:10808:1.42:12a00:
cc:80300:gcc:8.3-win32 20190406:
ciphers:arcfour:blowfish:cast5:des:aes:twofish:serpent:rfc2268:seed:camellia:idea:salsa20:gost28147:chacha20:
pubkeys:dsa:elgamal:rsa:ecc:
digests:crc:gostr3411-94::md4:md5:rmd160:sha1:sha256:sha512:sha3:tiger:whirlpool:stribog:blake2:
rnd-mod:w32:
cpu-arch:x86:
mpi-asm:i386/mpih-add1.S:i386/mpih-sub1.S:i386/mpih-mul1.S:i386/mpih-mul2.S:i386/mpih-mul3.S:i386/mpih-lshift.S:i386/mpih-rshift.S:
hwflist:intel-cpu:intel-ssse3:intel-sse4.1:intel-pclmul:intel-rdrand:intel-rdtsc:
fips-mode:n:n:
rng-type:standard:1:2010000:1:

Y:\>chcp 65501

Y:\>chcp
Aktive Codepage: 65001.

Y:\>type C:\Tools\GPG_HOME\gnupg\gpg.conf
default-key 0xFBB66A599D7B7A40
encrypt-to 0xFBB66A599D7B7A40
Y:\>
Y:\>gpg -K
gpg: DBG: Using CREATE_BREAKAWAY_FROM_JOB flag

C:/Tools/GPG_HOME/gnupg/pubring.kbx

sec rsa2048 2018-01-15 [SC]

57C1C60A5FA849E4285CD6F4FBB66A599D7B7A40

uid [ unbekannt ] Testx Testy <test@test.de>
ssb rsa2048 2018-01-15 [E]

Y:\>gpg -e Testfile.rar
gpg: Fatal: WriteConsole failed: Ein an das System angeschlossenes Gerät funktioniert nicht.

Y:\>REM Test only with sign

Y:\>gpg -s Testfile.rar
gpg: "0xFBB66A599D7B7A40" wird als voreingestellter geheimer Signaturschlüssel benutzt

Y:\>REM Signing works flawlessly - just not encryption!

Y:\>

Y:\>gpg -es Testfile.rar
gpg: "0xFBB66A599D7B7A40" wird als voreingestellter geheimer Signaturschlüssel benutzt
gpg: Fatal: WriteConsole failed: Ein an das System angeschlossenes Gerät funktioniert nicht.

Best regard, Reiner.

When console font is not a Unicode font, it seems that the WriteConsoleW function may return ERROR_GEN_FAILURE.

It will be fixed if you can switch console font to Lucida Console.

It would be good for GnuPG to fallback to WriteConsoleA.

I found this one, as a reference: https://github.com/winscp/winscp/commit/d654a7935971d9a8f1efc136f25304cdeec0532e

And another one: https://www.mail-archive.com/cygwin@cygwin.com/msg153851.html

gniibe renamed this task from GnuPG 2.2.28 is not working with »encrypt-to« in gpg.conf without specifying another recipient. to Console output failure with no-unicode font: GnuPG 2.2.28 is not working with »encrypt-to« in gpg.conf without specifying another recipient..Jun 22 2021, 6:08 AM

I think that a patch like following is needed:

diff --git a/common/ttyio.c b/common/ttyio.c
index c385700de..55468bdf0 100644
--- a/common/ttyio.c
+++ b/common/ttyio.c
@@ -236,7 +236,21 @@ w32_write_console (const char *string)
   n = wcslen (wstring);
 
   if (!WriteConsoleW (con.out, wstring, n, &nwritten, NULL))
-    log_fatal ("WriteConsole failed: %s", w32_strerror (-1));
+    {
+      int ec = GetLastError ();
+
+      if (ec == ERROR_GEN_FAILURE)
+        {
+          n = strlen (string);
+
+          if (WriteConsoleA (con.out, string, n, &nwritten, NULL))
+            ec = 0;
+          else
+            ec = GetLastError ();
+        }
+      if (ec)
+        log_fatal ("WriteConsole failed: %s", w32_strerror (ec));
+    }
   if (n != nwritten)
     log_fatal ("WriteConsole failed: %lu != %lu\n",
                (unsigned long)n, (unsigned long)nwritten);

For testing ion Windows 10 you need to switch to "Legacy Console" and reboot.

werner changed the task status from Open to Testing.Jun 22 2021, 11:32 AM

I did some test on Windows 10 using gnupg 2.2 with this patch and things work.

Same error message in Windows 8.1 x64 with the commands:
gpg --local-user 0x12345678 --sign-key 0xABCDEF12 or: gpg --default-key 0x12345678 --sign-key 0xABCDEF12.

--> gpg: Fatal: WriteConsole failed: Ein an das System angeschlossenes Gerät funktioniert nicht.

It is a matter of the used font. 2.2.29 will fix this problem.

werner triaged this task as Normal priority.Jul 4 2021, 4:19 PM
werner claimed this task.