[java-shib-shared] branch main updated: JSSH-42 - DataSealer encryption fails on Red Hat 9 OpenJDK in FIPS mode

Scott Cantor cantor.2 at osu.edu
Mon Nov 27 14:23:28 UTC 2023


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch main
in repository java-shib-shared.

View the commit online:
http://git.shibboleth.net/view/?p=java-shib-shared.git;a=commit;h=80c313ce0dd02d6e54a6fa147ba4c7b5765878df

The following commit(s) were added to refs/heads/main by this push:
     new 80c313ce JSSH-42 - DataSealer encryption fails on Red Hat 9 OpenJDK in FIPS mode
80c313ce is described below

commit 80c313ce0dd02d6e54a6fa147ba4c7b5765878df
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Nov 27 09:23:26 2023 -0500

    JSSH-42 - DataSealer encryption fails on Red Hat 9 OpenJDK in FIPS mode
    
    https://shibboleth.atlassian.net/browse/JSSH-42
---
 .../net/shibboleth/shared/security/DataSealer.java | 27 +++++++++++-----------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/shib-security/src/main/java/net/shibboleth/shared/security/DataSealer.java b/shib-security/src/main/java/net/shibboleth/shared/security/DataSealer.java
index 0d6cbade..686c26e2 100644
--- a/shib-security/src/main/java/net/shibboleth/shared/security/DataSealer.java
+++ b/shib-security/src/main/java/net/shibboleth/shared/security/DataSealer.java
@@ -283,11 +283,10 @@ public class DataSealer extends AbstractInitializableComponent {
                 final int dataSize = inputDataStream.read(data);
 
                 final byte[] plaintext = new byte[cipher.getOutputSize(dataSize)];
-                final int outputLen = cipher.update(data, 0, dataSize, plaintext, 0);
-                cipher.doFinal(plaintext, outputLen);
+                final int outputLen = cipher.doFinal(data, 0, dataSize, plaintext);
 
                 // Pass the plaintext into the subroutine for processing.
-                return extractAndCheckDecryptedData(plaintext);
+                return extractAndCheckDecryptedData(plaintext, 0, outputLen);
             }
 
         } catch (final KeyNotFoundException e) {
@@ -310,15 +309,20 @@ public class DataSealer extends AbstractInitializableComponent {
      * Extract the GZIP'd data and test for expiration before returning it.
      * 
      * @param decryptedBytes the data we are looking at
+     * @param decryptedOffset offset into the buffer
+     * @param decryptedLen length of data in the buffer
      * 
      * @return the decoded data if it is valid and unexpired
      * @throws DataSealerException if the data cannot be unwrapped and verified
      */
-    @Nonnull private String extractAndCheckDecryptedData(@Nonnull @NotEmpty final byte[] decryptedBytes)
+    @Nonnull private String extractAndCheckDecryptedData(@Nonnull @NotEmpty final byte[] decryptedBytes,
+            final int decryptedOffset, final int decryptedLen)
             throws DataSealerException {
         
         try (final DataInputStream dataInputStream =
-                new DataInputStream(new GZIPInputStream(new ByteArrayInputStream(decryptedBytes)))) {
+                new DataInputStream(
+                        new GZIPInputStream(
+                                new ByteArrayInputStream(decryptedBytes, decryptedOffset, decryptedLen)))) {
 
             final long decodedExpirationTime = dataInputStream.readLong();
             if (decodedExpirationTime > 0 && System.currentTimeMillis() > decodedExpirationTime) {
@@ -421,8 +425,7 @@ public class DataSealer extends AbstractInitializableComponent {
                 final byte[] plaintext = byteStream.toByteArray();
 
                 final byte[] encryptedData = new byte[cipher.getOutputSize(plaintext.length)];
-                int outputLen = cipher.update(plaintext, 0, plaintext.length, encryptedData, 0);
-                outputLen += cipher.doFinal(encryptedData, outputLen);
+                final int outputLen = cipher.doFinal(plaintext, 0, plaintext.length, encryptedData);
 
                 try (final ByteArrayOutputStream finalByteStream = new ByteArrayOutputStream();
                         final DataOutputStream finalDataStream = new DataOutputStream(finalByteStream)) {
@@ -482,17 +485,15 @@ public class DataSealer extends AbstractInitializableComponent {
             byte[] plaintext = "test".getBytes(StandardCharsets.UTF_8);
             
             final byte[] encryptedData = new byte[cipher.getOutputSize(plaintext.length)];
-            int outputLen = cipher.update(plaintext, 0, plaintext.length, encryptedData, 0);
-            cipher.doFinal(encryptedData, outputLen);
+            int outputLen = cipher.doFinal(plaintext, 0, plaintext.length, encryptedData);
 
             cipher.init(Cipher.DECRYPT_MODE, key, params);
             cipher.updateAAD("aad".getBytes(StandardCharsets.UTF_8));
             
             plaintext = new byte[cipher.getOutputSize(encryptedData.length)];
-            outputLen = cipher.update(encryptedData, 0, encryptedData.length, plaintext, 0);
-            cipher.doFinal(plaintext, outputLen);
+            outputLen = cipher.doFinal(encryptedData, 0, encryptedData.length, plaintext);
             
-            decrypted = new String(plaintext, StandardCharsets.UTF_8);
+            decrypted = new String(plaintext, 0, outputLen, StandardCharsets.UTF_8);
             
         } catch (final IllegalStateException | GeneralSecurityException e) {
             log.error("Round trip encryption/decryption test unsuccessful: {}", e.getMessage());
@@ -505,4 +506,4 @@ public class DataSealer extends AbstractInitializableComponent {
         }
     }
 
-}
\ No newline at end of file
+}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list