Skip to content

Conversation

@Narrat
Copy link
Collaborator

@Narrat Narrat commented Oct 3, 2025

As a draft because of the same reasons mentioned in #585


Background of this PR is the issue that tomb has issues with passwords that try to use characters in a combination so they create control sequences for the shell. For example newline \n, form feed \f and tabulator \t.
This is due how the password is provided for the gpg call. gpg is used with --passphrase-fd 0 which reads the password from STDIN until it encounters a newline. Unfortunately this means the shell interprets those character sequences in the password itself. Especially fatal in case of \n as this will reduce the password to this point. Example: you want to set password test\ntest. gpg, while reading STDIN, will stop at \n and the resulting password will be only test.
Not sure yet what happens with the rest, but it does seem to be discarded in general and not added to or used as TOMBSECRET.

Two ways to avoid interpreting control sequences:

  • change --passphrase-fd to a dedicated descriptor above 2 (like --passphrase-fd 3 and input password like 3<<<"$password"
  • use --passphrase-file and use an anonymous pipe

In general the first option is similar to the current solution, just changing it to a different FD, which allows to avoid interpreting control sequences. But is untested if the redirect isn't visible while tracing.
This solutions changes the fd for the password input from STDIN to a new one file-descriptor (3 in this example).

Narrat added 2 commits October 3, 2025 17:20
Remove last remnant of 9e820f3
The latest release of gpg1 is 1.4.23 from 2018. It is safe to assume, that there
is no modern distribution, which ships this specific gpg1 version.
As the workaround itself only applies to 1.4.11, any version before or after seem
to be safe.
This removal doesn't remove support for gpg1 in general as it isn't end-of-life.
All the options in use are available with gpg1 and only a broken --status-fd
seemed to be of concern.

Closes dyne#581
Formerly a combined password+key divided by a newline was piped into the
gpg operation which sets --passphrase-fd 0 to get the password from
STDIN. This gets stripped from the pipe and only the encrypted data
remains.
This has some consequences for entered passwords in general.
Mainly \ and % related.
\ can be used for control sequences like \n, \t and \f.
If those are used in passwords various stuff can happen.
\n not at the end: Only the password up to the backslash is used and
valid.
\n at the end: <ToDo>
\t not at the end: <ToDo>
\t at the end: <ToDo>
\f
\f

<Description for % stuff>

In that regard change how gpg gets the password.
Two ways for improvements:
1) use a specific file descriptor --passphrase-fd 3 and
redirect the password via "3<<<$password".

2) switch to --passphrase-file and use an anonymous pipe <(print -R -n -
   "$password")
   In general the use of --passphrase-file is discouraged, but that
   should only apply if a real file is used. With the pipe only the
   respective file descriptor should be seen and not its content. Which
   only gpg is allowed to have access. And if gpg is completed the pipe
   and its content is gone.

This solutions uses the first way as it is similar to the current
solution.

What changes:
\n not at the end: Assuan still outputs a formated password, but the
complete password is used.
\n at the end: <ToDo>
\t not at the end: password is functional
\t at the end: <ToDo>
\f
\f

<Does it help with % ?>
@jaromil
Copy link
Member

jaromil commented Dec 15, 2025

I'm in favor of this, yet we'll need to state the introduction of a breaking change for anyone who uses passwords with control characters which were previously misinterpreted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants