From 63cc38e6bd6329dfe0021adc2f8609bf7819fc49 Mon Sep 17 00:00:00 2001 From: Erwin Nindl Date: Wed, 27 Feb 2008 21:21:05 +0000 Subject: added mux to options --- anytun.cpp | 18 +++++++++++++++++- buffer.cpp | 18 ++++++++++++++++++ buffer.h | 1 + options.cpp | 36 ++++++++++++++++++++++++++++++++++++ options.h | 10 ++++++++++ 5 files changed, 82 insertions(+), 1 deletion(-) diff --git a/anytun.cpp b/anytun.cpp index 66568c0..a408019 100644 --- a/anytun.cpp +++ b/anytun.cpp @@ -142,7 +142,7 @@ void* sender(void* p) Buffer session_auth_key(u_int32_t(SESSION_KEYLEN_AUTH)); // TODO: hardcoded size //TODO replace mux - u_int16_t mux = 0; + u_int16_t mux = gOpt.getMux(); while(1) { plain_packet.setLength(MAX_PACKET_LENGTH); @@ -335,6 +335,22 @@ bool initLibGCrypt() int main(int argc, char* argv[]) { +/* + + char INPUT[] = "101232565621f6e77f56"; + + std::string input(INPUT, sizeof(INPUT)); + + Buffer b(input); + + std::cout << " b:" << b.getHexDump() << std::endl; + + + + + exit(0); +*/ + std::cout << "anytun - secure anycast tunneling protocol" << std::endl; if(!gOpt.parse(argc, argv)) { diff --git a/buffer.cpp b/buffer.cpp index 91ad950..986c7ba 100644 --- a/buffer.cpp +++ b/buffer.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include "datatypes.h" @@ -64,6 +65,23 @@ Buffer::Buffer(u_int8_t* data, u_int32_t length, bool allow_realloc) : length_(l std::memcpy(buf_, data, length_); } +Buffer::Buffer(std::string hex_data, bool allow_realloc) : length_(hex_data.size()/2), + real_length_(length_ + Buffer::OVER_SIZE_), + allow_realloc_(allow_realloc) +{ + buf_ = new u_int8_t[real_length_]; + if(!buf_) { + length_ = 0; + real_length_ = 0; + throw std::bad_alloc(); + } + std::stringstream tmp(hex_data); + for(u_int32_t i=0;i> std::hex >> std::setw(2) >> buf_[i]; + } +} + Buffer::~Buffer() { if(buf_) diff --git a/buffer.h b/buffer.h index df17953..e22c96a 100644 --- a/buffer.h +++ b/buffer.h @@ -43,6 +43,7 @@ public: Buffer(bool allow_realloc = true); Buffer(u_int32_t length, bool allow_realloc = true); Buffer(u_int8_t* data, u_int32_t length, bool allow_realloc = true); + Buffer(std::string data, bool allow_realloc = true); virtual ~Buffer(); Buffer(const Buffer &src); void operator=(const Buffer &src); diff --git a/options.cpp b/options.cpp index 48c0110..2886332 100644 --- a/options.cpp +++ b/options.cpp @@ -69,6 +69,9 @@ Options::Options() cipher_ = "aes-ctr"; kd_prf_ = "aes-ctr"; auth_algo_ = "sha1"; + key_ = ""; + salt_ = ""; + mux_ = 0; } Options::~Options() @@ -152,7 +155,10 @@ bool Options::parse(int argc, char* argv[]) PARSE_SCALAR_PARAM("-t","--type", dev_type_) PARSE_SCALAR_PARAM2("-n","--ifconfig", ifconfig_param_local_, ifconfig_param_remote_netmask_) PARSE_SCALAR_PARAM("-w","--window-size", seq_window_size_) + PARSE_SCALAR_PARAM("-m","--mux", mux_) PARSE_SCALAR_PARAM("-c","--cipher", cipher_) + PARSE_SCALAR_PARAM("-K","--key", key_) + PARSE_SCALAR_PARAM("-a","--salt", salt_) PARSE_SCALAR_PARAM("-k","--kd-prf", kd_prf_) PARSE_SCALAR_PARAM("-a","--auth-algo", auth_algo_) PARSE_CSLIST_PARAM("-M","--sync-hosts", host_port_queue) @@ -195,7 +201,10 @@ void Options::printUsage() std::cout << " [-n|--ifconfig] the local address for the tun/tap device" << std::endl << " the remote address(tun) or netmask(tap)" << std::endl; std::cout << " [-w|--window-size] seqence number window size" << std::endl; + std::cout << " [-m|--mux] the multiplex id to use" << std::endl; std::cout << " [-c|--cipher] payload encryption algorithm" << std::endl; + std::cout << " [-K|--key] master key to use for encryption" << std::endl; + std::cout << " [-a|--salt] master salt to use for encryption" << std::endl; std::cout << " [-k|--kd-prf] key derivation pseudo random function" << std::endl; std::cout << " [-a|--auth-algo] message authentication algorithm" << std::endl; } @@ -216,7 +225,9 @@ void Options::printOptions() std::cout << "ifconfig_param_local='" << ifconfig_param_local_ << "'" << std::endl; std::cout << "ifconfig_param_remote_netmask='" << ifconfig_param_remote_netmask_ << "'" << std::endl; std::cout << "seq_window_size='" << seq_window_size_ << "'" << std::endl; + std::cout << "mux_id='" << mux_ << "'" << std::endl; std::cout << "cipher='" << cipher_ << "'" << std::endl; + std::cout << "salt='" << salt_.getHexDump() << "'" << std::endl; std::cout << "kd-prf='" << kd_prf_ << "'" << std::endl; std::cout << "auth_algo='" << auth_algo_ << "'" << std::endl; } @@ -457,3 +468,28 @@ Options& Options::setAuthAlgo(std::string a) auth_algo_ = a; return *this; } + +u_int16_t Options::getMux() +{ + Lock lock(mutex); + return mux_; +} + +Options& Options::setMux(u_int16_t m) +{ + Lock lock(mutex); + mux_ = m; + return *this; +} + +Buffer Options::getKey() +{ + Lock lock(mutex); + return Buffer(u_int32_t(0)); +} + +Options& Options::setKey(std::string k) +{ + Lock lock(mutex); + return *this; +} diff --git a/options.h b/options.h index b533695..b34e012 100644 --- a/options.h +++ b/options.h @@ -32,6 +32,7 @@ #define _OPTIONS_H_ #include "datatypes.h" +#include "buffer.h" #include "threadUtils.hpp" #include @@ -90,6 +91,12 @@ public: std::string getAuthAlgo(); Options& setAuthAlgo(std::string a); ConnectToList getConnectTo(); + Options& setMux(u_int16_t m); + u_int16_t getMux(); + Options& setKey(std::string k); + Buffer getKey(); + Options& setSalt(std::string s); + Buffer getSalt(); private: Options(); @@ -128,6 +135,9 @@ private: std::string cipher_; std::string kd_prf_; std::string auth_algo_; + u_int16_t mux_; + Buffer key_; + Buffer salt_; }; extern Options& gOpt; -- cgit v1.2.3