wip
This commit is contained in:
parent
9ee1f80afa
commit
40d2fe6383
|
@ -40,43 +40,45 @@ final class ClientMartinOMEMO {
|
|||
|
||||
let hasKeyPair = keyPair() != nil
|
||||
if wipe || localRegistrationId() == 0 || !hasKeyPair {
|
||||
let regId: UInt32 = context.generateRegistrationId()
|
||||
let regId = context.generateRegistrationId()
|
||||
let address = SignalAddress(name: credentials.bareJid, deviceId: Int32(regId))
|
||||
|
||||
var settings = Settings.getFor(credentials.bareJid)
|
||||
settings?.omemoRegId = Int(regId)
|
||||
settings?.save()
|
||||
|
||||
let keyPair = SignalIdentityKeyPair.generateKeyPair(context: context)
|
||||
guard let keyPair = SignalIdentityKeyPair.generateKeyPair(context: context), let publicKey = keyPair.publicKey else {
|
||||
return false
|
||||
}
|
||||
let fingerprint = publicKey.map { byte -> String in
|
||||
String(format: "%02x", byte)
|
||||
}.joined()
|
||||
|
||||
// do {
|
||||
// _ = try Database.shared.dbQueue.write { db in
|
||||
// try OMEMOIdentity(
|
||||
// account: credentials.bareJid,
|
||||
// name: credentials.bareJid,
|
||||
// deviceId: regId,
|
||||
// key: keyPair.publicKey,
|
||||
// fingerprint: fingerprint(publicKey: keyPair.publicKey),
|
||||
// status: MartinOMEMO.IdentityStatus.trusted.rawValue,
|
||||
// own: 1
|
||||
// )
|
||||
// .insert(db)
|
||||
// }
|
||||
// } catch {
|
||||
// logIt(.error, "Error storing identity key: \(error.localizedDescription)")
|
||||
// return false
|
||||
// }
|
||||
guard !OMEMOIdentity.existsFor(account: credentials.bareJid, name: credentials.bareJid, fingerprint: fingerprint) else {
|
||||
return false
|
||||
}
|
||||
|
||||
// 102
|
||||
// if !identityKeyStore.save(identity: SignalAddress(name: context!.sessionObject.userBareJid!.stringValue, deviceId: Int32(identityKeyStore.localRegistrationId())), key: keyPair) {}
|
||||
do {
|
||||
_ = try Database.shared.dbQueue.write { db in
|
||||
try OMEMOIdentity(
|
||||
account: credentials.bareJid,
|
||||
name: address.name,
|
||||
deviceId: Int(address.deviceId),
|
||||
fingerprint: fingerprint,
|
||||
key: keyPair.serialized(),
|
||||
own: true,
|
||||
status: MartinOMEMO.IdentityStatus.trustedActive.rawValue
|
||||
)
|
||||
.insert(db)
|
||||
}
|
||||
return true
|
||||
} catch {
|
||||
logIt(.error, "Error storing identity key: \(error.localizedDescription)")
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private func fingerprint(publicKey: Data) -> String {
|
||||
publicKey.map { byte -> String in
|
||||
String(format: "%02x", byte)
|
||||
}.joined()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Session
|
||||
|
|
|
@ -112,6 +112,20 @@ extension OMEMOIdentity {
|
|||
logIt(.error, "Failed to wipe OMEMO identity: \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
static func existsFor(account: String, name: String, fingerprint: String) -> Bool {
|
||||
do {
|
||||
return try Database.shared.dbQueue.read { db in
|
||||
try OMEMOIdentity
|
||||
.filter(Column("account") == account)
|
||||
.filter(Column("name") == name)
|
||||
.filter(Column("fingerprint") == fingerprint)
|
||||
.fetchOne(db) != nil
|
||||
}
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - PreKey
|
||||
|
|
Loading…
Reference in a new issue