pull/156/head
gmbnt 5 years ago
parent 85a4dd0546
commit 664717b1d0

@ -11,7 +11,6 @@ internal final class LokiAPITarget : NSObject, NSCoding {
/// Only supported by snode targets.
case getMessages = "retrieve"
case sendMessage = "store"
case getStats = "get_stats"
}
internal struct KeySet {

@ -33,8 +33,8 @@ extension OnionRequestAPI {
let snodeX25519PublicKey = Data(hex: hexEncodedSnodeX25519PublicKey)
let ephemeralKeyPair = Curve25519.generateKeyPair()
let ephemeralSharedSecret = try Curve25519.generateSharedSecret(fromPublicKey: snodeX25519PublicKey, privateKey: ephemeralKeyPair.privateKey)
let key = "LOKI"
let symmetricKey = try HMAC(key: key.bytes, variant: .sha256).authenticate(ephemeralSharedSecret.bytes)
let salt = "LOKI"
let symmetricKey = try HMAC(key: salt.bytes, variant: .sha256).authenticate(ephemeralSharedSecret.bytes)
let ciphertext = try encrypt(plaintext, usingAESGCMWithSymmetricKey: Data(bytes: symmetricKey))
return (ciphertext, Data(bytes: symmetricKey), ephemeralKeyPair.publicKey)
}

@ -4,9 +4,9 @@ import PromiseKit
/// See the "Onion Requests" section of [The Session Whitepaper](https://arxiv.org/pdf/2002.04609.pdf) for more information.
internal enum OnionRequestAPI {
/// - Note: Must only be modified from `LokiAPI.workQueue`.
internal static var guardSnodes: Set<LokiAPITarget> = []
private static var guardSnodes: Set<LokiAPITarget> = []
/// - Note: Must only be modified from `LokiAPI.workQueue`.
internal static var paths: Set<Path> = []
private static var paths: Set<Path> = []
private static var snodePool: Set<LokiAPITarget> {
let unreliableSnodes = Set(LokiAPI.failureCount.keys)
@ -111,7 +111,7 @@ internal enum OnionRequestAPI {
return Set(guardSnodes.map { guardSnode in
let result = [ guardSnode ] + (0..<(pathSize - 1)).map { _ in
// randomElement() uses the system's default random generator, which is cryptographically secure
let pathSnode = unusedSnodes.randomElement()! // Safe because of the minSnodeCount check above
let pathSnode = unusedSnodes.randomElement()! // Safe because of the pathSnodeCount check above
unusedSnodes.remove(pathSnode) // All used snodes should be unique
return pathSnode
}

Loading…
Cancel
Save