Skip to content

Commit b37d2b5

Browse files
authored
Improve support for alpine linux (#675)
* Add alpine linux docker image * Support alpine via ???-unknown-linux-musl bindings * Setup GitHub CI * Satiate clippy * Add clippy-fix make target
1 parent 82c61a7 commit b37d2b5

26 files changed

+165
-50
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM alpine:3.20
2+
3+
VOLUME ["/aws_lc_rs"]
4+
5+
WORKDIR /
6+
7+
RUN apk add \
8+
alpine-sdk \
9+
bash \
10+
boost-dev \
11+
build-base \
12+
busybox-suid \
13+
clang-dev \
14+
cargo \
15+
curl \
16+
cmake \
17+
openssl-dev
18+
19+
ARG UID
20+
RUN adduser -u $UID -S -s /bin/sh -G abuild satoshi
21+
USER satoshi
22+
WORKDIR /home/satoshi
23+
ENV CARGO_HTTP_MULTIPLEXING=false
24+
25+
# If needed, setup Rust environment for user
26+
#RUN cd "${HOME}" && \
27+
# curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > ./rustup.sh && \
28+
# chmod +x ./rustup.sh && \
29+
# ./rustup.sh -y && \
30+
# . "${HOME}/.cargo/env" && \
31+
# echo '. "${HOME}/.cargo/env"' >> ${HOME}/.profile && \
32+
# cargo install --locked bindgen-cli && \
33+
# rustup component add rustfmt clippy && \
34+
# rm ./rustup.sh
35+
36+
COPY aws_lc_rs_build.sh /
37+
COPY entry.sh /
38+
39+
ENTRYPOINT ["/entry.sh"]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
# SPDX-License-Identifier: Apache-2.0 OR ISC
4+
5+
set -ex -o pipefail
6+
7+
SRC_DIR="${SRC_DIR:-/aws_lc_rs}"
8+
9+
pushd "${SRC_DIR}"
10+
11+
cargo test -p aws-lc-rs
12+
cargo clean
13+
14+
popd # ${SRC_DIR}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
# SPDX-License-Identifier: Apache-2.0 OR ISC
4+
5+
set -ex
6+
7+
SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
8+
9+
# Ubuntu:
10+
# sudo apt-get install jq
11+
12+
# Amazon Linux:
13+
# sudo yum install jq
14+
15+
# Log Docker hub limit https://docs.docker.com/docker-hub/download-rate-limit/#how-can-i-check-my-current-rate
16+
TOKEN=$(curl "https://auth.docker.io/token?service=registry.docker.io&scope=repository:ratelimitpreview/test:pull" | jq -r .token)
17+
curl --head -H "Authorization: Bearer $TOKEN" https://registry-1.docker.io/v2/ratelimitpreview/test/manifests/latest
18+
19+
EXTRA_ARGS=()
20+
if [[ -n "${GOPROXY:+x}" ]]; then
21+
EXTRA_ARGS=("--build-arg" "GOPROXY=${GOPROXY}" "${EXTRA_ARGS[@]}")
22+
fi
23+
24+
pushd "${SCRIPT_DIR}"
25+
docker build -t alpine:3.20 . --build-arg UID=$(id -u) --load "${EXTRA_ARGS[@]}"
26+
popd
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
# SPDX-License-Identifier: Apache-2.0 OR ISC
4+
5+
set -ex -o pipefail
6+
7+
/aws_lc_rs_build.sh "${argv[@]}"

.github/workflows/cross.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,19 @@ jobs:
312312
- name: Build
313313
run: |
314314
docker run -v "${{ github.workspace }}:/aws_lc_rs" ohos:5.0.0
315+
316+
alpine-linux:
317+
runs-on: ubuntu-latest
318+
env:
319+
DOCKER_BUILDKIT: 1
320+
steps:
321+
- uses: actions/checkout@v4
322+
with:
323+
submodules: "recursive"
324+
- name: Build Docker Image
325+
working-directory: .github/docker_images/alpine-3.20
326+
run: |
327+
./build_image.sh
328+
- name: Build
329+
run: |
330+
docker run -v "${{ github.workspace }}:/aws_lc_rs" alpine:3.20

aws-lc-fips-sys/builder/cmake_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ impl crate::Builder for CmakeBuilder {
396396
} else {
397397
eprintln!("Missing dependency: cmake");
398398
missing_dependency = true;
399-
};
399+
}
400400

401401
if missing_dependency {
402402
return Err("Required build dependency is missing. Halting build.".to_owned());

aws-lc-rs/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@ msrv:
4545
clippy:
4646
cargo +nightly clippy --all-targets --features bindgen,fips,unstable -- -W clippy::all -W clippy::pedantic
4747

48+
clippy-fix:
49+
cargo +nightly clippy --all-targets --features bindgen,fips,unstable --fix --allow-dirty -- -W clippy::all -W clippy::pedantic
50+
4851
ci: format clippy msrv test coverage api-diff-pub
4952

5053
readme:
5154
cargo readme | tee README.md
5255

53-
.PHONY: asan asan-fips asan-release ci clippy coverage coverage-fips test msrv clippy
56+
.PHONY: asan asan-fips asan-release ci clippy coverage coverage-fips test msrv clippy clippy-fix

aws-lc-rs/src/agreement.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ fn ec_key_ecdh<'a>(
720720

721721
if 1 != unsafe { EVP_PKEY_derive_init(*pkey_ctx.as_mut()) } {
722722
return Err(Unspecified);
723-
};
723+
}
724724

725725
if 1 != unsafe { EVP_PKEY_derive_set_peer(*pkey_ctx.as_mut(), *pub_key.as_mut()) } {
726726
return Err(Unspecified);
@@ -751,7 +751,7 @@ fn x25519_diffie_hellman<'a>(
751751

752752
if 1 != unsafe { EVP_PKEY_derive_init(*pkey_ctx.as_mut()) } {
753753
return Err(());
754-
};
754+
}
755755

756756
let mut pub_key = try_parse_x25519_public_key_bytes(peer_pub_key)?;
757757

aws-lc-rs/src/cbb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl LcCBB<'static> {
2626

2727
if 1 != unsafe { CBB_finish(self.as_mut_ptr(), &mut out_data, &mut out_len) } {
2828
return Err(Unspecified);
29-
};
29+
}
3030

3131
let out_data = LcPtr::new(out_data)?;
3232
let slice = unsafe { std::slice::from_raw_parts(*out_data.as_const(), out_len) };

aws-lc-rs/src/digest/digest_ctx.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl DigestContext {
1818
unsafe {
1919
if 1 != EVP_DigestInit_ex(dc.as_mut_ptr(), *evp_md_type, null_mut()) {
2020
return Err(Unspecified);
21-
};
21+
}
2222
Ok(dc)
2323
}
2424
}
@@ -65,7 +65,7 @@ impl DigestContext {
6565
// https://github.com/aws/aws-lc/blob/98ccf4a316401112943bed604562102ad52efac6/include/openssl/digest.h#L280
6666
if 1 != EVP_MD_CTX_copy(dc.as_mut_ptr(), self.as_ptr()) {
6767
return Err("EVP_MD_CTX_copy failed");
68-
};
68+
}
6969
Ok(Self(dc.assume_init()))
7070
}
7171
}

aws-lc-rs/src/hkdf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ impl PrkMode {
252252
return Err(Unspecified);
253253
}
254254
}
255-
};
255+
}
256256

257257
Ok(())
258258
}

aws-lc-rs/src/hmac.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl Key {
306306
null_mut(),
307307
) {
308308
return Err(Unspecified);
309-
};
309+
}
310310
let result = Self {
311311
algorithm,
312312
ctx: LcHmacCtx(ctx.assume_init()),

aws-lc-rs/src/key_wrap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ impl KeyWrapPadded for KeyEncryptionKey<AesBlockCipher> {
404404
)
405405
}) {
406406
return Err(Unspecified);
407-
};
407+
}
408408

409409
Ok(&mut output[..out_len])
410410
}

aws-lc-rs/src/rsa/encryption.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl PrivateDecryptingKey {
4343
fn validate_key(key: &LcPtr<EVP_PKEY>) -> Result<(), Unspecified> {
4444
if !is_rsa_key(key) {
4545
return Err(Unspecified);
46-
};
46+
}
4747
match key.key_size_bits() {
4848
2048..=8192 => Ok(()),
4949
_ => Err(Unspecified),
@@ -152,7 +152,7 @@ impl PublicEncryptingKey {
152152
fn validate_key(key: &LcPtr<EVP_PKEY>) -> Result<(), Unspecified> {
153153
if !is_rsa_key(key) {
154154
return Err(Unspecified);
155-
};
155+
}
156156
match key.key_size_bits() {
157157
2048..=8192 => Ok(()),
158158
_ => Err(Unspecified),

aws-lc-rs/src/rsa/encryption/oaep.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl OaepPublicEncryptingKey {
136136
)
137137
}) {
138138
return Err(Unspecified);
139-
};
139+
}
140140

141141
Ok(&mut ciphertext[..out_len])
142142
}
@@ -240,7 +240,7 @@ impl OaepPrivateDecryptingKey {
240240
)
241241
}) {
242242
return Err(Unspecified);
243-
};
243+
}
244244

245245
Ok(&mut plaintext[..out_len])
246246
}
@@ -280,15 +280,15 @@ fn configure_oaep_crypto_operation(
280280
if 1 != unsafe { EVP_PKEY_CTX_set_rsa_padding(*evp_pkey_ctx.as_mut(), RSA_PKCS1_OAEP_PADDING) }
281281
{
282282
return Err(Unspecified);
283-
};
283+
}
284284

285285
if 1 != unsafe { EVP_PKEY_CTX_set_rsa_oaep_md(*evp_pkey_ctx.as_mut(), oaep_hash_fn()) } {
286286
return Err(Unspecified);
287-
};
287+
}
288288

289289
if 1 != unsafe { EVP_PKEY_CTX_set_rsa_mgf1_md(*evp_pkey_ctx.as_mut(), mgf1_hash_fn()) } {
290290
return Err(Unspecified);
291-
};
291+
}
292292

293293
let label = label.unwrap_or(&[0u8; 0]);
294294

@@ -315,7 +315,7 @@ fn configure_oaep_crypto_operation(
315315
EVP_PKEY_CTX_set0_rsa_oaep_label(*evp_pkey_ctx.as_mut(), *label_ptr, label.len())
316316
} {
317317
return Err(Unspecified);
318-
};
318+
}
319319

320320
// AWS-LC owns the allocation now, so we detach it to avoid freeing it here when label_ptr goes out of scope.
321321
label_ptr.detach();

aws-lc-rs/src/rsa/encryption/pkcs1.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl Pkcs1PublicEncryptingKey {
6262
)
6363
}) {
6464
return Err(Unspecified);
65-
};
65+
}
6666

6767
Ok(&mut ciphertext[..out_len])
6868
}
@@ -149,7 +149,7 @@ impl Pkcs1PrivateDecryptingKey {
149149
)
150150
}) {
151151
return Err(Unspecified);
152-
};
152+
}
153153

154154
Ok(&mut plaintext[..out_len])
155155
}
@@ -185,7 +185,7 @@ fn configure_pkcs1_crypto_operation(
185185
) -> Result<(), Unspecified> {
186186
if 1 != unsafe { EVP_PKEY_CTX_set_rsa_padding(*evp_pkey_ctx.as_mut(), RSA_PKCS1_PADDING) } {
187187
return Err(Unspecified);
188-
};
188+
}
189189

190190
Ok(())
191191
}

aws-lc-rs/src/rsa/key.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl KeyPair {
173173
fn validate_private_key(key: &LcPtr<EVP_PKEY>) -> Result<(), KeyRejected> {
174174
if !is_rsa_key(key) {
175175
return Err(KeyRejected::unspecified());
176-
};
176+
}
177177
match key.key_size_bits() {
178178
2048..=8192 => Ok(()),
179179
_ => Err(KeyRejected::unspecified()),
@@ -489,7 +489,7 @@ pub(super) fn generate_rsa_key(size: c_int, fips: bool) -> Result<LcPtr<EVP_PKEY
489489

490490
if 1 != unsafe { EVP_PKEY_assign_RSA(*evp_pkey.as_mut(), *rsa) } {
491491
return Err(Unspecified);
492-
};
492+
}
493493

494494
rsa.detach();
495495

aws-lc-rs/src/rsa/signature.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ pub(super) fn compute_rsa_signature<'a>(
235235
pub(crate) fn configure_rsa_pkcs1_pss_padding(pctx: *mut EVP_PKEY_CTX) -> Result<(), ()> {
236236
if 1 != unsafe { EVP_PKEY_CTX_set_rsa_padding(pctx, RSA_PKCS1_PSS_PADDING) } {
237237
return Err(());
238-
};
238+
}
239239
if 1 != unsafe { EVP_PKEY_CTX_set_rsa_pss_saltlen(pctx, RSA_PSS_SALTLEN_DIGEST) } {
240240
return Err(());
241-
};
241+
}
242242
Ok(())
243243
}
244244

aws-lc-rs/tests/aead_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ fn test_aead<Seal, Open>(
167167
return Ok(());
168168
}
169169
_ => (),
170-
};
170+
}
171171

172172
let mut s_in_out = plaintext.clone();
173173
let nonce = Nonce::try_assume_unique_for_key(&nonce_bytes).unwrap();
@@ -242,7 +242,7 @@ fn test_aead<Seal, Open>(
242242
Some(error) => {
243243
panic!("Unexpected error test case: {error}");
244244
}
245-
};
245+
}
246246
}
247247

248248
Ok(())

aws-lc-rs/tests/ecdsa_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn ecdsa_from_pkcs8_test() {
8484
"Input: {}",
8585
test::to_hex(&input)
8686
),
87-
};
87+
}
8888

8989
match (EcdsaKeyPair::from_pkcs8(this_asn1, &input), error) {
9090
(Ok(_), None) => (),
@@ -93,7 +93,7 @@ fn ecdsa_from_pkcs8_test() {
9393
}
9494
(Ok(_), Some(e)) => panic!("Succeeded, but expected error \"{e}\""),
9595
(Err(actual), Some(expected)) => assert_eq!(format!("{actual}"), expected),
96-
};
96+
}
9797

9898
assert!(
9999
EcdsaKeyPair::from_pkcs8(other_fixed, &input).is_err(),

aws-lc-rs/tests/ed25519_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ fn test_ed25519_from_pkcs8() {
135135
test::to_hex(input)
136136
);
137137
}
138-
};
138+
}
139139
}
140140

141141
// Just test that we can parse the input.

aws-lc-rs/tests/rsa_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn rsa_from_pkcs8_test() {
4747
"Input: {}",
4848
test::to_hex(input.as_slice())
4949
),
50-
};
50+
}
5151

5252
Ok(())
5353
},

0 commit comments

Comments
 (0)