Score:1

GPG Decrypt: Bad Session key / Variable Unset / Exclamation Mark

us flag

I am trying to decrypt a gpg file, but am continually getting the following error:

gpg: decryption failed: Bad session key

I realised afterwards that the gpg passphrase (which is set by a script) has an exclamation in it

passphrase="my!pass"

When setting via TTY, bash complains

-bash: !pass: event not found

When I echo the variable, it's unset.

user@host:~$ echo $passphrase

user@host:~$

So, the variable is unknown, and I assume that's why I can't decrypt my file.

I've tried the following as a password:

  • my!pass
  • my
  • !pass
  • 'my!pass'
  • -bash: !pass: event not found
  • bash: !pass: event not found
  • -bash:
  • bash:
  • event not found

Fairly sure I've just learned a very painful lesson here, but it's worth a shot.

Can anyone help with:

  1. What does bash do with an unset variable if you try to use it?
  2. How does a script deal with an unset variable?
  3. Is there anything else I can try in place of the password?
  4. Is there an ASCII / UTF whitespace code that I can try in place of the password?
FedKad avatar
cn flag
Did you try the empty (`''`) string?
edooze avatar
us flag
This is why I'm not 100% sure the variable is the issue, I pressed enter when prompted, and it says 'No secret key'. Fair enough. Unfortunately, I can't find any way to change what it thinks is the key, and it just keeps saying 'no secret key' and not prompting for another one.
sancho.s ReinstateMonicaCellio avatar
Did the suggestions work for you? Please post feedback.
Score:1
pl flag

There are a few comments worth noting.

  1. "... the gpg passphrase (which is set by a script)". I take it you didn't write the script. Please post the script. Are there any instructions to use it?
  2. passphrase="my!pass". This doesn't mean "use ! as part of the string". !pass means "read history, and get the last command starting with pass". If there are no commmands in history starting with pass, the error bash: !pass: event not found is raised, as you are getting at the command line. That's why I guess you didn't write the script. It is conceived for a case when there is some command in history starting with pass.
  3. "When setting via TTY (and I guess you executed passphrase="my!pass"), bash complains... When I echo the variable, it's unset". As mentioned above, an error is raised. But there are two more things happening: 1) The command is not executed. I.e., you don't even get "my" (you might have expected to get "my" = "my" + empty string) as the value of passphrase, it keeps unset. 2) The command is not even added to the history.

As for some of your questions:

  1. What does bash do with an unset variable if you try to use it? bash typically replaces it by an empty string. But generally speaking, it depends on how it is used, it may raise errors, you may have a sentence that replaces its value by a default value in case it is not set, etc. There is no single answer for this.
  2. How does a script deal with an unset variable? Same as above.

I don't know about the rest of your problem, but this perhaps helps you understanding the issue and solving it.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.