mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-26 20:55:10 +00:00
Introduce Wire for proto codegen.
This commit is contained in:
committed by
Nicholas Tinsley
parent
72449fd73e
commit
a91a13cead
@@ -3,7 +3,7 @@ package org.thoughtcrime.securesms.absbackup.backupables
|
||||
import com.google.protobuf.InvalidProtocolBufferException
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.thoughtcrime.securesms.absbackup.AndroidBackupItem
|
||||
import org.thoughtcrime.securesms.absbackup.ExternalBackupProtos
|
||||
import org.thoughtcrime.securesms.absbackup.protos.KbsAuthToken
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
|
||||
/**
|
||||
@@ -18,10 +18,8 @@ object KbsAuthTokens : AndroidBackupItem {
|
||||
|
||||
override fun getDataForBackup(): ByteArray {
|
||||
val registrationRecoveryTokenList = SignalStore.kbsValues().kbsAuthTokenList
|
||||
val proto = ExternalBackupProtos.KbsAuthToken.newBuilder()
|
||||
.addAllToken(registrationRecoveryTokenList)
|
||||
.build()
|
||||
return proto.toByteArray()
|
||||
val proto = KbsAuthToken(tokens = registrationRecoveryTokenList)
|
||||
return proto.encode()
|
||||
}
|
||||
|
||||
override fun restoreData(data: ByteArray) {
|
||||
@@ -30,9 +28,9 @@ object KbsAuthTokens : AndroidBackupItem {
|
||||
}
|
||||
|
||||
try {
|
||||
val proto = ExternalBackupProtos.KbsAuthToken.parseFrom(data)
|
||||
val proto = KbsAuthToken.ADAPTER.decode(data)
|
||||
|
||||
SignalStore.kbsValues().putAuthTokenList(proto.tokenList)
|
||||
SignalStore.kbsValues().putAuthTokenList(proto.tokens)
|
||||
} catch (e: InvalidProtocolBufferException) {
|
||||
Log.w(TAG, "Cannot restore KbsAuthToken from backup service.")
|
||||
}
|
||||
|
||||
@@ -29,13 +29,14 @@ import java.security.MessageDigest;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import static org.thoughtcrime.securesms.devicelist.DeviceNameProtos.DeviceName;
|
||||
import org.thoughtcrime.securesms.devicelist.protos.DeviceName;
|
||||
|
||||
public class DeviceListLoader extends AsyncLoader<List<Device>> {
|
||||
|
||||
@@ -71,9 +72,9 @@ public class DeviceListLoader extends AsyncLoader<List<Device>> {
|
||||
throw new IOException("Invalid DeviceInfo name.");
|
||||
}
|
||||
|
||||
DeviceName deviceName = DeviceName.parseFrom(Base64.decode(deviceInfo.getName()));
|
||||
DeviceName deviceName = DeviceName.ADAPTER.decode(Base64.decode(deviceInfo.getName()));
|
||||
|
||||
if (!deviceName.hasCiphertext() || !deviceName.hasEphemeralPublic() || !deviceName.hasSyntheticIv()) {
|
||||
if (deviceName.ciphertext == null || deviceName.ephemeralPublic == null || deviceName.syntheticIv == null) {
|
||||
throw new IOException("Got a DeviceName that wasn't properly populated.");
|
||||
}
|
||||
|
||||
@@ -90,10 +91,10 @@ public class DeviceListLoader extends AsyncLoader<List<Device>> {
|
||||
|
||||
@VisibleForTesting
|
||||
public static byte[] decryptName(DeviceName deviceName, IdentityKeyPair identityKeyPair) throws InvalidKeyException, GeneralSecurityException {
|
||||
byte[] syntheticIv = deviceName.getSyntheticIv().toByteArray();
|
||||
byte[] cipherText = deviceName.getCiphertext().toByteArray();
|
||||
byte[] syntheticIv = Objects.requireNonNull(deviceName.syntheticIv).toByteArray();
|
||||
byte[] cipherText = Objects.requireNonNull(deviceName.ciphertext).toByteArray();
|
||||
ECPrivateKey identityKey = identityKeyPair.getPrivateKey();
|
||||
ECPublicKey ephemeralPublic = Curve.decodePoint(deviceName.getEphemeralPublic().toByteArray(), 0);
|
||||
ECPublicKey ephemeralPublic = Curve.decodePoint(Objects.requireNonNull(deviceName.ephemeralPublic).toByteArray(), 0);
|
||||
byte[] masterSecret = Curve.calculateAgreement(ephemeralPublic, identityKey);
|
||||
|
||||
Mac mac = Mac.getInstance("HmacSHA256");
|
||||
|
||||
@@ -116,13 +116,13 @@ object JumboEmoji {
|
||||
Log.i(TAG, "No file for emoji, downloading jumbo")
|
||||
EmojiDownloader.streamFileFromRemote(version, version.density, archiveName) { stream ->
|
||||
stream.use { remote ->
|
||||
val jumbomojiPack = JumbomojiPack.parseFrom(remote)
|
||||
val jumbomojiPack = JumbomojiPack.ADAPTER.decode(remote)
|
||||
|
||||
jumbomojiPack.itemsList.forEach { jumbo ->
|
||||
jumbomojiPack.items.forEach { jumbo ->
|
||||
val emojiNameEntry = EmojiFiles.Name(jumbo.name, UUID.randomUUID())
|
||||
val outputStream = EmojiFiles.openForWriting(applicationContext, version, emojiNameEntry.uuid)
|
||||
|
||||
outputStream.use { jumbo.image.writeTo(it) }
|
||||
outputStream.use { jumbo.image.write(it) }
|
||||
|
||||
jumbos = EmojiFiles.JumboCollection.append(applicationContext, jumbos, emojiNameEntry)
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package org.thoughtcrime.securesms.registration.secondary
|
||||
|
||||
import com.google.protobuf.ByteString
|
||||
import okio.ByteString.Companion.toByteString
|
||||
import org.signal.libsignal.protocol.IdentityKeyPair
|
||||
import org.signal.libsignal.protocol.ecc.Curve
|
||||
import org.signal.libsignal.protocol.ecc.ECKeyPair
|
||||
import org.thoughtcrime.securesms.devicelist.DeviceNameProtos
|
||||
import org.thoughtcrime.securesms.devicelist.protos.DeviceName
|
||||
import java.nio.charset.Charset
|
||||
import javax.crypto.Cipher
|
||||
import javax.crypto.Mac
|
||||
@@ -30,12 +30,11 @@ object DeviceNameCipher {
|
||||
cipher.init(Cipher.ENCRYPT_MODE, SecretKeySpec(cipherKey, "AES"), IvParameterSpec(ByteArray(16)))
|
||||
val cipherText = cipher.doFinal(plaintext)
|
||||
|
||||
return DeviceNameProtos.DeviceName.newBuilder()
|
||||
.setEphemeralPublic(ByteString.copyFrom(ephemeralKeyPair.publicKey.serialize()))
|
||||
.setSyntheticIv(ByteString.copyFrom(syntheticIv))
|
||||
.setCiphertext(ByteString.copyFrom(cipherText))
|
||||
.build()
|
||||
.toByteArray()
|
||||
return DeviceName(
|
||||
ephemeralPublic = ephemeralKeyPair.publicKey.serialize().toByteString(),
|
||||
syntheticIv = syntheticIv.toByteString(),
|
||||
ciphertext = cipherText.toByteString()
|
||||
).encode()
|
||||
}
|
||||
|
||||
private fun computeCipherKey(masterSecret: ByteArray, syntheticIv: ByteArray): ByteArray {
|
||||
|
||||
Reference in New Issue
Block a user