2 # Get the online version of the GnuPG software version database
3 # Copyright (C) 2014 Werner Koch
5 # This file is free software; as a special exception the author gives
6 # unlimited permission to copy and/or distribute it, with or without
7 # modifications, as long as this notice is preserved.
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
11 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 # The URL of the file to retrieve.
14 urlbase="https://www.gnupg.org/"
19 srcdir=$(dirname "$0")
20 distsigkey="$srcdir/../g10/distsigkey.gpg"
22 # Convert a 3 part version number it a numeric value.
24 awk 'NR==1 {split($NF,A,".");X=1000000*A[1]+1000*A[2]+A[3];print X;exit 0}'
27 # Prints usage information.
31 Usage: $(basename $0) [OPTIONS]
32 Get the online version of the GnuPG software version database
34 --skip-download Assume download has already been done.
35 --find-sha1sum Print the name of the sha1sum utility
36 --help Print this help.
46 while test $# -gt 0; do
50 optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'`
74 # Mac OSX has only a shasum and not sha1sum
75 if [ ${find_sha1sum} = yes ]; then
76 for i in sha1sum shasum ; do
77 tmp=$($i </dev/null 2>/dev/null | cut -d ' ' -f1)
78 if [ x"$tmp" = x"da39a3ee5e6b4b0d3255bfef95601890afd80709" ]; then
87 # Get GnuPG version from VERSION file. For a GIT checkout this means
88 # that ./autogen.sh must have been run first. For a regular tarball
89 # VERSION is always available.
90 if [ ! -f "$srcdir/../VERSION" ]; then
91 echo "VERSION file missing - run autogen.sh first." >&2
94 version=$(cat "$srcdir/../VERSION")
95 version_num=$(echo "$version" | cvtver)
98 # Download the list and verify.
100 if [ $skip_download = yes ]; then
101 if [ ! -f swdb.lst ]; then
102 echo "swdb.lst is missing." >&2
105 if [ ! -f swdb.lst.sig ]; then
106 echo "swdb.lst.sig is missing." >&2
110 if ! $WGET -q -O swdb.lst "$urlbase/swdb.lst" ; then
111 echo "download of swdb.lst failed." >&2
114 if ! $WGET -q -O swdb.lst.sig "$urlbase/swdb.lst.sig" ; then
115 echo "download of swdb.lst.sig failed." >&2
119 if ! $GPGV --keyring "$distsigkey" swdb.lst.sig swdb.lst; then
120 echo "list of software versions is not valid!" >&2
125 # Check that the online version of GnuPG is not less than this version
126 # to help detect rollback attacks.
128 gnupg_ver=$(awk '$1=="gnupg21_ver" {print $2;exit}' swdb.lst)
129 if [ -z "$gnupg_ver" ]; then
130 echo "GnuPG 2.1 version missing in swdb.lst!" >&2
133 gnupg_ver_num=$(echo "$gnupg_ver" | cvtver)
134 if [ $(( $gnupg_ver_num >= $version_num )) = 0 ]; then
135 echo "GnuPG version in swdb.lst is less than this version!" >&2
136 echo " This version: $version" >&2
137 echo " SWDB version: $gnupg_ver" >&2