diff --git a/OpenVPN Adapter.xcodeproj/project.pbxproj b/OpenVPN Adapter.xcodeproj/project.pbxproj index 673b8e2..775f69a 100644 --- a/OpenVPN Adapter.xcodeproj/project.pbxproj +++ b/OpenVPN Adapter.xcodeproj/project.pbxproj @@ -10,8 +10,6 @@ C90BAD311E73FF6C00DEFB32 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C90BAD301E73FF6C00DEFB32 /* SystemConfiguration.framework */; }; C912BB251E7C3339002B9414 /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C912BB241E7C3339002B9414 /* NetworkExtension.framework */; }; C9BB47601E71663A00F3F98C /* Umbrella-Header.h in Headers */ = {isa = PBXBuildFile; fileRef = C9BB475E1E71663A00F3F98C /* Umbrella-Header.h */; settings = {ATTRIBUTES = (Public, ); }; }; - C9BB476C1E716AEE00F3F98C /* ovpncli.hpp in Headers */ = {isa = PBXBuildFile; fileRef = C9BB476A1E716AEE00F3F98C /* ovpncli.hpp */; }; - C9BB476D1E716AEE00F3F98C /* ovpncli.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C9BB476B1E716AEE00F3F98C /* ovpncli.cpp */; }; C9BB47711E7171A100F3F98C /* OpenVPNError.h in Headers */ = {isa = PBXBuildFile; fileRef = C9BB476F1E7171A100F3F98C /* OpenVPNError.h */; settings = {ATTRIBUTES = (Public, ); }; }; C9BB47721E7171A100F3F98C /* OpenVPNEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = C9BB47701E7171A100F3F98C /* OpenVPNEvent.h */; settings = {ATTRIBUTES = (Public, ); }; }; C9BB47751E7171D900F3F98C /* TUNConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = C9BB47731E7171D900F3F98C /* TUNConfiguration.h */; }; @@ -50,8 +48,6 @@ C912BB241E7C3339002B9414 /* NetworkExtension.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NetworkExtension.framework; path = System/Library/Frameworks/NetworkExtension.framework; sourceTree = SDKROOT; }; C9BB475C1E71663A00F3F98C /* OpenVPNAdapter.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = OpenVPNAdapter.framework; sourceTree = BUILT_PRODUCTS_DIR; }; C9BB475E1E71663A00F3F98C /* Umbrella-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Umbrella-Header.h"; sourceTree = ""; }; - C9BB476A1E716AEE00F3F98C /* ovpncli.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = ovpncli.hpp; path = Vendors/openvpn/openvpn/client/ovpncli.hpp; sourceTree = ""; }; - C9BB476B1E716AEE00F3F98C /* ovpncli.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ovpncli.cpp; path = Vendors/openvpn/openvpn/client/ovpncli.cpp; sourceTree = ""; }; C9BB476F1E7171A100F3F98C /* OpenVPNError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = OpenVPNError.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; C9BB47701E7171A100F3F98C /* OpenVPNEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OpenVPNEvent.h; sourceTree = ""; }; C9BB47731E7171D900F3F98C /* TUNConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TUNConfiguration.h; sourceTree = ""; }; @@ -186,8 +182,6 @@ C9BB47691E716AC500F3F98C /* OpenVPN */ = { isa = PBXGroup; children = ( - C9BB476A1E716AEE00F3F98C /* ovpncli.hpp */, - C9BB476B1E716AEE00F3F98C /* ovpncli.cpp */, ); name = OpenVPN; sourceTree = ""; @@ -251,7 +245,6 @@ files = ( C9BB47791E7171ED00F3F98C /* OpenVPNClient.h in Headers */, C9BB47721E7171A100F3F98C /* OpenVPNEvent.h in Headers */, - C9BB476C1E716AEE00F3F98C /* ovpncli.hpp in Headers */, C9BB477F1E7173C700F3F98C /* OpenVPNAdapter.h in Headers */, C9BB47601E71663A00F3F98C /* Umbrella-Header.h in Headers */, C9BB47811E7173C700F3F98C /* OpenVPNAdapter+Public.h in Headers */, @@ -383,7 +376,6 @@ C9BB47821E7173C700F3F98C /* OpenVPNAdapter.mm in Sources */, C9BB477A1E7171ED00F3F98C /* OpenVPNClient.mm in Sources */, C9BB47761E7171D900F3F98C /* TUNConfiguration.m in Sources */, - C9BB476D1E716AEE00F3F98C /* ovpncli.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/addrlist.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/addrlist.hpp deleted file mode 100644 index 4479876..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/addrlist.hpp +++ /dev/null @@ -1,65 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_ADDR_ADDRLIST_H -#define OPENVPN_ADDR_ADDRLIST_H - -#include -#include - -namespace openvpn { - namespace IP { - - // A list of unique IP addresses - class AddrList : public std::vector, public RC - { - public: - typedef RCPtr Ptr; - - void add(const IP::Addr& a) - { - if (!exists(a)) - push_back(a); - } - - bool exists(const IP::Addr& a) const - { - for (const_iterator i = begin(); i != end(); ++i) - { - if (a == *i) - return true; - } - return false; - } - -#if 0 - void dump() const - { - OPENVPN_LOG("******* AddrList::dump"); - for (const_iterator i = begin(); i != end(); ++i) - OPENVPN_LOG(i->to_string()); - } -#endif - }; - } -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/addrpair.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/addrpair.hpp deleted file mode 100644 index c380b8a..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/addrpair.hpp +++ /dev/null @@ -1,218 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_ADDR_ADDRPAIR_H -#define OPENVPN_ADDR_ADDRPAIR_H - -#include - -#include -#include -#include -#include - -namespace openvpn { - namespace IP { - - // AddrMaskPair is basically an object that combines an IP address (v4 or v6) - // with a netmask or prefix length. - struct AddrMaskPair - { - public: - OPENVPN_EXCEPTION(addr_pair_mask_parse_error); - - class StringPair { - public: - OPENVPN_SIMPLE_EXCEPTION(addr_pair_string_error); - - StringPair() - : size_(0) - { - } - - explicit StringPair(const std::string& s1) - : size_(1) - { - data[0] = s1; - } - - explicit StringPair(const std::string& s1, const std::string& s2) - : size_(2) - { - data[0] = s1; - data[1] = s2; - } - - void push_back(const std::string& s) - { - if (size_ < 2) - data[size_++] = s; - else - throw addr_pair_string_error(); - } - - const std::string& operator[](const size_t i) const - { - if (i >= 2) - throw addr_pair_string_error(); - return data[i]; - } - - std::string& operator[](const size_t i) - { - if (i >= 2) - throw addr_pair_string_error(); - return data[i]; - } - - size_t size() const { return size_; } - - std::string render() const - { - switch (size_) - { - case 1: - return data[0]; - case 2: - return data[0] + "/" + data[1]; - default: - return ""; - } - } - - private: - std::string data[2]; - unsigned int size_; - }; - - static AddrMaskPair from_string(const std::string& s1, const std::string& s2, const char *title = nullptr) - { - try { - if (s2.empty()) - { - const StringPair pair = Split::by_char(s1, '/'); - return from_string_impl(pair, title); - } - else - { - const StringPair pair(s1, s2); - return from_string_impl(pair, title); - } - } - catch (const std::exception& e) - { - const StringPair pair(s1, s2); - error(e, pair.render(), title); - } - return AddrMaskPair(); // NOTREACHED - } - - static AddrMaskPair from_string(const std::string& s, const char *title = nullptr) - { - try { - const StringPair pair = Split::by_char(s, '/'); - return from_string_impl(pair, title); - } - catch (const std::exception& e) - { - error(e, s, title); - } - return AddrMaskPair(); // NOTREACHED - } - - static AddrMaskPair from_string(const StringPair& pair, const char *title = nullptr) - { - try { - return from_string_impl(pair, title); - } - catch (const std::exception& e) - { - error(e, pair.render(), title); - } - return AddrMaskPair(); // NOTREACHED - } - - std::string to_string(const bool netmask_form=false) const - { - std::ostringstream os; - if (netmask_form) - os << addr.to_string() << '/' << netmask.to_string(); - else - os << addr.to_string() << '/' << netmask.prefix_len(); - return os.str(); - } - - bool is_canonical() const - { - return (addr & netmask) == addr; - } - - Addr::Version version() const - { - const Addr::Version v1 = addr.version(); - const Addr::Version v2 = netmask.version(); - if (v1 == v2) - return v1; - else - return Addr::UNSPEC; - } - - Addr addr; - Addr netmask; - - private: - static void error(const std::exception& e, const std::string& s, const char *title) - { - if (!title) - title = ""; - OPENVPN_THROW(addr_pair_mask_parse_error, "AddrMaskPair parse error '" << title << "': " << s << " : " << e.what()); - } - - static AddrMaskPair from_string_impl(const StringPair& pair, const char *title = nullptr) - { - AddrMaskPair ret; - if (pair.size() == 1 || pair.size() == 2) - { - ret.addr = Addr::from_string(pair[0], title); - if (pair.size() == 2 && !pair[1].empty()) - { - if (is_number(pair[1].c_str())) - ret.netmask = Addr::netmask_from_prefix_len(ret.addr.version(), - parse_number_throw(pair[1], "prefix length")); - else - ret.netmask = Addr::from_string(pair[1]); - ret.netmask.prefix_len(); // verify that netmask is ok - } - else - ret.netmask = Addr::from_zero_complement(ret.addr.version()); - ret.addr.verify_version_consistency(ret.netmask); - } - else - throw addr_pair_mask_parse_error("only one or two address terms allowed"); - return ret; - } - - }; - OPENVPN_OSTREAM(AddrMaskPair, to_string) - } -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/ip.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/ip.hpp deleted file mode 100644 index 90c432f..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/ip.hpp +++ /dev/null @@ -1,895 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_ADDR_IP_H -#define OPENVPN_ADDR_IP_H - -#include -#include // for std::memset - -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace openvpn { - // This is our fundamental IP address class that handles IPv4 or IPv6 - // IP addresses. It is implemented as a discriminated union of IPv4::Addr - // and IPv6::Addr. - namespace IP { - - OPENVPN_EXCEPTION(ip_exception); - - class Addr - { - public: - enum Version { UNSPEC, V4, V6 }; - - enum { V4_MASK=(1<<0), V6_MASK=(1<<1) }; - typedef unsigned int VersionMask; - - enum VersionSize { - V4_SIZE = IPv4::Addr::SIZE, - V6_SIZE = IPv6::Addr::SIZE, - }; - - Addr(const Addr& other, const char *title = nullptr, Version required_version = UNSPEC) - : ver(other.ver) - { - other.validate_version(title, required_version); - switch (ver) - { - case V4: - u.v4 = other.u.v4; - break; - case V6: - u.v6 = other.u.v6; - break; - default: - break; - } - } - - Addr(const std::string& ipstr, const char *title = nullptr, Version required_version = UNSPEC) - : Addr(from_string(ipstr, title, required_version)) - { - } - - Addr(const std::string& ipstr, const std::string& title, Version required_version = UNSPEC) - : Addr(from_string(ipstr, title.c_str(), required_version)) - { - } - - void validate_version(const char *title, Version required_version) const - { - if (required_version != UNSPEC && required_version != ver) - throw ip_exception(internal::format_error(to_string(), title, version_string_static(required_version), "wrong IP version")); - } - - void validate_version(const std::string& title, Version required_version) const - { - validate_version(title.c_str(), required_version); - } - - static std::string validate(const std::string& ipstr, const char *title = nullptr, Version required_version = UNSPEC) - { - Addr a = from_string(ipstr, title, required_version); - return a.to_string(); - } - - static std::string validate(const std::string& ipstr, const std::string& title, Version required_version = UNSPEC) - { - return validate(ipstr, title.c_str(), required_version); - } - - static bool is_valid(const std::string& ipstr) - { - // fast path -- rule out validity if invalid chars - for (size_t i = 0; i < ipstr.length(); ++i) - { - const char c = ipstr[i]; - if (!((c >= '0' && c <= '9') - || (c >= 'a' && c <= 'f') - || (c >= 'A' && c <= 'F') - || (c == '.' || c == ':' || c == '%'))) - return false; - } - - // slow path - { - asio::error_code ec; - asio::ip::make_address(ipstr, ec); - return !ec; - } - } - - static Addr from_string(const std::string& ipstr, const char *title = nullptr, Version required_version = UNSPEC) - { - asio::error_code ec; - asio::ip::address a = asio::ip::make_address(ipstr, ec); - if (ec) - throw ip_exception(internal::format_error(ipstr, title, "", ec)); - const Addr ret = from_asio(a); - if (required_version != UNSPEC && required_version != ret.ver) - throw ip_exception(internal::format_error(ipstr, title, version_string_static(required_version), "wrong IP version")); - return ret; - } - - static Addr from_hex(Version v, const std::string& s) - { - if (v == V4) - return from_ipv4(IPv4::Addr::from_hex(s)); - else if (v == V6) - return from_ipv6(IPv6::Addr::from_hex(s)); - else - throw ip_exception("address unspecified"); - } - - static Addr from_ipv4(const IPv4::Addr& addr) - { - Addr a; - a.ver = V4; - a.u.v4 = addr; - return a; - } - - static Addr from_ipv6(const IPv6::Addr& addr) - { - Addr a; - a.ver = V6; - a.u.v6 = addr; - return a; - } - - const IPv4::Addr& to_ipv4() const - { - if (ver == V4) - return u.v4; - else - throw ip_exception("address is not IPv4"); - } - - const IPv6::Addr& to_ipv6() const - { - if (ver == V6) - return u.v6; - else - throw ip_exception("address is not IPv6"); - } - - const IPv4::Addr& to_ipv4_nocheck() const - { - return u.v4; - } - - const IPv6::Addr& to_ipv6_nocheck() const - { - return u.v6; - } - - static Addr from_sockaddr(const struct sockaddr *sa) - { - if (sa->sa_family == AF_INET) - return from_ipv4(IPv4::Addr::from_sockaddr((struct sockaddr_in *)sa)); - else if (sa->sa_family == AF_INET6) - return from_ipv6(IPv6::Addr::from_sockaddr((struct sockaddr_in6 *)sa)); - else - return Addr(); - } - - static bool sockaddr_defined(const struct sockaddr *sa) - { - return sa && (sa->sa_family == AF_INET || sa->sa_family == AF_INET6); - } - - static Addr from_ulong(Version v, unsigned long ul) - { - if (v == V4) - return from_ipv4(IPv4::Addr::from_ulong(ul)); - else if (v == V6) - return from_ipv6(IPv6::Addr::from_ulong(ul)); - else - throw ip_exception("address unspecified"); - } - - // return *this as a ulong, will raise exception on overflow - unsigned long to_ulong() const - { - if (ver == V4) - return u.v4.to_ulong(); - else if (ver == V6) - return u.v6.to_ulong(); - else - throw ip_exception("address unspecified"); - } - - static Addr from_long(Version v, long ul) - { - if (v == V4) - return from_ipv4(IPv4::Addr::from_long(ul)); - else if (v == V6) - return from_ipv6(IPv6::Addr::from_long(ul)); - else - throw ip_exception("address unspecified"); - } - - // return *this as a long, will raise exception on overflow - long to_long() const - { - if (ver == V4) - return u.v4.to_long(); - else if (ver == V6) - return u.v6.to_long(); - else - throw ip_exception("address unspecified"); - } - - // return Addr from 16 byte binary string - static Addr from_byte_string(const unsigned char *bytestr) - { - Addr a; - if (IPv6::Addr::byte_string_is_v4(bytestr)) - { - a.ver = V4; - a.u.v4 = IPv4::Addr::from_uint32_net(IPv6::Addr::v4_from_byte_string(bytestr)); - } - else - { - a.ver = V4; - a.u.v6 = IPv6::Addr::from_byte_string(bytestr); - } - return a; - } - - // convert Addr to 16 byte binary string - void to_byte_string(unsigned char *bytestr) const - { - if (ver == V4) - IPv6::Addr::v4_to_byte_string(bytestr, u.v4.to_uint32_net()); - else if (ver == V6) - u.v6.to_byte_string(bytestr); - else - std::memset(bytestr, 0, 16); - } - - std::uint32_t to_uint32_net() const // return value in net byte order - { - if (ver == V4) - return u.v4.to_uint32_net(); - else - return 0; - } - - // construct an address where all bits are zero - static Addr from_zero(Version v) - { - if (v == V4) - return from_ipv4(IPv4::Addr::from_zero()); - else if (v == V6) - return from_ipv6(IPv6::Addr::from_zero()); - else - throw ip_exception("address unspecified"); - } - - // construct an address where all bits are zero - static Addr from_one(Version v) - { - if (v == V4) - return from_ipv4(IPv4::Addr::from_one()); - else if (v == V6) - return from_ipv6(IPv6::Addr::from_one()); - else - throw ip_exception("address unspecified"); - } - - // construct an address where all bits are one - static Addr from_zero_complement(Version v) - { - if (v == V4) - return from_ipv4(IPv4::Addr::from_zero_complement()); - else if (v == V6) - return from_ipv6(IPv6::Addr::from_zero_complement()); - else - throw ip_exception("address unspecified"); - } - - // build a netmask using given prefix_len - static Addr netmask_from_prefix_len(Version v, const unsigned int prefix_len) - { - if (v == V4) - return from_ipv4(IPv4::Addr::netmask_from_prefix_len(prefix_len)); - else if (v == V6) - return from_ipv6(IPv6::Addr::netmask_from_prefix_len(prefix_len)); - else - throw ip_exception("address unspecified"); - } - - // build a netmask using *this as extent - Addr netmask_from_extent() const - { - if (ver == V4) - return from_ipv4(u.v4.netmask_from_extent()); - else if (ver == V6) - return from_ipv6(u.v6.netmask_from_extent()); - else - throw ip_exception("address unspecified"); - } - - std::string to_string() const - { - if (ver != UNSPEC) - { - const asio::ip::address a = to_asio(); - std::string ret = a.to_string(); - return ret; - } - else - return "UNSPEC"; - } - - std::string to_string_bracket_ipv6() const - { - std::string ret; - if (ver == V6) - ret += '['; - ret += to_string(); - if (ver == V6) - ret += ']'; - return ret; - } - - std::string to_hex() const - { - if (ver == V4) - return u.v4.to_hex(); - else if (ver == V6) - return u.v6.to_hex(); - else - throw ip_exception("address unspecified"); - } - - std::string arpa() const - { - if (ver == V4) - return u.v4.arpa(); - else if (ver == V6) - return u.v6.arpa(); - else - throw ip_exception("address unspecified"); - } - - static Addr from_asio(const asio::ip::address& addr) - { - if (addr.is_v4()) - { - Addr a; - a.ver = V4; - a.u.v4 = IPv4::Addr::from_asio(addr.to_v4()); - return a; - } - else if (addr.is_v6()) - { - Addr a; - a.ver = V6; - a.u.v6 = IPv6::Addr::from_asio(addr.to_v6()); - return a; - } - else - throw ip_exception("address unspecified"); - } - - asio::ip::address to_asio() const - { - switch (ver) - { - case V4: - return asio::ip::address_v4(u.v4.to_asio()); - case V6: - return asio::ip::address_v6(u.v6.to_asio()); - default: - throw ip_exception("address unspecified"); - } - } - - Addr operator+(const long delta) const { - switch (ver) - { - case V4: - { - Addr ret; - ret.ver = V4; - ret.u.v4 = u.v4 + delta; - return ret; - } - case V6: - { - Addr ret; - ret.ver = V6; - ret.u.v6 = u.v6 + delta; - return ret; - } - default: - throw ip_exception("address unspecified"); - } - } - - Addr operator-(const long delta) const { - return operator+(-delta); - } - -#define OPENVPN_IP_OPERATOR_BINOP(OP) \ - Addr operator OP (const Addr& other) const { \ - if (ver != other.ver) \ - throw ip_exception("version inconsistency"); \ - switch (ver) \ - { \ - case V4: \ - { \ - Addr ret; \ - ret.ver = V4; \ - ret.u.v4 = u.v4 OP other.u.v4; \ - return ret; \ - } \ - case V6: \ - { \ - Addr ret; \ - ret.ver = V6; \ - ret.u.v6 = u.v6 OP other.u.v6; \ - return ret; \ - } \ - default: \ - throw ip_exception("address unspecified"); \ - } \ - } - - OPENVPN_IP_OPERATOR_BINOP(+) - OPENVPN_IP_OPERATOR_BINOP(-) - OPENVPN_IP_OPERATOR_BINOP(*) - OPENVPN_IP_OPERATOR_BINOP(/) - OPENVPN_IP_OPERATOR_BINOP(%) - OPENVPN_IP_OPERATOR_BINOP(&) - OPENVPN_IP_OPERATOR_BINOP(|) - -#undef OPENVPN_IP_OPERATOR_BINOP - - Addr operator<<(const unsigned int shift) const { - switch (ver) - { - case V4: - { - Addr ret; - ret.ver = V4; - ret.u.v4 = u.v4 << shift; - return ret; - } - case V6: - { - Addr ret; - ret.ver = V6; - ret.u.v6 = u.v6 << shift; - return ret; - } - default: - throw ip_exception("address unspecified"); - } - } - - Addr operator>>(const unsigned int shift) const { - switch (ver) - { - case V4: - { - Addr ret; - ret.ver = V4; - ret.u.v4 = u.v4 >> shift; - return ret; - } - case V6: - { - Addr ret; - ret.ver = V6; - ret.u.v6 = u.v6 >> shift; - return ret; - } - default: - throw ip_exception("address unspecified"); - } - } - - Addr operator~() const { - switch (ver) - { - case V4: - { - Addr ret; - ret.ver = V4; - ret.u.v4 = ~u.v4; - return ret; - } - case V6: - { - Addr ret; - ret.ver = V6; - ret.u.v6 = ~u.v6; - return ret; - } - default: - throw ip_exception("address unspecified"); - } - } - - Addr network_addr(const unsigned int prefix_len) const { - switch (ver) - { - case V4: - { - Addr ret; - ret.ver = V4; - ret.u.v4 = u.v4.network_addr(prefix_len); - return ret; - } - case V6: - { - Addr ret; - ret.ver = V6; - ret.u.v6 = u.v6.network_addr(prefix_len); - return ret; - } - default: - throw ip_exception("address unspecified"); - } - } - - bool operator==(const Addr& other) const - { - switch (ver) - { - case UNSPEC: - return other.ver == UNSPEC; - case V4: - if (ver == other.ver) - return u.v4 == other.u.v4; - break; - case V6: - if (ver == other.ver) - return u.v6 == other.u.v6; - break; - } - return false; - } - - bool operator!=(const Addr& other) const - { - return !operator==(other); - } - -#define OPENVPN_IP_OPERATOR_REL(OP) \ - bool operator OP(const Addr& other) const \ - { \ - if (ver == other.ver) \ - { \ - switch (ver) \ - { \ - case V4: \ - return u.v4 OP other.u.v4; \ - case V6: \ - return u.v6 OP other.u.v6; \ - default: \ - return false; \ - } \ - } \ - else if (ver OP other.ver) \ - return true; \ - else \ - return false; \ - } - - OPENVPN_IP_OPERATOR_REL(<) - OPENVPN_IP_OPERATOR_REL(>) - OPENVPN_IP_OPERATOR_REL(<=) - OPENVPN_IP_OPERATOR_REL(>=) - -#undef OPENVPN_IP_OPERATOR_REL - - bool unspecified() const - { - return all_zeros(); - } - - bool specified() const - { - return !unspecified(); - } - - bool all_zeros() const - { - switch (ver) - { - case V4: - return u.v4.all_zeros(); - case V6: - return u.v6.all_zeros(); - default: - return true; - } - } - - bool all_ones() const - { - switch (ver) - { - case V4: - return u.v4.all_ones(); - case V6: - return u.v6.all_ones(); - default: - return false; - } - } - - bool defined() const - { - return ver != UNSPEC; - } - - const char *version_string() const - { - return version_string_static(ver); - } - - static const char *version_string_static(Version ver) - { - switch (ver) - { - case V4: - return "v4"; - case V6: - return "v6"; - default: - return "v?"; - } - } - - Version version() const { return ver; } - - static VersionMask version_mask(const Version ver) - { - switch (ver) - { - case V4: - return V4_MASK; - case V6: - return V6_MASK; - default: - return 0; - } - } - - VersionMask version_mask() const - { - return version_mask(ver); - } - - bool is_compatible(const Addr& other) const - { - return ver == other.ver; - } - - void verify_version_consistency(const Addr& other) const - { - if (!is_compatible(other)) - throw ip_exception("version inconsistency"); - } - - // throw exception if address is not a valid netmask - void validate_netmask() - { - prefix_len(); - } - - // number of network bits in netmask, - // throws exception if addr is not a netmask - unsigned int prefix_len() const - { - switch (ver) - { - case V4: - return u.v4.prefix_len(); - case V6: - return u.v6.prefix_len(); - default: - throw ip_exception("address unspecified"); - } - } - - // IPv6 scope ID or -1 if not IPv6 - int scope_id() const - { - return ver == V6 ? u.v6.scope_id() : -1; - } - - // number of host bits in netmask - unsigned int host_len() const - { - switch (ver) - { - case V4: - return u.v4.host_len(); - case V6: - return u.v6.host_len(); - default: - throw ip_exception("address unspecified"); - } - } - - // return the number of host addresses contained within netmask - Addr extent_from_netmask() const - { - switch (ver) - { - case V4: - return from_ipv4(u.v4.extent_from_netmask()); - case V6: - return from_ipv6(u.v6.extent_from_netmask()); - default: - throw ip_exception("address unspecified"); - } - } - - // address size in bits - unsigned int size() const - { - return version_size(ver); - } - - // address size in bits of particular IP version - static unsigned int version_size(Version v) - { - if (v == V4) - return IPv4::Addr::SIZE; - else if (v == V6) - return IPv6::Addr::SIZE; - else - return 0; - } - - std::size_t hashval() const - { - std::size_t seed = 0; - switch (ver) - { - case Addr::V4: - Hash::combine(seed, 4, u.v4); - break; - case Addr::V6: - Hash::combine(seed, 6, u.v6); - break; - default: - break; - } - return seed; - } - -#ifdef OPENVPN_IP_IMMUTABLE - private: -#endif - - Addr() - : ver(UNSPEC) - { - } - - void reset() - { - ver = UNSPEC; - } - - Addr& operator=(const Addr& other) - { - switch (ver = other.ver) - { - case V4: - u.v4 = other.u.v4; - break; - case V6: - u.v6 = other.u.v6; - break; - default: - break; - } - return *this; - } - - Addr& operator++() - { - switch (ver) - { - case V4: - ++u.v4; - break; - case V6: - ++u.v6; - break; - default: - break; - } - return *this; - } - - Addr& operator+=(const long delta) - { - switch (ver) - { - case V4: - u.v4 += delta; - break; - case V6: - u.v6 += delta; - break; - default: - break; - } - return *this; - } - - Addr& operator-=(const long delta) - { - switch (ver) - { - case V4: - u.v4 -= delta; - break; - case V6: - u.v6 -= delta; - break; - default: - break; - } - return *this; - } - - void reset_ipv4_from_uint32(const IPv4::Addr::base_type addr) - { - ver = V4; - u.v4 = IPv4::Addr::from_uint32(addr); - } - - private: - union { - IPv4::Addr v4; - IPv6::Addr v6; - } u; - - Version ver; - }; - - OPENVPN_OSTREAM(Addr, to_string) - } -} - -OPENVPN_HASH_METHOD(openvpn::IP::Addr, hashval); - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/iperr.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/iperr.hpp deleted file mode 100644 index bd7c403..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/iperr.hpp +++ /dev/null @@ -1,75 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_ADDR_IPERR_H -#define OPENVPN_ADDR_IPERR_H - -#include - -#include - -namespace openvpn { - namespace IP { - namespace internal { - // Called internally by IP, IPv4, and IPv6 classes - - inline std::string format_error(const std::string& ipstr, const char *title, const char *ipver, const asio::error_code& ec) - { - std::string err = "error parsing"; - if (title) - { - err += ' '; - err += title; - } - err += " IP"; - err += ipver; - err += " address '"; - err += ipstr; - err += "' : "; - err += ec.message(); - return err; - } - - inline std::string format_error(const std::string& ipstr, const char *title, const char *ipver, const char *message) - { - std::string err = "error parsing"; - if (title) - { - err += ' '; - err += title; - } - err += " IP"; - err += ipver; - err += " address '"; - err += ipstr; - err += '\''; - if (message) - { - err += " : "; - err += message; - } - return err; - } - } - } -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/ipv4.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/ipv4.hpp deleted file mode 100644 index c647415..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/ipv4.hpp +++ /dev/null @@ -1,561 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_ADDR_IPV4_H -#define OPENVPN_ADDR_IPV4_H - -#include // for std::memcpy, std::memset -#include -#include // for std::uint32_t - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace openvpn { - namespace IP { - class Addr; - } - - // Fundamental classes for representing an IPv4 IP address. - - namespace IPv4 { - - OPENVPN_EXCEPTION(ipv4_exception); - - class Addr // NOTE: must be union-legal, so default constructor does not initialize - { - friend class IP::Addr; - - public: - enum { SIZE=32 }; - - typedef std::uint32_t base_type; - typedef std::int32_t signed_base_type; - - static Addr from_addr(const Addr& addr) - { - return addr; - } - - static Addr from_in_addr(const struct in_addr *in4) - { - Addr ret; - ret.u.addr = ntohl(in4->s_addr); - return ret; - } - - struct in_addr to_in_addr() const - { - struct in_addr ret; - ret.s_addr = htonl(u.addr); - return ret; - } - - static Addr from_sockaddr(const struct sockaddr_in *sa) - { - Addr ret; - ret.u.addr = ntohl(sa->sin_addr.s_addr); - return ret; - } - - struct sockaddr_in to_sockaddr() const - { - struct sockaddr_in ret; - std::memset(&ret, 0, sizeof(ret)); - ret.sin_family = AF_INET; - ret.sin_port = 0; - ret.sin_addr.s_addr = htonl(u.addr);; - return ret; - } - - static Addr from_uint32(const base_type addr) // host byte order - { - Addr ret; - ret.u.addr = addr; - return ret; - } - - std::uint32_t to_uint32() const // host byte order - { - return u.addr; - } - - static Addr from_uint32_net(const base_type addr) // addr in net byte order - { - Addr ret; - ret.u.addr = ntohl(addr); - return ret; - } - - std::uint32_t to_uint32_net() const // return value in net byte order - { - return htonl(u.addr); - } - - static Addr from_ulong(unsigned long ul) - { - Addr ret; - ret.u.addr = (base_type)ul; - return ret; - } - - // return *this as a unsigned long - unsigned long to_ulong() const - { - return (unsigned long)u.addr; - } - - static Addr from_long(long ul) - { - Addr ret; - ret.u.addr = (base_type)(signed_base_type)ul; - return ret; - } - - // return *this as a long - long to_long() const - { - return (long)(signed_base_type)u.addr; - } - - static Addr from_bytes(const unsigned char *bytes) // host byte order - { - Addr ret; - std::memcpy(ret.u.bytes, bytes, 4); - return ret; - } - - static Addr from_bytes_net(const unsigned char *bytes) // network byte order - { - Addr ret; - std::memcpy(ret.u.bytes, bytes, 4); - ret.u.addr = ntohl(ret.u.addr); - return ret; - } - - static Addr from_zero() - { - Addr ret; - ret.zero(); - return ret; - } - - static Addr from_one() - { - Addr ret; - ret.one(); - return ret; - } - - static Addr from_zero_complement() - { - Addr ret; - ret.zero_complement(); - return ret; - } - - // build a netmask using given prefix_len - static Addr netmask_from_prefix_len(const unsigned int prefix_len) - { - Addr ret; - ret.u.addr = prefix_len_to_netmask(prefix_len); - return ret; - } - - // build a netmask using given extent - Addr netmask_from_extent() const - { - const int lb = find_last_set(u.addr - 1); - return netmask_from_prefix_len(SIZE - lb); - } - - static Addr from_string(const std::string& ipstr, const char *title = nullptr) - { - asio::error_code ec; - asio::ip::address_v4 a = asio::ip::make_address_v4(ipstr, ec); - if (ec) - throw ipv4_exception(IP::internal::format_error(ipstr, title, "v4", ec)); - return from_asio(a); - } - - std::string to_string() const - { - const asio::ip::address_v4 a = to_asio(); - std::string ret = a.to_string(); - return ret; - } - - static Addr from_hex(const std::string& s) - { - Addr ret; - ret.u.addr = 0; - size_t len = s.length(); - size_t base = 0; - if (len > 0 && s[len-1] == 'L') - len -= 1; - if (len >= 2 && s[0] == '0' && s[1] == 'x') - { - base = 2; - len -= 2; - } - if (len < 1 || len > 8) - throw ipv4_exception("parse hex error"); - size_t di = (len-1)>>1; - for (int i = (len & 1) ? -1 : 0; i < int(len); i += 2) - { - const size_t idx = base + i; - const int bh = (i >= 0) ? parse_hex_char(s[idx]) : 0; - const int bl = parse_hex_char(s[idx+1]); - if (bh == -1 || bl == -1) - throw ipv4_exception("parse hex error"); - ret.u.bytes[Endian::e4(di--)] = (bh<<4) + bl; - } - return ret; - } - - std::string to_hex() const - { - std::string ret; - ret.reserve(8); - bool firstnonzero = false; - for (size_t i = 0; i < 4; ++i) - { - const unsigned char b = u.bytes[Endian::e4rev(i)]; - if (b || firstnonzero || i == 3) - { - const char bh = b >> 4; - if (bh || firstnonzero) - ret += render_hex_char(bh); - ret += render_hex_char(b & 0x0F); - firstnonzero = true; - } - } - return ret; - } - - std::string arpa() const - { - std::ostringstream os; - os << int(u.bytes[Endian::e4(0)]) << '.' - << int(u.bytes[Endian::e4(1)]) << '.' - << int(u.bytes[Endian::e4(2)]) << '.' - << int(u.bytes[Endian::e4(3)]) << ".in-addr.arpa"; - return os.str(); - } - - static Addr from_asio(const asio::ip::address_v4& asio_addr) - { - Addr ret; - ret.u.addr = (std::uint32_t)asio_addr.to_uint(); - return ret; - } - - asio::ip::address_v4 to_asio() const - { - return asio::ip::address_v4(u.addr); - } - - Addr operator&(const Addr& other) const { - Addr ret; - ret.u.addr = u.addr & other.u.addr; - return ret; - } - - Addr operator|(const Addr& other) const { - Addr ret; - ret.u.addr = u.addr | other.u.addr; - return ret; - } - - Addr operator+(const long delta) const { - Addr ret; - ret.u.addr = u.addr + (std::uint32_t)delta; - return ret; - } - - Addr operator+(const Addr& other) const { - Addr ret; - ret.u.addr = u.addr + other.u.addr; - return ret; - } - - Addr operator-(const long delta) const { - return operator+(-delta); - } - - Addr operator-(const Addr& other) const { - Addr ret; - ret.u.addr = u.addr - other.u.addr; - return ret; - } - - Addr operator*(const Addr& other) const { - Addr ret; - ret.u.addr = u.addr * other.u.addr; - return ret; - } - - Addr operator/(const Addr& other) const { - Addr ret; - ret.u.addr = u.addr / other.u.addr; - return ret; - } - - Addr operator%(const Addr& other) const { - Addr ret; - ret.u.addr = u.addr % other.u.addr; - return ret; - } - - Addr operator<<(const unsigned int shift) const { - Addr ret; - ret.u.addr = u.addr << shift; - return ret; - } - - Addr operator>>(const unsigned int shift) const { - Addr ret; - ret.u.addr = u.addr >> shift; - return ret; - } - - Addr operator~() const { - Addr ret; - ret.u.addr = ~u.addr; - return ret; - } - - // return the network that contains the current address - Addr network_addr(const unsigned int prefix_len) const - { - Addr ret; - ret.u.addr = u.addr & prefix_len_to_netmask(prefix_len); - return ret; - } - - bool operator==(const Addr& other) const - { - return u.addr == other.u.addr; - } - - bool operator!=(const Addr& other) const - { - return u.addr != other.u.addr; - } - - bool operator<(const Addr& other) const - { - return u.addr < other.u.addr; - } - - bool operator>(const Addr& other) const - { - return u.addr > other.u.addr; - } - - bool operator<=(const Addr& other) const - { - return u.addr <= other.u.addr; - } - - bool operator>=(const Addr& other) const - { - return u.addr >= other.u.addr; - } - - bool unspecified() const - { - return all_zeros(); - } - - bool specified() const - { - return !unspecified(); - } - - bool all_zeros() const - { - return u.addr == 0; - } - - bool all_ones() const - { - return ~u.addr == 0; - } - - // number of network bits in netmask, - // throws exception if addr is not a netmask - unsigned int prefix_len() const - { - const int ret = prefix_len_32(u.addr); - if (ret >= 0) - return ret; - else - throw ipv4_exception("malformed netmask"); - } - - int prefix_len_nothrow() const - { - return prefix_len_32(u.addr); - } - - // number of host bits in netmask - unsigned int host_len() const - { - return SIZE - prefix_len(); - } - - // return the number of host addresses contained within netmask - Addr extent_from_netmask() const - { - Addr ret; - ret.u.addr = extent_from_netmask_uint32(); - return ret; - } - - std::uint32_t extent_from_netmask_uint32() const - { - const unsigned int hl = host_len(); - if (hl < SIZE) - return 1 << hl; - else if (hl == SIZE) - return 0; - else - throw ipv4_exception("extent overflow"); - } - - // convert netmask in addr to prefix_len, will return -1 on error - static int prefix_len_32(const std::uint32_t addr) - { - if (addr == ~std::uint32_t(0)) - return 32; - else if (addr == 0) - return 0; - else - { - unsigned int high = 32; - unsigned int low = 1; - for (unsigned int i = 0; i < 5; ++i) - { - const unsigned int mid = (high + low) / 2; - const IPv4::Addr::base_type test = prefix_len_to_netmask_unchecked(mid); - if (addr == test) - return mid; - else if (addr > test) - low = mid; - else - high = mid; - } - return -1; - } - } - - // address size in bits - static unsigned int size() - { - return SIZE; - } - - std::size_t hashval() const - { - return Hash::value(u.addr); - } - -#ifdef OPENVPN_IP_IMMUTABLE - private: -#endif - - void negate() - { - u.addr = ~u.addr; - } - - void zero() - { - u.addr = 0; - } - - void zero_complement() - { - u.addr = ~0; - } - - void one() - { - u.addr = 1; - } - - Addr& operator++() - { - ++u.addr; - return *this; - } - - Addr& operator+=(const long delta) - { - u.addr += (std::uint32_t)delta; - return *this; - } - - Addr& operator-=(const long delta) - { - return operator+=(-delta); - } - - private: - static base_type prefix_len_to_netmask_unchecked(const unsigned int prefix_len) - { - if (prefix_len) - return ~((1 << (SIZE - prefix_len)) - 1); - else - return 0; - } - - static base_type prefix_len_to_netmask(const unsigned int prefix_len) - { - if (prefix_len <= SIZE) - return prefix_len_to_netmask_unchecked(prefix_len); - else - throw ipv4_exception("bad prefix len"); - } - - union { - base_type addr; // host byte order - unsigned char bytes[4]; - } u; - }; - - OPENVPN_OSTREAM(Addr, to_string) - } -} - -OPENVPN_HASH_METHOD(openvpn::IPv4::Addr, hashval); - -#endif // OPENVPN_ADDR_IPV4_H diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/ipv6.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/ipv6.hpp deleted file mode 100644 index f29a8cd..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/ipv6.hpp +++ /dev/null @@ -1,825 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_ADDR_IPV6_H -#define OPENVPN_ADDR_IPV6_H - -#include // for std::memcpy, std::memset -#include // for std::min -#include // for std::uint32_t - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace openvpn { - namespace IP { - class Addr; - } - - // Fundamental classes for representing an IPv6 IP address. - - namespace IPv6 { - - OPENVPN_EXCEPTION(ipv6_exception); - - class Addr // NOTE: must be union-legal, so default constructor does not initialize - { - friend class IP::Addr; - - public: - enum { SIZE=128 }; - - static Addr from_addr(const Addr& addr) - { - return addr; - } - - static Addr from_in6_addr(const struct in6_addr *in6) - { - Addr ret; - network_to_host_order(&ret.u, (const union ipv6addr *)in6->s6_addr); - ret.scope_id_ = 0; - return ret; - } - - struct in6_addr to_in6_addr() const - { - struct in6_addr ret; - host_to_network_order((union ipv6addr *)&ret, &u); - return ret; - } - - static Addr from_sockaddr(const struct sockaddr_in6 *sa) - { - Addr ret; - network_to_host_order(&ret.u, (const union ipv6addr *)sa->sin6_addr.s6_addr); - ret.scope_id_ = sa->sin6_scope_id; - return ret; - } - - struct sockaddr_in6 to_sockaddr() const - { - struct sockaddr_in6 ret; - std::memset(&ret, 0, sizeof(ret)); - ret.sin6_family = AF_INET6; - ret.sin6_port = 0; - host_to_network_order((union ipv6addr *)&ret.sin6_addr.s6_addr, &u); - ret.sin6_scope_id = scope_id_; - return ret; - } - - static Addr from_string(const std::string& ipstr, const char *title = nullptr) - { - asio::error_code ec; - asio::ip::address_v6 a = asio::ip::make_address_v6(ipstr, ec); - if (ec) - throw ipv6_exception(IP::internal::format_error(ipstr, title, "v6", ec)); - return from_asio(a); - } - - std::string to_string() const - { - const asio::ip::address_v6 a = to_asio(); - std::string ret = a.to_string(); - return ret; - } - - static Addr from_hex(const std::string& s) - { - Addr ret; - ret.scope_id_ = 0; - ret.zero(); - size_t len = s.length(); - size_t base = 0; - if (len > 0 && s[len-1] == 'L') - len -= 1; - if (len >= 2 && s[0] == '0' && s[1] == 'x') - { - base = 2; - len -= 2; - } - if (len < 1 || len > 32) - throw ipv6_exception("parse hex error"); - size_t di = (len-1)>>1; - for (int i = (len & 1) ? -1 : 0; i < int(len); i += 2) - { - const size_t idx = base + i; - const int bh = (i >= 0) ? parse_hex_char(s[idx]) : 0; - const int bl = parse_hex_char(s[idx+1]); - if (bh == -1 || bl == -1) - throw ipv6_exception("parse hex error"); - ret.u.bytes[Endian::e16(di--)] = (bh<<4) + bl; - } - return ret; - } - - std::string to_hex() const - { - std::string ret; - ret.reserve(32); - bool firstnonzero = false; - for (size_t i = 0; i < 16; ++i) - { - const unsigned char b = u.bytes[Endian::e16rev(i)]; - if (b || firstnonzero || i == 15) - { - const char bh = b >> 4; - if (bh || firstnonzero) - ret += render_hex_char(bh); - ret += render_hex_char(b & 0x0F); - firstnonzero = true; - } - } - return ret; - } - - static Addr from_ulong(unsigned long ul) - { - Addr ret; - ret.scope_id_ = 0; - ret.u.u64[Endian::e2(0)] = std::uint64_t(ul); - ret.u.u64[Endian::e2(1)] = 0; - return ret; - } - - // return *this as a unsigned long - unsigned long to_ulong() const - { - const unsigned long ret = (unsigned long)u.u64[Endian::e2(0)]; - const std::uint64_t cmp = std::uint64_t(ret); - if (u.u64[Endian::e2(1)] || cmp != u.u64[Endian::e2(0)]) - throw ipv6_exception("overflow in conversion from IPv6.Addr to unsigned long"); - return ret; - } - - static Addr from_long(long ul) - { - bool neg = false; - Addr ret; - ret.scope_id_ = 0; - if (ul < 0) - { - ul = -(ul + 1); - neg = true; - } - ret.u.u64[Endian::e2(0)] = std::uint64_t(ul); - ret.u.u64[Endian::e2(1)] = 0; - if (neg) - ret.negate(); - return ret; - } - - // return *this as a long - long to_long() const - { - bool neg = false; - Addr a = *this; - if (a.u.u64[Endian::e2(1)]) - { - a.negate(); - neg = true; - } - const long ret = (long)a.u.u64[Endian::e2(0)]; - const std::uint64_t cmp = std::uint64_t(ret); - if (a.u.u64[Endian::e2(1)] || cmp != a.u.u64[Endian::e2(0)]) - throw ipv6_exception("overflow in conversion from IPv6.Addr to long"); - return neg ? -(ret + 1) : ret; - } - - std::string arpa() const - { - throw ipv6_exception("arpa() not implemented"); - } - - static Addr from_asio(const asio::ip::address_v6& asio_addr) - { - Addr ret; - union ipv6addr addr; - addr.asio_bytes = asio_addr.to_bytes(); - network_to_host_order(&ret.u, &addr); - ret.scope_id_ = (unsigned int)asio_addr.scope_id(); - return ret; - } - - static Addr from_byte_string(const unsigned char *bytestr) - { - Addr ret; - network_to_host_order(&ret.u, (const union ipv6addr *)bytestr); - ret.scope_id_ = 0; - return ret; - } - - void to_byte_string(unsigned char *bytestr) const - { - host_to_network_order((union ipv6addr *)bytestr, &u); - } - - static void v4_to_byte_string(unsigned char *bytestr, - const std::uint32_t v4addr) - { - union ipv6addr *a = (union ipv6addr *)bytestr; - a->u32[0] = a->u32[1] = a->u32[2] = 0; - a->u32[3] = v4addr; - } - - static bool byte_string_is_v4(const unsigned char *bytestr) - { - const union ipv6addr *a = (const union ipv6addr *)bytestr; - return a->u32[0] == 0 && a->u32[1] == 0 && a->u32[2] == 0; - } - - static std::uint32_t v4_from_byte_string(const unsigned char *bytestr) - { - const union ipv6addr *a = (const union ipv6addr *)bytestr; - return a->u32[3]; - } - - asio::ip::address_v6 to_asio() const - { - union ipv6addr addr; - host_to_network_order(&addr, &u); - return asio::ip::address_v6(addr.asio_bytes, scope_id_); - } - - static Addr from_zero() - { - Addr ret; - ret.scope_id_ = 0; - ret.zero(); - return ret; - } - - static Addr from_one() - { - Addr ret; - ret.scope_id_ = 0; - ret.one(); - return ret; - } - - static Addr from_zero_complement() - { - Addr ret; - ret.scope_id_ = 0; - ret.zero_complement(); - return ret; - } - - // build a netmask using given prefix_len - static Addr netmask_from_prefix_len(const unsigned int prefix_len) - { - Addr ret; - ret.scope_id_ = 0; - ret.prefix_len_to_netmask(prefix_len); - return ret; - } - - // build a netmask using given extent - Addr netmask_from_extent() const - { - const Addr lb = *this - 1; - for (size_t i = 4; i --> 0 ;) - { - const std::uint32_t v = lb.u.u32[Endian::e4(i)]; - if (v) - return netmask_from_prefix_len(SIZE - (((unsigned int)i<<5) + find_last_set(v))); - } - return from_zero_complement(); - } - - Addr operator&(const Addr& other) const { - Addr ret; - ret.scope_id_ = scope_id_; - ret.u.u64[0] = u.u64[0] & other.u.u64[0]; - ret.u.u64[1] = u.u64[1] & other.u.u64[1]; - return ret; - } - - Addr operator|(const Addr& other) const { - Addr ret; - ret.scope_id_ = scope_id_; - ret.u.u64[0] = u.u64[0] | other.u.u64[0]; - ret.u.u64[1] = u.u64[1] | other.u.u64[1]; - return ret; - } - - Addr operator+(const long delta) const { - Addr ret = *this; - ret.u.u64[Endian::e2(0)] += delta; - ret.u.u64[Endian::e2(1)] += (delta >= 0) - ? (ret.u.u64[Endian::e2(0)] < u.u64[Endian::e2(0)]) - : -(ret.u.u64[Endian::e2(0)] > u.u64[Endian::e2(0)]); - return ret; - } - - Addr operator+(const Addr& other) const { - Addr ret = *this; - add(ret.u, other.u); - return ret; - } - - Addr operator-(const long delta) const { - return operator+(-delta); - } - - Addr operator-(const Addr& other) const { - Addr ret = *this; - sub(ret.u, other.u); - return ret; - } - - Addr operator*(const Addr& d) const { - Addr m = d; - Addr ret = from_zero(); - for (unsigned int i = 0; i < SIZE; ++i) - { - if (bit(i)) - ret += m; - m <<= 1; - } - return ret; - } - - Addr operator/(const Addr& d) const { - Addr q, r; - div(*this, d, q, r); - return q; - } - - Addr operator%(const Addr& d) const { - Addr q, r; - div(*this, d, q, r); - return r; - } - - Addr operator<<(const unsigned int shift) const { - Addr ret = *this; - shiftl128(ret.u.u64[Endian::e2(0)], - ret.u.u64[Endian::e2(1)], - shift); - return ret; - } - - Addr operator>>(const unsigned int shift) const { - Addr ret = *this; - shiftr128(ret.u.u64[Endian::e2(0)], - ret.u.u64[Endian::e2(1)], - shift); - return ret; - } - - Addr operator~() const { - Addr ret; - ret.scope_id_ = scope_id_; - ret.u.u64[0] = ~u.u64[0]; - ret.u.u64[1] = ~u.u64[1]; - return ret; - } - - // return the network that contains the current address - Addr network_addr(const unsigned int prefix_len) const - { - return *this & netmask_from_prefix_len(prefix_len); - } - - bool operator==(const Addr& other) const - { - return u.u64[0] == other.u.u64[0] && u.u64[1] == other.u.u64[1] && scope_id_ == other.scope_id_; - } - - bool operator!=(const Addr& other) const - { - return !operator==(other); - } - -#define OPENVPN_IPV6_OPERATOR_REL(OP) \ - bool operator OP(const Addr& other) const \ - { \ - if (u.u64[Endian::e2(1)] == other.u.u64[Endian::e2(1)]) \ - { \ - if (u.u64[Endian::e2(0)] != other.u.u64[Endian::e2(0)]) \ - return u.u64[Endian::e2(0)] OP other.u.u64[Endian::e2(0)]; \ - else \ - return scope_id_ OP other.scope_id_; \ - } \ - else \ - return u.u64[Endian::e2(1)] OP other.u.u64[Endian::e2(1)]; \ - } - - OPENVPN_IPV6_OPERATOR_REL(<) - OPENVPN_IPV6_OPERATOR_REL(>) - OPENVPN_IPV6_OPERATOR_REL(<=) - OPENVPN_IPV6_OPERATOR_REL(>=) - -#undef OPENVPN_IPV6_OPERATOR_REL - - bool unspecified() const - { - return all_zeros(); - } - - bool specified() const - { - return !unspecified(); - } - - bool all_zeros() const - { - return u.u64[0] == 0 && u.u64[1] == 0; - } - - bool all_ones() const - { - return u.u64[0] == ~std::uint64_t(0) && u.u64[1] == ~std::uint64_t(0); - } - - bool bit(unsigned int pos) const - { - if (pos < 64) - return (u.u64[Endian::e2(0)] & (std::uint64_t(1)<= 0) - { - const int ret = IPv4::Addr::prefix_len_32(u.u32[Endian::e4rev(idx)]); - if (ret >= 0) - return ret + (idx<<5); - } - throw ipv6_exception("malformed netmask"); - } - - // number of host bits in netmask - unsigned int host_len() const - { - return SIZE - prefix_len(); - } - - // return the number of host addresses contained within netmask - Addr extent_from_netmask() const - { - const unsigned int hl = host_len(); - if (hl < SIZE) - { - Addr a; - a.scope_id_ = 0; - a.one(); - return a << hl; - } - else if (hl == SIZE) - return from_zero(); - else - throw ipv6_exception("extent overflow"); - } - - // address size in bits - static unsigned int size() - { - return SIZE; - } - - std::size_t hashval() const - { - return Hash::value(u.u32[0], u.u32[1], u.u32[2], u.u32[3]); - } - -#ifdef OPENVPN_IP_IMMUTABLE - private: -#endif - - void negate() - { - u.u64[0] = ~u.u64[0]; - u.u64[1] = ~u.u64[1]; - } - - void zero() - { - u.u64[0] = 0; - u.u64[1] = 0; - } - - void zero_complement() - { - u.u64[0] = ~std::uint64_t(0); - u.u64[1] = ~std::uint64_t(0); - } - - void one() - { - u.u64[0] = 1; - u.u64[1] = 0; - } - - Addr& operator++() - { - if (++u.u64[Endian::e2(0)] == 0) - ++u.u64[Endian::e2(1)]; - return *this; - } - - Addr& operator+=(const long delta) - { - *this = *this + delta; - return *this; - } - - Addr& operator-=(const long delta) - { - return operator+=(-delta); - } - - Addr& operator+=(const Addr& other) { - add(u, other.u); - return *this; - } - - Addr& operator-=(const Addr& other) { - sub(u, other.u); - return *this; - } - - Addr& operator<<=(const unsigned int shift) { - shiftl128(u.u64[Endian::e2(0)], - u.u64[Endian::e2(1)], - shift); - return *this; - } - - Addr& operator>>=(const unsigned int shift) { - shiftr128(u.u64[Endian::e2(0)], - u.u64[Endian::e2(1)], - shift); - return *this; - } - - void set_clear_bit(unsigned int pos, bool value) - { - if (pos < 64) - { - if (value) - u.u64[Endian::e2(0)] |= (std::uint64_t(1)<>= 1; - ml.set_bit(SIZE-1, mh.bit(0)); - mh >>= 1; - if (mh.all_zeros() && r >= ml) - { - r -= ml; - q.set_bit((SIZE-1)-i, true); - } - } - } - - int scope_id() const - { - return scope_id_; - } - - private: - union ipv6addr { - std::uint64_t u64[2]; - std::uint32_t u32[4]; // generally stored in host byte order - unsigned char bytes[16]; - asio::ip::address_v6::bytes_type asio_bytes; - }; - - void prefix_len_to_netmask_unchecked(const unsigned int prefix_len) - { - if (prefix_len > 0) - { - const unsigned int pl = prefix_len - 1; - const std::uint32_t mask = ~((1 << (31 - (pl & 31))) - 1); - switch (pl >> 5) - { - case 0: - u.u32[Endian::e4(0)] = 0; - u.u32[Endian::e4(1)] = 0; - u.u32[Endian::e4(2)] = 0; - u.u32[Endian::e4(3)] = mask; - break; - case 1: - u.u32[Endian::e4(0)] = 0; - u.u32[Endian::e4(1)] = 0; - u.u32[Endian::e4(2)] = mask; - u.u32[Endian::e4(3)] = ~0; - break; - case 2: - u.u32[Endian::e4(0)] = 0; - u.u32[Endian::e4(1)] = mask; - u.u32[Endian::e4(2)] = ~0; - u.u32[Endian::e4(3)] = ~0; - break; - case 3: - u.u32[Endian::e4(0)] = mask; - u.u32[Endian::e4(1)] = ~0; - u.u32[Endian::e4(2)] = ~0; - u.u32[Endian::e4(3)] = ~0; - break; - } - } - else - zero(); - } - - void prefix_len_to_netmask(const unsigned int prefix_len) - { - if (prefix_len <= SIZE) - return prefix_len_to_netmask_unchecked(prefix_len); - else - throw ipv6_exception("bad prefix len"); - } - - static void host_to_network_order(union ipv6addr *dest, const union ipv6addr *src) - { - dest->u32[0] = htonl(src->u32[Endian::e4rev(0)]); - dest->u32[1] = htonl(src->u32[Endian::e4rev(1)]); - dest->u32[2] = htonl(src->u32[Endian::e4rev(2)]); - dest->u32[3] = htonl(src->u32[Endian::e4rev(3)]); - } - - static void network_to_host_order(union ipv6addr *dest, const union ipv6addr *src) - { - dest->u32[0] = ntohl(src->u32[Endian::e4rev(0)]); - dest->u32[1] = ntohl(src->u32[Endian::e4rev(1)]); - dest->u32[2] = ntohl(src->u32[Endian::e4rev(2)]); - dest->u32[3] = ntohl(src->u32[Endian::e4rev(3)]); - } - - static void shiftl128(std::uint64_t& low, - std::uint64_t& high, - unsigned int shift) - { - if (shift == 1) - { - high <<= 1; - if (low & (std::uint64_t(1) << 63)) - high |= 1; - low <<= 1; - } - else if (shift == 0) - ; - else if (shift <= 128) - { - if (shift >= 64) - { - high = low; - low = 0; - shift -= 64; - } - if (shift < 64) - { - high = (high << shift) | (low >> (64-shift)); - low <<= shift; - } - else // shift == 64 - high = 0; - } - else - throw ipv6_exception("l-shift too large"); - } - - static void shiftr128(std::uint64_t& low, - std::uint64_t& high, - unsigned int shift) - { - if (shift == 1) - { - low >>= 1; - if (high & 1) - low |= (std::uint64_t(1) << 63); - high >>= 1; - } - else if (shift == 0) - ; - else if (shift <= 128) - { - if (shift >= 64) - { - low = high; - high = 0; - shift -= 64; - } - if (shift < 64) - { - low = (low >> shift) | (high << (64-shift)); - high >>= shift; - } - else // shift == 64 - low = 0; - } - else - throw ipv6_exception("r-shift too large"); - } - - static void add(ipv6addr& dest, const ipv6addr& src) { - const std::uint64_t dorigl = dest.u64[Endian::e2(0)]; - dest.u64[Endian::e2(0)] += src.u64[Endian::e2(0)]; - dest.u64[Endian::e2(1)] += src.u64[Endian::e2(1)]; - // check for overflow of low 64 bits, add carry to high - if (dest.u64[Endian::e2(0)] < dorigl) - ++dest.u64[Endian::e2(1)]; - } - - static void sub(ipv6addr& dest, const ipv6addr& src) { - const std::uint64_t dorigl = dest.u64[Endian::e2(0)]; - dest.u64[Endian::e2(0)] -= src.u64[Endian::e2(0)]; - dest.u64[Endian::e2(1)] -= src.u64[Endian::e2(1)] - + (dorigl < dest.u64[Endian::e2(0)]); - } - - union ipv6addr u; - unsigned int scope_id_; - }; - - OPENVPN_OSTREAM(Addr, to_string) - } -} - -OPENVPN_HASH_METHOD(openvpn::IPv6::Addr, hashval); - -#endif // OPENVPN_ADDR_IPV6_H diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/macaddr.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/macaddr.hpp deleted file mode 100644 index f53100f..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/macaddr.hpp +++ /dev/null @@ -1,67 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_ADDR_MACADDR_H -#define OPENVPN_ADDR_MACADDR_H - -#include -#include -#include - -#include -#include -#include - -namespace openvpn { - - // Fundamental class for representing an ethernet MAC address. - - class MACAddr { - public: - MACAddr() - { - std::memset(addr_, 0, sizeof(addr_)); - } - - MACAddr(const unsigned char *addr) - { - reset(addr); - } - - void reset(const unsigned char *addr) - { - std::memcpy(addr_, addr, sizeof(addr_)); - } - - std::string to_string() const - { - return render_hex_sep(addr_, sizeof(addr_), ':'); - } - - private: - unsigned char addr_[6]; - }; - - OPENVPN_OSTREAM(MACAddr, to_string) - -} // namespace openvpn - -#endif // OPENVPN_ADDR_MACADDR_H diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/pool.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/pool.hpp deleted file mode 100644 index 4803edc..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/pool.hpp +++ /dev/null @@ -1,138 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_ADDR_POOL_H -#define OPENVPN_ADDR_POOL_H - -#include -#include -#include -#include - -#include -#include - -#include -#include - -namespace openvpn { - namespace IP { - - // Maintain a pool of IP addresses. - // A should be IP::Addr, IPv4::Addr, or IPv6::Addr. - template - class PoolType - { - public: - PoolType() {} - - // Add range of addresses to pool (pool will own the addresses). - void add_range(const RangeType& range) - { - typename RangeType::Iterator iter = range.iterator(); - while (iter.more()) - { - const ADDR& a = iter.addr(); - add_addr(a); - iter.next(); - } - } - - // Add single address to pool (pool will own the address). - void add_addr(const ADDR& addr) - { - typename std::unordered_map::const_iterator e = map.find(addr); - if (e == map.end()) - { - freelist.push_back(addr); - map[addr] = false; - } - } - - // Return number of pool addresses currently in use. - size_t n_in_use() const - { - return map.size() - freelist.size(); - } - - // Acquire an address from pool. Returns true if successful, - // with address placed in dest, or false if pool depleted. - bool acquire_addr(ADDR& dest) - { - while (true) - { - if (freelist.empty()) - return false; - const ADDR& a = freelist.front(); - typename std::unordered_map::iterator e = map.find(a); - if (e == map.end()) // any address in freelist must exist in map - throw Exception("PoolType: address in freelist doesn't exist in map"); - if (!e->second) - { - e->second = true; - dest = a; - freelist.pop_front(); - return true; - } - freelist.pop_front(); - } - } - - // Acquire a specific address from pool, returning true if - // successful, or false if the address is not available. - bool acquire_specific_addr(const ADDR& addr) - { - typename std::unordered_map::iterator e = map.find(addr); - if (e != map.end() && !e->second) - { - e->second = true; - return true; - } - else - return false; - } - - // Return a previously acquired address to the pool. Does nothing if - // (a) the address is owned by the pool and marked as free, or - // (b) the address is not owned by the pool. - void release_addr(const ADDR& addr) - { - typename std::unordered_map::iterator e = map.find(addr); - if (e != map.end() && e->second) - { - freelist.push_back(addr); - e->second = false; - } - } - - // DEBUGGING -- get the map load factor - float load_factor() const { return map.load_factor(); } - - private: - std::deque freelist; - std::unordered_map map; - }; - - typedef PoolType Pool; - } -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/range.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/range.hpp deleted file mode 100644 index 4c30b1f..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/range.hpp +++ /dev/null @@ -1,137 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_ADDR_RANGE_H -#define OPENVPN_ADDR_RANGE_H - -#include -#include - -#include -#include - -#include - -namespace openvpn { - namespace IP { - - // Denote a range of IP addresses with a start and extent, - // where A represents an address class. - // A should be a network address class such as IP::Addr, IPv4::Addr, or IPv6::Addr. - - template - class RangeType - { - public: - class Iterator - { - friend class RangeType; - public: - bool more() const { return remaining_ > 0; } - - const ADDR& addr() const { return addr_; } - - void next() - { - if (more()) - { - ++addr_; - --remaining_; - } - } - - private: - Iterator(const RangeType& range) - : addr_(range.start_), remaining_(range.extent_) {} - - ADDR addr_; - size_t remaining_; - }; - - RangeType() : extent_(0) {} - - RangeType(const ADDR& start, const size_t extent) - : start_(start), extent_(extent) {} - - Iterator iterator() const { return Iterator(*this); } - - const bool defined() const { return extent_ > 0; } - const ADDR& start() const { return start_; } - size_t extent() const { return extent_; } - - RangeType pull_front(size_t extent) - { - if (extent > extent_) - extent = extent_; - RangeType ret(start_, extent); - start_ += extent; - extent_ -= extent; - return ret; - } - - std::string to_string() const - { - std::ostringstream os; - os << start_.to_string() << '[' << extent_ << ']'; - return os.str(); - } - - private: - ADDR start_; - size_t extent_; - }; - - template - class RangePartitionType - { - public: - RangePartitionType(const RangeType& src_range, const size_t n_partitions) - : range(src_range), - remaining(n_partitions) - { - } - - bool next(RangeType& r) - { - if (remaining) - { - if (remaining > 1) - r = range.pull_front(range.extent() / remaining); - else - r = range; - --remaining; - return r.defined(); - } - else - return false; - } - - private: - RangeType range; - size_t remaining; - }; - - typedef RangeType Range; - typedef RangePartitionType RangePartition; - } -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/regex.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/regex.hpp deleted file mode 100644 index dc4a027..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/regex.hpp +++ /dev/null @@ -1,38 +0,0 @@ -// Regular expressions for IPv4/v6 -// Source: http://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses - -#ifndef OPENVPN_ADDR_REGEX_H -#define OPENVPN_ADDR_REGEX_H - -#include - -namespace openvpn { - namespace IP { - inline std::string v4_regex() - { - const std::string ipv4seg = "(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])"; - return "(?:" + ipv4seg + "\\.){3,3}" + ipv4seg; - } - - inline std::string v6_regex() - { - const std::string ipv6seg = "[0-9a-fA-F]{1,4}"; - return "(?:" - "(?:" + ipv6seg + ":){7,7}" + ipv6seg + "|" // 1:2:3:4:5:6:7:8 - "(?:" + ipv6seg + ":){1,7}:|" // 1:: 1:2:3:4:5:6:7:: - "(?:" + ipv6seg + ":){1,6}:" + ipv6seg + "|" // 1::8 1:2:3:4:5:6::8 1:2:3:4:5:6::8 - "(?:" + ipv6seg + ":){1,5}(?::" + ipv6seg + "){1,2}|" // 1::7:8 1:2:3:4:5::7:8 1:2:3:4:5::8 - "(?:" + ipv6seg + ":){1,4}(?::" + ipv6seg + "){1,3}|" // 1::6:7:8 1:2:3:4::6:7:8 1:2:3:4::8 - "(?:" + ipv6seg + ":){1,3}(?::" + ipv6seg + "){1,4}|" // 1::5:6:7:8 1:2:3::5:6:7:8 1:2:3::8 - "(?:" + ipv6seg + ":){1,2}(?::" + ipv6seg + "){1,5}|" + // 1::4:5:6:7:8 1:2::4:5:6:7:8 1:2::8 - ipv6seg + ":(?:(?::" + ipv6seg + "){1,6})|" // 1::3:4:5:6:7:8 1::3:4:5:6:7:8 1::8 - ":(?:(?::" + ipv6seg + "){1,7}|:)|" // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 :: - "fe80:(?::" + ipv6seg + "){0,4}%[0-9a-zA-Z]{1,}|" // fe80::7:8%eth0 fe80::7:8%1 (link-local IPv6 addresses with zone index) - "::(?:ffff(?::0{1,4}){0,1}:){0,1}" + v4_regex() + "|" // ::255.255.255.255 ::ffff:255.255.255.255 ::ffff:0:255.255.255.255 (IPv4-mapped IPv6 addresses and IPv4-translated addresses) - "(?:" + ipv6seg + ":){1,4}:" + v4_regex() + // 2001:db8:3:4::192.0.2.33 64:ff9b::192.0.2.33 (IPv4-Embedded IPv6 Address) - ")"; - } - } -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/route.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/route.hpp deleted file mode 100644 index b03aceb..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/route.hpp +++ /dev/null @@ -1,251 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_ADDR_ROUTE_H -#define OPENVPN_ADDR_ROUTE_H - -#include -#include -#include -#include // for std::uint32_t - -#include -#include -#include -#include -#include -#include -#include - -namespace openvpn { - namespace IP { - // Basic route object - template - struct RouteType - { - typedef ADDR Addr; - - ADDR addr; - unsigned int prefix_len; - - OPENVPN_EXCEPTION(route_error); - - RouteType() - : prefix_len(0) - { - } - - RouteType(const std::string& rtstr, const char *title = nullptr) - : RouteType(RouteType::from_string(rtstr, title)) - { - } - - RouteType(const std::string& rtstr, const std::string& title) - : RouteType(RouteType::from_string(rtstr, title.c_str())) - { - } - - RouteType(const ADDR& addr_arg, - const unsigned int prefix_len_arg) - : addr(addr_arg), - prefix_len(prefix_len_arg) - { - } - - static RouteType from_string(const std::string& rtstr, const char *title = nullptr) - { - RouteType r; - std::vector pair; - pair.reserve(2); - Split::by_char_void, NullLex, Split::NullLimit>(pair, rtstr, '/', 0, 1); - r.addr = ADDR::from_string(pair[0], title); - if (pair.size() >= 2) - { - r.prefix_len = parse_number_throw(pair[1], "prefix length"); - if (r.prefix_len > r.addr.size()) - OPENVPN_THROW(route_error, (title ? title : "route") << " : bad prefix length : " << rtstr); - } - else - r.prefix_len = r.addr.size(); - return r; - } - - IP::Addr::Version version() const - { - return addr.version(); - } - - IP::Addr::VersionMask version_mask() const - { - return addr.version_mask(); - } - - ADDR netmask() const - { - return ADDR::netmask_from_prefix_len(version(), prefix_len); - } - - size_t extent() const - { - return netmask().extent_from_netmask().to_ulong(); - } - - bool is_canonical() const - { - return (addr & netmask()) == addr; - } - - void force_canonical() - { - addr = addr & netmask(); - } - - bool is_host() const - { - return addr.defined() && prefix_len == addr.size(); - } - - bool contains(const ADDR& a) const // assumes canonical address/routes - { - if (addr.defined() && addr.version() == a.version()) - return (a & netmask()) == addr; - else - return false; - } - - bool contains(const RouteType& r) const // assumes canonical routes - { - return contains(r.addr) && r.prefix_len >= prefix_len; - } - - bool split(RouteType& r1, RouteType& r2) const // assumes we are canonical - { - if (!is_host()) - { - const unsigned int newpl = prefix_len + 1; - r1.addr = addr; - r1.prefix_len = newpl; - - r2.addr = addr + ADDR::netmask_from_prefix_len(addr.version(), newpl).extent_from_netmask(); - r2.prefix_len = newpl; - - return true; - } - return false; - } - - std::string to_string() const - { - return addr.to_string() + '/' + openvpn::to_string(prefix_len); - } - - std::string to_string_by_netmask() const - { - return addr.to_string() + ' ' + netmask().to_string(); - } - - bool operator==(const RouteType& other) const - { - return prefix_len == other.prefix_len && addr == other.addr; - } - - std::size_t hash_value() const - { - return Hash::value(addr, prefix_len); - } - }; - - template - struct RouteTypeList : public std::vector> - { - typedef std::vector< RouteType > Base; - - OPENVPN_EXCEPTION(route_list_error); - - std::string to_string() const - { - std::ostringstream os; - for (typename Base::const_iterator i = Base::begin(); i != Base::end(); ++i) - os << i->to_string() << std::endl; - return os.str(); - } - - IP::Addr::VersionMask version_mask() const - { - IP::Addr::VersionMask mask = 0; - for (typename Base::const_iterator i = Base::begin(); i != Base::end(); ++i) - mask |= i->version_mask(); - return mask; - } - - void verify_canonical() const - { - for (typename Base::const_iterator i = Base::begin(); i != Base::end(); ++i) - if (!i->is_canonical()) - throw route_list_error("route not canonical: " + i->to_string()); - } - }; - - typedef RouteType Route; - typedef RouteType Route4; - typedef RouteType Route6; - - typedef RouteTypeList RouteList; - typedef RouteTypeList Route4List; - typedef RouteTypeList Route6List; - - OPENVPN_OSTREAM(Route, to_string); - OPENVPN_OSTREAM(Route4, to_string); - OPENVPN_OSTREAM(Route6, to_string); - - OPENVPN_OSTREAM(RouteList, to_string); - OPENVPN_OSTREAM(Route4List, to_string); - OPENVPN_OSTREAM(Route6List, to_string); - - inline Route route_from_string_prefix(const std::string& addrstr, - const unsigned int prefix_len, - const std::string& title, - const IP::Addr::Version required_version = IP::Addr::UNSPEC) - { - Route r; - r.addr = IP::Addr(addrstr, title, required_version); - r.prefix_len = prefix_len; - if (r.prefix_len > r.addr.size()) - OPENVPN_THROW(Route::route_error, title << " : bad prefix length : " << addrstr); - return r; - } - - inline Route route_from_string(const std::string& rtstr, - const std::string& title, - const IP::Addr::Version required_version = IP::Addr::UNSPEC) - { - Route r(rtstr, title); - r.addr.validate_version(title, required_version); - return r; - } - } -} - -OPENVPN_HASH_METHOD(openvpn::IP::Route, hash_value); -OPENVPN_HASH_METHOD(openvpn::IP::Route4, hash_value); -OPENVPN_HASH_METHOD(openvpn::IP::Route6, hash_value); - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/routeinv.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/routeinv.hpp deleted file mode 100644 index 10cda35..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/addr/routeinv.hpp +++ /dev/null @@ -1,105 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -// Invert a route list. Used to support excluded routes on platforms that -// don't support them natively. - -#ifndef OPENVPN_ADDR_ROUTEINV_H -#define OPENVPN_ADDR_ROUTEINV_H - -#include -#include - -namespace openvpn { - namespace IP { - class RouteInverter : public RouteList - { - public: - OPENVPN_EXCEPTION(route_inverter); - - RouteInverter() {} - - // NOTE: when passing RouteInverter to this constructor, make sure - // to static_cast it to RouteList& so as to avoid matching the - // default copy constructor. - explicit RouteInverter(const RouteList& in) - : RouteInverter(in, in.version_mask()) - { - } - - RouteInverter(const RouteList& in, const Addr::VersionMask vermask) - { - in.verify_canonical(); - if (vermask & Addr::V4_MASK) - descend(in, Addr::V4, Route(Addr::from_zero(Addr::V4), 0)); - if (vermask & Addr::V6_MASK) - descend(in, Addr::V6, Route(Addr::from_zero(Addr::V6), 0)); - } - - private: - enum Type { - EQUAL, - SUBROUTE, - LEAF, - }; - - void descend(const RouteList& in, const Addr::Version ver, const Route& route) - { - switch (find(in, route)) - { - case SUBROUTE: - { - Route r1, r2; - if (route.split(r1, r2)) - { - descend(in, ver, r1); - descend(in, ver, r2); - } - else - push_back(route); - break; - } - case LEAF: - push_back(route); - break; - case EQUAL: - break; - } - } - - static Type find(const RouteList& in, const Route& route) - { - Type type = LEAF; - for (RouteList::const_iterator i = in.begin(); i != in.end(); ++i) - { - const Route& r = *i; - if (route == r) - return EQUAL; - else if (route.contains(r)) - type = SUBROUTE; - } - return type; - } - }; - } -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/apple/maclife.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/apple/maclife.hpp deleted file mode 100644 index c49364a..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/apple/maclife.hpp +++ /dev/null @@ -1,324 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_APPLE_MACLIFE_H -#define OPENVPN_APPLE_MACLIFE_H - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace openvpn { - class MacLifeCycle : public ClientLifeCycle, MacSleep, ReachabilityTracker - { - public: - OPENVPN_EXCEPTION(mac_lifecycle_error); - - MacLifeCycle() - : ReachabilityTracker(true, true), - nc(nullptr), - thread(nullptr), - paused(false) - { - } - - virtual ~MacLifeCycle() - { - stop_thread(); - } - - virtual bool network_available() - { - return net_up(); - } - - virtual void start(NotifyCallback* nc_arg) - { - if (!thread && nc_arg) - { - nc = nc_arg; - thread = new std::thread(&MacLifeCycle::thread_func, this); - } - } - - virtual void stop() - { - stop_thread(); - } - - private: - struct State - { - State() - : net_up(false), - sleep(false) - { - } - - State(bool net_up_arg, const std::string& iface_arg, bool sleep_arg) - : net_up(net_up_arg), - iface(iface_arg), - sleep(sleep_arg) - { - } - - bool operator==(const State& other) const - { - return net_up == other.net_up && iface == other.iface && sleep == other.sleep; - } - - bool operator!=(const State& other) const - { - return !operator==(other); - } - - std::string to_string() const - { - std::ostringstream os; - os << "[net_up=" << net_up << " iface=" << iface << " sleep=" << sleep << ']'; - return os.str(); - } - - bool net_up; - std::string iface; - bool sleep; - }; - - void stop_thread() - { - if (thread) - { - if (runloop.defined()) - CFRunLoopStop(runloop()); - thread->join(); - delete thread; - thread = nullptr; - } - } - - void thread_func() - { - runloop.reset(CFRunLoopGetCurrent(), CF::BORROW); - Log::Context logctx(logwrap); - try { - // set up dynamic store query object - dstore.reset(SCDynamicStoreCreate(kCFAllocatorDefault, - CFSTR("OpenVPN_MacLifeCycle"), - nullptr, - nullptr)); - - // init state - state = State(net_up(), primary_interface(), false); - prev_state = state; - paused = false; - - // enable sleep/wakeup notifications - mac_sleep_start(); - - // enable network reachability notifications - reachability_tracker_schedule(); - - // enable interface change notifications - iface_watch(); - - // process event loop until CFRunLoopStop is called from parent thread - CFRunLoopRun(); - } - catch (const std::exception& e) - { - OPENVPN_LOG("MacLifeCycle Exception: " << e.what()); - } - - // cleanup - cancel_action_timer(); - mac_sleep_stop(); - reachability_tracker_cancel(); - dstore.reset(); - } - - std::string primary_interface() - { - CF::Dict dict(CF::DynamicStoreCopyDict(dstore, "State:/Network/Global/IPv4")); - return CF::dict_get_str(dict, "PrimaryInterface"); - } - - bool net_up() - { - ReachabilityViaWiFi r; - return ReachabilityViaWiFi::status_from_flags(r.flags()) != ReachabilityInterface::NotReachable; - } - - void iface_watch() - { - SCDynamicStoreContext context = {0, this, nullptr, nullptr, nullptr}; - CF::DynamicStore ds(SCDynamicStoreCreate(kCFAllocatorDefault, - CFSTR("OpenVPN_MacLifeCycle_iface_watch"), - iface_watch_callback_static, - &context)); - if (!ds.defined()) - throw mac_lifecycle_error("SCDynamicStoreCreate"); - CF::MutableArray watched_keys(CF::mutable_array()); - CF::array_append_str(watched_keys, "State:/Network/Global/IPv4"); - //CF::array_append_str(watched_keys, "State:/Network/Global/IPv6"); - if (!watched_keys.defined()) - throw mac_lifecycle_error("watched_keys is undefined"); - if (!SCDynamicStoreSetNotificationKeys(ds(), - watched_keys(), - nullptr)) - throw mac_lifecycle_error("SCDynamicStoreSetNotificationKeys failed"); - CF::RunLoopSource rls(SCDynamicStoreCreateRunLoopSource(kCFAllocatorDefault, ds(), 0)); - if (!rls.defined()) - throw mac_lifecycle_error("SCDynamicStoreCreateRunLoopSource failed"); - CFRunLoopAddSource(CFRunLoopGetCurrent(), rls(), kCFRunLoopDefaultMode); - } - - static void iface_watch_callback_static(SCDynamicStoreRef store, CFArrayRef changedKeys, void *arg) - { - MacLifeCycle *self = (MacLifeCycle *)arg; - self->iface_watch_callback(store, changedKeys); - } - - void iface_watch_callback(SCDynamicStoreRef store, CFArrayRef changedKeys) - { - state.iface = primary_interface(); - OPENVPN_LOG("MacLifeCycle NET_IFACE " << state.iface); - schedule_action_timer(1); - } - - virtual void notify_sleep() - { - OPENVPN_LOG("MacLifeCycle SLEEP"); - state.sleep = true; - schedule_action_timer(0); - } - - virtual void notify_wakeup() - { - OPENVPN_LOG("MacLifeCycle WAKEUP"); - state.sleep = false; - schedule_action_timer(1); - } - - virtual void reachability_tracker_event(const ReachabilityBase& rb, SCNetworkReachabilityFlags flags) - { - if (rb.vtype() == ReachabilityBase::WiFi) - { - state.net_up = (rb.vstatus(flags) != ReachabilityInterface::NotReachable); - OPENVPN_LOG("MacLifeCycle NET_STATE " << state.net_up); - schedule_action_timer(1); - } - } - - void schedule_action_timer(const int seconds) - { - cancel_action_timer(); - if (seconds) - { - CFRunLoopTimerContext context = { 0, this, nullptr, nullptr, nullptr }; - action_timer.reset(CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + seconds, 0, 0, 0, action_timer_callback_static, &context)); - if (action_timer.defined()) - CFRunLoopAddTimer(CFRunLoopGetCurrent(), action_timer(), kCFRunLoopCommonModes); - else - OPENVPN_LOG("MacLifeCycle::schedule_action_timer: failed to create timer"); - } - else - action_timer_callback(nullptr); - } - - void cancel_action_timer() - { - if (action_timer.defined()) - { - CFRunLoopTimerInvalidate(action_timer()); - action_timer.reset(nullptr); - } - } - - static void action_timer_callback_static(CFRunLoopTimerRef timer, void *info) - { - MacLifeCycle* self = (MacLifeCycle*)info; - self->action_timer_callback(timer); - } - - void action_timer_callback(CFRunLoopTimerRef timer) - { - try { - if (state != prev_state) - { - OPENVPN_LOG("MacLifeCycle ACTION pause=" << paused << " state=" << state.to_string() << " prev=" << prev_state.to_string()); - if (paused) - { - if (!state.sleep && state.net_up) - { - nc->cln_resume(); - paused = false; - } - } - else - { - if (state.sleep) - { - nc->cln_pause("sleep"); - paused = true; - } - else if (!state.net_up) - { - nc->cln_pause("network-unavailable"); - paused = true; - } - else - { - if (state.iface != prev_state.iface) - nc->cln_reconnect(0); - } - } - prev_state = state; - } - } - catch (const std::exception& e) - { - OPENVPN_LOG("MacLifeCycle::action_timer_callback: " << e.what()); - } - } - - NotifyCallback* nc; - std::thread* thread; - CF::RunLoop runloop; // run loop in thread - CF::DynamicStore dstore; - State state; - State prev_state; - bool paused; - CF::Timer action_timer; - Log::Context::Wrapper logwrap; // used to carry forward the log context from parent thread - }; -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/apple/macsleep.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/apple/macsleep.hpp deleted file mode 100644 index 876b92c..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/apple/macsleep.hpp +++ /dev/null @@ -1,129 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_APPLE_MACSLEEP_H -#define OPENVPN_APPLE_MACSLEEP_H - -#include -#include -#include - -#include -#include - -#include - -namespace openvpn { - class MacSleep - { - MacSleep(const MacSleep&) = delete; - MacSleep& operator=(const MacSleep&) = delete; - - public: - MacSleep() - : root_port(0), - notifyPortRef(nullptr), - notifierObject(0) - { - } - - virtual ~MacSleep() - { - mac_sleep_stop(); - } - - bool mac_sleep_start() - { - if (!root_port) - { - root_port = IORegisterForSystemPower(this, ¬ifyPortRef, callback_static, ¬ifierObject); - if (!root_port) - return false; - CFRunLoopAddSource(CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notifyPortRef), kCFRunLoopCommonModes); - } - return true; - } - - void mac_sleep_stop() - { - if (root_port) - { - // remove the sleep notification port from the application runloop - CFRunLoopRemoveSource(CFRunLoopGetCurrent(), - IONotificationPortGetRunLoopSource(notifyPortRef), - kCFRunLoopCommonModes); - - // deregister for system sleep notifications - IODeregisterForSystemPower(¬ifierObject); - - // IORegisterForSystemPower implicitly opens the Root Power Domain IOService - // so we close it here - IOServiceClose(root_port); - - // destroy the notification port allocated by IORegisterForSystemPower - IONotificationPortDestroy(notifyPortRef); - - // reset object members - root_port = 0; - notifyPortRef = nullptr; - notifierObject = 0; - } - } - - virtual void notify_sleep() = 0; - virtual void notify_wakeup() = 0; - - private: - static void callback_static(void* arg, io_service_t service, natural_t messageType, void *messageArgument) - { - MacSleep* self = (MacSleep*)arg; - self->callback(service, messageType, messageArgument); - } - - void callback(io_service_t service, natural_t messageType, void *messageArgument) - { - switch (messageType) - { - case kIOMessageCanSystemSleep: - IOAllowPowerChange(root_port, (long)messageArgument); - break; - case kIOMessageSystemWillSleep: - notify_sleep(); - IOAllowPowerChange(root_port, (long)messageArgument); - break; - case kIOMessageSystemHasPoweredOn: - notify_wakeup(); - break; - } - } - - // a reference to the Root Power Domain IOService - io_connect_t root_port; - - // notification port allocated by IORegisterForSystemPower - IONotificationPortRef notifyPortRef; - - // notifier object, used to deregister later - io_object_t notifierObject; - }; -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/apple/macver.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/apple/macver.hpp deleted file mode 100644 index 51d7ea7..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/apple/macver.hpp +++ /dev/null @@ -1,75 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_APPLE_MACVER_H -#define OPENVPN_APPLE_MACVER_H - -#include -#include - -#include -#include -#include - -#include -#include -#include - -namespace openvpn { - namespace Mac { - class Version : public AppleVersion - { - public: - // Mac OS X versions - // 15.x.x OS X 10.11.x El Capitan - // 14.x.x OS X 10.10.x Yosemite - // 13.x.x OS X 10.9.x Mavericks - // 12.x.x OS X 10.8.x Mountain Lion - // 11.x.x OS X 10.7.x Lion - // 10.x.x OS X 10.6.x Snow Leopard - // 9.x.x OS X 10.5.x Leopard - // 8.x.x OS X 10.4.x Tiger - // 7.x.x OS X 10.3.x Panther - // 6.x.x OS X 10.2.x Jaguar - // 5.x OS X 10.1.x Puma - - enum { - OSX_10_11=15, - OSX_10_10=14, - OSX_10_9=13, - OSX_10_8=12, - OSX_10_7=11, - OSX_10_6=10, - }; - - Version() - { - char str[256]; - size_t size = sizeof(str); - int ret = sysctlbyname("kern.osrelease", str, &size, nullptr, 0); - if (!ret) - init(std::string(str, size)); - } - }; - } -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/apple/runloop.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/apple/runloop.hpp deleted file mode 100644 index b34295e..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/apple/runloop.hpp +++ /dev/null @@ -1,34 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_APPLE_RUNLOOP_H -#define OPENVPN_APPLE_RUNLOOP_H - -#include - -namespace openvpn { - namespace CF { - OPENVPN_CF_WRAP(RunLoop, runloop_cast, CFRunLoopRef, CFRunLoopGetTypeID); - OPENVPN_CF_WRAP(RunLoopSource, runloop_source_cast, CFRunLoopSourceRef, CFRunLoopSourceGetTypeID); - } -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/apple/scdynstore.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/apple/scdynstore.hpp deleted file mode 100644 index bdc3603..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/apple/scdynstore.hpp +++ /dev/null @@ -1,52 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_APPLE_SCDYNSTORE_H -#define OPENVPN_APPLE_SCDYNSTORE_H - -#include - -#include - -namespace openvpn { - namespace CF { - OPENVPN_CF_WRAP(DynamicStore, dynamic_store_cast, SCDynamicStoreRef, SCDynamicStoreGetTypeID) - - template - inline RET DynamicStoreCopy(const DynamicStore& ds, const KEY& key) - { - String keystr = string(key); - return RET(RET::cast(SCDynamicStoreCopyValue(ds(), keystr()))); - } - - template - inline Dict DynamicStoreCopyDict(const DynamicStore& ds, const KEY& key) - { - Dict dict = DynamicStoreCopy(ds, key); - if (dict.defined()) - return dict; - else - return CF::empty_dict(); - } - } -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/apple/ver.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/apple/ver.hpp deleted file mode 100644 index 7ce9f63..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/apple/ver.hpp +++ /dev/null @@ -1,81 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_APPLE_VER_H -#define OPENVPN_APPLE_VER_H - -#include -#include - -#include -#include -#include - -#include -#include - -namespace openvpn { - class AppleVersion - { - public: - int major() const { return ver[0]; } - int minor() const { return ver[1]; } - int build() const { return ver[2]; } - - std::string to_string() const - { - std::ostringstream os; - os << major() << '.' << minor() << '.' << build(); - return os.str(); - } - - protected: - AppleVersion() - { - reset(); - } - - // verstr should be in the form major.minor.build - void init(const std::string& verstr) - { - typedef std::vector StringList; - reset(); - StringList sl; - sl.reserve(3); - Split::by_char_void(sl, verstr, '.'); - for (size_t i = 0; i < 3; ++i) - { - if (i < sl.size()) - parse_number(sl[i], ver[i]); - } - } - - private: - void reset() - { - ver[0] = ver[1] = ver[2] = -1; - } - - int ver[3]; - }; -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/cf/cf.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/cf/cf.hpp deleted file mode 100644 index 6b3f1f0..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/cf/cf.hpp +++ /dev/null @@ -1,464 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_APPLECRYPTO_CF_CF_H -#define OPENVPN_APPLECRYPTO_CF_CF_H - -#include -#include -#include -#include - -#include - -#include -#include -#include - -// Wrapper classes for Apple Core Foundation objects. - -#define OPENVPN_CF_WRAP(cls, castmeth, cftype, idmeth) \ - template <> \ - struct Type \ - { \ - static CFTypeRef cast(CFTypeRef obj) \ - { \ - if (obj && CFGetTypeID(obj) == idmeth()) \ - return obj; \ - else \ - return nullptr; \ - } \ - }; \ - typedef Wrap cls; \ - inline cls castmeth(CFTypeRef obj) \ - { \ - CFTypeRef o = Type::cast(obj); \ - if (o) \ - return cls(cftype(o), BORROW); \ - else \ - return cls(); \ - } - -namespace openvpn { - namespace CF - { - enum Own { - OWN, - BORROW - }; - - template struct Type {}; - - template - class Wrap - { - public: - Wrap() : obj_(nullptr) {} - - // Set own=BORROW if we don't currently own the object - explicit Wrap(T obj, const Own own=OWN) - { - if (own == BORROW && obj) - CFRetain(obj); - obj_ = obj; - } - - Wrap(const Wrap& other) - { - obj_ = other.obj_; - if (obj_) - CFRetain(obj_); - } - - Wrap& operator=(const Wrap& other) - { - if (other.obj_) - CFRetain(other.obj_); - if (obj_) - CFRelease(obj_); - obj_ = other.obj_; - return *this; - } - - Wrap(Wrap&& other) noexcept - { - obj_ = other.obj_; - other.obj_ = nullptr; - } - - Wrap& operator=(Wrap&& other) noexcept - { - if (obj_) - CFRelease(obj_); - obj_ = other.obj_; - other.obj_ = nullptr; - return *this; - } - - void swap(Wrap& other) - { - std::swap(obj_, other.obj_); - } - - void reset(T obj=nullptr, const Own own=OWN) - { - if (own == BORROW && obj) - CFRetain(obj); - if (obj_) - CFRelease(obj_); - obj_ = obj; - } - - bool defined() const { return obj_ != nullptr; } - - T operator()() const { return obj_; } - - CFTypeRef generic() const { return (CFTypeRef)obj_; } - - static T cast(CFTypeRef obj) { return T(Type::cast(obj)); } - - static Wrap from_generic(CFTypeRef obj, const Own own=OWN) - { - return Wrap(cast(obj), own); - } - - T release() - { - T ret = obj_; - obj_ = nullptr; - return ret; - } - - CFTypeRef generic_release() - { - T ret = obj_; - obj_ = nullptr; - return (CFTypeRef)ret; - } - - // Intended for use with Core Foundation methods that require - // a T* for saving a (non-borrowed) return value - T* mod_ref() - { - if (obj_) - { - CFRelease(obj_); - obj_ = nullptr; - } - return &obj_; - } - - void show() const - { - if (obj_) - CFShow(obj_); - else - std::cerr << "CF_UNDEFINED" << std::endl; - } - - virtual ~Wrap() - { - if (obj_) - CFRelease(obj_); - } - - private: - Wrap& operator=(T obj); // prevent use because no way to pass ownership parameter - - T obj_; - }; - - // essentially a vector of void *, used as source for array and dictionary constructors - typedef BufferAllocatedType SrcList; - - // common CF types - - OPENVPN_CF_WRAP(String, string_cast, CFStringRef, CFStringGetTypeID) - OPENVPN_CF_WRAP(Number, number_cast, CFNumberRef, CFNumberGetTypeID) - OPENVPN_CF_WRAP(Bool, bool_cast, CFBooleanRef, CFBooleanGetTypeID) - OPENVPN_CF_WRAP(Data, data_cast, CFDataRef, CFDataGetTypeID) - OPENVPN_CF_WRAP(Array, array_cast, CFArrayRef, CFArrayGetTypeID) - OPENVPN_CF_WRAP(MutableArray, mutable_array_cast, CFMutableArrayRef, CFArrayGetTypeID) - OPENVPN_CF_WRAP(Dict, dict_cast, CFDictionaryRef, CFDictionaryGetTypeID) - OPENVPN_CF_WRAP(MutableDict, mutable_dict_cast, CFMutableDictionaryRef, CFDictionaryGetTypeID) - OPENVPN_CF_WRAP(Error, error_cast, CFErrorRef, CFErrorGetTypeID); - - // generic CFTypeRef wrapper - - typedef Wrap Generic; - - inline Generic generic_cast(CFTypeRef obj) - { - return Generic(obj, BORROW); - } - - // constructors - - inline String string(const char *str) - { - return String(CFStringCreateWithCString(kCFAllocatorDefault, str, kCFStringEncodingUTF8)); - } - - inline String string(CFStringRef str) - { - return String(str, BORROW); - } - - inline String string(const String& str) - { - return String(str); - } - - inline String string(const std::string& str) - { - return String(CFStringCreateWithCString(kCFAllocatorDefault, str.c_str(), kCFStringEncodingUTF8)); - } - - inline String string(const std::string* str) - { - return String(CFStringCreateWithCString(kCFAllocatorDefault, str->c_str(), kCFStringEncodingUTF8)); - } - - inline Number number_from_int(const int n) - { - return Number(CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &n)); - } - - inline Number number_from_int32(const SInt32 n) - { - return Number(CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &n)); - } - - inline Number number_from_long_long(const long long n) - { - return Number(CFNumberCreate(kCFAllocatorDefault, kCFNumberLongLongType, &n)); - } - - inline Number number_from_index(const CFIndex n) - { - return Number(CFNumberCreate(kCFAllocatorDefault, kCFNumberCFIndexType, &n)); - } - - inline Data data(const void *bytes, CFIndex length) - { - return Data(CFDataCreate(kCFAllocatorDefault, (const UInt8 *)bytes, length)); - } - - inline Array array(const void **values, CFIndex numValues) - { - return Array(CFArrayCreate(kCFAllocatorDefault, values, numValues, &kCFTypeArrayCallBacks)); - } - - inline Array array(const SrcList& values) - { - return array((const void **)values.c_data(), values.size()); - } - - inline Dict dict(const void **keys, const void **values, CFIndex numValues) - { - return Dict(CFDictionaryCreate(kCFAllocatorDefault, - keys, - values, - numValues, - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks)); - } - - inline Dict dict(const SrcList& keys, const SrcList& values) - { - return dict((const void **)keys.c_data(), (const void **)values.c_data(), std::min(keys.size(), values.size())); - } - - inline Dict const_dict(MutableDict& mdict) - { - return Dict(mdict(), CF::BORROW); - } - - inline Array const_array(MutableArray& marray) - { - return Array(marray(), CF::BORROW); - } - - inline Dict empty_dict() - { - return Dict(CFDictionaryCreate(kCFAllocatorDefault, - nullptr, - nullptr, - 0, - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks)); - } - - inline MutableArray mutable_array(const CFIndex capacity=0) - { - return MutableArray(CFArrayCreateMutable(kCFAllocatorDefault, capacity, &kCFTypeArrayCallBacks)); - } - - inline MutableDict mutable_dict(const CFIndex capacity=0) - { - return MutableDict(CFDictionaryCreateMutable(kCFAllocatorDefault, capacity, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); - } - - template - inline MutableDict mutable_dict_copy(const DICT& dict, const CFIndex capacity=0) - { - if (dict.defined()) - return MutableDict(CFDictionaryCreateMutableCopy(kCFAllocatorDefault, capacity, dict())); - else - return mutable_dict(capacity); - } - - inline Error error(CFStringRef domain, CFIndex code, CFDictionaryRef userInfo) - { - return Error(CFErrorCreate(kCFAllocatorDefault, domain, code, userInfo)); - } - - // accessors - - template - inline CFIndex array_len(const ARRAY& array) - { - if (array.defined()) - return CFArrayGetCount(array()); - else - return 0; - } - - template - inline CFIndex dict_len(const DICT& dict) - { - if (dict.defined()) - return CFDictionaryGetCount(dict()); - else - return 0; - } - - template - inline CFTypeRef array_index(const ARRAY& array, const CFIndex idx) - { - if (array.defined() && CFArrayGetCount(array()) > idx) - return CFArrayGetValueAtIndex(array(), idx); - else - return nullptr; - } - - template - inline CFTypeRef dict_index(const DICT& dict, const KEY& key) - { - if (dict.defined()) - { - String keystr = string(key); - if (keystr.defined()) - return CFDictionaryGetValue(dict(), keystr()); - } - return nullptr; - } - - // string methods - - OPENVPN_SIMPLE_EXCEPTION(cppstring_error); - - inline std::string cppstring(CFStringRef str) - { - const CFStringEncoding encoding = kCFStringEncodingUTF8; - if (str) - { - const CFIndex len = CFStringGetLength(str); - if (len > 0) - { - const CFIndex maxsize = CFStringGetMaximumSizeForEncoding(len, encoding); - char *buf = new char[maxsize]; - const Boolean status = CFStringGetCString(str, buf, maxsize, encoding); - if (status) - { - std::string ret(buf); - delete [] buf; - return ret; - } - else - { - delete [] buf; - throw cppstring_error(); - } - } - } - return ""; - } - - inline std::string cppstring(const String& str) - { - return cppstring(str()); - } - - inline std::string description(CFTypeRef obj) - { - if (obj) - { - String s(CFCopyDescription(obj)); - return cppstring(s); - } - else - return "UNDEF"; - } - - // format an array of strings (non-string elements in array are ignored) - template - inline std::string array_to_string(const ARRAY& array, const char delim=',') - { - std::ostringstream os; - const CFIndex len = array_len(array); - if (len) - { - bool sep = false; - for (CFIndex i = 0; i < len; ++i) - { - const String v(string_cast(array_index(array, i))); - if (v.defined()) - { - if (sep) - os << delim; - os << cppstring(v); - sep = true; - } - } - } - return os.str(); - } - - inline bool string_equal(const String& s1, const String& s2, const CFStringCompareFlags compareOptions = 0) - { - return s1.defined() && s2.defined() && CFStringCompare(s1(), s2(), compareOptions) == kCFCompareEqualTo; - } - - // property lists - inline Data plist(CFTypeRef obj) - { - return Data(CFPropertyListCreateData(kCFAllocatorDefault, - obj, - kCFPropertyListBinaryFormat_v1_0, - 0, - nullptr)); - } - - } // namespace CF -} // namespace openvpn - -#endif // OPENVPN_APPLECRYPTO_CF_CF_H diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/cf/cfhelper.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/cf/cfhelper.hpp deleted file mode 100644 index 05e41d2..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/cf/cfhelper.hpp +++ /dev/null @@ -1,247 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_APPLECRYPTO_CF_CFHELPER_H -#define OPENVPN_APPLECRYPTO_CF_CFHELPER_H - -#include - -// These methods build on the Wrapper classes for Apple Core Foundation objects -// defined in cf.hpp. They add additional convenience methods, such as dictionary -// lookup. - -namespace openvpn { - namespace CF { - - inline CFTypeRef mutable_dict_new() - { - return CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); - } - - inline CFTypeRef mutable_array_new() - { - return CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks); - } - - // Lookup or create (if absent) an item in a mutable dictionary. - // Return the item, which will be owned by base. - template - inline CFTypeRef dict_get_create(CFMutableDictionaryRef base, - const KEY& key, - CFTypeRef (*create_method)()) - { - if (base) - { - String keystr = string(key); - CFTypeRef ret = CFDictionaryGetValue(base, keystr()); // try lookup first - if (!ret) - { - // doesn't exist, must create - ret = (*create_method)(); - CFDictionaryAddValue(base, keystr(), ret); - CFRelease(ret); // because ret is now owned by base - } - return ret; - } - return nullptr; - } - - // lookup a dict in another dict (base) and return or create if absent - template - inline MutableDict dict_get_create_dict(MutableDict& base, const KEY& key) - { - String keystr = string(key); - return mutable_dict_cast(dict_get_create(base(), keystr(), mutable_dict_new)); - } - - // lookup an array in a dict (base) and return or create if absent - template - inline MutableArray dict_get_create_array(MutableDict& base, const KEY& key) - { - String keystr = string(key); - return mutable_array_cast(dict_get_create(base(), keystr(), mutable_array_new)); - } - - // lookup an object in a dictionary (DICT should be a Dict or a MutableDict) - template - inline CFTypeRef dict_get_obj(const DICT& dict, const KEY& key) - { - return dict_index(dict, key); - } - - // lookup a string in a dictionary (DICT should be a Dict or a MutableDict) - template - inline std::string dict_get_str(const DICT& dict, const KEY& key) - { - return cppstring(string_cast(dict_index(dict, key))); - } - - // lookup a string in a dictionary (DICT should be a Dict or a MutableDict) - template - inline std::string dict_get_str(const DICT& dict, const KEY& key, const std::string& default_value) - { - String str(string_cast(dict_index(dict, key))); - if (str.defined()) - return cppstring(str()); - else - return default_value; - } - - // lookup an integer in a dictionary (DICT should be a Dict or a MutableDict) - template - inline int dict_get_int(const DICT& dict, const KEY& key, const int default_value) - { - int ret; - Number num = number_cast(dict_index(dict, key)); - if (num.defined() && CFNumberGetValue(num(), kCFNumberIntType, &ret)) - return ret; - else - return default_value; - } - - // lookup a boolean in a dictionary (DICT should be a Dict or a MutableDict) - template - inline bool dict_get_bool(const DICT& dict, const KEY& key, const bool default_value) - { - Bool b = bool_cast(dict_index(dict, key)); - if (b.defined()) - { - if (b() == kCFBooleanTrue) - return true; - else if (b() == kCFBooleanFalse) - return false; - } - return default_value; - } - - // like CFDictionarySetValue, but no-op if any args are NULL - inline void dictionarySetValue(CFMutableDictionaryRef theDict, const void *key, const void *value) - { - if (theDict && key && value) - CFDictionarySetValue(theDict, key, value); - } - - // like CFArrayAppendValue, but no-op if any args are NULL - inline void arrayAppendValue(CFMutableArrayRef theArray, const void *value) - { - if (theArray && value) - CFArrayAppendValue(theArray, value); - } - - // set a CFTypeRef in a mutable dictionary - template - inline void dict_set_obj(MutableDict& dict, const KEY& key, CFTypeRef value) - { - String keystr = string(key); - dictionarySetValue(dict(), keystr(), value); - } - - // set a string in a mutable dictionary - - template - inline void dict_set_str(MutableDict& dict, const KEY& key, const VALUE& value) - { - String keystr = string(key); - String valstr = string(value); - dictionarySetValue(dict(), keystr(), valstr()); - } - - // set a number in a mutable dictionary - - template - inline void dict_set_int(MutableDict& dict, const KEY& key, int value) - { - String keystr = string(key); - Number num = number_from_int(value); - dictionarySetValue(dict(), keystr(), num()); - } - - template - inline void dict_set_int32(MutableDict& dict, const KEY& key, SInt32 value) - { - String keystr = string(key); - Number num = number_from_int32(value); - dictionarySetValue(dict(), keystr(), num()); - } - - template - inline void dict_set_long_long(MutableDict& dict, const KEY& key, long long value) - { - String keystr = string(key); - Number num = number_from_long_long(value); - dictionarySetValue(dict(), keystr(), num()); - } - - template - inline void dict_set_index(MutableDict& dict, const KEY& key, CFIndex value) - { - String keystr = string(key); - Number num = number_from_index(value); - dictionarySetValue((CFMutableDictionaryRef)dict(), keystr(), num()); - } - - // set a boolean in a mutable dictionary - - template - inline void dict_set_bool(MutableDict& dict, const KEY& key, bool value) - { - String keystr = string(key); - CFBooleanRef boolref = value ? kCFBooleanTrue : kCFBooleanFalse; - dictionarySetValue(dict(), keystr(), boolref); - } - - // append string to a mutable array - - template - inline void array_append_str(MutableArray& array, const VALUE& value) - { - String valstr = string(value); - arrayAppendValue(array(), valstr()); - } - - // append a number to a mutable array - - inline void array_append_int(MutableArray& array, int value) - { - Number num = number_from_int(value); - arrayAppendValue(array(), num()); - } - - inline void array_append_int32(MutableArray& array, SInt32 value) - { - Number num = number_from_int32(value); - arrayAppendValue(array(), num()); - } - - inline void array_append_long_long(MutableArray& array, long long value) - { - Number num = number_from_long_long(value); - arrayAppendValue(array(), num()); - } - - inline void array_append_index(MutableArray& array, CFIndex value) - { - Number num = number_from_index(value); - arrayAppendValue(array(), num()); - } - } -} -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/cf/cfsec.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/cf/cfsec.hpp deleted file mode 100644 index cac8e75..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/cf/cfsec.hpp +++ /dev/null @@ -1,58 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_APPLECRYPTO_CF_CFSEC_H -#define OPENVPN_APPLECRYPTO_CF_CFSEC_H - -#include - -#include -#include -#include -#include - -#ifndef OPENVPN_PLATFORM_IPHONE -#include -#include -#endif - -#include -#include -#include - -// Define C++ wrappings for Apple security-related objects. - -namespace openvpn { - namespace CF { - OPENVPN_CF_WRAP(Cert, cert_cast, SecCertificateRef, SecCertificateGetTypeID) - OPENVPN_CF_WRAP(Key, key_cast, SecKeyRef, SecKeyGetTypeID) - OPENVPN_CF_WRAP(Identity, identity_cast, SecIdentityRef, SecIdentityGetTypeID) - OPENVPN_CF_WRAP(Policy, policy_cast, SecPolicyRef, SecPolicyGetTypeID) - OPENVPN_CF_WRAP(Trust, trust_cast, SecTrustRef, SecTrustGetTypeID) -#ifndef OPENVPN_PLATFORM_IPHONE - OPENVPN_CF_WRAP(Keychain, keychain_cast, SecKeychainRef, SecKeychainGetTypeID) - OPENVPN_CF_WRAP(Access, access_cast, SecAccessRef, SecAccessGetTypeID) -#endif - } // namespace CF - -} // namespace openvpn - -#endif // OPENVPN_APPLECRYPTO_CF_CFSEC_H diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/cf/cftimer.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/cf/cftimer.hpp deleted file mode 100644 index 4585d7b..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/cf/cftimer.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_APPLECRYPTO_CF_CFTIMER_H -#define OPENVPN_APPLECRYPTO_CF_CFTIMER_H - -#include - -namespace openvpn { - namespace CF { - OPENVPN_CF_WRAP(Timer, timer_cast, CFRunLoopTimerRef, CFRunLoopTimerGetTypeID) - } -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/cf/error.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/cf/error.hpp deleted file mode 100644 index 7628b0f..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/cf/error.hpp +++ /dev/null @@ -1,67 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_APPLECRYPTO_CF_ERROR_H -#define OPENVPN_APPLECRYPTO_CF_ERROR_H - -#include - -#include - -#include - -// An exception object that encapsulates Apple Core Foundation errors. - -namespace openvpn { - - // string exception class - class CFException : public std::exception - { - public: - CFException(const std::string& text) - { - errtxt = text; - } - - CFException(const std::string& text, const OSStatus status) - { - set_errtxt(text, status); - } - - virtual const char* what() const throw() { return errtxt.c_str(); } - std::string what_str() const { return errtxt; } - - virtual ~CFException() throw() {} - - private: - void set_errtxt(const std::string& text, const OSStatus status) - { - std::ostringstream s; - s << text << ": OSX Error code=" << status; - errtxt = s.str(); - } - - std::string errtxt; - }; - -} // namespace openvpn - -#endif // OPENVPN_APPLECRYPTO_CF_ERROR_H diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/crypto/api.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/crypto/api.hpp deleted file mode 100644 index 12826ac..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/crypto/api.hpp +++ /dev/null @@ -1,46 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_APPLECRYPTO_CRYPTO_API_H -#define OPENVPN_APPLECRYPTO_CRYPTO_API_H - -#include -#include -#include -#include - -namespace openvpn { - - // type container for Apple Crypto-level API - struct AppleCryptoAPI { - // cipher - typedef AppleCrypto::CipherContext CipherContext; - typedef AppleCrypto::CipherContextGCM CipherContextGCM; - - // digest - typedef AppleCrypto::DigestContext DigestContext; - - // HMAC - typedef AppleCrypto::HMACContext HMACContext; - }; -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/crypto/cipher.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/crypto/cipher.hpp deleted file mode 100644 index c0f75e5..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/crypto/cipher.hpp +++ /dev/null @@ -1,200 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -// Wrap the Apple cipher API defined in so -// that it can be used as part of the crypto layer of the OpenVPN core. - -#ifndef OPENVPN_APPLECRYPTO_CRYPTO_CIPHER_H -#define OPENVPN_APPLECRYPTO_CRYPTO_CIPHER_H - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace openvpn { - namespace AppleCrypto { - class CipherContext - { - CipherContext(const CipherContext&) = delete; - CipherContext& operator=(const CipherContext&) = delete; - - public: - OPENVPN_SIMPLE_EXCEPTION(apple_cipher_mode_error); - OPENVPN_SIMPLE_EXCEPTION(apple_cipher_uninitialized); - OPENVPN_EXCEPTION(apple_cipher_error); - - // mode parameter for constructor - enum { - MODE_UNDEF = -1, - ENCRYPT = kCCEncrypt, - DECRYPT = kCCDecrypt - }; - - enum { - MAX_IV_LENGTH = 16, - CIPH_CBC_MODE = 0 - }; - - CipherContext() - : cinfo(nullptr), cref(nullptr) - { - } - - ~CipherContext() { erase() ; } - - void init(const CryptoAlgs::Type alg, const unsigned char *key, const int mode) - { - erase(); - - // check that mode is valid - if (!(mode == ENCRYPT || mode == DECRYPT)) - throw apple_cipher_mode_error(); - - // initialize cipher context with cipher type - const CCCryptorStatus status = CCCryptorCreate(mode, - cipher_type(alg), - kCCOptionPKCS7Padding, - key, - CryptoAlgs::key_length(alg), - nullptr, - &cref); - if (status != kCCSuccess) - throw CFException("CipherContext: CCCryptorCreate", status); - - cinfo = CryptoAlgs::get_ptr(alg); - } - - void reset(const unsigned char *iv) - { - check_initialized(); - const CCCryptorStatus status = CCCryptorReset(cref, iv); - if (status != kCCSuccess) - throw CFException("CipherContext: CCCryptorReset", status); - } - - bool update(unsigned char *out, const size_t max_out_size, - const unsigned char *in, const size_t in_size, - size_t& out_acc) - { - check_initialized(); - size_t dataOutMoved; - const CCCryptorStatus status = CCCryptorUpdate(cref, in, in_size, out, max_out_size, &dataOutMoved); - if (status == kCCSuccess) - { - out_acc += dataOutMoved; - return true; - } - else - return false; - } - - bool final(unsigned char *out, const size_t max_out_size, size_t& out_acc) - { - check_initialized(); - size_t dataOutMoved; - const CCCryptorStatus status = CCCryptorFinal(cref, out, max_out_size, &dataOutMoved); - if (status == kCCSuccess) - { - out_acc += dataOutMoved; - return true; - } - else - return false; - } - - bool is_initialized() const { return cinfo != nullptr; } - - size_t iv_length() const - { - check_initialized(); - return cinfo->iv_length(); - } - - size_t block_size() const - { - check_initialized(); - return cinfo->block_size(); - } - - // return cipher mode (such as CIPH_CBC_MODE, etc.) - int cipher_mode() const - { - check_initialized(); - return CIPH_CBC_MODE; - } - - private: - static CCAlgorithm cipher_type(const CryptoAlgs::Type alg) - { - switch (alg) - { - case CryptoAlgs::AES_128_CBC: - case CryptoAlgs::AES_192_CBC: - case CryptoAlgs::AES_256_CBC: - return kCCAlgorithmAES128; - case CryptoAlgs::DES_CBC: - return kCCAlgorithmDES; - case CryptoAlgs::DES_EDE3_CBC: - return kCCAlgorithm3DES; -#ifdef OPENVPN_PLATFORM_IPHONE - case CryptoAlgs::BF_CBC: - return kCCAlgorithmBlowfish; -#endif - default: - OPENVPN_THROW(apple_cipher_error, CryptoAlgs::name(alg) << ": not usable"); - } - } - - void erase() - { - if (cinfo) - { - if (cref) - CCCryptorRelease(cref); - cref = nullptr; - cinfo = nullptr; - } - } - - void check_initialized() const - { -#ifdef OPENVPN_ENABLE_ASSERT - if (!cinfo) - throw apple_cipher_uninitialized(); -#endif - } - - const CryptoAlgs::Alg* cinfo; - CCCryptorRef cref; - }; - } -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/crypto/digest.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/crypto/digest.hpp deleted file mode 100644 index 68a6dd3..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/crypto/digest.hpp +++ /dev/null @@ -1,255 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -// Wrap the Apple digest API defined in -// so that it can be used as part of the crypto layer of the OpenVPN core. - -#ifndef OPENVPN_APPLECRYPTO_CRYPTO_DIGEST_H -#define OPENVPN_APPLECRYPTO_CRYPTO_DIGEST_H - -#include - -#include -#include - -#include -#include -#include -#include -#include - -#define OPENVPN_DIGEST_CONTEXT(TYPE) CC_##TYPE##_CTX TYPE##_ctx - -#define OPENVPN_DIGEST_ALG_CLASS(TYPE) \ - class DigestAlgorithm##TYPE : public DigestAlgorithm \ - { \ - public: \ - DigestAlgorithm##TYPE() {} \ - virtual int init(DigestCTX& ctx) const \ - { \ - return CC_##TYPE##_Init(&ctx.u.TYPE##_ctx); \ - } \ - virtual int update(DigestCTX& ctx, const unsigned char *data, size_t size) const \ - { \ - return CC_##TYPE##_Update(&ctx.u.TYPE##_ctx, data, size); \ - } \ - virtual int final(DigestCTX& ctx, unsigned char *md) const \ - { \ - return CC_##TYPE##_Final(md, &ctx.u.TYPE##_ctx); \ - } \ - } - -#define OPENVPN_DIGEST_ALG_DECLARE(TYPE) const DigestAlgorithm##TYPE alg_##TYPE; - -#define OPENVPN_DIGEST_INFO_DECLARE(TYPE) const DigestInfo info_##TYPE(CryptoAlgs::TYPE, &alg_##TYPE, kCCHmacAlg##TYPE) - -#define OPENVPN_DIGEST_INFO_DECLARE_NO_HMAC(TYPE) const DigestInfo info_##TYPE(CryptoAlgs::TYPE, &alg_##TYPE, DigestInfo::NO_HMAC_ALG) - -namespace openvpn { - namespace AppleCrypto { - typedef CC_SHA256_CTX CC_SHA224_CTX; - typedef CC_SHA512_CTX CC_SHA384_CTX; - - struct DigestCTX { - union { - OPENVPN_DIGEST_CONTEXT(MD4); - OPENVPN_DIGEST_CONTEXT(MD5); - OPENVPN_DIGEST_CONTEXT(SHA1); - OPENVPN_DIGEST_CONTEXT(SHA224); - OPENVPN_DIGEST_CONTEXT(SHA256); - OPENVPN_DIGEST_CONTEXT(SHA384); - OPENVPN_DIGEST_CONTEXT(SHA512); - } u; - }; - - struct DigestAlgorithm { - virtual int init(DigestCTX& ctx) const = 0; - virtual int update(DigestCTX& ctx, const unsigned char *data, size_t size) const = 0; - virtual int final(DigestCTX& ctx, unsigned char *md) const = 0; - }; - - // individual digest algorithm classes (each inherits from DigestAlgorithm) - OPENVPN_DIGEST_ALG_CLASS(MD4); - OPENVPN_DIGEST_ALG_CLASS(MD5); - OPENVPN_DIGEST_ALG_CLASS(SHA1); - OPENVPN_DIGEST_ALG_CLASS(SHA224); - OPENVPN_DIGEST_ALG_CLASS(SHA256); - OPENVPN_DIGEST_ALG_CLASS(SHA384); - OPENVPN_DIGEST_ALG_CLASS(SHA512); - - class DigestInfo - { - public: - enum { - NO_HMAC_ALG = -1 - }; - - DigestInfo(CryptoAlgs::Type type, - const DigestAlgorithm* digest_alg, - const CCHmacAlgorithm hmac_alg) - : type_(type), - digest_alg_(digest_alg), - hmac_alg_(hmac_alg) {} - - CryptoAlgs::Type type() const { return type_; } - const char *name() const { return CryptoAlgs::name(type_); } - size_t size() const { return CryptoAlgs::size(type_); } - const DigestAlgorithm* digest_alg() const { return digest_alg_; } - CCHmacAlgorithm hmac_alg() const { return hmac_alg_; } - - private: - CryptoAlgs::Type type_; - const DigestAlgorithm* digest_alg_; - CCHmacAlgorithm hmac_alg_; - }; - - // instantiate individual digest algorithm class instances (each inherits from DigestAlgorithm), - // naming convention is alg_TYPE - OPENVPN_DIGEST_ALG_DECLARE(MD4); - OPENVPN_DIGEST_ALG_DECLARE(MD5); - OPENVPN_DIGEST_ALG_DECLARE(SHA1); - OPENVPN_DIGEST_ALG_DECLARE(SHA224); - OPENVPN_DIGEST_ALG_DECLARE(SHA256); - OPENVPN_DIGEST_ALG_DECLARE(SHA384); - OPENVPN_DIGEST_ALG_DECLARE(SHA512); - - // instantiate individual digest info class instances (each is a DigestInfo), - // naming convention is info_TYPE - OPENVPN_DIGEST_INFO_DECLARE_NO_HMAC(MD4); - OPENVPN_DIGEST_INFO_DECLARE(MD5); - OPENVPN_DIGEST_INFO_DECLARE(SHA1); - OPENVPN_DIGEST_INFO_DECLARE(SHA224); - OPENVPN_DIGEST_INFO_DECLARE(SHA256); - OPENVPN_DIGEST_INFO_DECLARE(SHA384); - OPENVPN_DIGEST_INFO_DECLARE(SHA512); - - class HMACContext; - - class DigestContext - { - DigestContext(const DigestContext&) = delete; - DigestContext& operator=(const DigestContext&) = delete; - - public: - friend class HMACContext; - - OPENVPN_SIMPLE_EXCEPTION(apple_digest_uninitialized); - OPENVPN_SIMPLE_EXCEPTION(apple_digest_final_overflow); - OPENVPN_EXCEPTION(apple_digest_error); - - enum { - MAX_DIGEST_SIZE = CC_SHA512_DIGEST_LENGTH // largest known is SHA512 - }; - - DigestContext() - { - clear(); - } - - DigestContext(const CryptoAlgs::Type alg) - { - init(alg); - } - - void init(const CryptoAlgs::Type alg) - { - clear(); - info = digest_type(alg); - meth = info->digest_alg(); - if (meth->init(ctx) != 1) - throw apple_digest_error("init"); - initialized = true; - } - - void update(const unsigned char *in, const size_t size) - { - check_initialized(); - if (meth->update(ctx, in, size) != 1) - throw apple_digest_error("update"); - } - - size_t final(unsigned char *out) - { - check_initialized(); - if (meth->final(ctx, out) != 1) - throw apple_digest_error("final"); - return info->size(); - } - - size_t size() const - { - check_initialized(); - return info->size(); - } - - bool is_initialized() const { return initialized; } - - private: - static const DigestInfo *digest_type(const CryptoAlgs::Type alg) - { - switch (alg) - { - case CryptoAlgs::MD4: - return &info_MD4; - case CryptoAlgs::MD5: - return &info_MD5; - case CryptoAlgs::SHA1: - return &info_SHA1; - case CryptoAlgs::SHA224: - return &info_SHA224; - case CryptoAlgs::SHA256: - return &info_SHA256; - case CryptoAlgs::SHA384: - return &info_SHA384; - case CryptoAlgs::SHA512: - return &info_SHA512; - default: - OPENVPN_THROW(apple_digest_error, CryptoAlgs::name(alg) << ": not usable"); - } - } - - void clear() - { - initialized = false; - } - - void check_initialized() const - { -#ifdef OPENVPN_ENABLE_ASSERT - if (!initialized) - throw apple_digest_uninitialized(); -#endif - } - - bool initialized; - const DigestInfo *info; - const DigestAlgorithm *meth; - DigestCTX ctx; - }; - } -} - -#undef OPENVPN_DIGEST_CONTEXT -#undef OPENVPN_DIGEST_ALG_CLASS -#undef OPENVPN_DIGEST_ALG_DECLARE -#undef OPENVPN_DIGEST_INFO_DECLARE - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/crypto/hmac.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/crypto/hmac.hpp deleted file mode 100644 index 66d308f..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/crypto/hmac.hpp +++ /dev/null @@ -1,145 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_APPLECRYPTO_CRYPTO_HMAC_H -#define OPENVPN_APPLECRYPTO_CRYPTO_HMAC_H - -// Wrap the Apple HMAC API defined in so that -// it can be used as part of the crypto layer of the OpenVPN core. - -#include -#include - -#include - -#include -#include -#include - -namespace openvpn { - namespace AppleCrypto { - class HMACContext - { - HMACContext(const HMACContext&) = delete; - HMACContext& operator=(const HMACContext&) = delete; - - public: - OPENVPN_EXCEPTION(digest_cannot_be_used_with_hmac); - OPENVPN_SIMPLE_EXCEPTION(hmac_uninitialized); - OPENVPN_SIMPLE_EXCEPTION(hmac_keysize_error); - - enum { - MAX_HMAC_SIZE = DigestContext::MAX_DIGEST_SIZE, - MAX_HMAC_KEY_SIZE = 128, - }; - - HMACContext() - { - state = PRE; - } - - HMACContext(const CryptoAlgs::Type digest, const unsigned char *key, const size_t key_size) - { - init(digest, key, key_size); - } - - ~HMACContext() - { - } - - void init(const CryptoAlgs::Type digest, const unsigned char *key, const size_t key_size) - { - state = PRE; - info = DigestContext::digest_type(digest); - digest_size_ = CryptoAlgs::size(digest); - hmac_alg = info->hmac_alg(); - if (hmac_alg == DigestInfo::NO_HMAC_ALG) - throw digest_cannot_be_used_with_hmac(info->name()); - if (key_size > MAX_HMAC_KEY_SIZE) - throw hmac_keysize_error(); - std::memcpy(key_, key, key_size_ = key_size); - state = PARTIAL; - } - - void reset() // Apple HMAC API is missing reset method, so we have to reinit - { - cond_reset(true); - } - - void update(const unsigned char *in, const size_t size) - { - cond_reset(false); - CCHmacUpdate(&ctx, in, size); - } - - size_t final(unsigned char *out) - { - cond_reset(false); - CCHmacFinal(&ctx, out); - return digest_size_; - } - - size_t size() const - { - if (!is_initialized()) - throw hmac_uninitialized(); - return digest_size_; - } - - bool is_initialized() const - { - return state >= PARTIAL; - } - - private: - void cond_reset(const bool force_init) - { - switch (state) - { - case PRE: - throw hmac_uninitialized(); - case READY: - if (!force_init) - return; - case PARTIAL: - CCHmacInit(&ctx, hmac_alg, key_, key_size_); - state = READY; - } - } - - enum State { - PRE=0, - PARTIAL, - READY - }; - int state; - - const DigestInfo *info; - CCHmacAlgorithm hmac_alg; - size_t key_size_; - size_t digest_size_; - unsigned char key_[MAX_HMAC_KEY_SIZE]; - CCHmacContext ctx; - }; - } -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/ssl/sslctx.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/ssl/sslctx.hpp deleted file mode 100644 index 7c73dd6..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/ssl/sslctx.hpp +++ /dev/null @@ -1,493 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -// Wrap the Apple SSL API as defined in -// so that it can be used as the SSL layer by the OpenVPN core. -// NOTE: not used in production code. - -// Note that the Apple SSL API is missing some functionality (as of -// Mac OS X 10.8) that makes it difficult to use as a drop in replacement -// for OpenSSL or PolarSSL. The biggest issue is that the API doesn't -// allow an SSL context to be built out of PEM-based certificates and -// keys. It requires an "Identity" in the Keychain that was imported -// by the user as a PKCS#12 file. - -#ifndef OPENVPN_APPLECRYPTO_SSL_SSLCTX_H -#define OPENVPN_APPLECRYPTO_SSL_SSLCTX_H - -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// An SSL Context is essentially a configuration that can be used -// to generate an arbitrary number of actual SSL connections objects. - -// AppleSSLContext is an SSL Context implementation that uses the -// Mac/iOS SSL library as a backend. - -namespace openvpn { - - // Represents an SSL configuration that can be used - // to instantiate actual SSL sessions. - class AppleSSLContext : public SSLFactoryAPI - { - public: - typedef RCPtr Ptr; - - enum { - MAX_CIPHERTEXT_IN = 64 - }; - - // The data needed to construct an AppleSSLContext. - class Config : public SSLConfigAPI - { - friend class AppleSSLContext; - - public: - typedef RCPtr Ptr; - - Config() {} - - void load_identity(const std::string& subject_match) - { - identity = load_identity_(subject_match); - if (!identity()) - OPENVPN_THROW(ssl_context_error, "AppleSSLContext: identity '" << subject_match << "' undefined"); - } - - virtual SSLFactoryAPI::Ptr new_factory() - { - return SSLFactoryAPI::Ptr(new AppleSSLContext(this)); - } - - virtual void set_mode(const Mode& mode_arg) - { - mode = mode_arg; - } - - virtual const Mode& get_mode() const - { - return mode; - } - - virtual void set_frame(const Frame::Ptr& frame_arg) - { - frame = frame_arg; - } - - virtual void load(const OptionList& opt, const unsigned int lflags) - { - // client/server - if (lflags & LF_PARSE_MODE) - mode = opt.exists("client") ? Mode(Mode::CLIENT) : Mode(Mode::SERVER); - - // identity - { - const std::string& subject_match = opt.get("identity", 1, 256); - load_identity(subject_match); - } - } - - virtual void set_external_pki_callback(ExternalPKIBase* external_pki_arg) - { - not_implemented("set_external_pki_callback"); - } - - virtual void set_private_key_password(const std::string& pwd) - { - return not_implemented("set_private_key_password"); - } - - virtual void load_ca(const std::string& ca_txt, bool strict) - { - return not_implemented("load_ca"); - } - - virtual void load_crl(const std::string& crl_txt) - { - return not_implemented("load_crl"); - } - - virtual void load_cert(const std::string& cert_txt) - { - return not_implemented("load_cert"); - } - - virtual void load_cert(const std::string& cert_txt, const std::string& extra_certs_txt) - { - return not_implemented("load_cert"); - } - - virtual void load_private_key(const std::string& key_txt) - { - return not_implemented("load_private_key"); - } - - virtual void load_dh(const std::string& dh_txt) - { - return not_implemented("load_dh"); - } - - virtual void set_debug_level(const int debug_level) - { - return not_implemented("set_debug_level"); - } - - virtual void set_flags(const unsigned int flags_arg) - { - return not_implemented("set_flags"); - } - - virtual void set_ns_cert_type(const NSCert::Type ns_cert_type_arg) - { - return not_implemented("set_ns_cert_type"); - } - - virtual void set_remote_cert_tls(const KUParse::TLSWebType wt) - { - return not_implemented("set_remote_cert_tls"); - } - - virtual void set_tls_remote(const std::string& tls_remote_arg) - { - return not_implemented("set_tls_remote"); - } - - virtual void set_tls_version_min(const TLSVersion::Type tvm) - { - return not_implemented("set_tls_version_min"); - } - - virtual void set_local_cert_enabled(const bool v) - { - return not_implemented("set_local_cert_enabled"); - } - - virtual void set_enable_renegotiation(const bool v) - { - return not_implemented("set_enable_renegotiation"); - } - - virtual void set_force_aes_cbc_ciphersuites(const bool v) - { - return not_implemented("set_force_aes_cbc_ciphersuites"); - } - - virtual void set_rng(const RandomAPI::Ptr& rng_arg) - { - return not_implemented("set_rng"); - } - - private: - void not_implemented(const char *funcname) - { - OPENVPN_LOG("AppleSSL: " << funcname << " not implemented"); - } - - Mode mode; - CF::Array identity; // as returned by load_identity - Frame::Ptr frame; - }; - - // Represents an actual SSL session. - // Normally instantiated by AppleSSLContext::ssl(). - class SSL : public SSLAPI - { - friend class AppleSSLContext; - - public: - typedef RCPtr Ptr; - - virtual void start_handshake() - { - SSLHandshake(ssl); - } - - virtual ssize_t write_cleartext_unbuffered(const void *data, const size_t size) - { - size_t actual = 0; - const OSStatus status = SSLWrite(ssl, data, size, &actual); - if (status < 0) - { - if (status == errSSLWouldBlock) - return SSLConst::SHOULD_RETRY; - else - throw CFException("AppleSSLContext::SSL::write_cleartext failed", status); - } - else - return actual; - } - - virtual ssize_t read_cleartext(void *data, const size_t capacity) - { - if (!overflow) - { - size_t actual = 0; - const OSStatus status = SSLRead(ssl, data, capacity, &actual); - if (status < 0) - { - if (status == errSSLWouldBlock) - return SSLConst::SHOULD_RETRY; - else - throw CFException("AppleSSLContext::SSL::read_cleartext failed", status); - } - else - return actual; - } - else - throw ssl_ciphertext_in_overflow(); - } - - virtual bool read_cleartext_ready() const - { - // fixme: need to detect data buffered at SSL layer - return !ct_in.empty(); - } - - virtual void write_ciphertext(const BufferPtr& buf) - { - if (ct_in.size() < MAX_CIPHERTEXT_IN) - ct_in.write_buf(buf); - else - overflow = true; - } - - virtual bool read_ciphertext_ready() const - { - return !ct_out.empty(); - } - - virtual BufferPtr read_ciphertext() - { - return ct_out.read_buf(); - } - - virtual std::string ssl_handshake_details() const // fixme -- code me - { - return "[AppleSSL not implemented]"; - } - - virtual const AuthCert::Ptr& auth_cert() const - { - OPENVPN_THROW(ssl_context_error, "AppleSSL::SSL: auth_cert() not implemented"); - } - - ~SSL() - { - ssl_erase(); - } - - private: - SSL(const AppleSSLContext& ctx) - { - ssl_clear(); - try { - OSStatus s; - -#ifdef OPENVPN_PLATFORM_IPHONE - // init SSL object, select client or server mode - if (ctx.mode().is_server()) - ssl = SSLCreateContext(kCFAllocatorDefault, kSSLServerSide, kSSLStreamType); - else if (ctx.mode().is_client()) - ssl = SSLCreateContext(kCFAllocatorDefault, kSSLClientSide, kSSLStreamType); - else - OPENVPN_THROW(ssl_context_error, "AppleSSLContext::SSL: unknown client/server mode"); - if (ssl == nullptr) - throw CFException("SSLCreateContext failed"); - - // use TLS v1 - s = SSLSetProtocolVersionMin(ssl, kTLSProtocol1); - if (s) - throw CFException("SSLSetProtocolVersionMin failed", s); -#else - // init SSL object, select client or server mode - if (ctx.mode().is_server()) - s = SSLNewContext(true, &ssl); - else if (ctx.mode().is_client()) - s = SSLNewContext(false, &ssl); - else - OPENVPN_THROW(ssl_context_error, "AppleSSLContext::SSL: unknown client/server mode"); - if (s) - throw CFException("SSLNewContext failed", s); - - // use TLS v1 - s = SSLSetProtocolVersionEnabled(ssl, kSSLProtocol2, false); - if (s) - throw CFException("SSLSetProtocolVersionEnabled !S2 failed", s); - s = SSLSetProtocolVersionEnabled(ssl, kSSLProtocol3, false); - if (s) - throw CFException("SSLSetProtocolVersionEnabled !S3 failed", s); - s = SSLSetProtocolVersionEnabled(ssl, kTLSProtocol1, true); - if (s) - throw CFException("SSLSetProtocolVersionEnabled T1 failed", s); -#endif - // configure cert, private key, and supporting CAs via identity wrapper - s = SSLSetCertificate(ssl, ctx.identity()()); - if (s) - throw CFException("SSLSetCertificate failed", s); - - // configure ciphertext buffers - ct_in.set_frame(ctx.frame()); - ct_out.set_frame(ctx.frame()); - - // configure the "connection" object to be self - s = SSLSetConnection(ssl, this); - if (s) - throw CFException("SSLSetConnection", s); - - // configure ciphertext read/write callbacks - s = SSLSetIOFuncs(ssl, ct_read_func, ct_write_func); - if (s) - throw CFException("SSLSetIOFuncs failed", s); - } - catch (...) - { - ssl_erase(); - throw; - } - } - - static OSStatus ct_read_func(SSLConnectionRef cref, void *data, size_t *length) - { - try { - SSL *self = (SSL *)cref; - const size_t actual = self->ct_in.read((unsigned char *)data, *length); - const OSStatus ret = (*length == actual) ? 0 : errSSLWouldBlock; - *length = actual; - return ret; - } - catch (...) - { - return errSSLInternal; - } - } - - static OSStatus ct_write_func(SSLConnectionRef cref, const void *data, size_t *length) - { - try { - SSL *self = (SSL *)cref; - self->ct_out.write((const unsigned char *)data, *length); - return 0; - } - catch (...) - { - return errSSLInternal; - } - } - - void ssl_clear() - { - ssl = nullptr; - overflow = false; - } - - void ssl_erase() - { - if (ssl) - { -#ifdef OPENVPN_PLATFORM_IPHONE - CFRelease(ssl); -#else - SSLDisposeContext(ssl); -#endif - } - ssl_clear(); - } - - SSLContextRef ssl; // underlying SSL connection object - MemQStream ct_in; // write ciphertext to here - MemQStream ct_out; // read ciphertext from here - bool overflow; - }; - - /////// start of main class implementation - - // create a new SSL instance - virtual SSLAPI::Ptr ssl() - { - return SSL::Ptr(new SSL(*this)); - } - - // like ssl() above but verify hostname against cert CommonName and/or SubjectAltName - virtual SSLAPI::Ptr ssl(const std::string& hostname) - { - OPENVPN_THROW(ssl_context_error, "AppleSSLContext: ssl session with CommonName and/or SubjectAltName verification not implemented"); - } - - virtual const Mode& mode() const - { - return config_->mode; - } - - private: - AppleSSLContext(Config* config) - : config_(config) - { - if (!config_->identity()) - OPENVPN_THROW(ssl_context_error, "AppleSSLContext: identity undefined"); - } - - const Frame::Ptr& frame() const { return config_->frame; } - const CF::Array& identity() const { return config_->identity; } - - // load an identity from keychain, return as an array that can - // be passed to SSLSetCertificate - static CF::Array load_identity_(const std::string& subj_match) - { - const CF::String label = CF::string(subj_match); - const void *keys[] = { kSecClass, kSecMatchSubjectContains, kSecMatchTrustedOnly, kSecReturnRef }; - const void *values[] = { kSecClassIdentity, label(), kCFBooleanTrue, kCFBooleanTrue }; - const CF::Dict query = CF::dict(keys, values, sizeof(keys)/sizeof(keys[0])); - CF::Generic result; - const OSStatus s = SecItemCopyMatching(query(), result.mod_ref()); - if (!s && result.defined()) - { - const void *asrc[] = { result() }; - return CF::array(asrc, 1); - } - else - return CF::Array(); // not found - } - - Config::Ptr config_; - }; - - typedef AppleSSLContext::Ptr AppleSSLContextPtr; - -} // namespace openvpn - -#endif // OPENVPN_APPLECRYPTO_SSL_SSLCTX_H diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/util/iosactiveiface.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/util/iosactiveiface.hpp deleted file mode 100644 index c022ac3..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/util/iosactiveiface.hpp +++ /dev/null @@ -1,74 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#include - -#include -#include - -#ifndef OPENVPN_APPLECRYPTO_UTIL_IOSACTIVEIFACE_H -#define OPENVPN_APPLECRYPTO_UTIL_IOSACTIVEIFACE_H - -namespace openvpn { - - class iOSActiveInterface : public ReachabilityInterface - { - public: - virtual Status reachable() const - { - if (ei.iface_up("en0")) - return ReachableViaWiFi; - else if (ei.iface_up("pdp_ip0")) - return ReachableViaWWAN; - else - return NotReachable; - } - - virtual bool reachableVia(const std::string& net_type) const - { - const Status r = reachable(); - if (net_type == "cellular") - return r == ReachableViaWWAN; - else if (net_type == "wifi") - return r == ReachableViaWiFi; - else - return r != NotReachable; - } - - virtual std::string to_string() const - { - switch (reachable()) - { - case ReachableViaWiFi: - return "ReachableViaWiFi"; - case ReachableViaWWAN: - return "ReachableViaWWAN"; - case NotReachable: - return "NotReachable"; - } - } - - private: - EnumIface ei; - }; - -} -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/util/rand.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/util/rand.hpp deleted file mode 100644 index 92602a7..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/util/rand.hpp +++ /dev/null @@ -1,72 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -// Wrap the Apple Cryptographic Random API defined in -// so that it can be used as the primary source of cryptographic entropy by -// the OpenVPN core. - -#ifndef OPENVPN_APPLECRYPTO_UTIL_RAND_H -#define OPENVPN_APPLECRYPTO_UTIL_RAND_H - -#include - -#include - -namespace openvpn { - class AppleRandom : public RandomAPI - { - public: - OPENVPN_EXCEPTION(rand_error_apple); - - typedef RCPtr Ptr; - - AppleRandom(const bool prng) - { - } - - virtual std::string name() const - { - return "AppleRandom"; - } - - // Fill buffer with random bytes - virtual void rand_bytes(unsigned char *buf, size_t size) - { - if (!rndbytes(buf, size)) - throw rand_error_apple("rand_bytes"); - } - - // Like rand_bytes, but don't throw exception. - // Return true on successs, false on fail. - virtual bool rand_bytes_noexcept(unsigned char *buf, size_t size) - { - return rndbytes(buf, size); - } - - private: - bool rndbytes(unsigned char *buf, size_t size) - { - return SecRandomCopyBytes(kSecRandomDefault, size, buf) ? false : true; - } - }; -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/util/reach.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/util/reach.hpp deleted file mode 100644 index cb05389..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/util/reach.hpp +++ /dev/null @@ -1,43 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_APPLECRYPTO_UTIL_REACH_H -#define OPENVPN_APPLECRYPTO_UTIL_REACH_H - -// An interface to various network reachability implementations, -// primarily for iOS. - -namespace openvpn { - struct ReachabilityInterface - { - enum Status { - NotReachable, - ReachableViaWiFi, - ReachableViaWWAN - }; - - virtual Status reachable() const = 0; - virtual bool reachableVia(const std::string& net_type) const = 0; - virtual std::string to_string() const = 0; - virtual ~ReachabilityInterface() {} - }; -} -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/util/reachable.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/util/reachable.hpp deleted file mode 100644 index ae95327..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/applecrypto/util/reachable.hpp +++ /dev/null @@ -1,466 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . -// -// This code is derived from the Apple sample Reachability.m under -// the following license. -// -// Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple -// Inc. ("Apple") in consideration of your agreement to the following -// terms, and your use, installation, modification or redistribution of -// this Apple software constitutes acceptance of these terms. If you do -// not agree with these terms, please do not use, install, modify or -// redistribute this Apple software. -// -// In consideration of your agreement to abide by the following terms, and -// subject to these terms, Apple grants you a personal, non-exclusive -// license, under Apple's copyrights in this original Apple software (the -// "Apple Software"), to use, reproduce, modify and redistribute the Apple -// Software, with or without modifications, in source and/or binary forms; -// provided that if you redistribute the Apple Software in its entirety and -// without modifications, you must retain this notice and the following -// text and disclaimers in all such redistributions of the Apple Software. -// Neither the name, trademarks, service marks or logos of Apple Inc. may -// be used to endorse or promote products derived from the Apple Software -// without specific prior written permission from Apple. Except as -// expressly stated in this notice, no other rights or licenses, express or -// implied, are granted by Apple herein, including but not limited to any -// patent rights that may be infringed by your derivative works or by other -// works in which the Apple Software may be incorporated. -// -// The Apple Software is provided by Apple on an "AS IS" basis. APPLE -// MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION -// THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS -// FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND -// OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. -// -// IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL -// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, -// MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED -// AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), -// STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -// Copyright (C) 2013 Apple Inc. All Rights Reserved. - -// Wrapper for Apple SCNetworkReachability methods. - -#ifndef OPENVPN_APPLECRYPTO_UTIL_REACHABLE_H -#define OPENVPN_APPLECRYPTO_UTIL_REACHABLE_H - -#import "TargetConditionals.h" - -#include -#include - -#include -#include -#include - -#include -#include -#include - -namespace openvpn { - namespace CF { - OPENVPN_CF_WRAP(NetworkReachability, network_reachability_cast, SCNetworkReachabilityRef, SCNetworkReachabilityGetTypeID); - } - - class ReachabilityBase - { - public: - typedef ReachabilityInterface::Status Status; - - enum Type { - Internet, - WiFi, - }; - - std::string to_string() const - { - return to_string(flags()); - } - - std::string to_string(const SCNetworkReachabilityFlags f) const - { - const Status s = vstatus(f); - const Type t = vtype(); - - std::string ret; - ret += render_type(t); - ret += ':'; - ret += render_status(s); - ret += '/'; - ret += render_flags(f); - return ret; - } - - Status status() const - { - return vstatus(flags()); - } - - SCNetworkReachabilityFlags flags() const - { - SCNetworkReachabilityFlags f = 0; - if (SCNetworkReachabilityGetFlags(reach(), &f) == TRUE) - return f; - else - return 0; - } - - static std::string render_type(Type type) - { - switch (type) { - case Internet: - return "Internet"; - case WiFi: - return "WiFi"; - default: - return "Type???"; - } - } - - static std::string render_status(const Status status) - { - switch (status) { - case ReachabilityInterface::NotReachable: - return "NotReachable"; - case ReachabilityInterface::ReachableViaWiFi: - return "ReachableViaWiFi"; - case ReachabilityInterface::ReachableViaWWAN: - return "ReachableViaWWAN"; - default: - return "ReachableVia???"; - } - } - - static std::string render_flags(const SCNetworkReachabilityFlags flags) - { - std::string ret; -#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR // Mac OS X doesn't define WWAN flags - if (flags & kSCNetworkReachabilityFlagsIsWWAN) - ret += 'W'; - else -#endif - ret += '-'; - if (flags & kSCNetworkReachabilityFlagsReachable) - ret += 'R'; - else - ret += '-'; - ret += ' '; - if (flags & kSCNetworkReachabilityFlagsTransientConnection) - ret += 't'; - else - ret += '-'; - if (flags & kSCNetworkReachabilityFlagsConnectionRequired) - ret += 'c'; - else - ret += '-'; - if (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) - ret += 'C'; - else - ret += '-'; - if (flags & kSCNetworkReachabilityFlagsInterventionRequired) - ret += 'i'; - else - ret += '-'; - if (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) - ret += 'D'; - else - ret += '-'; - if (flags & kSCNetworkReachabilityFlagsIsLocalAddress) - ret += 'l'; - else - ret += '-'; - if (flags & kSCNetworkReachabilityFlagsIsDirect) - ret += 'd'; - else - ret += '-'; - return ret; - } - - virtual Type vtype() const = 0; - virtual Status vstatus(const SCNetworkReachabilityFlags flags) const = 0; - - CF::NetworkReachability reach; - }; - - class ReachabilityViaInternet : public ReachabilityBase - { - public: - ReachabilityViaInternet() - { - struct sockaddr_in addr; - bzero(&addr, sizeof(addr)); - addr.sin_len = sizeof(addr); - addr.sin_family = AF_INET; - reach.reset(SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (struct sockaddr*)&addr)); - } - - virtual Type vtype() const - { - return Internet; - } - - virtual Status vstatus(const SCNetworkReachabilityFlags flags) const - { - return status_from_flags(flags); - } - - static Status status_from_flags(const SCNetworkReachabilityFlags flags) - { - if ((flags & kSCNetworkReachabilityFlagsReachable) == 0) - { - // The target host is not reachable. - return ReachabilityInterface::NotReachable; - } - - Status ret = ReachabilityInterface::NotReachable; - - if ((flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0) - { - // If the target host is reachable and no connection is required then - // we'll assume (for now) that you're on Wi-Fi... - ret = ReachabilityInterface::ReachableViaWiFi; - } - -#if 0 // don't contaminate result by considering on-demand viability - if ((((flags & kSCNetworkReachabilityFlagsConnectionOnDemand ) != 0) || - (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0)) - { - // ... and the connection is on-demand (or on-traffic) if the - // calling application is using the CFSocketStream or higher APIs... - - if ((flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0) - { - // ... and no [user] intervention is needed... - ret = ReachabilityInterface::ReachableViaWiFi; - } - } -#endif - -#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR // Mac OS X doesn't define WWAN flags - if ((flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) - { - // ... but WWAN connections are OK if the calling application - // is using the CFNetwork APIs. - ret = ReachabilityInterface::ReachableViaWWAN; - } -#endif - - return ret; - } - }; - - class ReachabilityViaWiFi : public ReachabilityBase - { - public: - ReachabilityViaWiFi() - { - struct sockaddr_in addr; - bzero(&addr, sizeof(addr)); - addr.sin_len = sizeof(addr); - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM); // 169.254.0.0. - reach.reset(SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (struct sockaddr*)&addr)); - } - - virtual Type vtype() const - { - return WiFi; - } - - virtual Status vstatus(const SCNetworkReachabilityFlags flags) const - { - return status_from_flags(flags); - } - - static Status status_from_flags(const SCNetworkReachabilityFlags flags) - { - Status ret = ReachabilityInterface::NotReachable; - if ((flags & kSCNetworkReachabilityFlagsReachable) && (flags & kSCNetworkReachabilityFlagsIsDirect)) - ret = ReachabilityInterface::ReachableViaWiFi; - return ret; - } - }; - - class Reachability : public ReachabilityInterface - { - public: - Reachability(const bool enable_internet, const bool enable_wifi) - { - if (enable_internet) - internet.reset(new ReachabilityViaInternet); - if (enable_wifi) - wifi.reset(new ReachabilityViaWiFi); - } - - bool reachableViaWiFi() const { - if (internet) - { - if (wifi) - return internet->status() == ReachableViaWiFi && wifi->status() == ReachableViaWiFi; - else - return internet->status() == ReachableViaWiFi; - } - else - { - if (wifi) - return wifi->status() == ReachableViaWiFi; - else - return false; - } - } - - bool reachableViaCellular() const - { - if (internet) - return internet->status() == ReachableViaWWAN; - else - return false; - } - - virtual Status reachable() const - { - if (reachableViaWiFi()) - return ReachableViaWiFi; - else if (reachableViaCellular()) - return ReachableViaWWAN; - else - return NotReachable; - } - - virtual bool reachableVia(const std::string& net_type) const - { - if (net_type == "cellular") - return reachableViaCellular(); - else if (net_type == "wifi") - return reachableViaWiFi(); - else - return reachableViaWiFi() || reachableViaCellular(); - } - - virtual std::string to_string() const - { - std::string ret; - if (internet) - ret += internet->to_string(); - if (internet && wifi) - ret += ' '; - if (wifi) - ret += wifi->to_string(); - return ret; - } - - std::unique_ptr internet; - std::unique_ptr wifi; - }; - - class ReachabilityTracker - { - public: - ReachabilityTracker(const bool enable_internet, const bool enable_wifi) - : reachability(enable_internet, enable_wifi), - scheduled(false) - { - } - - void reachability_tracker_schedule() - { - if (!scheduled) - { - if (reachability.internet) - schedule(*reachability.internet, internet_callback_static); - if (reachability.wifi) - schedule(*reachability.wifi, wifi_callback_static); - scheduled = true; - } - } - - void reachability_tracker_cancel() - { - if (scheduled) - { - if (reachability.internet) - cancel(*reachability.internet); - if (reachability.wifi) - cancel(*reachability.wifi); - scheduled = false; - } - } - - virtual void reachability_tracker_event(const ReachabilityBase& rb, SCNetworkReachabilityFlags flags) = 0; - - virtual ~ReachabilityTracker() - { - reachability_tracker_cancel(); - } - - private: - bool schedule(ReachabilityBase& rb, SCNetworkReachabilityCallBack cb) - { - SCNetworkReachabilityContext context = { 0, this, nullptr, nullptr, nullptr }; - if (rb.reach.defined()) - { - if (SCNetworkReachabilitySetCallback(rb.reach(), - cb, - &context) == FALSE) - return false; - if (SCNetworkReachabilityScheduleWithRunLoop(rb.reach(), - CFRunLoopGetCurrent(), - kCFRunLoopCommonModes) == FALSE) - return false; - return true; - } - else - return false; - } - - void cancel(ReachabilityBase& rb) - { - if (rb.reach.defined()) - SCNetworkReachabilityUnscheduleFromRunLoop(rb.reach(), CFRunLoopGetCurrent(), kCFRunLoopCommonModes); - } - - static void internet_callback_static(SCNetworkReachabilityRef target, - SCNetworkReachabilityFlags flags, - void *info) - { - ReachabilityTracker* self = (ReachabilityTracker*)info; - self->reachability_tracker_event(*self->reachability.internet, flags); - } - - static void wifi_callback_static(SCNetworkReachabilityRef target, - SCNetworkReachabilityFlags flags, - void *info) - { - ReachabilityTracker* self = (ReachabilityTracker*)info; - self->reachability_tracker_event(*self->reachability.wifi, flags); - } - - Reachability reachability; - bool scheduled; - }; -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/auth/authcert.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/auth/authcert.hpp deleted file mode 100644 index 22f6f9d..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/auth/authcert.hpp +++ /dev/null @@ -1,239 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_AUTH_AUTHCERT_H -#define OPENVPN_AUTH_AUTHCERT_H - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -namespace openvpn { - - class OpenSSLContext; - class PolarSSLContext; - - struct AuthCert : public RC - { - // AuthCert needs to friend SSL implementation classes - friend class OpenSSLContext; - friend class PolarSSLContext; - - typedef RCPtr Ptr; - - class Fail - { - public: - // ordered by priority - enum Type { - OK=0, // OK MUST be 0 - OTHER, - BAD_CERT_TYPE, - EXPIRED, - N - }; - - void add_fail(const size_t depth, const Type new_code, const char *reason) - { - if (new_code > code) - code = new_code; - while (errors.size() <= depth) - errors.emplace_back(); - std::string& err = errors[depth]; - if (err.empty()) - err = reason; - else if (err.find(reason) == std::string::npos) - { - err += ", "; - err += reason; - } - } - - bool is_fail() const - { - return code != OK; - } - - Type get_code() const - { - return code; - } - - std::string to_string(const bool use_prefix) const - { - std::string ret; - if (use_prefix) - { - ret += render_code(code); - ret += ": "; - } - bool notfirst = false; - for (size_t i = 0; i < errors.size(); ++i) - { - if (errors[i].empty()) - continue; - if (notfirst) - ret += ", "; - notfirst = true; - ret += errors[i]; - ret += " ["; - ret += openvpn::to_string(i); - ret += ']'; - } - return ret; - } - - static const char *render_code(const Type code) - { - switch (code) - { - case OK: - return "OK"; - case OTHER: - default: - return "CERT_FAIL"; - case BAD_CERT_TYPE: - return "BAD_CERT_TYPE"; - case EXPIRED: - return "EXPIRED"; - } - } - - private: - Type code{OK}; // highest-valued cert fail code - std::vector errors; // human-readable cert errors by depth - }; - - AuthCert() - { - std::memset(issuer_fp, 0, sizeof(issuer_fp)); - sn = -1; - } - - bool defined() const - { - return sn >= 0; - } - - bool cn_defined() const - { - return !cn.empty(); - } - - template - T issuer_fp_prefix() const - { - return bin_prefix(issuer_fp); - } - - bool operator==(const AuthCert& other) const - { - return cn == other.cn && sn == other.sn && !std::memcmp(issuer_fp, other.issuer_fp, sizeof(issuer_fp)); - } - - bool operator!=(const AuthCert& other) const - { - return !operator==(other); - } - - std::string to_string() const - { - std::ostringstream os; - os << "CN=" << cn - << " SN=" << sn - << " ISSUER_FP=" << issuer_fp_str(false); - return os.str(); - } - - std::string issuer_fp_str(const bool openssl_fmt) const - { - if (openssl_fmt) - return render_hex_sep(issuer_fp, sizeof(issuer_fp), ':', true); - else - return render_hex(issuer_fp, sizeof(issuer_fp), false); - } - - std::string normalize_cn() const // remove trailing "_AUTOLOGIN" from AS certs - { - if (string::ends_with(cn, "_AUTOLOGIN")) - return cn.substr(0, cn.length() - 10); - else - return cn; - } - - const std::string& get_cn() const - { - return cn; - } - - long get_sn() const - { - return sn; - } - - const X509Track::Set* x509_track_get() const - { - return x509_track.get(); - } - - std::unique_ptr x509_track_take_ownership() - { - return std::move(x509_track); - } - - void add_fail(const size_t depth, const Fail::Type new_code, const char *reason) - { - if (!fail) - fail.reset(new Fail()); - fail->add_fail(depth, new_code, reason); - } - - bool is_fail() const - { - return fail && fail->is_fail(); - } - - const Fail* get_fail() const - { - return fail.get(); - } - - private: - std::string cn; // common name - long sn; // serial number - unsigned char issuer_fp[20]; // issuer cert fingerprint - - std::unique_ptr fail; - std::unique_ptr x509_track; - }; -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/auth/authcreds.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/auth/authcreds.hpp deleted file mode 100644 index b3d94ef..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/auth/authcreds.hpp +++ /dev/null @@ -1,91 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_AUTH_AUTHCREDS -#define OPENVPN_AUTH_AUTHCREDS - -#include // for std::move -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace openvpn { - - class AuthCreds : public RC - { - public: - typedef RCPtr Ptr; - - AuthCreds(std::string&& username_arg, - SafeString&& password_arg, - const std::string& peer_info_str) - : username(std::move(username_arg)), - password(std::move(password_arg)) - { - peer_info.parse_from_peer_info(peer_info_str, nullptr); - peer_info.update_map(); - } - - bool defined() const - { - return !username.empty(); - } - - bool is_valid_user_pass() const - { - return validate_auth_cred(username) && validate_auth_cred(password); - } - - bool is_valid() const - { - return defined() && is_valid_user_pass(); - } - - void wipe_password() - { - password.wipe(); - } - - std::string to_string() const - { - std::ostringstream os; - os << "*** AuthCreds ***" << std::endl; - os << "user: '" << username << "'" << std::endl; - //os << "pass: '" << password << "'" << std::endl; - os << "peer info:" << std::endl; - os << peer_info.render(Option::RENDER_BRACKET|Option::RENDER_NUMBER); - return os.str(); - } - - std::string username; - SafeString password; - OptionList peer_info; - }; - -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/auth/cr.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/auth/cr.hpp deleted file mode 100644 index da8c7ff..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/auth/cr.hpp +++ /dev/null @@ -1,228 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -// Encapsulate the state of a static or dynamic authentication challenge. - -#ifndef OPENVPN_AUTH_CR_H -#define OPENVPN_AUTH_CR_H - -#include -#include -#include - -#include -#include -#include -#include -#include - -// Static Challenge response: -// SCRV1:: -// -// Dynamic Challenge: -// CRV1:::: -// FLAGS is a comma-separated list of options: -// E -- echo -// R -- response required -// -// Dynamic Challenge response: -// Username: [username decoded from username_base64] -// Password: CRV1:::: - -namespace openvpn { - class ChallengeResponse : public RC { - public: - typedef RCPtr Ptr; - - OPENVPN_SIMPLE_EXCEPTION(dynamic_challenge_parse_error); - OPENVPN_SIMPLE_EXCEPTION(static_challenge_parse_error); - - ChallengeResponse() - : echo(false), response_required(false) - { - } - - explicit ChallengeResponse(const std::string& cookie) - : echo(false), response_required(false) - { - init(cookie); - } - - ChallengeResponse(const std::string& cookie, const std::string& user) - : echo(false), response_required(false) - { - if (!is_dynamic(cookie) && cookie.find_first_of(':') == std::string::npos) - { - state_id = cookie; - username = user; - } - else - init(cookie); - } - - void init(const std::string& cookie) - { - typedef std::vector StringList; - StringList sl; - sl.reserve(5); - Split::by_char_void(sl, cookie, ':', 0, 4); - if (sl.size() != 5) - throw dynamic_challenge_parse_error(); - if (sl[0] != "CRV1") - throw dynamic_challenge_parse_error(); - - // parse options - { - StringList opt; - opt.reserve(2); - Split::by_char_void(opt, sl[1], ','); - for (StringList::const_iterator i = opt.begin(); i != opt.end(); ++i) - { - if (*i == "E") - echo = true; - else if (*i == "R") - response_required = true; - } - } - - // save state ID - state_id = sl[2]; - - // save username - try { - username = base64->decode(sl[3]); - } - catch (const Base64::base64_decode_error&) - { - throw dynamic_challenge_parse_error(); - } - - // save challenge - challenge_text = sl[4]; - } - - static bool is_dynamic(const std::string& s) - { - return string::starts_with(s, "CRV1:"); - } - - static bool is_static(const std::string& s) - { - return string::starts_with(s, "SCRV1:"); - } - - static void validate_dynamic(const std::string& cookie) - { - ChallengeResponse cr(cookie); - } - - std::string construct_dynamic_password(const std::string& response) const - { - std::ostringstream os; - os << "CRV1::" << state_id << "::" << response; - return os.str(); - } - - static std::string construct_static_password(const std::string& password, - const std::string& response) - { - std::ostringstream os; - os << "SCRV1:" << base64->encode(password) << ':' << base64->encode(response); - return os.str(); - } - - static void parse_static_cookie(const std::string& cookie, - std::string& password, - std::string& response) - { - typedef std::vector StringList; - StringList sl; - sl.reserve(3); - Split::by_char_void(sl, cookie, ':'); - if (sl.size() != 3) - throw static_challenge_parse_error(); - if (sl[0] != "SCRV1") - throw static_challenge_parse_error(); - - // get password - try { - password = base64->decode(sl[1]); - } - catch (const Base64::base64_decode_error&) - { - throw static_challenge_parse_error(); - } - - // get response - try { - response = base64->decode(sl[2]); - } - catch (const Base64::base64_decode_error&) - { - throw static_challenge_parse_error(); - } - } - - static std::string generate_dynamic_challenge(const std::string& session_token, - const std::string& username, - const std::string& challenge, - const bool echo, - const bool response_required) - { - std::ostringstream os; - bool comma = false; - os << "CRV1:"; - if (echo) - { - if (comma) - os << ","; - os << "E"; - comma = true; - } - if (response_required) - { - if (comma) - os << ","; - os << "R"; - comma = true; - } - os << ':' << session_token; - os << ':' << base64->encode(username); - os << ':' << challenge; - return os.str(); - } - - const std::string& get_state_id() const { return state_id; } - const std::string& get_username() const { return username; } - bool get_echo() const { return echo; } - bool get_response_required() const { return response_required; } - const std::string& get_challenge_text() const { return challenge_text; } - - private: - bool echo; - bool response_required; - std::string state_id; - std::string username; - std::string challenge_text; - }; -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/auth/validatecreds.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/auth/validatecreds.hpp deleted file mode 100644 index 29a26ce..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/auth/validatecreds.hpp +++ /dev/null @@ -1,44 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_AUTH_VALIDATE_CREDS_H -#define OPENVPN_AUTH_VALIDATE_CREDS_H - -#include - -namespace openvpn { - // Authentication credential (username, password, or response) must - // satisfy these constraints: - // - // 1. must be a valid UTF-8 string - // 2. must not contain control or space characters - // 3. length must be <= 256 unicode characters - // - // Note that we don't check that string is non-empty here, - // callers should do this themselves if necessary. - template - inline bool validate_auth_cred(const STRING& cred) - { - return Unicode::is_valid_utf8(cred, 256 | Unicode::UTF8_NO_CTRL | Unicode::UTF8_NO_SPACE); - } -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/asiobuf.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/asiobuf.hpp deleted file mode 100644 index 0d14431..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/asiobuf.hpp +++ /dev/null @@ -1,56 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_BUFFER_ASIOBUF_H -#define OPENVPN_BUFFER_ASIOBUF_H - -#include - -#include - -namespace openvpn { - class AsioConstBufferSeq2 - { - public: - AsioConstBufferSeq2(const Buffer& b1, const Buffer& b2) - : buf({{b1.c_data(), b1.size()}, - {b2.c_data(), b2.size()}}) - { - } - - // Implement the ConstBufferSequence requirements. - typedef asio::const_buffer value_type; - typedef const asio::const_buffer* const_iterator; - const asio::const_buffer* begin() const { return buf; } - const asio::const_buffer* end() const { return buf + 2; } - - const size_t size() const - { - return asio::buffer_size(buf[0]) - + asio::buffer_size(buf[1]); - } - - private: - const asio::const_buffer buf[2]; - }; -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/bufclamp.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/bufclamp.hpp deleted file mode 100644 index 6f2b801..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/bufclamp.hpp +++ /dev/null @@ -1,52 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -// For debugging, reduce effective buffer size for I/O. -// Enable by defining OPENVPN_BUF_CLAMP_READ and/or OPENVPN_BUF_CLAMP_WRITE - -#ifndef OPENVPN_BUFFER_BUFCLAMP_H -#define OPENVPN_BUFFER_BUFCLAMP_H - -#include - -#include - -namespace openvpn { - inline size_t buf_clamp_read(const size_t size) - { -#ifdef OPENVPN_BUF_CLAMP_READ - return std::min(size, size_t(OPENVPN_BUF_CLAMP_READ)); -#else - return size; -#endif - } - - inline size_t buf_clamp_write(const size_t size) - { -#ifdef OPENVPN_BUF_CLAMP_WRITE - return std::min(size, size_t(OPENVPN_BUF_CLAMP_WRITE)); -#else - return size; -#endif - } -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/bufcomplete.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/bufcomplete.hpp deleted file mode 100644 index 8dbda91..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/bufcomplete.hpp +++ /dev/null @@ -1,112 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_BUFFER_BUFCOMPLETE_H -#define OPENVPN_BUFFER_BUFCOMPLETE_H - -#include // for std::uint32_t, uint16_t, uint8_t -#include // for std::min - -#include - -namespace openvpn { - - class BufferComplete - { - public: - /* each advance/get method returns false if message is incomplete */ - - bool advance(size_t size) - { - while (size) - { - if (!fetch_buffer()) - return false; - const size_t s = std::min(size, buf.size()); - buf.advance(s); - size -= s; - } - return true; - } - - // assumes embedded big-endian uint16_t length in the stream - bool advance_string() - { - std::uint8_t h, l; - if (!get(h)) - return false; - if (!get(l)) - return false; - return advance(size_t(h) << 8 | size_t(l)); - } - - bool advance_to_null() - { - std::uint8_t c; - while (get(c)) - { - if (!c) - return true; - } - return false; - } - - bool get(std::uint8_t& c) - { - if (!fetch_buffer()) - return false; - c = buf.pop_front(); - return true; - } - - bool defined() const - { - return buf.defined(); - } - - protected: - void reset_buf(const Buffer& buf_arg) - { - buf = buf_arg; - } - - void reset_buf() - { - buf.reset_content(); - } - - private: - virtual void next_buffer() = 0; - - bool fetch_buffer() - { - if (buf.defined()) - return true; - next_buffer(); - return buf.defined(); - } - - Buffer buf; - }; - -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/bufcomposed.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/bufcomposed.hpp deleted file mode 100644 index dcba54e..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/bufcomposed.hpp +++ /dev/null @@ -1,94 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_BUFFER_BUFCOMPOSED_H -#define OPENVPN_BUFFER_BUFCOMPOSED_H - -#include -#include -#include - -namespace openvpn { - class BufferComposed - { - public: - class Complete : public BufferComplete - { - public: - BufferPtr get() - { -#if 0 // don't include for production - if (iter_defined()) - throw Exception("BufferComposed::Complete: residual data"); -#endif - BufferPtr ret = bc.bv.join(); - bc.bv.clear(); - return ret; - } - - private: - friend class BufferComposed; - - Complete(BufferComposed& bc_arg) - : bc(bc_arg), - iter(bc.bv.cbegin()) - { - next_buffer(); - } - - bool iter_defined() - { - return iter != bc.bv.end(); - } - - virtual void next_buffer() override - { - if (iter_defined()) - reset_buf(**iter++); - else - reset_buf(); - } - - BufferComposed& bc; - BufferVector::const_iterator iter; - }; - - size_t size() const - { - return bv.join_size(); - } - - void put(BufferPtr bp) - { - bv.push_back(std::move(bp)); - } - - Complete complete() - { - return Complete(*this); - } - - private: - BufferVector bv; - }; -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/buffer.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/buffer.hpp deleted file mode 100644 index a48bbce..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/buffer.hpp +++ /dev/null @@ -1,834 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -// These templates define the fundamental data buffer classes used by the -// OpenVPN core. Normally OpenVPN uses buffers of unsigned chars, but the -// templatization of the classes would allow buffers of other types to -// be defined. -// -// Fundamentally a buffer is an object with 4 fields: -// -// 1. a pointer to underlying data array -// 2. the capacity of the underlying data array -// 3. an offset into the data array -// 4. the size of the referenced data within the array -// -// The BufferType template is the lowest-level buffer class template. It refers -// to a buffer but without any notion of ownership of the underlying data. -// -// The BufferAllocatedType template is a higher-level template that inherits -// from BufferType but which asserts ownership over the resources of the buffer -- -// for example, it will free the underlying buffer in its destructor. -// -// Since most of the time, we want our buffers to be made out of unsigned chars, -// some typedefs at the end of the file define common instantations for the -// BufferType and BufferAllocatedType templates. -// -// Buffer : a simple buffer of unsigned char without ownership semantics -// ConstBuffer : like buffer but where the data pointed to by the buffer is const -// BufferAllocated : an allocated Buffer with ownership semantics -// BufferPtr : a smart, reference-counted pointer to a BufferAllocated - -#ifndef OPENVPN_BUFFER_BUFFER_H -#define OPENVPN_BUFFER_BUFFER_H - -#include -#include -#include -#include // for std::is_nothrow_move_constructible - -#ifndef NO_ASIO -#include -#endif - -#include -#include -#include -#include -#include - -#ifdef OPENVPN_BUFFER_ABORT -#define OPENVPN_BUFFER_THROW(exc) { std::abort(); } -#else -#define OPENVPN_BUFFER_THROW(exc) { throw BufferException(BufferException::exc); } -#endif - -namespace openvpn { - - // special-purpose exception class for Buffer classes - class BufferException : public std::exception - { - public: - enum Status { - buffer_full, - buffer_headroom, - buffer_underflow, - buffer_overflow, - buffer_index, - buffer_const_index, - buffer_push_front_headroom, - buffer_no_reset_impl, - buffer_pop_back, - buffer_set_size, - buffer_range, - }; - - BufferException(Status status) - : status_(status) {} - - Status status() const { return status_; } - - const char *status_string() const - { - switch (status_) - { - case buffer_full: - return "buffer_full"; - case buffer_headroom: - return "buffer_headroom"; - case buffer_underflow: - return "buffer_underflow"; - case buffer_overflow: - return "buffer_overflow"; - case buffer_index: - return "buffer_index"; - case buffer_const_index: - return "buffer_const_index"; - case buffer_push_front_headroom: - return "buffer_push_front_headroom"; - case buffer_no_reset_impl: - return "buffer_no_reset_impl"; - case buffer_pop_back: - return "buffer_pop_back"; - case buffer_set_size: - return "buffer_set_size"; - case buffer_range: - return "buffer_range"; - default: - return "buffer_???"; - } - } - - virtual const char* what() const throw() { - return status_string(); - } - virtual ~BufferException() throw() {} - - private: - Status status_; - }; - - template - class BufferType { - public: - typedef T* type; - typedef const T* const_type; - - BufferType() - { - static_assert(std::is_nothrow_move_constructible::value, "class BufferType not noexcept move constructable"); - data_ = nullptr; - offset_ = size_ = capacity_ = 0; - } - - BufferType(T* data, const size_t size, const bool filled) - { - data_ = data; - offset_ = 0; - capacity_ = size; - size_ = filled ? size : 0; - } - - void reserve(const size_t n) - { - if (n > capacity_) - resize(n); - } - - void init_headroom(const size_t headroom) - { - if (headroom > capacity_) - OPENVPN_BUFFER_THROW(buffer_headroom); - offset_ = headroom; - size_ = 0; - } - - void reset_size() - { - size_ = 0; - } - - void reset_content() - { - offset_ = size_ = 0; - } - - // std::string compatible methods - const T* c_str() const { return c_data(); } - size_t length() const { return size(); } - - // return a const pointer to start of array - const T* c_data() const { return data_ + offset_; } - - // return a mutable pointer to start of array - T* data() { return data_ + offset_; } - - // return a const pointer to end of array - const T* c_data_end() const { return data_ + offset_ + size_; } - - // return a mutable pointer to end of array - T* data_end() { return data_ + offset_ + size_; } - - // return a const pointer to start of raw data - const T* c_data_raw() const { return data_; } - - // return a mutable pointer to start of raw data - T* data_raw() { return data_; } - - // return size of array in T objects - size_t size() const { return size_; } - - // return raw size of allocated buffer in T objects - size_t capacity() const { return capacity_; } - - // return current offset (headroom) into buffer - size_t offset() const { return offset_; } - - // return true if array is not empty - bool defined() const { return size_ > 0; } - - // return true if data memory is defined - bool allocated() const { return data_ != nullptr; } - - // return true if array is empty - bool empty() const { return !size_; } - - // return the number of additional T objects that can be added before capacity is reached (without considering resize) - size_t remaining(const size_t tailroom = 0) const { - const size_t r = capacity_ - (offset_ + size_ + tailroom); - return r <= capacity_ ? r : 0; - } - - // return the maximum allowable size value in T objects given the current offset (without considering resize) - size_t max_size() const { - const size_t r = capacity_ - offset_; - return r <= capacity_ ? r : 0; - } - - // like max_size, but take tailroom into account - size_t max_size_tailroom(const size_t tailroom) const { - const size_t r = capacity_ - (offset_ + tailroom); - return r <= capacity_ ? r : 0; - } - - // After an external method, operating on the array as - // a mutable unsigned char buffer, has written data to the - // array, use this method to set the array length in terms - // of T objects. - void set_size(const size_t size) - { - if (size > max_size()) - OPENVPN_BUFFER_THROW(buffer_set_size); - size_ = size; - } - - // Increment size (usually used in a similar context - // to set_size such as after mutable_buffers_1_append). - void inc_size(const size_t delta) - { - set_size(size_ + delta); - } - - // append a T object to array, with possible resize - void push_back(const T& value) - { - if (!remaining()) - resize(offset_ + size_ + 1); - *(data()+size_++) = value; - } - - // append a T object to array, with possible resize - void push_front(const T& value) - { - if (!offset_) - OPENVPN_BUFFER_THROW(buffer_push_front_headroom); - --offset_; - ++size_; - *data() = value; - } - - T pop_back() - { - if (!size_) - OPENVPN_BUFFER_THROW(buffer_pop_back); - return *(data()+(--size_)); - } - - T pop_front() - { - T ret = (*this)[0]; - ++offset_; - --size_; - return ret; - } - - T front() - { - return (*this)[0]; - } - - T back() - { - return (*this)[size_-1]; - } - - // Place a T object after the last object in the - // array, with possible resize to contain it, - // however don't actually change the size of the - // array to reflect the added object. Useful - // for maintaining null-terminated strings. - void set_trailer(const T& value) - { - if (!remaining()) - resize(offset_ + size_ + 1); - *(data()+size_) = value; - } - - void null_terminate() - { - if (empty() || back()) - push_back(0); - } - - void advance(const size_t delta) - { - if (delta > size_) - OPENVPN_BUFFER_THROW(buffer_overflow); - offset_ += delta; - size_ -= delta; - } - - bool contains_null() const - { - const T* end = c_data_end(); - for (const T* p = c_data(); p < end; ++p) - { - if (!*p) - return true; - } - return false; - } - - // mutable index into array - T& operator[](const size_t index) - { - if (index >= size_) - OPENVPN_BUFFER_THROW(buffer_index); - return data()[index]; - } - - // const index into array - const T& operator[](const size_t index) const - { - if (index >= size_) - OPENVPN_BUFFER_THROW(buffer_const_index); - return c_data()[index]; - } - - // mutable index into array - T* index(const size_t index) - { - if (index >= size_) - OPENVPN_BUFFER_THROW(buffer_index); - return &data()[index]; - } - - // const index into array - const T* c_index(const size_t index) const - { - if (index >= size_) - OPENVPN_BUFFER_THROW(buffer_const_index); - return &c_data()[index]; - } - - bool operator==(const BufferType& other) const - { - if (size_ != other.size_) - return false; - return std::memcmp(c_data(), other.c_data(), size_) == 0; - } - - bool operator!=(const BufferType& other) const - { - return !(*this == other); - } - -#ifndef NO_ASIO - // return a asio::mutable_buffers_1 object used by - // asio read methods, starting from data() - asio::mutable_buffers_1 mutable_buffers_1(const size_t tailroom = 0) - { - return asio::mutable_buffers_1(data(), max_size_tailroom(tailroom)); - } - - // return a asio::mutable_buffers_1 object used by - // asio read methods, starting from data_end() - asio::mutable_buffers_1 mutable_buffers_1_append(const size_t tailroom = 0) - { - return asio::mutable_buffers_1(data_end(), remaining(tailroom)); - } - - // return a asio::const_buffers_1 object used by - // asio write methods. - asio::const_buffers_1 const_buffers_1() const - { - return asio::const_buffers_1(c_data(), size()); - } - - // clamped versions of mutable_buffers_1(), mutable_buffers_1_append(), - // and const_buffers_1() - - asio::mutable_buffers_1 mutable_buffers_1_clamp(const size_t tailroom = 0) - { - return asio::mutable_buffers_1(data(), buf_clamp_read(max_size_tailroom(tailroom))); - } - - asio::mutable_buffers_1 mutable_buffers_1_append_clamp(const size_t tailroom = 0) - { - return asio::mutable_buffers_1(data_end(), buf_clamp_read(remaining(tailroom))); - } - - asio::const_buffers_1 const_buffers_1_clamp() const - { - return asio::const_buffers_1(c_data(), buf_clamp_write(size())); - } - - asio::const_buffers_1 const_buffers_1_limit(const size_t limit) const - { - return asio::const_buffers_1(c_data(), std::min(buf_clamp_write(size()), limit)); - } -#endif - - void realign(size_t headroom) - { - if (headroom != offset_) - { - if (headroom + size_ > capacity_) - OPENVPN_BUFFER_THROW(buffer_headroom); - std::memmove(data_ + headroom, data_ + offset_, size_); - offset_ = headroom; - } - } - - void write(const T* data, const size_t size) - { - std::memcpy(write_alloc(size), data, size * sizeof(T)); - } - - void prepend(const T* data, const size_t size) - { - std::memcpy(prepend_alloc(size), data, size * sizeof(T)); - } - - void read(T* data, const size_t size) - { - std::memcpy(data, read_alloc(size), size * sizeof(T)); - } - - T* write_alloc(const size_t size) - { - if (size > remaining()) - resize(offset_ + size_ + size); - T* ret = data() + size_; - size_ += size; - return ret; - } - - T* prepend_alloc(const size_t size) - { - if (size <= offset_) - { - offset_ -= size; - size_ += size; - return data(); - } - else - OPENVPN_BUFFER_THROW(buffer_headroom); - } - - T* read_alloc(const size_t size) - { - if (size <= size_) - { - T* ret = data(); - offset_ += size; - size_ -= size; - return ret; - } - else - OPENVPN_BUFFER_THROW(buffer_underflow); - } - - void reset(const size_t min_capacity, const unsigned int flags) - { - if (min_capacity > capacity_) - reset_impl(min_capacity, flags); - } - - void reset(const size_t headroom, const size_t min_capacity, const unsigned int flags) - { - reset(min_capacity, flags); - init_headroom(headroom); - } - - void append(const BufferType& other) - { - write(other.c_data(), other.size()); - } - - BufferType range(size_t offset, size_t len) const - { - if (offset + len > size()) - { - if (offset < size()) - len = size() - offset; - else - len = 0; - } - return BufferType(datac(), offset, len, len); - } - - protected: - BufferType(T* data, const size_t offset, const size_t size, const size_t capacity) - : data_(data), offset_(offset), size_(size), capacity_(capacity) - { - } - - // return a mutable pointer to start of array but - // remain const with respect to *this. - T* datac() const { return data_ + offset_; } - - // Called when reset method needs to expand the buffer size - virtual void reset_impl(const size_t min_capacity, const unsigned int flags) - { - OPENVPN_BUFFER_THROW(buffer_no_reset_impl); - } - - // Derived classes can implement buffer growing semantics - // by overloading this method. In the default implementation, - // buffers are non-growable, so we throw an exception. - virtual void resize(const size_t new_capacity) - { - if (new_capacity > capacity_) - { - OPENVPN_BUFFER_THROW(buffer_full); - } - } - - T* data_; // pointer to data - size_t offset_; // offset from data_ of beginning of T array (to allow for headroom) - size_t size_; // number of T objects in array starting at data_ + offset_ - size_t capacity_; // maximum number of array objects of type T for which memory is allocated, starting at data_ - }; - - template - class BufferAllocatedType : public BufferType, public RC - { - using BufferType::data_; - using BufferType::offset_; - using BufferType::size_; - using BufferType::capacity_; - - public: - enum { - CONSTRUCT_ZERO = (1<<0), // if enabled, constructors/init will zero allocated space - DESTRUCT_ZERO = (1<<1), // if enabled, destructor will zero data before deletion - GROW = (1<<2), // if enabled, buffer will grow (otherwise buffer_full exception will be thrown) - ARRAY = (1<<3), // if enabled, use as array - }; - - BufferAllocatedType() - { - static_assert(std::is_nothrow_move_constructible::value, "class BufferAllocatedType not noexcept move constructable"); - flags_ = 0; - } - - BufferAllocatedType(const size_t capacity, const unsigned int flags) - { - flags_ = flags; - capacity_ = capacity; - if (capacity) - { - data_ = new T[capacity]; - if (flags & CONSTRUCT_ZERO) - std::memset(data_, 0, capacity * sizeof(T)); - if (flags & ARRAY) - size_ = capacity; - } - } - - BufferAllocatedType(const T* data, const size_t size, const unsigned int flags) - { - flags_ = flags; - size_ = capacity_ = size; - if (size) - { - data_ = new T[size]; - std::memcpy(data_, data, size * sizeof(T)); - } - } - - BufferAllocatedType(const BufferAllocatedType& other) - { - offset_ = other.offset_; - size_ = other.size_; - capacity_ = other.capacity_; - flags_ = other.flags_; - if (capacity_) - { - data_ = new T[capacity_]; - if (size_) - std::memcpy(data_ + offset_, other.data_ + offset_, size_ * sizeof(T)); - } - } - - template - BufferAllocatedType(const BufferType& other, const unsigned int flags) - { - static_assert(sizeof(T) == sizeof(OT), "size inconsistency"); - offset_ = other.offset(); - size_ = other.size(); - capacity_ = other.capacity(); - flags_ = flags; - if (capacity_) - { - data_ = new T[capacity_]; - if (size_) - std::memcpy(data_ + offset_, other.c_data(), size_ * sizeof(T)); - } - } - - void operator=(const BufferAllocatedType& other) - { - if (this != &other) - { - offset_ = size_ = 0; - if (capacity_ != other.capacity_) - { - erase_(); - if (other.capacity_) - data_ = new T[other.capacity_]; - capacity_ = other.capacity_; - } - offset_ = other.offset_; - size_ = other.size_; - flags_ = other.flags_; - if (size_) - std::memcpy(data_ + offset_, other.data_ + offset_, size_ * sizeof(T)); - } - } - - void init(const size_t capacity, const unsigned int flags) - { - offset_ = size_ = 0; - flags_ = flags; - if (capacity_ != capacity) - { - erase_(); - if (capacity) - { - data_ = new T[capacity]; - } - capacity_ = capacity; - } - if ((flags & CONSTRUCT_ZERO) && capacity) - std::memset(data_, 0, capacity * sizeof(T)); - if (flags & ARRAY) - size_ = capacity; - } - - void init(const T* data, const size_t size, const unsigned int flags) - { - offset_ = size_ = 0; - flags_ = flags; - if (size != capacity_) - { - erase_(); - if (size) - data_ = new T[size]; - capacity_ = size; - } - size_ = size; - std::memcpy(data_, data, size * sizeof(T)); - } - - void realloc(const size_t newcap) - { - if (newcap > capacity_) - realloc_(newcap); - } - - void reset(const size_t min_capacity, const unsigned int flags) - { - if (min_capacity > capacity_) - init (min_capacity, flags); - } - - void reset(const size_t headroom, const size_t min_capacity, const unsigned int flags) - { - reset(min_capacity, flags); - BufferType::init_headroom(headroom); - } - - void move(BufferAllocatedType& other) - { - if (data_) - delete_(data_, capacity_, flags_); - move_(other); - } - - RCPtr> move_to_ptr() - { - RCPtr> bp = new BufferAllocatedType(); - bp->move(*this); - return bp; - } - - void swap(BufferAllocatedType& other) - { - std::swap(data_, other.data_); - std::swap(offset_, other.offset_); - std::swap(size_, other.size_); - std::swap(capacity_, other.capacity_); - std::swap(flags_, other.flags_); - } - - BufferAllocatedType(BufferAllocatedType&& other) noexcept - { - move_(other); - } - - BufferAllocatedType& operator=(BufferAllocatedType&& other) noexcept - { - move(other); - return *this; - } - - void clear() - { - erase_(); - flags_ = 0; - size_ = offset_ = 0; - } - - void or_flags(const unsigned int flags) - { - flags_ |= flags; - } - - void and_flags(const unsigned int flags) - { - flags_ &= flags; - } - - ~BufferAllocatedType() - { - if (data_) - delete_(data_, capacity_, flags_); - } - - protected: - // Called when reset method needs to expand the buffer size - virtual void reset_impl(const size_t min_capacity, const unsigned int flags) - { - init(min_capacity, flags); - } - - // Set current capacity to at least new_capacity. - virtual void resize(const size_t new_capacity) - { - const size_t newcap = std::max(new_capacity, capacity_ * 2); - if (newcap > capacity_) - { - if (flags_ & GROW) - realloc_(newcap); - else - OPENVPN_BUFFER_THROW(buffer_full); - } - } - - void realloc_(const size_t newcap) - { - T* data = new T[newcap]; - if (size_) - std::memcpy(data + offset_, data_ + offset_, size_ * sizeof(T)); - delete_(data_, capacity_, flags_); - data_ = data; - //std::cout << "*** RESIZE " << capacity_ << " -> " << newcap << std::endl; // fixme - capacity_ = newcap; - } - - void move_(BufferAllocatedType& other) - { - data_ = other.data_; - offset_ = other.offset_; - size_ = other.size_; - capacity_ = other.capacity_; - flags_ = other.flags_; - - other.data_ = nullptr; - other.offset_ = other.size_ = other.capacity_ = 0; - } - - void erase_() - { - if (data_) - { - delete_(data_, capacity_, flags_); - data_ = nullptr; - } - capacity_ = 0; - } - - static void delete_(T* data, const size_t size, const unsigned int flags) - { - if (size && (flags & DESTRUCT_ZERO)) - std::memset(data, 0, size * sizeof(T)); - delete [] data; - } - - unsigned int flags_; - }; - - typedef BufferType Buffer; - typedef BufferType ConstBuffer; - typedef BufferAllocatedType BufferAllocated; - typedef RCPtr BufferPtr; - - template - inline BufferType& const_buffer_ref(BufferType& src) - { - return (BufferType&)src; - } - -} // namespace openvpn - -#endif // OPENVPN_BUFFER_BUFFER_H diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/bufhex.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/bufhex.hpp deleted file mode 100644 index a3c7b8d..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/bufhex.hpp +++ /dev/null @@ -1,61 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_BUFFER_BUFHEX_H -#define OPENVPN_BUFFER_BUFHEX_H - -#include -#include -#include - -namespace openvpn { - namespace BufHex { - - OPENVPN_EXCEPTION(buf_hex); - - template - inline std::string render(const T obj) - { - const ConstBuffer buf((const unsigned char *)&obj, sizeof(obj), true); - return render_hex_generic(buf); - } - - template - inline T parse(const std::string& hex, const std::string& title) - { - T obj; - Buffer buf((unsigned char *)&obj, sizeof(obj), false); - try { - parse_hex(buf, hex); - } - catch (const BufferException& e) - { - OPENVPN_THROW(buf_hex, title << ": buffer issue: " << e.what()); - } - if (buf.size() != sizeof(obj)) - OPENVPN_THROW(buf_hex, title << ": unexpected size"); - return obj; - } - - } -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/buflimit.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/buflimit.hpp deleted file mode 100644 index 15c7a0f..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/buflimit.hpp +++ /dev/null @@ -1,92 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_BUFFER_BUFLIMIT_H -#define OPENVPN_BUFFER_BUFLIMIT_H - -#include - -namespace openvpn { - - template - class BufferLimit - { - public: - BufferLimit() - { - set_max(0, 0); - reset(); - } - - BufferLimit(const T max_lines_arg, - const T max_bytes_arg) - { - set_max(max_lines_arg, max_bytes_arg); - reset(); - } - - void set_max(const T max_lines_arg, - const T max_bytes_arg) - { - max_lines = max_lines_arg; - max_bytes = max_bytes_arg; - } - - void reset() - { - n_bytes = n_lines = 0; - } - - void add(const Buffer& buf) - { - T size = (T)buf.size(); - n_bytes += size; - if (max_bytes && n_bytes > max_bytes) - bytes_exceeded(); - if (max_lines) - { - const unsigned char *p = buf.c_data(); - while (size--) - { - const unsigned char c = *p++; - if (c == '\n') - { - ++n_lines; - if (n_lines > max_lines) - lines_exceeded(); - } - } - } - } - - virtual void bytes_exceeded() = 0; - virtual void lines_exceeded() = 0; - - protected: - T max_lines; - T max_bytes; - T n_bytes; - T n_lines; - }; - -} - -#endif diff --git a/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/buflist.hpp b/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/buflist.hpp deleted file mode 100644 index 79f5db9..0000000 --- a/OpenVPN Adapter/Vendors/openvpn/openvpn/buffer/buflist.hpp +++ /dev/null @@ -1,122 +0,0 @@ -// OpenVPN -- An application to securely tunnel IP networks -// over a single port, with support for SSL/TLS-based -// session authentication and key exchange, -// packet encryption, packet authentication, and -// packet compression. -// -// Copyright (C) 2012-2016 OpenVPN Technologies, Inc. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License Version 3 -// as published by the Free Software Foundation. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program in the COPYING file. -// If not, see . - -#ifndef OPENVPN_BUFFER_BUFLIST_H -#define OPENVPN_BUFFER_BUFLIST_H - -#include -#include - -#include -#include - -namespace openvpn { - - template