mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-15 07:28:30 +00:00
Remove redundant IdentityKeyUtil helper.
This commit is contained in:
committed by
Cody Henthorne
parent
76f65198bb
commit
f4f2976907
@@ -15,7 +15,6 @@ import org.signal.libsignal.protocol.IdentityKey
|
||||
import org.signal.libsignal.protocol.IdentityKeyPair
|
||||
import org.signal.libsignal.protocol.SignalProtocolAddress
|
||||
import org.thoughtcrime.securesms.SignalInstrumentationApplicationContext
|
||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecretUtil
|
||||
import org.thoughtcrime.securesms.crypto.ProfileKeyUtil
|
||||
import org.thoughtcrime.securesms.database.IdentityTable
|
||||
@@ -148,7 +147,7 @@ class SignalActivityRule(private val othersCount: Int = 4, private val createGro
|
||||
SignalDatabase.recipients.setCapabilities(recipientId, SignalServiceProfile.Capabilities(true, true))
|
||||
SignalDatabase.recipients.setProfileSharing(recipientId, true)
|
||||
SignalDatabase.recipients.markRegistered(recipientId, aci)
|
||||
val otherIdentity = IdentityKeyUtil.generateIdentityKeyPair()
|
||||
val otherIdentity = IdentityKeyPair.generate()
|
||||
AppDependencies.protocolStore.aci().saveIdentity(SignalProtocolAddress(aci.toString(), 1), otherIdentity.publicKey)
|
||||
others += recipientId
|
||||
othersKeys += otherIdentity
|
||||
@@ -161,7 +160,7 @@ class SignalActivityRule(private val othersCount: Int = 4, private val createGro
|
||||
return androidx.test.core.app.launchActivity(Intent(context, T::class.java).apply(initIntent))
|
||||
}
|
||||
|
||||
fun changeIdentityKey(recipient: Recipient, identityKey: IdentityKey = IdentityKeyUtil.generateIdentityKeyPair().publicKey) {
|
||||
fun changeIdentityKey(recipient: Recipient, identityKey: IdentityKey = IdentityKeyPair.generate().publicKey) {
|
||||
AppDependencies.protocolStore.aci().saveIdentity(SignalProtocolAddress(recipient.requireServiceId().toString(), 0), identityKey)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import android.app.Application
|
||||
import android.content.SharedPreferences
|
||||
import android.preference.PreferenceManager
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.signal.libsignal.protocol.IdentityKeyPair
|
||||
import org.signal.libsignal.protocol.SignalProtocolAddress
|
||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecretUtil
|
||||
import org.thoughtcrime.securesms.crypto.ProfileKeyUtil
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase
|
||||
@@ -96,7 +96,7 @@ object TestUsers {
|
||||
SignalDatabase.recipients.setCapabilities(recipientId, SignalServiceProfile.Capabilities(true, true))
|
||||
SignalDatabase.recipients.setProfileSharing(recipientId, true)
|
||||
SignalDatabase.recipients.markRegistered(recipientId, aci)
|
||||
val otherIdentity = IdentityKeyUtil.generateIdentityKeyPair()
|
||||
val otherIdentity = IdentityKeyPair.generate()
|
||||
AppDependencies.protocolStore.aci().saveIdentity(SignalProtocolAddress(aci.toString(), 1), otherIdentity.publicKey)
|
||||
|
||||
others += recipientId
|
||||
|
||||
@@ -19,7 +19,6 @@ import org.signal.libsignal.protocol.state.SignalProtocolStore
|
||||
import org.signal.libsignal.protocol.state.SignedPreKeyRecord
|
||||
import org.signal.libsignal.protocol.util.KeyHelper
|
||||
import org.signal.libsignal.protocol.util.Medium
|
||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
|
||||
import org.thoughtcrime.securesms.crypto.PreKeyUtil
|
||||
import org.thoughtcrime.securesms.database.IdentityTable
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase
|
||||
@@ -303,7 +302,7 @@ class ChangeNumberRepository(
|
||||
val selfIdentifier: String = SignalStore.account.requireAci().toString()
|
||||
val aciProtocolStore: SignalProtocolStore = AppDependencies.protocolStore.aci()
|
||||
|
||||
val pniIdentity: IdentityKeyPair = IdentityKeyUtil.generateIdentityKeyPair()
|
||||
val pniIdentity: IdentityKeyPair = IdentityKeyPair.generate()
|
||||
val deviceMessages = mutableListOf<OutgoingPushMessage>()
|
||||
val devicePniSignedPreKeys = mutableMapOf<Int, SignedPreKeyEntity>()
|
||||
val devicePniLastResortKyberPreKeys = mutableMapOf<Int, KyberPreKeyEntity>()
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Whisper Systems
|
||||
* Copyright (C) 2013 Open Whisper Systems
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.thoughtcrime.securesms.crypto;
|
||||
|
||||
import org.signal.libsignal.protocol.IdentityKey;
|
||||
import org.signal.libsignal.protocol.IdentityKeyPair;
|
||||
import org.signal.libsignal.protocol.ecc.ECKeyPair;
|
||||
import org.signal.libsignal.protocol.ecc.ECPrivateKey;
|
||||
|
||||
/**
|
||||
* Utility class for working with identity keys.
|
||||
*
|
||||
* @author Moxie Marlinspike
|
||||
*/
|
||||
|
||||
public class IdentityKeyUtil {
|
||||
|
||||
public static IdentityKeyPair generateIdentityKeyPair() {
|
||||
ECKeyPair djbKeyPair = ECKeyPair.generate();
|
||||
IdentityKey djbIdentityKey = new IdentityKey(djbKeyPair.getPublicKey());
|
||||
ECPrivateKey djbPrivateKey = djbKeyPair.getPrivateKey();
|
||||
|
||||
return new IdentityKeyPair(djbIdentityKey, djbPrivateKey);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import org.signal.libsignal.protocol.IdentityKey
|
||||
import org.signal.libsignal.protocol.IdentityKeyPair
|
||||
import org.signal.libsignal.protocol.ecc.ECPrivateKey
|
||||
import org.signal.libsignal.protocol.util.Medium
|
||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
|
||||
import org.thoughtcrime.securesms.crypto.MasterCipher
|
||||
import org.thoughtcrime.securesms.crypto.ProfileKeyUtil
|
||||
import org.thoughtcrime.securesms.crypto.storage.PreKeyMetadataStore
|
||||
@@ -282,7 +281,7 @@ class AccountValues internal constructor(store: KeyValueStore, context: Context)
|
||||
|
||||
Log.i(TAG, "Generating a new ACI identity key pair.")
|
||||
|
||||
val key: IdentityKeyPair = IdentityKeyUtil.generateIdentityKeyPair()
|
||||
val key: IdentityKeyPair = IdentityKeyPair.generate()
|
||||
store
|
||||
.beginWrite()
|
||||
.putBlob(KEY_ACI_IDENTITY_PUBLIC_KEY, key.publicKey.serialize())
|
||||
@@ -305,7 +304,7 @@ class AccountValues internal constructor(store: KeyValueStore, context: Context)
|
||||
|
||||
Log.i(TAG, "Generating a new PNI identity key pair.")
|
||||
|
||||
val key: IdentityKeyPair = IdentityKeyUtil.generateIdentityKeyPair()
|
||||
val key: IdentityKeyPair = IdentityKeyPair.generate()
|
||||
store
|
||||
.beginWrite()
|
||||
.putBlob(KEY_PNI_IDENTITY_PUBLIC_KEY, key.publicKey.serialize())
|
||||
|
||||
@@ -16,8 +16,8 @@ import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.isActive
|
||||
import kotlinx.coroutines.launch
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.signal.libsignal.protocol.IdentityKeyPair
|
||||
import org.thoughtcrime.securesms.components.settings.app.usernamelinks.QrCodeData
|
||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
|
||||
import org.thoughtcrime.securesms.dependencies.AppDependencies
|
||||
import org.whispersystems.signalservice.api.provisioning.ProvisioningSocket
|
||||
import org.whispersystems.signalservice.internal.crypto.SecondaryProvisioningCipher
|
||||
@@ -88,7 +88,7 @@ class RegisterLinkDeviceQrViewModel : ViewModel() {
|
||||
|
||||
return ProvisioningSocket.start<ProvisionMessage>(
|
||||
mode = ProvisioningSocket.Mode.LINK,
|
||||
identityKeyPair = IdentityKeyUtil.generateIdentityKeyPair(),
|
||||
identityKeyPair = IdentityKeyPair.generate(),
|
||||
configuration = AppDependencies.signalServiceNetworkAccess.getConfiguration(),
|
||||
handler = { id, t ->
|
||||
store.update {
|
||||
|
||||
@@ -16,10 +16,10 @@ import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.isActive
|
||||
import kotlinx.coroutines.launch
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.signal.libsignal.protocol.IdentityKeyPair
|
||||
import org.signal.registration.proto.RegistrationProvisionMessage
|
||||
import org.thoughtcrime.securesms.backup.v2.MessageBackupTier
|
||||
import org.thoughtcrime.securesms.components.settings.app.usernamelinks.QrCodeData
|
||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
|
||||
import org.thoughtcrime.securesms.dependencies.AppDependencies
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.registration.data.network.RegisterAccountResult
|
||||
@@ -123,7 +123,7 @@ class RestoreViaQrViewModel : ViewModel() {
|
||||
|
||||
return ProvisioningSocket.start<RegistrationProvisionMessage>(
|
||||
mode = ProvisioningSocket.Mode.REREG,
|
||||
identityKeyPair = IdentityKeyUtil.generateIdentityKeyPair(),
|
||||
identityKeyPair = IdentityKeyPair.generate(),
|
||||
configuration = AppDependencies.signalServiceNetworkAccess.getConfiguration(),
|
||||
handler = { id, t ->
|
||||
store.update {
|
||||
|
||||
@@ -17,7 +17,7 @@ import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
|
||||
import org.signal.libsignal.protocol.IdentityKeyPair
|
||||
import org.thoughtcrime.securesms.crypto.storage.SignalIdentityKeyStore
|
||||
import org.thoughtcrime.securesms.database.IdentityTable
|
||||
import org.thoughtcrime.securesms.database.RecipientDatabaseTestUtils
|
||||
@@ -79,7 +79,7 @@ class SafetyNumberRepositoryTest {
|
||||
|
||||
val record = IdentityRecord(
|
||||
recipientId = recipient.id,
|
||||
identityKey = IdentityKeyUtil.generateIdentityKeyPair().publicKey,
|
||||
identityKey = IdentityKeyPair.generate().publicKey,
|
||||
verifiedStatus = IdentityTable.VerifiedStatus.DEFAULT,
|
||||
firstUse = false,
|
||||
timestamp = 0,
|
||||
@@ -141,7 +141,7 @@ class SafetyNumberRepositoryTest {
|
||||
fun batchSafetyNumberCheckSync_batchOf1_oneChange() {
|
||||
val other = recipientPool[1]
|
||||
val otherAci = other.requireAci()
|
||||
val otherNewIdentityKey = IdentityKeyUtil.generateIdentityKeyPair().publicKey
|
||||
val otherNewIdentityKey = IdentityKeyPair.generate().publicKey
|
||||
val keys = listOf(ContactSearchKey.RecipientSearchKey(other.id, false))
|
||||
|
||||
every {
|
||||
@@ -175,7 +175,7 @@ class SafetyNumberRepositoryTest {
|
||||
val other = recipientPool[1]
|
||||
val secondOther = recipientPool[2]
|
||||
val otherAci = other.requireAci()
|
||||
val otherNewIdentityKey = IdentityKeyUtil.generateIdentityKeyPair().publicKey
|
||||
val otherNewIdentityKey = IdentityKeyPair.generate().publicKey
|
||||
val keys = listOf(ContactSearchKey.RecipientSearchKey(other.id, false), ContactSearchKey.RecipientSearchKey(secondOther.id, false))
|
||||
|
||||
every {
|
||||
|
||||
@@ -8,7 +8,7 @@ import assertk.assertions.isInstanceOf
|
||||
import okio.ByteString
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
|
||||
import org.signal.libsignal.protocol.IdentityKeyPair
|
||||
import org.thoughtcrime.securesms.util.Util
|
||||
import org.whispersystems.signalservice.test.LibSignalLibraryUtil
|
||||
|
||||
@@ -20,7 +20,7 @@ class MobileCoinPublicAddressProfileUtilTest {
|
||||
|
||||
@Test
|
||||
fun can_verify_an_address() {
|
||||
val identityKeyPair = IdentityKeyUtil.generateIdentityKeyPair()
|
||||
val identityKeyPair = IdentityKeyPair.generate()
|
||||
val address = Util.getSecretBytes(100)
|
||||
val signedPaymentAddress = MobileCoinPublicAddressProfileUtil.signPaymentsAddress(address, identityKeyPair)
|
||||
|
||||
@@ -31,8 +31,8 @@ class MobileCoinPublicAddressProfileUtilTest {
|
||||
|
||||
@Test
|
||||
fun can_not_verify_an_address_with_the_wrong_key() {
|
||||
val identityKeyPair = IdentityKeyUtil.generateIdentityKeyPair()
|
||||
val wrongPublicKey = IdentityKeyUtil.generateIdentityKeyPair().publicKey
|
||||
val identityKeyPair = IdentityKeyPair.generate()
|
||||
val wrongPublicKey = IdentityKeyPair.generate().publicKey
|
||||
val address = Util.getSecretBytes(100)
|
||||
val signedPaymentAddress = MobileCoinPublicAddressProfileUtil.signPaymentsAddress(address, identityKeyPair)
|
||||
|
||||
@@ -43,7 +43,7 @@ class MobileCoinPublicAddressProfileUtilTest {
|
||||
|
||||
@Test
|
||||
fun can_not_verify_a_tampered_signature() {
|
||||
val identityKeyPair = IdentityKeyUtil.generateIdentityKeyPair()
|
||||
val identityKeyPair = IdentityKeyPair.generate()
|
||||
val address = Util.getSecretBytes(100)
|
||||
val signedPaymentAddress = MobileCoinPublicAddressProfileUtil.signPaymentsAddress(address, identityKeyPair)
|
||||
val mobileCoinAddress = signedPaymentAddress.mobileCoin!!
|
||||
@@ -66,7 +66,7 @@ class MobileCoinPublicAddressProfileUtilTest {
|
||||
|
||||
@Test
|
||||
fun can_not_verify_a_tampered_address() {
|
||||
val identityKeyPair = IdentityKeyUtil.generateIdentityKeyPair()
|
||||
val identityKeyPair = IdentityKeyPair.generate()
|
||||
val addressBytes = Util.getSecretBytes(100)
|
||||
val signedPaymentAddress = MobileCoinPublicAddressProfileUtil.signPaymentsAddress(addressBytes, identityKeyPair)
|
||||
val mobileCoinAddress = signedPaymentAddress.mobileCoin!!
|
||||
@@ -89,7 +89,7 @@ class MobileCoinPublicAddressProfileUtilTest {
|
||||
|
||||
@Test
|
||||
fun can_not_verify_a_missing_signature() {
|
||||
val identityKeyPair = IdentityKeyUtil.generateIdentityKeyPair()
|
||||
val identityKeyPair = IdentityKeyPair.generate()
|
||||
val address = Util.getSecretBytes(100)
|
||||
val signedPaymentAddress = MobileCoinPublicAddressProfileUtil.signPaymentsAddress(address, identityKeyPair)
|
||||
|
||||
@@ -109,7 +109,7 @@ class MobileCoinPublicAddressProfileUtilTest {
|
||||
|
||||
@Test
|
||||
fun can_not_verify_a_missing_address() {
|
||||
val identityKeyPair = IdentityKeyUtil.generateIdentityKeyPair()
|
||||
val identityKeyPair = IdentityKeyPair.generate()
|
||||
val address = Util.getSecretBytes(100)
|
||||
val signedPaymentAddress = MobileCoinPublicAddressProfileUtil.signPaymentsAddress(address, identityKeyPair)
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.thoughtcrime.securesms.registration.secondary
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.isEqualTo
|
||||
import org.junit.Test
|
||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
|
||||
import org.signal.libsignal.protocol.IdentityKeyPair
|
||||
import org.thoughtcrime.securesms.devicelist.protos.DeviceName
|
||||
import java.nio.charset.Charset
|
||||
|
||||
@@ -11,7 +11,7 @@ class DeviceNameCipherTest {
|
||||
@Test
|
||||
fun encryptDeviceName() {
|
||||
val deviceName = "xXxCoolDeviceNamexXx"
|
||||
val identityKeyPair = IdentityKeyUtil.generateIdentityKeyPair()
|
||||
val identityKeyPair = IdentityKeyPair.generate()
|
||||
|
||||
val encryptedDeviceName = DeviceNameCipher.encryptDeviceName(deviceName.toByteArray(Charset.forName("UTF-8")), identityKeyPair)
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import okio.ByteString
|
||||
import org.junit.Test
|
||||
import org.signal.libsignal.protocol.IdentityKey
|
||||
import org.signal.libsignal.protocol.IdentityKeyPair
|
||||
import org.signal.libsignal.protocol.ecc.ECKeyPair
|
||||
import org.signal.libsignal.protocol.ecc.ECPrivateKey
|
||||
import org.signal.libsignal.zkgroup.profiles.ProfileKey
|
||||
import org.whispersystems.signalservice.api.util.UuidUtil
|
||||
@@ -25,9 +24,9 @@ import kotlin.random.Random
|
||||
class SecondaryProvisioningCipherTest {
|
||||
@Test
|
||||
fun decrypt() {
|
||||
val provisioningCipher = SecondaryProvisioningCipher.generate(generateIdentityKeyPair())
|
||||
val provisioningCipher = SecondaryProvisioningCipher.generate(IdentityKeyPair.generate())
|
||||
|
||||
val primaryIdentityKeyPair = generateIdentityKeyPair()
|
||||
val primaryIdentityKeyPair = IdentityKeyPair.generate()
|
||||
val primaryProfileKey = generateProfileKey()
|
||||
val primaryProvisioningCipher = PrimaryProvisioningCipher(provisioningCipher.secondaryDevicePublicKey.publicKey)
|
||||
|
||||
@@ -60,14 +59,6 @@ class SecondaryProvisioningCipherTest {
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun generateIdentityKeyPair(): IdentityKeyPair {
|
||||
val djbKeyPair = ECKeyPair.generate()
|
||||
val djbIdentityKey = IdentityKey(djbKeyPair.publicKey)
|
||||
val djbPrivateKey = djbKeyPair.privateKey
|
||||
|
||||
return IdentityKeyPair(djbIdentityKey, djbPrivateKey)
|
||||
}
|
||||
|
||||
fun generateProfileKey(): ProfileKey {
|
||||
return ProfileKey(Random.nextBytes(32))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user