How to send all traffic over a VPN connection? - ios

I am creating an application to connect to a VPN server.
I have worked out how to do this, but need to be able to send all traffic over the connection.
Is there any code which can do this?
So far I have tried:
let manager: NEVPNManager = NEVPNManager.sharedManager()
var p = NEVPNProtocolIPSec()
manager.`protocol` = p
let pw = ""
println(manager.connection.status)
p.username = ""
p.passwordReference = pw.dataUsingEncoding(NSUTF8StringEncoding)
p.serverAddress = ""
p.authenticationMethod = NEVPNIKEAuthenticationMethod.SharedSecret
//p.sharedSecretReference = getPasscodeNSData("vpnSharedSecret")
p.useExtendedAuthentication = true
p.disconnectOnSleep = false

No, I don't think there is any way to switch all system IP traffic over a VPN connection. Apple doesn't let apps muck around with the OS like that.

Related

Hide URL when sending with email

I am developing iOS app that sending selected pdfs(urls) stored in firebase with using SMTP. I don't want to be seen urls in mail.
It should be like this "https://...." = "Document1 or proper name"
Is it possible ?
func sendEmail() {
let message = SKPSMTPMessage()
message.relayHost = "smtp.gmail.com"
message.login = "****#gmail.com"
message.pass = "*****"
message.requiresAuth = true
message.wantsSecure = true
message.relayPorts = [587]
message.fromEmail = "****#gmail.com"
message.toEmail = "****#gmail.com"
message.subject = "subject"
let messagePart = [kSKPSMTPPartContentTypeKey: "text/plain; charset=UTF-8", kSKPSMTPPartMessageKey: "Hi,\n\n Please see the requested documents below\n\n\(getmailpdf.joined(separator: "\n\n\n"))"]
message.parts = [messagePart]
message.delegate = self
message.send()
}

XCode console: WARNING! Sole personality is ambiguous; this may lead to erradic behavior - in Keyboard Extension

I am have iOS app that consist of custom keyboard extension and its container app. When I try to debug the custom keyboard extension I get the following, rather disturbing log in the XCode console:
EasyType Keyboard[84937:5754706] [lifecycle] [u 9061FF85-F4D2-401A-94C2-73377E20E419] [com.easytype.EasyType.Keyboard(1.7.1)] WARNING! Sole personality is ambiguous; this may lead to erradic behavior; personalities: {
"com.easytype.EasyType.Keyboard" = {
685 = "<PKServicePersonality: 0x283175340; core = <PKPlugInCore: 0x283175340; uuid = [9061FF85-F4D2-401A-94C2-73377E20E419], identifier = [com.easytype.EasyType.Keyboard(1.7.1)], isAppExtension = 1, onSystemVolume = 0, containingBundle = [(null)], lastModified = 0, discoveryInstanceUUID = [(null)], path = [/private/var/containers/Bundle/Application/762C0B3C-A600-4AB4-AB84-AB2019FA053C/EasyType.app/PlugIns/EasyType Keyboard.appex]>, host pid = 685>";
84881 = "<PKServicePersonality: 0x2831782a0; core = <PKPlugInCore: 0x2831782a0; uuid = [DAEEF528-9AB6-4482-95E9-03E6BB353BBD], identifier = [com.easytype.EasyType.Keyboard(1.7.1)], isAppExtension = 1, onSystemVolume = 0, containingBundle = [(null)], lastModified = 0, discoveryInstanceUUID = [(null)], path = [/private/var/containers/Bundle/Application/762C0B3C-A600-4AB4-AB84-AB2019FA053C/EasyType.app/PlugIns/EasyType Keyboard.appex]>, host pid = 84881>";
};
}
com.easytype.EasyType.Keyboard is bundle ID of the keyboard extension. The project was dormant for a while, this log started to show when I started work on it again. How can I fix this?
EDIT
There also another version of the log, that appears above the more common log sometimes:
EasyType Keyboard[85190:5767015] [lifecycle] WARNING! Sole personality requested when nil; THIS MAY BE A SPURIOUS LAUNCH OF THE PLUGIN due to a message to an XPC endpoint other than the main service endpoint; personalities: {
"com.easytype.EasyType.Keyboard" = {
79474 = "<PKServicePersonality: 0x2828c0700; core = <PKPlugInCore: 0x2828c0700; uuid = [706FFAE3-DC72-4DBB-AC32-C2CFFD0BD992], identifier = [com.easytype.EasyType.Keyboard(1.7.1)], isAppExtension = 1, onSystemVolume = 0, containingBundle = [(null)], lastModified = 0, discoveryInstanceUUID = [(null)], path = [/private/var/containers/Bundle/Application/648263C7-603F-458E-AB8D-9109DD2C0D80/EasyType.app/PlugIns/EasyType Keyboard.appex]>, host pid = 79474>";
};
}

iOS VPN auto disconnected after sometime

I'm working on a VPN application, VPN working fine but after 15-20 minutes, its automatically disconnected.
Here is configuration I'm using
let vpnProtocol = NEVPNProtocolIKEv2()
vpnProtocol.username = CredentialsManager.shared.accessToken
vpnProtocol.localIdentifier = CredentialsManager.shared.accessToken
print("VPN Connecting to \(self.region.name ?? "Error! Must be a valid region name!")")
if let region = self.region {
f
vpnProtocol.serverAddress = region.serverAddress
vpnProtocol.remoteIdentifier = region.serverAddress
}
let encodedIdentifier = "Secret Password".data(using: .utf8)!
let item = [kSecClass: kSecClassGenericPassword,
kSecAttrGeneric: encodedIdentifier,
kSecAttrAccount: encodedIdentifier,
kSecMatchLimit: kSecMatchLimitOne,
kSecReturnPersistentRef: kCFBooleanTrue as Any,
kSecAttrService: "XYZ"] as [CFString : Any]
var passwordReference: CFTypeRef?
SecItemCopyMatching(item as CFDictionary, &passwordReference)
vpnProtocol.passwordReference = passwordReference as? Data
vpnProtocol.authenticationMethod = .none
vpnProtocol.useExtendedAuthentication = true
vpnProtocol.ikeSecurityAssociationParameters.encryptionAlgorithm =
.algorithmAES256GCM
vpnProtocol.ikeSecurityAssociationParameters.integrityAlgorithm = .SHA384
vpnProtocol.ikeSecurityAssociationParameters.diffieHellmanGroup = .group14
vpnProtocol.childSecurityAssociationParameters.encryptionAlgorithm = .algorithmAES256GCM
vpnProtocol.childSecurityAssociationParameters.integrityAlgorithm = .SHA384
vpnProtocol.childSecurityAssociationParameters.diffieHellmanGroup = .group14
vpnProtocol.disconnectOnSleep = false
self.vpnManager.protocolConfiguration = vpnProtocol
let connectRule = NEOnDemandRuleConnect()
connectRule.interfaceTypeMatch = .any
self.vpnManager.onDemandRules = [connectRule]
self.vpnManager.isOnDemandEnabled = self.connectOnDemand
self.vpnManager.localizedDescription = "XYZ VPN"
self.vpnManager.isEnabled = true
Please help me out, how to identify problem that causing auto disconnect.
change your VPN protocol with this: NEVPNProtocolIPSec
maybe it will help you.
You have configured "connect on demand", so it will connect back automatically when you will access resource next time. That is how VPN on iOS works, it will always close connection on idle.

Issue with code for connecting to VPN

I am creating an app the allows you to connect to a VPN at the tap of a button. I've been experimenting with the code, and I receive an error Use of unresolved identifier 'getPasscodeNSData'. I Googled everywhere but I could not find a way to solve this. Thank you in advance, I will leave the chunk of code below.
func initVPN() {
let manager: NEVPNManager = NEVPNManager.sharedManager()
let p = NEVPNProtocolIPSec()
p.username = "vpnUser"
p.passwordReference = getPasscodeNSData("vpnPassword")
p.serverAddress = "vpnIP"
p.authenticationMethod = NEVPNIKEAuthenticationMethod.SharedSecret
p.sharedSecretReference = getPasscodeNSData("vpnSharedSecret")
p.useExtendedAuthentication = true
p.disconnectOnSleep = false
}
Probably you copied this code from someone. getPasscodeNSData is a function that this person wrote. You need to copy that function too.

RTCDataChannel not working iOS

I'm using RTCDataChannel. But messages which i'm sending through the channel are not receiving at the other peer.
Here is the code:
let audioConstraint : RTCPair = RTCPair(key: "OfferToReceiveAudio", value: "true")
let videoConstraint : RTCPair = RTCPair(key: "OfferToReceiveVideo", value: "true")
let dtlsConstraint : RTCPair = RTCPair(key: "DtlsSrtpKeyAgreement", value: "true")
let mediaContraints : RTCMediaConstraints = RTCMediaConstraints(mandatoryConstraints: [audioConstraint, videoConstraint], optionalConstraints: [ dtlsConstraint])
RTCPeerConnectionFactory.initializeSSL()
peerConnection = peerConnectionFactory.peerConnectionWithICEServers(servers, constraints: mediaContraints, delegate: self)
dataChannels = peerConnection?.createDataChannelWithLabel(channelName,config: nil)
dataChannels?.delegate = self
var message : NSData = NSData(base64EncodedString: "helloo")
var buffer : RTCDataBuffer = RTCDataBuffer(data: message, isBinary: true)
dataChannels?.sendData(buffer)
Have you resolved it?
One of the two peers should create data channel and other should attach the received data channel object to its data channel object.
The initiator should create datachannel before sending offer. Hope this might be helpful
I had the same problem until I set the option not to nil. If I skipped the steamId, it would not send. Even though the channel is open.
RTCDataChannelInit *dataInit = [[RTCDataChannelInit alloc] init];
dataInit.isNegotiated = YES;
dataInit.isOrdered = YES;
dataInit.maxRetransmits = 30;
dataInit.maxRetransmitTimeMs = 30000;
dataInit.streamId = 12; //important setting
self.dataChannel = [_peerConnection createDataChannelWithLabel:kRTCDataChannelLabel config:dataInit];
self.dataChannel.delegate = self;

Resources