summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErwin Nindl <nine@wirdorange.org>2008-02-27 21:21:05 +0000
committerErwin Nindl <nine@wirdorange.org>2008-02-27 21:21:05 +0000
commit63cc38e6bd6329dfe0021adc2f8609bf7819fc49 (patch)
tree07bceb456776f1f0b98dcc53a843097f612f37ef
parentremoved debug statements (diff)
added mux to options
-rw-r--r--anytun.cpp18
-rw-r--r--buffer.cpp18
-rw-r--r--buffer.h1
-rw-r--r--options.cpp36
-rw-r--r--options.h10
5 files changed, 82 insertions, 1 deletions
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 <stdexcept>
#include <string>
#include <sstream>
+#include <iostream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#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<length_;++i)
+ {
+ tmp >> 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] <local> the local address for the tun/tap device" << std::endl
<< " <remote|netmask> the remote address(tun) or netmask(tap)" << std::endl;
std::cout << " [-w|--window-size] <window size> seqence number window size" << std::endl;
+ std::cout << " [-m|--mux] <mux-id> the multiplex id to use" << std::endl;
std::cout << " [-c|--cipher] <cipher type> payload encryption algorithm" << std::endl;
+ std::cout << " [-K|--key] <master key> master key to use for encryption" << std::endl;
+ std::cout << " [-a|--salt] <master salt> master salt to use for encryption" << std::endl;
std::cout << " [-k|--kd-prf] <kd-prf type> key derivation pseudo random function" << std::endl;
std::cout << " [-a|--auth-algo] <algo type> 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 <list>
@@ -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;