|
24 | 24 | import java.io.FileInputStream;
|
25 | 25 | import java.io.IOException;
|
26 | 26 | import java.io.PrintWriter;
|
| 27 | +import java.net.URISyntaxException; |
27 | 28 | import java.nio.ByteBuffer;
|
28 | 29 | import java.nio.channels.FileChannel;
|
29 | 30 | import java.nio.charset.StandardCharsets;
|
@@ -245,8 +246,10 @@ private SDK buildSDK() {
|
245 | 246 | void decrypt(@Option(names = { "-f", "--file" }, required = true) Path tdfPath,
|
246 | 247 | @Option(names = { "--rewrap-key-type" }, defaultValue = Option.NULL_VALUE, description = "Preferred rewrap algorithm, one of ${COMPLETION-CANDIDATES}") Optional<KeyType> rewrapKeyType,
|
247 | 248 | @Option(names = { "--with-assertion-verification-disabled" }, defaultValue = "false") boolean disableAssertionVerification,
|
248 |
| - @Option(names = { "--with-assertion-verification-keys" }, defaultValue = Option.NULL_VALUE) Optional<String> assertionVerification) |
249 |
| - throws IOException, TDF.FailedToCreateGMAC, JOSEException, ParseException, NoSuchAlgorithmException, DecoderException { |
| 249 | + @Option(names = { "--with-assertion-verification-keys" }, defaultValue = Option.NULL_VALUE) Optional<String> assertionVerification, |
| 250 | + @Option(names = { "--kas-allowlist" }, defaultValue = Option.NULL_VALUE) Optional<String> kasAllowlistStr, |
| 251 | + @Option(names = { "--ignore-kas-allowlist" }, defaultValue = Option.NULL_VALUE) Optional<Boolean> ignoreAllowlist) |
| 252 | + throws IOException, TDF.FailedToCreateGMAC, JOSEException, ParseException, NoSuchAlgorithmException, DecoderException, InterruptedException, ExecutionException, URISyntaxException { |
250 | 253 | var sdk = buildSDK();
|
251 | 254 | var opts = new ArrayList<Consumer<Config.TDFReaderConfig>>();
|
252 | 255 | try (var in = FileChannel.open(tdfPath, StandardOpenOption.READ)) {
|
@@ -286,21 +289,39 @@ void decrypt(@Option(names = { "-f", "--file" }, required = true) Path tdfPath,
|
286 | 289 | }
|
287 | 290 | rewrapKeyType.map(Config::WithSessionKeyType).ifPresent(opts::add);
|
288 | 291 |
|
| 292 | + if (ignoreAllowlist.isPresent()) { |
| 293 | + opts.add(Config.WithIgnoreKasAllowlist(ignoreAllowlist.get())); |
| 294 | + } |
| 295 | + if (kasAllowlistStr.isPresent()) { |
| 296 | + opts.add(Config.WithKasAllowlist(kasAllowlistStr.get().split(","))); |
| 297 | + } |
| 298 | + |
289 | 299 | var readerConfig = Config.newTDFReaderConfig(opts.toArray(new Consumer[0]));
|
290 |
| - var reader = new TDF().loadTDF(in, sdk.getServices().kas(), readerConfig); |
| 300 | + var reader = new TDF().loadTDF(in, sdk.getServices().kas(), readerConfig, sdk.getServices().kasRegistry(), sdk.getPlatformUrl()); |
291 | 301 | reader.readPayload(stdout);
|
292 | 302 | }
|
293 | 303 | }
|
294 | 304 | }
|
295 | 305 |
|
296 | 306 | @CommandLine.Command(name = "metadata")
|
297 |
| - void readMetadata(@Option(names = { "-f", "--file" }, required = true) Path tdfPath) throws IOException, |
298 |
| - TDF.FailedToCreateGMAC, JOSEException, NoSuchAlgorithmException, ParseException, DecoderException { |
| 307 | + void readMetadata(@Option(names = { "-f", "--file" }, required = true) Path tdfPath, |
| 308 | + @Option(names = { "--kas-allowlist" }, defaultValue = Option.NULL_VALUE) Optional<String> kasAllowlistStr, |
| 309 | + @Option(names = { "--ignore-kas-allowlist" }, defaultValue = Option.NULL_VALUE) Optional<Boolean> ignoreAllowlist) throws IOException, |
| 310 | + TDF.FailedToCreateGMAC, JOSEException, NoSuchAlgorithmException, ParseException, DecoderException, InterruptedException, ExecutionException, URISyntaxException { |
299 | 311 | var sdk = buildSDK();
|
300 |
| - |
| 312 | + var opts = new ArrayList<Consumer<Config.TDFReaderConfig>>(); |
301 | 313 | try (var in = FileChannel.open(tdfPath, StandardOpenOption.READ)) {
|
302 | 314 | try (var stdout = new PrintWriter(System.out)) {
|
303 |
| - var reader = new TDF().loadTDF(in, sdk.getServices().kas()); |
| 315 | + |
| 316 | + if (ignoreAllowlist.isPresent()) { |
| 317 | + opts.add(Config.WithIgnoreKasAllowlist(ignoreAllowlist.get())); |
| 318 | + } |
| 319 | + if (kasAllowlistStr.isPresent()) { |
| 320 | + opts.add(Config.WithKasAllowlist(kasAllowlistStr.get().split(","))); |
| 321 | + } |
| 322 | + |
| 323 | + var readerConfig = Config.newTDFReaderConfig(opts.toArray(new Consumer[0])); |
| 324 | + var reader = new TDF().loadTDF(in, sdk.getServices().kas(), readerConfig, sdk.getServices().kasRegistry(), sdk.getPlatformUrl()); |
304 | 325 | stdout.write(reader.getMetadata() == null ? "" : reader.getMetadata());
|
305 | 326 | }
|
306 | 327 | }
|
@@ -337,15 +358,25 @@ void createNanoTDF(
|
337 | 358 | }
|
338 | 359 |
|
339 | 360 | @CommandLine.Command(name = "decryptnano")
|
340 |
| - void readNanoTDF(@Option(names = { "-f", "--file" }, required = true) Path nanoTDFPath) throws Exception { |
| 361 | + void readNanoTDF(@Option(names = { "-f", "--file" }, required = true) Path nanoTDFPath, |
| 362 | + @Option(names = { "--kas-allowlist" }, defaultValue = Option.NULL_VALUE) Optional<String> kasAllowlistStr, |
| 363 | + @Option(names = { "--ignore-kas-allowlist" }, defaultValue = Option.NULL_VALUE) Optional<Boolean> ignoreAllowlist) throws Exception { |
341 | 364 | var sdk = buildSDK();
|
342 | 365 | try (var in = FileChannel.open(nanoTDFPath, StandardOpenOption.READ)) {
|
343 | 366 | try (var stdout = new BufferedOutputStream(System.out)) {
|
344 | 367 | NanoTDF ntdf = new NanoTDF();
|
345 | 368 | ByteBuffer buffer = ByteBuffer.allocate((int) in.size());
|
346 | 369 | in.read(buffer);
|
347 | 370 | buffer.flip();
|
348 |
| - ntdf.readNanoTDF(buffer, stdout, sdk.getServices().kas()); |
| 371 | + var opts = new ArrayList<Consumer<Config.NanoTDFReaderConfig>>(); |
| 372 | + if (ignoreAllowlist.isPresent()) { |
| 373 | + opts.add(Config.WithNanoIgnoreKasAllowlist(ignoreAllowlist.get())); |
| 374 | + } |
| 375 | + if (kasAllowlistStr.isPresent()) { |
| 376 | + opts.add(Config.WithNanoKasAllowlist(kasAllowlistStr.get().split(","))); |
| 377 | + } |
| 378 | + var readerConfig = Config.newNanoTDFReaderConfig(opts.toArray(new Consumer[0])); |
| 379 | + ntdf.readNanoTDF(buffer, stdout, sdk.getServices().kas(), readerConfig, sdk.getServices().kasRegistry(), sdk.getPlatformUrl()); |
349 | 380 | }
|
350 | 381 | }
|
351 | 382 | }
|
|
0 commit comments