diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 884fff9d5..1a4cd79d3 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -299,6 +299,9 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int else printf("%s got recv.%d\n",typestr,recvlen); #endif double millis = OS_milliseconds(); + if ( strlen((char *)ptr)+sizeof(bits256) <= recvlen ) + if ( LP_magic_check(ptr,recvlen) < 0 ) + printf("magic check error\n"); if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,ptr,recvlen,sock)) != 0 ) free(retstr); if ( Broadcaststr != 0 ) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 41d514078..b8d973f49 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -166,13 +166,29 @@ bits256 LP_calc_magic(uint8_t *msg,int32_t len) { magic = rand256(1); pubkey = curve25519(magic,curve25519_basepoint9()); - shared = curve25519(magic,pubkey); + shared = curve25519(hash,pubkey); if ( shared.bytes[1] == LP_BARTERDEX_VERSION ) break; } return(magic); } +int32_t LP_magic_check(uint8_t *msg,int32_t recvlen) +{ + bits256 magic,hash,pubkey,shared; + recvlen -= sizeof(bits256); + if ( recvlen > 0 ) + { + vcalc_sha256(0,hash.bytes,msg,recvlen); + memcpy(magic.bytes,&msg[recvlen],sizeof(magic)); + pubkey = curve25519(magic,curve25519_basepoint9()); + shared = curve25519(hash,pubkey); + printf("shared.[1] = %d\n",shared.bytes[1]); + return(shared.bytes[1] == LP_BARTERDEX_VERSION); + } + return(-1); +} + int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32) { static uint32_t crcs[1024]; static unsigned long dup,total;