Parse pushed cipher if any
This commit is contained in:
parent
e900454504
commit
cff359fceb
|
@ -146,6 +146,12 @@ public protocol SessionReply {
|
||||||
|
|
||||||
/// The DNS servers set up for this session.
|
/// The DNS servers set up for this session.
|
||||||
var dnsServers: [String] { get }
|
var dnsServers: [String] { get }
|
||||||
|
|
||||||
|
/// The optional 24-bit peer-id.
|
||||||
|
var peerId: UInt32? { get }
|
||||||
|
|
||||||
|
/// The negotiated cipher if any (NCP).
|
||||||
|
var cipher: SessionProxy.Cipher? { get }
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SessionProxy {
|
extension SessionProxy {
|
||||||
|
@ -179,6 +185,8 @@ extension SessionProxy {
|
||||||
|
|
||||||
private static let peerIdRegexp = try! NSRegularExpression(pattern: "peer-id [0-9]+", options: [])
|
private static let peerIdRegexp = try! NSRegularExpression(pattern: "peer-id [0-9]+", options: [])
|
||||||
|
|
||||||
|
private static let cipherRegexp = try! NSRegularExpression(pattern: "cipher [^\\s]+", options: [])
|
||||||
|
|
||||||
let ipv4: IPv4Settings?
|
let ipv4: IPv4Settings?
|
||||||
|
|
||||||
let ipv6: IPv6Settings?
|
let ipv6: IPv6Settings?
|
||||||
|
@ -189,6 +197,8 @@ extension SessionProxy {
|
||||||
|
|
||||||
let peerId: UInt32?
|
let peerId: UInt32?
|
||||||
|
|
||||||
|
let cipher: SessionProxy.Cipher?
|
||||||
|
|
||||||
init?(message: String) throws {
|
init?(message: String) throws {
|
||||||
guard message.hasPrefix("PUSH_REPLY") else {
|
guard message.hasPrefix("PUSH_REPLY") else {
|
||||||
return nil
|
return nil
|
||||||
|
@ -207,6 +217,7 @@ extension SessionProxy {
|
||||||
var dnsServers: [String] = []
|
var dnsServers: [String] = []
|
||||||
var authToken: String?
|
var authToken: String?
|
||||||
var peerId: UInt32?
|
var peerId: UInt32?
|
||||||
|
var cipher: SessionProxy.Cipher?
|
||||||
|
|
||||||
// MARK: Routing (IPv4)
|
// MARK: Routing (IPv4)
|
||||||
|
|
||||||
|
@ -354,10 +365,17 @@ extension SessionProxy {
|
||||||
PushReply.peerIdRegexp.enumerateArguments(in: message) {
|
PushReply.peerIdRegexp.enumerateArguments(in: message) {
|
||||||
peerId = UInt32($0[0])
|
peerId = UInt32($0[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: NCP
|
||||||
|
|
||||||
|
PushReply.cipherRegexp.enumerateArguments(in: message) {
|
||||||
|
cipher = SessionProxy.Cipher(rawValue: $0[0].uppercased())
|
||||||
|
}
|
||||||
|
|
||||||
self.dnsServers = dnsServers
|
self.dnsServers = dnsServers
|
||||||
self.authToken = authToken
|
self.authToken = authToken
|
||||||
self.peerId = peerId
|
self.peerId = peerId
|
||||||
|
self.cipher = cipher
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,4 +91,12 @@ class PushTests: XCTestCase {
|
||||||
XCTAssertEqual(reply.ipv6?.defaultGateway, "fe80::601:30ff:feb7:dc02")
|
XCTAssertEqual(reply.ipv6?.defaultGateway, "fe80::601:30ff:feb7:dc02")
|
||||||
XCTAssertEqual(reply.dnsServers, ["2001:4860:4860::8888", "2001:4860:4860::8844"])
|
XCTAssertEqual(reply.dnsServers, ["2001:4860:4860::8888", "2001:4860:4860::8844"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testNCP() {
|
||||||
|
let msg = "PUSH_REPLY,dhcp-option DNS 8.8.8.8,dhcp-option DNS 4.4.4.4,comp-lzo no,route 10.8.0.1,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.6 10.8.0.5,peer-id 0,cipher AES-256-CBC"
|
||||||
|
let reply = try! SessionProxy.PushReply(message: msg)!
|
||||||
|
reply.debug()
|
||||||
|
|
||||||
|
XCTAssertEqual(reply.cipher, .aes256cbc)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue