Skip to content

Commit

Permalink
TLS example fixes for MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
FAlbertDev committed Oct 14, 2024
1 parent 05f4053 commit e2f7a58
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/examples/hybrid_key_encapsulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class Hybrid_PublicKey : public virtual Botan::Public_Key {
std::unique_ptr<Botan::Public_Key> m_kem_pk;
};

BOTAN_DIAGNOSTIC_PUSH
BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE

/**
* This is the private key class for the custom public-key algorithm.
*/
Expand Down Expand Up @@ -147,6 +150,8 @@ class Hybrid_PrivateKey : public virtual Botan::Private_Key,
std::unique_ptr<Botan::Private_Key> m_kem_sk;
};

BOTAN_DIAGNOSTIC_POP

namespace {

/**
Expand Down
8 changes: 8 additions & 0 deletions src/examples/tls_ssl_key_log_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include <sys/ioctl.h>
#include <sys/socket.h>
#endif
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
#include <unistd.h>
#endif

namespace {

Expand Down Expand Up @@ -142,6 +145,8 @@ class DtlsConnection : public Botan::TLS::Callbacks {
remote_addr.sin_family = AF_INET;
inet_aton(r_addr.c_str(), &remote_addr.sin_addr);
remote_addr.sin_port = htons(r_port);
#else
BOTAN_UNUSED(r_addr, r_port);
#endif
auto tls_callbacks_proxy = std::make_shared<BotanTLSCallbacksProxy>(*this);
auto rng = std::make_shared<Botan::AutoSeeded_RNG>();
Expand Down Expand Up @@ -169,6 +174,7 @@ class DtlsConnection : public Botan::TLS::Callbacks {
#if defined(BOTAN_TARGET_OS_HAS_SOCKETS)
sendto(fd, data.data(), data.size(), 0, reinterpret_cast<const sockaddr*>(&remote_addr), sizeof(sockaddr_in));
#else
BOTAN_UNUSED(data);
// send data to the other side
// ...
#endif
Expand Down Expand Up @@ -201,7 +207,9 @@ class DtlsConnection : public Botan::TLS::Callbacks {
if(fd) {
#if defined(BOTAN_TARGET_OS_HAS_SOCKETS)
shutdown(fd, SHUT_RDWR);
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
::close(fd);
#endif
#endif
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/examples/tls_stream_coroutine_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
// in clang 14 and newer. Older versions of Boost might work with other
// compilers, though.
#if defined(BOTAN_FOUND_COMPATIBLE_BOOST_ASIO_VERSION) && BOOST_VERSION >= 108100
#define BOOST_VERSION_IS_COMPATIBLE
#endif

#if defined(BOOST_VERSION_IS_COMPATIBLE) && defined(BOTAN_HAS_HAS_DEFAULT_TLS_CONTEXT)

#include <botan/asio_stream.h>
#include <botan/version.h>
Expand Down Expand Up @@ -106,8 +110,13 @@ int main(int argc, char* argv[]) {
#else

int main() {
#if !defined(BOOST_VERSION_IS_COMPATIBLE)
std::cout << "Your boost version is too old, sorry.\n"
<< "Or did you compile Botan without --with-boost?\n";
#endif
#if !defined(BOTAN_HAS_HAS_DEFAULT_TLS_CONTEXT)
std::cout << "Your system needs an auto seeded RNG and a certificate store.\n";
#endif
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/tls/asio/asio_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class Stream {
std::shared_ptr<StreamCallbacks> callbacks = std::make_shared<StreamCallbacks>()) :
Stream(std::move(context), std::move(callbacks), std::forward<Arg>(arg)) {}

#if defined(BOTAN_HAS_AUTO_SEEDING_RNG)
#if defined(BOTAN_HAS_HAS_DEFAULT_TLS_CONTEXT)
/**
* @brief Conveniently construct a new Stream with default settings
*
Expand Down

0 comments on commit e2f7a58

Please sign in to comment.