Skip to content

refactor!: move to single jar #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,21 @@ jobs:
--client-id=opentdf-sdk \
--client-secret=secret \
--platform-endpoint=localhost:8080 \
-i -h \
-h\
encrypt --kas-url=localhost:8080 --mime-type=text/plain --attr https://example.com/attr/attr1/value/value1 --autoconfigure=false -f data -m 'here is some metadata' > test.tdf

java -jar target/cmdline.jar \
--client-id=opentdf-sdk \
--client-secret=secret \
--platform-endpoint=localhost:8080 \
-i -h \
-h\
decrypt -f test.tdf > decrypted

java -jar target/cmdline.jar \
--client-id=opentdf-sdk \
--client-secret=secret \
--platform-endpoint=localhost:8080 \
-i -h \
-h\
metadata -f test.tdf > metadata

if ! diff -q data decrypted; then
Expand All @@ -174,14 +174,14 @@ jobs:
--client-id=opentdf-sdk \
--client-secret=secret \
--platform-endpoint=localhost:8080 \
-i -h \
-h\
encryptnano --kas-url=http://localhost:8080 --attr https://example.com/attr/attr1/value/value1 -f data -m 'here is some metadata' > nano.ntdf

java -jar target/cmdline.jar \
--client-id=opentdf-sdk \
--client-secret=secret \
--platform-endpoint=localhost:8080 \
-i -h \
-h\
decryptnano -f nano.ntdf > decrypted

if ! diff -q data decrypted; then
Expand Down Expand Up @@ -216,21 +216,21 @@ jobs:
--client-id=opentdf-sdk \
--client-secret=secret \
--platform-endpoint=localhost:8080 \
-i -h \
-h\
encrypt --kas-url=localhost:8080,localhost:8282 -f data -m 'here is some metadata' > test.tdf

java -jar target/cmdline.jar \
--client-id=opentdf-sdk \
--client-secret=secret \
--platform-endpoint=localhost:8080 \
-i -h \
-h\
decrypt -f test.tdf > decrypted

java -jar target/cmdline.jar \
--client-id=opentdf-sdk \
--client-secret=secret \
--platform-endpoint=localhost:8080 \
-i -h \
-h\
metadata -f test.tdf > metadata

if ! diff -q data decrypted; then
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
protocol/src/main/protogen
sdk/src/main/protogen
/.idea/
target/
.vscode/
.DS_Store
sdk/sample.tdf
4 changes: 2 additions & 2 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ managed:
- buf.build/grpc-ecosystem/grpc-gateway
plugins:
- plugin: buf.build/protocolbuffers/java:v25.3
out: protocol/src/main/protogen
out: sdk/src/main/protogen
- plugin: buf.build/grpc/java:v1.61.1
out: protocol/src/main/protogen
out: sdk/src/main/protogen
59 changes: 42 additions & 17 deletions cmdline/pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.opentdf.platform</groupId>
<artifactId>sdk-pom</artifactId>
<version>0.6.2-SNAPSHOT</version><!-- {x-version-update:java-sdk:current} -->
<version>${revision}</version>
</parent>
<artifactId>cmdline</artifactId>
<properties>
Expand All @@ -18,27 +18,52 @@
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.7.1</version>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
<goal>shade</goal>
</goals>
<configuration>

<createDependencyReducedPom>false</createDependencyReducedPom>
<finalName>cmdline</finalName>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>io.opentdf.platform.TDF</mainClass>
<manifestEntries>
<Implementation-Version>${version}</Implementation-Version>
<Main-Class>io.opentdf.platform.TDF</Main-Class>
</manifestEntries>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>

<!-- Skip deployment for this child module -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>cmdline</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>io.opentdf.platform.TDF</mainClass>
</manifest>
</archive>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
Expand All @@ -52,7 +77,7 @@
<dependency>
<groupId>io.opentdf.platform</groupId>
<artifactId>sdk</artifactId>
<version>0.6.2-SNAPSHOT</version><!-- {x-version-update:java-sdk:current} -->
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
70 changes: 35 additions & 35 deletions cmdline/src/main/java/io/opentdf/platform/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,89 +39,88 @@
@CommandLine.Command(name = "tdf")
class Command {

@Option(names = {"--client-secret"}, required = true)
@Option(names = { "--client-secret" }, required = true)
private String clientSecret;

@Option(names = {"-h", "--plaintext"}, defaultValue = "false")
@Option(names = { "-h", "--plaintext" }, defaultValue = "false")
private boolean plaintext;

@Option(names = {"-i", "--insecure"}, defaultValue = "false")
@Option(names = { "-i", "--insecure" }, defaultValue = "false")
private boolean insecure;

@Option(names = {"--client-id"}, required = true)
@Option(names = { "--client-id" }, required = true)
private String clientId;

@Option(names = {"-p", "--platform-endpoint"}, required = true)
@Option(names = { "-p", "--platform-endpoint" }, required = true)
private String platformEndpoint;

@CommandLine.Command(name = "encrypt")
void encrypt(
@Option(names = {"-f", "--file"}, defaultValue = Option.NULL_VALUE) Optional<File> file,
@Option(names = {"-k", "--kas-url"}, required = true, split = ",") List<String> kas,
@Option(names = {"-m", "--metadata"}, defaultValue = Option.NULL_VALUE) Optional<String> metadata,
@Option(names = { "-f", "--file" }, defaultValue = Option.NULL_VALUE) Optional<File> file,
@Option(names = { "-k", "--kas-url" }, required = true, split = ",") List<String> kas,
@Option(names = { "-m", "--metadata" }, defaultValue = Option.NULL_VALUE) Optional<String> metadata,
// cant split on optional parameters
@Option(names = {"-a", "--attr"}, defaultValue = Option.NULL_VALUE) Optional<String> attributes,
@Option(names = {"-c", "--autoconfigure"}, defaultValue = Option.NULL_VALUE) Optional<Boolean> autoconfigure,
@Option(names = {"--mime-type"}, defaultValue = Option.NULL_VALUE) Optional<String> mimeType) throws
IOException, JOSEException, AutoConfigureException, InterruptedException, ExecutionException {
@Option(names = { "-a", "--attr" }, defaultValue = Option.NULL_VALUE) Optional<String> attributes,
@Option(names = { "-c",
"--autoconfigure" }, defaultValue = Option.NULL_VALUE) Optional<Boolean> autoconfigure,
@Option(names = { "--mime-type" }, defaultValue = Option.NULL_VALUE) Optional<String> mimeType)
throws IOException, JOSEException, AutoConfigureException, InterruptedException, ExecutionException {

var sdk = buildSDK();
var kasInfos = kas.stream().map(k -> {
var ki = new Config.KASInfo();
ki.URL = k;
return ki;
}).toArray(Config.KASInfo[]::new);


List<Consumer<Config.TDFConfig>> configs = new ArrayList<>();
configs.add(Config.withKasInformation(kasInfos));
metadata.map(Config::withMetaData).ifPresent(configs::add);
autoconfigure.map(Config::withAutoconfigure).ifPresent(configs::add);
mimeType.map(Config::withMimeType).ifPresent(configs::add);
if (attributes.isPresent()){
if (attributes.isPresent()) {
configs.add(Config.withDataAttributes(attributes.get().split(",")));
}
var tdfConfig = Config.newTDFConfig(configs.toArray(Consumer[]::new));
try (var in = file.isEmpty() ? new BufferedInputStream(System.in) : new FileInputStream(file.get())) {
try (var out = new BufferedOutputStream(System.out)) {
new TDF().createTDF(in, out, tdfConfig,
sdk.getServices().kas(),
sdk.getServices().attributes()
);
new TDF().createTDF(in, out, tdfConfig,
sdk.getServices().kas(),
sdk.getServices().attributes());
}
}
}

private SDK buildSDK() {
SDKBuilder builder = new SDKBuilder();
if (insecure){
if (insecure) {
SSLFactory sslFactory = SSLFactory.builder()
.withUnsafeTrustMaterial() // Trust all certificates
.build();
.withUnsafeTrustMaterial() // Trust all certificates
.build();
builder.sslFactory(sslFactory);
}

return builder.platformEndpoint(platformEndpoint)
.clientSecret(clientId, clientSecret)
.useInsecurePlaintextConnection(plaintext)

return builder.platformEndpoint(platformEndpoint)
.clientSecret(clientId, clientSecret).useInsecurePlaintextConnection(plaintext)
.build();
}

@CommandLine.Command(name = "decrypt")
void decrypt(@Option(names = {"-f", "--file"}, required = true) Path tdfPath) throws IOException,
void decrypt(@Option(names = { "-f", "--file" }, required = true) Path tdfPath) throws IOException,
InvalidAlgorithmParameterException, NoSuchPaddingException, IllegalBlockSizeException,
BadPaddingException, InvalidKeyException, TDF.FailedToCreateGMAC,
JOSEException, ParseException, NoSuchAlgorithmException, DecoderException {
var sdk = buildSDK();
try (var in = FileChannel.open(tdfPath, StandardOpenOption.READ)) {
try (var stdout = new BufferedOutputStream(System.out)) {
var reader = new TDF().loadTDF(in, sdk.getServices().kas());
reader.readPayload(stdout);
}
var reader = new TDF().loadTDF(in, sdk.getServices().kas());
reader.readPayload(stdout);
}
}
}

@CommandLine.Command(name = "metadata")
void readMetadata(@Option(names = {"-f", "--file"}, required = true) Path tdfPath) throws IOException,
void readMetadata(@Option(names = { "-f", "--file" }, required = true) Path tdfPath) throws IOException,
TDF.FailedToCreateGMAC, JOSEException, NoSuchAlgorithmException, ParseException, DecoderException {
var sdk = buildSDK();

Expand All @@ -135,10 +134,11 @@ void readMetadata(@Option(names = {"-f", "--file"}, required = true) Path tdfPat

@CommandLine.Command(name = "encryptnano")
void createNanoTDF(
@Option(names = {"-f", "--file"}, defaultValue = Option.NULL_VALUE) Optional<File> file,
@Option(names = {"-k", "--kas-url"}, required = true) List<String> kas,
@Option(names = {"-m", "--metadata"}, defaultValue = Option.NULL_VALUE) Optional<String> metadata,
@Option(names = {"-a", "--attr"}, defaultValue = Option.NULL_VALUE) Optional<String> attributes) throws Exception {
@Option(names = { "-f", "--file" }, defaultValue = Option.NULL_VALUE) Optional<File> file,
@Option(names = { "-k", "--kas-url" }, required = true) List<String> kas,
@Option(names = { "-m", "--metadata" }, defaultValue = Option.NULL_VALUE) Optional<String> metadata,
@Option(names = { "-a", "--attr" }, defaultValue = Option.NULL_VALUE) Optional<String> attributes)
throws Exception {

var sdk = buildSDK();
var kasInfos = kas.stream().map(k -> {
Expand All @@ -163,7 +163,7 @@ void createNanoTDF(
}

@CommandLine.Command(name = "decryptnano")
void readNanoTDF(@Option(names = {"-f", "--file"}, required = true) Path nanoTDFPath) throws Exception {
void readNanoTDF(@Option(names = { "-f", "--file" }, required = true) Path nanoTDFPath) throws Exception {
var sdk = buildSDK();
try (var in = FileChannel.open(nanoTDFPath, StandardOpenOption.READ)) {
try (var stdout = new BufferedOutputStream(System.out)) {
Expand Down
Loading
Loading