Skip to content

Commit

Permalink
AmneziaWG 1.0.0 (0)
Browse files Browse the repository at this point in the history
  • Loading branch information
isamnezia committed Mar 6, 2024
1 parent 0829e99 commit 002c47f
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 1,458 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,5 @@ fastlane/test_output
Preview.html
output

# Wireguard specific
Sources/WireGuardApp/Config/Developer.xcconfig

# Vim
.*.sw*
109 changes: 55 additions & 54 deletions Sources/Shared/Model/TunnelConfiguration+WgQuickConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,32 +130,33 @@ extension TunnelConfiguration {
if let listenPort = interface.listenPort {
output.append("ListenPort = \(listenPort)\n")
}
if let Jc = interface.Jc {
output.append("Jc = \(Jc)\n")

if let junkPacketCount = interface.junkPacketCount {
output.append("Jc = \(junkPacketCount)\n")
}
if let Jmin = interface.Jmin {
output.append("Jmin = \(Jmin)\n")
if let junkPacketMinSize = interface.junkPacketMinSize {
output.append("Jmin = \(junkPacketMinSize)\n")
}
if let Jmax = interface.Jmax {
output.append("Jmax = \(Jmax)\n")
if let junkPacketMaxSize = interface.junkPacketMaxSize {
output.append("Jmax = \(junkPacketMaxSize)\n")
}
if let S1 = interface.S1 {
output.append("S1 = \(S1)\n")
if let initPacketJunkSize = interface.initPacketJunkSize {
output.append("S1 = \(initPacketJunkSize)\n")
}
if let S2 = interface.S2 {
output.append("S2 = \(S2)\n")
if let responsePacketJunkSize = interface.responsePacketJunkSize {
output.append("S2 = \(responsePacketJunkSize)\n")
}
if let H1 = interface.H1 {
output.append("H1 = \(H1)\n")
if let initPacketMagicHeader = interface.initPacketMagicHeader {
output.append("H1 = \(initPacketMagicHeader)\n")
}
if let H2 = interface.H2 {
output.append("H2 = \(H2)\n")
if let responsePacketMagicHeader = interface.responsePacketMagicHeader {
output.append("H2 = \(responsePacketMagicHeader)\n")
}
if let H3 = interface.H3 {
output.append("H3 = \(H3)\n")
if let underloadPacketMagicHeader = interface.underloadPacketMagicHeader {
output.append("H3 = \(underloadPacketMagicHeader)\n")
}
if let H4 = interface.H4 {
output.append("H4 = \(H4)\n")
if let transportPacketMagicHeader = interface.transportPacketMagicHeader {
output.append("H4 = \(transportPacketMagicHeader)\n")
}
if !interface.addresses.isEmpty {
let addressString = interface.addresses.map { $0.stringRepresentation }.joined(separator: ", ")
Expand Down Expand Up @@ -235,59 +236,59 @@ extension TunnelConfiguration {
}
interface.mtu = mtu
}
if let JcString = attributes["jc"] {
guard let jc = UInt16(JcString) else {
throw ParseError.interfaceHasInvalidCustomParam(JcString)
if let junkPacketCountString = attributes["jc"] {
guard let junkPacketCount = UInt16(junkPacketCountString) else {
throw ParseError.interfaceHasInvalidCustomParam(junkPacketCountString)
}
interface.Jc = jc
interface.junkPacketCount = junkPacketCount
}
if let JminString = attributes["jmin"] {
guard let jmin = UInt16(JminString) else {
throw ParseError.interfaceHasInvalidCustomParam(JminString)
if let junkPacketMinSizeString = attributes["jmin"] {
guard let junkPacketMinSize = UInt16(junkPacketMinSizeString) else {
throw ParseError.interfaceHasInvalidCustomParam(junkPacketMinSizeString)
}
interface.Jmin = jmin
interface.junkPacketMinSize = junkPacketMinSize
}
if let JmaxString = attributes["jmax"] {
guard let jmax = UInt16(JmaxString) else {
throw ParseError.interfaceHasInvalidCustomParam(JmaxString)
if let junkPacketMaxSizeString = attributes["jmax"] {
guard let junkPacketMaxSize = UInt16(junkPacketMaxSizeString) else {
throw ParseError.interfaceHasInvalidCustomParam(junkPacketMaxSizeString)
}
interface.Jmax = jmax
interface.junkPacketMaxSize = junkPacketMaxSize
}
if let S1String = attributes["s1"] {
guard let s1 = UInt16(S1String) else {
throw ParseError.interfaceHasInvalidCustomParam(S1String)
if let initPacketJunkSizeString = attributes["s1"] {
guard let initPacketJunkSize = UInt16(initPacketJunkSizeString) else {
throw ParseError.interfaceHasInvalidCustomParam(initPacketJunkSizeString)
}
interface.S1 = s1
interface.initPacketJunkSize = initPacketJunkSize
}
if let S2String = attributes["s2"] {
guard let s2 = UInt16(S2String) else {
throw ParseError.interfaceHasInvalidCustomParam(S2String)
if let responsePacketJunkSizeString = attributes["s2"] {
guard let responsePacketJunkSize = UInt16(responsePacketJunkSizeString) else {
throw ParseError.interfaceHasInvalidCustomParam(responsePacketJunkSizeString)
}
interface.S2 = s2
interface.responsePacketJunkSize = responsePacketJunkSize
}
if let H1String = attributes["h1"] {
guard let h1 = UInt32(H1String) else {
throw ParseError.interfaceHasInvalidCustomParam(H1String)
if let initPacketMagicHeaderString = attributes["h1"] {
guard let initPacketMagicHeader = UInt32(initPacketMagicHeaderString) else {
throw ParseError.interfaceHasInvalidCustomParam(initPacketMagicHeaderString)
}
interface.H1 = h1
interface.initPacketMagicHeader = initPacketMagicHeader
}
if let H2String = attributes["h2"] {
guard let h2 = UInt32(H2String) else {
throw ParseError.interfaceHasInvalidCustomParam(H2String)
if let responsePacketMagicHeaderString = attributes["h2"] {
guard let responsePacketMagicHeader = UInt32(responsePacketMagicHeaderString) else {
throw ParseError.interfaceHasInvalidCustomParam(responsePacketMagicHeaderString)
}
interface.H2 = h2
interface.responsePacketMagicHeader = responsePacketMagicHeader
}
if let H3String = attributes["h3"] {
guard let h3 = UInt32(H3String) else {
throw ParseError.interfaceHasInvalidCustomParam(H3String)
if let underloadPacketMagicHeaderString = attributes["h3"] {
guard let underloadPacketMagicHeader = UInt32(underloadPacketMagicHeaderString) else {
throw ParseError.interfaceHasInvalidCustomParam(underloadPacketMagicHeaderString)
}
interface.H3 = h3
interface.underloadPacketMagicHeader = underloadPacketMagicHeader
}
if let H4String = attributes["h4"] {
guard let h4 = UInt32(H4String) else {
throw ParseError.interfaceHasInvalidCustomParam(H4String)
if let transportPacketMagicHeaderString = attributes["h4"] {
guard let transportPacketMagicHeader = UInt32(transportPacketMagicHeaderString) else {
throw ParseError.interfaceHasInvalidCustomParam(transportPacketMagicHeaderString)
}
interface.H4 = h4
interface.transportPacketMagicHeader = transportPacketMagicHeader
}
return interface
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/WireGuardApp/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,8 @@

"macAlertMultipleEntriesForKey (%@)" = "There should be only one entry per section for key ‘%@’";

"macAlertInterfaceHasInvalidCustomParam (%@)" = "Interface has invalid custom param ‘%@’";

// Mac about dialog

"macAppVersion (%@)" = "App version: %@";
Expand Down
10 changes: 10 additions & 0 deletions Sources/WireGuardApp/Config/Developer.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Developer.xcconfig

// You Apple developer account's Team ID
DEVELOPMENT_TEAM = X7UJ388FXK

// The bundle identifier of the apps.
// Should be an app id created at developer.apple.com
// with Network Extensions capabilty.
APP_ID_IOS = org.amnezia.awg
APP_ID_MACOS = org.amnezia.awg
4 changes: 2 additions & 2 deletions Sources/WireGuardApp/Config/Version.xcconfig
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VERSION_NAME = 1.0.16
VERSION_ID = 27
VERSION_NAME = 1.0.0
VERSION_ID = 0
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,10 @@ extension SettingsTableViewController {
appVersion += " (\(appBuild))"
}
cell.value = appVersion
} else if field == .goBackendVersion {
cell.value = WIREGUARD_GO_VERSION
}
// else if field == .goBackendVersion {
// cell.value = WIREGUARD_GO_VERSION
// }
return cell
} else if field == .exportZipArchive {
let cell: ButtonCell = tableView.dequeueReusableCell(for: indexPath)
Expand Down
2 changes: 1 addition & 1 deletion Sources/WireGuardApp/UI/macOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ extension AppDelegate {
}
let appVersionString = [
tr(format: "macAppVersion (%@)", appVersion),
tr(format: "macGoBackendVersion (%@)", WIREGUARD_GO_VERSION)
// tr(format: "macGoBackendVersion (%@)", WIREGUARD_GO_VERSION)
].joined(separator: "\n")
NSApp.activate(ignoringOtherApps: true)
NSApp.orderFrontStandardAboutPanel(options: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ extension TunnelConfiguration.ParseError: WireGuardAppError {
return (tr("alertInvalidPeerMessagePublicKeyDuplicated"), "")
case .multipleEntriesForKey(let value):
return (tr(format: "macAlertMultipleEntriesForKey (%@)", value), "")
case .interfaceHasInvalidCustomParam(let customParam):
return (tr(format: "macAlertInterfaceHasInvalidCustomParam (%@)", customParam), "")
}
}
}
18 changes: 9 additions & 9 deletions Sources/WireGuardKit/InterfaceConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import Network
public struct InterfaceConfiguration {
public var privateKey: PrivateKey
public var addresses = [IPAddressRange]()
public var Jc: UInt16?
public var Jmin: UInt16?
public var Jmax: UInt16?
public var S1: UInt16?
public var S2: UInt16?
public var H1: UInt32?
public var H2: UInt32?
public var H3: UInt32?
public var H4: UInt32?
public var junkPacketCount: UInt16?
public var junkPacketMinSize: UInt16?
public var junkPacketMaxSize: UInt16?
public var initPacketJunkSize: UInt16?
public var responsePacketJunkSize: UInt16?
public var initPacketMagicHeader: UInt32?
public var responsePacketMagicHeader: UInt32?
public var underloadPacketMagicHeader: UInt32?
public var transportPacketMagicHeader: UInt32?
public var listenPort: UInt16?
public var mtu: UInt16?
public var dns = [DNSServer]()
Expand Down
41 changes: 21 additions & 20 deletions Sources/WireGuardKit/PacketTunnelSettingsGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,33 @@ class PacketTunnelSettingsGenerator {
if let listenPort = tunnelConfiguration.interface.listenPort {
wgSettings.append("listen_port=\(listenPort)\n")
}
if let Jc = tunnelConfiguration.interface.Jc {
wgSettings.append("jc=\(Jc)\n")

if let junkPacketCount = tunnelConfiguration.interface.junkPacketCount {
wgSettings.append("jc=\(junkPacketCount)\n")
}
if let Jmin = tunnelConfiguration.interface.Jmin {
wgSettings.append("jmin=\(Jmin)\n")
if let junkPacketMinSize = tunnelConfiguration.interface.junkPacketMinSize {
wgSettings.append("jmin=\(junkPacketMinSize)\n")
}
if let Jmax = tunnelConfiguration.interface.Jmax {
wgSettings.append("jmax=\(Jmax)\n")
if let junkPacketMaxSize = tunnelConfiguration.interface.junkPacketMaxSize {
wgSettings.append("jmax=\(junkPacketMaxSize)\n")
}
if let S1 = tunnelConfiguration.interface.S1 {
wgSettings.append("s1=\(S1)\n")
if let initPacketJunkSize = tunnelConfiguration.interface.initPacketJunkSize {
wgSettings.append("s1=\(initPacketJunkSize)\n")
}
if let S2 = tunnelConfiguration.interface.S2 {
wgSettings.append("s2=\(S2)\n")
if let responsePacketJunkSize = tunnelConfiguration.interface.responsePacketJunkSize {
wgSettings.append("s2=\(responsePacketJunkSize)\n")
}
if let H1 = tunnelConfiguration.interface.H1 {
wgSettings.append("h1=\(H1)\n")
if let initPacketMagicHeader = tunnelConfiguration.interface.initPacketMagicHeader {
wgSettings.append("h1=\(initPacketMagicHeader)\n")
}
if let H2 = tunnelConfiguration.interface.H2 {
wgSettings.append("h2=\(H2)\n")
if let responsePacketMagicHeader = tunnelConfiguration.interface.responsePacketMagicHeader {
wgSettings.append("h2=\(responsePacketMagicHeader)\n")
}
if let H3 = tunnelConfiguration.interface.H3 {
wgSettings.append("h3=\(H3)\n")
if let underloadPacketMagicHeader = tunnelConfiguration.interface.underloadPacketMagicHeader {
wgSettings.append("h3=\(underloadPacketMagicHeader)\n")
}
if let H4 = tunnelConfiguration.interface.H4 {
wgSettings.append("h4=\(H4)\n")
if let transportPacketMagicHeader = tunnelConfiguration.interface.transportPacketMagicHeader {
wgSettings.append("h4=\(transportPacketMagicHeader)\n")
}
if !tunnelConfiguration.peers.isEmpty {
wgSettings.append("replace_peers=true\n")
Expand Down Expand Up @@ -143,7 +144,7 @@ class PacketTunnelSettingsGenerator {
let (ipv4Addresses, ipv6Addresses) = addresses()
let (ipv4IncludedRoutes, ipv6IncludedRoutes) = includedRoutes()
let (ipv4ExcludedRoutes, ipv6ExcludedRoutes) = excludedRoutes()

let ipv4Settings = NEIPv4Settings(addresses: ipv4Addresses.map { $0.destinationAddress }, subnetMasks: ipv4Addresses.map { $0.destinationSubnetMask })
ipv4Settings.includedRoutes = ipv4IncludedRoutes
ipv4Settings.excludedRoutes = ipv4ExcludedRoutes
Expand Down Expand Up @@ -202,7 +203,7 @@ class PacketTunnelSettingsGenerator {
}
return (ipv4IncludedRoutes, ipv6IncludedRoutes)
}

private func excludedRoutes() -> ([NEIPv4Route], [NEIPv6Route]) {
var ipv4ExcludedRoutes = [NEIPv4Route]()
var ipv6ExcludedRoutes = [NEIPv6Route]()
Expand Down
7 changes: 7 additions & 0 deletions Sources/WireGuardKitGo/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ require (
github.com/amnezia-vpn/amneziawg-go v0.2.1
golang.org/x/sys v0.17.0
)

require (
github.com/tevino/abool/v2 v2.1.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
)
Loading

0 comments on commit 002c47f

Please sign in to comment.