Created attachment 2775 [details] public key with ANSI escape sequences I noticed that ssh-keygen prints most non-printable characters in the comment as-is when showing the fingerprint of a key. This can lead to confusing output on the terminal when the comment contains ANSI escape characters which are interpreted by the terminal. The attached public key file serves as an example, which, when fingerprinted on my Linux terminal, looks like this: $ ssh-keygen -E sha256 -lf test.pub 1024 MD5:de:ad:be:ef:00:7h:15:15:af:0r:6e:d0:ha:5h:00:00 nobody@example.org (RSA) ... in nice rainbow colors (see attached screenshot). Also note that a SHA256 hash was requested whereas the output is an MD5 hash (which also contains invalid characters, so it cannot really be an MD5 hash...), but you get the point that, in general, this technique can be used to suppress the real fingerprint of a key and let the user see a different one. For this reason, I suggest applying the attached patch (based on commit 271df81 from the OpenSSH Portable GitHub repository), which emplys strvis() to escape possibly dangerous characters in the comment prior to printing it to the terminal. This should serve as a sufficient workaround for the obfuscating escape behaviour of the underlying terminal emulator.
Created attachment 2776 [details] screenshot showing the output from ssh-keygen on the public key
Created attachment 2777 [details] proposed patch
This is not going to be popular with users who have UTF-8 or other non-ASCII characters in their comments. We need something like that proposed for bug #2058
Created attachment 2940 [details] sanitise escape sequences but not valid UTF-8 when the locale supports it This patch uses Ingo's recent mprintf API to safely render strings while preserving UTF-8 characters when the locale supports them.
Fix applied. This will be in OpenSSH 7.5 commit a287c5ad1e0bf9811c7b9221979b969255076019 Author: djm@openbsd.org <djm@openbsd.org> Date: Fri Feb 10 03:36:40 2017 +0000 upstream commit Sanitise escape sequences in key comments sent to printf but preserve valid UTF-8 when the locale supports it; bz#2520 ok dtucker@ Upstream-ID: e8eed28712ba7b22d49be534237eed019875bd1e
Close all resolved bugs after release of OpenSSH 7.7.