Skip to content

Commit 6ff003c

Browse files
chore(cmdline): Adds nano plaintext to cmdline (#284)
1 parent 47041c5 commit 6ff003c

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

.github/workflows/checks.yaml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ jobs:
167167
--client-secret=secret \
168168
--platform-endpoint=http://localhost:8080 \
169169
-h\
170-
encryptnano --kas-url=http://localhost:8080 --attr https://example.com/attr/attr1/value/value1 -f data -m 'here is some metadata' > nano.ntdf
170+
encryptnano --kas-url=http://localhost:8080 --attr https://example.com/attr/attr1/value/value1 --policy-type encrypted -f data -m 'here is some metadata' > nano.ntdf
171171
172172
java -jar target/cmdline.jar \
173173
--client-id=opentdf-sdk \
@@ -182,6 +182,30 @@ jobs:
182182
fi
183183
working-directory: cmdline
184184

185+
- name: Encrypt/Decrypt NanoTDF with plain text policy type
186+
run: |
187+
echo 'here is some data to encrypt' > data
188+
189+
java -jar target/cmdline.jar \
190+
--client-id=opentdf-sdk \
191+
--client-secret=secret \
192+
--platform-endpoint=http://localhost:8080 \
193+
-h\
194+
encryptnano --kas-url=http://localhost:8080 --attr https://example.com/attr/attr1/value/value1 --policy-type plaintext -f data -m 'here is some metadata' > nanopt.ntdf
195+
196+
java -jar target/cmdline.jar \
197+
--client-id=opentdf-sdk \
198+
--client-secret=secret \
199+
--platform-endpoint=http://localhost:8080 \
200+
-h\
201+
decryptnano -f nanopt.ntdf > decrypted
202+
203+
if ! diff -q data decrypted; then
204+
printf 'decrypted data is incorrect [%s]' "$(< decrypted)"
205+
exit 1
206+
fi
207+
working-directory: cmdline
208+
185209
- name: Encrypt/Decrypt Assertions
186210
run: |
187211
echo "basic assertions"

cmdline/src/main/java/io/opentdf/platform/Command.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.opentdf.platform.sdk.Config;
99
import io.opentdf.platform.sdk.KeyType;
1010
import io.opentdf.platform.sdk.Config.AssertionVerificationKeys;
11+
import io.opentdf.platform.sdk.NanoTDFType;
1112
import io.opentdf.platform.sdk.SDK;
1213
import io.opentdf.platform.sdk.SDKBuilder;
1314
import nl.altindag.ssl.SSLFactory;
@@ -328,6 +329,7 @@ void createNanoTDF(
328329
@Option(names = { "-f", "--file" }, defaultValue = Option.NULL_VALUE) Optional<File> file,
329330
@Option(names = { "-k", "--kas-url" }, required = true) List<String> kas,
330331
@Option(names = { "-m", "--metadata" }, defaultValue = Option.NULL_VALUE) Optional<String> metadata,
332+
@Option(names = { "--policy-type" }, defaultValue = Option.NULL_VALUE, description = "how to embed the policy, either plaintext or encrypted") Optional<String> policyType,
331333
@Option(names = { "-a", "--attr" }, defaultValue = Option.NULL_VALUE) Optional<String> attributes)
332334
throws Exception {
333335

@@ -343,6 +345,19 @@ void createNanoTDF(
343345
attributes.ifPresent(attr -> {
344346
configs.add(Config.witDataAttributes(attr.split(",")));
345347
});
348+
policyType.ifPresent(mode -> {
349+
switch (mode) {
350+
case "":
351+
case "encrypted":
352+
configs.add(Config.withPolicyType(NanoTDFType.PolicyType.EMBEDDED_POLICY_ENCRYPTED));
353+
break;
354+
case "plaintext":
355+
configs.add(Config.withPolicyType(NanoTDFType.PolicyType.EMBEDDED_POLICY_PLAIN_TEXT));
356+
break;
357+
default:
358+
throw new IllegalArgumentException("Unknown policy type: " + mode);
359+
}
360+
});
346361

347362
var nanoTDFConfig = Config.newNanoTDFConfig(configs.toArray(Consumer[]::new));
348363
try (var in = file.isEmpty() ? new BufferedInputStream(System.in) : new FileInputStream(file.get())) {

0 commit comments

Comments
 (0)