|
1 | 1 | package io.opentdf.platform;
|
2 | 2 |
|
| 3 | +import com.google.gson.Gson; |
3 | 4 | import com.google.gson.JsonSyntaxException;
|
4 | 5 | import com.nimbusds.jose.JOSEException;
|
5 |
| -import io.opentdf.platform.sdk.*; |
6 |
| -import io.opentdf.platform.sdk.TDF; |
| 6 | +import io.opentdf.platform.sdk.AssertionConfig; |
| 7 | +import io.opentdf.platform.sdk.AutoConfigureException; |
| 8 | +import io.opentdf.platform.sdk.Config; |
7 | 9 | import io.opentdf.platform.sdk.Config.AssertionVerificationKeys;
|
8 |
| - |
9 |
| -import com.google.gson.Gson; |
| 10 | +import io.opentdf.platform.sdk.NanoTDF; |
| 11 | +import io.opentdf.platform.sdk.SDK; |
| 12 | +import io.opentdf.platform.sdk.SDKBuilder; |
| 13 | +import io.opentdf.platform.sdk.TDF; |
| 14 | +import nl.altindag.ssl.SSLFactory; |
10 | 15 | import org.apache.commons.codec.DecoderException;
|
11 |
| -import org.bouncycastle.crypto.RuntimeCryptoException; |
12 |
| - |
13 | 16 | import picocli.CommandLine;
|
14 | 17 | import picocli.CommandLine.HelpCommand;
|
15 | 18 | import picocli.CommandLine.Option;
|
16 | 19 |
|
17 |
| -import javax.crypto.BadPaddingException; |
18 |
| -import javax.crypto.IllegalBlockSizeException; |
19 |
| -import javax.crypto.NoSuchPaddingException; |
20 | 20 | import java.io.BufferedInputStream;
|
21 | 21 | import java.io.BufferedOutputStream;
|
22 | 22 | import java.io.File;
|
|
30 | 30 | import java.nio.file.Path;
|
31 | 31 | import java.nio.file.Paths;
|
32 | 32 | import java.nio.file.StandardOpenOption;
|
33 |
| -import java.security.InvalidAlgorithmParameterException; |
34 |
| -import java.security.InvalidKeyException; |
| 33 | +import java.security.KeyFactory; |
35 | 34 | import java.security.NoSuchAlgorithmException;
|
36 | 35 | import java.security.spec.InvalidKeySpecException;
|
37 | 36 | import java.security.spec.PKCS8EncodedKeySpec;
|
38 | 37 | import java.security.spec.X509EncodedKeySpec;
|
39 |
| -import java.security.KeyFactory; |
40 |
| -import java.security.PrivateKey; |
41 | 38 | import java.text.ParseException;
|
42 | 39 | import java.util.ArrayList;
|
43 | 40 | import java.util.Base64;
|
|
47 | 44 | import java.util.concurrent.ExecutionException;
|
48 | 45 | import java.util.function.Consumer;
|
49 | 46 |
|
50 |
| -import nl.altindag.ssl.SSLFactory; |
51 |
| -import nl.altindag.ssl.util.TrustManagerUtils; |
52 |
| - |
53 |
| -import javax.net.ssl.TrustManager; |
54 |
| - |
55 | 47 | @CommandLine.Command(
|
56 | 48 | name = "tdf",
|
57 | 49 | subcommands = {HelpCommand.class},
|
@@ -234,12 +226,11 @@ private SDK buildSDK() {
|
234 | 226 |
|
235 | 227 | @CommandLine.Command(name = "decrypt")
|
236 | 228 | void decrypt(@Option(names = { "-f", "--file" }, required = true) Path tdfPath,
|
| 229 | + @Option(names = { "--with-assertion-verification-disabled" }, defaultValue = "false") boolean disableAssertionVerification, |
237 | 230 | @Option(names = { "--with-assertion-verification-keys" }, defaultValue = Option.NULL_VALUE) Optional<String> assertionVerification)
|
238 |
| - throws IOException, |
239 |
| - InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException, |
240 |
| - BadPaddingException, InvalidKeyException, TDF.FailedToCreateGMAC, |
241 |
| - JOSEException, ParseException, NoSuchAlgorithmException, DecoderException { |
| 231 | + throws IOException, TDF.FailedToCreateGMAC, JOSEException, ParseException, NoSuchAlgorithmException, DecoderException { |
242 | 232 | var sdk = buildSDK();
|
| 233 | + var opts = new ArrayList<Consumer<Config.TDFReaderConfig>>(); |
243 | 234 | try (var in = FileChannel.open(tdfPath, StandardOpenOption.READ)) {
|
244 | 235 | try (var stdout = new BufferedOutputStream(System.out)) {
|
245 | 236 | if (assertionVerification.isPresent()) {
|
@@ -269,14 +260,16 @@ void decrypt(@Option(names = { "-f", "--file" }, required = true) Path tdfPath,
|
269 | 260 | throw new RuntimeException("Error with assertion verification key: " + e.getMessage(), e);
|
270 | 261 | }
|
271 | 262 | }
|
272 |
| - Config.TDFReaderConfig readerConfig = Config.newTDFReaderConfig( |
273 |
| - Config.withAssertionVerificationKeys(assertionVerificationKeys)); |
274 |
| - var reader = new TDF().loadTDF(in, sdk.getServices().kas(), readerConfig); |
275 |
| - reader.readPayload(stdout); |
276 |
| - } else { |
277 |
| - var reader = new TDF().loadTDF(in, sdk.getServices().kas()); |
278 |
| - reader.readPayload(stdout); |
| 263 | + opts.add(Config.withAssertionVerificationKeys(assertionVerificationKeys)); |
279 | 264 | }
|
| 265 | + |
| 266 | + if (disableAssertionVerification) { |
| 267 | + opts.add(Config.withDisableAssertionVerification(true)); |
| 268 | + } |
| 269 | + |
| 270 | + var readerConfig = Config.newTDFReaderConfig(opts.toArray(new Consumer[0])); |
| 271 | + var reader = new TDF().loadTDF(in, sdk.getServices().kas(), readerConfig); |
| 272 | + reader.readPayload(stdout); |
280 | 273 | }
|
281 | 274 | }
|
282 | 275 | }
|
|
0 commit comments