Skip to content

Commit 0f47702

Browse files
authored
fix(sdk): group splits with empty/missing split IDs together (#217)
Covered by [a new xtest](opentdf/tests#240)
1 parent e076d11 commit 0f47702

File tree

1 file changed

+12
-18
lines changed
  • sdk/src/main/java/io/opentdf/platform/sdk

1 file changed

+12
-18
lines changed

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

+12-18
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
*/
3838
public class TDF {
3939

40+
private static final String EMPTY_SPLIT_ID = "";
4041
private static final String TDF_VERSION = "4.3.0";
4142
private static final String KEY_ACCESS_SECHMA_VERSION = "4.3.0";
4243
private final long maximumSize;
@@ -607,29 +608,22 @@ public Reader loadTDF(SeekableByteChannel tdf, SDK.KAS kas,
607608
Set<String> foundSplits = new HashSet<>();
608609

609610
Map<Autoconfigure.KeySplitStep, Exception> skippedSplits = new HashMap<>();
610-
boolean mixedSplits = manifest.encryptionInformation.keyAccessObj.size() > 1 &&
611-
(manifest.encryptionInformation.keyAccessObj.get(0).sid != null) &&
612-
!manifest.encryptionInformation.keyAccessObj.get(0).sid.isEmpty();
613-
614611
MessageDigest digest = MessageDigest.getInstance("SHA-256");
615612

616613
if (manifest.payload.isEncrypted) {
617614
for (Manifest.KeyAccess keyAccess : manifest.encryptionInformation.keyAccessObj) {
618-
Autoconfigure.KeySplitStep ss = new Autoconfigure.KeySplitStep(keyAccess.url, keyAccess.sid);
615+
String splitId = keyAccess.sid == null || keyAccess.sid.isEmpty() ? EMPTY_SPLIT_ID : keyAccess.sid;
616+
Autoconfigure.KeySplitStep ss = new Autoconfigure.KeySplitStep(keyAccess.url, splitId);
619617
byte[] unwrappedKey;
620-
if (!mixedSplits) {
618+
if (foundSplits.contains(ss.splitID)) {
619+
continue;
620+
}
621+
knownSplits.add(ss.splitID);
622+
try {
621623
unwrappedKey = kas.unwrap(keyAccess, manifest.encryptionInformation.policy);
622-
} else {
623-
if (foundSplits.contains(ss.splitID)) {
624-
continue;
625-
}
626-
knownSplits.add(ss.splitID);
627-
try {
628-
unwrappedKey = kas.unwrap(keyAccess, manifest.encryptionInformation.policy);
629-
} catch (Exception e) {
630-
skippedSplits.put(ss, e);
631-
continue;
632-
}
624+
} catch (Exception e) {
625+
skippedSplits.put(ss, e);
626+
continue;
633627
}
634628

635629
for (int index = 0; index < unwrappedKey.length; index++) {
@@ -656,7 +650,7 @@ public Reader loadTDF(SeekableByteChannel tdf, SDK.KAS kas,
656650
}
657651
}
658652

659-
if (mixedSplits && knownSplits.size() > foundSplits.size()) {
653+
if (knownSplits.size() > foundSplits.size()) {
660654
List<Exception> exceptionList = new ArrayList<>(skippedSplits.size() + 1);
661655
exceptionList.add(new Exception("splitKey.unable to reconstruct split key: " + skippedSplits));
662656

0 commit comments

Comments
 (0)