Skip to content

Commit fed9f93

Browse files
committed
Merge branch 'RM-3344_key-capsule-expiry-configuration' into 'master'
RM-3344: Add key capsule expiry time parameter to open API client See merge request cdoc2/cdoc2-java-ref-impl!18
2 parents ae97c9d + 2d2aa11 commit fed9f93

File tree

13 files changed

+137
-76
lines changed

13 files changed

+137
-76
lines changed

cdoc2-cli/pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
<parent>
55
<artifactId>cdoc2</artifactId>
66
<groupId>ee.cyber.cdoc2</groupId>
7-
<version>1.2.0</version>
7+
<version>1.3.0-SNAPSHOT</version>
88
</parent>
99

1010
<artifactId>cdoc2-cli</artifactId>
11+
<version>1.2.0</version>
1112
<description>Command line utility to create/process CDOC2 files</description>
1213

1314
<properties>
@@ -41,7 +42,7 @@
4142
<dependency>
4243
<groupId>ee.cyber.cdoc2</groupId>
4344
<artifactId>cdoc2-lib</artifactId>
44-
<version>1.2.0</version>
45+
<version>1.3.0-SNAPSHOT</version>
4546
</dependency>
4647
</dependencies>
4748

cdoc2-client/pom.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
<parent>
55
<artifactId>cdoc2</artifactId>
66
<groupId>ee.cyber.cdoc2</groupId>
7-
<version>1.2.0</version>
7+
<version>1.3.0-SNAPSHOT</version>
88
</parent>
99

1010
<artifactId>cdoc2-client</artifactId>
11-
<version>1.3.0</version>
11+
<version>1.4.0-SNAPSHOT</version>
1212
<description>CDOC2 server client generation from openapi specification</description>
1313

1414
<properties>
@@ -19,7 +19,7 @@
1919

2020
<spotbugs-annotations.version>4.7.3</spotbugs-annotations.version>
2121
<!--info.version from cdoc2-openapi/cdoc2-key-capsules-openapi.yaml -->
22-
<cdoc2-key-capsules-openapi.version>2.0.0</cdoc2-key-capsules-openapi.version>
22+
<cdoc2-key-capsules-openapi.version>2.1.0-SNAPSHOT</cdoc2-key-capsules-openapi.version>
2323
<maven.repository.url>gitlab.ext.cyber.ee::::https://gitlab.ext.cyber.ee/api/v4/projects/39/packages/maven</maven.repository.url>
2424
</properties>
2525

@@ -178,6 +178,7 @@
178178
<outputDirectory>${project.build.directory}/openapi</outputDirectory>
179179
</artifactItem>
180180
</artifactItems>
181+
<useBaseVersion>true</useBaseVersion>
181182
</configuration>
182183
</execution>
183184
</executions>
@@ -218,7 +219,7 @@
218219
<dateLibrary>java8</dateLibrary>
219220
<enumUnknownDefaultCase>true</enumUnknownDefaultCase>
220221
<oas3>true</oas3>
221-
<useOptional>true</useOptional>
222+
<useOptional>false</useOptional>
222223
<bigDecimalAsString>true</bigDecimalAsString>
223224
<legacyDiscriminatorBehavior>false</legacyDiscriminatorBehavior>
224225
</configOptions>

cdoc2-client/src/main/java/ee/cyber/cdoc2/client/Cdoc2KeyCapsuleApiClient.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.security.KeyStoreException;
1414
import java.security.NoSuchAlgorithmException;
1515
import java.security.SecureRandom;
16+
import java.time.OffsetDateTime;
1617
import java.util.List;
1718
import java.util.Objects;
1819
import java.util.Optional;
@@ -26,11 +27,13 @@
2627
import org.slf4j.Logger;
2728
import org.slf4j.LoggerFactory;
2829

30+
2931
/**
3032
* Client for creating and getting CDOC2 key capsules from key server. Provides Builder to initialize mutual TLS
3133
* from PKCS11 (smart-card) or PKCS12 (software) key stores.
3234
*/
3335
public final class Cdoc2KeyCapsuleApiClient {
36+
3437
private static final Logger log = LoggerFactory.getLogger(Cdoc2KeyCapsuleApiClient.class);
3538

3639
public static final int DEFAULT_CONNECT_TIMEOUT_MS = 1000;
@@ -76,7 +79,7 @@ private Builder() {
7679
/**
7780
* Init server base url
7881
* @param url server base url, example https://host:8443
79-
* @return
82+
* @return client builder
8083
*/
8184
public Builder withBaseUrl(String url) {
8285
this.baseUrl = url;
@@ -86,7 +89,7 @@ public Builder withBaseUrl(String url) {
8689
/**
8790
* Client keystore used for mutual TLS
8891
* @param clientKS client key store containing client keys for mutual TLS or null, if mTLS is not used
89-
* @return
92+
* @return client builder
9093
*/
9194
public Builder withClientKeyStore(@Nullable KeyStore clientKS) {
9295
this.clientKeyStore = clientKS;
@@ -111,7 +114,7 @@ public Builder withClientKeyStoreProtectionParameter(KeyStore.ProtectionParamete
111114
* "passwd".toCharArray());
112115
*</code>
113116
* @param trustKS initialized trusted key store to be used by TLS
114-
* @return
117+
* @return client builder
115118
*/
116119
public Builder withTrustKeyStore(KeyStore trustKS) {
117120
this.trustKeyStore = trustKS;
@@ -172,7 +175,7 @@ protected void customizeClientBuilder(ClientBuilder clientBuilder) {
172175

173176
apiClient.setDebugging(debug);
174177
apiClient.addDefaultHeader("Accept", "application/json");
175-
apiClient.selectHeaderAccept(new String[]{"application/json"});
178+
apiClient.selectHeaderAccept("application/json");
176179

177180
apiClient.setUserAgent(userAgent);
178181

@@ -226,11 +229,21 @@ public static Builder builder() {
226229
}
227230

228231
/**
229-
* @param capsule
232+
* @param capsule key capsule
230233
* @return transactionId
231-
* @throws ApiException
234+
* @throws ApiException if capsule creation has failed
232235
*/
233236
public String createCapsule(Capsule capsule) throws ApiException {
237+
return createCapsule(capsule, null);
238+
}
239+
240+
/**
241+
* @param capsule key capsule
242+
* @param xExpiryTime capsule expiry time (optional)
243+
* @return transactionId
244+
* @throws ApiException if capsule creation has failed
245+
*/
246+
public String createCapsule(Capsule capsule, @Nullable OffsetDateTime xExpiryTime) throws ApiException {
234247

235248
Objects.requireNonNull(capsule);
236249
Objects.requireNonNull(capsule.getCapsuleType());
@@ -240,7 +253,7 @@ public String createCapsule(Capsule capsule) throws ApiException {
240253
Objects.requireNonNull(capsule.getRecipientId());
241254
Objects.requireNonNull(capsule.getEphemeralKeyMaterial());
242255

243-
ApiResponse<Void> response = capsulesApi.createCapsuleWithHttpInfo(capsule);
256+
ApiResponse<Void> response = capsulesApi.createCapsuleWithHttpInfo(capsule, xExpiryTime);
244257
String locationHeaderValue = null;
245258
if (response.getStatusCode() == 201
246259
&& response.getHeaders() != null
@@ -267,17 +280,16 @@ public String createCapsule(Capsule capsule) throws ApiException {
267280
}
268281

269282
/**
270-
*
271-
* @param id
283+
* @param transactionId transaction ID
272284
* @return Optional with value, if server returned 200 or empty Optional if 404
273285
* @throws ApiException if http response code is something else that 200 or 404
274286
*/
275-
public Optional<Capsule> getCapsule(String id) throws ApiException {
276-
if (id == null) {
287+
public Optional<Capsule> getCapsule(String transactionId) throws ApiException {
288+
if (transactionId == null) {
277289
throw new IllegalArgumentException("transactionId cannot be null");
278290
}
279291

280-
ApiResponse<Capsule> response = capsulesApi.getCapsuleByTransactionIdWithHttpInfo(id);
292+
ApiResponse<Capsule> response = capsulesApi.getCapsuleByTransactionIdWithHttpInfo(transactionId);
281293

282294
switch (response.getStatusCode()) {
283295
case 200:

cdoc2-lib/pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
<parent>
44
<artifactId>cdoc2</artifactId>
55
<groupId>ee.cyber.cdoc2</groupId>
6-
<version>1.2.0</version>
6+
<version>1.3.0-SNAPSHOT</version>
77
</parent>
88
<modelVersion>4.0.0</modelVersion>
99

1010
<artifactId>cdoc2-lib</artifactId>
11+
<version>1.3.0-SNAPSHOT</version>
1112
<description>CDOC2 creation and processing library</description>
1213

1314
<properties>
@@ -25,7 +26,7 @@
2526
<dependency>
2627
<groupId>ee.cyber.cdoc2</groupId>
2728
<artifactId>cdoc2-client</artifactId>
28-
<version>1.3.0</version>
29+
<version>1.4.0-SNAPSHOT</version>
2930
</dependency>
3031

3132
<dependency>

cdoc2-lib/src/main/java/ee/cyber/cdoc2/client/EcCapsuleClientImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public String storeSenderKey(ECPublicKey receiverKey, ECPublicKey senderKey) thr
4747
.recipientId(ECKeys.encodeEcPubKeyForTls(curve, receiverKey))
4848
.ephemeralKeyMaterial(ECKeys.encodeEcPubKeyForTls(curve, senderKey));
4949

50-
return keyCapsulesClient.storeCapsule(capsule);
50+
return keyCapsulesClient.storeCapsule(capsule, null);
5151
}
5252

5353
@Override
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
package ee.cyber.cdoc2.client;
22

3+
import jakarta.annotation.Nullable;
4+
35
import ee.cyber.cdoc2.client.model.Capsule;
6+
7+
import java.time.OffsetDateTime;
48
import java.util.Optional;
59

10+
611
/**
712
* Generic capsule client
813
*/
914
public interface KeyCapsuleClient extends ServerClient {
1015

1116
String storeCapsule(Capsule capsule) throws ExtApiException;
1217

18+
String storeCapsule(Capsule capsule, @Nullable OffsetDateTime xExpiryTime) throws ExtApiException;
19+
1320
Optional<Capsule> getCapsule(String id) throws ExtApiException;
21+
1422
}

0 commit comments

Comments
 (0)