Skip to content

Commit 5b666ee

Browse files
committed
fix: use generated certificates
Adds a script to generate a long lasting self signed certificate for the redirector and other services to use
1 parent 7c946a6 commit 5b666ee

4 files changed

Lines changed: 103 additions & 55 deletions

File tree

certs/generate.sh

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# -------------------------
6+
# Variables
7+
# -------------------------
8+
9+
CA_NAME="GOS 2015 Certificate Authority"
10+
CA_KEY="gos2015-ca.key"
11+
CA_CRT="gos2015-ca.crt"
12+
13+
SERVER_CN="winter15.gosredirector.ea.com"
14+
SERVER_KEY="winter15.key"
15+
SERVER_CSR="winter15.csr"
16+
SERVER_CRT="winter15.crt"
17+
18+
OPENSSL_CONF="winter15-openssl.cnf"
19+
20+
# -------------------------
21+
# Create OpenSSL Config for SANs
22+
# -------------------------
23+
24+
cat > "$OPENSSL_CONF" <<EOF
25+
[ req ]
26+
default_bits = 4096
27+
prompt = no
28+
default_md = sha256
29+
distinguished_name = req_distinguished_name
30+
req_extensions = req_ext
31+
32+
[ req_distinguished_name ]
33+
CN = winter15.gosredirector.ea.com
34+
O = Electronic Arts, Inc. Ltd
35+
ST = California
36+
C = US
37+
38+
[ req_ext ]
39+
subjectAltName = @alt_names
40+
41+
[ alt_names ]
42+
DNS.1 = winter15.gosredirector.ea.com
43+
DNS.2 = spring18.gosredirector.ea.com
44+
EOF
45+
46+
echo "[+] OpenSSL SAN configuration created in $OPENSSL_CONF"
47+
48+
# -------------------------
49+
# Create CA
50+
# -------------------------
51+
52+
echo "[+] Generating CA private key..."
53+
openssl genrsa -out "$CA_KEY" 4096
54+
55+
echo "[+] Generating CA certificate..."
56+
MSYS2_ARG_CONV_EXCL='*' openssl req -x509 -new -nodes \
57+
-key "$CA_KEY" \
58+
-sha256 -days 3650 \
59+
-subj "/CN=GOS 2015 Certificate Authority/O=Electronic Arts, Inc. Ltd/ST=California/C=US" \
60+
-out "$CA_CRT"
61+
62+
# -------------------------
63+
# Create server key + CSR
64+
# -------------------------
65+
66+
echo "[+] Generating server private key..."
67+
openssl genrsa -out "$SERVER_KEY" 4096
68+
69+
echo "[+] Generating server CSR..."
70+
openssl req -new \
71+
-key "$SERVER_KEY" \
72+
-out "$SERVER_CSR" \
73+
-config "$OPENSSL_CONF"
74+
75+
# -------------------------
76+
# Sign certificate with the CA
77+
# -------------------------
78+
79+
echo "[+] Signing server certificate with CA..."
80+
openssl x509 -req \
81+
-in "$SERVER_CSR" \
82+
-CA "$CA_CRT" \
83+
-CAkey "$CA_KEY" \
84+
-CAcreateserial \
85+
-out "$SERVER_CRT" \
86+
-days 3650 \
87+
-sha256 \
88+
-extensions req_ext \
89+
-extfile "$OPENSSL_CONF"
90+
91+
echo ""
92+
echo "============================================"
93+
echo " Certificate Generation Complete"
94+
echo "============================================"
95+
echo "CA Key: $CA_KEY"
96+
echo "CA Cert: $CA_CRT"
97+
echo "Server Key: $SERVER_KEY"
98+
echo "Server CSR: $SERVER_CSR"
99+
echo "Server Cert: $SERVER_CRT"
100+
echo ""

src/pocket_ark.crt

-1.61 KB
Binary file not shown.

src/pocket_ark.key

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/ssl.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use openssl::{
1212
/// Creates a new [SslContext] for use within a server context for
1313
/// accepting connections
1414
pub fn create_ssl_context() -> anyhow::Result<SslContext> {
15-
const CERTIFICATE_BYTES: &[u8] = include_bytes!("pocket_ark.crt");
16-
const PRIVATE_KEY_BYTES: &[u8] = include_bytes!("pocket_ark.key");
15+
const CERTIFICATE_BYTES: &[u8] = include_bytes!("../certs/winter15.crt");
16+
const PRIVATE_KEY_BYTES: &[u8] = include_bytes!("../certs/winter15.key");
1717

18-
let certificate = X509::from_der(CERTIFICATE_BYTES).context("Failed to load certificate")?;
18+
let certificate = X509::from_pem(CERTIFICATE_BYTES).context("Failed to load certificate")?;
1919
let private_key =
2020
Rsa::private_key_from_pem(PRIVATE_KEY_BYTES).context("Failed to load private key")?;
2121
let private_key = PKey::from_rsa(private_key).context("Failed to create private key")?;

0 commit comments

Comments
 (0)