diff --git a/configure.ac b/configure.ac index a6fbb2322..b0f97e621 100644 --- a/configure.ac +++ b/configure.ac @@ -13,10 +13,13 @@ AC_SUBST([$1], ['$2']) AC_PREREQ([2.69]) -AC_INIT([teonet], [0.3.3], [kirill@scherba.ru]) -AC_DEFINE_SUBST(LIBRARY_MAJOR_VERSION, 158, [Teonet dynamic library version]) +AC_INIT([teonet], [0.3.4], [Kirill Scherba , Max Ponka ]) -AC_DEFINE(COPYRIGHT, ["(c) Kirsoft Inc., 1996-2019"], [Teonet library copyright]) +AC_DEFINE_SUBST(LIBRARY_CURRENT, 2, [teocli dynamic library version]) +AC_DEFINE_SUBST(LIBRARY_REVISION, 3, [teocli dynamic library version]) +AC_DEFINE_SUBST(LIBRARY_AGE, 2, [teocli dynamic library version]) + +AC_DEFINE(COPYRIGHT, ["(c) Teonet co., 1996-2019"], [Teonet library copyright]) AC_CONFIG_HEADERS([src/config/config.h]) AC_CONFIG_SRCDIR([src/teonet.hpp]) diff --git a/embedded/teocli b/embedded/teocli index 70832d272..a44e1ddad 160000 --- a/embedded/teocli +++ b/embedded/teocli @@ -1 +1 @@ -Subproject commit 70832d27298e73382338b4e358a831dc5bbfacd4 +Subproject commit a44e1ddade5b0236148ee23f95260f0e6915b4ef diff --git a/sh/make_package.c b/sh/make_package.c index 36b0b69a7..0d92b4915 100644 --- a/sh/make_package.c +++ b/sh/make_package.c @@ -107,8 +107,8 @@ int main(int argc, char** argv) { b_type == DEB ? argv[1] : "rpm", // 0 // Script parameters version, // $1 Version - LIBRARY_MAJOR_VERSION, // $2 Library major version - LIBRARY_MAJOR_VERSION, // $3 Library version + PACKAGE_VERSION, // $2 Library major version + PACKAGE_VERSION, // $3 Library version CI_BUILD_ID != NULL ? CI_BUILD_ID : (CIRCLE_BUILD_NUM != NULL ? CIRCLE_BUILD_NUM : "1"), // $4 Build argc >= 3 ? argv[2] : b_type == DEB ? "amd64" : "x86_64", // $5 Architecture b_type > DEB ? argv[1] : "deb" // $6 RPM subtype diff --git a/src/Makefile.am b/src/Makefile.am index 254ec15ec..dafbda484 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -97,7 +97,8 @@ DEFS = @DEFS@ -DLOCALEDIR=\"${localedir}\" #nodist_include_HEADERS = config/config.h.in teonetincludedir=$(includedir)/teonet - +teobaseincludedir=$(includedir)/teobase +teocclincludedir=$(includedir)/teoccl #teonetinclude_HEADERS = nobase_teonetinclude_HEADERS = \ crypt.h \ @@ -218,8 +219,11 @@ endif # AM_LFLAGS=-Pcfg_yy -olex.yy.c #lexer.c: lexer.l -libteonet_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(LIBRARY_MAJOR_VERSION):0:0 +libteonet_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(LIBRARY_CURRENT):$(LIBRARY_REVISION):$(LIBRARY_AGE) #49:0:0 uninstall-local: -rm -r $(teonetincludedir) + -rm -r $(teobaseincludedir) + -rm -r $(teocclincludedir) + diff --git a/src/config/opt.c b/src/config/opt.c index 1a6f99f9f..5a427f932 100644 --- a/src/config/opt.c +++ b/src/config/opt.c @@ -206,9 +206,15 @@ char ** ksnet_optRead(int argc, char **argv, ksnet_cfg *conf, conf->r_tcp_port = atoi(optarg); break; - case 'a': - strncpy((char*)conf->r_host_addr, optarg, KSN_BUFFER_SM_SIZE/2); - break; + case 'a': { + const char *localhost_str = "localhost"; + const char *localhost_num = "127.0.0.1"; + if (!strncmp(localhost_str, optarg, strlen(localhost_str))) { + strncpy((char*)conf->r_host_addr, localhost_num, strlen(localhost_num)); + } else { + strncpy((char*)conf->r_host_addr, optarg, KSN_BUFFER_SM_SIZE/2); + } + } break; case 'i': strncpy((char*)conf->vpn_ip, optarg, KSN_BUFFER_SM_SIZE/2); diff --git a/src/crypt.c b/src/crypt.c index 82cc6e79f..4c915290f 100644 --- a/src/crypt.c +++ b/src/crypt.c @@ -30,7 +30,7 @@ int num_crypt_module = 0; ksnCryptClass *ksnCryptInit(void *ke) { #define kev ((ksnetEvMgrClass*)ke) - + ksnCryptClass *kcr = malloc(sizeof(ksnCryptClass)); if (kcr == NULL) { fprintf(stderr, "Insufficient memory"); @@ -42,18 +42,18 @@ ksnCryptClass *ksnCryptInit(void *ke) { const char *iv = "0123456789012345"; static const char *key = "01234567890123456789012345678901"; // Network key example: c7931346-add1-4945-b229-b52468f5d1d3 - + // Create unique network IV - strncpy((char*)kcr->iv, iv, BLOCK_SIZE); - if(kev != NULL && kev->ksn_cfg.net_key[0]) + strncpy((char*)kcr->iv, iv, BLOCK_SIZE); + if(kev != NULL && kev->ksn_cfg.net_key[0]) strncpy((char*)kcr->iv, kev->ksn_cfg.net_key, BLOCK_SIZE); - + // Create unique network key - kcr->key = (unsigned char *)strdup((char*)key); - if(kev != NULL && kev->ksn_cfg.net_key[0]) + kcr->key = (unsigned char *)strdup((char*)key); + if(kev != NULL && kev->ksn_cfg.net_key[0]) strncpy((char*)kcr->key, kev->ksn_cfg.net_key, KEY_SIZE); if(kev != NULL && kev->ksn_cfg.network[0]) - strncpy((char*)kcr->key, kev->ksn_cfg.network, KEY_SIZE); + strncpy((char*)kcr->key, kev->ksn_cfg.network, KEY_SIZE); kcr->key_len = strlen((char*)kcr->key); // 32 - 256 bits kcr->blocksize = BLOCK_SIZE; @@ -61,12 +61,12 @@ ksnCryptClass *ksnCryptInit(void *ke) { if(!num_crypt_module) { ERR_load_crypto_strings(); OpenSSL_add_all_algorithms(); - OPENSSL_config(NULL); + //OPENSSL_config(NULL); } num_crypt_module++; return kcr; - + #undef kev } @@ -115,7 +115,7 @@ size_t _encrypt(unsigned char *plaintext, size_t plaintext_len, * IV size for *most* modes is the same as the block size. For AES this * is 128 bits */ if(1 != EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv)) { - + handleErrors(); return 0; } @@ -124,7 +124,7 @@ size_t _encrypt(unsigned char *plaintext, size_t plaintext_len, * EVP_EncryptUpdate can be called multiple times if necessary */ if(1 != EVP_EncryptUpdate(ctx, ciphertext, &len, plaintext, plaintext_len)) { - + handleErrors(); return 0; } @@ -134,7 +134,7 @@ size_t _encrypt(unsigned char *plaintext, size_t plaintext_len, * this stage. */ if(1 != EVP_EncryptFinal_ex(ctx, ciphertext + len, &len)) { - + handleErrors(); return 0; } @@ -169,7 +169,7 @@ int _decrypt(ksnCryptClass *kcr, unsigned char *ciphertext, int ciphertext_len, /* Create and initialize the context */ if(!(ctx = EVP_CIPHER_CTX_new())) { - + handleErrors(); return 0; } @@ -180,7 +180,7 @@ int _decrypt(ksnCryptClass *kcr, unsigned char *ciphertext, int ciphertext_len, * IV size for *most* modes is the same as the block size. For AES this * is 128 bits */ if(1 != EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), NULL, key, iv)) { - + handleErrors(); return 0; } @@ -189,7 +189,7 @@ int _decrypt(ksnCryptClass *kcr, unsigned char *ciphertext, int ciphertext_len, * EVP_DecryptUpdate can be called multiple times if necessary */ if(1 != EVP_DecryptUpdate(ctx, plaintext, &len, ciphertext, ciphertext_len)) { - + handleErrors(); return 0; } @@ -199,7 +199,7 @@ int _decrypt(ksnCryptClass *kcr, unsigned char *ciphertext, int ciphertext_len, * this stage. */ if(1 != EVP_DecryptFinal_ex(ctx, plaintext + len, &len)) { - + #ifdef DEBUG_KSNET ksn_printf(((ksnetEvMgrClass*)kcr->ke), MODULE, DEBUG, "can't decrypt %d bytes package ...\n", @@ -291,9 +291,9 @@ void *ksnDecryptPackage(ksnCryptClass *kcr, void* package, #endif *decrypt_len = _decrypt(kcr, package + ptr, package_len - ptr, kcr->key, kcr->iv, decrypted); - - // Copy decrypted data (if decrypted, or - if(*decrypt_len) { + + // Copy decrypted data (if decrypted, or + if(*decrypt_len) { // Add a NULL terminator. We are expecting printable text decrypted[*decrypt_len] = '\0'; @@ -301,13 +301,13 @@ void *ksnDecryptPackage(ksnCryptClass *kcr, void* package, // Copy and free decrypted buffer memcpy(package + ptr, decrypted, *decrypt_len + 1); } - + // If data not decrypted - return input package with package len else { ptr = 0; *decrypt_len = package_len; } - + free(decrypted); return package + ptr; @@ -315,15 +315,15 @@ void *ksnDecryptPackage(ksnCryptClass *kcr, void* package, /** * Simple check if the packet is encrypted - * + * * @param package Pointer to package * @param package_len Package length - * @return + * @return */ int ksnCheckEncrypted(void *package, size_t package_len) { - + size_t ptr = 0; - size_t decrypt_len = *((uint16_t*)package); ptr += sizeof(uint16_t); - + size_t decrypt_len = *((uint16_t*)package); ptr += sizeof(uint16_t); + return decrypt_len && decrypt_len < package_len && !((package_len - ptr) % BLOCK_SIZE); } diff --git a/src/ev_mgr.c b/src/ev_mgr.c index a76190c1e..484d42db3 100644 --- a/src/ev_mgr.c +++ b/src/ev_mgr.c @@ -1295,7 +1295,7 @@ void idle_activity_cb(EV_P_ ev_idle *w, int revents) { } // Check TR-UDP activity - trudpProcessKeepConnection(kev->kc->ku); + //trudpProcessKeepConnection(kev->kc->ku); #undef kev } diff --git a/src/net_core.c b/src/net_core.c index 556584fd0..c11543500 100644 --- a/src/net_core.c +++ b/src/net_core.c @@ -576,17 +576,20 @@ int ksnCoreParsePacket(void *packet, size_t packet_len, ksnCorePacketData *rd) { rd->raw_data = packet; rd->raw_data_len = packet_len; - rd->from_len = *((uint8_t*)packet); ptr += sizeof(rd->from_len); // From length - if(rd->from_len && - rd->from_len + PACKET_HEADER_ADD_SIZE <= packet_len && - *((char*)(packet + ptr + rd->from_len - 1)) == '\0') { - - rd->from = (char*)(packet + ptr); ptr += rd->from_len; // From pointer - rd->cmd = *((uint8_t*)(packet + ptr)); ptr += sizeof(rd->cmd); // Command ID + rd->from_len = *((uint8_t *)packet); ptr += sizeof(rd->from_len); // From length + if (rd->from_len && + rd->from_len + PACKET_HEADER_ADD_SIZE <= packet_len && + *((char *)(packet + ptr + rd->from_len - 1)) == '\0' + ) { + rd->from = (char *)(packet + ptr); ptr += rd->from_len; // From pointer + if(strlen(rd->from) + 1 == rd->from_len) { + + rd->cmd = *((uint8_t *)(packet + ptr)); ptr += sizeof(rd->cmd); // Command ID rd->data = packet + ptr; // Data pointer rd->data_len = packet_len - ptr; // Data length packed_valid = 1; + } } return packed_valid;