From 7cc887267f973b3e17337249aaeee2632ce1d745 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Wed, 4 May 2022 16:12:45 +1000 Subject: [PATCH] fix retrieve from default inbox --- SessionSnodeKit/OnionRequestAPI.swift | 3 +++ SessionSnodeKit/SnodeAPI.swift | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/SessionSnodeKit/OnionRequestAPI.swift b/SessionSnodeKit/OnionRequestAPI.swift index 7a03b16f0..1a8b36ee4 100644 --- a/SessionSnodeKit/OnionRequestAPI.swift +++ b/SessionSnodeKit/OnionRequestAPI.swift @@ -395,6 +395,9 @@ public enum OnionRequestAPI { if statusCode == 406 { // Clock out of sync SNLog("The user's clock is out of sync with the service node network.") seal.reject(SnodeAPI.Error.clockOutOfSync) + } else if statusCode == 401 { // Signature verification failed + SNLog("Failed to verify the signature.") + seal.reject(SnodeAPI.Error.signatureVerificationFailed) } else if let bodyAsString = json["body"] as? String { guard let bodyAsData = bodyAsString.data(using: .utf8), let body = try JSONSerialization.jsonObject(with: bodyAsData, options: [ .fragmentsAllowed ]) as? JSON else { return seal.reject(HTTP.Error.invalidJSON) } diff --git a/SessionSnodeKit/SnodeAPI.swift b/SessionSnodeKit/SnodeAPI.swift index dea03b4cc..12b10c708 100644 --- a/SessionSnodeKit/SnodeAPI.swift +++ b/SessionSnodeKit/SnodeAPI.swift @@ -49,6 +49,7 @@ public final class SnodeAPI : NSObject { case inconsistentSnodePools case noKeyPair case signingFailed + case signatureVerificationFailed // ONS case decryptionFailed case hashingFailed @@ -62,6 +63,7 @@ public final class SnodeAPI : NSObject { case .inconsistentSnodePools: return "Received inconsistent Service Node pool information from the Service Node network." case .noKeyPair: return "Missing user key pair." case .signingFailed: return "Couldn't sign message." + case . signatureVerificationFailed: return "Failed to verify the signature." // ONS case .decryptionFailed: return "Couldn't decrypt ONS name." case .hashingFailed: return "Couldn't compute ONS name hash." @@ -456,7 +458,8 @@ public final class SnodeAPI : NSObject { // Construct signature let timestamp = UInt64(Int64(NSDate.millisecondTimestamp()) + SnodeAPI.clockOffset) let ed25519PublicKey = userED25519KeyPair.publicKey.toHexString() - guard let verificationData = ("retrieve" + String(namespace) + String(timestamp)).data(using: String.Encoding.utf8), + let namespaceVerificationString = namespace == defaultNamespace ? "" : String(namespace) + guard let verificationData = ("retrieve" + namespaceVerificationString + String(timestamp)).data(using: String.Encoding.utf8), let signature = sodium.sign.signature(message: Bytes(verificationData), secretKey: userED25519KeyPair.secretKey) else { return Promise(error: Error.signingFailed) } // Make the request