mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-01-31 00:00:06 +08:00
Add support to option "dhcp-option" in ovpn file
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
17
Sources/OpenVPNAdapter/library/OpenVPNDhcpOptionEntry.h
Normal file
17
Sources/OpenVPNAdapter/library/OpenVPNDhcpOptionEntry.h
Normal 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
|
||||
21
Sources/OpenVPNAdapter/library/OpenVPNDhcpOptionEntry.mm
Normal file
21
Sources/OpenVPNAdapter/library/OpenVPNDhcpOptionEntry.mm
Normal 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
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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]++ )
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user