diff --git a/build-aux/authenticode-sign.sh b/build-aux/authenticode-sign.sh index 0740fd62..f1a77793 100755 --- a/build-aux/authenticode-sign.sh +++ b/build-aux/authenticode-sign.sh @@ -1,249 +1,253 @@ #!/bin/sh # authenticode-sign.sh - Wrapper for osslsigncode # Copyright (C) 2024 g10 Code GmbH # # This file is free software; as a special exception the author gives # unlimited permission to copy and/or distribute it, with or without # modifications, as long as this notice is preserved. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. VERSION=2024-03-25 PGM=authenticode-sign.sh set -e usage() { cat <&2 "$PGM: Note: Please consider to use gpg-authcode-sign.sh in the future + autogenrc="$HOME/.gnupg-autogen.rc" dryrun= stamp= buildtype= # Set defaults accrding to our build system. if [ -n "$abs_top_srcdir" -a -f "$abs_top_srcdir/packages/BUILDTYPE" ]; then buildtype=$(cat "$abs_top_srcdir/packages/BUILDTYPE") elif [ -f "../packages/BUILDTYPE" ]; then buildtype=$(cat "../packages/BUILDTYPE") elif [ -f "packages/BUILDTYPE" ]; then buildtype=$(cat "packages/BUILDTYPE") fi case "$buildtype" in vsd) desc="GnuPG VS-Desktop" url="https://gnupg.com" ;; gpd) desc="GnuPG Desktop" url="https://gnupg.com" ;; default|gpg4win) desc="Gpg4win" url="https://gpg4win.org" ;; *) desc= url= ;; esac while [ $# -gt 0 ]; do case "$1" in --*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; *) optarg="" ;; esac case $1 in --desc=*) desc="$optarg" ;; --url=*) url="$optarg" ;; --dry-run|-n) dryrun=yes ;; --stamp) stamp=yes ;; --help|-h) usage 0 ;; --version) echo $VERSION exit 0 ;; --template) print_autogenrc_template exit 0 ;; --*) usage 1 1>&2 ;; *) break ;; esac shift done if [ $# -ne 2 ]; then usage 1 1>&2 fi inname="$1" outname="$2" shift if [ ! -f $autogenrc ]; then echo >&2 "$PGM: error: '$autogenrc' missing" echo >&2 "$PGM: hint: use option --template" exit 1 fi for v in AUTHENTICODE_SIGNHOST AUTHENTICODE_TOOL AUTHENTICODE_TSURL \ AUTHENTICODE_KEY AUTHENTICODE_CERTS VERSION_SIGNKEY \ OSSLSIGNCODE OSSLPKCS11ENGINE SCUTEMODULE ; do eval $v=$(grep '^[[:blank:]]*'$v'[[:blank:]]*=' "$autogenrc"|cut -d= -f2\ |sed -e 's,\\,\\\\,g'| sed -e 's,^",'\', -e 's,"$,'\',) done if [ "$stamp" = yes ]; then if [ "$outname.asig-done" -nt "$outname" ]; then echo >&2 "$PGM: file is '$outname' is already signed" exit 0 fi fi if [ -n "$AUTHENTICODE_SIGNHOST" ]; then echo >&2 "$PGM: Signing via host $AUTHENTICODE_SIGNHOST" scp "$inname" "$AUTHENTICODE_SIGNHOST:a.exe" # Invoke command on Windows via ssh ssh "$AUTHENTICODE_SIGNHOST" \""$AUTHENTICODE_TOOL"\" sign \ /v /sm \ /a /n '"g10 Code GmbH"' \ /tr \""$AUTHENTICODE_TSURL"\" /td sha256 \ /d \""$desc"\" \ /fd sha256 /du https://gnupg.com a.exe scp "$AUTHENTICODE_SIGNHOST:a.exe" "$outname" elif [ "$AUTHENTICODE_KEY" = card ]; then echo >&2 "$PGM: Signing using a card: '$inname'" "$OSSLSIGNCODE" sign \ -pkcs11engine "$OSSLPKCS11ENGINE" \ -pkcs11module "$SCUTEMODULE" \ -certs "$AUTHENTICODE_CERTS" \ -h sha256 -n "$desc" -i "$url" \ -ts "$AUTHENTICODE_TSURL" \ -in "$inname" -out "$outname.tmp" cp "$outname.tmp" "$outname" rm "$outname.tmp" elif [ "$AUTHENTICODE_KEY" = none ]; then echo >&2 "$PGM: Signing disabled; would sign: '$inname'" [ "$inname" != "$outname" ] && cp "$inname" "$outname" else echo >&2 "$PGM: Signing using key $AUTHENTICODE_KEY" osslsigncode sign -certs "$AUTHENTICODE_CERTS" \ -pkcs12 "$AUTHENTICODE_KEY" -askpass \ -ts "$AUTHENTICODE_TSURL" \ -h sha256 -n "$desc" -i "$url" \ -in "$inname" -out "$outname.tmp" cp "$outname.tmp" "$outname" rm "$outname.tmp" fi [ "$stamp" = yes ] && touch "$outname.asig-done" echo >&2 "$PGM: signed file is '$outname'"