1
+ #! /bin/bash
2
+
3
+ # // SPDX-License-Identifier: LGPL-2.1-or-later
4
+ # // Copyright (c) 2015-2025 MariaDB Corporation Ab
5
+
6
+ # Script to generate self-signed certificates for testing
7
+ # CN: mariadb.example.com
8
+
9
+ set -e
10
+
11
+ echo " Generating self-signed certificates for mariadb.example.com..."
12
+
13
+ # Create directory for certificates
14
+ mkdir -p .github/workflows/certs
15
+
16
+ echo " Generate CA private key"
17
+ openssl genrsa 2048 > .github/workflows/certs/ca.key
18
+
19
+ echo " [ req ]" > .github/workflows/certs/ca.conf
20
+ echo " prompt = no" >> .github/workflows/certs/ca.conf
21
+ echo " distinguished_name = req_distinguished_name" >> .github/workflows/certs/ca.conf
22
+ echo " " >> .github/workflows/certs/ca.conf
23
+ echo " [ req_distinguished_name ]" >> .github/workflows/certs/ca.conf
24
+ echo " countryName = FR" >> .github/workflows/certs/ca.conf
25
+ echo " stateOrProvinceName = Loire-atlantique" >> .github/workflows/certs/ca.conf
26
+ echo " localityName = Nantes" >> .github/workflows/certs/ca.conf
27
+ echo " organizationName = Home" >> .github/workflows/certs/ca.conf
28
+ echo " organizationalUnitName = Lab" >> .github/workflows/certs/ca.conf
29
+ echo " commonName = mariadb.example.com" >> .github/workflows/certs/ca.conf
30
+ echo " emailAddress = [email protected] " >> .github/workflows/certs/ca.conf
31
+
32
+ echo " Generate CA certificate (self-signed)"
33
+ openssl req -days 365 -new -x509 -nodes -key .github/workflows/certs/ca.key -out .github/workflows/certs/ca.crt --config .github/workflows/certs/ca.conf
34
+
35
+
36
+
37
+ echo " [ req ]" > .github/workflows/certs/server.conf
38
+ echo " prompt = no" >> .github/workflows/certs/server.conf
39
+ echo " distinguished_name = req_distinguished_name" >> .github/workflows/certs/server.conf
40
+ echo " req_extensions = req_ext" >> .github/workflows/certs/server.conf
41
+ echo " " >> .github/workflows/certs/server.conf
42
+ echo " [ req_distinguished_name ]" >> .github/workflows/certs/server.conf
43
+ echo " countryName = FR" >> .github/workflows/certs/server.conf
44
+ echo " stateOrProvinceName = Loire-atlantique" >> .github/workflows/certs/server.conf
45
+ echo " localityName = Nantes" >> .github/workflows/certs/server.conf
46
+ echo " organizationName = Home" >> .github/workflows/certs/server.conf
47
+ echo " organizationalUnitName = Lab" >> .github/workflows/certs/server.conf
48
+ echo " commonName = mariadb.example.com" >> .github/workflows/certs/server.conf
49
+ echo " emailAddress = [email protected] " >> .github/workflows/certs/server.conf
50
+ echo " " >> .github/workflows/certs/server.conf
51
+ echo " [ req_ext ]" >> .github/workflows/certs/server.conf
52
+ echo " subjectAltName = DNS: mariadb.example.com, IP: 127.0.0.1" >> .github/workflows/certs/server.conf
53
+
54
+
55
+ echo " Generating private key..."
56
+ openssl genrsa -out .github/workflows/certs/server.key 2048
57
+
58
+ echo " Generating certificate signing request..."
59
+ openssl req -new -key .github/workflows/certs/server.key -out .github/workflows/certs/server.csr --config .github/workflows/certs/server.conf
60
+
61
+
62
+ echo " Generate the certificate for the server:"
63
+ openssl x509 -req -days 365 -in .github/workflows/certs/server.csr -out .github/workflows/certs/server.crt -CA .github/workflows/certs/ca.crt -CAkey .github/workflows/certs/ca.key -extensions req_ext -extfile .github/workflows/certs/server.conf
64
+
65
+ # Set appropriate permissions
66
+ chmod 600 .github/workflows/certs/ca.key
67
+ chmod 644 .github/workflows/certs/server.crt .github/workflows/certs/ca.crt .github/workflows/certs/server.key
68
+
69
+ # List generated certificates
70
+ echo " Generated certificates:"
71
+ ls -la .github/workflows/certs/
72
+
73
+ # Verify certificate
74
+ echo " Certificate details:"
75
+ openssl x509 -in .github/workflows/certs/server.crt -text -noout | grep -E " (Subject|CN)"
76
+
77
+ echo " Certificate generation completed successfully!"
0 commit comments