Fix incorrect padding setting
This commit is contained in:
parent
3c2109e698
commit
ede00b1a02
|
@ -42,8 +42,7 @@ internal enum HTTP {
|
|||
// MARK: Main
|
||||
internal static func execute(_ verb: Verb, _ url: String, parameters: JSON? = nil, timeout: TimeInterval = HTTP.timeout) -> Promise<JSON> {
|
||||
return Promise<JSON> { seal in
|
||||
let url = URL(string: url)!
|
||||
var request = URLRequest(url: url)
|
||||
var request = URLRequest(url: URL(string: url)!)
|
||||
request.httpMethod = verb.rawValue
|
||||
if let parameters = parameters {
|
||||
do {
|
||||
|
|
|
@ -43,14 +43,14 @@ public extension LokiAPI {
|
|||
let target = seedNodePool.randomElement()!
|
||||
let url = "\(target)/json_rpc"
|
||||
let parameters: JSON = [
|
||||
"method" : "get_service_nodes",
|
||||
"method" : "get_n_service_nodes",
|
||||
"params" : [
|
||||
"active_only" : true,
|
||||
"fields" : [
|
||||
"public_ip" : true,
|
||||
"storage_port" : true,
|
||||
"pubkey_ed25519": true,
|
||||
"pubkey_x25519": true
|
||||
"pubkey_ed25519" : true,
|
||||
"pubkey_x25519" : true
|
||||
]
|
||||
]
|
||||
]
|
||||
|
|
|
@ -29,12 +29,13 @@ public final class LokiAPI : NSObject {
|
|||
internal static let userHexEncodedPublicKey = getUserHexEncodedPublicKey()
|
||||
|
||||
// MARK: Settings
|
||||
private static let apiVersion = "v1"
|
||||
private static let maxRetryCount: UInt = 8
|
||||
private static let maxRetryCount: UInt = 4
|
||||
private static let defaultTimeout: TimeInterval = 20
|
||||
private static let longPollingTimeout: TimeInterval = 40
|
||||
private static var userIDScanLimit: UInt = 4096
|
||||
internal static var powDifficulty: UInt = 4
|
||||
|
||||
internal static var powDifficulty: UInt = 2
|
||||
|
||||
public static let defaultMessageTTL: UInt64 = 24 * 60 * 60 * 1000
|
||||
public static let deviceLinkUpdateInterval: TimeInterval = 20
|
||||
|
||||
|
@ -93,8 +94,8 @@ public final class LokiAPI : NSObject {
|
|||
|
||||
// MARK: Internal API
|
||||
internal static func invoke(_ method: LokiAPITarget.Method, on target: LokiAPITarget, associatedWith hexEncodedPublicKey: String,
|
||||
parameters: [String:Any], headers: [String:String]? = nil, timeout: TimeInterval? = nil) -> RawResponsePromise {
|
||||
let url = URL(string: "\(target.address):\(target.port)/storage_rpc/\(apiVersion)")!
|
||||
parameters: JSON, headers: [String:String]? = nil, timeout: TimeInterval? = nil) -> RawResponsePromise {
|
||||
let url = URL(string: "\(target.address):\(target.port)/storage_rpc/v1")!
|
||||
let request = TSRequest(url: url, method: "POST", parameters: [ "method" : method.rawValue, "params" : parameters ])
|
||||
if let headers = headers { request.allHTTPHeaderFields = headers }
|
||||
request.timeoutInterval = timeout ?? defaultTimeout
|
||||
|
|
|
@ -25,7 +25,7 @@ extension OnionRequestAPI {
|
|||
guard !Thread.isMainThread else { preconditionFailure("It's illegal to call encrypt(_:usingAESGCMWithSymmetricKey:) from the main thread.") }
|
||||
let iv = try getSecureRandomData(ofSize: ivSize)
|
||||
let gcm = GCM(iv: iv.bytes, tagLength: Int(gcmTagSize), mode: .combined)
|
||||
let aes = try AES(key: symmetricKey.bytes, blockMode: gcm, padding: .pkcs7)
|
||||
let aes = try AES(key: symmetricKey.bytes, blockMode: gcm, padding: .noPadding)
|
||||
let ciphertext = try aes.encrypt(plaintext.bytes)
|
||||
return iv + Data(bytes: ciphertext)
|
||||
}
|
||||
|
|
|
@ -199,7 +199,7 @@ internal enum OnionRequestAPI {
|
|||
let ciphertext = ivAndCiphertext[Int(ivSize)...]
|
||||
do {
|
||||
let gcm = GCM(iv: iv.bytes, tagLength: Int(gcmTagSize), mode: .combined)
|
||||
let aes = try AES(key: targetSnodeSymmetricKey.bytes, blockMode: gcm, padding: .pkcs7)
|
||||
let aes = try AES(key: targetSnodeSymmetricKey.bytes, blockMode: gcm, padding: .noPadding)
|
||||
let result = try aes.decrypt(ciphertext.bytes)
|
||||
seal.fulfill(Data(bytes: result))
|
||||
} catch (let error) {
|
||||
|
|
|
@ -12,6 +12,7 @@ class OnionRequestAPITests : XCTestCase {
|
|||
var totalSuccessRate: Double = 0
|
||||
let testCount = 10
|
||||
LokiAPI.getRandomSnode().then(on: OnionRequestAPI.workQueue) { snode -> Promise<LokiAPITarget> in
|
||||
print("[Loki] [Onion Request API] Target snode: \(snode).")
|
||||
return OnionRequestAPI.getPath(excluding: snode).map(on: OnionRequestAPI.workQueue) { _ in snode } // Ensure we only build a path once
|
||||
}.done(on: OnionRequestAPI.workQueue) { snode in
|
||||
var successCount = 0
|
||||
|
|
Loading…
Reference in New Issue