From eab5cd72d7497cc43c85ec84cad972c5bb0c3c8b Mon Sep 17 00:00:00 2001 From: Sergey Abramchuk Date: Wed, 26 Apr 2017 18:06:34 +0300 Subject: [PATCH] Wrap eval config --- OpenVPN Adapter/OpenVPNProperties+Internal.h | 19 +++++ OpenVPN Adapter/OpenVPNProperties.h | 79 ++++++++++++++++++++ OpenVPN Adapter/OpenVPNProperties.mm | 61 +++++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 OpenVPN Adapter/OpenVPNProperties+Internal.h create mode 100644 OpenVPN Adapter/OpenVPNProperties.h create mode 100644 OpenVPN Adapter/OpenVPNProperties.mm diff --git a/OpenVPN Adapter/OpenVPNProperties+Internal.h b/OpenVPN Adapter/OpenVPNProperties+Internal.h new file mode 100644 index 0000000..c4f0ea9 --- /dev/null +++ b/OpenVPN Adapter/OpenVPNProperties+Internal.h @@ -0,0 +1,19 @@ +// +// OpenVPNProperties+Internal.h +// OpenVPN Adapter +// +// Created by Sergey Abramchuk on 26.04.17. +// +// + +#import + +#import "OpenVPNProperties.h" + +using namespace openvpn; + +@interface OpenVPNProperties (Internal) + +- (instancetype)initWithEvalConfig:(ClientAPI::EvalConfig)eval; + +@end diff --git a/OpenVPN Adapter/OpenVPNProperties.h b/OpenVPN Adapter/OpenVPNProperties.h new file mode 100644 index 0000000..1182d2d --- /dev/null +++ b/OpenVPN Adapter/OpenVPNProperties.h @@ -0,0 +1,79 @@ +// +// OpenVPNProperties.h +// OpenVPN Adapter +// +// Created by Sergey Abramchuk on 26.04.17. +// +// + +#import + +#import "OpenVPNTransportProtocol.h" + +@class OpenVPNServerEntry; + +@interface OpenVPNProperties : NSObject + +/** + This username must be used with profile + */ +@property (nullable, readonly, nonatomic) NSString *username; + +/** + Profile name of config + */ +@property (nullable, readonly, nonatomic) NSString *profileName; + +/** + "Friendly" name of config + */ +@property (nullable, readonly, nonatomic) NSString *friendlyName; + +/** + If YES no creds required, otherwise username/password required + */ +@property (readonly, nonatomic) BOOL autologin; + +/** + Static challenge, may be empty, ignored if autologin + */ +@property (nullable, readonly, nonatomic) NSString *staticChallenge; + +/** + YES if static challenge response should be echoed to UI, ignored if autologin + */ +@property (readonly, nonatomic) BOOL staticChallengeEcho; + +/** + YES if this profile requires a private key password + */ +@property (readonly, nonatomic) BOOL privateKeyPasswordRequired; + +/** + YES if user is allowed to save authentication password in UI + */ +@property (readonly, nonatomic) BOOL allowPasswordSave; + +/** + Address of the first remote item in config + */ +@property (nullable, readonly, nonatomic) NSString *remoteHost; + +/** + Port of the first remote item in config + */ +@property (readonly, nonatomic) NSUInteger remotePort; + +/** + Transport protocol of the first remote item in config + */ +@property (readonly, nonatomic) OpenVPNTransportProtocol remoteProto; + +/** + Optional list of user-selectable VPN servers + */ +@property (nullable, readonly, nonatomic) NSArray *servers; + +- (nonnull instancetype) __unavailable init; + +@end diff --git a/OpenVPN Adapter/OpenVPNProperties.mm b/OpenVPN Adapter/OpenVPNProperties.mm new file mode 100644 index 0000000..b3ec6f0 --- /dev/null +++ b/OpenVPN Adapter/OpenVPNProperties.mm @@ -0,0 +1,61 @@ +// +// OpenVPNProperties.m +// OpenVPN Adapter +// +// Created by Sergey Abramchuk on 26.04.17. +// +// + +#import + +#import "OpenVPNValuesConverter.h" +#import "OpenVPNServerEntry+Internal.h" +#import "OpenVPNProperties.h" +#import "OpenVPNProperties+Internal.h" + +using namespace openvpn; + +@implementation OpenVPNProperties + +- (instancetype)initWithEvalConfig:(ClientAPI::EvalConfig)eval { + self = [super init]; + if (self) { + _username = !eval.userlockedUsername.empty() ? [NSString stringWithUTF8String:eval.userlockedUsername.c_str()] : nil; + + _profileName = !eval.profileName.empty() ? [NSString stringWithUTF8String:eval.profileName.c_str()] : nil; + _friendlyName = !eval.friendlyName.empty() ? [NSString stringWithUTF8String:eval.friendlyName.c_str()] : nil; + + _autologin = eval.autologin; + + _staticChallenge = !eval.staticChallenge.empty() ? [NSString stringWithUTF8String:eval.staticChallenge.c_str()] : nil; + _staticChallengeEcho = eval.staticChallengeEcho; + + _privateKeyPasswordRequired = eval.privateKeyPasswordRequired; + _allowPasswordSave = eval.allowPasswordSave; + + _remoteHost = !eval.remoteHost.empty() ? [NSString stringWithUTF8String:eval.remoteHost.c_str()] : nil; + + uint16_t port = 0; + parse_number(eval.remotePort, port); + + _remotePort = port; + + NSString *currentProto = [NSString stringWithUTF8String:eval.remoteProto.c_str()]; + _remoteProto = [OpenVPNPropertyConverter getTransportProtocolFromString:currentProto]; + + _servers = nil; + if (!eval.serverList.empty()) { + NSMutableArray *servers = [NSMutableArray new]; + + for (ClientAPI::ServerEntry entry : eval.serverList) { + OpenVPNServerEntry *serverEntry = [[OpenVPNServerEntry alloc] initWithServerEntry:entry]; + [servers addObject:serverEntry]; + } + + _servers = servers; + } + } + return self; +} + +@end