Checking File Checksum In Alpine
Asked Answered
I

2

11

I got this curious problem with Alpine. I want to check the checksum of a file inside a bash console. It works under CentOS but not under Alpine. Where is the error?

Under CentOS

$ sha1sum /bin/tini
fa23d1e20732501c3bb8eeeca423c89ac80ed452  /bin/tini
$ echo "fa23d1e20732501c3bb8eeeca423c89ac80ed452 /bin/tini" | sha1sum -c -
/bin/tini: OK

Under Alpine

$ sha1sum /bin/tini
fa23d1e20732501c3bb8eeeca423c89ac80ed452  /bin/tini
$ echo "fa23d1e20732501c3bb8eeeca423c89ac80ed452 /bin/tini" | sha1sum -c -
sha1sum: WARNING: 1 of 1 computed checksums did NOT match
Infeld answered 27/5, 2016 at 16:47 Comment(4)
Just for testing, would echo 'fa23d1e20732501c3bb8eeeca423c89ac80ed452 /bin/tini' | sha1sum -c - (simple quotes) work better?Emmery
Same result. Thanks for helping, my post is regarding the following Docker container and i use the following Docker command: 'docker run -it --rm blacklabelops/jenkins:alpine bash'Infeld
Would a shell command work better? docker run -it --rm blacklabelops/jenkins:alpine sh -c 'echo "fa23d1e20732501c3bb8eeeca423c89ac80ed452 /bin/tini" | sha1sum -c -'Emmery
Same result: sha1sum: WARNING: 1 of 1 computed checksums did NOT matchInfeld
A
24

Could you try adding 1 space (total 2) between the checksum and the path:

$ echo "fa23d1e20732501c3bb8eeeca423c89ac80ed452  /bin/tini" | sha1sum -c -

I've tried with /bin/busybox:

# sha1sum /bin/busybox
71bdaf6e52759f7f277c89b694c494f472ca2dfb  /bin/busybox
# echo '71bdaf6e52759f7f277c89b694c494f472ca2dfb /bin/busybox' | sha1sum -c -
sha1sum: WARNING: 1 of 1 computed checksums did NOT match
# echo '71bdaf6e52759f7f277c89b694c494f472ca2dfb  /bin/busybox' | sha1sum -c -
/bin/busybox: OK

The error is because sha1sum expects its own output as input when called with -c and its output uses 2 spaces.

Adviser answered 28/5, 2016 at 12:43 Comment(1)
This TWO spaces "rule" holds true for sha512sum as well. Nowhere in any of the examples I found was that small but "critical" fact made clear. IMHO the syntax of these command are rotten. -c should accept an argument which is the checksum to check. e.g sha1sum -c knownchecksum filetocheckGae
S
0

I had this issue while installing kubectl on Alpine Linux v3.13:

echo "$(<kubectl.sha256) kubectl" | sha256sum -c
sha256sum: WARNING: 1 of 1 computed checksums did NOT match

My two-part fix:

  1. the default shell (ash) responds to echo "$(<file.txt)" with an empty new line whereas bash responds with the contents of the file (expected behavior).
  2. Alpine's version of sha256sum wants two spaces between the hash and the file name (Ubuntu accepts one space).
bash
echo "$(<kubectl.sha256)  kubectl" | sha256sum -c
kubectl: OK
Spiky answered 3/12, 2021 at 18:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.