Update logging format.

This commit is contained in:
Greyson Parrelli
2023-11-30 08:54:17 -08:00
committed by Cody Henthorne
parent 0b0c54d874
commit 97c34b889a
9 changed files with 82 additions and 30 deletions

View File

@@ -1,35 +0,0 @@
package org.whispersystems.signalservice.api.crypto;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
public final class CryptoUtil {
private static final String HMAC_SHA256 = "HmacSHA256";
private CryptoUtil() {
}
public static byte[] hmacSha256(byte[] key, byte[] data) {
try {
Mac mac = Mac.getInstance(HMAC_SHA256);
mac.init(new SecretKeySpec(key, HMAC_SHA256));
return mac.doFinal(data);
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
throw new AssertionError(e);
}
}
public static byte[] sha256(byte[] data) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
return digest.digest(data);
} catch (NoSuchAlgorithmException e) {
throw new AssertionError(e);
}
}
}

View File

@@ -4,7 +4,7 @@ import org.whispersystems.util.StringUtil;
import java.util.Arrays;
import static org.whispersystems.signalservice.api.crypto.CryptoUtil.hmacSha256;
import static org.signal.core.util.CryptoUtil.hmacSha256;
import static org.whispersystems.util.ByteArrayUtil.concat;
import static org.whispersystems.util.ByteArrayUtil.xor;
import static java.util.Arrays.copyOfRange;

View File

@@ -8,7 +8,7 @@ import org.whispersystems.util.StringUtil;
import java.security.SecureRandom;
import java.util.Arrays;
import static org.whispersystems.signalservice.api.crypto.CryptoUtil.hmacSha256;
import static org.signal.core.util.CryptoUtil.hmacSha256;
public final class MasterKey {
@@ -40,6 +40,10 @@ public final class MasterKey {
return new StorageKey(derive("Storage Service Encryption"));
}
public byte[] deriveLoggingKey() {
return derive("Logging Key");
}
private byte[] derive(String keyName) {
return hmacSha256(masterKey, StringUtil.utf8(keyName));
}

View File

@@ -6,7 +6,7 @@ import org.whispersystems.util.StringUtil;
import java.util.Arrays;
import static org.whispersystems.signalservice.api.crypto.CryptoUtil.hmacSha256;
import static org.signal.core.util.CryptoUtil.hmacSha256;
/**
* Key used to encrypt data on the storage service. Not used directly -- instead we used keys that

View File

@@ -1,7 +1,7 @@
package org.whispersystems.signalservice.internal.contacts.crypto;
import org.signal.libsignal.protocol.util.ByteUtil;
import org.whispersystems.signalservice.api.crypto.CryptoUtil;
import org.signal.core.util.CryptoUtil;
import org.whispersystems.signalservice.api.crypto.InvalidCiphertextException;
import org.whispersystems.signalservice.internal.contacts.crypto.AESCipher.AESEncryptedResult;
import org.whispersystems.signalservice.internal.contacts.entities.DiscoveryRequest;