That fuck shit the fascists are using
at master 59 lines 2.3 kB view raw
1package org.tm.archive.testing 2 3import org.signal.core.util.logging.Log 4import org.signal.libsignal.protocol.ecc.ECKeyPair 5import org.signal.libsignal.zkgroup.profiles.ProfileKey 6import org.tm.archive.crypto.ProfileKeyUtil 7import org.tm.archive.dependencies.ApplicationDependencies 8import org.tm.archive.keyvalue.SignalStore 9import org.tm.archive.messages.protocol.BufferedProtocolStore 10import org.tm.archive.recipients.Recipient 11import org.tm.archive.testing.FakeClientHelpers.toEnvelope 12import org.whispersystems.signalservice.api.push.ServiceId 13import org.whispersystems.signalservice.api.push.SignalServiceAddress 14import org.whispersystems.signalservice.internal.push.Envelope 15 16/** 17 * Welcome to Alice's Client. 18 * 19 * Alice represent the Android instrumentation test user. Unlike [BobClient] much less is needed here 20 * as it can make use of the standard Signal Android App infrastructure. 21 */ 22class AliceClient(val serviceId: ServiceId, val e164: String, val trustRoot: ECKeyPair) { 23 24 companion object { 25 val TAG = Log.tag(AliceClient::class.java) 26 } 27 28 private val aliceSenderCertificate = FakeClientHelpers.createCertificateFor( 29 trustRoot = trustRoot, 30 uuid = serviceId.rawUuid, 31 e164 = e164, 32 deviceId = 1, 33 identityKey = SignalStore.account().aciIdentityKey.publicKey.publicKey, 34 expires = 31337 35 ) 36 37 fun process(envelope: Envelope, serverDeliveredTimestamp: Long) { 38 val start = System.currentTimeMillis() 39 val bufferedStore = BufferedProtocolStore.create() 40 ApplicationDependencies.getIncomingMessageObserver() 41 .processEnvelope(bufferedStore, envelope, serverDeliveredTimestamp) 42 ?.mapNotNull { it.run() } 43 ?.forEach { it.enqueue() } 44 45 bufferedStore.flushToDisk() 46 val end = System.currentTimeMillis() 47 Log.d(TAG, "${end - start}") 48 } 49 50 fun encrypt(now: Long, destination: Recipient): Envelope { 51 return ApplicationDependencies.getSignalServiceMessageSender().getEncryptedMessage( 52 SignalServiceAddress(destination.requireServiceId(), destination.requireE164()), 53 FakeClientHelpers.getTargetUnidentifiedAccess(ProfileKeyUtil.getSelfProfileKey(), ProfileKey(destination.profileKey), aliceSenderCertificate), 54 1, 55 FakeClientHelpers.encryptedTextMessage(now), 56 false 57 ).toEnvelope(now, destination.requireServiceId()) 58 } 59}