-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Salvatore Dario Minonne <sminonne@redhat.com>
- Loading branch information
Showing
6 changed files
with
430 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ | |
kubeconfig.* | ||
kubeconfig | ||
trashcan/ | ||
mini-ca/root/ | ||
mini-ca/intermediate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
This sets of script generate a mini CA through openssl. | ||
|
||
```shell | ||
$ ./check-or-generate-root.sh | ||
... | ||
``` | ||
|
||
```shell | ||
$ ./check-or-generate-intermediate.sh | ||
``` | ||
|
||
|
||
Now let's add the intermediate cert as a trusted certificate authority. | ||
|
||
``` shell | ||
$ sudo cp intermediate/intermediate_cert.pem /etc/pki/ca-trust/source/anchors/intermediate_cert.pem | ||
``` | ||
|
||
```shell | ||
$ sudo update-ca-trust | ||
``` | ||
|
||
OK now we can test, let's generate a certificate for localhost with the just added CA. | ||
|
||
|
||
```shell | ||
cat << EOF > localhost.cnf | ||
[req] | ||
prompt = no | ||
distinguished_name = distinguished_name_server_cert | ||
req_extensions = v3_server_cert | ||
[distinguished_name_server_cert] | ||
countryName = FR | ||
stateOrProvinceName = Paca | ||
localityName = Trourrettes sur Loup | ||
organizationName = Minonne | ||
commonName = localhost | ||
[v3_server_cert] | ||
subjectAltName = DNS:localhost | ||
EOF | ||
``` | ||
|
||
```shell | ||
openssl genpkey \ | ||
-algorithm ED448 \ | ||
-out localhost-key.pem | ||
``` | ||
|
||
```shell | ||
openssl req \ | ||
-config localhost.cnf \ | ||
-new \ | ||
-key localhost-key.pem \ | ||
-out localhost-csr.pem \ | ||
-text | ||
``` | ||
|
||
|
||
let's sign it with the intermediate CA | ||
|
||
|
||
```shell | ||
openssl ca \ | ||
-batch \ | ||
-config ./intermediate/intermediate.cnf \ | ||
-in ./localhost-csr.pem \ | ||
-out ./localhost-cert.pem | ||
``` | ||
|
||
|
||
and now let's create a test http server on localhost. | ||
|
||
```shell | ||
openssl s_server -key localhost-key.pem -cert localhost-cert.pem -accept 5000 -WWW | ||
``` | ||
|
||
and now in another shell you can connect to the server: | ||
|
||
```shell | ||
$ curl https://localhost:5000 | ||
``` | ||
|
||
|
||
|
||
To remove the intermediate CA | ||
|
||
`` shell | ||
$ sudo rm /etc/pki/ca-trust/source/anchors/intermediate_cert.pem | ||
``` | ||
```shell | ||
$ sudo update-ca-trust | ||
``` | ||
|
||
|
||
|
||
Thanks to https://github.com/PacktPublishing/Demystifying-Cryptography-with-OpenSSL-3/tree/main/Chapter12/mini-ca | ||
and https://www.devdungeon.com/content/how-add-trusted-ca-certificate-centosfedora |
Oops, something went wrong.