3

I want to write a script that runs gpg --verify to check a signature.

The gpg command returns 1 for invalid signatures and 0 for valid ones. But it gives different output for keys that are in my trustdb and keys that aren't:

gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.

I want to run gpg in such a way that this warning is treated as an error, and without resorting to grepping the output. Is that possible?

By the way: It's fine if the solution requires me to use gpgme, but I haven't found anything related to the trustdb that looks remotely relevant in gpgme's documentation yet.

1
  • 1
    This question on ServerFault addresses the same issue. The answers aren't great but may point you in the right direction.
    – larsks
    Jun 24, 2013 at 15:27

1 Answer 1

1

This is not a particularly elegant solution, but it may be usable.

check_sig(){
    local LC_ALL=C output
    output=$(gpg --verify -- "$1" 2>&1) || return 1
    ! grep -Fqx 'gpg: WARNING: This key is not certified with a trusted signature!' <<<"$output"
}
1
  • It's worth to set LC_ALL=C environment variable so that command output is not translated to user's language.
    – skalee
    Jul 7, 2018 at 19:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .