ggershinsky commented on code in PR #18220:
URL: https://github.com/apache/iceberg/pull/18220#discussion_r4366565809
##########
core/src/main/java/org/apache/iceberg/encryption/EncryptionUtil.java:
##########
@@ -202,6 +211,51 @@ static ByteBuffer encryptManifestListKeyMetadata(
return ByteBuffer.wrap(encryptedKeyMetadata);
}
+ /**
+ * Produces a base64-encoded hash of the serialized table metadata.
+ *
+ * <p>Catalogs that keep encryption parameters, such as the table key ID,
outside of the metadata
+ * file can store this hash next to them, in order to detect tampering with
a metadata file kept
+ * in a storage vulnerable to modification.
+ *
+ * @param metadata table metadata to hash
+ * @return base64-encoded hash of the metadata
+ */
+ public static String metadataHash(TableMetadata metadata) {
+ return Base64.getEncoder().encodeToString(hashOf(metadata));
+ }
+
+ /**
+ * Verifies that the table metadata loaded from storage matches a hash
produced by {@link
+ * #metadataHash(TableMetadata)} and kept in a trusted catalog.
+ *
+ * @param metadata table metadata loaded from storage
+ * @param expectedMetadataHash base64-encoded hash retrieved from the catalog
+ */
+ public static void verifyMetadataHash(TableMetadata metadata, String
expectedMetadataHash) {
+ byte[] currentHashBytes = hashOf(metadata);
Review Comment:
Looks like this is ok in this PR too, the hash calculation is done via a
HashWriter that uses streaming.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]