This repository has been archived by the owner on Sep 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ConfirmedConstants.swift
400 lines (349 loc) · 16.3 KB
/
ConfirmedConstants.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
//
// Global.swift
// Confirmed VPN
//
//
// Copyright © 2018 Confirmed, Inc. All rights reserved.
//
#if os(iOS)
import UIKit
#elseif os(OSX)
import Foundation
#endif
import KeychainAccess
import Reachability
class Global {
static let reachability = Reachability()
static let keychain = Keychain(service: "com.confirmed.tunnels").synchronizable(true)
static let forceProduction = true //switch on to force prod routes
static var sourceID : String {
get {
if Global.isVersion(version: .v1API) {
return ""
}
else if Global.isVersion(version: .v2API){
return "-090718" //certificate chain
}
else {
return "-111818" //certificate chain
}
}
}
static func isVersion(version : APIVersionType) -> Bool {
if UserDefaults.standard.string(forKey:Global.kConfirmedAPIVersion) == nil {
Utils.chooseAPIVersion()
}
if UserDefaults.standard.string(forKey:Global.kConfirmedAPIVersion) == version {
return true
}
else {
return false
}
}
static var vpnPassword : String {
get {
if Global.isVersion(version: .v1API) {
return "trustwizardsjustplaying"
}
else {
#if os(iOS)
return ""
#else
return "rdar://12503102" //macOS requires a password here
#endif
}
}
}
//MARK: - URLS
static func endPoint(base : String) -> String {
return base + sourceID + "." + Global.vpnDomain
}
static var remoteIdentifier : String {
return "www" + sourceID + "." + "confirmedvpn.com"
}
static var vpnDomain : String {
if Utils.isAppInProduction() {
if Global.isVersion(version: .v1API) || Global.isVersion(version: .v2API) { //deprecated domain
if !UserDefaults.standard.bool(forKey: Global.kIsOnFinalDeprecatedV1V2) {
Global.keychain[Global.kConfirmedP12Key] = nil
Global.keychain[Global.kConfirmedID] = nil
}
return "confirmedvpn.co"
}
return "confirmedvpn.com"
}
else {
return "confirmedvpn.com" // enter staging url
}
}
static var masterURL : String {
get {
if Utils.isAppInProduction() {
//production routes
if Global.isVersion(version: .v1API) {
if UserDefaults.standard.bool(forKey: Global.kIsOnFinalDeprecatedV1V2) {
return "https://v1." + Global.vpnDomain
}
return "https://api." + Global.vpnDomain
}
else if Global.isVersion(version: .v2API) {
return "https://v2." + Global.vpnDomain
}
else {
return "https://v3." + Global.vpnDomain
}
}
else {
//staging/dev routes
if Global.isVersion(version: .v1API) {
return "https://v1." + Global.vpnDomain
}
else if Global.isVersion(version: .v2API) {
return "https://v2" + Global.vpnDomain
}
else {
return "https://v3." + Global.vpnDomain
}
}
}
}
static var createUserURL : String {
get {
UserDefaults.standard.set(APIVersionType.v3API, forKey: Global.kConfirmedAPIVersion) //all new users are v2
UserDefaults.standard.synchronize()
NotificationCenter.post(name: .switchingAPIVersions)
return Global.masterURL + "/signup"
}
}
static var getIPURL : String {
return "https://ip.confirmedvpn.com/ip" //no support on v1/v2
}
static var getSpeedTestBucket : String {
return "https://v3.confirmedvpn.com/download-speed-test"
}
static var signinURL : String {
get {
return Global.masterURL + "/signin"
}
}
static var activeSubscriptionInformationURL : String {
get {
return Global.masterURL + "/active-subscriptions"
}
}
static var subscriptionInformationURL : String {
get {
return Global.masterURL + "/subscriptions"
}
}
static var subscriptionReceiptUploadURL : String {
get {
return Global.masterURL + "/subscription-event"
}
}
static var getKeyURL : String {
get {
return Global.masterURL + "/get-key"
}
}
static var forgotPasswordURL : String {
get {
return Global.masterURL + "/forgot-password"
}
}
static var addEmailToUserURL : String {
get {
UserDefaults.standard.set(APIVersionType.v3API, forKey: Global.kConfirmedAPIVersion)
UserDefaults.standard.synchronize() //all new users are v3
NotificationCenter.post(name: .switchingAPIVersions)
return Global.masterURL + "/convert-shadow-user"
}
}
static var paymentURL : String {
get {
return Global.masterURL + "/new-subscription" + "?type=mac" + "&plan=all-monthly"
}
}
/*
* keychain key declaration
* attach prefix based on version to prevent incorrect value for api server
*/
//MARK: - KEYCHAIN KEYS
static let vpnName = "Confirmed VPN"
static let kICloudContainer = "iCloud.com.confirmed.tunnels"
static let kOpenTunnelRecord = "OpenTunnelRemotely"
static let kCloseTunnelRecord = "CloseTunnelRemotely"
static func apiVersionPrefix() -> APIVersionType {
if Global.isVersion(version: .v1API) {
return APIVersionType.v1API
}
if Global.isVersion(version: .v2API) {
return APIVersionType.v2API
}
return APIVersionType.v3API
}
static var vpnSavedRegionKey : String { get { return apiVersionPrefix() + "savedRegion-universal" }}
static var kConfirmedP12Key : String { get { return apiVersionPrefix() + "TunnelsP12" }}
static var kConfirmedPrivateKey : String { get { return apiVersionPrefix() + "TunnelsPrivateKey" }}
static var kConfirmedCACertKey : String { get { return apiVersionPrefix() + "TunnelsCACert" }}
static var kConfirmedCLCertKey : String { get { return apiVersionPrefix() + "TunneCLCert" }}
static var kConfirmedID : String { get { return apiVersionPrefix() + "TunnelsID" }}
static var kConfirmedEmail : String { get { return apiVersionPrefix() + "TunnelsEmail" }}
static var kConfirmedPassword : String { get { return apiVersionPrefix() + "TunnelsPassword" }}
static var kConfirmedReceiptKey : String { get { return apiVersionPrefix() + "TunnelsReceipt" }}
static var kPartnerCode = "PartnerCode"
static var kLastEnvironment = "lastEnvironment"
static let kPlatformiOS = "ios"
static let kPlatformMac = "mac"
static let kPartnerCodePasteboardType = "com.confirmed.tunnels.PartnerCode"
static let kConfirmedUniquePartnerCode = "266347633"
static let kConfirmedAPIVersion = "API-Version"
static let contentBlockerBundleID = "com.confirmed.tunnels.Confirmed-Blocker"
//MARK: - URLS (macOS ONLY)
static let kPaymentAcceptedURL = "tunnels://stripesuccess"
static let kEmailConfirmedURL = "tunnels://emailconfirmed"
//**********************************************************
//NOTIFICATIONS
//**********************************************************
//MARK: - NOTIFICATIONS
static let fetchingP12Notification = "ConfirmFetchingP12Notification"
static let kInternetConnectionLost = -1005
static let kInternetDownError = -1009
static let kServerDownError = -1004
static let kServerTimedOutError = -1001
static let kStreamError = -2102
static let kNoError = 0
static let kEmailNotConfirmed = 1
static let kIncorrectLogin = 2
static let kRequestFieldValidationError = 3
static let kMobileSubscriptionOnly = 38
static let kEmailAlreadyUsed = 40
static let kReceiptAlreadyUsed = 48
static let kMissingPaymentErrorCode = 6
static let kInvalidAuth = 401
static let kTooManyRequests = 999
static let kUnknownError = 99999
static func errorMessageForError(eCode : Int) -> String {
if let errorMessage = kAuthErrorCodes[eCode] {
return errorMessage
}
return kAuthErrorCodes[Global.kUnknownError]!
}
private static var kAuthErrorCodes = [ kEmailNotConfirmed : "Please check your e-mail for a confirmation link.",
kRequestFieldValidationError : "Invalid field.",
kInvalidAuth : "Incorrect login.",
kIncorrectLogin : "Incorrect login.",
kMobileSubscriptionOnly : "Please upgrade from mobile only at https://confirmedvpn.com",
kEmailAlreadyUsed : "This e-mail is already registered to a user.",
kReceiptAlreadyUsed : "Your account is already associated with another email.",
kUnknownError : "Unknown error."
]
//MARK: - USER DEFAULTS
static let kAdBlockingEnabled = "AdBlockingEnabled" //content blocker: should block ads
static let kScriptBlockingEnabled = "PrivacyBlockingEnabled" //content blocker: should block tracking scripts
static let kSocialBlockingEnabled = "SocialBlockingEnabled" //content blocker: should block social domains
static let kUserWhitelistedDomains = "whitelisted_domains_user" //customized whitelisted domains from user
static let kConfirmedWhitelistedDomains = "whitelisted_domains" //default whitelisted domains from Confirmed Team
static let kIsLastStateConnected = "Connected" //track last selected state from user
static let kConnectOnLaunch = "ConnectOnLaunch" //should VPN connect on launch
static let kForceVPNOnMac = "ForceVPNOn" //prevents any traffic from processing outside the VPN (except whitelisted sites)
static let kIsOnFinalDeprecatedV1V2 = "IsOnFinalDeprecatedV1V2" //for old users, moving to v1/v2 on .co to keep launch environment clean
static func sharedUserDefaults() -> UserDefaults {
return UserDefaults(suiteName: Utils.userDefaultsSuite)!
}
static let accountText = "Account".localized()
static let helpText = "Help".localized()
static let privacyText = "Privacy".localized()
static let benefitsText = "Benefits".localized()
static let speedTestText = "Speed Test".localized()
static let whitelistingText = "Whitelisting".localized()
static let contentBlockerText = "Content Blocker".localized()
static let disconnectingText = "Disconnecting...".localized()
static let connectingText = "Connecting...".localized()
static let disconnectedText = "Disconnected".localized()
static let protectedText = "Protected".localized()
static let ipAddressHidden = "IP Address Hidden".localized()
static let ipAddressVisible = "IP Address Visible".localized()
static let ipAddressInformation = "Your IP address is a uniquely identifiable number to track your activities. Confirmed masks this number to let you browse anonymously.".localized()
static let encryptedTraffic = "Encrypted Traffic".localized()
static let unencryptedTraffic = "Some Unencrypted Traffic".localized()
static let encryptedInformation = "Confirmed uses 256-bit encryption to prevent snoopers and ISPs from viewing your data or browsing history.".localized()
static let blockAds = "Block Ads".localized()
static let allowAds = "Ads Allowed".localized()
static let adInformation = "Confirmed provides a Content Blocker to speed up your Internet and prevent obtrusive ads from ruining your Internet experience.".localized()
static let trackingScriptsBlocked = "Tracking Scripts Blocked".localized()
static let trackingScriptsEnabled = "Tracking Scripts Enabled".localized()
static let trackingScriptsInformation = "Many websites include tracking scripts from Facebook, Google, and other sites that allow companies to track you across the Internet. Confirmed's Content Blocker removes these scripts, allowing you to have a privacy-focused experience.".localized()
static let vpnSetupDescription = "Your traffic is now encrypted with bank-level 256-bit encryption and your uniquely identifiable IP address is hidden to protect your privacy.".localized()
static let blockTrackingScripts = "Block Tracking Scripts".localized()
static let blockSocialTrackers = "Block Social Trackers".localized()
static let monthly = "Monthly".localized()
static let annual = "Annual".localized()
}
public typealias APIVersionType = String
extension APIVersionType {
static let v1API = "v1"
static let v2API = "v2"
static let v3API = "v3"
}
#if os(iOS)
extension UIImage {
static let questionIcon = UIImage.init(named: "question_mark")?.withRenderingMode(.alwaysTemplate)
static let privacyIcon = UIImage.init(named: "privacy_policy")?.withRenderingMode(.alwaysTemplate)
static let informationIcon = UIImage.init(named: "information_icon")?.withRenderingMode(.alwaysTemplate)
static let lightningIconThick = UIImage.init(named: "lightning_icon_thick")?.withRenderingMode(.alwaysTemplate)
static let installIcon = UIImage.init(named: "install_icon")?.withRenderingMode(.alwaysTemplate)
static let checkIcon = UIImage.init(named: "checkmark")?.withRenderingMode(.alwaysTemplate)
static let blockIcon = UIImage.init(named: "block_icon")?.withRenderingMode(.alwaysTemplate)
static let accountIcon = UIImage.init(named: "account_icon")?.withRenderingMode(.alwaysTemplate)
static let powerIconPadded = UIImage(named: "power_button_padded")?.withRenderingMode(.alwaysTemplate)
}
extension UIColor {
static let tunnelsBlueColor = UIColor.init(red: 0/255.0, green: 173/255.0, blue: 231/255.0, alpha: 1.0)
static let tunnelsLightBlueColor = UIColor.init(red: 0/255.0, green: 173/255.0, blue: 231/255.0, alpha: 1.0)
static let tunnelsErrorColor = UIColor.init(red: 200/255.0, green: 20.0/255.0, blue: 20/255.0, alpha: 1.0)
}
#elseif os(OSX)
extension NSImage {
static let checkmarkIcon = NSImage.init(named: NSImage.Name(rawValue: "checkmark"))
static let blockIcon = NSImage.init(named: NSImage.Name(rawValue: "block_icon"))
static let statusBarIcon = NSImage(named: NSImage.Name(rawValue: "StatusBarImage"))
static let statusBarIconDisabled = NSImage(named: NSImage.Name(rawValue: "status_bar_image_disabled"))
static let settingsIcon = NSImage(named: NSImage.Name(rawValue: "settings_icon"))
static let powerIcon = NSImage(named: NSImage.Name(rawValue: "power_button"))
static let downArrow = NSImage.init(named: NSImage.Name(rawValue: "down_arrow"))
static let downArrowWhite = NSImage.init(named: NSImage.Name(rawValue: "down_arrow_white"))
static let upArrow = NSImage.init(named: NSImage.Name(rawValue: "up_arrow"))
static let upArrowWhite = NSImage.init(named: NSImage.Name(rawValue: "up_arrow_white"))
}
extension NSColor {
static let tunnelsBlueColor = NSColor.init(red: 0/255.0, green: 173/255.0, blue: 231/255.0, alpha: 1.0)
static let tunnelsLightBlueColor = NSColor.init(red: 0/255.0, green: 173/255.0, blue: 231/255.0, alpha: 1.0)
static let tunnelsErrorColor = NSColor.init(red: 200/255.0, green: 20.0/255.0, blue: 20/255.0, alpha: 1.0)
}
#endif
//Server location structure
struct ServerMetadata {
var countryName: String
var flagImagePath: String
var countryCode: String
}
//Response fields from server
struct ServerResponse:Codable {
let code : Int?
let message : String?
let b64 : String?
let id : String?
enum CodingKeys: String, CodingKey {
case code
case message
case b64
case id
}
}
extension Encodable {
var dictionary: [String: Any]? {
guard let data = try? JSONEncoder().encode(self) else { return nil }
return (try? JSONSerialization.jsonObject(with: data, options: .allowFragments)).flatMap { $0 as? [String: Any] }
}
}