Skip to contentSkip to conversation

support/download: print dl hash if not provided

PATCH New Gaël PORTAY 3 participants 5 messages Jul 20, 2017 – Oct 23, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 support/download: print dl hash if not provided

When a hash file exists but the hash is not provided, the script exits without any information about the hash of the downloaded file.

        ERROR: No hash found for rpi-userland-771a9aa7155442615bbe4cd6cf87b29b90cd228a.tar.gz

Now, the script hashes the downloaded file and suggests its sha256 to the user.

	$ make
	...
	>>> rpi-userland 771a9aa7155442615bbe4cd6cf87b29b90cd228a Downloading
	--2017-07-19 21:38:39--  https://github.com/raspberrypi/userland/archive/771a9aa7155442615bbe4cd6cf87b29b90cd228a/rpi-userland-771a9aa7155442615bbe4cd6cf87b29b90cd228a.tar.gz
	...
	ERROR: No hash found for rpi-userland-771a9aa7155442615bbe4cd6cf87b29b90cd228a.tar.gz
	ERROR: If the source is trusted, consider adding these lines to package/rpi-userland//rpi-userland.hash
	# Locally calculated from download
	sha256 771fb1be53414b00a9213f24bd9c88059cf76b72c5e21ac613b267d3e58d3715 rpi-userland-771a9aa7155442615bbe4cd6cf87b29b90cd228a.tar.gz
	...

It also fixes check_one_hash description. check_one_hash() takes three arguments:
- algo hash
- known hash
- file to hash

---
 support/download/check-hash | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)
support/download/check-hash +23 -6
index c1ff53c02..b18447f86 100755
@@ -41,13 +41,12 @@ if [ ! -f "${h_file}" ]; then
     exit 0
 fi
 
-# Check one hash for a file
-# $1: known hash
+# Compute hash for a file
+# $1: algo hash
 # $2: file (full path)
-check_one_hash() {
+compute_hash() {
     _h="${1}"
-    _known="${2}"
-    _file="${3}"
+    _file="${2}"
 
     # Note: md5 is supported, but undocumented on purpose.
     # Note: sha3 is not supported, since there is currently no implementation
@@ -66,8 +65,20 @@ check_one_hash() {
             ;;
     esac
 
+    ${_h}sum "${_file}" |cut -d ' ' -f 1
+}
+
+# Check one hash for a file
+# $1: algo hash
+# $2: known hash
+# $3: file (full path)
+check_one_hash() {
+    _h="${1}"
+    _known="${2}"
+    _file="${3}"
+
     # Do the hashes match?
-    _hash=$( ${_h}sum "${_file}" |cut -d ' ' -f 1 )
+    _hash=$( compute_hash "${_h}" "${_file}" )
     if [ "${_hash}" = "${_known}" ]; then
         printf "%s: OK (%s: %s)\n" "${base}" "${_h}" "${_hash}"
         return 0
@@ -105,6 +116,12 @@ if [ ${nb_checks} -eq 0 ]; then
         exit 0
         ;;
     esac
+
+    h="sha256"
+    hash=$( compute_hash "${h}" "${file}" )
     printf "ERROR: No hash found for %s\n" "${base}" >&2
+    printf "ERROR: If the source is trusted, consider adding these lines to ${h_file}\n" >&2
+    printf "# Locally calculated from download\n" >&2
+    printf "${h} ${hash} ${base}\n" >&2
     exit 3
 fi
Signature · 1 line
2.13.2
#1 lore raw

PATCH 1/1 support/download: print dl hash if not provided

Ga?l, All,

On 2017-07-19 23:18 -0400, Ga?l PORTAY spake thusly:

Quoted 19 lines

When a hash file exists but the hash is not provided, the script exits without any information about the hash of the downloaded file.

        ERROR: No hash found for rpi-userland-771a9aa7155442615bbe4cd6cf87b29b90cd228a.tar.gz

Now, the script hashes the downloaded file and suggests its sha256 to the user.

	$ make
	...
	>>> rpi-userland 771a9aa7155442615bbe4cd6cf87b29b90cd228a Downloading
	--2017-07-19 21:38:39--  https://github.com/raspberrypi/userland/archive/771a9aa7155442615bbe4cd6cf87b29b90cd228a/rpi-userland-771a9aa7155442615bbe4cd6cf87b29b90cd228a.tar.gz
	...
	ERROR: No hash found for rpi-userland-771a9aa7155442615bbe4cd6cf87b29b90cd228a.tar.gz
	ERROR: If the source is trusted, consider adding these lines to package/rpi-userland//rpi-userland.hash
	# Locally calculated from download
	sha256 771fb1be53414b00a9213f24bd9c88059cf76b72c5e21ac613b267d3e58d3715 rpi-userland-771a9aa7155442615bbe4cd6cf87b29b90cd228a.tar.gz
	...
Quoted 7 lines

It also fixes check_one_hash description. check_one_hash() takes three arguments:
- algo hash
- known hash
- file to hash

NAK from me.

The reason we do not want this is that we instead want the user to go fetch the hash(es) as provided by upstream, like in an announcement email, or in an on-the-side hash file.

Having the download infra print the locally computed hash defeats the very purpose of hashes: check that we get what upstream provides.

We only accept local calculations of hashes for the cases where upstream does not provide any (or too weak) hash.

As an aside, this patch does two things: fix the comment for check_one_hash() and print the hash. It should be split.

Regards,
Yann E. MORIN.

Quoted 64 lines
---
 support/download/check-hash | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)
support/download/check-hash +23 -6
index c1ff53c02..b18447f86 100755
@@ -41,13 +41,12 @@ if [ ! -f "${h_file}" ]; then
     exit 0
 fi
 
-# Check one hash for a file
-# $1: known hash
+# Compute hash for a file
+# $1: algo hash
 # $2: file (full path)
-check_one_hash() {
+compute_hash() {
     _h="${1}"
-    _known="${2}"
-    _file="${3}"
+    _file="${2}"
 
     # Note: md5 is supported, but undocumented on purpose.
     # Note: sha3 is not supported, since there is currently no implementation
@@ -66,8 +65,20 @@ check_one_hash() {
             ;;
     esac
 
+    ${_h}sum "${_file}" |cut -d ' ' -f 1
+}
+
+# Check one hash for a file
+# $1: algo hash
+# $2: known hash
+# $3: file (full path)
+check_one_hash() {
+    _h="${1}"
+    _known="${2}"
+    _file="${3}"
+
     # Do the hashes match?
-    _hash=$( ${_h}sum "${_file}" |cut -d ' ' -f 1 )
+    _hash=$( compute_hash "${_h}" "${_file}" )
     if [ "${_hash}" = "${_known}" ]; then
         printf "%s: OK (%s: %s)\n" "${base}" "${_h}" "${_hash}"
         return 0
@@ -105,6 +116,12 @@ if [ ${nb_checks} -eq 0 ]; then
         exit 0
         ;;
     esac
+
+    h="sha256"
+    hash=$( compute_hash "${h}" "${file}" )
     printf "ERROR: No hash found for %s\n" "${base}" >&2
+    printf "ERROR: If the source is trusted, consider adding these lines to ${h_file}\n" >&2
+    printf "# Locally calculated from download\n" >&2
+    printf "${h} ${hash} ${base}\n" >&2
     exit 3
 fi
Signature · 1 line
2.13.2
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#2 lore raw

PATCH 1/1 support/download: print dl hash if not provided

Yann,

Quoted 19 lines · Yann E. MORIN

Ga?l, All,

On 2017-07-19 23:18 -0400, Ga?l PORTAY spake thusly:

Quoted 9 lines

...

It also fixes check_one_hash description. check_one_hash() takes three arguments:
- algo hash
- known hash
- file to hash

NAK from me.

The reason we do not want this is that we instead want the user to go fetch the hash(es) as provided by upstream, like in an announcement email, or in an on-the-side hash file.

Quoted 6 lines

Having the download infra print the locally computed hash defeats the very purpose of hashes: check that we get what upstream provides.

We only accept local calculations of hashes for the cases where upstream does not provide any (or too weak) hash.

Okay.

Quoted 3 lines

As an aside, this patch does two things: fix the comment for check_one_hash() and print the hash. It should be split.

I will send a patch for this tiny nitpick.

Regards,
Ga?l

#3 lore raw

PATCH 1/1 support/download: print dl hash if not provided

Hi Ga?l,

Quoted 22 lines · Ga?l PORTAY

Yann,

Quoted 19 lines · Yann E. MORIN

Ga?l, All,

On 2017-07-19 23:18 -0400, Ga?l PORTAY spake thusly:

Quoted 9 lines

...

It also fixes check_one_hash description. check_one_hash() takes three arguments:
- algo hash
- known hash
- file to hash

NAK from me.

The reason we do not want this is that we instead want the user to go fetch the hash(es) as provided by upstream, like in an announcement email, or in an on-the-side hash file.

Quoted 8 lines
Quoted 6 lines

Having the download infra print the locally computed hash defeats the very purpose of hashes: check that we get what upstream provides.

We only accept local calculations of hashes for the cases where upstream does not provide any (or too weak) hash.

Okay.

Thomas and I discussed this at the BR developer meeting, and we disagree with
Yann that we should make life difficult for people bumping a package :-P. So we think this patch does have value. Would you be willing to respin it?

However, the text you propose is not strong enough. How about:

Please find a hash in the upstream announcement or website and add it to ${h_file}
If upstream doesn't provide a hash and the source is trusted, consider adding these lines:

Also, the most annoying thing actually is that when the hash is wrong, the
just-downloaded file will be removed again. It would be convenient to avoid removing it, similar to how it is done when the file exists already.

Regards,
Arnout

Quoted 14 lines
Quoted 4 lines

As an aside, this patch does two things: fix the comment for check_one_hash() and print the hash. It should be split.

I will send a patch for this tiny nitpick.

Regards,
Ga?l
_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot

Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
#4 lore raw

PATCH 1/1 support/download: print dl hash if not provided

Hi Arnout,

Quoted 32 lines · Arnout Vandecappelle

Hi Ga?l,

Quoted 29 lines · Ga?l PORTAY

Yann,

Quoted 25 lines · Yann E. MORIN

Ga?l, All,

On 2017-07-19 23:18 -0400, Ga?l PORTAY spake thusly:

Quoted 9 lines

...

It also fixes check_one_hash description. check_one_hash() takes three arguments:
- algo hash
- known hash
- file to hash

NAK from me.

The reason we do not want this is that we instead want the user to go fetch the hash(es) as provided by upstream, like in an announcement email, or in an on-the-side hash file.

Having the download infra print the locally computed hash defeats the very purpose of hashes: check that we get what upstream provides.

We only accept local calculations of hashes for the cases where upstream does not provide any (or too weak) hash.

Quoted 6 lines
Quoted 1 line

Okay.

Thomas and I discussed this at the BR developer meeting, and we disagree with
Yann that we should make life difficult for people bumping a package :-P. So we think this patch does have value. Would you be willing to respin it?

For sure. Let me do a rebase and I will respin it at the end of the day.

Quoted 7 lines

However, the text you propose is not strong enough. How about:

Please find a hash in the upstream announcement or website and add it to ${h_file}
If upstream doesn't provide a hash and the source is trusted, consider adding these lines:

I agree.

Quoted 4 lines

Also, the most annoying thing actually is that when the hash is wrong, the
just-downloaded file will be removed again. It would be convenient to avoid removing it, similar to how it is done when the file exists already.

I was thinking the same thing when write this patch. Let me see. I think it is just another case to add in the download script.

Regards,
Gael