Date: Thu, 16 May 2024 13:21:24 -0400
Subject: [PATCH 14/16] fix: Base64 decoding to discard newline characters
(#1941)
* fix: Base64 decoding to discard newline characters
* adding test case for "+" character and new line character
* test case with the slash character
---
.../com/google/api/client/util/Base64.java | 14 +++-
.../google/api/client/util/Base64Test.java | 71 +++++++++++++++++++
2 files changed, 83 insertions(+), 2 deletions(-)
diff --git a/google-http-client/src/main/java/com/google/api/client/util/Base64.java b/google-http-client/src/main/java/com/google/api/client/util/Base64.java
index 9225cd5dd..178bc4829 100644
--- a/google-http-client/src/main/java/com/google/api/client/util/Base64.java
+++ b/google-http-client/src/main/java/com/google/api/client/util/Base64.java
@@ -26,6 +26,13 @@
*/
@Deprecated
public class Base64 {
+ // Guava's Base64 (https://datatracker.ietf.org/doc/html/rfc4648#section-4) decoders. When
+ // decoding, they discard the new line character so that the behavior matches what we had with
+ // Apache Commons Codec's decodeBase64.
+ // The 2nd argument of the withSeparator method, "64", does not have any effect in decoding.
+ private static final BaseEncoding BASE64_DECODER = BaseEncoding.base64().withSeparator("\n", 64);
+ private static final BaseEncoding BASE64URL_DECODER =
+ BaseEncoding.base64Url().withSeparator("\n", 64);
/**
* Encodes binary data using the base64 algorithm but does not chunk the output.
@@ -92,6 +99,9 @@ public static byte[] decodeBase64(byte[] base64Data) {
* Decodes a Base64 String into octets. Note that this method handles both URL-safe and
* non-URL-safe base 64 encoded strings.
*
+ * For the compatibility with the old version that used Apache Commons Coded's decodeBase64,
+ * this method discards new line characters and trailing whitespaces.
+ *
* @param base64String String containing Base64 data or {@code null} for {@code null} result
* @return Array containing decoded data or {@code null} for {@code null} input
*/
@@ -100,10 +110,10 @@ public static byte[] decodeBase64(String base64String) {
return null;
}
try {
- return BaseEncoding.base64().decode(base64String);
+ return BASE64_DECODER.decode(base64String);
} catch (IllegalArgumentException e) {
if (e.getCause() instanceof DecodingException) {
- return BaseEncoding.base64Url().decode(base64String.trim());
+ return BASE64URL_DECODER.decode(base64String.trim());
}
throw e;
}
diff --git a/google-http-client/src/test/java/com/google/api/client/util/Base64Test.java b/google-http-client/src/test/java/com/google/api/client/util/Base64Test.java
index 0ee174f9f..218dd1f1b 100644
--- a/google-http-client/src/test/java/com/google/api/client/util/Base64Test.java
+++ b/google-http-client/src/test/java/com/google/api/client/util/Base64Test.java
@@ -14,6 +14,8 @@
package com.google.api.client.util;
+import static com.google.common.truth.Truth.assertThat;
+
import java.nio.charset.StandardCharsets;
import junit.framework.TestCase;
@@ -62,4 +64,73 @@ public void test_encodeBase64URLSafe_withNull_shouldReturnNull() {
public void test_encodeBase64_withNull_shouldReturnNull() {
assertNull(Base64.encodeBase64(null));
}
+
+ public void test_decodeBase64_newline_character_invalid_length() {
+ // The RFC 4648 (https://datatracker.ietf.org/doc/html/rfc4648#section-3.3) states that a
+ // specification referring to the Base64 encoding may state that it ignores characters outside
+ // the base alphabet.
+
+ // In Base64 encoding, 3 characters (24 bits) are converted to 4 of 6-bits, each of which is
+ // converted to a byte (a character).
+ // Base64encode("abc") => "YWJj" (4 characters)
+ // Base64encode("def") => "ZGVm" (4 characters)
+ // Adding a new line character between them. This should be discarded.
+ String encodedString = "YWJj\nZGVm";
+
+ // This is a reference implementation by Apache Commons Codec. It discards the new line
+ // characters.
+ // assertEquals(
+ // "abcdef",
+ // new String(
+ // org.apache.commons.codec.binary.Base64.decodeBase64(encodedString),
+ // StandardCharsets.UTF_8));
+
+ // This is our implementation. Before the
+ // https://github.com/googleapis/google-http-java-client/pull/1941/, it was throwing
+ // IllegalArgumentException("Invalid length 9").
+ assertEquals("abcdef", new String(Base64.decodeBase64(encodedString), StandardCharsets.UTF_8));
+ }
+
+ public void test_decodeBase64_newline_character() {
+ // In Base64 encoding, 2 characters (16 bits) are converted to 3 of 6-bits plus the padding
+ // character ('=").
+ // Base64encode("ab") => "YWI=" (3 characters + padding character)
+ // Adding a new line character that should be discarded between them
+ String encodedString = "YW\nI=";
+
+ // This is a reference implementation by Apache Commons Codec. It discards the new line
+ // characters.
+ // assertEquals(
+ // "ab",
+ // new String(
+ // org.apache.commons.codec.binary.Base64.decodeBase64(encodedString),
+ // StandardCharsets.UTF_8));
+
+ // This is our implementation. Before the fix
+ // https://github.com/googleapis/google-http-java-client/pull/1941/, it was throwing
+ // IllegalArgumentException("Unrecognized character: 0xa").
+ assertEquals("ab", new String(Base64.decodeBase64(encodedString), StandardCharsets.UTF_8));
+ }
+
+ public void test_decodeBase64_plus_and_newline_characters() {
+ // The plus sign is 62 in the Base64 table. So it's a valid character in encoded strings.
+ // https://datatracker.ietf.org/doc/html/rfc4648#section-4
+ String encodedString = "+\nw==";
+
+ byte[] actual = Base64.decodeBase64(encodedString);
+ // Before the fix https://github.com/googleapis/google-http-java-client/pull/1941/, it was
+ // throwing IllegalArgumentException("Unrecognized character: +").
+ assertThat(actual).isEqualTo(new byte[] {(byte) 0xfb});
+ }
+
+ public void test_decodeBase64_slash_and_newline_characters() {
+ // The slash sign is 63 in the Base64 table. So it's a valid character in encoded strings.
+ // https://datatracker.ietf.org/doc/html/rfc4648#section-4
+ String encodedString = "/\nw==";
+
+ byte[] actual = Base64.decodeBase64(encodedString);
+ // Before the fix https://github.com/googleapis/google-http-java-client/pull/1941/, it was
+ // throwing IllegalArgumentException("Unrecognized character: /").
+ assertThat(actual).isEqualTo(new byte[] {(byte) 0xff});
+ }
}
From 1538b9df467fc2c31188a9988d3aa6a87068dc0b Mon Sep 17 00:00:00 2001
From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com>
Date: Thu, 16 May 2024 15:06:06 -0400
Subject: [PATCH 15/16] chore: update dependency versions in java templates
(#1964) (#1940)
* chore: update dependency versions in java templates
* update other templates
Source-Link: https://github.com/googleapis/synthtool/commit/0b86c72fe652dd7e52ba05a63f61bc1399ad5d65
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-java:latest@sha256:68ba5f5164a4b55529d358bb262feaa000536a0c62980727dd05a91bbb47ea5e
Co-authored-by: Owl Bot
---
.github/.OwlBot.lock.yaml | 4 ++--
.github/workflows/approve-readme.yaml | 2 +-
.github/workflows/renovate_config_check.yaml | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml
index db1099bec..5db36a5f7 100644
--- a/.github/.OwlBot.lock.yaml
+++ b/.github/.OwlBot.lock.yaml
@@ -13,5 +13,5 @@
# limitations under the License.
docker:
image: gcr.io/cloud-devrel-public-resources/owlbot-java:latest
- digest: sha256:084ad4c60551b075846bcb2405ec1c14b0d00ec1eb5503d4dd0d2a92cdc2d3e2
-# created: 2024-03-15T14:33:32.257974519Z
+ digest: sha256:68ba5f5164a4b55529d358bb262feaa000536a0c62980727dd05a91bbb47ea5e
+# created: 2024-05-09T16:31:37.168667071Z
diff --git a/.github/workflows/approve-readme.yaml b/.github/workflows/approve-readme.yaml
index f5fc7d516..59f00b8eb 100644
--- a/.github/workflows/approve-readme.yaml
+++ b/.github/workflows/approve-readme.yaml
@@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-latest
if: github.repository_owner == 'googleapis' && github.head_ref == 'autosynth-readme'
steps:
- - uses: actions/github-script@v6
+ - uses: actions/github-script@v7
with:
github-token: ${{secrets.YOSHI_APPROVER_TOKEN}}
script: |
diff --git a/.github/workflows/renovate_config_check.yaml b/.github/workflows/renovate_config_check.yaml
index 87d8eb2be..7c5ec7865 100644
--- a/.github/workflows/renovate_config_check.yaml
+++ b/.github/workflows/renovate_config_check.yaml
@@ -14,7 +14,7 @@ jobs:
uses: actions/checkout@v4
- name: Set up Node.js
- uses: actions/setup-node@v3
+ uses: actions/setup-node@v4
with:
node-version: '20'
From a82b18e46ff85eaf5ca8b6dada01ace70c5655e2 Mon Sep 17 00:00:00 2001
From: "release-please[bot]"
<55107282+release-please[bot]@users.noreply.github.com>
Date: Thu, 16 May 2024 15:08:43 -0400
Subject: [PATCH 16/16] chore(main): release 1.44.2 (#1930)
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
---
CHANGELOG.md | 15 ++++++++++
google-http-client-android-test/pom.xml | 6 ++--
google-http-client-android/pom.xml | 4 +--
google-http-client-apache-v2/pom.xml | 4 +--
google-http-client-appengine/pom.xml | 4 +--
google-http-client-assembly/pom.xml | 4 +--
google-http-client-bom/pom.xml | 22 +++++++--------
google-http-client-findbugs/pom.xml | 4 +--
google-http-client-gson/pom.xml | 4 +--
google-http-client-jackson2/pom.xml | 4 +--
google-http-client-protobuf/pom.xml | 4 +--
google-http-client-test/pom.xml | 4 +--
google-http-client-xml/pom.xml | 4 +--
google-http-client/pom.xml | 4 +--
pom.xml | 4 +--
.../dailymotion-simple-cmdline-sample/pom.xml | 2 +-
versions.txt | 28 +++++++++----------
17 files changed, 68 insertions(+), 53 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9d6cf6ea4..4cb4c04d2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,20 @@
# Changelog
+## [1.44.2](https://github.com/googleapis/google-http-java-client/compare/v1.44.1...v1.44.2) (2024-05-16)
+
+
+### Bug Fixes
+
+* Base64 decoding to discard newline characters ([#1941](https://github.com/googleapis/google-http-java-client/issues/1941)) ([4e153db](https://github.com/googleapis/google-http-java-client/commit/4e153db9443832dbe6ca56b6fe10dcea26921b6f))
+
+
+### Dependencies
+
+* Update actions/upload-artifact action to v3.1.3 ([#1860](https://github.com/googleapis/google-http-java-client/issues/1860)) ([60deab2](https://github.com/googleapis/google-http-java-client/commit/60deab2fc93c70f4f37733a90a07b11e19b9f508))
+* Update dependency com.google.cloud:native-image-shared-config to v1.7.6 ([#1928](https://github.com/googleapis/google-http-java-client/issues/1928)) ([3dd6b79](https://github.com/googleapis/google-http-java-client/commit/3dd6b79368dd31efaf293009e8f424c905e9cc38))
+* Update dependency org.apache.felix:maven-bundle-plugin to v5.1.9 ([#1888](https://github.com/googleapis/google-http-java-client/issues/1888)) ([41c16b9](https://github.com/googleapis/google-http-java-client/commit/41c16b9334e218412826c1c07cdd303611bc7dbf))
+* Update project.appengine.version to v2.0.25 ([#1931](https://github.com/googleapis/google-http-java-client/issues/1931)) ([53eb6a1](https://github.com/googleapis/google-http-java-client/commit/53eb6a1f62d106190cc75af1e6b6eebec481f874))
+
## [1.44.1](https://github.com/googleapis/google-http-java-client/compare/v1.44.0...v1.44.1) (2024-01-26)
diff --git a/google-http-client-android-test/pom.xml b/google-http-client-android-test/pom.xml
index 866d2f1bd..372af1f53 100644
--- a/google-http-client-android-test/pom.xml
+++ b/google-http-client-android-test/pom.xml
@@ -4,7 +4,7 @@
google-http-client
google-http-client-android-test
Test project for google-http-client-android.
- 1.44.2-SNAPSHOT
+ 1.44.2
apk
@@ -53,7 +53,7 @@
com.google.http-client
google-http-client-android
- 1.44.2-SNAPSHOT
+ 1.44.2
android
@@ -72,7 +72,7 @@
com.google.http-client
google-http-client-test
- 1.44.2-SNAPSHOT
+ 1.44.2
junit
diff --git a/google-http-client-android/pom.xml b/google-http-client-android/pom.xml
index 720c3c91e..fadc64cb6 100644
--- a/google-http-client-android/pom.xml
+++ b/google-http-client-android/pom.xml
@@ -4,11 +4,11 @@
com.google.http-client
google-http-client-parent
- 1.44.2-SNAPSHOT
+ 1.44.2
../pom.xml
google-http-client-android
- 1.44.2-SNAPSHOT
+ 1.44.2
Android Platform Extensions to the Google HTTP Client Library for Java.
diff --git a/google-http-client-apache-v2/pom.xml b/google-http-client-apache-v2/pom.xml
index 0338037f9..55676873b 100644
--- a/google-http-client-apache-v2/pom.xml
+++ b/google-http-client-apache-v2/pom.xml
@@ -4,11 +4,11 @@
com.google.http-client
google-http-client-parent
- 1.44.2-SNAPSHOT
+ 1.44.2
../pom.xml
google-http-client-apache-v2
- 1.44.2-SNAPSHOT
+ 1.44.2
Apache HTTP transport v2 for the Google HTTP Client Library for Java.
diff --git a/google-http-client-appengine/pom.xml b/google-http-client-appengine/pom.xml
index 91bc10bf4..20ebf8f84 100644
--- a/google-http-client-appengine/pom.xml
+++ b/google-http-client-appengine/pom.xml
@@ -4,11 +4,11 @@
com.google.http-client
google-http-client-parent
- 1.44.2-SNAPSHOT
+ 1.44.2
../pom.xml
google-http-client-appengine
- 1.44.2-SNAPSHOT
+ 1.44.2
Google App Engine extensions to the Google HTTP Client Library for Java.
diff --git a/google-http-client-assembly/pom.xml b/google-http-client-assembly/pom.xml
index 21c266f23..f2cc29862 100644
--- a/google-http-client-assembly/pom.xml
+++ b/google-http-client-assembly/pom.xml
@@ -4,12 +4,12 @@
com.google.http-client
google-http-client-parent
- 1.44.2-SNAPSHOT
+ 1.44.2
../pom.xml
com.google.http-client
google-http-client-assembly
- 1.44.2-SNAPSHOT
+ 1.44.2
pom
Assembly for the Google HTTP Client Library for Java
diff --git a/google-http-client-bom/pom.xml b/google-http-client-bom/pom.xml
index 108ac5e9f..92ba7375c 100644
--- a/google-http-client-bom/pom.xml
+++ b/google-http-client-bom/pom.xml
@@ -3,7 +3,7 @@
4.0.0
com.google.http-client
google-http-client-bom
- 1.44.2-SNAPSHOT
+ 1.44.2
pom
Google HTTP Client Library for Java BOM
@@ -63,52 +63,52 @@
com.google.http-client
google-http-client
- 1.44.2-SNAPSHOT
+ 1.44.2
com.google.http-client
google-http-client-android
- 1.44.2-SNAPSHOT
+ 1.44.2
com.google.http-client
google-http-client-apache-v2
- 1.44.2-SNAPSHOT
+ 1.44.2
com.google.http-client
google-http-client-appengine
- 1.44.2-SNAPSHOT
+ 1.44.2
com.google.http-client
google-http-client-findbugs
- 1.44.2-SNAPSHOT
+ 1.44.2
com.google.http-client
google-http-client-gson
- 1.44.2-SNAPSHOT
+ 1.44.2
com.google.http-client
google-http-client-jackson2
- 1.44.2-SNAPSHOT
+ 1.44.2
com.google.http-client
google-http-client-protobuf
- 1.44.2-SNAPSHOT
+ 1.44.2
com.google.http-client
google-http-client-test
- 1.44.2-SNAPSHOT
+ 1.44.2
com.google.http-client
google-http-client-xml
- 1.44.2-SNAPSHOT
+ 1.44.2
diff --git a/google-http-client-findbugs/pom.xml b/google-http-client-findbugs/pom.xml
index c6ef961ae..320dd3d38 100644
--- a/google-http-client-findbugs/pom.xml
+++ b/google-http-client-findbugs/pom.xml
@@ -4,11 +4,11 @@
com.google.http-client
google-http-client-parent
- 1.44.2-SNAPSHOT
+ 1.44.2
../pom.xml
google-http-client-findbugs
- 1.44.2-SNAPSHOT
+ 1.44.2
Google APIs Client Library Findbugs custom plugin.
diff --git a/google-http-client-gson/pom.xml b/google-http-client-gson/pom.xml
index 15fc1d51a..9aec75be0 100644
--- a/google-http-client-gson/pom.xml
+++ b/google-http-client-gson/pom.xml
@@ -4,11 +4,11 @@
com.google.http-client
google-http-client-parent
- 1.44.2-SNAPSHOT
+ 1.44.2
../pom.xml
google-http-client-gson
- 1.44.2-SNAPSHOT
+ 1.44.2
GSON extensions to the Google HTTP Client Library for Java.
diff --git a/google-http-client-jackson2/pom.xml b/google-http-client-jackson2/pom.xml
index 05a06c4fd..62b449911 100644
--- a/google-http-client-jackson2/pom.xml
+++ b/google-http-client-jackson2/pom.xml
@@ -4,11 +4,11 @@
com.google.http-client
google-http-client-parent
- 1.44.2-SNAPSHOT
+ 1.44.2
../pom.xml
google-http-client-jackson2
- 1.44.2-SNAPSHOT
+ 1.44.2
Jackson 2 extensions to the Google HTTP Client Library for Java.
diff --git a/google-http-client-protobuf/pom.xml b/google-http-client-protobuf/pom.xml
index de94f1eb6..01bba38f4 100644
--- a/google-http-client-protobuf/pom.xml
+++ b/google-http-client-protobuf/pom.xml
@@ -4,11 +4,11 @@
com.google.http-client
google-http-client-parent
- 1.44.2-SNAPSHOT
+ 1.44.2
../pom.xml
google-http-client-protobuf
- 1.44.2-SNAPSHOT
+ 1.44.2
Protocol Buffer extensions to the Google HTTP Client Library for Java.
diff --git a/google-http-client-test/pom.xml b/google-http-client-test/pom.xml
index 595e690cb..1fc9bd0db 100644
--- a/google-http-client-test/pom.xml
+++ b/google-http-client-test/pom.xml
@@ -4,11 +4,11 @@
com.google.http-client
google-http-client-parent
- 1.44.2-SNAPSHOT
+ 1.44.2
../pom.xml
google-http-client-test
- 1.44.2-SNAPSHOT
+ 1.44.2
Shared classes used for testing of artifacts in the Google HTTP Client Library for Java.
diff --git a/google-http-client-xml/pom.xml b/google-http-client-xml/pom.xml
index 744a83e52..b5b5358c5 100644
--- a/google-http-client-xml/pom.xml
+++ b/google-http-client-xml/pom.xml
@@ -4,11 +4,11 @@
com.google.http-client
google-http-client-parent
- 1.44.2-SNAPSHOT
+ 1.44.2
../pom.xml
google-http-client-xml
- 1.44.2-SNAPSHOT
+ 1.44.2
XML extensions to the Google HTTP Client Library for Java.
diff --git a/google-http-client/pom.xml b/google-http-client/pom.xml
index 0c941e940..f5995ab1d 100644
--- a/google-http-client/pom.xml
+++ b/google-http-client/pom.xml
@@ -4,11 +4,11 @@
com.google.http-client
google-http-client-parent
- 1.44.2-SNAPSHOT
+ 1.44.2
../pom.xml
google-http-client
- 1.44.2-SNAPSHOT
+ 1.44.2
Google HTTP Client Library for Java
Google HTTP Client Library for Java. Functionality that works on all supported Java platforms,
diff --git a/pom.xml b/pom.xml
index 495ecf2fb..5d1bcaca9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
com.google.http-client
google-http-client-parent
- 1.44.2-SNAPSHOT
+ 1.44.2
pom
Parent for the Google HTTP Client Library for Java
Google HTTP Client Library for Java
@@ -592,7 +592,7 @@
- google-api-java-client/google-api-client-assembly/android-properties (make the filenames match the version here)
- Internally, update the default features.json file
-->
- 1.44.2-SNAPSHOT
+ 1.44.2
2.0.25
UTF-8
3.0.2
diff --git a/samples/dailymotion-simple-cmdline-sample/pom.xml b/samples/dailymotion-simple-cmdline-sample/pom.xml
index 25021bca0..58722fcdd 100644
--- a/samples/dailymotion-simple-cmdline-sample/pom.xml
+++ b/samples/dailymotion-simple-cmdline-sample/pom.xml
@@ -4,7 +4,7 @@
com.google.http-client
google-http-client-parent
- 1.44.2-SNAPSHOT
+ 1.44.2
../../pom.xml
dailymotion-simple-cmdline-sample
diff --git a/versions.txt b/versions.txt
index 59ea2f4a7..cad4285a1 100644
--- a/versions.txt
+++ b/versions.txt
@@ -1,17 +1,17 @@
# Format:
# module:released-version:current-version
-google-http-client:1.44.1:1.44.2-SNAPSHOT
-google-http-client-bom:1.44.1:1.44.2-SNAPSHOT
-google-http-client-parent:1.44.1:1.44.2-SNAPSHOT
-google-http-client-android:1.44.1:1.44.2-SNAPSHOT
-google-http-client-android-test:1.44.1:1.44.2-SNAPSHOT
-google-http-client-apache-v2:1.44.1:1.44.2-SNAPSHOT
-google-http-client-appengine:1.44.1:1.44.2-SNAPSHOT
-google-http-client-assembly:1.44.1:1.44.2-SNAPSHOT
-google-http-client-findbugs:1.44.1:1.44.2-SNAPSHOT
-google-http-client-gson:1.44.1:1.44.2-SNAPSHOT
-google-http-client-jackson2:1.44.1:1.44.2-SNAPSHOT
-google-http-client-protobuf:1.44.1:1.44.2-SNAPSHOT
-google-http-client-test:1.44.1:1.44.2-SNAPSHOT
-google-http-client-xml:1.44.1:1.44.2-SNAPSHOT
+google-http-client:1.44.2:1.44.2
+google-http-client-bom:1.44.2:1.44.2
+google-http-client-parent:1.44.2:1.44.2
+google-http-client-android:1.44.2:1.44.2
+google-http-client-android-test:1.44.2:1.44.2
+google-http-client-apache-v2:1.44.2:1.44.2
+google-http-client-appengine:1.44.2:1.44.2
+google-http-client-assembly:1.44.2:1.44.2
+google-http-client-findbugs:1.44.2:1.44.2
+google-http-client-gson:1.44.2:1.44.2
+google-http-client-jackson2:1.44.2:1.44.2
+google-http-client-protobuf:1.44.2:1.44.2
+google-http-client-test:1.44.2:1.44.2
+google-http-client-xml:1.44.2:1.44.2