New upstream version 0.3.7 upstream/0.3.7
authorDarshaka Pathirana <dpat@syn-net.org>
Sun, 22 Jul 2018 12:52:05 +0000 (14:52 +0200)
committerDarshaka Pathirana <dpat@syn-net.org>
Sun, 22 Jul 2018 12:52:05 +0000 (14:52 +0200)
16 files changed:
ChangeLog
doc/anytun-config.8
doc/anytun-controld.8
doc/anytun-showtables.8
doc/anytun.8
src/authAlgo.cpp
src/authAlgo.h
src/authAlgoFactory.cpp
src/cipher.cpp
src/cipher.h
src/configure
src/keyDerivation.cpp
src/linux/tunDevice.cpp
src/options.cpp
src/routingTreeNode.cpp
version

index c9dda20..9348e7e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2018.06.08 -- version 0.3.7
+
+* fix build for new versions of GCC and Boost
+* add support for OpenSSL 1.1
+
 2016.07.08 -- Version 0.3.6
 
 * fixed build for GCC-6 and C++0x
index bbb0b2e..f958056 100644 (file)
@@ -2,12 +2,12 @@
 .\"     Title: anytun-config
 .\"    Author: [see the "AUTHORS" section]
 .\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
-.\"      Date: 07/08/2016
+.\"      Date: 06/09/2018
 .\"    Manual: \ \&
 .\"    Source: \ \&
 .\"  Language: English
 .\"
-.TH "ANYTUN\-CONFIG" "8" "07/08/2016" "\ \&" "\ \&"
+.TH "ANYTUN\-CONFIG" "8" "06/09/2018" "\ \&" "\ \&"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
index 4cc0c41..a8ce738 100644 (file)
@@ -2,12 +2,12 @@
 .\"     Title: anytun-controld
 .\"    Author: [see the "AUTHORS" section]
 .\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
-.\"      Date: 07/08/2016
+.\"      Date: 06/09/2018
 .\"    Manual: \ \&
 .\"    Source: \ \&
 .\"  Language: English
 .\"
-.TH "ANYTUN\-CONTROLD" "8" "07/08/2016" "\ \&" "\ \&"
+.TH "ANYTUN\-CONTROLD" "8" "06/09/2018" "\ \&" "\ \&"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
index 74d39e5..f75de02 100644 (file)
@@ -2,12 +2,12 @@
 .\"     Title: anytun-showtables
 .\"    Author: [see the "AUTHORS" section]
 .\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
-.\"      Date: 07/08/2016
+.\"      Date: 06/09/2018
 .\"    Manual: \ \&
 .\"    Source: \ \&
 .\"  Language: English
 .\"
-.TH "ANYTUN\-SHOWTABLES" "8" "07/08/2016" "\ \&" "\ \&"
+.TH "ANYTUN\-SHOWTABLES" "8" "06/09/2018" "\ \&" "\ \&"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
index 7a35e5a..2539aec 100644 (file)
@@ -2,12 +2,12 @@
 .\"     Title: anytun
 .\"    Author: [see the "AUTHORS" section]
 .\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
-.\"      Date: 07/08/2016
+.\"      Date: 06/09/2018
 .\"    Manual: \ \&
 .\"    Source: \ \&
 .\"  Language: English
 .\"
-.TH "ANYTUN" "8" "07/08/2016" "\ \&" "\ \&"
+.TH "ANYTUN" "8" "06/09/2018" "\ \&" "\ \&"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
index f0e3303..561b0b6 100644 (file)
@@ -68,23 +68,51 @@ bool NullAuthAlgo::checkTag(KeyDerivation& kd, EncryptedPacket& packet)
 Sha1AuthAlgo::Sha1AuthAlgo(kd_dir_t d) : AuthAlgo(d), key_(DIGEST_LENGTH)
 {
 #if defined(USE_SSL_CRYPTO)
-  HMAC_CTX_init(&ctx_);
-  HMAC_Init_ex(&ctx_, NULL, 0, EVP_sha1(), NULL);
+  ctx_ = NULL;
+#elif defined(USE_NETTLE)
+  // nothing here
+#else  // USE_GCRYPT is the default
+  handle_ = 0;
+#endif
+}
+
+bool Sha1AuthAlgo::Init()
+{
+#if defined(USE_SSL_CRYPTO)
+# if OPENSSL_VERSION_NUMBER >= 0x10100000L
+  if ((ctx_ = HMAC_CTX_new()) == NULL) {
+    return false;
+  }
+# else
+  if ((ctx_ = (HMAC_CTX*)calloc(1, sizeof(HMAC_CTX))) == NULL) {
+    return false;
+  }
+  HMAC_CTX_init(ctx_);
+# endif
+  HMAC_Init_ex(ctx_, NULL, 0, EVP_sha1(), NULL);
 #elif defined(USE_NETTLE)
   // nothing here
 #else  // USE_GCRYPT is the default
   gcry_error_t err = gcry_md_open(&handle_, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC);
   if(err) {
     cLog.msg(Log::PRIO_ERROR) << "Sha1AuthAlgo::Sha1AuthAlgo: Failed to open message digest algo";
-    return;
+    return false;
   }
 #endif
+  return true;
 }
 
 Sha1AuthAlgo::~Sha1AuthAlgo()
 {
 #if defined(USE_SSL_CRYPTO)
-  HMAC_CTX_cleanup(&ctx_);
+  if(ctx_) {
+# if OPENSSL_VERSION_NUMBER >= 0x10100000L
+    HMAC_CTX_free(ctx_);
+# else
+    HMAC_CTX_cleanup(ctx_);
+    free(ctx_);
+# endif
+  }
 #elif defined(USE_NETTLE)
   // nothing here
 #else  // USE_GCRYPT is the default
@@ -109,11 +137,11 @@ void Sha1AuthAlgo::generate(KeyDerivation& kd, EncryptedPacket& packet)
 
   kd.generate(dir_, LABEL_AUTH, packet.getSeqNr(), key_);
 #if defined(USE_SSL_CRYPTO)
-  HMAC_Init_ex(&ctx_, key_.getBuf(), key_.getLength(), EVP_sha1(), NULL);
+  HMAC_Init_ex(ctx_, key_.getBuf(), key_.getLength(), EVP_sha1(), NULL);
 
   uint8_t hmac[DIGEST_LENGTH];
-  HMAC_Update(&ctx_, packet.getAuthenticatedPortion(), packet.getAuthenticatedPortionLength());
-  HMAC_Final(&ctx_, hmac, NULL);
+  HMAC_Update(ctx_, packet.getAuthenticatedPortion(), packet.getAuthenticatedPortionLength());
+  HMAC_Final(ctx_, hmac, NULL);
 #elif defined(USE_NETTLE)
   hmac_sha1_set_key(&ctx_, key_.getLength(), key_.getBuf());
 
@@ -158,11 +186,11 @@ bool Sha1AuthAlgo::checkTag(KeyDerivation& kd, EncryptedPacket& packet)
 
   kd.generate(dir_, LABEL_AUTH, packet.getSeqNr(), key_);
 #if defined(USE_SSL_CRYPTO)
-  HMAC_Init_ex(&ctx_, key_.getBuf(), key_.getLength(), EVP_sha1(), NULL);
+  HMAC_Init_ex(ctx_, key_.getBuf(), key_.getLength(), EVP_sha1(), NULL);
 
   uint8_t hmac[DIGEST_LENGTH];
-  HMAC_Update(&ctx_, packet.getAuthenticatedPortion(), packet.getAuthenticatedPortionLength());
-  HMAC_Final(&ctx_, hmac, NULL);
+  HMAC_Update(ctx_, packet.getAuthenticatedPortion(), packet.getAuthenticatedPortionLength());
+  HMAC_Final(ctx_, hmac, NULL);
 #elif defined(USE_NETTLE)
   hmac_sha1_set_key(&ctx_, key_.getLength(), key_.getBuf());
 
index a1fcea4..758e754 100644 (file)
@@ -101,10 +101,13 @@ public:
 //****** Sha1AuthAlgo ******
 //* HMAC SHA1 Auth Tag Generator Class
 
+class AuthAlgoFactory;
+
 class Sha1AuthAlgo : public AuthAlgo
 {
+  friend class AuthAlgoFactory;
+
 public:
-  Sha1AuthAlgo(kd_dir_t d);
   ~Sha1AuthAlgo();
 
   void generate(KeyDerivation& kd, EncryptedPacket& packet);
@@ -113,8 +116,11 @@ public:
   static const uint32_t DIGEST_LENGTH = 20;
 
 private:
+  Sha1AuthAlgo(kd_dir_t d);
+  bool Init();
+
 #if defined(USE_SSL_CRYPTO)
-  HMAC_CTX ctx_;
+  HMAC_CTX *ctx_;
 #elif defined(USE_NETTLE)
   struct hmac_sha1_ctx ctx_;
 #else  // USE_GCRYPT is the default
index b859f33..e30a4b4 100644 (file)
@@ -48,6 +48,7 @@
 
 #include "authAlgoFactory.h"
 #include "authAlgo.h"
+#include "anytunError.h"
 
 
 AuthAlgo* AuthAlgoFactory::create(std::string const& type, kd_dir_t dir)
@@ -57,7 +58,13 @@ AuthAlgo* AuthAlgoFactory::create(std::string const& type, kd_dir_t dir)
   }
 #ifndef NO_CRYPT
   else if(type == "sha1") {
-    return new Sha1AuthAlgo(dir);
+    Sha1AuthAlgo* a = new Sha1AuthAlgo(dir);
+    if(!a || !(a->Init())) {
+      if(a)
+        delete a;
+      AnytunError::throwErr() << "failed to initialize SHA1 auth algo";
+    }
+    return a;
   }
 #endif
   else {
index 52a2543..f3b2ed1 100644 (file)
@@ -207,7 +207,7 @@ void AesIcmCipher::calc(KeyDerivation& kd, uint8_t* in, uint32_t ilen, uint8_t*
   }
   unsigned int num = 0;
   std::memset(ecount_buf_, 0, AES_BLOCK_SIZE);
-  AES_ctr128_encrypt(in, out, (ilen < olen) ? ilen : olen, &aes_key_, ctr_.buf_, ecount_buf_, &num);
+  CRYPTO_ctr128_encrypt(in, out, (ilen < olen) ? ilen : olen, &aes_key_, ctr_.buf_, ecount_buf_, &num, (block128_f)AES_encrypt);
 #elif defined(USE_NETTLE)
   if(CTR_LENGTH != AES_BLOCK_SIZE) {
     cLog.msg(Log::PRIO_ERROR) << "AesIcmCipher: Failed to set cipher CTR: size doesn't fit";
index 6408ffd..e47dab9 100644 (file)
@@ -55,7 +55,9 @@
 #ifndef NO_CRYPT
 
 #if defined(USE_SSL_CRYPTO)
+#include <openssl/crypto.h>
 #include <openssl/aes.h>
+#include <openssl/modes.h>
 #elif defined(USE_NETTLE)
 #include <nettle/aes.h>
 #else  // USE_GCRYPT is the default
index 082e523..b8a7f3f 100755 (executable)
@@ -283,6 +283,7 @@ if [ -n "$BOOST_PREFIX" ]; then
   LDFLAGS="$LDFLAGS -L\"$BOOST_PREFIX/lib\""
 fi
 
+CRYPTO_LIB_NAME=""
 case $CRYPTO_LIB in
   gcrypt)
     CXXFLAGS=$CXXFLAGS' -DUSE_GCRYPT'
@@ -291,6 +292,7 @@ case $CRYPTO_LIB in
       CXXFLAGS="$CXXFLAGS -I\"$GCRYPT_PREFIX/include\""
       LDFLAGS="$LDFLAGS -L\"$GCRYPT_PREFIX/lib\""
     fi
+    CRYPTO_LIB_NAME="libgcrypt"
     echo "using gcrypt library"
   ;;
   nettle)
@@ -300,6 +302,7 @@ case $CRYPTO_LIB in
       CXXFLAGS="$CXXFLAGS -I\"$NETTLE_PREFIX/include\""
       LDFLAGS="$LDFLAGS -L\"$NETTLE_PREFIX/lib\""
     fi
+    CRYPTO_LIB_NAME="Nettle"
     echo "using nettle library"
   ;;
   ssl)
@@ -309,10 +312,12 @@ case $CRYPTO_LIB in
       CXXFLAGS="$CXXFLAGS -I\"$OPENSSL_PREFIX/include\""
       LDFLAGS="$LDFLAGS -L\"$OPENSSL_PREFIX/lib\""
     fi
+    CRYPTO_LIB_NAME="OpenSSL"
     echo "using openssl crypto library"
   ;;
   none)
     CXXFLAGS=$CXXFLAGS' -DNO_CRYPT'
+    CRYPTO_LIB_NAME="none"
     echo "disabling crypto"
   ;;
 esac
@@ -417,8 +422,6 @@ if which git >/dev/null; then
         VERSION="$VERSION (git $GIT_HASH)"
     fi
 fi
-HOSTNAME=`hostname`
-DATE=`date +"%d.%m.%Y %H:%M:%S %Z"`
 
 cat > version.h <<EOF
 /*
@@ -432,8 +435,8 @@ cat > version.h <<EOF
 #ifndef ANYTUN_version_h_INCLUDED
 #define ANYTUN_version_h_INCLUDED
 
-#define VERSION_STRING_0 " version $VERSION"
-#define VERSION_STRING_1 "built on $HOSTNAME, $DATE"
+#define VERSION_STRING " version $VERSION"
+#define CRYPTO_LIB_NAME "$CRYPTO_LIB_NAME"
 
 #endif
 EOF
index 780a51c..812dc44 100644 (file)
@@ -61,7 +61,9 @@
 #ifndef NO_PASSPHRASE
 
 #if defined(USE_SSL_CRYPTO)
+#include <openssl/crypto.h>
 #include <openssl/sha.h>
+#include <openssl/modes.h>
 #elif defined(USE_NETTLE)
 #include <nettle/sha1.h>
 #include <nettle/sha2.h>
@@ -363,9 +365,9 @@ bool AesIcmKeyDerivation::generate(kd_dir_t dir, satp_prf_label_t label, seq_nr_
     return false;
   }
   unsigned int num = 0;
-  std::memset(ecount_buf_[dir], 0, AES_BLOCK_SIZE);
   std::memset(key.getBuf(), 0, key.getLength());
-  AES_ctr128_encrypt(key.getBuf(), key.getBuf(), key.getLength(), &aes_key_[dir], ctr_[dir].buf_, ecount_buf_[dir], &num);
+  std::memset(ecount_buf_[dir], 0, AES_BLOCK_SIZE);
+  CRYPTO_ctr128_encrypt(key.getBuf(), key.getBuf(), key.getLength(), &aes_key_[dir], ctr_[dir].buf_, ecount_buf_[dir], &num, (block128_f)AES_encrypt);
 #elif defined(USE_NETTLE)
   if(CTR_LENGTH != AES_BLOCK_SIZE) {
     cLog.msg(Log::PRIO_ERROR) << "AesIcmCipher: Failed to set cipher CTR: size doesn't fit";
index e3f5bf4..97a7ede 100644 (file)
@@ -79,7 +79,7 @@ TunDevice::TunDevice(std::string dev_name, std::string dev_type, std::string ifc
   }
 
   if(dev_name != "") {
-    strncpy(ifr.ifr_name, dev_name.c_str(), IFNAMSIZ);
+    strncpy(ifr.ifr_name, dev_name.c_str(), IFNAMSIZ-1);
   }
 
   fd_ = ::open(DEFAULT_DEVICE, O_RDWR);
index 038e7b7..8cfc480 100644 (file)
@@ -558,17 +558,16 @@ void Options::printVersion()
 #else
   std::cout << "anytun";
 #endif
-  std::cout << VERSION_STRING_0 << std::endl;
+  std::cout << VERSION_STRING << std::endl;
 
 #if defined(__clang__)
-  std::cout << VERSION_STRING_1 << ", using CLANG " << __clang_version__ << std::endl;
+  std::cout << "built using CLANG " << __clang_version__ << " with " << CRYPTO_LIB_NAME << " crypto library." << std::endl;
 #elif defined(__GNUC__)
-  std::cout << VERSION_STRING_1 << ", using GCC " << __GNUC__ << '.' << __GNUC_MINOR__
-            << '.' << __GNUC_PATCHLEVEL__ << std::endl;
+  std::cout << "built using GCC " << __GNUC__ << '.' << __GNUC_MINOR__ << '.' << __GNUC_PATCHLEVEL__
+            << " with " << CRYPTO_LIB_NAME << " crypto library." << std::endl;
 #else
-  std::cout << VERSION_STRING_1 << std::endl;
+  std::cout << "built using an unknown compiler " << CRYPTO_LIB_NAME << " crypto library." << std::endl;
 #endif
-
 }
 
 void Options::printUsage()
index cee0eb2..880285b 100644 (file)
@@ -43,6 +43,8 @@
  *  files in the program, then also delete it here.
  */
 
+#include <iostream>
+
 #include "routingTreeNode.h"
 
 RoutingTreeNode::RoutingTreeNode():mux_(0),valid_(false)
diff --git a/version b/version
index 449d7e7..0f82685 100644 (file)
--- a/version
+++ b/version
@@ -1 +1 @@
-0.3.6
+0.3.7