Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Integrated new API to get VPN credentials

  • Loading branch information
naira-cliqz committed Jan 25, 2019
1 parent c88dc39 commit 24f707dc3eddf7369053a75c4510af9d2b513204
@@ -424,6 +424,7 @@
4FD0C7E7219B0E7F003A9B61 /* RegistrationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FD0C7E6219B0E7F003A9B61 /* RegistrationViewController.swift */; };
4FD0C7EF219C65A7003A9B61 /* EmailVerificationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FD0C7EE219C65A7003A9B61 /* EmailVerificationViewController.swift */; };
4FD19FC5205A9F7700547DD5 /* NativeContextMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FD19FC4205A9F7700547DD5 /* NativeContextMenu.swift */; };
4FDC331921F8BAAD001215EF /* VPNCredentialsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FDC331821F8BAAD001215EF /* VPNCredentialsService.swift */; };
4FF07D852063C99E001385A8 /* OffrView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FF07D802063C99D001385A8 /* OffrView.swift */; };
4FF07D862063C99E001385A8 /* OffrzViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FF07D812063C99D001385A8 /* OffrzViewController.swift */; };
4FF07D872063C99E001385A8 /* OffrzEmptyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FF07D822063C99E001385A8 /* OffrzEmptyView.swift */; };
@@ -1824,6 +1825,7 @@
4FD0C7E6219B0E7F003A9B61 /* RegistrationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegistrationViewController.swift; sourceTree = "<group>"; };
4FD0C7EE219C65A7003A9B61 /* EmailVerificationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmailVerificationViewController.swift; sourceTree = "<group>"; };
4FD19FC4205A9F7700547DD5 /* NativeContextMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeContextMenu.swift; sourceTree = "<group>"; };
4FDC331821F8BAAD001215EF /* VPNCredentialsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VPNCredentialsService.swift; sourceTree = "<group>"; };
4FF07D802063C99D001385A8 /* OffrView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OffrView.swift; sourceTree = "<group>"; };
4FF07D812063C99D001385A8 /* OffrzViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OffrzViewController.swift; sourceTree = "<group>"; };
4FF07D822063C99E001385A8 /* OffrzEmptyView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OffrzEmptyView.swift; sourceTree = "<group>"; };
@@ -3631,6 +3633,7 @@
AF6C8AFC21873B5D006F8166 /* VPNButton.swift */,
AF6C8AF921873B5C006F8166 /* VPNCountryController.swift */,
AF6C8AFB21873B5D006F8166 /* VPNViewController.swift */,
4FDC331821F8BAAD001215EF /* VPNCredentialsService.swift */,
);
path = VPN;
sourceTree = "<group>";
D0C95E0E200FD3B200E4E51C /* PrintHelper.swift in Sources */,
E64ED8FA1BC55AE300DAF864 /* UIAlertControllerExtensions.swift in Sources */,
4F3045CB204FF0C500C99162 /* CliqzSearchViewController.swift in Sources */,
4FDC331921F8BAAD001215EF /* VPNCredentialsService.swift in Sources */,
282DA4731A68C1E700A406E2 /* OpenSearch.swift in Sources */,
4F30F50C2051670C0049E4F6 /* Crypto.swift in Sources */,
F35B8D2F1D638408008E3D61 /* SessionRestoreHandler.swift in Sources */,
@@ -256,6 +256,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIViewControllerRestorati
}

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

// Override point for customization after application launch.
var shouldPerformAdditionalDelegateHandling = true

@@ -81,6 +81,8 @@
<string></string>
<key>LeanplumProductionKey</key>
<string></string>
<key>LumenAPIKey</key>
<string></string>
<key>MozDevelopmentTeam</key>
<string>$(DEVELOPMENT_TEAM)</string>
<key>MozWhatsNewTopic</key>
@@ -0,0 +1,76 @@
//
// VPNCredentialsService.swift
// Client
//
// Created by Sahakyan on 1/23/19.
// Copyright © 2019 Cliqz. All rights reserved.
//
import Foundation
import Alamofire
import SwiftyJSON

struct VPNData {
let country: String
let username: String
let password: String
let secret: String
let serverIP: String
let port: String
}

class VPNCredentialsService {

private static let APIKey = "LumenAPIKey"

class func getVPNCredentials(completion: @escaping ([VPNData]) -> Void) {
guard let apiKey = Bundle.main.object(forInfoDictionaryKey: APIKey) as? String, !apiKey.isEmpty else {
print("API Key is not available in Info.plist")
return
}

let params = ["user": "lumen@cliqz.com",
"password": "123pass",
"token": "token"]
let header = ["x-api-key": apiKey]
var result = [VPNData]()
Alamofire.request("https://nae1kxj155.execute-api.eu-central-1.amazonaws.com/default/bond-vpn", method: .post, parameters: params, encoding: JSONEncoding.default, headers: header).responseJSON { (response) in
if response.result.isSuccess {
let json = JSON(response.result.value ?? "")
if let vpnCreds = json.array {
for cred in vpnCreds {
if let c = cred.dictionary,
let country = c.keys.first,
let data = c[country]?.dictionary,
let username = data["Username"]?.string,
let password = data["Password"]?.string,
let secret = data["IPSecSecret"]?.string,
let ip = data["ServerIP"]?.string,
let port = data["ServerPort"]?.string {
result.append(VPNData(country: country, username: username, password: password, secret: secret, serverIP: ip, port: port))
}
}
}
} else {
print(response.error) // TODO proper Error
}
completion(result)
}

/*
Alamofire.request("http://c.betrad.com/mobile/ghostery-ios-can-access").responseData { (response) in
if response.value?.count == 0 {
DispatchQueue.main.async {
self.updateImageStatus(self.WifiProtectedStatusImage, isOn: true)
self.updateImageStatus(self.configStatusImage, isOn: true)
}
} else {
DispatchQueue.main.async {
self.updateImageStatus(self.WifiProtectedStatusImage, isOn: false)
self.updateImageStatus(self.configStatusImage, isOn: false)
}
}
}*/

}
}
@@ -247,6 +247,14 @@ class VPNEndPointManager {
}

private func getVPNCredentialsFromServer() {
VPNCredentialsService.getVPNCredentials { [weak self] (credentials) in
for cred in credentials {
if let country = self?.country(id: cred.country) {
self?.setCreds(country: country, username: cred.username, password: cred.password, sharedSecret: cred.secret)
}
}
}
/*
let userCred = AuthenticationService.shared.generateNewCredentials("vpn@lumen.com")
BondAPIManager.shared.currentBondHandler().getIPSecCreds(withRequest: userCred) { [weak self] (response, error) in
//TODO: write the credentials into the keychain
@@ -258,6 +266,7 @@ class VPNEndPointManager {
}
}
}
*/
}

func country(id: String) -> VPNCountry? {
@@ -468,13 +477,13 @@ class VPNViewController: UIViewController {
@objc func connectButtonPressed(_ sender: Any) {
//try to connect
guard AuthenticationService.shared.hasValidSubscription() == true else {
let text = NSLocalizedString("Your subscription has expired. Renew your subscription to continue to use the VPN.", tableName: "Lumen", comment: "[VPN] subscription expired alert text")
let alert = UIAlertController.alertWithOkay(text: text)
self.present(alert, animated: true, completion: nil)
return
}
// guard AuthenticationService.shared.hasValidSubscription() == true else {
// let text = NSLocalizedString("Your subscription has expired. Renew your subscription to continue to use the VPN.", tableName: "Lumen", comment: "[VPN] subscription expired alert text")
// let alert = UIAlertController.alertWithOkay(text: text)
// self.present(alert, animated: true, completion: nil)
// return
// }
if (NEVPNManager.shared().connection.status == .connected) {
VPN.disconnectVPN()
}
@@ -93,7 +93,8 @@ node('mac-vm-host') {
string(credentialsId: '05be12cd-5177-4adf-9812-809f01451fa0', variable: 'FASTLANE_PASSWORD'),
string(credentialsId: 'ee93743c-b0be-46aa-b49a-ab3caaea4f67', variable: 'MATCH_PASSWORD'),
string(credentialsId: 'f206e880-e09a-4369-a3f6-f86ee94481f2', variable: 'SENTRY_AUTH_TOKEN'),
string(credentialsId: 'ab91f92a-4588-4034-8d7f-c1a741fa31ab', variable: 'FASTLANE_ITC_TEAM_ID')])
string(credentialsId: 'ab91f92a-4588-4034-8d7f-c1a741fa31ab', variable: 'FASTLANE_ITC_TEAM_ID'),
string(credentialsId: 'cc9215e4-ca8f-41bd-9e0b-1c2ba1900949', variable: 'LumenAPIKey')])
{
sh '''#!/bin/bash -l
set -x
@@ -123,7 +124,8 @@ node('mac-vm-host') {
string(credentialsId: '05be12cd-5177-4adf-9812-809f01451fa0', variable: 'FASTLANE_PASSWORD'),
string(credentialsId: 'ee93743c-b0be-46aa-b49a-ab3caaea4f67', variable: 'MATCH_PASSWORD'),
string(credentialsId: 'f206e880-e09a-4369-a3f6-f86ee94481f2', variable: 'SENTRY_AUTH_TOKEN'),
string(credentialsId: 'ab91f92a-4588-4034-8d7f-c1a741fa31ab', variable: 'FASTLANE_ITC_TEAM_ID')])
string(credentialsId: 'ab91f92a-4588-4034-8d7f-c1a741fa31ab', variable: 'FASTLANE_ITC_TEAM_ID'),
string(credentialsId: 'cc9215e4-ca8f-41bd-9e0b-1c2ba1900949', variable: 'LumenAPIKey')])
{
sh '''#!/bin/bash -l
set -x

0 comments on commit 24f707d

Please sign in to comment.