1+ use core:: fmt:: Write as _;
12use std:: path:: Path ;
23
34use crate :: { Network , Os , mimalloc, os, write_dockerfile} ;
45
56pub fn bitcoin ( orchestration_path : & Path , network : Network ) {
6- const VERSION : & str = "30.2 " ;
7+ const VERSION : & str = "31.0 " ;
78 let file = format ! ( "bitcoin-{VERSION}-$(uname -m)-linux-gnu.tar.gz" ) ;
89 let url = format ! ( "https://bitcoincore.org/bin/bitcoin-core-{VERSION}" ) ;
910
10- // laanwj
11- const FINGERPRINT : & str = "71A3B16735405025D447E8F274810B012346C9A6" ;
12-
1311 #[ rustfmt:: skip]
14- let download_bitcoin = format ! ( r#"
12+ let mut download_bitcoin = format ! ( r#"
1513FROM alpine:latest AS download
1614
1715RUN apk --no-cache add git
@@ -23,49 +21,126 @@ RUN wget {url}/{file}
2321RUN tar -xf "{file}"
2422RUN mv $(find . -name bitcoind) .
2523
26- # Download the hashes, signature from laanwj
24+ # Download the hashes, signatures
2725RUN git clone --depth 1 https://github.com/bitcoin-core/guix.sigs
28- RUN cp guix.sigs/{VERSION}/laanwj/all.SHA256SUMS SHA256SUMS
29- RUN cp guix.sigs/{VERSION}/laanwj/all.SHA256SUMS.asc SHA256SUMS.asc
26+ "# ) ;
3027
28+ let mut run_bitcoin_first = String :: new ( ) ;
29+ let mut run_bitcoin_second = r#"
30+ RUN <<'EOF'
31+ set -eux
32+ COUNT=0
33+ "#
34+ . to_owned ( ) ;
35+
36+ let signers = [
37+ ( "laanwj" , "71A3B16735405025D447E8F274810B012346C9A6" ) ,
38+ ( "fanquake" , "E777299FC265DD04793070EB944D35F9AC3DB76A" ) ,
39+ ( "achow101" , "152812300785C96444D3334D17565732E08E5E41" ) ,
40+ ] ;
41+ for ( username, fingerprint) in signers {
42+ write ! (
43+ & mut download_bitcoin,
44+ r#"
3145# Verify `SHA256SUMS` with GnuPG
32- FROM alpine:latest AS gnupg
46+ FROM alpine:latest AS gnupg-{username}
3347RUN apk --no-cache add gnupg
3448RUN mkdir ~/.gnupg # Prevent the default config of `use-keyboxd`
35- COPY --from=download SHA256SUMS SHA256SUMS.asc /
36- RUN gpg --keyserver hkps://keyserver.ubuntu.com --keyserver-options no-self-sigs-only --receive-keys {FINGERPRINT}
37- RUN gpg --verify SHA256SUMS.asc SHA256SUMS
38- RUN touch /tmp/done
49+ COPY --from=download guix.sigs /guix.sigs
50+ RUN <<'EOF'
51+ set -eux
52+ mkdir -p /tmp
53+ if [ ! -d "/guix.sigs/{VERSION}/{username}" ]; then exit 0; fi
54+
55+ cp guix.sigs/{VERSION}/{username}/all.SHA256SUMS SHA256SUMS
56+ cp guix.sigs/{VERSION}/{username}/all.SHA256SUMS.asc SHA256SUMS.asc
57+ gpg --keyserver hkps://keyserver.ubuntu.com --keyserver-options no-self-sigs-only \
58+ --receive-keys {fingerprint}
59+ gpg --verify SHA256SUMS.asc SHA256SUMS
60+ touch /tmp/gnupg-{username}
61+ EOF
3962
4063# Verify `SHA256SUMS` with Sequoia PGP
41- FROM alpine:latest AS sequoia
64+ FROM alpine:latest AS sequoia-{username}
4265RUN apk --no-cache add sequoia-sq
43- COPY --from=download SHA256SUMS SHA256SUMS.asc /
44- RUN sq network keyserver search --server hkps://keyserver.ubuntu.com {FINGERPRINT}
45- RUN sq pki link add --cert {FINGERPRINT} --all
46- RUN sq verify --signature-file SHA256SUMS.asc SHA256SUMS
47- RUN touch /tmp/done
66+ COPY --from=download guix.sigs /guix.sigs
67+ RUN <<'EOF'
68+ set -eux
69+ mkdir -p /tmp
70+ if [ ! -d "/guix.sigs/{VERSION}/{username}" ]; then exit 0; fi
71+
72+ cp guix.sigs/{VERSION}/{username}/all.SHA256SUMS SHA256SUMS
73+ cp guix.sigs/{VERSION}/{username}/all.SHA256SUMS.asc SHA256SUMS.asc
74+ sq network keyserver search --server hkps://keyserver.ubuntu.com {fingerprint}
75+ sq pki link add --cert {fingerprint} --all
76+ sq verify --signature-file SHA256SUMS.asc SHA256SUMS
77+ touch /tmp/sequoia-{username}
78+ EOF
4879
4980# Verify the integrity of `bitcoin-*.tar.gz` with regards to the `SHA256SUMS` file
50- FROM alpine:latest AS sha256sum
51- COPY --from=download *.tar.gz SHA256SUMS /
52- # Parse to just the hash for the one file we downloaded
53- RUN echo $(grep "{file}" SHA256SUMS) > SHA256SUMS
54- # Ensure we successfully grabbed the line in question
55- RUN if [ $(wc -l SHA256SUMS) -ne 1 ]; then exit 1; fi
56- RUN cat SHA256SUMS | sha256sum -c
57- RUN touch /tmp/done
58- "# ) ;
81+ FROM alpine:latest AS sha256sum-{username}
82+ COPY --from=download *.tar.gz /
83+ COPY --from=download guix.sigs /guix.sigs
84+ RUN <<'EOF'
85+ set -eux
86+ mkdir -p /tmp
87+ if [ ! -d "/guix.sigs/{VERSION}/{username}" ]; then exit 0; fi
88+
89+ cp guix.sigs/{VERSION}/{username}/all.SHA256SUMS SHA256SUMS
90+ # Parse to just the hash for the one file we downloaded
91+ echo $(grep "{file}" SHA256SUMS) > SHA256SUMS
92+ # Ensure we successfully grabbed the line in question
93+ if [ $(wc -l SHA256SUMS) -ne 1 ]; then exit 1; fi
94+ cat SHA256SUMS | sha256sum -c
95+ touch /tmp/sha256sum-{username}
96+ EOF
97+ "#
98+ )
99+ . unwrap ( ) ;
100+
101+ write ! (
102+ & mut run_bitcoin_first,
103+ r#"
104+ # Require successful executions of the verification steps
105+ RUN mkdir -p /tmp
106+ # Use a wildcard to allow for if the file doesn't exist
107+ COPY --chown=bitcoin --from=gnupg-{username} /tmp/*gnupg-{username} /tmp/
108+ COPY --chown=bitcoin --from=sequoia-{username} /tmp/*sequoia-{username} /tmp/
109+ COPY --chown=bitcoin --from=sha256sum-{username} /tmp/*sha256sum-{username} /tmp/
110+ "#
111+ )
112+ . unwrap ( ) ;
113+
114+ write ! (
115+ & mut run_bitcoin_second,
116+ r#"
117+ if [ -f /tmp/gnupg-{username} ]; then
118+ if [ ! -f /tmp/sequoia-{username} ]; then exit 1; fi
119+ if [ ! -f /tmp/sha256sum-{username} ]; then exit 1; fi
120+ COUNT=$(( $COUNT + 1 ))
121+ fi
122+ "#
123+ )
124+ . unwrap ( ) ;
125+ }
126+
127+ write ! (
128+ & mut run_bitcoin_second,
129+ r#"
130+ if [ $COUNT -lt {} ]; then exit 1; fi
131+ rm -rf /tmp/*
132+ EOF
133+ "# ,
134+ signers. len( ) - 1
135+ )
136+ . unwrap ( ) ;
59137
60138 let setup = mimalloc ( Os :: Alpine , true ) + & download_bitcoin;
61139
62140 let run_bitcoin = format ! (
63141 r#"
64- # Require successful executions of the verification steps
65- COPY --from=sha256sum /tmp/done /tmp/done
66- COPY --from=gnupg /tmp/done /tmp/done
67- COPY --from=sequoia --chown=bitcoin /tmp/done /tmp/done
68- RUN rm /tmp/done
142+ {run_bitcoin_first}
143+ {run_bitcoin_second}
69144
70145COPY --from=download --chown=bitcoin bitcoind /usr/bin
71146
0 commit comments