diff --git a/OpenVPN Adapter/OpenVPNCredentials.h b/OpenVPN Adapter/OpenVPNCredentials.h index 7a2af91..6c310c8 100644 --- a/OpenVPN Adapter/OpenVPNCredentials.h +++ b/OpenVPN Adapter/OpenVPNCredentials.h @@ -8,6 +8,46 @@ #import +/** + Class used to pass credentials + */ @interface OpenVPNCredentials : NSObject +/** + Client username + */ +@property (nullable, nonatomic) NSString *username; + +/** + Client password + */ +@property (nullable, nonatomic) NSString *password; + +/** + Response to challenge + */ +@property (nullable, nonatomic) NSString *response; + +/** + Dynamic challenge/response cookie + */ +@property (nullable, nonatomic) NSString *dynamicChallengeCookie; + +/** + If YES, on successful connect, we will replace the password + with the session ID we receive from the server (if provided). + If NO, the password will be cached for future reconnects + and will not be replaced with a session ID, even if the + server provides one. + */ +@property (nonatomic) BOOL replacePasswordWithSessionID; + +/** + If YES, and if replacePasswordWithSessionID is YES, and if + we actually receive a session ID from the server, cache + the user-provided password for future use before replacing + the active password with the session ID. + */ +@property (nonatomic) BOOL cachePassword; + @end diff --git a/OpenVPN Adapter/OpenVPNCredentials.mm b/OpenVPN Adapter/OpenVPNCredentials.mm index 04b8a42..5c7bbf6 100644 --- a/OpenVPN Adapter/OpenVPNCredentials.mm +++ b/OpenVPN Adapter/OpenVPNCredentials.mm @@ -27,6 +27,52 @@ using namespace openvpn; @implementation OpenVPNCredentials +- (NSString *)username { + return !_credentials.username.empty() ? [NSString stringWithUTF8String:_credentials.username.c_str()] : nil; +} +- (void)setUsername:(NSString *)username { + _credentials.username = username ? std::string([username UTF8String]) : ""; +} + +- (NSString *)password { + return !_credentials.password.empty() ? [NSString stringWithUTF8String:_credentials.password.c_str()] : nil; +} + +- (void)setPassword:(NSString *)password { + _credentials.password = password ? std::string([password UTF8String]) : ""; +} + +- (NSString *)response { + return !_credentials.response.empty() ? [NSString stringWithUTF8String:_credentials.response.c_str()] : nil; +} + +- (void)setResponse:(NSString *)response { + _credentials.response = response ? std::string([response UTF8String]) : ""; +} + +- (NSString *)dynamicChallengeCookie { + return !_credentials.dynamicChallengeCookie.empty() ? [NSString stringWithUTF8String:_credentials.dynamicChallengeCookie.c_str()] : nil; +} + +- (void)setDynamicChallengeCookie:(NSString *)dynamicChallengeCookie { + _credentials.dynamicChallengeCookie = dynamicChallengeCookie ? std::string([dynamicChallengeCookie UTF8String]) : ""; +} + +- (BOOL)replacePasswordWithSessionID { + return _credentials.replacePasswordWithSessionID; +} + +- (void)setReplacePasswordWithSessionID:(BOOL)replacePasswordWithSessionID { + _credentials.replacePasswordWithSessionID = replacePasswordWithSessionID; +} + +- (BOOL)cachePassword { + return _credentials.cachePassword; +} + +- (void)setCachePassword:(BOOL)cachePassword { + _credentials.cachePassword = cachePassword; +} @end