Skip to content

Commit 2a462d1

Browse files
committed
Merge remote-tracking branch 'origin/main' into dspx-817/add-system-assertions
2 parents 5492e2f + 03d5d41 commit 2a462d1

File tree

28 files changed

+314
-227
lines changed

28 files changed

+314
-227
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "0.8.1"
2+
".": "0.9.0"
33
}

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Changelog
22

3+
## [0.9.0](https://github.com/opentdf/java-sdk/compare/v0.8.1...v0.9.0) (2025-07-14)
4+
5+
6+
### Features
7+
8+
* **sdk:** Get the algorithm from the KASInfo and not the config ([#272](https://github.com/opentdf/java-sdk/issues/272)) ([feff0e8](https://github.com/opentdf/java-sdk/commit/feff0e892671c0fb34d6cbdf2bc9ba9e3a743295))
9+
10+
11+
### Bug Fixes
12+
13+
* **sdk:** upgrade the platform protocol code ([#275](https://github.com/opentdf/java-sdk/issues/275)) ([90eaba1](https://github.com/opentdf/java-sdk/commit/90eaba11c59e4e096648e1d47570c58558673b85))
14+
315
## [0.8.1](https://github.com/opentdf/java-sdk/compare/v0.8.0...v0.8.1) (2025-05-29)
416

517

cmdline/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>io.opentdf.platform</groupId>
66
<artifactId>sdk-pom</artifactId>
7-
<version>0.8.2-SNAPSHOT</version>
7+
<version>0.9.1-SNAPSHOT</version>
88
</parent>
99
<artifactId>cmdline</artifactId>
1010
<properties>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
*/
4949
class Versions {
5050
// Version of the SDK, managed by release-please.
51-
public static final String SDK = "0.8.2-SNAPSHOT"; // x-release-please-version
51+
public static final String SDK = "0.9.1-SNAPSHOT"; // x-release-please-version
5252

5353
// This sdk aims to support this version of the TDF spec; currently 4.3.0.
5454
public static final String TDF_SPEC = "4.3.0";

examples/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<artifactId>sdk-pom</artifactId>
66
<groupId>io.opentdf.platform</groupId>
7-
<version>0.8.2-SNAPSHOT</version>
7+
<version>0.9.1-SNAPSHOT</version>
88
</parent>
99

1010
<groupId>io.opentdf.platform</groupId>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package io.opentdf.platform;
2+
3+
import io.opentdf.platform.sdk.Manifest;
4+
import io.opentdf.platform.sdk.PolicyObject;
5+
import io.opentdf.platform.sdk.SDK;
6+
7+
import java.io.IOException;
8+
import java.nio.channels.FileChannel;
9+
import java.nio.file.Path;
10+
import java.nio.file.StandardOpenOption;
11+
12+
public class GetManifestInformation {
13+
public static void main(String[] args) throws IOException {
14+
if (args.length < 1) {
15+
System.err.println("TDF file path must be provided as an argument.");
16+
return;
17+
}
18+
19+
try (FileChannel tdfStream = FileChannel.open(Path.of(args[0]), StandardOpenOption.READ)) {
20+
Manifest manifest = SDK.readManifest(tdfStream);
21+
System.out.println("loaded a TDF with key access type: " + manifest.encryptionInformation.keyAccessType);
22+
23+
PolicyObject policyObject = SDK.decodePolicyObject(manifest);
24+
System.out.println("the policy has uuid: " + policyObject.uuid);
25+
}
26+
}
27+
}
28+

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>io.opentdf.platform</groupId>
77
<artifactId>sdk-pom</artifactId>
8-
<version>0.8.2-SNAPSHOT</version>
8+
<version>0.9.1-SNAPSHOT</version>
99
<name>io.opentdf.platform:sdk-pom</name>
1010
<description>OpenTDF Java SDK</description>
1111
<url>https://github.com/opentdf/java-sdk</url>

sdk/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<parent>
99
<artifactId>sdk-pom</artifactId>
1010
<groupId>io.opentdf.platform</groupId>
11-
<version>0.8.2-SNAPSHOT</version>
11+
<version>0.9.1-SNAPSHOT</version>
1212
</parent>
1313
<packaging>jar</packaging>
1414
<properties>
@@ -18,7 +18,7 @@
1818
<kotlin.version>2.1.0</kotlin.version>
1919
<connect.version>0.7.2</connect.version>
2020
<okhttp.version>4.12.0</okhttp.version>
21-
<platform.branch>protocol/go/v0.3.0</platform.branch>
21+
<platform.branch>protocol/go/v0.5.0</platform.branch>
2222
</properties>
2323
<dependencies>
2424
<!-- Logging Dependencies -->

sdk/src/main/java/io/opentdf/platform/sdk/ECCMode.java

Lines changed: 7 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.opentdf.platform.sdk;
22

3+
import javax.annotation.Nonnull;
4+
35
public class ECCMode {
46
private ECCModeStruct data;
57

@@ -13,7 +15,7 @@ public ECCMode() {
1315
public ECCMode(byte value) {
1416
data = new ECCModeStruct();
1517
int curveMode = value & 0x07; // first 3 bits
16-
setEllipticCurve(NanoTDFType.ECCurve.values()[curveMode]);
18+
setEllipticCurve(NanoTDFType.ECCurve.fromCurveMode(curveMode));
1719
int useECDSABinding = (value >> 7) & 0x01; // most significant bit
1820
data.useECDSABinding = useECDSABinding;
1921
}
@@ -44,75 +46,24 @@ public void setEllipticCurve(NanoTDFType.ECCurve curve) {
4446
}
4547
}
4648

47-
public NanoTDFType.ECCurve getEllipticCurveType() {
48-
return NanoTDFType.ECCurve.values()[data.curveMode];
49-
}
50-
5149
public boolean isECDSABindingEnabled() {
5250
return data.useECDSABinding == 1;
5351
}
5452

55-
public String getCurveName() {
56-
return getEllipticCurveName(NanoTDFType.ECCurve.values()[data.curveMode]);
57-
}
58-
5953
public byte getECCModeAsByte() {
6054
int value = (data.useECDSABinding << 7) | data.curveMode;
6155
return (byte) value;
6256
}
6357

64-
public static String getEllipticCurveName(NanoTDFType.ECCurve curve) {
65-
switch (curve) {
66-
case SECP256R1:
67-
return "secp256r1";
68-
case SECP384R1:
69-
return "secp384r1";
70-
case SECP521R1:
71-
return "secp521r1";
72-
case SECP256K1:
73-
throw new RuntimeException("SDK doesn't support 'secp256k1' curve");
74-
default:
75-
throw new RuntimeException("Unsupported ECC algorithm.");
76-
}
77-
}
78-
79-
public static int getECKeySize(NanoTDFType.ECCurve curve) {
80-
switch (curve) {
81-
case SECP256K1:
82-
throw new RuntimeException("SDK doesn't support 'secp256k1' curve");
83-
case SECP256R1:
84-
return 32;
85-
case SECP384R1:
86-
return 48;
87-
case SECP521R1:
88-
return 66;
89-
default:
90-
throw new RuntimeException("Unsupported ECC algorithm.");
91-
}
92-
}
93-
9458
public static int getECDSASignatureStructSize(NanoTDFType.ECCurve curve) {
95-
int keySize = getECKeySize(curve);
59+
int keySize = curve.getKeySize();
9660
return (1 + keySize + 1 + keySize);
9761
}
9862

99-
public static int getECKeySize(String curveName) {
100-
return ECKeyPair.getECKeySize(curveName);
101-
}
10263

103-
public static int getECCompressedPubKeySize(NanoTDFType.ECCurve curve) {
104-
switch (curve) {
105-
case SECP256K1:
106-
throw new RuntimeException("SDK doesn't support 'secp256k1' curve");
107-
case SECP256R1:
108-
return 33;
109-
case SECP384R1:
110-
return 49;
111-
case SECP521R1:
112-
return 67;
113-
default:
114-
throw new RuntimeException("Unsupported ECC algorithm.");
115-
}
64+
@Nonnull
65+
public NanoTDFType.ECCurve getCurve() {
66+
return NanoTDFType.ECCurve.fromCurveMode(data.curveMode);
11667
}
11768

11869
private class ECCModeStruct {

sdk/src/main/java/io/opentdf/platform/sdk/ECKeyPair.java

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.*;
2525
import java.security.*;
2626
import java.security.spec.*;
27+
import java.util.Objects;
2728
// https://www.bouncycastle.org/latest_releases.html
2829

2930
public class ECKeyPair {
@@ -32,45 +33,23 @@ public class ECKeyPair {
3233
Security.addProvider(new BouncyCastleProvider());
3334
}
3435

36+
private final NanoTDFType.ECCurve curve;
37+
3538
public enum ECAlgorithm {
3639
ECDH,
3740
ECDSA
3841
}
3942

4043
private static final BouncyCastleProvider BOUNCY_CASTLE_PROVIDER = new BouncyCastleProvider();
4144

42-
public enum NanoTDFECCurve {
43-
SECP256R1("secp256r1", KeyType.EC256Key),
44-
PRIME256V1("prime256v1", KeyType.EC256Key),
45-
SECP384R1("secp384r1", KeyType.EC384Key),
46-
SECP521R1("secp521r1", KeyType.EC521Key);
47-
48-
private String name;
49-
private KeyType keyType;
50-
51-
NanoTDFECCurve(String curveName, KeyType keyType) {
52-
this.name = curveName;
53-
this.keyType = keyType;
54-
}
55-
56-
@Override
57-
public String toString() {
58-
return name;
59-
}
60-
61-
public KeyType getKeyType() {
62-
return keyType;
63-
}
64-
}
65-
6645
private KeyPair keyPair;
67-
private String curveName;
6846

6947
public ECKeyPair() {
70-
this("secp256r1", ECAlgorithm.ECDH);
48+
this(NanoTDFType.ECCurve.SECP256R1, ECAlgorithm.ECDH);
7149
}
7250

73-
public ECKeyPair(String curveName, ECAlgorithm algorithm) {
51+
public ECKeyPair(NanoTDFType.ECCurve curve, ECAlgorithm algorithm) {
52+
this.curve = Objects.requireNonNull(curve);
7453
KeyPairGenerator generator;
7554

7655
try {
@@ -85,19 +64,13 @@ public ECKeyPair(String curveName, ECAlgorithm algorithm) {
8564
throw new RuntimeException(e);
8665
}
8766

88-
ECGenParameterSpec spec = new ECGenParameterSpec(curveName);
67+
ECGenParameterSpec spec = new ECGenParameterSpec(this.curve.getCurveName());
8968
try {
9069
generator.initialize(spec);
9170
} catch (InvalidAlgorithmParameterException e) {
9271
throw new RuntimeException(e);
9372
}
9473
this.keyPair = generator.generateKeyPair();
95-
this.curveName = curveName;
96-
}
97-
98-
public ECKeyPair(ECPublicKey publicKey, ECPrivateKey privateKey, String curveName) {
99-
this.keyPair = new KeyPair(publicKey, privateKey);
100-
this.curveName = curveName;
10174
}
10275

10376
public ECPublicKey getPublicKey() {
@@ -108,17 +81,8 @@ public ECPrivateKey getPrivateKey() {
10881
return (ECPrivateKey) this.keyPair.getPrivate();
10982
}
11083

111-
public static int getECKeySize(String curveName) {
112-
if (curveName.equalsIgnoreCase(NanoTDFECCurve.SECP256R1.toString()) ||
113-
curveName.equalsIgnoreCase(NanoTDFECCurve.PRIME256V1.toString())) {
114-
return 32;
115-
} else if (curveName.equalsIgnoreCase(NanoTDFECCurve.SECP384R1.toString())) {
116-
return 48;
117-
} else if (curveName.equalsIgnoreCase(NanoTDFECCurve.SECP521R1.toString())) {
118-
return 66;
119-
} else {
120-
throw new IllegalArgumentException("Unsupported ECC algorithm.");
121-
}
84+
NanoTDFType.ECCurve getCurve() {
85+
return this.curve;
12286
}
12387

12488
public String publicKeyInPEMFormat() {
@@ -155,10 +119,6 @@ public int keySize() {
155119
return this.keyPair.getPrivate().getEncoded().length * 8;
156120
}
157121

158-
public String curveName() {
159-
return this.curveName;
160-
}
161-
162122
public byte[] compressECPublickey() {
163123
return ((ECPublicKey) this.keyPair.getPublic()).getQ().getEncoded(true);
164124
}

0 commit comments

Comments
 (0)