You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
//
|
|
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import PromiseKit
|
|
|
|
|
|
|
|
@objc(SSKRotateSignedPreKeyOperation)
|
|
|
|
public class RotateSignedPreKeyOperation: OWSOperation {
|
|
|
|
private var tsAccountManager: TSAccountManager {
|
|
|
|
return TSAccountManager.sharedInstance()
|
|
|
|
}
|
|
|
|
|
|
|
|
public override func run() {
|
|
|
|
Logger.debug("")
|
|
|
|
|
|
|
|
guard tsAccountManager.isRegistered() else {
|
|
|
|
Logger.debug("skipping - not registered")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
DispatchQueue.global().async {
|
|
|
|
let storage = OWSPrimaryStorage.shared()
|
|
|
|
let signedPreKeyRecord = storage.generateRandomSignedRecord()
|
|
|
|
signedPreKeyRecord.markAsAcceptedByService()
|
|
|
|
storage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord)
|
|
|
|
storage.setCurrentSignedPrekeyId(signedPreKeyRecord.id)
|
|
|
|
TSPreKeyManager.clearPreKeyUpdateFailureCount()
|
|
|
|
TSPreKeyManager.clearSignedPreKeyRecords()
|
|
|
|
SNLog("Signed pre key rotated successfully.")
|
|
|
|
self.reportSuccess()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override public func didFail(error: Error) {
|
|
|
|
Logger.debug("don't report SPK rotation failure w/ non NetworkManager error: \(error)")
|
|
|
|
}
|
|
|
|
}
|