Skip to content

Commit 8d2078f

Browse files
committed
Merge remote-tracking branch
'origin/issue/395_New_D-Trust_Server_Root_CAs' into develop_2
2 parents e48bd40 + e07f5ee commit 8d2078f

File tree

5 files changed

+91
-15
lines changed

5 files changed

+91
-15
lines changed

dsf-maven/dsf-maven-plugin/src/main/java/dev/dsf/maven/ca/DefaultCaFilesGenerator.java

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,18 @@ private static final class X509CertificateHolder
5959
{
6060
final X509Certificate certificate;
6161
final Predicate<String> isClientOnly;
62+
final Predicate<String> isServerOnly;
6263
final JcaX509CertificateHolder certificateHolder;
6364

6465
final List<X509CertificateHolder> children = new ArrayList<>();
6566
X509CertificateHolder parent;
6667

67-
X509CertificateHolder(X509Certificate certificate, Predicate<String> isClientOnly)
68+
X509CertificateHolder(X509Certificate certificate, Predicate<String> isClientOnly,
69+
Predicate<String> isServerOnly)
6870
{
6971
this.certificate = certificate;
7072
this.isClientOnly = isClientOnly;
73+
this.isServerOnly = isServerOnly;
7174

7275
try
7376
{
@@ -106,6 +109,12 @@ boolean isClientOnly()
106109
: getChildren().stream().allMatch(X509CertificateHolder::isClientOnly);
107110
}
108111

112+
boolean isServerOnly()
113+
{
114+
return getChildren().isEmpty() ? isServerOnly.test(getSubjectCommonName())
115+
: getChildren().stream().allMatch(X509CertificateHolder::isServerOnly);
116+
}
117+
109118
X500Name getSubject()
110119
{
111120
return certificateHolder.getSubject();
@@ -151,22 +160,26 @@ ZonedDateTime getNotBefore()
151160
private final Path projectBasedir;
152161
private final Path certFolder;
153162
private final List<String> clientOnlyCaCommonNames;
163+
private final List<String> serverOnlyCaCommonNames;
154164

155-
public DefaultCaFilesGenerator(Path projectBasedir, Path certFolder, List<String> clientOnlyCaCommonNames)
156-
throws MojoExecutionException
165+
public DefaultCaFilesGenerator(Path projectBasedir, Path certFolder, List<String> clientOnlyCaCommonNames,
166+
List<String> serverOnlyCaCommonNames) throws MojoExecutionException
157167
{
158168
this.projectBasedir = projectBasedir;
159169
this.certFolder = certFolder;
160170
this.clientOnlyCaCommonNames = clientOnlyCaCommonNames;
171+
this.serverOnlyCaCommonNames = serverOnlyCaCommonNames;
161172

162173
if (projectBasedir == null)
163174
throw new MojoExecutionException("projectBasedir not defined");
164175
if (certFolder == null)
165176
throw new MojoExecutionException("certFolder not defined");
166177
if (!Files.isReadable(certFolder))
167178
throw new MojoExecutionException("certFolder '" + certFolder.toString() + "' not readable");
168-
if (clientOnlyCaCommonNames == null || clientOnlyCaCommonNames.isEmpty())
169-
throw new MojoExecutionException("clientOnlyCaCommonNames not defined or empty");
179+
if (clientOnlyCaCommonNames == null)
180+
throw new MojoExecutionException("clientOnlyCaCommonNames not defined");
181+
if (serverOnlyCaCommonNames == null)
182+
throw new MojoExecutionException("serverOnlyCaCommonNames not defined");
170183
}
171184

172185
public void createFiles(Stream<Path> clientIssuingCas, Stream<Path> clientCaChains, Stream<Path> serverRootCas)
@@ -186,7 +199,7 @@ public void createFiles(Stream<Path> clientIssuingCas, Stream<Path> clientCaChai
186199
if (iToWrite.isEmpty() && cToWrite.isEmpty() && sWrite.isEmpty())
187200
return;
188201

189-
List<X509CertificateHolder> certificates = readCertificates(certFolder, clientOnlyCaCommonNames);
202+
List<X509CertificateHolder> certificates = readCertificates();
190203

191204
try
192205
{
@@ -215,14 +228,13 @@ private Predicate<Path> isDirectory(String logMessage)
215228
};
216229
}
217230

218-
private List<X509CertificateHolder> readCertificates(Path certFolder, List<String> clientOnlyCaCommonNames)
219-
throws IOException
231+
private List<X509CertificateHolder> readCertificates() throws IOException
220232
{
221233
List<X509CertificateHolder> certificates = new ArrayList<>();
222234
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(certFolder,
223235
entry -> entry.getFileName().toString().endsWith(".pem")))
224236
{
225-
directoryStream.forEach(readCertificate(certificates, clientOnlyCaCommonNames));
237+
directoryStream.forEach(readCertificate(certificates));
226238
}
227239

228240
Map<X500Name, X509CertificateHolder> certificatesBySubject = certificates.stream()
@@ -232,16 +244,15 @@ private List<X509CertificateHolder> readCertificates(Path certFolder, List<Strin
232244
return certificates;
233245
}
234246

235-
private Consumer<? super Path> readCertificate(List<X509CertificateHolder> certificates,
236-
List<String> clientOnlyCaCommonNames)
247+
private Consumer<? super Path> readCertificate(List<X509CertificateHolder> certificates)
237248
{
238249
return file ->
239250
{
240251
try
241252
{
242253
logger.info("Reading certificate from {}", projectBasedir.relativize(file));
243254
X509CertificateHolder certificate = new X509CertificateHolder(PemReader.readCertificate(file),
244-
clientOnlyCaCommonNames::contains);
255+
clientOnlyCaCommonNames::contains, serverOnlyCaCommonNames::contains);
245256

246257
if (!certificate.isCa())
247258
throw new RuntimeException("Certificate in " + file.toString() + " is not a CA certificate");
@@ -274,6 +285,7 @@ private Consumer<? super Path> readCertificate(List<X509CertificateHolder> certi
274285
private Consumer<Path> writeClientIssuingCas(List<X509CertificateHolder> certificates, String logMessage)
275286
{
276287
List<X509CertificateHolder> issuingCas = certificates.stream().filter(X509CertificateHolder::isIssuingCa)
288+
.filter(Predicate.not(X509CertificateHolder::isServerOnly))
277289
.sorted(Comparator.comparing(X509CertificateHolder::getSubjectCommonName)).toList();
278290

279291
return folder -> issuingCas.forEach(writeCert(folder, logMessage));
@@ -282,6 +294,7 @@ private Consumer<Path> writeClientIssuingCas(List<X509CertificateHolder> certifi
282294
private Consumer<Path> writeClientCaChains(List<X509CertificateHolder> certificates, String logMessage)
283295
{
284296
List<X509CertificateHolder> caChains = certificates.stream().filter(X509CertificateHolder::isRoot)
297+
.filter(Predicate.not(X509CertificateHolder::isServerOnly))
285298
.sorted(Comparator.comparing(X509CertificateHolder::getSubjectCommonName)).flatMap(childern()).toList();
286299

287300
return folder -> caChains.forEach(writeCert(folder, logMessage));

dsf-maven/dsf-maven-plugin/src/main/java/dev/dsf/maven/ca/GenerateDefaultCaFilesMojo.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public class GenerateDefaultCaFilesMojo extends AbstractMojo
4545
@Parameter(property = "dsf.clientOnlyCaCommonNames", required = true)
4646
private List<String> clientOnlyCaCommonNames;
4747

48+
@Parameter(property = "dsf.serverOnlyCaCommonNames", required = true)
49+
private List<String> serverOnlyCaCommonNames;
50+
4851
@Parameter(property = "dsf.clientIssuingCas", required = true)
4952
private List<File> clientIssuingCas;
5053

@@ -60,15 +63,16 @@ public void execute() throws MojoExecutionException, MojoFailureException
6063
getLog().debug("projectBasedir: " + projectBasedir);
6164
getLog().debug("certFolder: " + certFolder);
6265
getLog().debug("clientOnlyCaCommonNames: " + clientOnlyCaCommonNames);
66+
getLog().debug("serverOnlyCaCommonNames: " + serverOnlyCaCommonNames);
6367
getLog().debug("clientIssuingCas: " + clientIssuingCas);
6468
getLog().debug("clientCaChains: " + clientCaChains);
6569
getLog().debug("serverRootCas: " + serverRootCas);
6670

6771
try
6872
{
69-
new DefaultCaFilesGenerator(projectBasedir.toPath(), certFolder.toPath(), clientOnlyCaCommonNames)
70-
.createFiles(clientIssuingCas.stream().map(File::toPath), clientCaChains.stream().map(File::toPath),
71-
serverRootCas.stream().map(File::toPath));
73+
new DefaultCaFilesGenerator(projectBasedir.toPath(), certFolder.toPath(), clientOnlyCaCommonNames,
74+
serverOnlyCaCommonNames).createFiles(clientIssuingCas.stream().map(File::toPath),
75+
clientCaChains.stream().map(File::toPath), serverRootCas.stream().map(File::toPath));
7276
}
7377
catch (IOException e)
7478
{

pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,14 @@
858858
HARICA S/MIME RSA
859859
</clientOnlyCaCommonName>
860860
</clientOnlyCaCommonNames>
861+
<serverOnlyCaCommonNames>
862+
<serverOnlyCaCommonName>
863+
D-TRUST BR Root CA 1 2020
864+
</serverOnlyCaCommonName>
865+
<serverOnlyCaCommonName>
866+
D-TRUST BR Root CA 2 2023
867+
</serverOnlyCaCommonName>
868+
</serverOnlyCaCommonNames>
861869
</configuration>
862870
</plugin>
863871
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIC2zCCAmCgAwIBAgIQfMmPK4TX3+oPyWWa00tNljAKBggqhkjOPQQDAzBIMQsw
3+
CQYDVQQGEwJERTEVMBMGA1UEChMMRC1UcnVzdCBHbWJIMSIwIAYDVQQDExlELVRS
4+
VVNUIEJSIFJvb3QgQ0EgMSAyMDIwMB4XDTIwMDIxMTA5NDUwMFoXDTM1MDIxMTA5
5+
NDQ1OVowSDELMAkGA1UEBhMCREUxFTATBgNVBAoTDEQtVHJ1c3QgR21iSDEiMCAG
6+
A1UEAxMZRC1UUlVTVCBCUiBSb290IENBIDEgMjAyMDB2MBAGByqGSM49AgEGBSuB
7+
BAAiA2IABMbLxyjR+4T1mu9CFCDhQ2tuda38KwOE1HaTJddZO0Flax7mNCq7dPYS
8+
zuht56vkPE4/RAiLzRZxy7+SmfSk1zxQVFKQhYN4lGdnoxwJGT11NIXe7WB9xwy0
9+
QVK5buXuQqOCAQ0wggEJMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFHOREKv/
10+
VbNafAkl1bK6CKBrqx9tMA4GA1UdDwEB/wQEAwIBBjCBxgYDVR0fBIG+MIG7MD6g
11+
PKA6hjhodHRwOi8vY3JsLmQtdHJ1c3QubmV0L2NybC9kLXRydXN0X2JyX3Jvb3Rf
12+
Y2FfMV8yMDIwLmNybDB5oHegdYZzbGRhcDovL2RpcmVjdG9yeS5kLXRydXN0Lm5l
13+
dC9DTj1ELVRSVVNUJTIwQlIlMjBSb290JTIwQ0ElMjAxJTIwMjAyMCxPPUQtVHJ1
14+
c3QlMjBHbWJILEM9REU/Y2VydGlmaWNhdGVyZXZvY2F0aW9ubGlzdDAKBggqhkjO
15+
PQQDAwNpADBmAjEAlJAtE/rhY/hhY+ithXhUkZy4kzg+GkHaQBZTQgjKL47xPoFW
16+
wKrY7RjEsK70PvomAjEA8yjixtsrmfu3Ubgko6SUeho/5jbiA1czijDLgsfWFBHV
17+
dWNbFJWcHwHP2NVypw87
18+
-----END CERTIFICATE-----
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIFqTCCA5GgAwIBAgIQczswBEhb2U14LnNLyaHcZjANBgkqhkiG9w0BAQ0FADBI
3+
MQswCQYDVQQGEwJERTEVMBMGA1UEChMMRC1UcnVzdCBHbWJIMSIwIAYDVQQDExlE
4+
LVRSVVNUIEJSIFJvb3QgQ0EgMiAyMDIzMB4XDTIzMDUwOTA4NTYzMVoXDTM4MDUw
5+
OTA4NTYzMFowSDELMAkGA1UEBhMCREUxFTATBgNVBAoTDEQtVHJ1c3QgR21iSDEi
6+
MCAGA1UEAxMZRC1UUlVTVCBCUiBSb290IENBIDIgMjAyMzCCAiIwDQYJKoZIhvcN
7+
AQEBBQADggIPADCCAgoCggIBAK7/CVmRgApKaOYkP7in5Mg6CjoWzckjYaCTcfKr
8+
i3OPoGdlYNJUa2NRb0kz4HIHE304zQaSBylSa053bATTlfrdTIzZXcFhfUvnKLNE
9+
gXtRr90zsWh81k5M/itoucpmacTsXld/9w3HnDY25QdgrMBM6ghs7wZ8T1soegj8
10+
k12b9py0i4a6Ibn08OhZWiihNIQaJZG2tY/vsvmA+vk9PBFy2OMvhnbFeSzBqZCT
11+
Rphny4NqoFAjpzv2gTng7fC5v2Xx2Mt6++9zA84A9H3X4F07ZrjcjrqDy4d2A/wl
12+
2ecjbwb9Z/Pg/4S8R7+1FhhGaRTMBffb00msa8yr5LULQyReS2tNZ9/WtT5PeB+U
13+
cSTq3nD88ZP+npNa5JRal1QMNXtfbO4AHyTsA7oC9Xb0n9Sa7YUsOCIvx9gvdhFP
14+
/Wxc6PWOJ4d/GUohR5AdeY0cW/jPSoXk7bNbjb7EZChdQcRurDh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