Skip to content

Commit dc0217a

Browse files
committed
ID-35: add support to remove certificates
1 parent 528c2b8 commit dc0217a

File tree

6 files changed

+72
-6
lines changed

6 files changed

+72
-6
lines changed

doc/manual/_config-tool.adoc

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Options:
6161
If environmentalized fields or certificates are not configured, the build fails.
6262
Missing fields or certificates are automatically added to the configuration file.
6363

64-
[cols="2,5", options="header"]
64+
[cols="2,5a", options="header"]
6565
|===
6666
|Option
6767
|Description
@@ -134,11 +134,19 @@ If not set the output archives have the same passphrase as the source archives.
134134
|Enable simulation mode.
135135

136136
In simulation mode, no output files (`.fed` or `.env`) will be written.
137-
Also non existing certificate files will be ignored.
138137

138+
The simulation mode will ignore non existing certificate files and will not apply the values of environmentalized fields.
139+
140+
[NOTE]
141+
====
142+
The simulation mode can be used to prepare packages for CI/CD pipelines.
143+
144+
In this case configuration parameters and certificates may be stored in a configuration database.
145+
So during the preparation phase the certificates may not be available and the configuration files may contain placeholders.
146+
To avoid errors due to incompatible types (e.g. placeholder string used for an integer field) the values will not be applied to the entity store.
147+
====
139148
|===
140149

141-
TIP: The simulation mode can be used to check the configuration and to update the configuration files.
142150

143151
== Configuration Files
144152

@@ -340,6 +348,17 @@ It specifies the alias of the certificates within the project and the source of
340348
"source": "env", <16>
341349
"type": "p12"
342350
}
351+
},
352+
"test4": {
353+
"origin": {
354+
"info": {
355+
"not_after": "2021-09-30T16:01:15+02:00",
356+
"subject": "CN=DST Root CA X3, O=Digital Signature Trust Co."
357+
}
358+
},
359+
"update": {
360+
"type": "empty" <17>
361+
}
343362
}
344363
}
345364
}
@@ -364,6 +383,7 @@ This certificate will be added to the certificate store.
364383
<14> Declares the property "password" as the source of the password for the `.p12` file.
365384
<15> The password is retrieved from the `TEST3_PASSWORD` environment variable.
366385
<16> Specifies an environment variable as the source of the password.
386+
<17> Type `empty` indicates that a certificate will be updated with an _empty_ certificate and therefore will be removed.
367387

368388
=== Properties
369389

example/config-tool/config/gateway.certs.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,28 @@
3333
"file": "config/certs/staged-root-ca.crt",
3434
"type": "crt"
3535
}
36+
},
37+
"to-be-deleted": {
38+
"origin": {
39+
"info": {
40+
"not_after": "2020-08-23T20:24:00+02:00",
41+
"subject": "CN=localhost, O=ACME Inc., C=EX"
42+
}
43+
},
44+
"update": {
45+
"type": "empty"
46+
}
47+
},
48+
"to-be-removed-ca": {
49+
"origin": {
50+
"info": {
51+
"not_after": "2029-08-23T20:19:00+02:00",
52+
"subject": "CN=acme-inc-example, O=ACME Inc., L=Example, C=EX"
53+
}
54+
},
55+
"update": {
56+
"type": "empty"
57+
}
3658
}
3759
}
3860
}
1.4 KB
Binary file not shown.
3 Bytes
Binary file not shown.

src/main/resources/scripts/lib/envconfig.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ def __init__(self, alias, cert_type, cert_file_path, password = ""):
223223
self.__file_path = cert_file_path
224224
self.__password = password
225225

226+
if cert_type not in ["crt", "p12", "empty"]:
227+
raise ValueError("Invalid certificate type '%s' for alias '%s'!" % (cert_type, alias))
228+
if self.__type != "empty" and not self.__file_path:
229+
raise ValueError("Missing path to certificate file for alias '%s'!" % (alias))
230+
return
231+
226232
def get_alias(self):
227233
return self.__alias
228234

@@ -234,6 +240,9 @@ def get_file(self):
234240

235241
def get_password(self):
236242
return self.__password
243+
244+
def is_empty():
245+
return self.__type == "empty"
237246

238247
class CertInfo:
239248
__alias = None
@@ -362,10 +371,13 @@ def get_certificates(self):
362371

363372
cert = cert_cfg["update"]
364373

374+
if "type" not in cert:
375+
raise ValueError("Missing certificate type for alias '%s'!" % (alias))
365376
cert_type = cert["type"]
366-
if cert_type not in ["crt", "p12"]:
367-
raise ValueError("Invalid certificate type '%s' for alias '%s'!" % (cert_type, alias))
368-
cert_file = cert["file"]
377+
378+
cert_file = None
379+
if "file" in cert:
380+
cert_file = cert["file"]
369381

370382
password = None
371383
if "password" in cert:

src/main/resources/scripts/lib/fedconfig.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,14 @@ def __add_or_replace_certificate(self, es, alias, cert, private_key=None):
182182
es.updateEntity(cert_entity)
183183
return
184184

185+
def __remove_certificate(self, es, alias):
186+
# Get certificate entity
187+
cert_store = es.get('/[Certificates]name=Certificate Store')
188+
cert_entity = es.getChild(cert_store, '[Certificate]dname=%s' % (es.escapeField(alias)))
189+
if cert_entity:
190+
es.cutEntity(cert_entity)
191+
return
192+
185193
def __configure_certificates(self):
186194
if self.__cert_config is not None:
187195
# determine existing certificates
@@ -223,6 +231,10 @@ def __configure_certificates(self):
223231
continue
224232
else:
225233
raise ValueError("Certificate file not found for alias '%s': %s" % (cert_ref.get_alias(), cert_ref.get_file()))
234+
elif cert_ref.get_type() == "empty":
235+
self.__remove_certificate(es, cert_ref.get_alias())
236+
logging.info("Certificate removed: %s" % (cert_ref.get_alias()))
237+
continue
226238
else:
227239
raise ValueError("Unsupported certificate type: %s" % (cert_ref.get_type()))
228240

0 commit comments

Comments
 (0)