Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ target
log.txt
/AuthSchema/
.vscode
secureData*.txt
*secureData*.txt
logfile.txt
rmc_log.txt
logfileConf.txt
6 changes: 6 additions & 0 deletions .jules/sentinel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Sentinel Security Journal

## 2026-02-01 - [Unsalted Password Storage in Authentication Protocol]
**Vulnerability:** Passwords are stored in the database as unsalted SHA256 hashes (with a dummy '000000000' salt prefix).
**Learning:** The authentication protocol requires the client to compute a salted hash of the stored hash. Since the client does not have access to a per-user salt before authentication, the stored hash must be computable by the client using only the password. This architectural constraint prevents the use of per-user salts in the database without changing the authentication protocol (e.g., by sending the salt to the client first).
**Prevention:** When designing authentication protocols, ensure that the server-side storage can use modern, salted hashing (like Argon2 or bcrypt) and that the protocol supports challenge-response mechanisms that don't depend on the client knowing the exact stored representation.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.bouncycastle.crypto.digests.SHA256Digest;
import it.richkmeli.jframework.util.TypeConverter;

import java.nio.charset.StandardCharsets;

public class SHA256 {
public static byte[] hash(byte[] input) {
SHA256Digest digest = new SHA256Digest();
Expand All @@ -15,7 +17,7 @@ public static byte[] hash(byte[] input) {

// sha256: string to hex
public static String hash(String input) {
return TypeConverter.bytesToHex(hash(input.getBytes()));
return TypeConverter.bytesToHex(hash(input.getBytes(StandardCharsets.UTF_8)));
}

public static String hashToString(byte[] input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import it.richkmeli.jframework.crypto.algorithm.SHA256;
import it.richkmeli.jframework.util.RandomStringGenerator;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Base64;

public class PasswordManager {
Expand All @@ -26,20 +27,20 @@ public static String hashPassword(String password, boolean saltEnabled) {

//System.out.println("hashPassword, saltS: " + saltS + " " + saltS.length() + " | hashedPassword: " + hashedPassword + " " + hashedPassword.length());
String out = saltS + hashedPassword;
return Base64.getUrlEncoder().encodeToString(out.getBytes(Charset.defaultCharset()));
return Base64.getUrlEncoder().encodeToString(out.getBytes(StandardCharsets.UTF_8));
}

// hashedPassword = db password, hashedSaltPassword = login password
public static boolean verifyPassword(String hashedPassword, String hashedSaltPassword) {
String decodedHashedPassword = new String(Base64.getUrlDecoder().decode(hashedPassword));
String decodedHashedSaltPassword = new String(Base64.getUrlDecoder().decode(hashedSaltPassword));
String decodedHashedPassword = new String(Base64.getUrlDecoder().decode(hashedPassword), StandardCharsets.UTF_8);
String decodedHashedSaltPassword = new String(Base64.getUrlDecoder().decode(hashedSaltPassword), StandardCharsets.UTF_8);
String salt = decodedHashedSaltPassword.substring(0, 9);
String hashSP = decodedHashedSaltPassword.substring(9);
String hashP = decodedHashedPassword.substring(9);

//System.out.println("verifyPassword, saltS: " + salt + " " + salt.length() + " | hashedSaltPassword: " + hashSP + " " + hashSP.length());
String hp = SHA256.hash(hashP + salt);

return hashSP.equalsIgnoreCase(hp);
return MessageDigest.isEqual(hashSP.toLowerCase().getBytes(StandardCharsets.UTF_8), hp.toLowerCase().getBytes(StandardCharsets.UTF_8));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import it.richkmeli.jframework.crypto.exception.CryptoException;
import it.richkmeli.jframework.util.RandomStringGenerator;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -29,7 +31,7 @@ public static boolean verifyNumericCompact(String numericCompactToken, String va
String extendedToken = generate(extractedNumericSalt + value, false);
// put extractedNumericSalt at first chars of extendedToken
extendedToken = reduceToNumeric(extractedNumericSalt + extendedToken, numericCompactToken.length());
return numericCompactToken.equalsIgnoreCase(extendedToken);
return MessageDigest.isEqual(numericCompactToken.getBytes(StandardCharsets.UTF_8), extendedToken.getBytes(StandardCharsets.UTF_8));
}

public static String generate(String value) {
Expand Down Expand Up @@ -109,7 +111,7 @@ public static boolean verifyTemporized(String token, String value, int minutesOf
hashed = token;
calculatedHash = SHA256.hash(value + (currentTimeMinutes * minutesOfValidity));
}
return hashed.equalsIgnoreCase(calculatedHash);
return MessageDigest.isEqual(hashed.toLowerCase().getBytes(StandardCharsets.UTF_8), calculatedHash.toLowerCase().getBytes(StandardCharsets.UTF_8));
}

private static String reduceToNumeric(String extendedToken, int length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public class RandomStringGenerator {
public static final String ALPHANUMERIC_ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
public static final String NUMERIC_ALPHABET = "0123456789";

private static final SecureRandom secureRandom = new SecureRandom();

public static String generateAlphanumericString(int length) {
String alphabet = ALPHANUMERIC_ALPHABET;
return generateString(length, alphabet);
Expand All @@ -21,7 +23,6 @@ private static String generateString(int length, String alphabet) {
int alphabetLength = alphabet.length();

StringBuilder result = new StringBuilder();
SecureRandom secureRandom = new SecureRandom();

for (int i = 0; i < length; ++i) {
result.append(alphabet.charAt(secureRandom.nextInt(alphabetLength)));
Expand All @@ -42,11 +43,10 @@ public static String generateBoundedString(int targetStringLength, int leftLimit
//int leftLimit = 97; // letter 'a'
//int rightLimit = 122; // letter 'z'
//int targetStringLength = 10;
SecureRandom random = new SecureRandom();
StringBuilder buffer = new StringBuilder(targetStringLength);
for (int i = 0; i < targetStringLength; i++) {
int randomLimitedInt = leftLimit + (int)
(random.nextFloat() * (rightLimit - leftLimit + 1));
(secureRandom.nextFloat() * (rightLimit - leftLimit + 1));
buffer.append((char) randomLimitedInt);
}
return buffer.toString();
Expand All @@ -55,19 +55,19 @@ public static String generateBoundedString(int targetStringLength, int leftLimit

public static String generateUtf8String(int length) {
byte[] array = new byte[length]; // length is bounded by 7
new SecureRandom().nextBytes(array);
secureRandom.nextBytes(array);
return new String(array, StandardCharsets.UTF_8);
}

public static String generateUtf16String(int length) {
byte[] array = new byte[length]; // length is bounded by 7
new SecureRandom().nextBytes(array);
secureRandom.nextBytes(array);
return new String(array, StandardCharsets.UTF_16);
}

public static String generateASCIItring(int length) {
byte[] array = new byte[length]; // length is bounded by 7
new SecureRandom().nextBytes(array);
secureRandom.nextBytes(array);
return new String(array, StandardCharsets.US_ASCII);
}

Expand Down