Enforce all hmac/mac to always be lower case.

pull/2/head
Tom Hacohen 8 years ago
parent 80bb0d6a70
commit dcb3429884

@ -120,9 +120,13 @@ public class Helpers {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest(base);
return Hex.toHexString(hash);
return toHex(hash);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
public static String toHex(byte[] bytes) {
return Hex.toHexString(bytes).toLowerCase();
}
}

@ -105,7 +105,7 @@ public class JournalEntryManager extends BaseManager {
uuid = previous.getUuid();
}
return Hex.toHexString(calculateHmac(keyBase64, uuid));
return Helpers.toHex(calculateHmac(keyBase64, uuid));
}
}

@ -19,6 +19,7 @@ import okhttp3.Response;
import okhttp3.ResponseBody;
import static at.bitfire.davdroid.journalmanager.Helpers.sha256;
import static at.bitfire.davdroid.journalmanager.Helpers.toHex;
public class JournalManager extends BaseManager {
final static private Type journalType = new TypeToken<List<Journal>>() {
@ -104,7 +105,7 @@ public class JournalManager extends BaseManager {
byte[] correctHash = calculateHmac(keyBase64);
if (!Arrays.areEqual(hmac, correctHash)) {
throw new Exceptions.IntegrityException("Bad HMAC. " + Hex.toHexString(hmac) + " != " + Hex.toHexString(correctHash));
throw new Exceptions.IntegrityException("Bad HMAC. " + toHex(hmac) + " != " + toHex(correctHash));
}
}

Loading…
Cancel
Save