That fuck shit the fascists are using
1package org.tm.archive.testing
2
3import org.signal.libsignal.protocol.IdentityKeyPair
4import org.signal.libsignal.protocol.ecc.Curve
5import org.signal.libsignal.protocol.state.PreKeyRecord
6import org.signal.libsignal.protocol.util.KeyHelper
7import org.signal.libsignal.protocol.util.Medium
8import org.tm.archive.crypto.PreKeyUtil
9import org.tm.archive.keyvalue.SignalStore
10import org.whispersystems.signalservice.api.messages.multidevice.DeviceInfo
11import org.whispersystems.signalservice.api.push.ServiceId
12import org.whispersystems.signalservice.api.push.SignedPreKeyEntity
13import org.whispersystems.signalservice.internal.push.AuthCredentials
14import org.whispersystems.signalservice.internal.push.DeviceInfoList
15import org.whispersystems.signalservice.internal.push.PreKeyEntity
16import org.whispersystems.signalservice.internal.push.PreKeyResponse
17import org.whispersystems.signalservice.internal.push.PreKeyResponseItem
18import org.whispersystems.signalservice.internal.push.PushServiceSocket
19import org.whispersystems.signalservice.internal.push.RegistrationSessionMetadataJson
20import org.whispersystems.signalservice.internal.push.SenderCertificate
21import org.whispersystems.signalservice.internal.push.VerifyAccountResponse
22import org.whispersystems.signalservice.internal.push.WhoAmIResponse
23import java.security.SecureRandom
24
25/**
26 * Warehouse of reusable test data and mock configurations.
27 */
28object MockProvider {
29
30 val senderCertificate = SenderCertificate().apply { certificate = ByteArray(0) }
31
32 val lockedFailure = PushServiceSocket.RegistrationLockFailure().apply {
33 svr1Credentials = AuthCredentials.create("username", "password")
34 svr2Credentials = null
35 }
36
37 val primaryOnlyDeviceList = DeviceInfoList().apply {
38 devices = listOf(
39 DeviceInfo().apply {
40 id = 1
41 }
42 )
43 }
44
45 val sessionMetadataJson = RegistrationSessionMetadataJson(
46 id = "asdfasdfasdfasdf",
47 nextCall = null,
48 nextSms = null,
49 nextVerificationAttempt = null,
50 allowedToRequestCode = true,
51 requestedInformation = emptyList(),
52 verified = true
53 )
54
55 fun createVerifyAccountResponse(aci: ServiceId, newPni: ServiceId): VerifyAccountResponse {
56 return VerifyAccountResponse().apply {
57 uuid = aci.toString()
58 pni = newPni.toString()
59 storageCapable = false
60 }
61 }
62
63 fun createWhoAmIResponse(aci: ServiceId, pni: ServiceId, e164: String): WhoAmIResponse {
64 return WhoAmIResponse().apply {
65 this.uuid = aci.toString()
66 this.pni = pni.toString()
67 this.number = e164
68 }
69 }
70
71 fun createPreKeyResponse(identity: IdentityKeyPair = SignalStore.account().aciIdentityKey, deviceId: Int): PreKeyResponse {
72 val signedPreKeyRecord = PreKeyUtil.generateSignedPreKey(SecureRandom().nextInt(Medium.MAX_VALUE), identity.privateKey)
73 val oneTimePreKey = PreKeyRecord(SecureRandom().nextInt(Medium.MAX_VALUE), Curve.generateKeyPair())
74
75 val device = PreKeyResponseItem().apply {
76 this.deviceId = deviceId
77 registrationId = KeyHelper.generateRegistrationId(false)
78 signedPreKey = SignedPreKeyEntity(signedPreKeyRecord.id, signedPreKeyRecord.keyPair.publicKey, signedPreKeyRecord.signature)
79 preKey = PreKeyEntity(oneTimePreKey.id, oneTimePreKey.keyPair.publicKey)
80 }
81
82 return PreKeyResponse().apply {
83 identityKey = identity.publicKey
84 devices = listOf(device)
85 }
86 }
87}