diff --git a/Sources/OpenVPN3/client/ovpncli.cpp b/Sources/OpenVPN3/client/ovpncli.cpp index 6d23519..c9a1406 100644 --- a/Sources/OpenVPN3/client/ovpncli.cpp +++ b/Sources/OpenVPN3/client/ovpncli.cpp @@ -663,6 +663,14 @@ namespace openvpn { se.friendlyName = i->friendlyName; eval.serverList.push_back(se); } + // Added by Dener Araújo - 2020-09-06 + for (ParseClientConfig::DhcpOptionList::const_iterator i = cc.dhcpOptionList().begin(); i != cc.dhcpOptionList().end(); ++i) + { + DhcpOptionEntry de; + de.type = i->type; + de.address = i->address; + eval.dhcpOptionList.push_back(de); + } } catch (const std::exception& e) { diff --git a/Sources/OpenVPN3/client/ovpncli.hpp b/Sources/OpenVPN3/client/ovpncli.hpp index 9a1f5be..96eb699 100644 --- a/Sources/OpenVPN3/client/ovpncli.hpp +++ b/Sources/OpenVPN3/client/ovpncli.hpp @@ -47,6 +47,15 @@ namespace openvpn { std::string friendlyName; }; + // Added by Dener Araújo - 2020-09-06 + // Represents an "dhcp-option" with its type (DNS, WINS, etc) and its address + // (client reads) + struct DhcpOptionEntry + { + std::string type; + std::string address; + }; + // return properties of config // (client reads) struct EvalConfig @@ -91,6 +100,10 @@ namespace openvpn { // optional list of user-selectable VPN servers std::vector serverList; + + // Added by Dener Araújo - 2020-09-06 + // optional list of "dhcp-option" + std::vector dhcpOptionList; }; // used to pass credentials to VPN core diff --git a/Sources/OpenVPN3/openvpn/client/cliopthelper.hpp b/Sources/OpenVPN3/openvpn/client/cliopthelper.hpp index 6a24013..491d388 100644 --- a/Sources/OpenVPN3/openvpn/client/cliopthelper.hpp +++ b/Sources/OpenVPN3/openvpn/client/cliopthelper.hpp @@ -59,6 +59,17 @@ namespace openvpn { { }; + // Added by Dener Araújo - 2020-09-06 + struct DhcpOptionEntry { + std::string type; + std::string address; + }; + + // Added by Dener Araújo - 2020-09-06 + struct DhcpOptionList : public std::vector + { + }; + struct RemoteItem { std::string host; std::string port; @@ -283,6 +294,30 @@ namespace openvpn { } } + // Added by Dener Araújo - 2020-09-06 + // dhpc-option + { + const OptionList::IndexList *dhcpList = options.get_index_ptr("dhcp-option"); + + if (dhcpList) + { + for (OptionList::IndexList::const_iterator i = dhcpList->begin(); i != dhcpList->end(); ++i) + { + const Option& o = options[*i]; + o.touch(); + + const std::string arg1 = o.get_optional(1, 256); + const std::string arg2 = o.get_optional(2, 256); + + DhcpOptionEntry dhcp; + dhcp.type = arg1; + dhcp.address = arg2; + + dhcpOptionList_.push_back(std::move(dhcp)); + } + } + } + // protocol configuration { protoConfig.reset(new ProtoContext::Config()); @@ -435,6 +470,10 @@ namespace openvpn { // return first remote directive in config const RemoteItem& firstRemoteListItem() const { return firstRemoteListItem_; } + + // Added by Dener Araújo - 2020-09-06 + // dhpc-option + const DhcpOptionList& dhcpOptionList() const { return dhcpOptionList_; } std::string to_string() const { @@ -524,6 +563,18 @@ namespace openvpn { root["mode"] = Json::Value("client"); root["dev"] = Json::Value(dev); + // Added by Dener Araújo - 2020-09-06 + root["dhcp-options"] = Json::Value(Json::arrayValue); + for (size_t i = 0; i < dhcpOptionList_.size(); i++) + { + const DhcpOptionEntry& item = dhcpOptionList_[i]; + + Json::Value el = Json::Value(Json::objectValue); + el["type"] = Json::Value(item.type); + el["address"] = Json::Value(item.address); + + root["dhcp-options"].append(el); + } root["dev-type"] = Json::Value(protoConfig->layer.dev_type()); root["remotes"] = Json::Value(Json::arrayValue); for (size_t i = 0; i < remoteList->size(); i++) @@ -716,6 +767,7 @@ namespace openvpn { ProtoContext::Config::Ptr protoConfig; SSLLib::SSLAPI::Config::Ptr sslConfig; std::string dev; + DhcpOptionList dhcpOptionList_; // Added by Dener Araújo - 2020-09-06 }; } diff --git a/Sources/OpenVPNAdapter/Umbrella-Header.h b/Sources/OpenVPNAdapter/Umbrella-Header.h index e30ed5a..f0a92df 100644 --- a/Sources/OpenVPNAdapter/Umbrella-Header.h +++ b/Sources/OpenVPNAdapter/Umbrella-Header.h @@ -26,6 +26,7 @@ FOUNDATION_EXPORT const unsigned char OpenVPNAdapterVersionString[]; #import #import #import +#import // Added by Dener Araújo - 2020-09-06 #import #import #import diff --git a/Sources/OpenVPNAdapter/library/OpenVPNConfigurationEvaluation.h b/Sources/OpenVPNAdapter/library/OpenVPNConfigurationEvaluation.h index f304c83..2435b5a 100644 --- a/Sources/OpenVPNAdapter/library/OpenVPNConfigurationEvaluation.h +++ b/Sources/OpenVPNAdapter/library/OpenVPNConfigurationEvaluation.h @@ -10,6 +10,7 @@ typedef NS_ENUM(NSInteger, OpenVPNTransportProtocol); @class OpenVPNServerEntry; +@class OpenVPNDhcpOptionEntry; //Added by Dener Araújo - 2020-09-06 @interface OpenVPNConfigurationEvaluation : NSObject @@ -78,6 +79,12 @@ typedef NS_ENUM(NSInteger, OpenVPNTransportProtocol); */ @property (nullable, readonly, nonatomic) NSArray *servers; +/** + Added by Dener Araújo - 2020-09-06 + Optional list of "dhcp-option" +*/ +@property (nullable, readonly, nonatomic) NSArray *dhcpOptions; + - (nonnull instancetype) init NS_UNAVAILABLE; @end diff --git a/Sources/OpenVPNAdapter/library/OpenVPNConfigurationEvaluation.mm b/Sources/OpenVPNAdapter/library/OpenVPNConfigurationEvaluation.mm index 6c53413..973c994 100644 --- a/Sources/OpenVPNAdapter/library/OpenVPNConfigurationEvaluation.mm +++ b/Sources/OpenVPNAdapter/library/OpenVPNConfigurationEvaluation.mm @@ -13,6 +13,7 @@ #import "OpenVPNConfiguration+Internal.h" #import "OpenVPNServerEntry+Internal.h" +#import "OpenVPNDhcpOptionEntry+Internal.h" //Added by Dener Araújo - 2020-09-06 using namespace openvpn; @@ -56,6 +57,20 @@ using namespace openvpn; _servers = servers; } + + //Added by Dener Araújo - 2020-09-06 + _dhcpOptions = nil; + + if (!eval.dhcpOptionList.empty()) { + NSMutableArray *dhcpOptions = [NSMutableArray new]; + + for (ClientAPI::DhcpOptionEntry entry : eval.dhcpOptionList) { + OpenVPNDhcpOptionEntry *dhcpOptionEntry = [[OpenVPNDhcpOptionEntry alloc] initWithDhcpOptionEntry:entry]; + [dhcpOptions addObject:dhcpOptionEntry]; + } + + _dhcpOptions = dhcpOptions; + } } return self; } diff --git a/Sources/OpenVPNAdapter/library/OpenVPNDhcpOptionEntry+Internal.h b/Sources/OpenVPNAdapter/library/OpenVPNDhcpOptionEntry+Internal.h new file mode 100644 index 0000000..f972917 --- /dev/null +++ b/Sources/OpenVPNAdapter/library/OpenVPNDhcpOptionEntry+Internal.h @@ -0,0 +1,18 @@ +// +// OpenVPNDhcpOptionEntry+Internal.h +// Pods +// +// Created by Dener Araújo on 06/09/20. +// + +#import "OpenVPNDhcpOptionEntry.h" + +#include + +using namespace openvpn; + +@interface OpenVPNDhcpOptionEntry (Internal) + +- (instancetype)initWithDhcpOptionEntry:(ClientAPI::DhcpOptionEntry)entry; + +@end diff --git a/Sources/OpenVPNAdapter/library/OpenVPNDhcpOptionEntry.h b/Sources/OpenVPNAdapter/library/OpenVPNDhcpOptionEntry.h new file mode 100644 index 0000000..7aabf3f --- /dev/null +++ b/Sources/OpenVPNAdapter/library/OpenVPNDhcpOptionEntry.h @@ -0,0 +1,17 @@ +// +// OpenVPNDhcpOptionEntry.h +// Pods +// +// Created by Dener Araújo on 06/09/20. +// + +#import + +@interface OpenVPNDhcpOptionEntry : NSObject + +@property (nullable, readonly, nonatomic) NSString *type; +@property (nullable, readonly, nonatomic) NSString *address; + +- (nonnull instancetype) init NS_UNAVAILABLE; + +@end diff --git a/Sources/OpenVPNAdapter/library/OpenVPNDhcpOptionEntry.mm b/Sources/OpenVPNAdapter/library/OpenVPNDhcpOptionEntry.mm new file mode 100644 index 0000000..9f82b8e --- /dev/null +++ b/Sources/OpenVPNAdapter/library/OpenVPNDhcpOptionEntry.mm @@ -0,0 +1,21 @@ +// +// OpenVPNDhcpOptionEntry.mm +// OpenVPNAdapter +// +// Created by Dener Araújo on 06/09/20. +// + +#import "OpenVPNDhcpOptionEntry.h" +#import "OpenVPNDhcpOptionEntry+Internal.h" + +@implementation OpenVPNDhcpOptionEntry + +- (instancetype)initWithDhcpOptionEntry:(ClientAPI::DhcpOptionEntry)entry { + if (self = [super init]) { + _type = !entry.type.empty() ? [NSString stringWithUTF8String:entry.type.c_str()] : nil; + _address = !entry.address.empty() ? [NSString stringWithUTF8String:entry.address.c_str()] : nil; + } + return self; +} + +@end diff --git a/Sources/mbedTLS/library/entropy.c b/Sources/mbedTLS/library/entropy.c index e17512e..ebe3575 100644 --- a/Sources/mbedTLS/library/entropy.c +++ b/Sources/mbedTLS/library/entropy.c @@ -262,7 +262,7 @@ int mbedtls_entropy_update_manual( mbedtls_entropy_context *ctx, */ static int entropy_gather_internal( mbedtls_entropy_context *ctx ) { - int ret, i, have_one_strong = 0; + int ret = 0, i, have_one_strong = 0; // Updated by Dener Araújo - 2020-09-06 unsigned char buf[MBEDTLS_ENTROPY_MAX_GATHER]; size_t olen; diff --git a/Sources/mbedTLS/library/hmac_drbg.c b/Sources/mbedTLS/library/hmac_drbg.c index 346c263..2454f90 100644 --- a/Sources/mbedTLS/library/hmac_drbg.c +++ b/Sources/mbedTLS/library/hmac_drbg.c @@ -78,7 +78,7 @@ int mbedtls_hmac_drbg_update_ret( mbedtls_hmac_drbg_context *ctx, unsigned char rounds = ( additional != NULL && add_len != 0 ) ? 2 : 1; unsigned char sep[1]; unsigned char K[MBEDTLS_MD_MAX_SIZE]; - int ret; + int ret = 0; // Updated by Dener Araújo - 2020-09-06 for( sep[0] = 0; sep[0] < rounds; sep[0]++ ) { diff --git a/Sources/mbedTLS/library/x509_crl.c b/Sources/mbedTLS/library/x509_crl.c index 3ceb770..8b99979 100644 --- a/Sources/mbedTLS/library/x509_crl.c +++ b/Sources/mbedTLS/library/x509_crl.c @@ -544,7 +544,7 @@ int mbedtls_x509_crl_parse( mbedtls_x509_crl *chain, const unsigned char *buf, s { #if defined(MBEDTLS_PEM_PARSE_C) int ret; - size_t use_len; + size_t use_len = 0; // Updated by Dener Araújo - 2020-09-06 mbedtls_pem_context pem; int is_pem = 0;