mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-22 16:07:30 +00:00
Remove some logging that could result in an information leak.
This commit is contained in:
parent
e45bc61624
commit
dda75006e4
@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (C) 2011 Whisper Systems
|
* Copyright (C) 2011 Whisper Systems
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
@ -10,49 +10,47 @@
|
|||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package org.thoughtcrime.securesms.protocol;
|
package org.thoughtcrime.securesms.protocol;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.util.Base64;
|
||||||
|
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.util.Base64;
|
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates prefixes that identify a message as
|
* Calculates prefixes that identify a message as
|
||||||
* being part of an encrypted session. The idea was to
|
* being part of an encrypted session. The idea was to
|
||||||
* make calculating and identifying these prefixes somewhat
|
* make calculating and identifying these prefixes somewhat
|
||||||
* expensive, so that filtering them en-mass would come at a cost.
|
* expensive, so that filtering them en-mass would come at a cost.
|
||||||
*
|
*
|
||||||
* @author Moxie Marlinspike
|
* @author Moxie Marlinspike
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public abstract class WirePrefix {
|
public abstract class WirePrefix {
|
||||||
|
|
||||||
private static final int HASH_ITERATIONS = 1000;
|
private static final int HASH_ITERATIONS = 1000;
|
||||||
private static final int PREFIX_BYTES = 3;
|
private static final int PREFIX_BYTES = 3;
|
||||||
public static final int PREFIX_SIZE = 4;
|
public static final int PREFIX_SIZE = 4;
|
||||||
|
|
||||||
public abstract String calculatePrefix(String message);
|
public abstract String calculatePrefix(String message);
|
||||||
|
|
||||||
public static boolean isKeyExchange(String message) {
|
public static boolean isKeyExchange(String message) {
|
||||||
return verifyPrefix("?TSK", message);
|
return verifyPrefix("?TSK", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isEncryptedMessage(String message) {
|
public static boolean isEncryptedMessage(String message) {
|
||||||
return verifyPrefix("?TSM", message);
|
return verifyPrefix("?TSM", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String calculateKeyExchangePrefix(String message) {
|
public static String calculateKeyExchangePrefix(String message) {
|
||||||
return calculatePrefix(("?TSK" + message).getBytes(), PREFIX_BYTES);
|
return calculatePrefix(("?TSK" + message).getBytes(), PREFIX_BYTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String calculateEncryptedMesagePrefix(String message) {
|
public static String calculateEncryptedMesagePrefix(String message) {
|
||||||
return calculatePrefix(("?TSM" + message).getBytes(), PREFIX_BYTES);
|
return calculatePrefix(("?TSM" + message).getBytes(), PREFIX_BYTES);
|
||||||
}
|
}
|
||||||
@ -60,27 +58,22 @@ public abstract class WirePrefix {
|
|||||||
private static boolean verifyPrefix(String prefixType, String message) {
|
private static boolean verifyPrefix(String prefixType, String message) {
|
||||||
if (message.length() <= PREFIX_SIZE)
|
if (message.length() <= PREFIX_SIZE)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
String prefix = message.substring(0, PREFIX_SIZE);
|
String prefix = message.substring(0, PREFIX_SIZE);
|
||||||
message = message.substring(PREFIX_SIZE);
|
message = message.substring(PREFIX_SIZE);
|
||||||
|
|
||||||
Log.w("Prefix", "Calculating on message: " + message + "**");
|
|
||||||
|
|
||||||
String calculatedPrefix = calculatePrefix((prefixType + message).getBytes(), PREFIX_BYTES);
|
String calculatedPrefix = calculatePrefix((prefixType + message).getBytes(), PREFIX_BYTES);
|
||||||
|
|
||||||
assert(calculatedPrefix.length() == PREFIX_SIZE);
|
assert(calculatedPrefix.length() == PREFIX_SIZE);
|
||||||
|
|
||||||
Log.w("Prefix", "Received prefix: " + prefix);
|
return prefix.equals(calculatedPrefix);
|
||||||
Log.w("Prefix", "Calculated prefix: " + calculatedPrefix);
|
|
||||||
|
|
||||||
return prefix.equals(calculatedPrefix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String calculatePrefix(byte[] message, int byteCount) {
|
private static String calculatePrefix(byte[] message, int byteCount) {
|
||||||
try {
|
try {
|
||||||
MessageDigest md = MessageDigest.getInstance("SHA1");
|
MessageDigest md = MessageDigest.getInstance("SHA1");
|
||||||
byte[] runningDigest = message;
|
byte[] runningDigest = message;
|
||||||
|
|
||||||
for (int i=0;i<HASH_ITERATIONS;i++) {
|
for (int i=0;i<HASH_ITERATIONS;i++) {
|
||||||
runningDigest = md.digest(runningDigest);
|
runningDigest = md.digest(runningDigest);
|
||||||
}
|
}
|
||||||
@ -88,30 +81,30 @@ public abstract class WirePrefix {
|
|||||||
return Base64.encodeBytes(runningDigest, 0, byteCount);
|
return Base64.encodeBytes(runningDigest, 0, byteCount);
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String calculateEncryptedMmsSubject() {
|
public static String calculateEncryptedMmsSubject() {
|
||||||
try {
|
try {
|
||||||
byte[] postfix = new byte[6];
|
byte[] postfix = new byte[6];
|
||||||
SecureRandom.getInstance("SHA1PRNG").nextBytes(postfix);
|
SecureRandom.getInstance("SHA1PRNG").nextBytes(postfix);
|
||||||
|
|
||||||
String postfixString = Base64.encodeBytes(postfix);
|
String postfixString = Base64.encodeBytes(postfix);
|
||||||
String prefix = calculatePrefix(postfixString.getBytes(), 6);
|
String prefix = calculatePrefix(postfixString.getBytes(), 6);
|
||||||
|
|
||||||
return prefix + postfixString;
|
return prefix + postfixString;
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isEncryptedMmsSubject(String subject) {
|
public static boolean isEncryptedMmsSubject(String subject) {
|
||||||
if (subject.length() < 9)
|
if (subject.length() < 9)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
String prefix = subject.substring(0, 8);
|
String prefix = subject.substring(0, 8);
|
||||||
String postfix = subject.substring(8);
|
String postfix = subject.substring(8);
|
||||||
|
|
||||||
String calculatedPrefix = calculatePrefix(postfix.getBytes(), 6);
|
String calculatedPrefix = calculatePrefix(postfix.getBytes(), 6);
|
||||||
return calculatedPrefix.equals(prefix);
|
return calculatedPrefix.equals(prefix);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user