-
Notifications
You must be signed in to change notification settings - Fork 2
/
mkCaConfig.dhall
138 lines (115 loc) · 3.79 KB
/
mkCaConfig.dhall
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
let Config = ./CaConfig.dhall
let Policy = ./Policy.dhall
let prelude = ./prelude.dhall
let render = ./render.dhall
in λ(config : Config.Type) →
let distinguishedName = render.distinguishedName config.distinguishedName
let mkConstraints =
λ(type : Text) →
λ(hosts : List Text) →
prelude.Text.concatMapSep
"\n"
{ index : Natural, value : Text }
( λ(data : { index : Natural, value : Text }) →
"permitted;${type}.${Natural/show
data.index} = ${data.value}"
)
(prelude.List.indexed Text hosts)
let policies =
prelude.Text.concatMapSep
"\n"
{ name : Text, policy : Policy.Type }
render.policy
config.policies
let pathlen =
prelude.Optional.fold
Natural
config.pathlen
Text
(λ(n : Natural) → ", pathlen:${Natural/show n}")
""
let defaultPolicy =
prelude.Optional.fold
Text
config.defaultPolicy
Text
(λ(policy : Text) → "policy = ${policy}")
""
let crl =
prelude.Optional.fold
Text
config.crl
Text
( λ(p : Text) →
''
crl = ${p}''
)
""
let crlDir =
prelude.Optional.fold
Text
config.crlDir
Text
( λ(p : Text) →
''
crl_dir = ${p}''
)
""
let crlNumber =
prelude.Optional.fold
Text
config.crlNumber
Text
( λ(p : Text) →
''
crl_dir = ${p}''
)
""
let defaultCrlDays =
prelude.Optional.fold
Natural
config.defaultCrlDays
Text
( λ(p : Natural) →
''
default_crl_days = ${Natural/show p}''
)
""
in ''
[ req ]
default_bits = ${Natural/show config.defaultBits}
encrypt_key = ${render.yesNo config.encryptKey}
default_md = ${config.defaultMd}
string_mask = ${config.stringMask}
utf8 = ${render.yesNo config.utf8}
prompt = ${render.yesNo config.prompt}
x509_extensions = x509_ext
distinguished_name = distinguished_name
[ x509_ext ]
basicConstraints = critical, CA:true${pathlen}
${if prelude.List.null Text config.allowedHosts
then ""
else "nameConstraints = critical, @name_constraints"}
subjectKeyIdentifier = hash
issuerAltName = issuer:copy
authorityKeyIdentifier = keyid:always, issuer:always
${render.keyUsage config.usage}
${distinguishedName}
[ ca ]
default_ca = CA_default
[ CA_default ]
base_dir = ${config.caDir}
database = ${config.database}
serial = ${config.serial}
new_certs_dir = ${config.caDir}${crl}${crlDir}${crlNumber}${defaultCrlDays}
default_md = ${config.defaultMd}
default_days = ${Natural/show config.defaultDays}
email_in_dn = no
${defaultPolicy}
copy_extensions = copy
uniqueSubject = ${render.yesNo config.uniqueSubject}
${policies}
[ name_constraints ]
${mkConstraints "DNS" config.allowedHosts}
${mkConstraints "IP" config.allowedIPs}
''