Skip to content

Commit 049a935

Browse files
Gematik-EntwicklungPhyliac
authored andcommitted
R2.1.5
1 parent c970d93 commit 049a935

37 files changed

Lines changed: 828 additions & 75 deletions

File tree

ReleaseNotes.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22

33
# Release Notes popp-sample-code
44

5-
## Release 2.1.4
5+
## Release 2.1.5
66

77
### Known Issues
88
- If your eGK has an older CVCA you may get problems while testing with the RÍSE PoPP-Service
99
- Standard-Kartenleser with Docker is not supported in this release, we will fix this in an upcoming release
1010

1111
### changed
1212

13-
- Introduce static key id for signing PoPP token and JWKS endpoint
13+
- Updated ZETA version to 0.4.2
14+
- Removed static key id for signing PoPP token and JWKS endpoint, instead we calculate the correct key id now
15+
16+
## Release 2.1.4
1417

18+
### changed
19+
20+
- Introduce static key id for signing PoPP token and JWKS endpoint
1521

1622
## Release 2.1.3
1723

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</parent>
88
<groupId>de.gematik.refpopp</groupId>
99
<artifactId>popp-example-impl-global</artifactId>
10-
<version>2.1.4</version>
10+
<version>2.1.5</version>
1111
<packaging>pom</packaging>
1212
<name>popp-sample-code</name>
1313
<description>PoPP - example implementation</description>
@@ -91,7 +91,7 @@
9191
<version.spotless-maven-plugin>3.4.0</version.spotless-maven-plugin>
9292
<version.spotless.google-java-format>1.27.0</version.spotless.google-java-format>
9393
<version.spring-boot-maven-plugin>3.3.2</version.spring-boot-maven-plugin>
94-
<version.zeta-sdk-jvm>0.2.12</version.zeta-sdk-jvm>
94+
<version.zeta-sdk-jvm>0.4.2</version.zeta-sdk-jvm>
9595
<jackson-2-bom.version>2.21.1</jackson-2-bom.version>
9696
<jackson-bom.version>3.1.0</jackson-bom.version>
9797
<mockito.agent.jar>${settings.localRepository}/org/mockito/mockito-core/${mockito.version}/mockito-core-${mockito.version}.jar</mockito.agent.jar>

popp-client/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
<parent>
88
<groupId>de.gematik.refpopp</groupId>
99
<artifactId>popp-example-impl-global</artifactId>
10-
<version>2.1.4</version>
10+
<version>2.1.5</version>
1111
<relativePath>../pom.xml</relativePath>
1212
</parent>
1313

1414
<artifactId>popp-client</artifactId>
15-
<version>2.1.4</version>
15+
<version>2.1.5</version>
1616
<packaging>jar</packaging>
1717

1818
<name>popp-client</name>

popp-client/src/main/java/de/gematik/refpopp/popp_client/client/SecureWebSocketClient.java

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import de.gematik.zeta.sdk.WsClientExtension;
3232
import de.gematik.zeta.sdk.ZetaSdk;
3333
import de.gematik.zeta.sdk.ZetaSdkClient;
34-
import de.gematik.zeta.sdk.attestation.model.ClientSelfAssessment;
34+
import de.gematik.zeta.sdk.attestation.model.AttestationConfig;
3535
import de.gematik.zeta.sdk.attestation.model.PlatformProductId;
3636
import de.gematik.zeta.sdk.authentication.AuthConfig;
3737
import de.gematik.zeta.sdk.authentication.SubjectTokenProvider;
@@ -46,8 +46,11 @@
4646
import java.util.HashMap;
4747
import java.util.List;
4848
import java.util.Map;
49+
import java.util.concurrent.CountDownLatch;
4950
import java.util.concurrent.ExecutorService;
5051
import java.util.concurrent.Executors;
52+
import java.util.concurrent.TimeUnit;
53+
import java.util.concurrent.atomic.AtomicReference;
5154
import kotlin.Unit;
5255
import lombok.extern.slf4j.Slf4j;
5356
import org.java_websocket.handshake.ServerHandshake;
@@ -68,9 +71,11 @@ public class SecureWebSocketClient {
6871
private final boolean disableServerValidation;
6972
private final URI serverUri;
7073
private final ZetaSdkClient zetaSdk;
71-
private ExecutorService pool;
72-
private WsClientExtension.WsSession session;
74+
private final ExecutorService pool;
75+
private final CountDownLatch sessionReady = new CountDownLatch(1);
76+
private final AtomicReference<WsClientExtension.WsSession> session = new AtomicReference<>();
7377
private final Map<String, Object> sessionMetadata;
78+
private final WsClientWrapper wsClientWrapper;
7479

7580
@Autowired
7681
public SecureWebSocketClient(
@@ -79,7 +84,8 @@ public SecureWebSocketClient(
7984
@Value("${zeta.authentication.smb.keyfile}") final String keyfile,
8085
@Value("${zeta.authentication.smb.alias}") final String alias,
8186
@Value("${zeta.authentication.smb.password}") final String password,
82-
@Value("${zeta.client.disableServerValidation}") final boolean disableServerValidation) {
87+
@Value("${zeta.client.disableServerValidation}") final boolean disableServerValidation,
88+
final WsClientWrapper wsClientWrapper) {
8389
this.serverUri = serverUri;
8490
this.eventPublisher = eventPublisher;
8591
this.pool = Executors.newFixedThreadPool(1);
@@ -88,6 +94,7 @@ public SecureWebSocketClient(
8894
this.alias = alias;
8995
this.password = password;
9096
this.disableServerValidation = disableServerValidation;
97+
this.wsClientWrapper = wsClientWrapper;
9198
this.zetaSdk =
9299
ZetaSdk.INSTANCE.build(
93100
serverUri.toString(),
@@ -98,15 +105,9 @@ public SecureWebSocketClient(
98105
new StorageConfig(
99106
new InMemoryStorage(), "7aae7xXr8rnzVqjpYbosS0CFMrlprkD7jbVotm0fd+w="),
100107
new TpmConfig() {},
101-
new AuthConfig(List.of("popp"), 30, true, getTokenProvider()),
102-
new ClientSelfAssessment(
103-
"name",
104-
"clientId",
105-
"manufacturerId",
106-
"manufacturerName",
107-
"test@example.com",
108-
0,
109-
new PlatformProductId.AppleProductId("apple", "macos", List.of("bundleX"))),
108+
new AuthConfig(
109+
List.of("popp"), 30L, true, getTokenProvider(), AttestationConfig.software()),
110+
new PlatformProductId.AppleProductId("apple", "macos", List.of("bundleX")),
110111
new ZetaHttpClientBuilder("")
111112
.disableServerValidation(disableServerValidation)
112113
.logging(LogLevel.ALL, message -> log.info("Ktor HttpClient: {}", message)),
@@ -118,8 +119,9 @@ private SubjectTokenProvider getTokenProvider() {
118119
if (!Files.isReadable(keyfile)) {
119120
throw new IllegalStateException("Can't read private key: " + keyfile);
120121
}
122+
121123
return new SmbTokenProvider(
122-
new SmbTokenProvider.Credentials(keyfile.toString(), alias, password));
124+
new SmbTokenProvider.Credentials(keyfile.toString(), alias, password, ""));
123125
}
124126

125127
@PostConstruct
@@ -156,59 +158,56 @@ public void onError(final Exception ex) {
156158
}
157159

158160
public boolean isClosed() {
159-
return session == null;
161+
return session.get() == null;
160162
}
161163

162164
public boolean isOpen() {
163-
return session != null;
165+
return session.get() != null;
164166
}
165167

166168
public void connectBlocking() {
167-
// Start new thread
168-
169169
pool.submit(
170-
() -> {
171-
WsClientExtension.ws(
172-
zetaSdk,
173-
this.serverUri.toString(),
174-
builder -> {
175-
builder.disableServerValidation(true);
176-
return Unit.INSTANCE;
177-
},
178-
new HashMap<>(),
179-
session -> {
180-
this.session = session;
181-
log.info("Zeta SDK WS connected");
182-
183-
while (true) {
184-
WsClientExtension.WsMessage incoming = session.receiveNext();
185-
if (incoming == null || incoming instanceof WsClientExtension.WsMessage.Close) {
186-
log.debug("WebSocket closed.");
187-
break;
170+
() ->
171+
wsClientWrapper.ws(
172+
zetaSdk,
173+
this.serverUri.toString(),
174+
builder -> {
175+
builder.disableServerValidation(true);
176+
return Unit.INSTANCE;
177+
},
178+
new HashMap<>(),
179+
session -> {
180+
this.session.set(session);
181+
log.info("Zeta SDK WS connected");
182+
sessionReady.countDown();
183+
184+
while (true) {
185+
WsClientExtension.WsMessage incoming = session.receiveNext();
186+
if (incoming == null || incoming instanceof WsClientExtension.WsMessage.Close) {
187+
log.debug("WebSocket closed.");
188+
break;
189+
}
190+
if (incoming instanceof WsClientExtension.WsMessage.Text text) {
191+
log.debug("WebSocket received: {}", text.getText());
192+
onMessage(text.getText());
193+
} else if (incoming instanceof WsClientExtension.WsMessage.Binary bin) {
194+
log.debug("WebSocket received binary (bytes): {}", bin.getBytes().length);
195+
}
188196
}
189-
if (incoming instanceof WsClientExtension.WsMessage.Text text) {
190-
log.debug("WebSocket received: " + text.getText());
191-
onMessage(text.getText());
192-
} else if (incoming instanceof WsClientExtension.WsMessage.Binary bin) {
193-
log.debug("WebSocket received binary (bytes): " + bin.getBytes().length);
194-
}
195-
}
196-
});
197-
});
198-
199-
// TODO: instead of busy waiting, use semaphor for inter-thread communication or smth similar
200-
while (true) {
201-
if (this.session != null) break;
202-
try {
203-
Thread.sleep(1000);
204-
} catch (InterruptedException e) {
205-
throw new RuntimeException(e);
197+
}));
198+
199+
try {
200+
if (!sessionReady.await(10, TimeUnit.SECONDS)) {
201+
throw new RuntimeException("Connection timeout");
206202
}
203+
} catch (InterruptedException e) {
204+
Thread.currentThread().interrupt();
205+
throw new RuntimeException(e);
207206
}
208207
}
209208

210209
public void send(String messageAsString) {
211-
this.session.sendText(messageAsString);
210+
this.session.get().sendText(messageAsString);
212211
}
213212

214213
public Map<String, Object> getSSLSession() {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (Date see Readme), gematik GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* *******
17+
*
18+
* For additional notes and disclaimer from gematik and in case of changes by gematik find details in the "Readme" file.
19+
*/
20+
21+
package de.gematik.refpopp.popp_client.client;
22+
23+
import de.gematik.zeta.sdk.WsClientExtension;
24+
import de.gematik.zeta.sdk.ZetaSdkClient;
25+
import de.gematik.zeta.sdk.network.http.client.ZetaHttpClientBuilder;
26+
import java.util.Map;
27+
import kotlin.Unit;
28+
import kotlin.jvm.functions.Function1;
29+
import org.springframework.stereotype.Component;
30+
31+
@Component
32+
public class WsClientWrapper {
33+
34+
void ws(
35+
ZetaSdkClient zetaSdk,
36+
String targetUrl,
37+
Function1<ZetaHttpClientBuilder, Unit> builder,
38+
Map<String, String> customHeaders,
39+
WsClientExtension.WsSession.WsHandler handler) {
40+
WsClientExtension.ws(zetaSdk, targetUrl, builder, customHeaders, handler);
41+
}
42+
}

0 commit comments

Comments
 (0)