Refine linter rules excepting a few
This commit is contained in:
parent
0c77062add
commit
d8563e7f15
|
@ -0,0 +1,12 @@
|
||||||
|
analyzer_rules:
|
||||||
|
- unused_declaration
|
||||||
|
- unused_import
|
||||||
|
disabled_rules:
|
||||||
|
- cyclomatic_complexity
|
||||||
|
- file_length
|
||||||
|
- force_cast
|
||||||
|
- function_body_length
|
||||||
|
- identifier_name
|
||||||
|
- line_length
|
||||||
|
- nesting
|
||||||
|
- todo
|
|
@ -88,20 +88,32 @@ aeb893d9a96d1f15519bb3c4dcb40ee3
|
||||||
-----END OpenVPN Static key V1-----
|
-----END OpenVPN Static key V1-----
|
||||||
""", direction: .client)!
|
""", direction: .client)!
|
||||||
|
|
||||||
static func make(_ title: String, appGroup: String, hostname: String, port: UInt16, socketType: SocketType) -> OpenVPN.ProviderConfiguration {
|
struct Parameters {
|
||||||
|
let title: String
|
||||||
|
|
||||||
|
let appGroup: String
|
||||||
|
|
||||||
|
let hostname: String
|
||||||
|
|
||||||
|
let port: UInt16
|
||||||
|
|
||||||
|
let socketType: SocketType
|
||||||
|
}
|
||||||
|
|
||||||
|
static func make(params: Parameters) -> OpenVPN.ProviderConfiguration {
|
||||||
var builder = OpenVPN.ConfigurationBuilder()
|
var builder = OpenVPN.ConfigurationBuilder()
|
||||||
builder.ca = ca
|
builder.ca = ca
|
||||||
builder.cipher = .aes256cbc
|
builder.cipher = .aes256cbc
|
||||||
builder.digest = .sha512
|
builder.digest = .sha512
|
||||||
builder.compressionFraming = .compLZO
|
builder.compressionFraming = .compLZO
|
||||||
builder.renegotiatesAfter = nil
|
builder.renegotiatesAfter = nil
|
||||||
builder.remotes = [Endpoint(hostname, EndpointProtocol(socketType, port))]
|
builder.remotes = [Endpoint(params.hostname, EndpointProtocol(params.socketType, params.port))]
|
||||||
builder.tlsWrap = TLSWrap(strategy: .auth, key: tlsKey)
|
builder.tlsWrap = TLSWrap(strategy: .auth, key: tlsKey)
|
||||||
builder.mtu = 1350
|
builder.mtu = 1350
|
||||||
builder.routingPolicies = [.IPv4, .IPv6]
|
builder.routingPolicies = [.IPv4, .IPv6]
|
||||||
let cfg = builder.build()
|
let cfg = builder.build()
|
||||||
|
|
||||||
var providerConfiguration = OpenVPN.ProviderConfiguration(title, appGroup: appGroup, configuration: cfg)
|
var providerConfiguration = OpenVPN.ProviderConfiguration(params.title, appGroup: params.appGroup, configuration: cfg)
|
||||||
providerConfiguration.shouldDebug = true
|
providerConfiguration.shouldDebug = true
|
||||||
providerConfiguration.masksPrivateData = false
|
providerConfiguration.masksPrivateData = false
|
||||||
return providerConfiguration
|
return providerConfiguration
|
||||||
|
@ -110,24 +122,43 @@ aeb893d9a96d1f15519bb3c4dcb40ee3
|
||||||
}
|
}
|
||||||
|
|
||||||
extension WireGuard {
|
extension WireGuard {
|
||||||
|
struct Parameters {
|
||||||
|
let title: String
|
||||||
|
|
||||||
|
let appGroup: String
|
||||||
|
|
||||||
|
let clientPrivateKey: String
|
||||||
|
|
||||||
|
let clientAddress: String
|
||||||
|
|
||||||
|
let serverPublicKey: String
|
||||||
|
|
||||||
|
let serverAddress: String
|
||||||
|
|
||||||
|
let serverPort: String
|
||||||
|
}
|
||||||
|
|
||||||
struct DemoConfiguration {
|
struct DemoConfiguration {
|
||||||
static func make(
|
static func make(params: Parameters) -> WireGuard.ProviderConfiguration? {
|
||||||
_ title: String,
|
var builder: WireGuard.ConfigurationBuilder
|
||||||
appGroup: String,
|
do {
|
||||||
clientPrivateKey: String,
|
builder = try WireGuard.ConfigurationBuilder(params.clientPrivateKey)
|
||||||
clientAddress: String,
|
} catch {
|
||||||
serverPublicKey: String,
|
print(">>> \(error)")
|
||||||
serverAddress: String,
|
return nil
|
||||||
serverPort: String
|
}
|
||||||
) -> WireGuard.ProviderConfiguration? {
|
builder.addresses = [params.clientAddress]
|
||||||
var builder = try! WireGuard.ConfigurationBuilder(clientPrivateKey)
|
|
||||||
builder.addresses = [clientAddress]
|
|
||||||
builder.dnsServers = ["1.1.1.1", "1.0.0.1"]
|
builder.dnsServers = ["1.1.1.1", "1.0.0.1"]
|
||||||
try! builder.addPeer(serverPublicKey, endpoint: "\(serverAddress):\(serverPort)")
|
do {
|
||||||
|
try builder.addPeer(params.serverPublicKey, endpoint: "\(params.serverAddress):\(params.serverPort)")
|
||||||
|
} catch {
|
||||||
|
print(">>> \(error)")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
builder.addDefaultGatewayIPv4(toPeer: 0)
|
builder.addDefaultGatewayIPv4(toPeer: 0)
|
||||||
let cfg = builder.build()
|
let cfg = builder.build()
|
||||||
|
|
||||||
return WireGuard.ProviderConfiguration(title, appGroup: appGroup, configuration: cfg)
|
return WireGuard.ProviderConfiguration(params.title, appGroup: params.appGroup, configuration: cfg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,13 +108,13 @@ class OpenVPNViewController: UIViewController {
|
||||||
let socketType: SocketType = switchTCP.isOn ? .tcp : .udp
|
let socketType: SocketType = switchTCP.isOn ? .tcp : .udp
|
||||||
|
|
||||||
let credentials = OpenVPN.Credentials(textUsername.text!, textPassword.text!)
|
let credentials = OpenVPN.Credentials(textUsername.text!, textPassword.text!)
|
||||||
cfg = OpenVPN.DemoConfiguration.make(
|
cfg = OpenVPN.DemoConfiguration.make(params: .init(
|
||||||
"TunnelKit.OpenVPN",
|
title: "TunnelKit.OpenVPN",
|
||||||
appGroup: appGroup,
|
appGroup: appGroup,
|
||||||
hostname: hostname,
|
hostname: hostname,
|
||||||
port: port,
|
port: port,
|
||||||
socketType: socketType
|
socketType: socketType
|
||||||
)
|
))
|
||||||
cfg?.username = credentials.username
|
cfg?.username = credentials.username
|
||||||
|
|
||||||
let passwordReference: Data
|
let passwordReference: Data
|
||||||
|
|
|
@ -94,15 +94,15 @@ class WireGuardViewController: UIViewController {
|
||||||
let serverAddress = textServerAddress.text!
|
let serverAddress = textServerAddress.text!
|
||||||
let serverPort = textServerPort.text!
|
let serverPort = textServerPort.text!
|
||||||
|
|
||||||
guard let cfg = WireGuard.DemoConfiguration.make(
|
guard let cfg = WireGuard.DemoConfiguration.make(params: .init(
|
||||||
"TunnelKit.WireGuard",
|
title: "TunnelKit.WireGuard",
|
||||||
appGroup: appGroup,
|
appGroup: appGroup,
|
||||||
clientPrivateKey: clientPrivateKey,
|
clientPrivateKey: clientPrivateKey,
|
||||||
clientAddress: clientAddress,
|
clientAddress: clientAddress,
|
||||||
serverPublicKey: serverPublicKey,
|
serverPublicKey: serverPublicKey,
|
||||||
serverAddress: serverAddress,
|
serverAddress: serverAddress,
|
||||||
serverPort: serverPort
|
serverPort: serverPort
|
||||||
) else {
|
)) else {
|
||||||
print("Configuration incomplete")
|
print("Configuration incomplete")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,13 +99,13 @@ class OpenVPNViewController: NSViewController {
|
||||||
let port = UInt16(textPort.stringValue)!
|
let port = UInt16(textPort.stringValue)!
|
||||||
|
|
||||||
let credentials = OpenVPN.Credentials(textUsername.stringValue, textPassword.stringValue)
|
let credentials = OpenVPN.Credentials(textUsername.stringValue, textPassword.stringValue)
|
||||||
cfg = OpenVPN.DemoConfiguration.make(
|
cfg = OpenVPN.DemoConfiguration.make(params: .init(
|
||||||
"TunnelKit.OpenVPN",
|
title: "TunnelKit.OpenVPN",
|
||||||
appGroup: appGroup,
|
appGroup: appGroup,
|
||||||
hostname: hostname,
|
hostname: hostname,
|
||||||
port: port,
|
port: port,
|
||||||
socketType: .udp
|
socketType: .udp
|
||||||
)
|
))
|
||||||
cfg?.username = credentials.username
|
cfg?.username = credentials.username
|
||||||
|
|
||||||
let passwordReference: Data
|
let passwordReference: Data
|
||||||
|
|
|
@ -94,15 +94,15 @@ class WireGuardViewController: NSViewController {
|
||||||
let serverAddress = textServerAddress.stringValue
|
let serverAddress = textServerAddress.stringValue
|
||||||
let serverPort = textServerPort.stringValue
|
let serverPort = textServerPort.stringValue
|
||||||
|
|
||||||
guard let cfg = WireGuard.DemoConfiguration.make(
|
guard let cfg = WireGuard.DemoConfiguration.make(params: .init(
|
||||||
"TunnelKit.WireGuard",
|
title: "TunnelKit.WireGuard",
|
||||||
appGroup: appGroup,
|
appGroup: appGroup,
|
||||||
clientPrivateKey: clientPrivateKey,
|
clientPrivateKey: clientPrivateKey,
|
||||||
clientAddress: clientAddress,
|
clientAddress: clientAddress,
|
||||||
serverPublicKey: serverPublicKey,
|
serverPublicKey: serverPublicKey,
|
||||||
serverAddress: serverAddress,
|
serverAddress: serverAddress,
|
||||||
serverPort: serverPort
|
serverPort: serverPort
|
||||||
) else {
|
)) else {
|
||||||
print("Configuration incomplete")
|
print("Configuration incomplete")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue