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", id: "sessionId_for_ONS_response",
args: [name, 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 throw SnodeAPIError.onsDecryptionFailed
} }
// Name must be in lowercase // Name must be in lowercase
var cCiphertext: [UInt8] = Array(Data(hex: response.result.encryptedValue)) var cCiphertext: [UInt8] = Array(Data(hex: response.result.encryptedValue))
var cNonce: [UInt8] = Array(Data(hex: hexEncodedNonce))
var cSessionId: [CChar] = [CChar](repeating: 0, count: 67) var cSessionId: [CChar] = [CChar](repeating: 0, count: 67)
// 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 guard
cNonce.count == 24, cNonce.count == 24,
var cName: [CChar] = name.lowercased().cString(using: .utf8),
session_decrypt_ons_response( session_decrypt_ons_response(
&cName, &cName,
cName.count,
&cCiphertext, &cCiphertext,
cCiphertext.count, cCiphertext.count,
&cNonce, &cNonce,
&cSessionId &cSessionId
) )
else { throw SnodeAPIError.onsDecryptionFailed } else { throw SnodeAPIError.onsDecryptionFailed }
}
return String(cString: cSessionId) return String(cString: cSessionId)
} }

Loading…
Cancel
Save