Skip to content

Commit dba9bbf

Browse files
fix(sdk): Support RSA4096 Kas keys (#343)
This pull request primarily enhances the SDK's cryptographic capabilities by introducing comprehensive support for RSA4096 keys, allowing for stronger encryption in Key Access Server (KAS) operations. It also refines the key retrieval process by incorporating Key IDs (KID) for better key management. ### Highlights * **RSA4096 Key Support**: Added `RSA4096Key` to the `KeyType` enum and updated its mapping methods (`fromAlgorithm`, `fromPublicKeyAlgorithm`) to correctly recognize and handle 4096-bit RSA keys for KAS operations. * **Key ID (KID) Inclusion in KASInfo**: Included the Key ID (KID) when retrieving public keys from a Key Access Server (KAS), improving key resolution and management. * **Unit Test Coverage**: Expanded unit tests in `KeyTypeTest` to ensure proper functionality and mapping for the newly introduced `RSA4096Key`.
1 parent 4660e27 commit dba9bbf

4 files changed

Lines changed: 17 additions & 5 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
public enum KeyType {
1313
RSA2048Key("rsa:2048"),
14+
RSA4096Key("rsa:4096"),
1415
EC256Key("ec:secp256r1", SECP256R1),
1516
EC384Key("ec:secp384r1", SECP384R1),
1617
EC521Key("ec:secp521r1", SECP521R1);
@@ -56,6 +57,8 @@ public static KeyType fromAlgorithm(Algorithm algorithm) {
5657
switch (algorithm) {
5758
case ALGORITHM_RSA_2048:
5859
return KeyType.RSA2048Key;
60+
case ALGORITHM_RSA_4096:
61+
return KeyType.RSA4096Key;
5962
case ALGORITHM_EC_P256:
6063
return KeyType.EC256Key;
6164
case ALGORITHM_EC_P384:
@@ -74,6 +77,8 @@ public static KeyType fromPublicKeyAlgorithm(KasPublicKeyAlgEnum algorithm) {
7477
switch (algorithm) {
7578
case KAS_PUBLIC_KEY_ALG_ENUM_RSA_2048:
7679
return KeyType.RSA2048Key;
80+
case KAS_PUBLIC_KEY_ALG_ENUM_RSA_4096:
81+
return KeyType.RSA4096Key;
7782
case KAS_PUBLIC_KEY_ALG_ENUM_EC_SECP256R1:
7883
return KeyType.EC256Key;
7984
case KAS_PUBLIC_KEY_ALG_ENUM_EC_SECP384R1:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ Map<String, List<Config.KASInfo>> resolveKeys(List<Autoconfigure.KeySplitTemplat
163163
logger.info("no public key provided for KAS at {}, retrieving", splitInfo.kas);
164164
var getKI = new Config.KASInfo();
165165
getKI.URL = splitInfo.kas;
166+
getKI.KID = splitInfo.kid;
166167
getKI.Algorithm = splitInfo.keyType == null
167168
? (tdfConfig.wrappingKeyType == null ? null : tdfConfig.wrappingKeyType.toString())
168169
: splitInfo.keyType.toString();

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

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

3-
import org.slf4j.Logger;
4-
import org.slf4j.LoggerFactory;
5-
6-
import javax.annotation.Nonnull;
7-
import javax.annotation.Nullable;
83
import java.util.Objects;
94
import java.util.Optional;
105
import java.util.regex.Pattern;
116

7+
import javax.annotation.Nonnull;
8+
import javax.annotation.Nullable;
9+
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
12+
1213
class Version implements Comparable<Version> {
1314

1415
// Version of the SDK, managed by release-please.

sdk/src/test/java/io/opentdf/platform/sdk/KeyTypeTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@
66
import static io.opentdf.platform.policy.Algorithm.ALGORITHM_EC_P384;
77
import static io.opentdf.platform.policy.Algorithm.ALGORITHM_EC_P521;
88
import static io.opentdf.platform.policy.Algorithm.ALGORITHM_RSA_2048;
9+
import static io.opentdf.platform.policy.Algorithm.ALGORITHM_RSA_4096;
910
import static io.opentdf.platform.policy.KasPublicKeyAlgEnum.KAS_PUBLIC_KEY_ALG_ENUM_EC_SECP256R1;
1011
import static io.opentdf.platform.policy.KasPublicKeyAlgEnum.KAS_PUBLIC_KEY_ALG_ENUM_EC_SECP384R1;
1112
import static io.opentdf.platform.policy.KasPublicKeyAlgEnum.KAS_PUBLIC_KEY_ALG_ENUM_EC_SECP521R1;
1213
import static io.opentdf.platform.policy.KasPublicKeyAlgEnum.KAS_PUBLIC_KEY_ALG_ENUM_RSA_2048;
14+
import static io.opentdf.platform.policy.KasPublicKeyAlgEnum.KAS_PUBLIC_KEY_ALG_ENUM_RSA_4096;
1315
import static org.junit.jupiter.api.Assertions.*;
1416

1517
class KeyTypeTest {
1618
@Test
1719
void testFromString() {
1820
assertEquals(KeyType.RSA2048Key, KeyType.fromString("rsa:2048"));
21+
assertEquals(KeyType.RSA4096Key, KeyType.fromString("rsa:4096"));
1922
assertEquals(KeyType.EC256Key, KeyType.fromString("ec:secp256r1"));
2023
assertEquals(KeyType.EC384Key, KeyType.fromString("ec:secp384r1"));
2124
assertEquals(KeyType.EC521Key, KeyType.fromString("ec:secp521r1"));
@@ -29,6 +32,7 @@ void testFromStringInvalid() {
2932
@Test
3033
void testFromAlgorithm() {
3134
assertEquals(KeyType.RSA2048Key, KeyType.fromAlgorithm(ALGORITHM_RSA_2048));
35+
assertEquals(KeyType.RSA4096Key, KeyType.fromAlgorithm(ALGORITHM_RSA_4096));
3236
assertEquals(KeyType.EC256Key, KeyType.fromAlgorithm(ALGORITHM_EC_P256));
3337
assertEquals(KeyType.EC384Key, KeyType.fromAlgorithm(ALGORITHM_EC_P384));
3438
assertEquals(KeyType.EC521Key, KeyType.fromAlgorithm(ALGORITHM_EC_P521));
@@ -37,6 +41,7 @@ void testFromAlgorithm() {
3741
@Test
3842
void testFromPublicKeyAlgEnum() {
3943
assertEquals(KeyType.RSA2048Key, KeyType.fromPublicKeyAlgorithm(KAS_PUBLIC_KEY_ALG_ENUM_RSA_2048));
44+
assertEquals(KeyType.RSA4096Key, KeyType.fromPublicKeyAlgorithm(KAS_PUBLIC_KEY_ALG_ENUM_RSA_4096));
4045
assertEquals(KeyType.EC256Key, KeyType.fromPublicKeyAlgorithm(KAS_PUBLIC_KEY_ALG_ENUM_EC_SECP256R1));
4146
assertEquals(KeyType.EC384Key, KeyType.fromPublicKeyAlgorithm(KAS_PUBLIC_KEY_ALG_ENUM_EC_SECP384R1));
4247
assertEquals(KeyType.EC521Key, KeyType.fromPublicKeyAlgorithm(KAS_PUBLIC_KEY_ALG_ENUM_EC_SECP521R1));

0 commit comments

Comments
 (0)