Skip to content

Commit

Permalink
Validate tagmanifest of ocrdzip with sha512sum
Browse files Browse the repository at this point in the history
  • Loading branch information
joschrew committed Apr 23, 2024
1 parent d430659 commit 6a5497a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/main/java/ola/hd/longtermstorage/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class Constants {
public static final String BAGINFO_KEY_IS_GT = "Olahd-GT";

public static final String PAYLOAD_MANIFEST_NAME = "manifest-sha512.txt";
public static final String TAG_MANIFEST_NAME = "tagmanifest-sha512.txt";

private Constants() {
//pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,13 @@ public static List<AbstractMap.SimpleImmutableEntry<String, String>> extractAndV
MandatoryVerifier.checkBagitFileExists(bag.getRootDir(), bag.getVersion());
MandatoryVerifier.checkPayloadDirectoryExists(bag);
MandatoryVerifier.checkIfAtLeastOnePayloadManifestsExist(bag.getRootDir(), bag.getVersion());
// TODO: generate and verify payload-manifest: manifest-sha512.txt is mandatory for ocrdzip. The
// sha512sum of this file is in tagmanifest-sha512.txt. Validate that this sum fits
}
// This is the old way of validating the bagit
//verifier.isValid(bag, true);

// Validate with external command sha512sum
Validation.validatePayloadChecksums(destination);
Validation.validateTagmanifestChecksums(destination);

// Check for the validity and completeness of a bag
Validation.validateOcrdzip(bag, destination, params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,33 @@ public static void validatePayloadChecksums(Path destination) {
}
}

/**
* Validate tagmanifest-sha512.txt if it exists
*
* @param destination - Path to unpacked root of bagit
*/
public static void validateTagmanifestChecksums(Path destination) {
Path tagmanifest = destination.resolve(Constants.TAG_MANIFEST_NAME);
if (!Files.exists(tagmanifest)) {
return;
}

String[] cmd = new String[] { "/usr/bin/sha512sum", "--status", "-c", tagmanifest.toString() };
Process proc;
int exitCode = -1;
try {
proc = Runtime.getRuntime().exec(cmd, null, destination.toFile());
exitCode = proc.waitFor();
} catch (Exception e) {
throw new PayloadSumException("Executing external command for tagmanifest verification failed", e);
}
if (exitCode == 1) {
throw new PayloadSumException(
String.format("Checksums in %s do not match", Constants.TAG_MANIFEST_NAME)
);
} else if (exitCode != 0) {
throw new PayloadSumException("Tag-Manifest-Validation failed");
}
}

}

0 comments on commit 6a5497a

Please sign in to comment.