Gargi-jais11 commented on code in PR #11222:
URL: https://github.com/apache/ozone/pull/11222#discussion_r4068692935


##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/signature/ChunksValidator.java:
##########
@@ -101,15 +103,34 @@ public void validateChunk(String chunkSignature, String 
payloadSha256Hex)
     String stringToSign = String.join(NEWLINE,
         CHUNK_STRING_TO_SIGN_ALGORITHM, dateTime, credentialScope,
         previousSignature, EMPTY_STRING_SHA256, payloadSha256Hex);
+    validateSignature(chunkSignature, stringToSign);
+    // The chain feeds this chunk's signature, in hex, into the next chunk's 
string-to-sign.
+    // chunkSignature equals expected (verified above), so reuse it normalized 
to lower-case.
+    previousSignature = chunkSignature.toLowerCase(Locale.ROOT);
+  }
+
+  /**
+   * Verify the signature of the trailing headers and complete the signature 
chain.
+   *
+   * @param trailerSignature the signature from the {@code 
x-amz-trailer-signature} header
+   * @param trailingHeadersSha256Hex SHA-256 of the canonical trailing headers
+   * @throws OS3Exception if the computed signature does not match
+   */
+  public void validateTrailer(String trailerSignature, String 
trailingHeadersSha256Hex)
+      throws OS3Exception {
+    String stringToSign = String.join(NEWLINE,
+        TRAILER_STRING_TO_SIGN_ALGORITHM, dateTime, credentialScope,
+        previousSignature, trailingHeadersSha256Hex);
+    validateSignature(trailerSignature, stringToSign);
+  }
+
+  private void validateSignature(String signature, String stringToSign) {
     byte[] expected = hmacSha256(stringToSign);
     // Constant-time comparison to avoid leaking the signature via timing. 
Decoding the hex also
     // makes the comparison case-insensitive, as the signature may be sent in 
either case.
-    if (!MessageDigest.isEqual(expected, 
DatatypeConverter.parseHexBinary(chunkSignature))) {
+    if (!MessageDigest.isEqual(expected, 
DatatypeConverter.parseHexBinary(signature))) {

Review Comment:
   Please wrap decode in try/catch.



-- 
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]

Reply via email to