Fixed an issue where ONS lookups stopped working

pull/988/head
Morgan Pretty 8 months ago
parent b3d90df15e
commit d44871e2a8

@ -1 +1 @@
Subproject commit f0016f512956c3f8fef83e3daf17e76fec272968
Subproject commit 116256ab521e421420ed9bcd9e10cb0e9c78e468

@ -17,27 +17,42 @@ internal extension Crypto.Generator {
id: "sessionId_for_ONS_response",
args: [name, response]
) {
guard let hexEncodedNonce: String = response.result.nonce else {
guard var cName: [CChar] = name.lowercased().cString(using: .utf8) else {
throw SnodeAPIError.onsDecryptionFailed
}
// Name must be in lowercase
var cCiphertext: [UInt8] = Array(Data(hex: response.result.encryptedValue))
var cNonce: [UInt8] = Array(Data(hex: hexEncodedNonce))
var cSessionId: [CChar] = [CChar](repeating: 0, count: 67)
guard
cNonce.count == 24,
var cName: [CChar] = name.lowercased().cString(using: .utf8),
session_decrypt_ons_response(
&cName,
cName.count,
&cCiphertext,
cCiphertext.count,
&cNonce,
&cSessionId
)
else { throw SnodeAPIError.onsDecryptionFailed }
// Need to switch on `result.nonce` and explciitly pass `nil` because passing an optional
// to a C function doesn't seem to work correctly
switch response.result.nonce {
case .none:
guard
session_decrypt_ons_response(
&cName,
&cCiphertext,
cCiphertext.count,
nil,
&cSessionId
)
else { throw SnodeAPIError.onsDecryptionFailed }
case .some(let nonce):
var cNonce: [UInt8] = Array(Data(hex: nonce))
guard
cNonce.count == 24,
session_decrypt_ons_response(
&cName,
&cCiphertext,
cCiphertext.count,
&cNonce,
&cSessionId
)
else { throw SnodeAPIError.onsDecryptionFailed }
}
return String(cString: cSessionId)
}

Loading…
Cancel
Save