Skip to content

Commit 17b3713

Browse files
att
1 parent 9318fe8 commit 17b3713

3 files changed

Lines changed: 53 additions & 14 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
BearSSLTrustAnchors.c
22
*.o
3-
*.so
3+
*.so
4+
certs/

README.md

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# BearSSLTrustedAnchors
22

3-
A trusted CA certificates generator for BearSSL applications, providing a ready-to-use C source file with trusted root certificates.
3+
A trusted CA certificates generator for BearSSL applications, providing a ready-to-use C source file with trusted root certificates compatible with virtually any website.
44

55
## Latest Release
66

@@ -10,14 +10,25 @@ A trusted CA certificates generator for BearSSL applications, providing a ready-
1010

1111
## Overview
1212

13-
This project generates trusted anchor certificates for [BearSSL](https://bearssl.org/) from the official Mozilla CA certificate bundle. The generated C source file contains all trusted root certificates in a format that can be directly compiled into BearSSL applications.
13+
This project generates trusted anchor certificates for [BearSSL](https://bearssl.org/) from multiple CA sources, maximizing compatibility with public websites, government portals, and enterprise services. The generated C source file contains all trusted root certificates in a format that can be directly compiled into BearSSL applications.
1414

15-
### Certificate Source
15+
### Certificate Sources
1616

17-
The trusted anchors are generated from:
18-
- **Source**: [Mozilla CA Certificate Bundle](https://curl.se/docs/caextract.html)
19-
- **URL**: [https://curl.se/ca/cacert.pem](https://curl.se/ca/cacert.pem)
20-
- **Tool**: `brssl` from [BearSSL](https://bearssl.org/)
17+
The trusted anchors are generated by combining:
18+
19+
| # | Source | Description |
20+
|---|--------|-------------|
21+
| 1 | [Mozilla CA Bundle](https://curl.se/docs/caextract.html) (`curl.se/ca/cacert.pem`) | Primary bundle — covers the vast majority of public websites |
22+
| 2 | System CA bundle (auto-detected) | Adds national, governmental, and corporate CAs not present in Mozilla's bundle |
23+
24+
**System bundle auto-detection order:**
25+
26+
| Path | Distribution |
27+
|------|-------------|
28+
| `/etc/ssl/certs/ca-certificates.crt` | Debian / Ubuntu |
29+
| `/etc/pki/tls/certs/ca-bundle.crt` | RHEL / CentOS / Fedora |
30+
| `/etc/ssl/ca-bundle.pem` | openSUSE |
31+
| `/etc/ssl/cert.pem` | Alpine / macOS |
2132

2233
## Usage
2334

@@ -31,11 +42,12 @@ sh generator.sh
3142

3243
This script will:
3344
1. Download the latest CA certificate bundle from Mozilla
34-
2. Convert it to BearSSL format using the `brssl` tool
35-
3. Generate the `BearSSLTrustedAnchors.c` file
45+
2. Merge it with the system CA bundle (if available)
46+
3. Convert the combined bundle to BearSSL format using the `brssl` tool
47+
4. Generate the `BearSSLTrustedAnchors.c` file
3648

3749
### Requirements
3850

3951
- [BearSSL](https://bearssl.org/) tools (`brssl`)
40-
- `curl` or `wget` for downloading certificates
52+
- `curl` for downloading certificates
4153
- `bash` shell

generator.sh

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,34 @@
11
#!/bin/bash
22

3+
CERT_DIR="certs"
4+
COMBINED_CERT="$CERT_DIR/cacert.pem"
35

6+
mkdir -p "$CERT_DIR"
47

5-
# Download CA certificates
6-
curl -L https://curl.se/ca/cacert.pem -o BearSSL/cacert.pem
8+
# Start with empty combined file
9+
> "$COMBINED_CERT"
10+
11+
# Source 1: Mozilla CA Bundle (via curl.se) — primary, most comprehensive public bundle
12+
echo "Downloading Mozilla CA Bundle..."
13+
curl -L https://curl.se/ca/cacert.pem -o "$CERT_DIR/mozilla.pem"
14+
cat "$CERT_DIR/mozilla.pem" >> "$COMBINED_CERT"
15+
16+
# Source 2: System CA certificates — adds national/corporate/enterprise CAs not in Mozilla
17+
if [ -f /etc/ssl/certs/ca-certificates.crt ]; then
18+
echo "Adding system CA certificates (Debian/Ubuntu)..."
19+
cat /etc/ssl/certs/ca-certificates.crt >> "$COMBINED_CERT"
20+
elif [ -f /etc/pki/tls/certs/ca-bundle.crt ]; then
21+
echo "Adding system CA certificates (RHEL/CentOS/Fedora)..."
22+
cat /etc/pki/tls/certs/ca-bundle.crt >> "$COMBINED_CERT"
23+
elif [ -f /etc/ssl/ca-bundle.pem ]; then
24+
echo "Adding system CA certificates (openSUSE)..."
25+
cat /etc/ssl/ca-bundle.pem >> "$COMBINED_CERT"
26+
elif [ -f /etc/ssl/cert.pem ]; then
27+
echo "Adding system CA certificates (Alpine/macOS)..."
28+
cat /etc/ssl/cert.pem >> "$COMBINED_CERT"
29+
else
30+
echo "No system CA bundle found, using Mozilla bundle only."
31+
fi
732

833
# Build BearSSL
934
cd BearSSL && make
@@ -13,5 +38,6 @@ cd ..
1338
chmod +x BearSSL/build/brssl
1439

1540
# Generate trust anchors file
16-
./BearSSL/build/brssl ta BearSSL/cacert.pem > BearSSLTrustAnchors.c
41+
./BearSSL/build/brssl ta "$COMBINED_CERT" > BearSSLTrustAnchors.c
1742

43+
echo "Done! Generated BearSSLTrustAnchors.c"

0 commit comments

Comments
 (0)