diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml
index 9961d031..c2785110 100644
--- a/.github/workflows/checks.yaml
+++ b/.github/workflows/checks.yaml
@@ -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
@@ -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
@@ -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
diff --git a/.gitignore b/.gitignore
index 476c7749..35853a81 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
-protocol/src/main/protogen
+sdk/src/main/protogen
/.idea/
target/
.vscode/
.DS_Store
+sdk/sample.tdf
\ No newline at end of file
diff --git a/buf.gen.yaml b/buf.gen.yaml
index e829ee09..797abc12 100644
--- a/buf.gen.yaml
+++ b/buf.gen.yaml
@@ -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
diff --git a/cmdline/pom.xml b/cmdline/pom.xml
index 65b0d13e..8d7a128f 100644
--- a/cmdline/pom.xml
+++ b/cmdline/pom.xml
@@ -1,12 +1,12 @@
+ 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">
4.0.0
io.opentdf.platform
sdk-pom
- 0.6.2-SNAPSHOT
+ ${revision}
cmdline
@@ -18,27 +18,52 @@
org.apache.maven.plugins
- maven-assembly-plugin
- 3.7.1
+ maven-shade-plugin
+ 3.5.3
package
- single
+ shade
+
+
+ false
+ cmdline
+
+
+ io.opentdf.platform.TDF
+
+ ${version}
+ io.opentdf.platform.TDF
+
+
+
+
+
+
+ *:*
+
+ META-INF/*.SF
+ META-INF/*.DSA
+ META-INF/*.RSA
+
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-deploy-plugin
+ 3.1.1
-
- jar-with-dependencies
-
- cmdline
- false
-
-
- io.opentdf.platform.TDF
-
-
+ true
@@ -52,7 +77,7 @@
io.opentdf.platform
sdk
- 0.6.2-SNAPSHOT
+ ${project.version}
\ No newline at end of file
diff --git a/cmdline/src/main/java/io/opentdf/platform/Command.java b/cmdline/src/main/java/io/opentdf/platform/Command.java
index ca784283..71770cd2 100644
--- a/cmdline/src/main/java/io/opentdf/platform/Command.java
+++ b/cmdline/src/main/java/io/opentdf/platform/Command.java
@@ -39,31 +39,32 @@
@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,
- @Option(names = {"-k", "--kas-url"}, required = true, split = ",") List kas,
- @Option(names = {"-m", "--metadata"}, defaultValue = Option.NULL_VALUE) Optional metadata,
+ @Option(names = { "-f", "--file" }, defaultValue = Option.NULL_VALUE) Optional file,
+ @Option(names = { "-k", "--kas-url" }, required = true, split = ",") List kas,
+ @Option(names = { "-m", "--metadata" }, defaultValue = Option.NULL_VALUE) Optional metadata,
// cant split on optional parameters
- @Option(names = {"-a", "--attr"}, defaultValue = Option.NULL_VALUE) Optional attributes,
- @Option(names = {"-c", "--autoconfigure"}, defaultValue = Option.NULL_VALUE) Optional autoconfigure,
- @Option(names = {"--mime-type"}, defaultValue = Option.NULL_VALUE) Optional mimeType) throws
- IOException, JOSEException, AutoConfigureException, InterruptedException, ExecutionException {
+ @Option(names = { "-a", "--attr" }, defaultValue = Option.NULL_VALUE) Optional attributes,
+ @Option(names = { "-c",
+ "--autoconfigure" }, defaultValue = Option.NULL_VALUE) Optional autoconfigure,
+ @Option(names = { "--mime-type" }, defaultValue = Option.NULL_VALUE) Optional mimeType)
+ throws IOException, JOSEException, AutoConfigureException, InterruptedException, ExecutionException {
var sdk = buildSDK();
var kasInfos = kas.stream().map(k -> {
@@ -71,57 +72,55 @@ void encrypt(
ki.URL = k;
return ki;
}).toArray(Config.KASInfo[]::new);
-
List> 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();
@@ -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,
- @Option(names = {"-k", "--kas-url"}, required = true) List kas,
- @Option(names = {"-m", "--metadata"}, defaultValue = Option.NULL_VALUE) Optional metadata,
- @Option(names = {"-a", "--attr"}, defaultValue = Option.NULL_VALUE) Optional attributes) throws Exception {
+ @Option(names = { "-f", "--file" }, defaultValue = Option.NULL_VALUE) Optional file,
+ @Option(names = { "-k", "--kas-url" }, required = true) List kas,
+ @Option(names = { "-m", "--metadata" }, defaultValue = Option.NULL_VALUE) Optional metadata,
+ @Option(names = { "-a", "--attr" }, defaultValue = Option.NULL_VALUE) Optional attributes)
+ throws Exception {
var sdk = buildSDK();
var kasInfos = kas.stream().map(k -> {
@@ -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)) {
diff --git a/pom.xml b/pom.xml
index 1b3475e0..317d9f21 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,26 +1,27 @@
-
+
4.0.0
io.opentdf.platform
sdk-pom
- 0.6.2-SNAPSHOT
+ ${revision}
sdk-pom
pom
UTF-8
-
+
11
11
2.20.0
1.63.0
3.25.3
8.3.5
+ 0.6.2-SNAPSHOT
- protocol
sdk
cmdline
@@ -114,14 +115,17 @@
-
+
-
+
maven-clean-plugin
3.1.0
-
+
maven-resources-plugin
3.0.2
@@ -146,7 +150,8 @@
maven-deploy-plugin
2.8.2
-
+
maven-site-plugin
3.7.1
@@ -162,10 +167,10 @@
false
-
-
-
-
+
+
+
+
@@ -187,12 +192,12 @@
${maven.compiler.target}
WARN
-
-
-
-
-
-
+
+
+
+
+
+
@@ -234,5 +239,4 @@
-
-
+
\ No newline at end of file
diff --git a/protocol/pom.xml b/protocol/pom.xml
deleted file mode 100644
index 143caf39..00000000
--- a/protocol/pom.xml
+++ /dev/null
@@ -1,105 +0,0 @@
-
-
-
- 4.0.0
- io.opentdf.platform
- protocol
- protocol
- 0.6.2-SNAPSHOT
-
- sdk-pom
- io.opentdf.platform
- 0.6.2-SNAPSHOT
-
- jar
-
-
- com.google.protobuf
- protobuf-java
- ${protobuf.version}
-
-
- javax.annotation
- javax.annotation-api
- 1.3.2
-
-
- build.buf
- protovalidate
- 0.1.9
-
-
- io.grpc
- grpc-protobuf
-
-
- io.grpc
- grpc-stub
-
-
-
-
-
- org.apache.maven.plugins
- maven-antrun-plugin
- 3.1.0
-
-
- generateSources
- generate-sources
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- run
-
-
-
-
-
- org.codehaus.mojo
- build-helper-maven-plugin
- 3.5.0
-
-
- add-source
- generate-sources
-
- add-source
-
-
-
- src/main/protogen
-
-
-
-
-
-
-
-
diff --git a/release-please.json b/release-please.json
index 1df29bb8..aaa7732d 100644
--- a/release-please.json
+++ b/release-please.json
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
- "release-type": "java-yoshi-mono-repo",
+ "release-type": "maven",
"bump-minor-pre-major": true,
"bump-patch-for-minor-pre-major": true,
"separate-pull-requests": false,
@@ -9,4 +9,4 @@
"packages": {
".": {}
}
-}
+}
\ No newline at end of file
diff --git a/protocol/buf.lock b/sdk/buf.lock
similarity index 100%
rename from protocol/buf.lock
rename to sdk/buf.lock
diff --git a/protocol/buf.yaml b/sdk/buf.yaml
similarity index 100%
rename from protocol/buf.yaml
rename to sdk/buf.yaml
diff --git a/sdk/pom.xml b/sdk/pom.xml
index 05c3f19b..20a48594 100644
--- a/sdk/pom.xml
+++ b/sdk/pom.xml
@@ -1,22 +1,18 @@
-
+
4.0.0
sdk
sdk
sdk-pom
io.opentdf.platform
- 0.6.2-SNAPSHOT
+ ${revision}
jar
-
- io.opentdf.platform
- protocol
- 0.6.2-SNAPSHOT
-
org.slf4j
slf4j-api
@@ -28,7 +24,7 @@
test
- org.apache.logging.log4j
+ org.apache.logging.log4j
log4j-core
test
@@ -135,5 +131,75 @@
org.mockito
mockito-junit-jupiter
+
+ build.buf
+ protovalidate
+ 0.1.9
+
-
+
+
+
+ org.apache.maven.plugins
+ maven-antrun-plugin
+ 3.1.0
+
+
+ generateSources
+ generate-sources
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ run
+
+
+
+
+
+ org.codehaus.mojo
+ build-helper-maven-plugin
+ 3.5.0
+
+
+ add-source
+ generate-sources
+
+ add-source
+
+
+
+ src/main/protogen
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/sdk/src/main/java/io/opentdf/platform/sdk/AssertionConfig.java b/sdk/src/main/java/io/opentdf/platform/sdk/AssertionConfig.java
index 6a8c229c..510a008c 100644
--- a/sdk/src/main/java/io/opentdf/platform/sdk/AssertionConfig.java
+++ b/sdk/src/main/java/io/opentdf/platform/sdk/AssertionConfig.java
@@ -1,10 +1,8 @@
package io.opentdf.platform.sdk;
-import com.nimbusds.jose.JWSSigner;
import java.util.Objects;
-
public class AssertionConfig {
public enum Type {
@@ -70,7 +68,7 @@ public AssertionKey(AssertionKeyAlg alg, Object key) {
this.key = key;
}
- public boolean isDefined() {
+ public boolean isDefined() {
return alg != AssertionKeyAlg.NotDefined;
}
}
@@ -82,10 +80,13 @@ static public class Statement {
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
Statement statement = (Statement) o;
- return Objects.equals(format, statement.format) && Objects.equals(schema, statement.schema) && Objects.equals(value, statement.value);
+ return Objects.equals(format, statement.format) && Objects.equals(schema, statement.schema)
+ && Objects.equals(value, statement.value);
}
@Override
diff --git a/sdk/src/main/java/io/opentdf/platform/sdk/Autoconfigure.java b/sdk/src/main/java/io/opentdf/platform/sdk/Autoconfigure.java
index 29b7c4d5..5e9eb7da 100644
--- a/sdk/src/main/java/io/opentdf/platform/sdk/Autoconfigure.java
+++ b/sdk/src/main/java/io/opentdf/platform/sdk/Autoconfigure.java
@@ -45,7 +45,6 @@ class RuleType {
public static final String EMPTY_TERM = "DEFAULT";
}
-
public class Autoconfigure {
public static Logger logger = LoggerFactory.getLogger(Autoconfigure.class);
@@ -73,7 +72,7 @@ public boolean equals(Object obj) {
return false;
}
KeySplitStep ss = (KeySplitStep) obj;
- if ((this.kas.equals(ss.kas)) && (this.splitID.equals(ss.splitID))){
+ if ((this.kas.equals(ss.kas)) && (this.splitID.equals(ss.splitID))) {
return true;
}
return false;
@@ -185,7 +184,7 @@ public boolean equals(Object obj) {
return false;
}
AttributeValueFQN afqn = (AttributeValueFQN) obj;
- if (this.key.equals(afqn.key)){
+ if (this.key.equals(afqn.key)) {
return true;
}
return false;
@@ -264,8 +263,8 @@ public Granter(List policy) {
this.policy = policy;
}
- public Map getGrants() {
- return new HashMap(grants);
+ public Map getGrants() {
+ return new HashMap(grants);
}
public List getPolicy() {
@@ -273,8 +272,7 @@ public List getPolicy() {
}
public void addGrant(AttributeValueFQN fqn, String kas, Attribute attr) {
- grants.computeIfAbsent(fqn.key, k -> new KeyAccessGrant(attr, new ArrayList<>()))
- .kases.add(kas);
+ grants.computeIfAbsent(fqn.key, k -> new KeyAccessGrant(attr, new ArrayList<>())).kases.add(kas);
}
public void addAllGrants(AttributeValueFQN fqn, List gs, Attribute attr) {
@@ -293,8 +291,8 @@ public KeyAccessGrant byAttribute(AttributeValueFQN fqn) {
return grants.get(fqn.key);
}
-
- public List plan(List defaultKas, Supplier genSplitID) throws AutoConfigureException {
+ public List plan(List defaultKas, Supplier genSplitID)
+ throws AutoConfigureException {
AttributeBooleanExpression b = constructAttributeBoolean();
BooleanKeyExpression k = insertKeysForAttribute(b);
if (k == null) {
@@ -330,35 +328,35 @@ public List plan(List defaultKas, Supplier genSpli
BooleanKeyExpression insertKeysForAttribute(AttributeBooleanExpression e) throws AutoConfigureException {
List kcs = new ArrayList<>(e.must.size());
-
+
for (SingleAttributeClause clause : e.must) {
List kcv = new ArrayList<>(clause.values.size());
-
+
for (AttributeValueFQN term : clause.values) {
KeyAccessGrant grant = byAttribute(term);
if (grant == null) {
throw new AutoConfigureException(String.format("no definition or grant found for [%s]", term));
}
-
+
List kases = grant.kases;
if (kases.isEmpty()) {
kases = List.of(RuleType.EMPTY_TERM);
}
-
+
for (String kas : kases) {
kcv.add(new PublicKeyInfo(kas));
}
}
-
+
String op = ruleToOperator(clause.def.getRule());
if (op == RuleType.UNSPECIFIED) {
logger.warn("Unknown attribute rule type: " + clause);
}
-
+
KeyClause kc = new KeyClause(op, kcv);
kcs.add(kc);
}
-
+
return new BooleanKeyExpression(kcs);
}
@@ -371,7 +369,8 @@ AttributeBooleanExpression constructAttributeBoolean() throws AutoConfigureExcep
if (clause != null) {
clause.values.add(aP);
} else if (byAttribute(aP) != null) {
- var x = new SingleAttributeClause(byAttribute(aP).attr, new ArrayList(Arrays.asList(aP)));
+ var x = new SingleAttributeClause(byAttribute(aP).attr,
+ new ArrayList(Arrays.asList(aP)));
prefixes.put(a.getKey(), x);
sortedPrefixes.add(a.getKey());
}
@@ -384,34 +383,33 @@ AttributeBooleanExpression constructAttributeBoolean() throws AutoConfigureExcep
return new AttributeBooleanExpression(must);
}
-
-
static class AttributeMapping {
private Map dict;
-
+
public AttributeMapping() {
this.dict = new HashMap<>();
}
-
+
public void put(Attribute ad) throws AutoConfigureException {
if (this.dict == null) {
this.dict = new HashMap<>();
}
-
+
AttributeNameFQN prefix = new AttributeNameFQN(ad.getFqn());
-
+
if (this.dict.containsKey(prefix)) {
throw new AutoConfigureException("Attribute prefix already found: [" + prefix.toString() + "]");
}
-
+
this.dict.put(prefix, ad);
}
-
+
public Attribute get(AttributeNameFQN prefix) throws AutoConfigureException {
Attribute ad = this.dict.get(prefix);
if (ad == null) {
- throw new AutoConfigureException("Unknown attribute type: [" + prefix.toString() + "], not in [" + this.dict.keySet().toString() + "]");
+ throw new AutoConfigureException("Unknown attribute type: [" + prefix.toString() + "], not in ["
+ + this.dict.keySet().toString() + "]");
}
return ad;
}
@@ -422,7 +420,7 @@ static class SingleAttributeClause {
private Attribute def;
private List values;
-
+
public SingleAttributeClause(Attribute def, List values) {
this.def = def;
this.values = values;
@@ -432,24 +430,24 @@ public SingleAttributeClause(Attribute def, List values) {
class AttributeBooleanExpression {
private List must;
-
+
public AttributeBooleanExpression(List must) {
this.must = must;
}
-
+
@Override
public String toString() {
if (must == null || must.isEmpty()) {
return "∅";
}
-
+
StringBuilder sb = new StringBuilder();
for (int i = 0; i < must.size(); i++) {
SingleAttributeClause clause = must.get(i);
if (i > 0) {
sb.append("&");
}
-
+
List values = clause.values;
if (values == null || values.isEmpty()) {
sb.append(clause.def.getFqn());
@@ -458,7 +456,7 @@ public String toString() {
} else {
sb.append(clause.def.getFqn());
sb.append("/value/{");
-
+
StringJoiner joiner = new StringJoiner(",");
for (AttributeValueFQN v : values) {
joiner.add(v.value());
@@ -469,20 +467,20 @@ public String toString() {
}
return sb.toString();
}
-
+
}
public class PublicKeyInfo {
private String kas;
-
+
public PublicKeyInfo(String kas) {
this.kas = kas;
}
-
+
public String getKas() {
return kas;
}
-
+
public void setKas(String kas) {
this.kas = kas;
}
@@ -491,12 +489,12 @@ public void setKas(String kas) {
public class KeyClause {
private String operator;
private List values;
-
+
public KeyClause(String operator, List values) {
this.operator = operator;
this.values = values;
}
-
+
@Override
public String toString() {
if (values.size() == 1 && values.get(0).getKas().equals(RuleType.EMPTY_TERM)) {
@@ -505,14 +503,14 @@ public String toString() {
if (values.size() == 1) {
return "(" + values.get(0).getKas() + ")";
}
-
+
StringBuilder sb = new StringBuilder();
sb.append("(");
String op = "⋀";
if (operator.equals(RuleType.ANY_OF)) {
op = "⋁";
}
-
+
for (int i = 0; i < values.size(); i++) {
if (i > 0) {
sb.append(op);
@@ -520,18 +518,18 @@ public String toString() {
sb.append(values.get(i).getKas());
}
sb.append(")");
-
+
return sb.toString();
}
}
public class BooleanKeyExpression {
private List values;
-
+
public BooleanKeyExpression(List values) {
this.values = values;
}
-
+
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
@@ -576,7 +574,7 @@ public BooleanKeyExpression reduce() {
if (conjunction.isEmpty()) {
return new BooleanKeyExpression(new ArrayList<>());
}
-
+
List newValues = new ArrayList<>();
for (List d : conjunction) {
List pki = new ArrayList<>();
@@ -591,7 +589,7 @@ public BooleanKeyExpression reduce() {
public Disjunction sortedNoDupes(List l) {
Set set = new HashSet<>();
Disjunction list = new Disjunction();
-
+
for (PublicKeyInfo e : l) {
String kas = e.getKas();
if (!kas.equals(RuleType.EMPTY_TERM) && !set.contains(kas)) {
@@ -599,7 +597,7 @@ public Disjunction sortedNoDupes(List l) {
list.add(kas);
}
}
-
+
Collections.sort(list);
return list;
}
@@ -621,7 +619,7 @@ public boolean less(Disjunction r) {
}
return this.size() < r.size();
}
-
+
public boolean equals(Object obj) {
if (this == obj) {
return true;
@@ -675,23 +673,25 @@ public static String ruleToOperator(AttributeRuleTypeEnum e) {
}
// Gets a list of directory of KAS grants for a list of attribute FQNs
- public static Granter newGranterFromService(AttributesServiceFutureStub as, KASKeyCache keyCache, AttributeValueFQN... fqns) throws AutoConfigureException, InterruptedException, ExecutionException {
+ public static Granter newGranterFromService(AttributesServiceFutureStub as, KASKeyCache keyCache,
+ AttributeValueFQN... fqns) throws AutoConfigureException, InterruptedException, ExecutionException {
String[] fqnsStr = new String[fqns.length];
for (int i = 0; i < fqns.length; i++) {
fqnsStr[i] = fqns[i].toString();
}
GetAttributeValuesByFqnsRequest request = GetAttributeValuesByFqnsRequest.newBuilder()
- .addAllFqns(Arrays.asList(fqnsStr))
- .setWithValue(AttributeValueSelector.newBuilder().setWithKeyAccessGrants(true).build())
- .build();
+ .addAllFqns(Arrays.asList(fqnsStr))
+ .setWithValue(AttributeValueSelector.newBuilder().setWithKeyAccessGrants(true).build())
+ .build();
GetAttributeValuesByFqnsResponse av;
av = as.getAttributeValuesByFqns(request).get();
Granter grants = new Granter(Arrays.asList(fqns));
- for (Map.Entry entry : av.getFqnAttributeValuesMap().entrySet()) {
+ for (Map.Entry entry : av.getFqnAttributeValuesMap()
+ .entrySet()) {
String fqnstr = entry.getKey();
AttributeAndValue pair = entry.getValue();
@@ -708,10 +708,10 @@ public static Granter newGranterFromService(AttributesServiceFutureStub as, KASK
grants.addAllGrants(fqn, v.getGrantsList(), def);
storeKeysToCache(v.getGrantsList(), keyCache);
} else {
- if (def != null) {
- grants.addAllGrants(fqn, def.getGrantsList(), def);
- storeKeysToCache(def.getGrantsList(), keyCache);
- }
+ if (def != null) {
+ grants.addAllGrants(fqn, def.getGrantsList(), def);
+ storeKeysToCache(def.getGrantsList(), keyCache);
+ }
}
}
diff --git a/sdk/src/main/java/io/opentdf/platform/sdk/Config.java b/sdk/src/main/java/io/opentdf/platform/sdk/Config.java
index 591dbe4d..a8766820 100644
--- a/sdk/src/main/java/io/opentdf/platform/sdk/Config.java
+++ b/sdk/src/main/java/io/opentdf/platform/sdk/Config.java
@@ -67,7 +67,6 @@ public String toString() {
}
}
-
public static class AssertionVerificationKeys {
public AssertionConfig.AssertionKey defaultKey;
public Map keys = new HashMap<>();
@@ -100,7 +99,8 @@ public static TDFReaderConfig newTDFReaderConfig(Consumer... op
return config;
}
- public static Consumer withAssertionVerificationKeys(AssertionVerificationKeys assertionVerificationKeys) {
+ public static Consumer withAssertionVerificationKeys(
+ AssertionVerificationKeys assertionVerificationKeys) {
return (TDFReaderConfig config) -> config.assertionVerificationKeys = assertionVerificationKeys;
}
@@ -147,7 +147,7 @@ public static TDFConfig newTDFConfig(Consumer... options) {
public static Consumer withDataAttributes(String... attributes) throws AutoConfigureException {
List attrValFqns = new ArrayList();
- for (String a : attributes){
+ for (String a : attributes) {
Autoconfigure.AttributeValueFQN attrValFqn = new Autoconfigure.AttributeValueFQN(a);
attrValFqns.add(attrValFqn);
}
@@ -159,7 +159,7 @@ public static Consumer withDataAttributes(String... attributes) throw
public static Consumer withDataAttributeValues(String... attributes) throws AutoConfigureException {
List attrValFqns = new ArrayList();
- for (String a : attributes){
+ for (String a : attributes) {
Autoconfigure.AttributeValueFQN attrValFqn = new Autoconfigure.AttributeValueFQN(a);
attrValFqns.add(attrValFqn);
}
@@ -169,8 +169,10 @@ public static Consumer withDataAttributeValues(String... attributes)
};
}
- // WithDataAttributeValues appends the given data attributes to the bound policy.
- // Unlike `WithDataAttributes`, this will not trigger an attribute definition lookup
+ // WithDataAttributeValues appends the given data attributes to the bound
+ // policy.
+ // Unlike `WithDataAttributes`, this will not trigger an attribute definition
+ // lookup
// during autoconfigure. That is, to use autoconfigure in an 'offline' context,
// you must first store the relevant attribute information locally and load
// it to the `CreateTDF` method with this option.
@@ -222,9 +224,9 @@ public static Consumer withAutoconfigure(boolean enable) {
};
}
-// public static Consumer withDisableEncryption() {
-// return (TDFConfig config) -> config.enableEncryption = false;
-// }
+ // public static Consumer withDisableEncryption() {
+ // return (TDFConfig config) -> config.enableEncryption = false;
+ // }
public static Consumer withMimeType(String mimeType) {
return (TDFConfig config) -> config.mimeType = mimeType;
diff --git a/sdk/src/main/java/io/opentdf/platform/sdk/KASClient.java b/sdk/src/main/java/io/opentdf/platform/sdk/KASClient.java
index 3cd9da3a..4732865b 100644
--- a/sdk/src/main/java/io/opentdf/platform/sdk/KASClient.java
+++ b/sdk/src/main/java/io/opentdf/platform/sdk/KASClient.java
@@ -30,7 +30,7 @@
import static java.lang.String.format;
-public class KASClient implements SDK.KAS, AutoCloseable {
+public class KASClient implements SDK.KAS {
private final Function channelFactory;
private final RSASSASigner signer;
@@ -41,10 +41,12 @@ public class KASClient implements SDK.KAS, AutoCloseable {
/***
* A client that communicates with KAS
- * @param channelFactory A function that produces channels that can be used to communicate
+ *
+ * @param channelFactory A function that produces channels that can be used to
+ * communicate
* @param dpopKey
*/
- public KASClient(Function channelFactory, RSAKey dpopKey) {
+ public KASClient(Function channelFactory, RSAKey dpopKey) {
this.channelFactory = channelFactory;
try {
this.signer = new RSASSASigner(dpopKey);
@@ -61,7 +63,8 @@ public KASClient(Function channelFactory, RSAKey dpopKe
@Override
public KASInfo getECPublicKey(Config.KASInfo kasInfo, NanoTDFType.ECCurve curve) {
var r = getStub(kasInfo.URL)
- .publicKey(PublicKeyRequest.newBuilder().setAlgorithm(String.format("ec:%s", curve.toString())).build());
+ .publicKey(
+ PublicKeyRequest.newBuilder().setAlgorithm(String.format("ec:%s", curve.toString())).build());
var k2 = kasInfo.clone();
k2.KID = r.getKid();
k2.PublicKey = r.getPublicKey();
@@ -75,7 +78,7 @@ public Config.KASInfo getPublicKey(Config.KASInfo kasInfo) {
return cachedValue;
}
PublicKeyResponse resp = getStub(kasInfo.URL).publicKey(PublicKeyRequest.getDefaultInstance());
-
+
var kiCopy = new Config.KASInfo();
kiCopy.KID = resp.getKid();
kiCopy.PublicKey = resp.getPublicKey();
@@ -87,7 +90,7 @@ public Config.KASInfo getPublicKey(Config.KASInfo kasInfo) {
}
@Override
- public KASKeyCache getKeyCache(){
+ public KASKeyCache getKeyCache() {
return this.kasKeyCache;
}
@@ -122,7 +125,7 @@ private String normalizeAddress(String urlString) {
public synchronized void close() {
var entries = new ArrayList<>(stubs.values());
stubs.clear();
- for (var entry: entries) {
+ for (var entry : entries) {
entry.channel.shutdownNow();
}
}
@@ -179,7 +182,7 @@ public byte[] unwrap(Manifest.KeyAccess keyAccess, String policy) {
return decryptor.decrypt(wrappedKey);
}
- public byte[] unwrapNanoTDF(NanoTDFType.ECCurve curve, String header, String kasURL) {
+ public byte[] unwrapNanoTDF(NanoTDFType.ECCurve curve, String header, String kasURL) {
ECKeyPair keyPair = new ECKeyPair(curve.toString(), ECKeyPair.ECAlgorithm.ECDH);
NanoTDFKeyAccess keyAccess = new NanoTDFKeyAccess();
@@ -190,7 +193,7 @@ public byte[] unwrapNanoTDF(NanoTDFType.ECCurve curve, String header, String kas
NanoTDFRewrapRequestBody body = new NanoTDFRewrapRequestBody();
body.algorithm = String.format("ec:%s", curve.toString());
- body.clientPublicKey = keyPair.publicKeyInPEMFormat();
+ body.clientPublicKey = keyPair.publicKeyInPEMFormat();
body.keyAccess = keyAccess;
var requestBody = gson.toJson(body);
@@ -236,9 +239,11 @@ public byte[] unwrapNanoTDF(NanoTDFType.ECCurve curve, String header, String kas
}
private final HashMap stubs = new HashMap<>();
+
private static class CacheEntry {
final ManagedChannel channel;
final AccessServiceGrpc.AccessServiceBlockingStub stub;
+
private CacheEntry(ManagedChannel channel, AccessServiceGrpc.AccessServiceBlockingStub stub) {
this.channel = channel;
this.stub = stub;
@@ -257,4 +262,3 @@ synchronized AccessServiceGrpc.AccessServiceBlockingStub getStub(String url) {
return stubs.get(realAddress).stub;
}
}
-
diff --git a/sdk/src/main/java/io/opentdf/platform/sdk/Manifest.java b/sdk/src/main/java/io/opentdf/platform/sdk/Manifest.java
index 27837fbd..831274e2 100644
--- a/sdk/src/main/java/io/opentdf/platform/sdk/Manifest.java
+++ b/sdk/src/main/java/io/opentdf/platform/sdk/Manifest.java
@@ -21,7 +21,6 @@
import java.security.interfaces.RSAPublicKey;
import java.text.ParseException;
import java.util.ArrayList;
-import java.util.Base64;
import java.util.List;
import java.util.Objects;
@@ -32,10 +31,13 @@ public class Manifest {
@Override
public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
Manifest manifest = (Manifest) o;
- return Objects.equals(encryptionInformation, manifest.encryptionInformation) && Objects.equals(payload, manifest.payload) && Objects.equals(assertions, manifest.assertions);
+ return Objects.equals(encryptionInformation, manifest.encryptionInformation)
+ && Objects.equals(payload, manifest.payload) && Objects.equals(assertions, manifest.assertions);
}
@Override
@@ -45,7 +47,8 @@ public int hashCode() {
private static class PolicyBindingSerializer implements JsonDeserializer