diff --git a/pom.xml b/pom.xml index 8451b89fc4..43d94b4471 100644 --- a/pom.xml +++ b/pom.xml @@ -64,6 +64,8 @@ 6.11.0 2.13.0 3.2.6 + 1.41.8 + 1.33.3 0.7.1 hadoop3-2.2.21 2.18.3 @@ -74,13 +76,15 @@ 1.24.7 2.3.0 1.105.1 - 3.19.4 + 3.25.5 1.3.0-rc3 + 20260719 27.0.1-jre 3.3.6 2.6.6-hadoop3 - 4.5.13 - 2.13.4.2 + 4.5.14 + 4.4.16 + 2.18.12 4.13.1 2.0.2 1.7.5 @@ -92,6 +96,41 @@ + + + com.fasterxml.jackson + jackson-bom + ${jackson.core.version} + pom + import + + + + com.google.protobuf + protobuf-bom + ${google.protobuf.java.version} + pom + import + + + + com.google.http-client + google-http-client-bom + ${google.http.client.version} + pom + import + + + com.google.oauth-client + google-oauth-client + ${google.oauth.client.version} + + + + org.json + json + ${org.json.version} + com.google.apis google-api-services-bigquery @@ -102,6 +141,16 @@ google-api-services-storage v1-rev20211201-1.32.1 + + org.apache.httpcomponents + httpclient + ${httpclient.version} + + + org.apache.httpcomponents + httpcore + ${httpcore.version} + @@ -613,6 +662,16 @@ avro-mapred ${avro.version} + + + org.apache.avro + avro-ipc + + + org.apache.avro + avro-ipc-jetty + com.fasterxml.jackson.core jackson-core @@ -766,7 +825,7 @@ org.xerial.snappy snappy-java - 1.1.10.5 + 1.1.10.12 diff --git a/src/test/java/io/cdap/plugin/gcp/gcs/source/TinkKeysetJsonTest.java b/src/test/java/io/cdap/plugin/gcp/gcs/source/TinkKeysetJsonTest.java new file mode 100644 index 0000000000..8231b745e4 --- /dev/null +++ b/src/test/java/io/cdap/plugin/gcp/gcs/source/TinkKeysetJsonTest.java @@ -0,0 +1,93 @@ +/* + * Copyright © 2026 Cask Data, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package io.cdap.plugin.gcp.gcs.source; + +import com.google.common.io.ByteStreams; +import com.google.crypto.tink.Aead; +import com.google.crypto.tink.JsonKeysetReader; +import com.google.crypto.tink.JsonKeysetWriter; +import com.google.crypto.tink.KeysetHandle; +import com.google.crypto.tink.StreamingAead; +import com.google.crypto.tink.aead.AeadConfig; +import com.google.crypto.tink.aead.AeadKeyTemplates; +import com.google.crypto.tink.streamingaead.StreamingAeadConfig; +import com.google.crypto.tink.streamingaead.StreamingAeadKeyTemplates; +import org.json.JSONObject; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Base64; + +import static java.nio.charset.StandardCharsets.UTF_8; + +/** + * Checks that the encryption metadata written by {@link GCSTinkTool} can be parsed with org.json and read back by + * Tink the same way {@link TinkDecryptor} does. A local AEAD key stands in for the Cloud KMS key. + */ +public class TinkKeysetJsonTest { + + private static final int ITERATIONS = 10; + + @BeforeClass + public static void setupClass() throws Exception { + AeadConfig.register(); + StreamingAeadConfig.register(); + } + + @Test + public void testMetadataRoundTrip() throws Exception { + Aead keysetAead = KeysetHandle.generateNew(AeadKeyTemplates.AES128_GCM).getPrimitive(Aead.class); + byte[] plaintext = "some plaintext to encrypt".getBytes(UTF_8); + byte[] associatedData = "gs://bucket/path/file.csv".getBytes(UTF_8); + + // Each iteration uses a new keyset, so different random key ids go through the JSON round trip. + for (int i = 0; i < ITERATIONS; i++) { + KeysetHandle handle = KeysetHandle.generateNew(StreamingAeadKeyTemplates.AES256_GCM_HKDF_4KB); + + // Encrypt and write the metadata the same way as GCSTinkTool. + ByteArrayOutputStream ciphertext = new ByteArrayOutputStream(); + try (OutputStream os = handle.getPrimitive(StreamingAead.class).newEncryptingStream(ciphertext, + associatedData)) { + os.write(plaintext); + } + ByteArrayOutputStream keyset = new ByteArrayOutputStream(); + handle.write(JsonKeysetWriter.withOutputStream(keyset), keysetAead); + JSONObject metadataObj = new JSONObject(); + metadataObj.put("kms", "gcp-kms://projects/p/locations/global/keyRings/r/cryptoKeys/k"); + metadataObj.put("aad", Base64.getEncoder().encodeToString(associatedData)); + metadataObj.put("keyset", new JSONObject(new String(keyset.toByteArray(), UTF_8))); + String metadataJson = metadataObj.toString(4); + + // Parse and read it back the same way as TinkDecryptor. + JSONObject metadata = new JSONObject(metadataJson); + KeysetHandle readHandle = KeysetHandle.read(JsonKeysetReader.withJsonObject(metadata.getJSONObject("keyset")), + keysetAead); + byte[] aad = Base64.getDecoder().decode(metadata.getString("aad")); + Assert.assertEquals(handle.getKeysetInfo().getPrimaryKeyId(), readHandle.getKeysetInfo().getPrimaryKeyId()); + + try (InputStream is = readHandle.getPrimitive(StreamingAead.class) + .newDecryptingStream(new ByteArrayInputStream(ciphertext.toByteArray()), aad)) { + Assert.assertArrayEquals(plaintext, ByteStreams.toByteArray(is)); + } + } + } +}