Skip to content

Commit 29ebde7

Browse files
committed
ID-17, ID-18: check expiration of certificates
1 parent f716fc5 commit 29ebde7

File tree

10 files changed

+191
-48
lines changed

10 files changed

+191
-48
lines changed

CHANGELOG.adoc

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,59 @@
11
= Changelog
22

3+
== Version 0.7.0
4+
5+
[cols="1,2,<10a", options="header"]
6+
|===
7+
|ID|Type|Description
8+
|https://github.com/Axway-API-Management-Plus/apigw-maven-plugin/issues/17[#17]
9+
|Enhancement
10+
|Check expiration of configured certificates.
11+
12+
The plugin and the configuration tool now supports to check if configured certificates expires within a given number of days.
13+
If at least one certificate expires within the time frame an error will be raised.
14+
15+
For the configuration tool the check is disabled by default.
16+
17+
For the plugin the default number of days is 10.
18+
To disable the check for the plugin specify set `axway.tools.cfg.cert.expirationDays` property to -1.
19+
20+
|https://github.com/Axway-API-Management-Plus/apigw-maven-plugin/issues/18[#18]
21+
|Enhancement
22+
|Don't create "info" section for "update" certificates.
23+
Information about the configured certificates are written to log instead.
24+
25+
Previously the configuration tool has written the "info" section (see below).
26+
This will change a source file, which is not suitable for build environments.
27+
28+
.previous-cert-config.json
29+
....
30+
"update": {
31+
"file": "cert/server.p12",
32+
"info": { <1>
33+
"not_after": "2020-05-21T07:02:00+02:00",
34+
"subject": "CN=server, O=Axway, L=Berlin, ST=Berlin, C=DE"
35+
},
36+
"password": "server",
37+
"type": "p12"
38+
}
39+
....
40+
<1> Information about the configured certificate, will no longer be created or updated.
41+
42+
The "info" section is no longer created or updated for "update" certificates.
43+
44+
.cert-config.json
45+
....
46+
"update": {
47+
"file": "cert/server.p12",
48+
"password": "server",
49+
"type": "p12"
50+
}
51+
....
52+
53+
54+
NOTE: To enable the previous behavior, use the `--cert-config-update` parameter of the configuration tool or the `axway.tools.cfg.cert.updateConfigured` property of the plugin.
55+
|===
56+
357
== Version 0.6.0
458

559
[cols="1,2,<10a", options="header"]

doc/getting-started/getting-started.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
:sectnums:
66
:source-highlighter: prettify
77

8-
:mvn-plugin-ver: 0.6.0
8+
:mvn-plugin-ver: 0.7.0-SNAPSHOT
99

1010
Here you get a simple introduction on how to use the _Maven Plugin for Axway API Gateway_.
1111
It assumes that you are familiar with https://maven.apache.org[Apache Maven] and that you are familiar with PolicyStudio and the API Gateway.

doc/manual/_config-tool.adoc

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,24 @@ Options:
3737
Path of JSON configuration file
3838
--prop=FILEPATH Path of JSON property file [optional]
3939
--cert=FILEPATH Path of JSON certificate configuration file [optional]
40+
--cert-expiration=DAYS
41+
Check if certificates expire within the next days
42+
[optional]
43+
--cert-config-update Enable writing of info section for 'update'
44+
certificates within the configuration file [optional]
4045
--output-fed=FILEPATH
41-
Path of output deployment archive file (.fed) [optional]
46+
Path of output deployment archive file (.fed)
47+
[optional]
4248
--output-env=FILEPATH
43-
Path of output environment archive file (.env) [optional]
49+
Path of output environment archive file (.env)
50+
[optional]
4451
-D NAME:VALUE, --define=NAME:VALUE
4552
Define a system property [multiple]
4653
--passphrase-in=PASSPHRASE
4754
Passphrase of input archive files [optional]
4855
--passphrase-out=PASSPHRASE
4956
Passphrase for output archive files [optional]
57+
-s, --simulate Enable simulation mode [optional]
5058
....
5159

5260
If environmentalized fields or certificates are not configured, the build fails.
@@ -76,6 +84,17 @@ The option is mandatory.
7684
|--cert
7785
|An optional JSON file containing the certificate configuration.
7886

87+
|--cert-expiration
88+
|Optional number of days for certificate expiration check.
89+
90+
If at least one certificate expires with the next given days an error will be raised.
91+
92+
|--cert-config-update
93+
|Enable writing of info section for 'update' certificates within the configuration file.
94+
95+
Since version v0.7.0 the info section of "update" certificates are not written any more.
96+
Use this to enable the previous behavior.
97+
7998
|--output-fed
8099
|The path of the configured `.fed` file.
81100
If missing, no `.fed` file is generated.
@@ -105,6 +124,7 @@ If not set the output archives have the same passphrase as the source archives.
105124

106125
In simulation mode, no output files (`.fed` or `.env`) will be written.
107126
Also non existing certificate files will be ignored.
127+
108128
|===
109129

110130
TIP: The simulation mode can be used to check the configuration and to update the configuration files.
@@ -279,11 +299,7 @@ It specifies the alias of the certificates within the project and the source of
279299
},
280300
"update": { <6>
281301
"file": "cert/extern.crt", <7>
282-
"info": { <8>
283-
"not_after": "2020-05-21T07:04:00+02:00",
284-
"subject": "CN=extern, O=Axway, L=Berlin, ST=Berlin, C=DE"
285-
},
286-
"type": "crt" <9>
302+
"type": "crt" <8>
287303
}
288304
},
289305
"server-p12": {
@@ -295,11 +311,7 @@ It specifies the alias of the certificates within the project and the source of
295311
},
296312
"update": {
297313
"file": "cert/server.p12",
298-
"info": {
299-
"not_after": "2020-05-21T07:02:00+02:00",
300-
"subject": "CN=server, O=Axway, L=Berlin, ST=Berlin, C=DE"
301-
},
302-
"password": "server", <10>
314+
"password": "server", <9>
303315
"type": "p12"
304316
}
305317
},
@@ -310,16 +322,12 @@ It specifies the alias of the certificates within the project and the source of
310322
"subject": "CN=DST Root CA X3, O=Digital Signature Trust Co."
311323
}
312324
},
313-
"update": null <11>
325+
"update": null <10>
314326
},
315-
"test2": { <12>
327+
"test2": { <11>
316328
"update": {
317329
"file": "cert/server.p12",
318-
"info": {
319-
"not_after": "2020-05-21T07:02:00+02:00",
320-
"subject": "CN=server, O=Axway, L=Berlin, ST=Berlin, C=DE"
321-
},
322-
"password-property": "server.password", <13>
330+
"password-property": "server.password", <12>
323331
"type": "p12"
324332
}
325333
}
@@ -335,15 +343,13 @@ A missing `origin` attribute indicates the origin certificate store doesn't has
335343
<6> Defines the certificate to update the certificate with the same alias within the certificate store.
336344
A missing `update` attribute indicates a new/unconfigured certificate.
337345
<7> Path to the new certificate file.
338-
<8> Information of the new certificate.
339-
Will be updated automatically be the plugin.
340-
<9> Type of the certificate.
346+
<8> Type of the certificate.
341347
`crt` for certificates and `p12` for certificates with key.
342-
<10> Password to for the `.p12` file.
343-
<11> _null_ value indicates that the certificate will not be updated.
344-
<12> Certificate without a `origin` attribute.
348+
<9> Password to for the `.p12` file.
349+
<10> _null_ value indicates that the certificate will not be updated.
350+
<11> Certificate without a `origin` attribute.
345351
This certificate will be added to the certificate store.
346-
<13> Password for the `.p12` file is retrieved from the property configuration file.
352+
<12> Password for the `.p12` file is retrieved from the property configuration file.
347353

348354
=== Properties
349355

doc/manual/_reference.adoc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,22 @@ Default: ${axway.home}/apigateway/system/conf/templates/BlankNoSettingsConfigura
231231

232232
Default: false
233233

234+
|axway.tools.cfg.cert.expirationDays
235+
|Minimum number of days before certificates expires.
236+
237+
The build fails if at least one configured certificate expires within the next given days.
238+
Use -1 to disable the check.
239+
240+
Default: 10
241+
242+
|axway.tools.cfg.cert.updateConfigured
243+
|Set to _true_ to enable writing the info section of "update" certificates in the configuration file.
244+
245+
Since version v0.7.0 the info section of "update" certificates are not written any more.
246+
This property can be used to enable the previous behavior.
247+
248+
Default: false
249+
234250
|axway.passphrase.in
235251
|Passphrase for reading input (`.pol`, `.env`) packages.
236252
Applicable to deployment projects only.

doc/manual/user-guide.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ifdef::env-github[]
1818
:warning-caption: :warning:
1919
endif::[]
2020

21-
:mvn-plugin-ver: 0.6.0
21+
:mvn-plugin-ver: 0.7.0-SNAPSHOT
2222

2323
== About the Plugin
2424

example/getting-started/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<packaging>pom</packaging>
88

99
<properties>
10-
<axway.maven.plugin.ver>0.6.0</axway.maven.plugin.ver>
10+
<axway.maven.plugin.ver>0.7.0-SNAPSHOT</axway.maven.plugin.ver>
1111
</properties>
1212

1313
<modules>

src/main/java/com/axway/maven/apigw/DeploymentArchiveMojo.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ public class DeploymentArchiveMojo extends AbstractFlattendProjectArchiveMojo {
3232
@Parameter(property = "certsFile", required = false)
3333
private File certsFile;
3434

35+
@Parameter(property = "axway.tools.cfg.cert.expirationDays", required = false)
36+
private int certExpirationDays = 10;
37+
38+
@Parameter(property = "axway.tools.cfg.cert.updateConfigured", required = false)
39+
private boolean updateCertConfigFile = false;
40+
3541
@Parameter(property = "axway.tools.cfg.verbose", defaultValue = "false", required = true)
3642
protected boolean verboseCfgTools;
3743

@@ -149,6 +155,14 @@ private void buildFedArchive(File targetDir, File srcPolFile, File srcEnvFile) t
149155
if (this.certsFile != null) {
150156
args.add("--cert");
151157
args.add(this.certsFile.getPath());
158+
159+
if (this.certExpirationDays >= 0) {
160+
args.add("--cert-expiration=" + this.certExpirationDays);
161+
}
162+
163+
if (this.updateCertConfigFile) {
164+
args.add("--cert-config-update");
165+
}
152166
}
153167
args.add("--output-fed");
154168
args.add(outFedFile.getPath());

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def main():
3333
parser.add_option("-c", "--config", dest="config_file_path", help="Path of JSON configuration file", metavar="FILEPATH")
3434
parser.add_option("--prop", dest="prop_file_path", help="Path of JSON property file [optional]", metavar="FILEPATH")
3535
parser.add_option("--cert", dest="cert_file_path", help="Path of JSON certificate configuration file [optional]", metavar="FILEPATH")
36+
parser.add_option("--cert-expiration", dest="cert_expiration_days", help="Check if certificates expire within the next days [optional]", metavar="DAYS")
37+
parser.add_option("--cert-config-update", dest="cert_config_update", help="Enable writing of info section for 'update' certificates within the configuration file [optional]", action="store_true")
3638
parser.add_option("--output-fed", dest="out_fed_file_path", help="Path of output deployment archive file (.fed) [optional]", metavar="FILEPATH")
3739
parser.add_option("--output-env", dest="out_env_file_path", help="Path of output environment archive file (.env) [optional]", metavar="FILEPATH")
3840
parser.add_option("-D", "--define", dest="sys_properties", help="Define a system property [multiple]", metavar="NAME:VALUE", action="append")
@@ -70,6 +72,12 @@ def main():
7072
if options.simulate:
7173
fed_config.enable_simulation_mode()
7274

75+
if options.cert_config_update:
76+
fed_config.enable_cert_config_update()
77+
78+
if options.cert_expiration_days:
79+
fed_config.set_cert_expiration_days(int(options.cert_expiration_days))
80+
7381
for name, value in sys_properties.items():
7482
print "INFO : System property %s" % (name)
7583
fed_config.set_system_properties(sys_properties)

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

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import os
33
from com.vordel.es.xes import PortableESPKFactory;
44
from java.text import SimpleDateFormat
5+
from java.util import Date
6+
from java.util.concurrent import TimeUnit
57

68
class FieldKey:
79
def __init__(self, entity_short_hand_key, field_name, field_index, field_type):
@@ -190,17 +192,38 @@ def get_password(self):
190192
return self.__password
191193

192194
class CertInfo:
193-
alias = None
194-
subject = None
195-
not_after = None
195+
__alias = None
196+
__subject = None
197+
__not_after = None
196198
def __init__(self, alias, subject, not_after):
197-
self.alias = alias
198-
self.subject = subject
199-
self.not_after = not_after
199+
self.__alias = alias
200+
self.__subject = subject
201+
self.__not_after = not_after
202+
203+
def get_alias(self):
204+
return self.__alias
205+
206+
def get_subject(self):
207+
return self.__subject
200208

201209
def get_info(self):
210+
return {"info": {"subject": self.__subject, "not_after": self.format_not_after() }}
211+
212+
def format_not_after(self):
213+
"""
214+
Formats the expiration date/time of the certificate.
215+
"""
202216
df = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX")
203-
return {"info": {"subject": self.subject, "not_after": df.format(self.not_after) }}
217+
return df.format(self.__not_after)
218+
219+
def expiration_in_days(self):
220+
"""
221+
Return the number of days until the certificate expires.
222+
If the certificate is already expired a negative number is returned.
223+
"""
224+
now = Date()
225+
diff = self.__not_after.getTime() - now.getTime()
226+
return TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS)
204227

205228
class CertConfig:
206229
__config_file_path = None
@@ -240,19 +263,19 @@ def set_cert_infos(self, cert_infos):
240263

241264
# set certificate infos
242265
for info in cert_infos:
243-
if info.alias in certificates:
244-
certificates[info.alias]["origin"] = info.get_info()
266+
if info.get_alias() in certificates:
267+
certificates[info.get_alias()]["origin"] = info.get_info()
245268
else:
246-
certificates[info.alias] = { "origin": info.get_info() }
269+
certificates[info.get_alias()] = { "origin": info.get_info() }
247270
return
248271

249272
def set_update_cert_infos(self, cert_infos):
250273
certificates = self.__config_json["certificates"]
251274

252275
for info in cert_infos:
253-
if info.alias in certificates:
254-
if "update" in certificates[info.alias]:
255-
certificates[info.alias]["update"].update(info.get_info())
276+
if info.get_alias() in certificates:
277+
if "update" in certificates[info.get_alias()]:
278+
certificates[info.get_alias()]["update"].update(info.get_info())
256279
return
257280

258281
def get_certificates(self):

0 commit comments

Comments
 (0)