gpg.sh raw

   1  #!/bin/sh
   2  # Copyright (c) 2014-2019 The Limenka developers
   3  # Distributed under the MIT software license, see the accompanying
   4  # file COPYING or http://www.opensource.org/licenses/mit-license.php.
   5  
   6  export LC_ALL=C
   7  INPUT=$(cat /dev/stdin)
   8  if [ "$LIMENKA_VERIFY_COMMITS_ALLOW_SHA1" = 1 ]; then
   9      printf '%s\n' "$INPUT" | gpg --trust-model always "$@" 2>/dev/null
  10      exit $?
  11  else
  12  	# Note how we've disabled SHA1 with the --weak-digest option, disabling
  13  	# signatures - including selfsigs - that use SHA1. While you might think that
  14  	# collision attacks shouldn't be an issue as they'd be an attack on yourself,
  15  	# in fact because what's being signed is a commit object that's
  16  	# semi-deterministically generated by untrusted input (the pull-req) in theory
  17  	# an attacker could construct a pull-req that results in a commit object that
  18  	# they've created a collision for. Not the most likely attack, but preventing
  19  	# it is pretty easy so we do so as a "belt-and-suspenders" measure.
  20  	for LINE in $(gpg --version); do
  21  		case "$LINE" in
  22  			"gpg (GnuPG) 1.4.1"*|"gpg (GnuPG) 2.0."*)
  23  				echo "Please upgrade to at least gpg 2.1.10 to check for weak signatures" > /dev/stderr
  24                                  printf '%s\n' "$INPUT" | gpg --trust-model always "$@" 2>/dev/null
  25                                  exit $?
  26  				;;
  27  			# We assume if you're running 2.1+, you're probably running 2.1.10+
  28  			# gpg will fail otherwise
  29  			# We assume if you're running 1.X, it is either 1.4.1X or 1.4.20+
  30  			# gpg will fail otherwise
  31  		esac
  32  	done
  33          printf '%s\n' "$INPUT" | gpg --trust-model always --weak-digest sha1 "$@" 2>/dev/null
  34          exit $?
  35  fi
  36