Skip to content

Commit

Permalink
Merge branch 'release/v0.3.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
angelskieglazki committed Aug 28, 2019
2 parents 7db8c93 + 957e527 commit 197b8c0
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 46 deletions.
9 changes: 6 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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 <kirill@scherba.ru>, Max Ponka <mpano91@gmail.com>])

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])
Expand Down
2 changes: 1 addition & 1 deletion embedded/teocli
4 changes: 2 additions & 2 deletions sh/make_package.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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)

12 changes: 9 additions & 3 deletions src/config/opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
54 changes: 27 additions & 27 deletions src/crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -42,31 +42,31 @@ 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;

// Initialize the library
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
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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",
Expand Down Expand Up @@ -291,39 +291,39 @@ 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';

// 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;
}

/**
* 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);
}
2 changes: 1 addition & 1 deletion src/ev_mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
17 changes: 10 additions & 7 deletions src/net_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 197b8c0

Please sign in to comment.