Skip to content

Commit 1d4d302

Browse files
committed
Merge branch 'main' into develop
# Conflicts: # pom.xml # src/main/java/com/siemens/pki/cmpclientcomponent/main/CmpClient.java # src/main/java/com/siemens/pki/cmpracomponent/cryptoservices/AlgorithmHelper.java # src/main/java/com/siemens/pki/cmpracomponent/cryptoservices/CmsEncryptorBase.java # src/main/java/com/siemens/pki/cmpracomponent/cryptoservices/DataSignVerifier.java # src/main/java/com/siemens/pki/cmpracomponent/cryptoservices/DataSigner.java # src/main/java/com/siemens/pki/cmpracomponent/cryptoservices/TrustCredentialAdapter.java # src/main/java/com/siemens/pki/cmpracomponent/msggeneration/PkiMessageGenerator.java # src/main/java/com/siemens/pki/cmpracomponent/msgvalidation/MessageBodyValidator.java # src/main/java/com/siemens/pki/cmpracomponent/persistency/PersistencyContext.java # src/main/java/com/siemens/pki/cmpracomponent/persistency/PersistencyContextManager.java # src/main/java/com/siemens/pki/cmpracomponent/persistency/TransactionStateTracker.java # src/test/java/com/siemens/pki/cmpracomponent/test/framework/TestCertUtility.java
2 parents 43c4c58 + d6b53f8 commit 1d4d302

39 files changed

+1670
-559
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ feat: implement configurable recipient
128128

129129
fix: extension processing in CMP client
130130

131-
### 4.1.0 (Dec 14 2023)
131+
### 4.1.0 (Dec 14 2024)
132132

133133
feat: revocation checking via inventory interface
134134

pom.xml

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
<groupId>com.siemens.pki</groupId>
99
<artifactId>CmpRaComponent</artifactId>
1010
<packaging>jar</packaging>
11-
<version>4.3.0-SNAPSHOT</version>
11+
<version>4.2.0_PQ</version>
1212
<properties>
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1414
<parent.basedir>.</parent.basedir>
15-
<spotless.version>3.0.0</spotless.version>
16-
<jacoco.version>0.8.14</jacoco.version>
15+
<spotless.version>2.46.1</spotless.version>
16+
<jacoco.version>0.8.13</jacoco.version>
1717
<source.version>3.3.1</source.version>
18-
<maven.compiler.source>25</maven.compiler.source>
19-
<maven.compiler.target>25</maven.compiler.target>
20-
<maven-failsafe-plugin.version>3.5.4</maven-failsafe-plugin.version>
18+
<maven.compiler.source>11</maven.compiler.source>
19+
<maven.compiler.target>11</maven.compiler.target>
20+
<maven-failsafe-plugin.version>3.0.0-M3</maven-failsafe-plugin.version>
2121
<maven-site-plugin.version>3.8.2</maven-site-plugin.version>
2222
<sonar.organization>siemens</sonar.organization>
2323
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
@@ -44,7 +44,7 @@
4444
<plugin>
4545
<groupId>org.apache.maven.plugins</groupId>
4646
<artifactId>maven-dependency-plugin</artifactId>
47-
<version>3.9.0</version>
47+
<version>3.8.1</version>
4848
<executions>
4949
<execution>
5050
<id>copy-dependencies</id>
@@ -83,7 +83,7 @@
8383
<plugin>
8484
<groupId>org.apache.maven.plugins</groupId>
8585
<artifactId>maven-surefire-plugin</artifactId>
86-
<version>3.5.4</version>
86+
<version>3.5.3</version>
8787
<configuration>
8888
<excludes>
8989
<exclude>**/local/**</exclude>
@@ -93,7 +93,7 @@
9393
<plugin>
9494
<groupId>org.apache.maven.plugins</groupId>
9595
<artifactId>maven-javadoc-plugin</artifactId>
96-
<version>3.12.0</version>
96+
<version>3.11.3</version>
9797
<executions>
9898
<execution>
9999
<id>javadoc-jar</id>
@@ -118,7 +118,7 @@
118118
<include>src/test/java/**/*.java</include>
119119
</includes>
120120
<palantirJavaFormat>
121-
<version>2.80.0</version>
121+
<version>2.39.0</version>
122122
</palantirJavaFormat>
123123
<importOrder />
124124
<removeUnusedImports />
@@ -130,7 +130,7 @@
130130
<plugin>
131131
<groupId>org.owasp</groupId>
132132
<artifactId>dependency-check-maven</artifactId>
133-
<version>12.1.8</version>
133+
<version>12.1.3</version>
134134
<executions>
135135
<execution>
136136
<goals>
@@ -236,12 +236,12 @@
236236
<dependency>
237237
<groupId>org.bouncycastle</groupId>
238238
<artifactId>bcprov-jdk18on</artifactId>
239-
<version>1.82</version>
239+
<version>1.81</version>
240240
</dependency>
241241
<dependency>
242242
<groupId>org.bouncycastle</groupId>
243243
<artifactId>bcpkix-jdk18on</artifactId>
244-
<version>1.82</version>
244+
<version>1.81</version>
245245
</dependency>
246246
<dependency>
247247
<groupId>org.slf4j</groupId>
@@ -251,12 +251,17 @@
251251
<dependency>
252252
<groupId>com.fasterxml.jackson.core</groupId>
253253
<artifactId>jackson-databind</artifactId>
254-
<version>2.19.1</version>
254+
<version>2.20.0</version>
255255
</dependency>
256256
<dependency>
257257
<groupId>com.fasterxml.jackson.dataformat</groupId>
258258
<artifactId>jackson-dataformat-yaml</artifactId>
259-
<version>2.19.1</version>
259+
<version>2.20.0</version>
260+
</dependency>
261+
<dependency>
262+
<groupId>org.jacoco</groupId>
263+
<artifactId>jacoco-maven-plugin</artifactId>
264+
<version>${jacoco.version}</version>
260265
</dependency>
261266
<dependency>
262267
<!-- Indirect dependency of jacoco-maven-plugin. We add this one

src/main/java/com/siemens/pki/cmpclientcomponent/main/ClientRequestHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class ValidatorAndProtector {
7272

7373
private final MessageHeaderValidator headerValidator;
7474

75-
private final ValidatorIF<String> bodyValidator;
75+
private final ValidatorIF<Boolean> bodyValidator;
7676

7777
private final VerificationContext inputVerification;
7878

src/main/java/com/siemens/pki/cmpclientcomponent/main/CmpClient.java

Lines changed: 67 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2025 Siemens AG
2+
* Copyright (c) 2023 Siemens AG
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may
55
* not use this file except in compliance with the License.
@@ -40,12 +40,10 @@
4040
import com.siemens.pki.cmpracomponent.protection.ProtectionProvider;
4141
import com.siemens.pki.cmpracomponent.protection.SignatureBasedProtection;
4242
import com.siemens.pki.cmpracomponent.util.MessageDumper;
43-
import java.io.ByteArrayInputStream;
4443
import java.io.IOException;
4544
import java.security.KeyPair;
4645
import java.security.PrivateKey;
4746
import java.security.cert.CertificateException;
48-
import java.security.cert.CertificateFactory;
4947
import java.security.cert.X509CRL;
5048
import java.security.cert.X509Certificate;
5149
import java.util.ArrayList;
@@ -63,6 +61,7 @@
6361
import org.bouncycastle.asn1.cmp.CMPObjectIdentifiers;
6462
import org.bouncycastle.asn1.cmp.CRLSource;
6563
import org.bouncycastle.asn1.cmp.CRLStatus;
64+
import org.bouncycastle.asn1.cmp.CertOrEncCert;
6665
import org.bouncycastle.asn1.cmp.CertRepMessage;
6766
import org.bouncycastle.asn1.cmp.CertReqTemplateContent;
6867
import org.bouncycastle.asn1.cmp.CertResponse;
@@ -76,6 +75,7 @@
7675
import org.bouncycastle.asn1.cmp.PKIStatus;
7776
import org.bouncycastle.asn1.cmp.RevRepContent;
7877
import org.bouncycastle.asn1.cmp.RootCaKeyUpdateContent;
78+
import org.bouncycastle.asn1.cms.ContentInfo;
7979
import org.bouncycastle.asn1.cms.EnvelopedData;
8080
import org.bouncycastle.asn1.crmf.AttributeTypeAndValue;
8181
import org.bouncycastle.asn1.crmf.CertId;
@@ -89,17 +89,28 @@
8989
import org.bouncycastle.asn1.x509.GeneralNames;
9090
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
9191
import org.bouncycastle.asn1.x509.Time;
92+
import org.bouncycastle.cms.CMSEnvelopedData;
93+
import org.bouncycastle.cms.CMSException;
94+
import org.bouncycastle.cms.RecipientInformation;
95+
import org.bouncycastle.cms.RecipientInformationStore;
96+
import org.bouncycastle.cms.jcajce.JceKEMEnvelopedRecipient;
9297
import org.bouncycastle.pkcs.PKCS10CertificationRequest;
9398
import org.slf4j.Logger;
9499
import org.slf4j.LoggerFactory;
95100

96-
/** a CMP client implementation */
101+
/**
102+
* a CMP client implementation
103+
*
104+
*/
97105
public class CmpClient
98106
implements CrlUpdateRetrievalHandler,
99107
GetCaCertificatesHandler,
100108
GetCertificateRequestTemplateHandler,
101109
GetRootCaCertificateUpdateHandler {
102-
/** result of an enrollment transaction */
110+
/**
111+
* result of an enrollment transaction
112+
*
113+
*/
103114
public interface EnrollmentResult {
104115
/**
105116
* get enrolled certificate
@@ -109,7 +120,8 @@ public interface EnrollmentResult {
109120
X509Certificate getEnrolledCertificate();
110121

111122
/**
112-
* get certificate chain (1st intermediate certificate up to root certificate) of the enrolled certificate
123+
* get certificate chain (1st intermediate certificate up to root certificate)
124+
* of the enrolled certificate
113125
*
114126
* @return the certificate chain of the enrolled certificate
115127
*/
@@ -134,11 +146,17 @@ public interface EnrollmentResult {
134146
/**
135147
* ctor
136148
*
137-
* @param certProfile certificate profile to be used for enrollment. <code>null</code> if no certificate profile
138-
* should be used.
139-
* @param upstreamExchange the {@link UpstreamExchange} interface implemented by the wrapping application.
140-
* @param upstreamConfiguration configuration for the upstream CMP interface towards the CA
141-
* @param clientContext client specific configuration
149+
* @param certProfile certificate profile to be used for enrollment.
150+
* <code>null</code> if no certificate profile
151+
* should be used.
152+
*
153+
* @param upstreamExchange the {@link UpstreamExchange} interface
154+
* implemented by the wrapping application.
155+
*
156+
* @param upstreamConfiguration configuration for the upstream CMP interface
157+
* towards the CA
158+
*
159+
* @param clientContext client specific configuration
142160
* @throws Exception in case of error
143161
*/
144162
public CmpClient(
@@ -180,7 +198,9 @@ private Extension fetchSubjectAlternativeName(final X509Certificate cert) {
180198
return ret.length > 0 ? ret[0] : null;
181199
}
182200

183-
/** invoke a Get CA certificates GENM request {@inheritDoc} */
201+
/**
202+
* invoke a Get CA certificates GENM request {@inheritDoc}
203+
*/
184204
@Override
185205
public List<X509Certificate> getCaCertificates() {
186206
final PKIBody requestBody = new PKIBody(
@@ -205,7 +225,9 @@ public List<X509Certificate> getCaCertificates() {
205225
return null;
206226
}
207227

208-
/** invoke a Get certificate request template GENM request {@inheritDoc} */
228+
/**
229+
* invoke a Get certificate request template GENM request {@inheritDoc}
230+
*/
209231
@Override
210232
public byte[] getCertificateRequestTemplate() {
211233
final PKIBody requestBody = new PKIBody(
@@ -283,12 +305,11 @@ public List<X509CRL> getCrls(
283305
if (infoValue == null) {
284306
return null;
285307
}
286-
final CertificateFactory certificateFactory = CertUtility.getCertificateFactory();
287308
final ASN1Sequence crls = ASN1Sequence.getInstance(infoValue);
288309
final List<X509CRL> ret = new ArrayList<>(crls.size());
289310
for (final ASN1Encodable aktCrl : crls) {
290-
ret.add((X509CRL) certificateFactory.generateCRL(new ByteArrayInputStream(
291-
aktCrl.toASN1Primitive().getEncoded())));
311+
ret.add(CertUtility.parseCrl(
312+
aktCrl.toASN1Primitive().getEncoded()));
292313
}
293314
return ret;
294315
}
@@ -302,7 +323,9 @@ public List<X509CRL> getCrls(
302323
return null;
303324
}
304325

305-
/** invoke a Get root CA certificate update GENM request {@inheritDoc} */
326+
/**
327+
* invoke a Get root CA certificate update GENM request {@inheritDoc}
328+
*/
306329
@Override
307330
public RootCaCertificateUpdateResponse getRootCaCertificateUpdate(final X509Certificate oldRootCaCertificate) {
308331

@@ -479,8 +502,33 @@ public EnrollmentResult invokeEnrollment() {
479502
return null;
480503
}
481504
final CertifiedKeyPair certifiedKeyPair = certResponse.getCertifiedKeyPair();
482-
final CMPCertificate enrolledCertificate =
483-
certifiedKeyPair.getCertOrEncCert().getCertificate();
505+
CertOrEncCert certOrEncCert = certifiedKeyPair.getCertOrEncCert();
506+
CMPCertificate enrolledCertificate = null;
507+
if (certOrEncCert.hasEncryptedCertificate()) {
508+
JceKEMEnvelopedRecipient jkr = new JceKEMEnvelopedRecipient(certificateKeypair.getPrivate());
509+
EnvelopedData envelopedData =
510+
(EnvelopedData) certOrEncCert.getEncryptedCert().getValue();
511+
final CMSEnvelopedData cmsEnvelopedData = new CMSEnvelopedData(
512+
new ContentInfo(envelopedData.getEncryptedContentInfo().getContentType(), envelopedData));
513+
final RecipientInformationStore recipients = cmsEnvelopedData.getRecipientInfos();
514+
for (RecipientInformation recipient : recipients.getRecipients()) {
515+
// in case of multiple recipients we try until we find a
516+
// recipient fitting our key
517+
try {
518+
byte[] content = recipient.getContent(jkr);
519+
enrolledCertificate = CMPCertificate.getInstance(content);
520+
break;
521+
} catch (CMSException ex) {
522+
LOGGER.debug("unable to decrypt recipient, try next", ex);
523+
}
524+
}
525+
} else {
526+
enrolledCertificate = certOrEncCert.getCertificate();
527+
}
528+
if (enrolledCertificate == null) {
529+
LOGGER.error("could not extract enrolled certificate from response");
530+
return null;
531+
}
484532

485533
if (enrollmentType != PKIBody.TYPE_P10_CERT_REQ && enrolledPrivateKey == null) {
486534
// central key generation in place, decrypt private key

src/main/java/com/siemens/pki/cmpracomponent/configuration/SignatureCredentialContext.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ public interface SignatureCredentialContext extends CredentialContext {
4343
*/
4444
PrivateKey getPrivateKey();
4545

46+
/**
47+
* provide the alternative private key for the end certificate, see X.509 (2019)
48+
* section 9.8
49+
*
50+
* @return private key for first certificate returned by
51+
* {@link #getCertificateChain()}
52+
*/
53+
default PrivateKey getAlternativePrivateKey() {
54+
return null;
55+
}
56+
4657
/**
4758
* provide name or OID of signature algorithm, see <a
4859
* href=https://docs.oracle.com/en/java/javase/11/docs/specs/security/standard-names.html#signature-algorithms>Signature

0 commit comments

Comments
 (0)