Fix pre key bundle usage

pull/33/head
Niels Andriesse 6 years ago
parent 923f4a0f7c
commit de346cb645

@ -23,21 +23,21 @@ public class CreatePreKeysOperation: OWSOperation {
public override func run() { public override func run() {
Logger.debug("") Logger.debug("")
if self.identityKeyManager.identityKeyPair() == nil { if identityKeyManager.identityKeyPair() == nil {
self.identityKeyManager.generateNewIdentityKey() identityKeyManager.generateNewIdentityKey()
} }
// Loki: We don't generate PreKeyRecords here. // Loki: We don't generate PreKeyRecords here.
// This is because we need the records to be linked to a contact since we don't have a central server. // This is because we need the records to be linked to a contact since we don't have a central server.
// It is done automatically when we generate a PreKeyBundle to send to a contact (`generatePreKeyBundleForContact:`). // It is done automatically when we generate a PreKeyBundle to send to a contact (`generatePreKeyBundleForContact:`).
// You can use `getOrCreatePreKeyForContact:` to generate one if needed. // You can use `getOrCreatePreKeyForContact:` to generate one if needed.
let signedPreKeyRecord = self.primaryStorage.generateRandomSignedRecord() let signedPreKeyRecord = primaryStorage.generateRandomSignedRecord()
signedPreKeyRecord.markAsAcceptedByService() signedPreKeyRecord.markAsAcceptedByService()
self.primaryStorage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord) primaryStorage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord)
self.primaryStorage.setCurrentSignedPrekeyId(signedPreKeyRecord.id) primaryStorage.setCurrentSignedPrekeyId(signedPreKeyRecord.id)
print("[Loki] Create pre keys operation done.") print("[Loki] Pre keys created successfully.")
self.reportSuccess() reportSuccess()
/* Loki: Original code /* Loki: Original code
* ================ * ================

@ -36,12 +36,11 @@ public class RefreshPreKeysOperation: OWSOperation {
return return
} }
// Loki: Doing this on the global queue because they do it at the bottom // Loki: Doing this on the global queue to match Signal
DispatchQueue.global().async { DispatchQueue.global().async {
guard self.primaryStorage.currentSignedPrekeyId() == nil else { guard self.primaryStorage.currentSignedPrekeyId() == nil else {
Logger.debug("Already have a signed prekey set") print("[Loki] Using existing signed pre key.")
self.reportSuccess() return self.reportSuccess()
return
} }
let signedPreKeyRecord = self.primaryStorage.generateRandomSignedRecord() let signedPreKeyRecord = self.primaryStorage.generateRandomSignedRecord()
@ -52,7 +51,7 @@ public class RefreshPreKeysOperation: OWSOperation {
TSPreKeyManager.clearPreKeyUpdateFailureCount() TSPreKeyManager.clearPreKeyUpdateFailureCount()
TSPreKeyManager.clearSignedPreKeyRecords() TSPreKeyManager.clearSignedPreKeyRecords()
print("[Loki] Pre key refresh operation done.") print("[Loki] Pre keys refreshed successfully.")
self.reportSuccess() self.reportSuccess()
} }

@ -27,7 +27,7 @@ public class RotateSignedPreKeyOperation: OWSOperation {
return return
} }
// Loki: Doing this on the global queue because they do it at the bottom // Loki: Doing this on the global queue to match Signal
DispatchQueue.global().async { DispatchQueue.global().async {
let signedPreKeyRecord = self.primaryStorage.generateRandomSignedRecord() let signedPreKeyRecord = self.primaryStorage.generateRandomSignedRecord()
signedPreKeyRecord.markAsAcceptedByService() signedPreKeyRecord.markAsAcceptedByService()
@ -37,7 +37,7 @@ public class RotateSignedPreKeyOperation: OWSOperation {
TSPreKeyManager.clearPreKeyUpdateFailureCount() TSPreKeyManager.clearPreKeyUpdateFailureCount()
TSPreKeyManager.clearSignedPreKeyRecords() TSPreKeyManager.clearSignedPreKeyRecords()
print("[Loki] Rotate signed pre key operation done.") print("[Loki] Pre keys rotated successfully.")
self.reportSuccess() self.reportSuccess()
} }

@ -89,7 +89,16 @@
ECKeyPair *_Nullable keyPair = self.identityManager.identityKeyPair; ECKeyPair *_Nullable keyPair = self.identityManager.identityKeyPair;
OWSAssertDebug(keyPair); OWSAssertDebug(keyPair);
// Refresh the signed pre key if needed
if (self.currentSignedPreKey == nil) {
SignedPreKeyRecord *signedPreKeyRecord = [self generateRandomSignedRecord];
[signedPreKeyRecord markAsAcceptedByService];
[self storeSignedPreKey:signedPreKeyRecord.Id signedPreKeyRecord:signedPreKeyRecord];
[self setCurrentSignedPrekeyId:signedPreKeyRecord.Id];
NSLog(@"[Loki] Pre keys refreshed successfully.");
}
SignedPreKeyRecord *_Nullable signedPreKey = self.currentSignedPreKey; SignedPreKeyRecord *_Nullable signedPreKey = self.currentSignedPreKey;
if (!signedPreKey) { if (!signedPreKey) {
OWSFailDebug(@"Signed prekey is null"); OWSFailDebug(@"Signed prekey is null");

Loading…
Cancel
Save