feat: sign the ICA1 CSR

This introduces a bunch of facilities for PKI manipulations.

Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
This commit is contained in:
raito 2024-12-31 17:50:18 +01:00
parent 02b140aa3d
commit 1bb6e8a681
13 changed files with 167 additions and 0 deletions

13
default.nix Normal file
View file

@ -0,0 +1,13 @@
(import
(
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
inherit (lock.nodes.flake-compat.locked) narHash rev url;
in
builtins.fetchTarball {
url = "${url}/archive/${rev}.tar.gz";
sha256 = narHash;
}
)
{ src = ./.; }
).defaultNix

1
pki/.envrc Normal file
View file

@ -0,0 +1 @@
use nix

5
pki/README.md Normal file
View file

@ -0,0 +1,5 @@
# PKI management
This is our expressions to generate and manage our PKI in the project.
We are using NitroHSMs for the offline storage and OpenBao server for the online operations.

13
pki/cacerts/README.md Normal file
View file

@ -0,0 +1,13 @@
# CA certificate chains
## `ca.crt`
The root CA.
## `ica1.crt`
The chain from ICA1 to root CA.
## `ica2.crt`
The chain from ICA2 to root CA (ICA2 → ICA → root CA), this is what you want to usually use to trust our PKI.

36
pki/cacerts/ica1.crt Normal file
View file

@ -0,0 +1,36 @@
-----BEGIN CERTIFICATE-----
MIICrzCCAhKgAwIBAgIUUfC3HiC4wWFjkavirLxjTpVrxkcwCgYIKoZIzj0EAwIw
gZsxCzAJBgNVBAYTAkRFMQ8wDQYDVQQIDAZIZXNzZW4xEjAQBgNVBAcMCURhcm1z
dGFkdDEXMBUGA1UECgwORmxvcmFsIFN5c3RlbXMxLTArBgNVBAsMJEZsb3JhbCBT
eXN0ZW1zIENlcnRpZmljYXRlIEF1dGhvcml0eTEfMB0GA1UEAwwWRmxvcmFsIFN5
c3RlbXMgUm9vdCBDQTAeFw0yNDEyMzExNjQ0MjJaFw0yNTAxMzAxNjQ0MjJaMIGZ
MQswCQYDVQQGEwJERTEPMA0GA1UECBMGSGVzc2VuMRIwEAYDVQQHEwlEYXJtc3Rh
ZHQxFzAVBgNVBAoTDkZsb3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END CERTIFICATE REQUEST-----

3
pki/csr/README.md Normal file
View file

@ -0,0 +1,3 @@
# A trace of our CSRs files
This is a collection of the CSRs we built for our needs.

23
pki/default.nix Normal file
View file

@ -0,0 +1,23 @@
{ flake ? import ../., nixpkgs ? flake.inputs.nixpkgs, pkgs ? import nixpkgs { } }:
{
shell = pkgs.mkShell {
buildInputs = [
pkgs.openssl
];
OPENSSL_CONF = pkgs.writeText "openssl-pkcs11.conf" ''
openssl_conf = openssl_def
[openssl_def]
engines = engine_section
[engine_section]
pkcs11 = pkcs11_section
[pkcs11_section]
engine_id = pkcs11
dynamic_path = ${pkgs.libp11}/lib/engines/libpkcs11.so
MODULE_PATH = ${pkgs.opensc}/lib/opensc-pkcs11.so
'';
};
}

1
pki/policies/README.md Normal file
View file

@ -0,0 +1 @@
# OpenSSL policies for extensions and CAs

56
pki/policies/ca.conf Normal file
View file

@ -0,0 +1,56 @@
[ ca ]
# `man ca`
default_ca = CA_default
[ CA_default ]
# Directory and file locations.
dir = .
certs = $dir/certs
crl_dir = $dir/crl
new_certs_dir = $dir/newcerts
database = $dir/index.txt
serial = $dir/serial
# SHA-1 is deprecated, so use SHA-2 instead.
default_md = sha512
name_opt = ca_default
cert_opt = ca_default
default_days = 375
preserve = no
policy = policy_strict
[ policy_strict ]
# The root CA should only sign intermediate certificates that match.
# See the POLICY FORMAT section of `man ca`.
countryName = match
stateOrProvinceName = match
organizationName = match
organizationalUnitName = optional
commonName = supplied
emailAddress = optional
[ req ]
# Options for the `req` tool (`man req`).
default_bits = 4096
distinguished_name = req_distinguished_name
string_mask = utf8only
prompt = no
# SHA-1 is deprecated, so use SHA-2 instead.
default_md = sha512
[ req_distinguished_name ]
C = DE
ST = Hessen
L = Darmstadt
O = Floral Systems
OU = Floral Systems Certificate Authority
CN = Floral Systems Root CA
[ v3_ca ]
# Extensions for a typical CA (`man x509v3_config`).
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = critical, CA:true
keyUsage = critical, digitalSignature, cRLSign, keyCertSign

View file

@ -0,0 +1,6 @@
[ v3_intermediate_ca ]
# Extensions for a typical intermediate CA (`man x509v3_config`).
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = critical, CA:true
keyUsage = critical, digitalSignature, cRLSign, keyCertSign

2
pki/shell.nix Normal file
View file

@ -0,0 +1,2 @@
(import ./. { }).shell