mirror of
https://github.com/outbackdingo/nDPId.git
synced 2026-01-27 10:19:45 +00:00
Added nDPId decryption example
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
This commit is contained in:
@@ -15,7 +15,8 @@ if("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
|
||||
"Please remove ${PROJECT_SOURCE_DIR}/CMakeCache.txt\n"
|
||||
"and\n"
|
||||
"${PROJECT_SOURCE_DIR}/CMakeFiles\n"
|
||||
"Create a build directory somewhere and run CMake again.")
|
||||
"Create a build directory somewhere and run CMake again.\n"
|
||||
"Or run: 'cmake -S ${PROJECT_SOURCE_DIR} -B ./your-custom-build-dir [CMAKE-OPTIONS]'")
|
||||
endif()
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
@@ -562,6 +563,14 @@ if(BUILD_EXAMPLES)
|
||||
install(TARGETS nDPIsrvd-influxd DESTINATION bin)
|
||||
endif()
|
||||
|
||||
if(ENABLE_CRYPTO)
|
||||
add_executable(nDPId-decrypt examples/c-decrypt/c-decrypt.c utils.c ncrypt.c)
|
||||
target_compile_definitions(nDPId-decrypt PRIVATE ${NDPID_DEFS} ${OSSL_DEFS})
|
||||
target_include_directories(nDPId-decrypt PRIVATE ${NDPID_DEPS_INC})
|
||||
target_link_libraries(nDPId-decrypt ${OSSL_LIBRARY})
|
||||
install(TARGETS nDPId-decrypt DESTINATION bin)
|
||||
endif()
|
||||
|
||||
install(TARGETS nDPIsrvd-analysed nDPIsrvd-collectd nDPIsrvd-captured nDPIsrvd-simple DESTINATION bin)
|
||||
install(FILES examples/c-collectd/plugin_nDPIsrvd.conf examples/c-collectd/rrdgraph.sh DESTINATION share/nDPId/nDPIsrvd-collectd)
|
||||
install(DIRECTORY examples/c-collectd/www DESTINATION share/nDPId/nDPIsrvd-collectd)
|
||||
|
||||
74
examples/c-decrypt/c-decrypt.c
Normal file
74
examples/c-decrypt/c-decrypt.c
Normal file
@@ -0,0 +1,74 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
static void print_usage(char const * const arg0)
|
||||
{
|
||||
static char const usage[] =
|
||||
"Usage: %s "
|
||||
"[-L listen-address] [-k private-key-file] [-K public-key-file]\n"
|
||||
"\t \t"
|
||||
"[-h]\n\n"
|
||||
"\t-L\tThe address on which this example will listen for incoming\n"
|
||||
"\t \t(encrypted) UDP packets sent by nDPId\n"
|
||||
"\t-k\tThe path to the local private X25519 key file (PEM format)\n"
|
||||
"\t-K\tThe path to the remote public X25519 key file (PEM format)\n"
|
||||
"\t-h\tthis\n";
|
||||
|
||||
fprintf(stderr, usage, arg0);
|
||||
}
|
||||
|
||||
static int parse_options(int argc, char ** argv)
|
||||
{
|
||||
int opt;
|
||||
|
||||
while ((opt = getopt(argc, argv, "hk:K:s:")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'h':
|
||||
print_usage(argv[0]);
|
||||
return 1;
|
||||
case 'k':
|
||||
break;
|
||||
case 'K':
|
||||
break;
|
||||
case 's':
|
||||
break;
|
||||
default:
|
||||
print_usage(argv[0]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (optind < argc)
|
||||
{
|
||||
if (optind > 0) {
|
||||
logger_early(1, "Unexpected argument(s) after %s\n\n", argv[optind]);
|
||||
} else {
|
||||
logger_early(1, "%s\n\n", "Unexpected argument(s)");
|
||||
}
|
||||
print_usage(argv[0]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
if (argc == 0 || argv == NULL || stdout == NULL || stderr == NULL)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
init_logging("nDPId-decrypt");
|
||||
|
||||
if (parse_options(argc, argv) != 0)
|
||||
{
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user