|
|
@ -33,7 +33,7 @@ extension OnionRequestAPI {
|
|
|
|
/// Encrypts `payload` for `snode` and returns the result. Use this to build the core of an onion request.
|
|
|
|
/// Encrypts `payload` for `snode` and returns the result. Use this to build the core of an onion request.
|
|
|
|
internal static func encrypt(_ payload: JSON, forTargetSnode snode: LokiAPITarget) -> Promise<EncryptionResult> {
|
|
|
|
internal static func encrypt(_ payload: JSON, forTargetSnode snode: LokiAPITarget) -> Promise<EncryptionResult> {
|
|
|
|
let (promise, seal) = Promise<EncryptionResult>.pending()
|
|
|
|
let (promise, seal) = Promise<EncryptionResult>.pending()
|
|
|
|
DispatchQueue.global().async {
|
|
|
|
DispatchQueue.global(qos: .userInitiated).async {
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
guard JSONSerialization.isValidJSONObject(payload) else { return seal.reject(HTTP.Error.invalidJSON) }
|
|
|
|
guard JSONSerialization.isValidJSONObject(payload) else { return seal.reject(HTTP.Error.invalidJSON) }
|
|
|
|
let payloadAsData = try JSONSerialization.data(withJSONObject: payload, options: [])
|
|
|
|
let payloadAsData = try JSONSerialization.data(withJSONObject: payload, options: [])
|
|
|
@ -53,7 +53,7 @@ extension OnionRequestAPI {
|
|
|
|
/// Encrypts the previous encryption result (i.e. that of the hop after this one) for this hop. Use this to build the layers of an onion request.
|
|
|
|
/// Encrypts the previous encryption result (i.e. that of the hop after this one) for this hop. Use this to build the layers of an onion request.
|
|
|
|
internal static func encryptHop(from lhs: LokiAPITarget, to rhs: LokiAPITarget, using previousEncryptionResult: EncryptionResult) -> Promise<EncryptionResult> {
|
|
|
|
internal static func encryptHop(from lhs: LokiAPITarget, to rhs: LokiAPITarget, using previousEncryptionResult: EncryptionResult) -> Promise<EncryptionResult> {
|
|
|
|
let (promise, seal) = Promise<EncryptionResult>.pending()
|
|
|
|
let (promise, seal) = Promise<EncryptionResult>.pending()
|
|
|
|
DispatchQueue.global().async {
|
|
|
|
DispatchQueue.global(qos: .userInitiated).async {
|
|
|
|
let parameters: JSON = [
|
|
|
|
let parameters: JSON = [
|
|
|
|
"ciphertext" : previousEncryptionResult.ciphertext.base64EncodedString(),
|
|
|
|
"ciphertext" : previousEncryptionResult.ciphertext.base64EncodedString(),
|
|
|
|
"ephemeral_key" : previousEncryptionResult.ephemeralPublicKey.toHexString(),
|
|
|
|
"ephemeral_key" : previousEncryptionResult.ephemeralPublicKey.toHexString(),
|
|
|
|