diff options
author | Christian Pointner <equinox@anytun.org> | 2008-02-27 22:24:52 +0000 |
---|---|---|
committer | Christian Pointner <equinox@anytun.org> | 2008-02-27 22:24:52 +0000 |
commit | 2f9b0dc4a80923c663c44d7af2f0311d225f0949 (patch) | |
tree | 771199288f80e42441977d96309a87505bb0c86c | |
parent | fixed mux autodetect (diff) |
added command line parameter for master key and salt
-rw-r--r-- | anytun.cpp | 29 | ||||
-rw-r--r-- | buffer.cpp | 25 | ||||
-rw-r--r-- | buffer.h | 3 | ||||
-rw-r--r-- | options.cpp | 37 |
4 files changed, 53 insertions, 41 deletions
@@ -77,21 +77,10 @@ void createConnection(const std::string & remote_host, u_int16_t remote_port, ConnectionList & cl, u_int16_t seqSize, SyncQueue & queue, mux_t mux) { - // TODO: use key exchange for master key/salt - uint8_t key[] = { - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', - 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p' - }; - - uint8_t salt[] = { - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', - 'i', 'j', 'k', 'l', 'm', 'n' - }; - SeqWindow * seq= new SeqWindow(seqSize); seq_nr_t seq_nr_=0; KeyDerivation * kd = KeyDerivationFactory::create(gOpt.getKdPrf()); - kd->init(Buffer(key, sizeof(key)), Buffer(salt, sizeof(salt))); + kd->init(gOpt.getKey(), gOpt.getSalt()); cLog.msg(Log::PRIO_NOTICE) << "added connection remote host " << remote_host << ":" << remote_port; ConnectionParam connparam ( (*kd), (*seq), seq_nr_, remote_host, remote_port); cl.addConnection(connparam,mux); @@ -339,22 +328,6 @@ 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)) { @@ -66,8 +66,8 @@ Buffer::Buffer(u_int8_t* data, u_int32_t length, bool allow_realloc) : length_(l } Buffer::Buffer(std::string hex_data, bool allow_realloc) : length_(hex_data.size()/2), - real_length_(length_ + Buffer::OVER_SIZE_), - allow_realloc_(allow_realloc) + real_length_(length_ + Buffer::OVER_SIZE_), + allow_realloc_(allow_realloc) { buf_ = new u_int8_t[real_length_]; if(!buf_) { @@ -75,10 +75,13 @@ Buffer::Buffer(std::string hex_data, bool allow_realloc) : length_(hex_data.size real_length_ = 0; throw std::bad_alloc(); } - std::stringstream tmp(hex_data); - for(u_int32_t i=0;i<length_;++i) + + for(u_int32_t i=0; i<length_; ++i) { - tmp >> std::hex >> std::setw(2) >> buf_[i]; + u_int32_t tmp; + std::istringstream ss(std::string(hex_data.c_str(), i*2, 2)); + if(!(ss >> std::hex >> tmp)) tmp = 0; + buf_[i] = tmp; } } @@ -230,6 +233,18 @@ std::string Buffer::getHexDump() const return ss.str(); } +std::string Buffer::getHexDumpOneLine() const +{ + std::stringstream ss; + ss << length_ << " Bytes,'" << std::hex << std::uppercase; + for( u_int32_t index = 0; index < length_; index++ ) + { + ss << std::setw(2) << std::setfill('0') << u_int32_t(buf_[index]); + } + ss << "'"; + return ss.str(); +} + bool Buffer::isReallocAllowed() const { return allow_realloc_; @@ -43,7 +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); + Buffer(std::string hex_data, bool allow_realloc = true); virtual ~Buffer(); Buffer(const Buffer &src); void operator=(const Buffer &src); @@ -56,6 +56,7 @@ public: u_int8_t& operator[](u_int32_t index); u_int8_t operator[](u_int32_t index) const; std::string getHexDump() const; + std::string getHexDumpOneLine() const; bool isReallocAllowed() const; diff --git a/options.cpp b/options.cpp index 2886332..7e5cac6 100644 --- a/options.cpp +++ b/options.cpp @@ -50,7 +50,7 @@ Options& Options::instance() return *inst; } -Options::Options() +Options::Options() : key_(u_int32_t(0)), salt_(u_int32_t(0)) { progname_ = "anytun"; sender_id_ = 0; @@ -69,8 +69,6 @@ Options::Options() cipher_ = "aes-ctr"; kd_prf_ = "aes-ctr"; auth_algo_ = "sha1"; - key_ = ""; - salt_ = ""; mux_ = 0; } @@ -112,6 +110,16 @@ Options::~Options() i+=2; \ } +#define PARSE_HEXSTRING_PARAM(SHORT, LONG, VALUE) \ + else if(str == SHORT || str == LONG) \ + { \ + if(argc < 1 || argv[i+1][0] == '-') \ + return false; \ + VALUE = Buffer(std::string(argv[i+1])); \ + argc--; \ + i++; \ + } + #define PARSE_CSLIST_PARAM(SHORT, LONG, LIST) \ else if(str == SHORT || str == LONG) \ { \ @@ -157,8 +165,8 @@ bool Options::parse(int argc, char* argv[]) 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_HEXSTRING_PARAM("-K","--key", key_) + PARSE_HEXSTRING_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) @@ -227,7 +235,8 @@ void Options::printOptions() 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 << "key=" << key_.getHexDumpOneLine() << std::endl; + std::cout << "salt=" << salt_.getHexDumpOneLine() << std::endl; std::cout << "kd-prf='" << kd_prf_ << "'" << std::endl; std::cout << "auth_algo='" << auth_algo_ << "'" << std::endl; } @@ -485,11 +494,25 @@ Options& Options::setMux(u_int16_t m) Buffer Options::getKey() { Lock lock(mutex); - return Buffer(u_int32_t(0)); + return key_; } Options& Options::setKey(std::string k) { Lock lock(mutex); + key_ = k; + return *this; +} + +Buffer Options::getSalt() +{ + Lock lock(mutex); + return salt_; +} + +Options& Options::setSalt(std::string s) +{ + Lock lock(mutex); + salt_ = s; return *this; } |