diff --git a/Demo/BasicTunnel-iOS/ViewController.swift b/Demo/BasicTunnel-iOS/ViewController.swift index a061ac8..c237f15 100644 --- a/Demo/BasicTunnel-iOS/ViewController.swift +++ b/Demo/BasicTunnel-iOS/ViewController.swift @@ -42,175 +42,6 @@ private let appGroup = "group.com.algoritmico.ios.demo.BasicTunnel" private let tunnelIdentifier = "com.algoritmico.ios.demo.BasicTunnel.Extension" -private let ca = OpenVPN.CryptoContainer(pem: """ ------BEGIN CERTIFICATE----- -MIIG6zCCBNOgAwIBAgIJAJhm2PWFkE8NMA0GCSqGSIb3DQEBCwUAMIGpMQswCQYD -VQQGEwJVUzELMAkGA1UECBMCQ0ExFjAUBgNVBAcTDU1vdW50YWluIFZpZXcxEzAR -BgNVBAoTCkdvb2dsZSBJbmMxEzARBgNVBAsTCkRldmVsb3BlcnMxFjAUBgNVBAMT -DUdvb2dsZSBJbmMgQ0ExEDAOBgNVBCkTB0Vhc3lSU0ExITAfBgkqhkiG9w0BCQEW -EnN1cHBvcnRAZ29vZ2xlLmNvbTAeFw0xNTAyMDIwNTMwMDlaFw0yNTAxMzAwNTMw -MDlaMIGpMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExFjAUBgNVBAcTDU1vdW50 -YWluIFZpZXcxEzARBgNVBAoTCkdvb2dsZSBJbmMxEzARBgNVBAsTCkRldmVsb3Bl -cnMxFjAUBgNVBAMTDUdvb2dsZSBJbmMgQ0ExEDAOBgNVBCkTB0Vhc3lSU0ExITAf -BgkqhkiG9w0BCQEWEnN1cHBvcnRAZ29vZ2xlLmNvbTCCAiIwDQYJKoZIhvcNAQEB -BQADggIPADCCAgoCggIBAN8T5cgRQ8+zsE2FWRpArqTlBh7MvoQU9Z4659eJ3Mhq -+pvR960HG9Bg6MkH0gwdcU65l0TLTwweOLBIZoxhLB+OVvl/x0FD4EnK9Pmp5SIU -P7cEqcqqRfRAI+9k0jwiGcPOl7KKqfz70c6QsQYn2VvrTMqgDt4IS/zpaToZsftq -ibCt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piqHuUb9BXlZ6gRVCWepm -l7cqF8038o6ZraHpeNAI6FejBEMrO45Wc5eutpbcg18FTkotiRWS3I6K4xg75lZp -tjF1aYGTAhC/8yoAYmBKzbKJXyNW2Vq93/9y+43OUJridoijB7cqbUpZFOVdtnZ5 -LHb3h7hLV/3C2WgehM73f/UMc65fIk+9CpwD7Cgpu9duBknf0c0s0Sw3HA/s6SL6 -V4FhARi7flTF9TGR6+e0i2oreXEwJXP3GoXpazOqzrGekSXRMqwLY83fJ/RzP0Ap -PMc5TfiQVcL/h92CUAwwH1vRJkAhrTvNXh1Ynd7zdFT/wYWrK0twm4qlTjKYpbVL -RIoeppgOUG+1t82/HW2geWLYSNRfZiTbpAvm00HJavD12qOD0NUIErlQnOZvW2UC -/RzA/yu9ZguEIlV+8qmkiUCKyajyLFydWqqScMYAeJMh6aJzfQ4UHu2bzr9Qo2MV -HiT8esMeX+/orMetzuTPgZInMhznvVdNdfwAfibwlXOKvm154UgDVgnKV405oNM= ------END CERTIFICATE----- -""") - -private let clientCertificate = OpenVPN.CryptoContainer(pem: """ ------BEGIN CERTIFICATE----- -MIIHPTCCBSWgAwIBAgIBAjANBgkqhkiG9w0BAQsFADCBqTELMAkGA1UEBhMCVVMx -CzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRMwEQYDVQQKEwpH -b29nbGUgSW5jMRMwEQYDVQQLEwpEZXZlbG9wZXJzMRYwFAYDVQQDEw1Hb29nbGUg -SW5jIENBMRAwDgYDVQQpEwdFYXN5UlNBMSEwHwYJKoZIhvcNAQkBFhJzdXBwb3J0 -QGdvb2dsZS5jb20wHhcNMTUwMjAyMDUzODUxWhcNMjUwMTMwMDUzODUxWjCBojEL -MAkGA1UEBhMCVVMxCzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3 -MRMwEQYDVQQKEwpHb29nbGUgSW5jMRMwEQYDVQQLEwpEZXZlbG9wZXJzMQ8wDQYD -VQQD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U1vdW50YWluIFZpZXcxEzARBgNVBAoT -Ckdvb2dsZSBJbmMxEzARBgNVBAsTCkRldmVsb3BlcnMxFjAUBgNVBAMTDUdvb2ds -ZSBJbmMgQ0ExEDAOBgNVBCkTB0Vhc3lSU0ExITAfBgkqhkiG9w0BCQEWEnN1cHBv -cnRAZ29vZ2xlLmNvbYIJAJhm2PWFkE8NMBMGA1UdJQQMMAoGCCsGAQUFBwMCMAsG -A1UdDwQEAwIHgDARBgNVHREECjAIggZjbGllbnQwDQYJKoZIhvcNAQELBQADggIB -ACEBDTW4moXsrkIOJVC66vlbcHqphCLkTsvSt3e7FU8+UGR7eKnvg61kG16HmBcZ -AQ/ChFyNafCdHXOmHFp9s7hRHFJ1LZ5xidBxQhBOTf66aoDzILj67MvLoCFnuxEq -f3Ok5ayGKWVppfMUs7RgTPL+XSMLM1lsHpFMcy983MNZ+w8sSVgHiWrso2q6nTSG -aZYn7nSTpxlDHSVDB757wsIcDKT8FF/4nA0649meuEVMtNYR3hCmqiAkK9QwK8MR -BCt3emHq5jVg51NNrhGKoaXwgab+p/YehHx1XFcDTUXIImkN0s1hZy4DlrUYkOBT -3izKnWFziq2Zkpx9N6ZEdknQvFXeQg+EAMnVcvpf78WBvq8BIa+PlIMlSojj3tjP -krsyjTwWk4/f3IL4Y9B8SpoGHW3hzsEA1Z1QdYy1LnRi0MQ6XIM06vMrM/JW6H/r -fHGa7wDILYCwgzmgqX8ek8R5v9fOdtzpJxL54o3mgkNsPuDglylNy87sR4xTd5Cr -NOQ9Q/PuNi0u2pEMsbmj3OrPjy2TFsW6BiDKr5y48lHin7OqmuiQZMnDX/o75Ylc -bcdJrlfMT2PJrSvH6ap61NqQK9xnIqKOhuI9xwVCvizI67GuGxiwCgiF+YSR5nOA -kiJ6Ts2iqIvR7T7Eme2vBYH/UJ1DXrdCJx6IDGxxgoXk ------END CERTIFICATE----- -""") - -private let clientKey = OpenVPN.CryptoContainer(pem: """ ------BEGIN PRIVATE KEY----- -MIIJQgI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""") - -extension ViewController { - private func makeConfiguration() -> OpenVPNTunnelProvider.Configuration { - let server = textServer.text! - let domain = textDomain.text! - - let hostname = ((domain == "") ? server : [server, domain].joined(separator: ".")) - let port = UInt16(textPort.text!)! - - var sessionBuilder = OpenVPN.ConfigurationBuilder() - sessionBuilder.ca = ca - sessionBuilder.cipher = .aes128cbc - sessionBuilder.digest = .sha1 - sessionBuilder.compressionFraming = .compLZO - sessionBuilder.renegotiatesAfter = nil - sessionBuilder.hostname = hostname - let socketType: SocketType = switchTCP.isOn ? .tcp : .udp - sessionBuilder.endpointProtocols = [EndpointProtocol(socketType, port)] - sessionBuilder.clientCertificate = clientCertificate - sessionBuilder.clientKey = clientKey - var builder = OpenVPNTunnelProvider.ConfigurationBuilder(sessionConfiguration: sessionBuilder.build()) - builder.mtu = 1350 - builder.shouldDebug = true - builder.masksPrivateData = false - - return builder.build() - } -} - class ViewController: UIViewController, URLSessionDataDelegate { @IBOutlet var textUsername: UITextField! @@ -270,14 +101,21 @@ class ViewController: UIViewController, URLSessionDataDelegate { } func connect() { + let server = textServer.text! + let domain = textDomain.text! + let hostname = ((domain == "") ? server : [server, domain].joined(separator: ".")) + let port = UInt16(textPort.text!)! + let socketType: SocketType = switchTCP.isOn ? .tcp : .udp + let credentials = OpenVPN.Credentials(textUsername.text!, textPassword.text!) - let proto = try! makeConfiguration().generatedTunnelProtocol( + let cfg = Configuration.make(hostname: hostname, port: port, socketType: socketType) + let proto = try! cfg.generatedTunnelProtocol( withBundleIdentifier: tunnelIdentifier, appGroup: appGroup, credentials: credentials ) - let cfg = NetworkExtensionVPNConfiguration(protocolConfiguration: proto, onDemandRules: []) - vpn.reconnect(configuration: cfg) { (error) in + let neCfg = NetworkExtensionVPNConfiguration(protocolConfiguration: proto, onDemandRules: []) + vpn.reconnect(configuration: neCfg) { (error) in if let error = error { print("configure error: \(error)") return diff --git a/Demo/BasicTunnelExtension-iOS/PacketTunnelProvider.swift b/Demo/BasicTunnelExtension-iOS/PacketTunnelProvider.swift index 256dad7..080851b 100644 --- a/Demo/BasicTunnelExtension-iOS/PacketTunnelProvider.swift +++ b/Demo/BasicTunnelExtension-iOS/PacketTunnelProvider.swift @@ -1,6 +1,6 @@ // // PacketTunnelProvider.swift -// BasicTunnelExtension-iOS +// BasicTunnel-iOS // // Created by Davide De Rosa on 9/15/17. // Copyright (c) 2018 Davide De Rosa. All rights reserved. diff --git a/Demo/Demo.xcodeproj/project.pbxproj b/Demo/Demo.xcodeproj/project.pbxproj index 38f348e..255e995 100644 --- a/Demo/Demo.xcodeproj/project.pbxproj +++ b/Demo/Demo.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 0EAC574724943B5D00D0FCE0 /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EAC574624943B5D00D0FCE0 /* Configuration.swift */; }; + 0EAC574824943B5D00D0FCE0 /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EAC574624943B5D00D0FCE0 /* Configuration.swift */; }; 0EB39FE91F7424F80023AFFC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EB39FE81F7424F80023AFFC /* AppDelegate.swift */; }; 0EB39FEB1F7424F80023AFFC /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EB39FEA1F7424F80023AFFC /* ViewController.swift */; }; 0EB39FEE1F7424F80023AFFC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0EB39FEC1F7424F80023AFFC /* Main.storyboard */; }; @@ -71,6 +73,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 0EAC574624943B5D00D0FCE0 /* Configuration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = ""; }; 0EB39FE61F7424F80023AFFC /* BasicTunnel-iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "BasicTunnel-iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 0EB39FE81F7424F80023AFFC /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 0EB39FEA1F7424F80023AFFC /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; @@ -147,6 +150,14 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 0EAC574524943B3500D0FCE0 /* Shared */ = { + isa = PBXGroup; + children = ( + 0EAC574624943B5D00D0FCE0 /* Configuration.swift */, + ); + path = Shared; + sourceTree = ""; + }; 0EB39FC41F7424580023AFFC = { isa = PBXGroup; children = ( @@ -154,6 +165,7 @@ 0EB39FFD1F7425140023AFFC /* BasicTunnelExtension-iOS */, 0EB6EEB81F92D417005F6221 /* BasicTunnel-macOS */, 0EB6EECC1F92D43D005F6221 /* BasicTunnelExtension-macOS */, + 0EAC574524943B3500D0FCE0 /* Shared */, 0EB39FCE1F7424580023AFFC /* Products */, B850E57E641AD1B37E79BAB5 /* Frameworks */, 94C1D7B5B11C6CCE74B21D93 /* Pods */, @@ -631,6 +643,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 0EAC574724943B5D00D0FCE0 /* Configuration.swift in Sources */, 0EB39FEB1F7424F80023AFFC /* ViewController.swift in Sources */, 0EB39FE91F7424F80023AFFC /* AppDelegate.swift in Sources */, ); @@ -648,6 +661,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 0EAC574824943B5D00D0FCE0 /* Configuration.swift in Sources */, 0EB6EEBC1F92D417005F6221 /* ViewController.swift in Sources */, 0EB6EEBA1F92D417005F6221 /* AppDelegate.swift in Sources */, ); diff --git a/Demo/Shared/Configuration.swift b/Demo/Shared/Configuration.swift new file mode 100644 index 0000000..893f593 --- /dev/null +++ b/Demo/Shared/Configuration.swift @@ -0,0 +1,188 @@ +// +// Configuration.swift +// Demo +// +// Created by Davide De Rosa on 6/13/20. +// Copyright (c) 2018 Davide De Rosa. All rights reserved. +// +// https://github.com/keeshux +// +// This file is part of TunnelKit. +// +// TunnelKit is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// TunnelKit is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with TunnelKit. If not, see . +// + +import Foundation +import TunnelKit + +struct Configuration { + static let ca = OpenVPN.CryptoContainer(pem: """ +-----BEGIN CERTIFICATE----- +MIIG6zCCBNOgAwIBAgIJAJhm2PWFkE8NMA0GCSqGSIb3DQEBCwUAMIGpMQswCQYD +VQQGEwJVUzELMAkGA1UECBMCQ0ExFjAUBgNVBAcTDU1vdW50YWluIFZpZXcxEzAR +BgNVBAoTCkdvb2dsZSBJbmMxEzARBgNVBAsTCkRldmVsb3BlcnMxFjAUBgNVBAMT +DUdvb2dsZSBJbmMgQ0ExEDAOBgNVBCkTB0Vhc3lSU0ExITAfBgkqhkiG9w0BCQEW +EnN1cHBvcnRAZ29vZ2xlLmNvbTAeFw0xNTAyMDIwNTMwMDlaFw0yNTAxMzAwNTMw +MDlaMIGpMQswCQYDVQQGEwJVUzELMAkGA1UECBMCQ0ExFjAUBgNVBAcTDU1vdW50 +YWluIFZpZXcxEzARBgNVBAoTCkdvb2dsZSBJbmMxEzARBgNVBAsTCkRldmVsb3Bl +cnMxFjAUBgNVBAMTDUdvb2dsZSBJbmMgQ0ExEDAOBgNVBCkTB0Vhc3lSU0ExITAf +BgkqhkiG9w0BCQEWEnN1cHBvcnRAZ29vZ2xlLmNvbTCCAiIwDQYJKoZIhvcNAQEB +BQADggIPADCCAgoCggIBAN8T5cgRQ8+zsE2FWRpArqTlBh7MvoQU9Z4659eJ3Mhq ++pvR960HG9Bg6MkH0gwdcU65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YyJIrPOe3jZZ+Vzk5mnEj8RCJ/H5DiYnxPSlpr7slNtI/AqG4d5ODwU3uGsrs +LaoUK5OWc81R0l5EBfzo+rfYI5O/0uG7M9BsGQZVz0ZpiqHuUb9BXlZ6gRVCWepm +l7cqF8038o6ZraHpeNAI6FejBEMrO45Wc5eutpbcg18FTkotiRWS3I6K4xg75lZp +tjF1aYGTAhC/8yoAYmBKzbKJXyNW2Vq93/9y+43OUJridoijB7cqbUpZFOVdtnZ5 +LHb3h7hLV/3C2WgehM73f/UMc65fIk+9CpwD7Cgpu9duBknf0c0s0Sw3HA/s6SL6 +V4FhARi7flTF9TGR6+e0i2oreXEwJXP3GoXpazOqzrGekSXRMqwLY83fJ/RzP0Ap +PMc5TfiQVcL/h92CUAwwH1vRJkAhrTvNXh1Ynd7zdFT/wYWrK0twm4qlTjKYpbVL +RIoeppgOUG+1t82/HW2geWLYSNRfZiTbpAvm00HJavD12qOD0NUIErlQnOZvW2UC +/RzA/yu9ZguEIlV+8qmkiUCKyajyLFydWqqScMYAeJMh6aJzfQ4UHu2bzr9Qo2MV +HiT8esMeX+/orMetzuTPgZInMhznvVdNdfwAfibwlXOKvm154UgDVgnKV405oNM= +-----END CERTIFICATE----- +""") + + static let clientCertificate = OpenVPN.CryptoContainer(pem: """ +-----BEGIN CERTIFICATE----- +MIIHPTCCBSWgAwIBAgIBAjANBgkqhkiG9w0BAQsFADCBqTELMAkGA1UEBhMCVVMx +CzAJBgNVBAgTAkNBMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRMwEQYDVQQKEwpH +b29nbGUgSW5jMRMwEQYDVQQLEwpEZXZlbG9wZXJzMRYwFAYDVQQDEw1Hb29nbGUg +SW5jIENBMRAwDgYDVQQpEwdFYXN5UlNBMSEwHwYJKoZIhvcNAQkBFhJzdXBwb3J0 +QGdvb2dsZS5jb20wHhcNMTUwMjAyMDUzODUxWhcNMjUwMTMwMDUzODUxWjCBojEL +MAkGA1UEBhMCVVMxCzAJBgNVBA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iqIvR7T7Eme2vBYH/UJ1DXrdCJx6IDGxxgoXk +-----END CERTIFICATE----- +""") + + static let clientKey = OpenVPN.CryptoContainer(pem: """ +-----BEGIN PRIVATE KEY----- +MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQDvgpUJoqgvHmbF +2y7Uvt1BfglAXWmzzhaSjr4ZqYLMQncpcwC1iuVgDseGp/rl4C/C64RebIx0hLU1 +4kc4envr6s59tvLemSiSAOYwwmeOAkwk2SncbtV/sEiTSBDs87uTlc1TOYED1jns +ATqvNTTGyx8Vlx1Qd4MmxOSlPOfVwSybrIfLwgSuTaN1TjJZiKlG8FQn1/JId9tj +eDyHvHb7BsgBY6p9OctGw/NyLlwGNB7Yo1MKrolhHmTvHZbiLTaqWJHjKTBmlNtP +P+z+v27U/RF7bh1enzBHnjv0lyKxPRBpq1rInl4PkxIpV7hjHIRw35EcOsXl0xQ+ +T9Cca2+RISmTFfRkSIPutlcj+rN3Xv98TmO/9gSqFopZsXVnJlS89IuWcZe8KJB3 +/HoBCJxAmZsmAsBoLvykv5AoZvCS2IkOaCSftfiWckHIpKPsZKr54G8faUx7XCWB +NZluoxMOFeX+yA9y3Tqi5oorSkN+JHv9jj2NTUgbKQC/z9jItFt9xkRznwCEcuTx +KgJOxoxBDz6chMgFF0tE6RXb4EBDiqsOKMSbmdRj1hg8TX6dYCSoNhwTPjXO0HqT +Fy4eSx0zUjklryX9y7K1EOoKCqdjwNLnKZLV8YdPLjQSeZ1KyWcorbnm0gL+dQua ++OVTQg5OeNr7zWVRsfplzo0V0H1S9wIDAQABAoICAGL0e6kod/5HvESA419ooDd/ +4Eikj5iHTFIvAaHOpEjKKTuJ1UAsa8p9MLiUzJePQYxyDBWLGZjGf6wMmkpeaLa3 +I6tTHBMWCmoQTwrUNz63+ke7JY16iWEhL0sSmlOb++LlIJkDCCfSqcm1VE6xV+XO +ZEBiV+04A4rQDHusp0hscIa9CLoJpi9xylgb/7d4PCAgCVUQ5nxE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/f5l +3qibvYTFj6CIqcdHA6Sy+UTEyb7zWnFwWVNEwAadsMmq45mhdoFjlm/5onPrpj+l +1LXZrtjAB4U+/F7um6YyAavpHYq9hg== +-----END PRIVATE KEY----- +""") + + static func make(hostname: String, port: UInt16, socketType: SocketType) -> OpenVPNTunnelProvider.Configuration { + var sessionBuilder = OpenVPN.ConfigurationBuilder() + sessionBuilder.ca = ca + sessionBuilder.cipher = .aes128cbc + sessionBuilder.digest = .sha1 + sessionBuilder.compressionFraming = .compLZO + sessionBuilder.renegotiatesAfter = nil + sessionBuilder.hostname = hostname + sessionBuilder.endpointProtocols = [EndpointProtocol(socketType, port)] + sessionBuilder.clientCertificate = clientCertificate + sessionBuilder.clientKey = clientKey + var builder = OpenVPNTunnelProvider.ConfigurationBuilder(sessionConfiguration: sessionBuilder.build()) + builder.mtu = 1350 + builder.shouldDebug = true + builder.masksPrivateData = false + return builder.build() + } +}