Skip to content

Commit f0d822d

Browse files
ismoilovdevmlclaude
andcommitted
🔧 Fix SSL certificate loading and aarch64 build
**SSL Certificate Improvements:** - Add support for PKCS8 private keys (ECDSA, Ed25519, etc.) - Fallback from RSA to PKCS8 format automatically - Prevent panic on empty key files with proper error messages - Fixes Let's Encrypt certificate loading issues **ARM64 Build Fix:** - Replace gcc-aarch64-linux-gnu with cross-rs tool for MUSL builds - Fixes `__memcpy_chk` undefined reference errors - Proper static linking for aarch64-unknown-linux-musl target **Changes:** - [src/tls.rs](src/tls.rs): Enhanced private key loading with multi-format support - [.github/workflows/release.yml](.github/workflows/release.yml): Use cross-rs for ARM64 cross-compilation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 3eb8402 commit f0d822d

File tree

2 files changed

+43
-25
lines changed

2 files changed

+43
-25
lines changed

.github/workflows/release.yml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,16 @@ jobs:
7777
with:
7878
targets: ${{ matrix.target }}
7979

80-
- name: Install MUSL tools
81-
if: matrix.os == 'ubuntu-latest'
80+
- name: Install MUSL tools (x86_64)
81+
if: matrix.target == 'x86_64-unknown-linux-musl'
8282
run: |
8383
sudo apt-get update
8484
sudo apt-get install -y musl-tools
8585
86-
- name: Install cross-compilation tools (ARM64 MUSL)
86+
- name: Install cross tool for ARM64 MUSL
8787
if: matrix.cross && matrix.os == 'ubuntu-latest'
8888
run: |
89-
sudo apt-get install -y gcc-aarch64-linux-gnu
90-
rustup target add aarch64-unknown-linux-musl
91-
92-
- name: Configure cross-compilation (ARM64 MUSL)
93-
if: matrix.cross && matrix.os == 'ubuntu-latest'
94-
run: |
95-
mkdir -p .cargo
96-
cat >> .cargo/config.toml <<EOF
97-
[target.aarch64-unknown-linux-musl]
98-
linker = "aarch64-linux-gnu-gcc"
99-
EOF
89+
cargo install cross --git https://github.com/cross-rs/cross
10090
10191
- name: Rust Cache
10292
uses: Swatinem/rust-cache@v2
@@ -105,9 +95,14 @@ jobs:
10595
shared-key: "release"
10696
cache-on-failure: true
10797

108-
- name: Build release binary
98+
- name: Build release binary (native)
99+
if: ${{ !matrix.cross }}
109100
run: cargo build --release --target ${{ matrix.target }}
110101

102+
- name: Build release binary (cross-compile)
103+
if: matrix.cross
104+
run: cross build --release --target ${{ matrix.target }}
105+
111106
- name: Strip binary (Linux)
112107
if: matrix.os == 'ubuntu-latest' && !matrix.cross
113108
run: strip target/${{ matrix.target }}/release/rust-strom

src/tls.rs

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use arc_swap::access::Access;
2-
use rustls_pemfile::{certs, rsa_private_keys};
2+
use rustls_pemfile::{certs, pkcs8_private_keys, rsa_private_keys};
33
use std::{
44
collections::HashMap,
55
fs::File,
6-
io::{self, BufReader, ErrorKind::InvalidData},
6+
io::{self, BufReader, ErrorKind::InvalidData, Seek},
77
path::Path,
88
sync::Arc,
99
};
@@ -71,7 +71,13 @@ fn load_key<P>(path: P) -> io::Result<PrivateKey>
7171
where
7272
P: AsRef<Path>,
7373
{
74-
let mut keys = load_keys(path)?;
74+
let mut keys = load_keys(&path)?;
75+
if keys.is_empty() {
76+
return Err(io::Error::new(
77+
InvalidData,
78+
format!("No private keys found in '{}'", path.as_ref().display()),
79+
));
80+
}
7581
Ok(keys.remove(0))
7682
}
7783

@@ -81,13 +87,30 @@ where
8187
{
8288
let file = File::open(&path)?;
8389
let mut reader = BufReader::new(file);
84-
let key_der_vec = rsa_private_keys(&mut reader).map_err(|_| {
85-
io::Error::new(
86-
InvalidData,
87-
format!("Invalid RSA key in '{}'", path.as_ref().display()),
88-
)
89-
})?;
90-
Ok(key_der_vec.into_iter().map(PrivateKey).collect())
90+
91+
// Try RSA keys first
92+
let rsa_keys = rsa_private_keys(&mut reader)
93+
.map(|keys| keys.into_iter().map(PrivateKey).collect::<Vec<_>>())
94+
.unwrap_or_default();
95+
96+
if !rsa_keys.is_empty() {
97+
return Ok(rsa_keys);
98+
}
99+
100+
// If no RSA keys found, try PKCS8 format (for ECDSA, Ed25519, etc.)
101+
reader.rewind()?;
102+
let pkcs8_keys = pkcs8_private_keys(&mut reader)
103+
.map(|keys| keys.into_iter().map(PrivateKey).collect::<Vec<_>>())
104+
.unwrap_or_default();
105+
106+
if !pkcs8_keys.is_empty() {
107+
return Ok(pkcs8_keys);
108+
}
109+
110+
Err(io::Error::new(
111+
InvalidData,
112+
format!("No valid private keys (RSA or PKCS8) found in '{}'", path.as_ref().display()),
113+
))
91114
}
92115

93116
pub struct ReconfigurableCertificateResolver<A>

0 commit comments

Comments
 (0)