Migrate from SQLite and ciphertext blobs to SQLCipher + KeyStore

This commit is contained in:
Moxie Marlinspike
2018-01-24 19:17:44 -08:00
parent d1819b6361
commit f36b296e2e
134 changed files with 3633 additions and 3544 deletions

View File

@@ -7,7 +7,6 @@ import android.support.annotation.NonNull;
import android.util.Log;
import org.spongycastle.util.encoders.Hex;
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.mms.PartAuthority;
import org.thoughtcrime.securesms.util.Util;
@@ -38,7 +37,6 @@ public class AttachmentServer implements Runnable {
private static final String TAG = AttachmentServer.class.getSimpleName();
private final Context context;
private final MasterSecret masterSecret;
private final Attachment attachment;
private final ServerSocket socket;
private final int port;
@@ -46,12 +44,11 @@ public class AttachmentServer implements Runnable {
private volatile boolean isRunning;
public AttachmentServer(Context context, MasterSecret masterSecret, Attachment attachment)
public AttachmentServer(Context context, Attachment attachment)
throws IOException
{
try {
this.context = context;
this.masterSecret = masterSecret;
this.attachment = attachment;
this.socket = new ServerSocket(0, 0, InetAddress.getByAddress(new byte[]{127, 0, 0, 1}));
this.port = socket.getLocalPort();
@@ -189,7 +186,7 @@ public class AttachmentServer implements Runnable {
}
protected void execute() throws IOException {
InputStream inputStream = PartAuthority.getAttachmentStream(context, masterSecret, attachment.getDataUri());
InputStream inputStream = PartAuthority.getAttachmentStream(context, attachment.getDataUri());
long fileSize = attachment.getSize();
String headers = "";

View File

@@ -4,9 +4,8 @@ import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import org.thoughtcrime.securesms.crypto.MasterSecretUnion;
import org.thoughtcrime.securesms.crypto.MediaKey;
import org.thoughtcrime.securesms.database.AttachmentDatabase;
import org.thoughtcrime.securesms.util.Base64;
import org.whispersystems.libsignal.util.guava.Optional;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
@@ -15,7 +14,7 @@ import java.util.List;
public class PointerAttachment extends Attachment {
public PointerAttachment(@NonNull String contentType, int transferState, long size,
private PointerAttachment(@NonNull String contentType, int transferState, long size,
@Nullable String fileName, @NonNull String location,
@NonNull String key, @NonNull String relay,
@Nullable byte[] digest, boolean voiceNote)
@@ -36,19 +35,20 @@ public class PointerAttachment extends Attachment {
}
public static List<Attachment> forPointers(@NonNull MasterSecretUnion masterSecret, Optional<List<SignalServiceAttachment>> pointers) {
public static List<Attachment> forPointers(Optional<List<SignalServiceAttachment>> pointers) {
List<Attachment> results = new LinkedList<>();
if (pointers.isPresent()) {
for (SignalServiceAttachment pointer : pointers.get()) {
if (pointer.isPointer()) {
String encryptedKey = MediaKey.getEncrypted(masterSecret, pointer.asPointer().getKey());
String encodedKey = Base64.encodeBytes(pointer.asPointer().getKey());
results.add(new PointerAttachment(pointer.getContentType(),
AttachmentDatabase.TRANSFER_PROGRESS_PENDING,
pointer.asPointer().getSize().or(0),
pointer.asPointer().getFileName().orNull(),
String.valueOf(pointer.asPointer().getId()),
encryptedKey, pointer.asPointer().getRelay().orNull(),
encodedKey, pointer.asPointer().getRelay().orNull(),
pointer.asPointer().getDigest().orNull(),
pointer.asPointer().getVoiceNote()));
}