mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-24 10:51:27 +01:00
Use long for key id.
This commit is contained in:
@@ -2850,6 +2850,10 @@ public class SignalServiceMessageSender {
|
||||
try {
|
||||
List<PreKeyBundle> preKeys = getPreKeys(recipient, sealedSenderAccess, deviceId, story);
|
||||
|
||||
if (preKeys.isEmpty()) {
|
||||
throw new InvalidKeyException("No valid prekey bundles available for " + signalProtocolAddress);
|
||||
}
|
||||
|
||||
for (PreKeyBundle preKey : preKeys) {
|
||||
Log.d(TAG, "Initializing prekey session for " + signalProtocolAddress);
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ class KeysApi(
|
||||
fun setPreKeys(preKeyUpload: PreKeyUpload): NetworkResult<Unit> {
|
||||
val signedPreKey: SignedPreKeyEntity? = if (preKeyUpload.signedPreKey != null) {
|
||||
SignedPreKeyEntity(
|
||||
preKeyUpload.signedPreKey.id,
|
||||
preKeyUpload.signedPreKey.id.toLong(),
|
||||
preKeyUpload.signedPreKey.keyPair.publicKey,
|
||||
preKeyUpload.signedPreKey.signature
|
||||
)
|
||||
@@ -105,14 +105,14 @@ class KeysApi(
|
||||
val oneTimeEcPreKeys: List<PreKeyEntity>? = if (preKeyUpload.oneTimeEcPreKeys != null) {
|
||||
preKeyUpload
|
||||
.oneTimeEcPreKeys
|
||||
.map { oneTimeEcKey: PreKeyRecord -> PreKeyEntity(oneTimeEcKey.id, oneTimeEcKey.keyPair.publicKey) }
|
||||
.map { oneTimeEcKey: PreKeyRecord -> PreKeyEntity(oneTimeEcKey.id.toLong(), oneTimeEcKey.keyPair.publicKey) }
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
val lastResortKyberPreKey: KyberPreKeyEntity? = if (preKeyUpload.lastResortKyberPreKey != null) {
|
||||
KyberPreKeyEntity(
|
||||
preKeyUpload.lastResortKyberPreKey.id,
|
||||
preKeyUpload.lastResortKyberPreKey.id.toLong(),
|
||||
preKeyUpload.lastResortKyberPreKey.keyPair.publicKey,
|
||||
preKeyUpload.lastResortKyberPreKey.signature
|
||||
)
|
||||
@@ -123,7 +123,7 @@ class KeysApi(
|
||||
val oneTimeKyberPreKeys: List<KyberPreKeyEntity>? = if (preKeyUpload.oneTimeKyberPreKeys != null) {
|
||||
preKeyUpload
|
||||
.oneTimeKyberPreKeys
|
||||
.map { record -> KyberPreKeyEntity(record.id, record.keyPair.publicKey, record.signature) }
|
||||
.map { record -> KyberPreKeyEntity(record.id.toLong(), record.keyPair.publicKey, record.signature) }
|
||||
} else {
|
||||
null
|
||||
}
|
||||
@@ -215,8 +215,13 @@ class KeysApi(
|
||||
var kyberPreKeySignature: ByteArray? = null
|
||||
|
||||
if (device.getSignedPreKey() != null) {
|
||||
val rawSignedPreKeyId = device.getSignedPreKey().keyId
|
||||
if (rawSignedPreKeyId !in 0..Int.MAX_VALUE) {
|
||||
Log.w(TAG, "Signed pre-key ID for device ${device.deviceId} is out of valid range! Skipping.")
|
||||
continue
|
||||
}
|
||||
signedPreKey = device.getSignedPreKey().publicKey
|
||||
signedPreKeyId = device.getSignedPreKey().keyId
|
||||
signedPreKeyId = rawSignedPreKeyId.toInt()
|
||||
signedPreKeySignature = device.getSignedPreKey().signature
|
||||
} else {
|
||||
Log.w(TAG, "No signed prekey for device ${device.deviceId}! Skipping.")
|
||||
@@ -224,13 +229,23 @@ class KeysApi(
|
||||
}
|
||||
|
||||
if (device.getPreKey() != null) {
|
||||
preKeyId = device.getPreKey().keyId
|
||||
val rawPreKeyId = device.getPreKey().keyId
|
||||
if (rawPreKeyId !in 0..Int.MAX_VALUE) {
|
||||
Log.w(TAG, "Pre-key ID for device ${device.deviceId} is out of valid range! Skipping.")
|
||||
continue
|
||||
}
|
||||
preKeyId = rawPreKeyId.toInt()
|
||||
preKey = device.getPreKey().publicKey
|
||||
}
|
||||
|
||||
if (device.getKyberPreKey() != null) {
|
||||
val rawKyberPreKeyId = device.getKyberPreKey().keyId
|
||||
if (rawKyberPreKeyId !in 0..Int.MAX_VALUE) {
|
||||
Log.w(TAG, "Kyber pre-key ID for device ${device.deviceId} is out of valid range! Skipping.")
|
||||
continue
|
||||
}
|
||||
kyberPreKey = device.getKyberPreKey().publicKey
|
||||
kyberPreKeyId = device.getKyberPreKey().keyId
|
||||
kyberPreKeyId = rawKyberPreKeyId.toInt()
|
||||
kyberPreKeySignature = device.getKyberPreKey().signature
|
||||
} else {
|
||||
Log.w(TAG, "No kyber prekey for device ${device.deviceId}! Skipping.")
|
||||
|
||||
@@ -31,7 +31,7 @@ public class SignedPreKeyEntity extends PreKeyEntity {
|
||||
|
||||
public SignedPreKeyEntity() {}
|
||||
|
||||
public SignedPreKeyEntity(int keyId, ECPublicKey publicKey, byte[] signature) {
|
||||
public SignedPreKeyEntity(long keyId, ECPublicKey publicKey, byte[] signature) {
|
||||
super(keyId, publicKey);
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
@@ -154,10 +154,10 @@ class RegistrationApi(
|
||||
val request = RegisterAsSecondaryDeviceRequest(
|
||||
verificationCode = verificationCode,
|
||||
accountAttributes = attributes,
|
||||
aciSignedPreKey = SignedPreKeyEntity(aciPreKeys.signedPreKey.id, aciPreKeys.signedPreKey.keyPair.publicKey, aciPreKeys.signedPreKey.signature),
|
||||
pniSignedPreKey = SignedPreKeyEntity(pniPreKeys.signedPreKey.id, pniPreKeys.signedPreKey.keyPair.publicKey, pniPreKeys.signedPreKey.signature),
|
||||
aciPqLastResortPreKey = KyberPreKeyEntity(aciPreKeys.lastResortKyberPreKey.id, aciPreKeys.lastResortKyberPreKey.keyPair.publicKey, aciPreKeys.lastResortKyberPreKey.signature),
|
||||
pniPqLastResortPreKey = KyberPreKeyEntity(pniPreKeys.lastResortKyberPreKey.id, pniPreKeys.lastResortKyberPreKey.keyPair.publicKey, pniPreKeys.lastResortKyberPreKey.signature),
|
||||
aciSignedPreKey = SignedPreKeyEntity(aciPreKeys.signedPreKey.id.toLong(), aciPreKeys.signedPreKey.keyPair.publicKey, aciPreKeys.signedPreKey.signature),
|
||||
pniSignedPreKey = SignedPreKeyEntity(pniPreKeys.signedPreKey.id.toLong(), pniPreKeys.signedPreKey.keyPair.publicKey, pniPreKeys.signedPreKey.signature),
|
||||
aciPqLastResortPreKey = KyberPreKeyEntity(aciPreKeys.lastResortKyberPreKey.id.toLong(), aciPreKeys.lastResortKyberPreKey.keyPair.publicKey, aciPreKeys.lastResortKyberPreKey.signature),
|
||||
pniPqLastResortPreKey = KyberPreKeyEntity(pniPreKeys.lastResortKyberPreKey.id.toLong(), pniPreKeys.lastResortKyberPreKey.keyPair.publicKey, pniPreKeys.lastResortKyberPreKey.signature),
|
||||
gcmToken = fcmToken?.let { GcmRegistrationId(it, true) }
|
||||
)
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.io.IOException;
|
||||
public class KyberPreKeyEntity {
|
||||
|
||||
@JsonProperty
|
||||
private int keyId;
|
||||
private long keyId;
|
||||
|
||||
@JsonProperty
|
||||
@JsonSerialize(using = KEMPublicKeySerializer.class)
|
||||
@@ -39,13 +39,13 @@ public class KyberPreKeyEntity {
|
||||
|
||||
public KyberPreKeyEntity() {}
|
||||
|
||||
public KyberPreKeyEntity(int keyId, KEMPublicKey publicKey, byte[] signature) {
|
||||
public KyberPreKeyEntity(long keyId, KEMPublicKey publicKey, byte[] signature) {
|
||||
this.keyId = keyId;
|
||||
this.publicKey = publicKey;
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public int getKeyId() {
|
||||
public long getKeyId() {
|
||||
return keyId;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.io.IOException;
|
||||
public class PreKeyEntity {
|
||||
|
||||
@JsonProperty
|
||||
private int keyId;
|
||||
private long keyId;
|
||||
|
||||
@JsonProperty
|
||||
@JsonSerialize(using = ECPublicKeySerializer.class)
|
||||
@@ -34,12 +34,12 @@ public class PreKeyEntity {
|
||||
|
||||
public PreKeyEntity() {}
|
||||
|
||||
public PreKeyEntity(int keyId, ECPublicKey publicKey) {
|
||||
public PreKeyEntity(long keyId, ECPublicKey publicKey) {
|
||||
this.keyId = keyId;
|
||||
this.publicKey = publicKey;
|
||||
}
|
||||
|
||||
public int getKeyId() {
|
||||
public long getKeyId() {
|
||||
return keyId;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user