diff --git a/cmake/src/main/hook/pri/CMakeLists.txt b/cmake/src/main/hook/pri/CMakeLists.txt index 8502c22..7deb123 100644 --- a/cmake/src/main/hook/pri/CMakeLists.txt +++ b/cmake/src/main/hook/pri/CMakeLists.txt @@ -8,6 +8,7 @@ add_resources(DOG_KEY ${SRC} prihook.hasp.key) set(SOURCE_FILES ${SRC}/main.c + ${SRC}/net-crypt.c ${SRC}/options.c ${SRC}/usb-updates.c) diff --git a/src/main/hook/pri/net-crypt.c b/src/main/hook/pri/net-crypt.c new file mode 100644 index 0000000..f0eda36 --- /dev/null +++ b/src/main/hook/pri/net-crypt.c @@ -0,0 +1,40 @@ +#define LOG_MODULE "prinet-net-crypt" + +#include "capnhook/hook/lib.h" + +#include "util/log.h" + +typedef int (*crypto_box_open_easy_t)( + unsigned char* m, + const unsigned char* c, + unsigned long long clen, + unsigned long long unkn_len, + const unsigned char* n, + const unsigned char* pk, + const unsigned char* sk); + +static crypto_box_open_easy_t prihook_net_crypt_real_crypto_box_open_easy; + +int crypto_box_open_easy( + unsigned char* m, + const unsigned char* c, + unsigned long long clen, + unsigned long long unkn_len, + const unsigned char* n, + const unsigned char* pk, + const unsigned char* sk) +{ + if (!prihook_net_crypt_real_crypto_box_open_easy) { + prihook_net_crypt_real_crypto_box_open_easy = + (crypto_box_open_easy_t) cnh_lib_get_func_addr("crypto_box_open_easy"); + } + + int res = prihook_net_crypt_real_crypto_box_open_easy( + m, c, clen, unkn_len, n, pk, sk); + + if (res != 0) { + log_error("Decrypting message (len %d) failed: %d", clen, res); + } + + return res; +}