Add support to option "dhcp-option" in ovpn file

This commit is contained in:
Dener Araújo
2020-09-06 15:03:47 -03:00
parent c50ec0a6af
commit 865f56794f
11 changed files with 154 additions and 3 deletions

View File

@@ -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)
{

View File

@@ -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<ServerEntry> serverList;
// Added by Dener Araújo - 2020-09-06
// optional list of "dhcp-option"
std::vector<DhcpOptionEntry> dhcpOptionList;
};
// used to pass credentials to VPN core

View File

@@ -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<DhcpOptionEntry>
{
};
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
};
}

View File

@@ -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<OpenVPNServerEntry *> *servers;
/**
Added by Dener Araújo - 2020-09-06
Optional list of "dhcp-option"
*/
@property (nullable, readonly, nonatomic) NSArray<OpenVPNDhcpOptionEntry *> *dhcpOptions;
- (nonnull instancetype) init NS_UNAVAILABLE;
@end

View File

@@ -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;
}

View File

@@ -0,0 +1,18 @@
//
// OpenVPNDhcpOptionEntry+Internal.h
// Pods
//
// Created by Dener Araújo on 06/09/20.
//
#import "OpenVPNDhcpOptionEntry.h"
#include <ovpnapi.hpp>
using namespace openvpn;
@interface OpenVPNDhcpOptionEntry (Internal)
- (instancetype)initWithDhcpOptionEntry:(ClientAPI::DhcpOptionEntry)entry;
@end

View File

@@ -0,0 +1,17 @@
//
// OpenVPNDhcpOptionEntry.h
// Pods
//
// Created by Dener Araújo on 06/09/20.
//
#import <Foundation/Foundation.h>
@interface OpenVPNDhcpOptionEntry : NSObject
@property (nullable, readonly, nonatomic) NSString *type;
@property (nullable, readonly, nonatomic) NSString *address;
- (nonnull instancetype) init NS_UNAVAILABLE;
@end

View File

@@ -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

View File

@@ -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;

View File

@@ -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]++ )
{

View File

@@ -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;