Skip to content

Commit 2a9c717

Browse files
committed
Botan-3 Migration
Complete Botan-3 migration target: Removal of FindBotan and using supplied config Migrate from marked as deprecated functions -1363 padding needs to be done manually now -No serialization directly on the hasher -no declaration of functions with a serialization. target_link_libraries: srp6 need botan and doesn't have it linked libs/shared need to be linked to botan as well
1 parent 1d53410 commit 2a9c717

File tree

22 files changed

+75
-160
lines changed

22 files changed

+75
-160
lines changed

CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,17 @@ set(version_file "${CMAKE_CURRENT_BINARY_DIR}/Version.cpp")
9999
##############################
100100
# Botan #
101101
##############################
102-
find_package(Botan 2.14.0 REQUIRED)
103-
include_directories(${BOTAN_INCLUDE_DIRS})
102+
find_package(Botan 3.7.0 REQUIRED)
103+
# Check if the static target exists; otherwise fallback to the shared target.
104+
if(TARGET Botan::Botan-static)
105+
set(BOTAN_LIBRARY Botan::Botan-static)
106+
message(STATUS "Using Botan static library")
107+
elseif(TARGET Botan::Botan)
108+
set(BOTAN_LIBRARY Botan::Botan)
109+
message(STATUS "Using Botan shared library")
110+
else()
111+
message(FATAL_ERROR "No valid Botan target found")
112+
endif()
104113

105114
##############################
106115
# MySQL Connector C++ #

Dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ RUN apt-get -y update && apt-get -y upgrade \
2222
&& apt-get -y install cmake \
2323
&& apt-get -y install git \
2424
# Install required library packages
25-
&& apt-get install -y libbotan-2-dev \
25+
&& apt-get install -y libbotan-3-dev \
2626
&& apt-get install -y libmysqlcppconn-dev \
2727
&& apt-get install -y zlib1g-dev \
2828
&& apt-get install -y libpcre3-dev \
@@ -60,8 +60,6 @@ RUN --mount=type=cache,target=build \
6060
-DBUILD_OPT_TOOLS=${build_optional_tools} \
6161
-DPCRE_STATIC_LIB=${pcre_static_lib} \
6262
-DDISABLE_EMBER_THREADS=${disable_threads} \
63-
-DBOTAN_ROOT_DIR=/usr/include/botan-2/ \
64-
-DBOTAN_LIBRARY=/usr/lib/x86_64-linux-gnu/libbotan-2.so \
6563
&& cd build && make -j$(nproc) install \
6664
&& make test
6765

@@ -70,7 +68,7 @@ ARG install_dir=/usr/local/bin
7068
ARG working_dir=/usr/src/ember
7169
WORKDIR ${install_dir}
7270
RUN apt-get -y update \
73-
&& apt-get install -y libbotan-2-19 \
71+
&& apt-get install -y libbotan-3-7 \
7472
&& apt-get install -y libmysqlcppconn7v5 \
7573
&& apt-get install -y mysql-client
7674
COPY --from=builder ${install_dir} ${install_dir}

cmake/FindBotan.cmake

Lines changed: 0 additions & 106 deletions
This file was deleted.

src/account/AccountService.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ AccountService::handle_session_fetch(const SessionLookup& msg, const Link& link,
4545
return response;
4646
}
4747

48-
auto key = Botan::BigInt::encode(*session);
48+
std::vector<uint8_t> key((*session).bytes());
49+
(*session).serialize_to(std::span<uint8_t>(key.data(), key.size()));
4950

5051
response.status = Status::OK;
5152
response.account_id = msg.account_id();

src/gateway/AccountClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void AccountClient::handle_locate_response(std::expected<const SessionResponse*,
8686
return;
8787
}
8888

89-
auto key = Botan::BigInt::decode(msg->key()->data(), msg->key()->size());
89+
auto key = Botan::BigInt::from_bytes(std::span<const std::uint8_t>(msg->key()->data(), msg->key()->size()));
9090
cb(msg->status(), std::move(key));
9191
}
9292

src/gateway/PacketCrypto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class PacketCrypto final {
4444
);
4545

4646
key_.resize(key.bytes(), boost::container::default_init);
47-
key.binary_encode(key_.data(), key_.size());
47+
key.serialize_to(std::span<uint8_t>( key_.data() + (key_.size() - key.bytes()), key.bytes() ));
4848
}
4949

5050
inline void encrypt(auto& data) {

src/gateway/states/Authentication.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void prove_session(ClientContext& ctx, const Botan::BigInt& key) {
164164
key.bytes(), boost::container::default_init
165165
);
166166

167-
key.binary_encode(k_bytes.data(), k_bytes.size());
167+
key.serialize_to(std::span<uint8_t>(k_bytes.data() + (k_bytes.size() - key.bytes()), key.bytes()));
168168

169169
const std::uint32_t protocol_id = 0; // best guess, this is hardcoded to zero in the client
170170
auto& auth_ctx = std::get<Context>(ctx.state_ctx);

src/libs/shared/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,5 @@ source_group("Metrics" FILES ${METRICS_SRC})
137137
include_directories(${CMAKE_SOURCE_DIR}/deps/utf8cpp ${PROJECT_BINARY_DIR}/src)
138138
add_library(${LIBRARY_NAME} ${LIBRARY_SRC})
139139
target_include_directories(${LIBRARY_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/)
140-
target_link_libraries(${LIBRARY_NAME} logger conpool ${PCRE_LIBRARY})
140+
target_link_libraries(${LIBRARY_NAME} logger conpool ${BOTAN_LIBRARY} ${PCRE_LIBRARY})
141141
set_target_properties(${LIBRARY_NAME} PROPERTIES FOLDER "Common Libraries")

src/libs/shared/shared/database/daos/mysql/PatchDAO.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ class MySQLPatchDAO final : public PatchDAO {
6464

6565
const auto md5 = res->getString("md5");
6666
Botan::BigInt md5_int(md5.asStdString());
67-
Botan::BigInt::encode_1363(meta.file_meta.md5.data(), meta.file_meta.md5.size(), md5_int);
67+
std::fill(meta.file_meta.md5.begin(), meta.file_meta.md5.end(), 0); // 1363 style padding
68+
md5_int.serialize_to({ meta.file_meta.md5.data() + meta.file_meta.md5.size() - md5_int.bytes(), md5_int.bytes() });
6869
patches.emplace_back(std::move(meta));
6970
}
7071

@@ -87,8 +88,8 @@ class MySQLPatchDAO final : public PatchDAO {
8788
stmt->setBoolean(3, meta.mpq);
8889
stmt->setString(4, meta.file_meta.name);
8990
stmt->setUInt64(5, meta.file_meta.size);
90-
auto md5 = Botan::BigInt::decode(reinterpret_cast<const std::uint8_t*>(meta.file_meta.md5.data()),
91-
meta.file_meta.md5.size());
91+
auto md5 = Botan::BigInt::from_bytes(std::span<const uint8_t>(reinterpret_cast<const std::uint8_t*>(
92+
meta.file_meta.md5.data()), meta.file_meta.md5.size()));
9293

9394
stmt->setString(6, md5.to_hex_string());
9495
stmt->setUInt(7, meta.locale_id);

src/libs/srp6/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ add_library(${LIBRARY_NAME}
1919
include/srp6/detail/Primes.h
2020
)
2121

22+
target_link_libraries(${LIBRARY_NAME} PRIVATE ${BOTAN_LIBRARY})
2223
target_include_directories(${LIBRARY_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
2324
set_target_properties(${LIBRARY_NAME} PROPERTIES FOLDER "Common Libraries")

0 commit comments

Comments
 (0)