diff --git a/core/src/main/java/com/onelogin/saml2/util/Util.java b/core/src/main/java/com/onelogin/saml2/util/Util.java index 148a2752..35e4c177 100644 --- a/core/src/main/java/com/onelogin/saml2/util/Util.java +++ b/core/src/main/java/com/onelogin/saml2/util/Util.java @@ -637,6 +637,9 @@ private static void copyBytes(InputStream is, OutputStream bytes) throws IOExcep * @return the base64 decoded and inflated string */ public static String base64decodedInflated(String input) { + if (input.isEmpty()) { + return input; + } // Base64 decoder byte[] decoded = Base64.decodeBase64(input); @@ -644,11 +647,15 @@ public static String base64decodedInflated(String input) { try { Inflater decompresser = new Inflater(true); decompresser.setInput(decoded); - byte[] result = new byte[2048]; - int resultLength = decompresser.inflate(result); + byte[] result = new byte[1024]; + String inflated = ""; + long limit = 0; + while(!decompresser.finished() && limit < 150) { + int resultLength = decompresser.inflate(result); + limit += 1; + inflated += new String(result, 0, resultLength, "UTF-8"); + } decompresser.end(); - - String inflated = new String(result, 0, resultLength, "UTF-8"); return inflated; } catch (Exception e) { return new String(decoded); diff --git a/core/src/test/java/com/onelogin/saml2/test/util/UtilsTest.java b/core/src/test/java/com/onelogin/saml2/test/util/UtilsTest.java index 95fcf7a3..ebe26939 100644 --- a/core/src/test/java/com/onelogin/saml2/test/util/UtilsTest.java +++ b/core/src/test/java/com/onelogin/saml2/test/util/UtilsTest.java @@ -779,6 +779,22 @@ public void testBase64decodedInflated() throws URISyntaxException, IOException { assertThat(authNRequest.toString(), equalTo(Util.base64decodedInflated(deflatedEncodedAuthNRequest).toString())); } + /** + * Tests the base64decodedInflated method + * Case: Long certs + * + * @throws IOException + * @throws URISyntaxException + * + * @see com.onelogin.saml2.util.Util#base64decodedInflated + */ + @Test + public void testBase64decodedInflated2() throws URISyntaxException, IOException { + String samlResponse = Util.getFileAsString("data/responses/response_long_cert.xml"); + String deflatedEncodedsamlResponse = Util.getFileAsString("data/responses/response_long_cert.xml.deflated.base64"); + + assertThat(samlResponse.toString(), equalTo(Util.base64decodedInflated(deflatedEncodedsamlResponse).toString())); + } /** * Tests the deflatedBase64encoded method diff --git a/core/src/test/resources/data/responses/response_long_cert.xml b/core/src/test/resources/data/responses/response_long_cert.xml new file mode 100644 index 00000000..5b7e28b4 --- /dev/null +++ b/core/src/test/resources/data/responses/response_long_cert.xml @@ -0,0 +1 @@ +https://app.onelogin.com/saml/metadata/xxxhttps://app.onelogin.com/saml/metadata/xxxNDtROTF2fPPikcJGomu4xGRjZBw=5y5JGtuZQBhmiNWnklJP9IXHbsMvwWQ8HZPuOg1j/K7p14AfFQVbNy4uJFRhsxrSH2dqKk79M/T7AgwUyMNmRV/T6hBXNg0RIW+f2Yp7BeqCX5XfhKXCbOsRBYwetvUUQpGrDFMEHzyY7UFWElNO8kyAI6hxD33dM7Q5ORDtxteFm0ONY90qPSsX5IGCnw2m2IZE/mInbteuRZYGzKxubbR6QXQLXrdrgXWduU80Gld65q5JMO3KEH/K6Ebym0GykyR3oS1dXXvz9ts+ZBF9RieRcAJ3515qRdJ3wd6JCBsrIu2W8ZBAeP9/Z6ynTJwj3MX7TaKm0eMUc+GM6HUjAVOkti6F4KP+rls6E6zRJxD2oeVljk5ssmeZnlGE3mzVxIiDXstmmStqqNdWRQ3NkNunvYAabml/BbbDSzRIH8xTwX0PQq7ZDttn0F5mKd9lF8ncBfLQ8ZahreLUSKRgUyUU0BycgTfuvfTFO/JWtMbNBoempSf+ptV632wXDAzzDCKriGvNGe4/i99fv48hTUvjrgcZoPSvfakh7EynEtB/gH7JRX90I8OV+Qnnkeq6nDgWuNPmhmB97JQCiauoSq2vKU42TC9Fi/pbDFW3mv5qzpbQH8qv/q/T/mDceNLelyUsIGPGBXzPwNmP8CdUKLE4Ln46ID+hq40BeY1YVdc=MIIGZTCCBE2gAwIBAgIULEW2UPHc+tQMo/j0NBM+8SbWK7IwDQYJKoZIhvcNAQELBQAwcjELMAkGA1UEBhMCVVMxKzApBgNVBAoMIk9uZUxvZ2luIFRlc3QgKHNnYXJjaWEtdXMtcHJlcHJvZCkxFTATBgNV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aSAFKewY7diVRP96TRYhW2f/1ktWrJAoXakdDByMQswCQYDVQQGEwJVUzErMCkGA1UECgwiT25lTG9naW4gVGVzdCAoc2dhcmNpYS11cy1wcmVwcm9kKTEVMBMGA1UECwwMT25lTG9naW4gSWRQMR8wHQYDVQQDDBZPbmVMb2dpbiBBY2NvdW50IDg5MTQ2ghQsRbZQ8dz61Ayj+PQ0Ez7xJtYrsjAOBgNVHQ8BAf8EBAMCB4AwDQYJKoZIhvcNAQELBQADggIBAC2TQ4yqwk0ePey99JYI5PfMRVEnUyyCSPfKmyVJgoOZwk97+CZuq1MNqGavcExd1ofc4wkN3unk/g7qVRPBV24k9FZaicYrp5maSHakL2SJD8qo/deohYFaeH8RzszxEZbJJYMLiXyRJi44T28TyF8admIwUJVg/KBhNAHi/IlAsRWPL92nWJjSCBHgiPaG5HF10t/GaQSJuQpdhxniUlseuqXZ/Qm0MjAgSTlyaBIxLyOErrpVujwiR5RTHLw0wn+2P0WmfVp7e79GOqzFuwmoLfxUtJgalc7av9VwFdEB2nWF2hu7BwE9rzg8FTaw1uAEu+LQ++IUuI+ydparFWoo/IwtSrXF59mBoKMld58K4L+TfWwUYF3hAmH2XNiSBTFZn1HBsK+XqS1CUGD8R0WSVvQC2jjFbxztFkrOIzz5ITLzKcjr1E86r5PvBQXeeTvVz6g2L+wEA5VXGYh/RItHEkuwn7EPWpvJUfc5B0m57rfr0+UqWZaLbhczrmHFn0HaDXcs2ldi7y+Eiv6IP3vrJrHhdCDlVPLQH8w0f4vNcR8YYVOfWFHYzyo4oqRYFMRmoqfubs90zGLcB5ugm56k5VaseP+VGwjjTEyiD4CYPLEvKm0Z2M0L6MIkhp/9VYl8ZAWvPGKFMSaANkiMlux2uEBeG3s4nLQcunumphAosixto.garcia+us-preprod@onelogin.comhttp://localhost:8080/java-saml-tookit-jspsample/metadata.jspurn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransportgarciasixtosixto.garcia+us-preprod@onelogin.com \ No newline at end of file diff --git a/core/src/test/resources/data/responses/response_long_cert.xml.deflated.base64 b/core/src/test/resources/data/responses/response_long_cert.xml.deflated.base64 new file mode 100644 index 00000000..6c02132b --- /dev/null +++ b/core/src/test/resources/data/responses/response_long_cert.xml.deflated.base64 @@ -0,0 +1 @@ +3TnZkqNIkr9Slv0oU4EQSCDrShtugQTiluBljCM4xClOia8fpKzMyayuqq7uWbOd3QdMFh5+u4dHuOv3xs2zaqOBpiqLBny65lnRbO7AL09dXWxKt0maTeHmoNm0/kYnpf0G+Qxv3KYBdZuUxdM7kurnNFVdtqVfZk+fBObLkwYvcOAi8HoJlgGOLGEE4B4WYuHa90MXRlyAuFjgrr2nTxaom0nUl6eJy0TcNB0QiqZ1i3YCwYv1HF7NkYWxQDcwssGWztMnBjRtUrjtgypu22oDQVnpu1lcNu0Gh3EYOru9O79rPW/LMk3a+bmppmWVAcj1m8/TahJVvDrGKL88HWR2f+AF+Z9hiK4XaxydI8BdzdEV8OZEgBJz1PdwbwXjyxXqPj3/fme+eWhbP991aCYl3Kr6XBYgK6Ok+OyXOXRHgnLQuoHbutD1ev0dek/3+0t89NZtu+bjii4D8Mlysw783O3NA3ujd74PmuYJen6R8JHphnwN6N9PgWvz5uthGD4Py89lHUEIDC+gk7TX/Rjk7r9xkz9HniePKPvgDykw5U8VXnEPRnwEmeKAeav5IiDwuR+uiHkY4gANYd/FV7+WL/9DsQomLyfRlHZd/XqSgh/5BIZgAppwgiaJfnt6owWBUITlY0m7RVkkU84m4yORJdDGZfCJzKKyTto4/6H/FvCd8Rxc/bm/QIvf7iF/r9ovMvqgYd1MhyV2F195aSAENZgi88nUhC9Pv/1qMB7ERu0WTVjWefNx+dc0AkU/haYCwbx5Neyrcr/O8Pu+gv6oI5NEU0X5O45757QXJo8T+ywzrXYwOCRUlCT1Rb7MO/TKa2eHGr48FHiP/AC8ufxl+U2yvAX3hQK7YSLfdo5KxXkiH4s0ExVCOG29RuqHo4pvHaU7RIsztFtXC5QMOdXy5BvaiZwWN9da3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