Skip to content

Commit cebe4fb

Browse files
author
drighetto
committed
Add method to protect serialized object #1
1 parent eefc237 commit cebe4fb

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/main/java/eu/righettod/ProcessingMode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package eu.righettod;
22

33
/**
4-
* Enumeration used by the method "SecurityUtils.ensureSerializedObjectIntegrity()" to define its working mode.
4+
* Enumeration used by the method <code>SecurityUtils.ensureSerializedObjectIntegrity()</code> to define its working mode.
55
*/
66
public enum ProcessingMode {
77
PROTECT, VALIDATE

src/main/java/eu/righettod/SecurityUtils.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -673,20 +673,21 @@ public static boolean isExcelCSVSafe(String csvFilePath) {
673673
}
674674

675675
/**
676-
* Provide a way to add an integrity marker (<a href="https://cryptobook.nakov.com/mac-and-key-derivation">HMAC</a>) to a serialized object serialized using the <a href="https://www.baeldung.com/java-serialization">java native system</a> (binary).<br>
676+
* Provide a way to add an integrity marker (<a href="https://en.wikipedia.org/wiki/HMAC">HMAC</a>) to a serialized object serialized using the <a href="https://www.baeldung.com/java-serialization">java native system</a> (binary).<br>
677677
* The goal is to provide <b>a temporary workaround</b> to try to prevent deserialization attacks and give time to move to a text-based serialization approach.
678678
*
679-
* @param processingMode Define the mode of processing i.e. protect or validate.
679+
* @param processingMode Define the mode of processing i.e. protect or validate. ({@link eu.righettod.ProcessingMode})
680680
* @param input When the processing mode is "protect" than the expected input (string) is a java serialized object encoded in Base64 otherwise (processing mode is "validate") expected input is the output of this method when the "protect" mode was used.
681-
* @param secret Secret to use to compute the HMAC.
681+
* @param secret Secret to use to compute the SHA256 HMAC.
682682
* @return A map with the following keys: <ul><li><b>PROCESSING_MODE</b>: Processing mode used to compute the result.</li><li><b>STATUS</b>: A boolean indicating if the processing was successful or not.</li><li><b>RESULT</b>: Always contains a string representing the protected serialized object in the format <code>[SERIALIZED_OBJECT_BASE64_ENCODED]:[SERIALIZED_OBJECT_HMAC_BASE64_ENCODED]</code>.</li></ul>
683-
* @throws Exception If any exception occurs
683+
* @throws Exception If any exception occurs.
684684
* @see "https://cheatsheetseries.owasp.org/cheatsheets/Deserialization_Cheat_Sheet.html"
685685
* @see "https://owasp.org/www-project-top-ten/2017/A8_2017-Insecure_Deserialization"
686686
* @see "https://portswigger.net/web-security/deserialization"
687687
* @see "https://www.baeldung.com/java-serialization-approaches"
688688
* @see "https://www.baeldung.com/java-serialization"
689-
* @see "https://cryptobook.nakov.com/mac-and-key-derivation"
689+
* @see "https://cryptobook.nakov.com/mac-and-key-derivation/hmac-and-key-derivation"
690+
* @see "https://en.wikipedia.org/wiki/HMAC"
690691
* @see "https://smattme.com/posts/how-to-generate-hmac-signature-in-java/"
691692
*/
692693
public static Map<String, Object> ensureSerializedObjectIntegrity(ProcessingMode processingMode, String input, byte[] secret) throws Exception {

0 commit comments

Comments
 (0)