This commit is contained in:
		
							
								
								
									
										1
									
								
								.idea/misc.xml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1
									
								
								.idea/misc.xml
									
									
									
										generated
									
									
									
								
							@@ -1,4 +1,3 @@
 | 
				
			|||||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
					 | 
				
			||||||
<project version="4">
 | 
					<project version="4">
 | 
				
			||||||
  <component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
 | 
					  <component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
 | 
				
			||||||
  <component name="CidrRootsConfiguration">
 | 
					  <component name="CidrRootsConfiguration">
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,7 +4,60 @@ project(fileserver)
 | 
				
			|||||||
set(CMAKE_CXX_STANDARD 23)
 | 
					set(CMAKE_CXX_STANDARD 23)
 | 
				
			||||||
set(CMAKE_CXX_STANDARD_REQUIRED YES)
 | 
					set(CMAKE_CXX_STANDARD_REQUIRED YES)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
add_subdirectory(lib EXCLUDE_FROM_ALL)
 | 
					include(CPM.cmake)
 | 
				
			||||||
 | 
					CPMAddPackage("gh:richgel999/miniz#3.0.2")
 | 
				
			||||||
 | 
					CPMAddPackage("gh:gabime/spdlog#v1.13.0")
 | 
				
			||||||
 | 
					CPMAddPackage(
 | 
				
			||||||
 | 
					    NAME restbed
 | 
				
			||||||
 | 
					    VERSION 4.8
 | 
				
			||||||
 | 
					    GITHUB_REPOSITORY Corvusoft/restbed
 | 
				
			||||||
 | 
					    GIT_TAG 4.8
 | 
				
			||||||
 | 
					    DOWNLOAD_ONLY YES
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					CPMAddPackage(
 | 
				
			||||||
 | 
					    NAME asio
 | 
				
			||||||
 | 
					    VERSION 1.29.0
 | 
				
			||||||
 | 
					    GITHUB_REPOSITORY chriskohlhoff/asio
 | 
				
			||||||
 | 
					    GIT_TAG asio-1-29-0
 | 
				
			||||||
 | 
					    DOWNLOAD_ONLY YES
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(asio_ADDED AND restbed_ADDED)
 | 
				
			||||||
 | 
					    file(GLOB_RECURSE restbed_SOURCE "${restbed_SOURCE_DIR}/source/corvusoft/restbed/*.cpp")
 | 
				
			||||||
 | 
					    add_library(restbed-static STATIC ${restbed_SOURCE} "${asio_SOURCE_DIR}/asio/src/asio.cpp")
 | 
				
			||||||
 | 
					    target_compile_definitions(restbed-static PUBLIC ASIO_SEPARATE_COMPILATION)
 | 
				
			||||||
 | 
					    target_include_directories(restbed-static PUBLIC "${restbed_SOURCE_DIR}/source" "${asio_SOURCE_DIR}/asio/include")
 | 
				
			||||||
 | 
					endif()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					set(BOTAN_MODULES argon2fmt hotp base32 auto_rng system_rng tls13 certstor_system certstor_flatfile md5)
 | 
				
			||||||
 | 
					CPMAddPackage(
 | 
				
			||||||
 | 
					    NAME botan
 | 
				
			||||||
 | 
					    VERSION 3.4.0
 | 
				
			||||||
 | 
					    GITHUB_REPOSITORY randombit/botan
 | 
				
			||||||
 | 
					    GIT_TAG 3.4.0
 | 
				
			||||||
 | 
					    DOWNLOAD_ONLY YES
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(botan_ADDED)
 | 
				
			||||||
 | 
					    list(JOIN BOTAN_MODULES , BOTAN_MODULES_STR)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    add_custom_command(
 | 
				
			||||||
 | 
					        OUTPUT botan_all.cpp botan_all.h
 | 
				
			||||||
 | 
					        COMMAND ${botan_SOURCE_DIR}/configure.py
 | 
				
			||||||
 | 
					            --disable-shared
 | 
				
			||||||
 | 
					            --amalgamation
 | 
				
			||||||
 | 
					            --minimized-build
 | 
				
			||||||
 | 
					            --without-documentation
 | 
				
			||||||
 | 
					            --enable-modules=${BOTAN_MODULES_STR}
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    add_library(botan STATIC ${CMAKE_CURRENT_BINARY_DIR}/botan_all.cpp ${CMAKE_CURRENT_BINARY_DIR}/botan_all.h)
 | 
				
			||||||
 | 
					endif()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#FetchContent_Declare(botan GIT_REPOSITORY https://gitea.mattv.de/root/cmake-libraries.git GIT_TAG origin/botan)
 | 
				
			||||||
 | 
					#FetchContent_MakeAvailable(botan)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#add_subdirectory(lib EXCLUDE_FROM_ALL)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
find_package(Threads REQUIRED)
 | 
					find_package(Threads REQUIRED)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -60,8 +113,15 @@ add_executable(fileserver
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
target_include_directories(fileserver PRIVATE include ${CMAKE_CURRENT_BINARY_DIR})
 | 
					target_include_directories(fileserver PRIVATE include ${CMAKE_CURRENT_BINARY_DIR})
 | 
				
			||||||
target_link_libraries(fileserver PRIVATE fileserver_libs Threads::Threads)
 | 
					 | 
				
			||||||
target_compile_options(fileserver PRIVATE -msse2)
 | 
					target_compile_options(fileserver PRIVATE -msse2)
 | 
				
			||||||
target_link_options(fileserver PRIVATE -static)
 | 
					target_link_options(fileserver PRIVATE -static)
 | 
				
			||||||
 | 
					target_link_libraries(fileserver PRIVATE
 | 
				
			||||||
 | 
					    spdlog::spdlog
 | 
				
			||||||
 | 
					    restbed-static
 | 
				
			||||||
 | 
					    #Botan::Botan
 | 
				
			||||||
 | 
					    botan
 | 
				
			||||||
 | 
					    miniz
 | 
				
			||||||
 | 
					    Threads::Threads
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
install(TARGETS fileserver)
 | 
					install(TARGETS fileserver)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,7 +9,7 @@
 | 
				
			|||||||
#ifndef BOTAN_ASIO_ASYNC_OPS_H_
 | 
					#ifndef BOTAN_ASIO_ASYNC_OPS_H_
 | 
				
			||||||
#define BOTAN_ASIO_ASYNC_OPS_H_
 | 
					#define BOTAN_ASIO_ASYNC_OPS_H_
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <botan/types.h>
 | 
					#include <botan_all.h>
 | 
				
			||||||
#include <asio.hpp>
 | 
					#include <asio.hpp>
 | 
				
			||||||
#include <asio/yield.hpp>
 | 
					#include <asio/yield.hpp>
 | 
				
			||||||
#include "asio_error.h"
 | 
					#include "asio_error.h"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,13 +9,7 @@
 | 
				
			|||||||
#ifndef BOTAN_ASIO_TLS_CONTEXT_H_
 | 
					#ifndef BOTAN_ASIO_TLS_CONTEXT_H_
 | 
				
			||||||
#define BOTAN_ASIO_TLS_CONTEXT_H_
 | 
					#define BOTAN_ASIO_TLS_CONTEXT_H_
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <botan/credentials_manager.h>
 | 
					#include <botan_all.h>
 | 
				
			||||||
#include <botan/ocsp.h>
 | 
					 | 
				
			||||||
#include <botan/rng.h>
 | 
					 | 
				
			||||||
#include <botan/tls_callbacks.h>
 | 
					 | 
				
			||||||
#include <botan/tls_policy.h>
 | 
					 | 
				
			||||||
#include <botan/tls_server_info.h>
 | 
					 | 
				
			||||||
#include <botan/tls_session_manager.h>
 | 
					 | 
				
			||||||
#include <functional>
 | 
					#include <functional>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Botan::TLS {
 | 
					namespace Botan::TLS {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,9 +9,7 @@
 | 
				
			|||||||
#ifndef BOTAN_ASIO_ERROR_H_
 | 
					#ifndef BOTAN_ASIO_ERROR_H_
 | 
				
			||||||
#define BOTAN_ASIO_ERROR_H_
 | 
					#define BOTAN_ASIO_ERROR_H_
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <botan/exceptn.h>
 | 
					#include <botan_all.h>
 | 
				
			||||||
#include <botan/tls_alert.h>
 | 
					 | 
				
			||||||
#include <botan/tls_exceptn.h>
 | 
					 | 
				
			||||||
#include <asio/error_code.hpp>
 | 
					#include <asio/error_code.hpp>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace boost{
 | 
					namespace boost{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,11 +9,7 @@
 | 
				
			|||||||
#ifndef BOTAN_ASIO_STREAM_H_
 | 
					#ifndef BOTAN_ASIO_STREAM_H_
 | 
				
			||||||
#define BOTAN_ASIO_STREAM_H_
 | 
					#define BOTAN_ASIO_STREAM_H_
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <botan/tls_callbacks.h>
 | 
					#include <botan_all.h>
 | 
				
			||||||
#include <botan/tls_channel.h>
 | 
					 | 
				
			||||||
#include <botan/tls_client.h>
 | 
					 | 
				
			||||||
#include <botan/tls_magic.h>
 | 
					 | 
				
			||||||
#include <botan/tls_server.h>
 | 
					 | 
				
			||||||
#include <asio.hpp>
 | 
					#include <asio.hpp>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "asio_async_ops.h"
 | 
					#include "asio_async_ops.h"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,19 +0,0 @@
 | 
				
			|||||||
include(FetchContent)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
set(BOTAN_MODULES argon2fmt hotp base32 auto_rng system_rng tls13 certstor_system certstor_flatfile md5)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
FetchContent_Declare(spdlog GIT_REPOSITORY https://gitea.mattv.de/root/cmake-libraries.git GIT_TAG origin/spdlog)
 | 
					 | 
				
			||||||
FetchContent_Declare(restbed GIT_REPOSITORY https://gitea.mattv.de/root/cmake-libraries.git GIT_TAG origin/restbed)
 | 
					 | 
				
			||||||
FetchContent_Declare(botan GIT_REPOSITORY https://gitea.mattv.de/root/cmake-libraries.git GIT_TAG origin/botan)
 | 
					 | 
				
			||||||
FetchContent_MakeAvailable(spdlog restbed botan)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
add_library(miniz STATIC miniz/miniz.c miniz/miniz.h)
 | 
					 | 
				
			||||||
target_include_directories(miniz PUBLIC miniz)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
add_library(${PROJECT_NAME}_libs INTERFACE)
 | 
					 | 
				
			||||||
target_link_libraries(${PROJECT_NAME}_libs INTERFACE
 | 
					 | 
				
			||||||
    spdlog::spdlog
 | 
					 | 
				
			||||||
    restbed::restbed
 | 
					 | 
				
			||||||
    Botan::Botan
 | 
					 | 
				
			||||||
    miniz
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
							
								
								
									
										7833
									
								
								lib/miniz/miniz.c
									
									
									
									
									
								
							
							
						
						
									
										7833
									
								
								lib/miniz/miniz.c
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										1422
									
								
								lib/miniz/miniz.h
									
									
									
									
									
								
							
							
						
						
									
										1422
									
								
								lib/miniz/miniz.h
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										17
									
								
								src/main.cxx
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								src/main.cxx
									
									
									
									
									
								
							@@ -1,7 +1,6 @@
 | 
				
			|||||||
#include <memory>
 | 
					#include <memory>
 | 
				
			||||||
#include <csignal>
 | 
					#include <csignal>
 | 
				
			||||||
#include <botan/hash.h>
 | 
					#include <botan_all.h>
 | 
				
			||||||
#include <botan/hex.h>
 | 
					 | 
				
			||||||
#include <corvusoft/restbed/request.hpp>
 | 
					#include <corvusoft/restbed/request.hpp>
 | 
				
			||||||
#include <corvusoft/restbed/resource.hpp>
 | 
					#include <corvusoft/restbed/resource.hpp>
 | 
				
			||||||
#include <corvusoft/restbed/session.hpp>
 | 
					#include <corvusoft/restbed/session.hpp>
 | 
				
			||||||
@@ -19,10 +18,21 @@ const static restbed::Bytes index_html_bytes{index_html, index_html + index_html
 | 
				
			|||||||
const static restbed::Bytes favicon_bytes{favicon_svg, favicon_svg + favicon_svg_len};
 | 
					const static restbed::Bytes favicon_bytes{favicon_svg, favicon_svg + favicon_svg_len};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void signal_shutdown(const int) {
 | 
					void signal_shutdown(const int) {
 | 
				
			||||||
    spdlog::info("Recieved stop signal");
 | 
					    spdlog::info("Received stop signal");
 | 
				
			||||||
    g_service->stop();
 | 
					    g_service->stop();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void error_handler(const int code, const std::exception& ex, const std::shared_ptr<restbed::Session> session) {
 | 
				
			||||||
 | 
					    std::stringstream ss;
 | 
				
			||||||
 | 
					    ss << "Encountered error with code '" << std::to_string(code) << "'";
 | 
				
			||||||
 | 
					    if (session != nullptr)
 | 
				
			||||||
 | 
					        ss << " in session from '" << session->get_origin() << "'";
 | 
				
			||||||
 | 
					    ss << ": " << ex.what();
 | 
				
			||||||
 | 
					    spdlog::error(ss.str());
 | 
				
			||||||
 | 
					    if (session != nullptr)
 | 
				
			||||||
 | 
					        session->close(code, ex.what());
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main() {
 | 
					int main() {
 | 
				
			||||||
    // TODO add current timestamp to log name
 | 
					    // TODO add current timestamp to log name
 | 
				
			||||||
    auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("log.txt");
 | 
					    auto file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>("log.txt");
 | 
				
			||||||
@@ -94,6 +104,7 @@ int main() {
 | 
				
			|||||||
    settings->set_default_header("Connection", "keep-alive");
 | 
					    settings->set_default_header("Connection", "keep-alive");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    g_service = std::make_shared<restbed::Service>();
 | 
					    g_service = std::make_shared<restbed::Service>();
 | 
				
			||||||
 | 
					    g_service->set_error_handler(error_handler);
 | 
				
			||||||
    g_service->set_logger(std::make_shared<logging::RestbedLogger>());
 | 
					    g_service->set_logger(std::make_shared<logging::RestbedLogger>());
 | 
				
			||||||
    g_service->set_signal_handler(SIGINT, signal_shutdown);
 | 
					    g_service->set_signal_handler(SIGINT, signal_shutdown);
 | 
				
			||||||
    g_service->set_signal_handler(SIGTERM, signal_shutdown);
 | 
					    g_service->set_signal_handler(SIGTERM, signal_shutdown);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,3 @@
 | 
				
			|||||||
#include <botan/argon2fmt.h>
 | 
					 | 
				
			||||||
#include <botan/hex.h>
 | 
					 | 
				
			||||||
#include <botan/mac.h>
 | 
					 | 
				
			||||||
#include <botan/base32.h>
 | 
					 | 
				
			||||||
#include "server_internal.hxx"
 | 
					#include "server_internal.hxx"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
std::string hash_password(const std::string &password) {
 | 
					std::string hash_password(const std::string &password) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,7 +2,6 @@
 | 
				
			|||||||
#include <fstream>
 | 
					#include <fstream>
 | 
				
			||||||
#include <stack>
 | 
					#include <stack>
 | 
				
			||||||
#include <unordered_set>
 | 
					#include <unordered_set>
 | 
				
			||||||
#include <botan/base64.h>
 | 
					 | 
				
			||||||
#include "server_internal.hxx"
 | 
					#include "server_internal.hxx"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mrpc::Node node_to_node(const std::shared_ptr<Node>& node) {
 | 
					mrpc::Node node_to_node(const std::shared_ptr<Node>& node) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,8 +1,5 @@
 | 
				
			|||||||
#include <asio.hpp>
 | 
					#include <asio.hpp>
 | 
				
			||||||
#include <botan_asio/asio_stream.h>
 | 
					#include <botan_asio/asio_stream.h>
 | 
				
			||||||
#include <botan/certstor_system.h>
 | 
					 | 
				
			||||||
#include <botan/tls_session_manager_noop.h>
 | 
					 | 
				
			||||||
#include <botan/base64.h>
 | 
					 | 
				
			||||||
#include <spdlog/spdlog.h>
 | 
					#include <spdlog/spdlog.h>
 | 
				
			||||||
#include "server_internal.hxx"
 | 
					#include "server_internal.hxx"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,3 @@
 | 
				
			|||||||
#include <botan/otp.h>
 | 
					 | 
				
			||||||
#include "server_internal.hxx"
 | 
					#include "server_internal.hxx"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
std::shared_ptr<Token> Server::get_token(const std::string &token) {
 | 
					std::shared_ptr<Token> Server::get_token(const std::string &token) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,7 @@
 | 
				
			|||||||
#ifndef FILESERVER_SERVER_INTERNAL_HXX
 | 
					#ifndef FILESERVER_SERVER_INTERNAL_HXX
 | 
				
			||||||
#define FILESERVER_SERVER_INTERNAL_HXX
 | 
					#define FILESERVER_SERVER_INTERNAL_HXX
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <botan/rng.h>
 | 
					#include <botan_all.h>
 | 
				
			||||||
#include "server.hxx"
 | 
					#include "server.hxx"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// TODO log user action with __FUNC__
 | 
					// TODO log user action with __FUNC__
 | 
				
			||||||
@@ -10,10 +10,8 @@
 | 
				
			|||||||
#define check_user_optional() check_user() return "Unauthorized"
 | 
					#define check_user_optional() check_user() return "Unauthorized"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(BOTAN_HAS_SYSTEM_RNG)
 | 
					#if defined(BOTAN_HAS_SYSTEM_RNG)
 | 
				
			||||||
#include <botan/system_rng.h>
 | 
					 | 
				
			||||||
    static std::unique_ptr<Botan::RNG> auth_rng = std::make_unique<Botan::System_RNG>();
 | 
					    static std::unique_ptr<Botan::RNG> auth_rng = std::make_unique<Botan::System_RNG>();
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
#include <botan/auto_rng.h>
 | 
					 | 
				
			||||||
    static std::unique_ptr<Botan::RNG> auth_rng = std::make_unique<Botan::AutoSeeded_RNG>();
 | 
					    static std::unique_ptr<Botan::RNG> auth_rng = std::make_unique<Botan::AutoSeeded_RNG>();
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user