Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disconnect after a second connect #72

Open
a8thunder opened this issue Dec 28, 2019 · 0 comments
Open

Disconnect after a second connect #72

a8thunder opened this issue Dec 28, 2019 · 0 comments

Comments

@a8thunder
Copy link

a8thunder commented Dec 28, 2019

private let ca = OpenVPN.CryptoContainer(pem: """
-----BEGIN CERTIFICATE-----
MIIDlDCCAnygAwIBAgIBADANBgkqhkiG9w0BAQsFADBJMRIwEAYDVQQDDAl2cHM1
NjMzOTIxEjAQBgNVBAoMCXZwczU2MzM5MjESMBAGA1UECwwJdnBzNTYzMzkyMQsw
CQYDVQQGEwJVUzAeFw0xODA3MDUxNjAxNTZaFw0zNzEyMzExNjAxNTZaMEkxEjAQ
BgNVBAMMCXZwczU2MzM5MjESMBAGA1UECgwJdnBzNTYzMzkyMRIwEAYDVQQLDAl2
cHM1NjMzOTIxCzAJBgNVBAYTAlVTMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
CgKCAQEAstQT8jAnasovlXu+O3Gvpbj5O2IuQI3XhrUWMpSCd30O3UMugKm6hFWh
z+VI4qrys80+MXTjyy/dSUkYn7PWwKFCh2+Mlzb3vKkChrPAGw65UOCStOpbjJQb
fejw7o/DmUglC6gMX1/DwKy26G57s2MX351v8gnT9bJH8PJMKNXlkPeb5TUhF+Ix
sk+d5ji6ow+o7PXZPH89JmPmUjqzHSn2fVPbs46kK/9ODmEvxTcrbjYVjOur7GbV
8nIVXKxgTCmkw+aWo4FFeU++uqEeTMGq07m1FWLKAqVjuJDTNLYej/NmRM2CgEiD
D0YfO2Fu58N9um0Whh3W18insC1SeQIDAQABo4GGMIGDMA8GA1UdEwEB/wQFMAMB
Af8wCwYDVR0PBAQDAgH2MGMGA1UdJQRcMFoGCCsGAQUFBwMBBggrBgEFBQcDAgYI
KwYBBQUHAwMGCCsGAQUFBwMEBggrBgEFBQcDBQYIKwYBBQUHAwYGCCsGAQUFBwMH
BggrBgEFBQcDCAYIKwYBBQUHAwkwDQYJKoZIhvcNAQELBQADggEBAK2jrfj8jKxE
Oqlv4JbdTGBUrzZYhvzsHqzPOdOrPVv1VFzWPIEgxnQn6TypHG+7B71x480hukxg
D0UolAvj8zkYOOGzesI5vFEmj61xhqown69aXi+76cQpMGOssiTems7X2eGFMeWA
tGuYQjbQEnkAohiPQp5GfKQP4JuUYWHgTxPl+ZIWlcuSwOfZYFsPXfWRtcmrw6NX
Tf4jqzftb2B36vgrCh3aRRuesO/4rjJ51GxI5sjL8jXiUoBwwopMLLE4x6kWKSKU
xeEEevhywHuaPT6wzL+yCV/+7rFVuxd1240VZB+7tbAAIluyL8ZVr0+yjDi7P2Ry
T7pPr8fySew=
-----END CERTIFICATE-----
""")

extension ViewController {
private static let appGroup = "group.tmt.DemoApp"

private static let tunnelIdentifier = "com.tmt.AppVPN.com-tmt-AppVPN-Extension"

private func makeProtocol() -> NETunnelProviderProtocol {
    let server = textServer.text!
    let domain = textDomain.text!
    
    let hostname = ((domain == "") ? server : [server, domain].joined(separator: "."))
    let port = UInt16(textPort.text!)!
    let credentials = OpenVPN.Credentials(textUsername.text!, textPassword.text!)
    
    var sessionBuilder = OpenVPN.ConfigurationBuilder()
    sessionBuilder.ca = ca
    sessionBuilder.cipher = .aes128cbc
    sessionBuilder.digest = .sha1
    sessionBuilder.compressionFraming = .compLZO
    sessionBuilder.renegotiatesAfter = nil
    sessionBuilder.hostname = "51.254.35.77"
    let socketType: SocketType = switchTCP.isOn ? .tcp : .udp
    sessionBuilder.endpointProtocols = [EndpointProtocol(socketType, port)]
    sessionBuilder.usesPIAPatches = false
    var builder = OpenVPNTunnelProvider.ConfigurationBuilder(sessionConfiguration: sessionBuilder.build())
    builder.mtu = 1350
    builder.shouldDebug = false
    builder.masksPrivateData = false
    
    let configuration = builder.build()
    return try! configuration.generatedTunnelProtocol(
        withBundleIdentifier: ViewController.tunnelIdentifier,
        appGroup: ViewController.appGroup,
        credentials: credentials
    )
}

}

class ViewController: UIViewController, URLSessionDataDelegate {

var currentManager: NETunnelProviderManager?

var status = NEVPNStatus.invalid

override func viewDidLoad() {
    super.viewDidLoad()
    
    textServer.text = "France"
    textDomain.text = "51.254.35.77"
    textPort.text = "443"
    switchTCP.isOn = false
    textUsername.text = "triminh0209-vpnjantit.com"
    textPassword.text = "minhtri0209"
    
    NotificationCenter.default.addObserver(self,
                                           selector: #selector(VPNStatusDidChange(notification:)),
                                           name: .NEVPNStatusDidChange,
                                           object: nil)
    
    reloadCurrentManager(nil)

    //
    
    testFetchRef()
}

Screen Shot 2019-12-28 at 07 29 48
Help me!!!!!!!!!!!!!1
thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant