Skip to content

Commit 4375d4f

Browse files
fix(sdk): update opentdf java sdk to 0.7.9 (#51)
addresses #47 by updating the opentdf java sdk version to the latest, 0.7.9. updates the ztdf conversion classes to use update config signatures. ~~I am having issues getting the tests to pass however~~ Thanks to Tim for help with this! --------- Co-authored-by: Tim Tschampel <[email protected]>
1 parent a7178bb commit 4375d4f

File tree

9 files changed

+61
-12
lines changed

9 files changed

+61
-12
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
/.idea/
22
/**/target/
3+
/nifi-rel-nifi-*/
4+
Dockerfile*
5+
nifi-**.tar.gz

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
NIFI_VERSION?=1.28.1
2+
3+
nifi-image:
4+
wget https://raw.githubusercontent.com/apache/nifi/refs/tags/rel/nifi-$(NIFI_VERSION)/nifi-docker/dockerhub/Dockerfile
5+
curl -L https://github.com/apache/nifi/archive/refs/tags/rel/nifi-$(NIFI_VERSION).tar.gz -o nifi-$(NIFI_VERSION).tar.gz
6+
tar -xzf nifi-$(NIFI_VERSION).tar.gz
7+
docker build -t opentdf-nifi:local -f ./nifi-rel-nifi-$(NIFI_VERSION)/nifi-docker/dockerhub/Dockerfile --build-arg IMAGE_TAG=17-jre --build-arg BASE_URL=https://dlcdn.apache.org --build-arg NIFI_VERSION=$(NIFI_VERSION) --build-arg IMAGE_NAME=public.ecr.aws/docker/library/eclipse-temurin ./nifi-rel-nifi-$(NIFI_VERSION)/nifi-docker/dockerhub
8+
19

210
.PHONY: compose-package
311
compose-package: nar-build
412
@echo "package for docker compose"
13+
mkdir -p deploy/extensions
514
rm -rf deploy/extensions/*.nar
615
cp nifi-tdf-nar/target/*.nar deploy/extensions
716
cp nifi-tdf-controller-services-api-nar/target/*.nar deploy/extensions

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ Upload and use this template in NiFi:
4747
export GITHUB_TOKEN=your gh token
4848
make compose-package
4949
```
50+
1. Build local Nifi Image
51+
52+
```shell
53+
make nifi-image
54+
```
55+
5056
1. Start docker compose
5157
```shell
5258
docker compose up

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '3'
22
services:
33
opentdf-nifi:
4-
image: ghcr.io/ttschampel/nifi/nifi-1.25.0-jre17:latest
4+
image: opentdf-nifi:local
55
restart: always
66
ulimits:
77
nofile:

nifi-tdf-processors/src/main/java/io/opentdf/nifi/ConvertFromZTDF.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package io.opentdf.nifi;
22

33
import io.opentdf.platform.sdk.Config;
4+
import io.opentdf.platform.sdk.Config.TDFConfig;
45
import io.opentdf.platform.sdk.SDK;
56
import io.opentdf.platform.sdk.TDF;
7+
import io.opentdf.platform.sdk.KeyType;
68
import org.apache.commons.compress.utils.SeekableInMemoryByteChannel;
79
import org.apache.nifi.annotation.documentation.CapabilityDescription;
810
import org.apache.nifi.annotation.documentation.Tags;
@@ -65,15 +67,17 @@ public ConvertFromZTDF() {
6567
@Override
6668
void processFlowFiles(ProcessContext processContext, ProcessSession processSession, List<FlowFile> flowFiles) throws ProcessException {
6769
SDK sdk = getTDFSDK(processContext);
68-
//TODO add assertion verification key list population
69-
List<Config.AssertionVerificationKeys> assertionVerificationKeysList = new ArrayList<>();
70+
7071
for (FlowFile flowFile : flowFiles) {
7172
try {
7273
try (SeekableByteChannel seekableByteChannel = new SeekableInMemoryByteChannel(readEntireFlowFile(flowFile, processSession))) {
7374
FlowFile updatedFlowFile = processSession.write(flowFile, outputStream -> {
7475
try {
75-
TDF.Reader reader = getTDF().loadTDF(seekableByteChannel, sdk.getServices().kas(), assertionVerificationKeysList.toArray(new Config.AssertionVerificationKeys[0]));
76+
TDF.Reader reader = getTDF().loadTDF(seekableByteChannel, sdk.getServices().kas(), Config.newTDFReaderConfig(Config.withDisableAssertionVerification(true)), sdk.getServices().kasRegistry(), sdk.getPlatformUrl());
7677
reader.readPayload(outputStream);
78+
} catch (InterruptedException e) {
79+
getLogger().error("error decrypting ZTDF", e);
80+
Thread.currentThread().interrupt();
7781
} catch (Exception e) {
7882
getLogger().error("error decrypting ZTDF", e);
7983
throw new IOException(e);

nifi-tdf-processors/src/main/java/io/opentdf/nifi/ConvertToZTDF.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ private void addSigningInfoToAssertionConfig(ProcessContext processContext, Asse
255255
getLogger().debug("adding signing configuration for assertion");
256256
//TODO assumes RSA256 signing key
257257
PrivateKey privateKey = privateKeyService.getPrivateKey();
258-
assertionConfig.assertionKey = new AssertionConfig.AssertionKey(AssertionConfig.AssertionKeyAlg.RS256, privateKey);
258+
assertionConfig.signingKey = new AssertionConfig.AssertionKey(AssertionConfig.AssertionKeyAlg.RS256, privateKey);
259259
}
260260
}
261261
}

nifi-tdf-processors/src/test/java/io/opentdf/nifi/ConvertFromZTDFTest.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package io.opentdf.nifi;
22

3+
import com.nimbusds.jose.JOSEException;
4+
import io.opentdf.platform.policy.kasregistry.KeyAccessServerRegistryServiceGrpc;
35
import io.opentdf.platform.sdk.*;
6+
import io.opentdf.platform.sdk.Config;
47
import io.opentdf.platform.sdk.TDF.Reader;
58
import nl.altindag.ssl.util.KeyStoreUtils;
9+
import org.apache.commons.codec.DecoderException;
610
import org.apache.commons.compress.utils.SeekableInMemoryByteChannel;
711
import org.apache.nifi.ssl.SSLContextService;
812
import org.apache.nifi.util.MockFlowFile;
@@ -14,11 +18,17 @@
1418

1519
import java.io.File;
1620
import java.io.FileOutputStream;
21+
import java.io.IOException;
1722
import java.io.OutputStream;
23+
import java.lang.reflect.Field;
24+
import java.net.URISyntaxException;
1825
import java.nio.ByteBuffer;
1926
import java.nio.channels.SeekableByteChannel;
2027
import java.nio.file.Files;
28+
import java.security.NoSuchAlgorithmException;
29+
import java.text.ParseException;
2130
import java.util.*;
31+
import java.util.concurrent.ExecutionException;
2232
import java.util.concurrent.atomic.AtomicInteger;
2333

2434
import static org.junit.jupiter.api.Assertions.*;
@@ -63,18 +73,24 @@ void testConvertFromTDF() throws Exception {
6373

6474

6575
runner.assertValid();
66-
76+
String platformEndpoint = "http://platform";
6777
SDK.Services mockServices = mock(SDK.Services.class);
6878
SDK.KAS mockKAS = mock(SDK.KAS.class);
6979
when(mockSDK.getServices()).thenReturn(mockServices);
7080
when(mockServices.kas()).thenReturn(mockKAS);
71-
when(mockSDKBuilder.platformEndpoint("http://platform")).thenReturn(mockSDKBuilder);
81+
when(mockSDK.getPlatformUrl()).thenReturn(platformEndpoint);
82+
when(mockSDKBuilder.platformEndpoint(platformEndpoint)).thenReturn(mockSDKBuilder);
7283
when(mockSDKBuilder.clientSecret("my-client", "123-456")).thenReturn(mockSDKBuilder);
7384
when(mockSDKBuilder.sslFactoryFromKeyStore(TRUST_STORE_PATH, TRUST_STORE_PASSWORD)).thenReturn(mockSDKBuilder);
7485
when(mockSDKBuilder.build()).thenReturn(mockSDK);
7586

7687
ArgumentCaptor<SeekableByteChannel> seekableByteChannelArgumentCaptor = ArgumentCaptor.forClass(SeekableByteChannel.class);
7788
ArgumentCaptor<SDK.KAS> kasArgumentCaptor = ArgumentCaptor.forClass(SDK.KAS.class);
89+
ArgumentCaptor<Config.TDFReaderConfig> tdfReaderConfigArgumentCaptor = ArgumentCaptor.forClass(Config.TDFReaderConfig.class);
90+
ArgumentCaptor<KeyAccessServerRegistryServiceGrpc.KeyAccessServerRegistryServiceFutureStub> keyAccessServerRegistryServiceGrpcArgumentCaptor =
91+
ArgumentCaptor.forClass(KeyAccessServerRegistryServiceGrpc.KeyAccessServerRegistryServiceFutureStub.class);
92+
ArgumentCaptor<String> platformUrlCaptor = ArgumentCaptor.forClass(String.class);
93+
7894
Reader mockReader = mock(Reader.class);
7995

8096
ArgumentCaptor<OutputStream> outputStreamArgumentCaptor = ArgumentCaptor.forClass(OutputStream.class);
@@ -96,7 +112,10 @@ void testConvertFromTDF() throws Exception {
96112
assertSame(mockKAS, kas, "Expected KAS passed in");
97113
return mockReader;
98114
}).when(mockTDF).loadTDF(seekableByteChannelArgumentCaptor.capture(),
99-
kasArgumentCaptor.capture()
115+
kasArgumentCaptor.capture(),
116+
tdfReaderConfigArgumentCaptor.capture(),
117+
keyAccessServerRegistryServiceGrpcArgumentCaptor.capture(),
118+
platformUrlCaptor.capture()
100119
);
101120
MockFlowFile messageOne = runner.enqueue("message one".getBytes());
102121
MockFlowFile messageTwo = runner.enqueue("message two".getBytes());
@@ -112,6 +131,13 @@ void testConvertFromTDF() throws Exception {
112131

113132
assertTrue(messages.contains("message one"));
114133
assertTrue(messages.contains("message two"));
134+
135+
assertEquals(platformEndpoint, platformUrlCaptor.getValue());
136+
// disableAssertionVerification is a private field
137+
Field field = Config.TDFReaderConfig.class.getDeclaredField("disableAssertionVerification");
138+
field.setAccessible(true);
139+
boolean disableAssertionVerification = (boolean) field.get(tdfReaderConfigArgumentCaptor.getValue());
140+
assertTrue(disableAssertionVerification);
115141
}
116142

117143
public static class MockRunner extends ConvertFromZTDF {

nifi-tdf-processors/src/test/java/io/opentdf/nifi/ConvertToZTDFTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.opentdf.platform.policy.attributes.AttributesServiceGrpc;
55
import io.opentdf.platform.sdk.*;
66
import io.opentdf.platform.sdk.Config;
7+
import org.apache.commons.codec.DecoderException;
78
import org.apache.commons.io.IOUtils;
89
import org.apache.nifi.key.service.api.PrivateKeyService;
910
import org.apache.nifi.processor.ProcessContext;
@@ -133,8 +134,8 @@ void testToTDF_WithAssertionsOn_And_Assertions_Provided() throws Exception {
133134
assertEquals(1, assertionConfigList.size());
134135
AssertionConfig assertionConfig = assertionConfigList.get(0);
135136
assertNotNull(assertionConfig, "Assertion configuration present");
136-
assertNotNull(assertionConfig.assertionKey.key, "signing key present");
137-
assertEquals(AssertionConfig.AssertionKeyAlg.RS256, assertionConfig.assertionKey.alg);
137+
assertNotNull(assertionConfig.signingKey.key, "signing key present");
138+
assertEquals(AssertionConfig.AssertionKeyAlg.RS256, assertionConfig.signingKey.alg);
138139
assertEquals("a test assertion", assertionConfig.statement.value);
139140
assertEquals("sample", assertionConfig.statement.format);
140141
assertEquals(AssertionConfig.Scope.Payload, assertionConfig.scope);
@@ -146,7 +147,7 @@ void testToTDF_WithAssertionsOn_And_Assertions_Provided() throws Exception {
146147
assertEquals(1, flowFileList.size(), "one success flow file");
147148
}
148149

149-
private Captures commonProcessorTestSetup(TestRunner runner) throws IOException, JOSEException, ExecutionException, InterruptedException {
150+
private Captures commonProcessorTestSetup(TestRunner runner) throws IOException, JOSEException, ExecutionException, InterruptedException, DecoderException {
150151
((ConvertToZTDFTest.MockRunner) runner.getProcessor()).mockSDK = mockSDK;
151152
((ConvertToZTDFTest.MockRunner) runner.getProcessor()).mockTDF = mockTDF;
152153
runner.setProperty(ConvertToZTDF.KAS_URL, "https://kas1");

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
<dependency>
6767
<groupId>io.opentdf.platform</groupId>
6868
<artifactId>sdk</artifactId>
69-
<version>0.7.3</version>
69+
<version>0.7.9</version>
7070
</dependency>
7171
<dependency>
7272
<groupId>org.apache.commons</groupId>

0 commit comments

Comments
 (0)