Skip to content

Commit

Permalink
Adds the necessary to compile with LibreSSL and on OpenBSD.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-vincent committed Aug 13, 2017
1 parent 3d5ae9d commit e37227d
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 23 deletions.
6 changes: 6 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ class FreelanEnvironment(Environment):
self.Append(LDFLAGS=['-L/usr/local/lib'])
self.Append(LIBPATH=['/usr/local/lib'])

if sys.platform.startswith('openbsd'):
self.Append(CXXFLAGS=['-I/usr/local/include', '-pthread', '-Wno-shadow', '-Wno-nested-anon-types', '-Wno-unused-parameter', '-Wno-unused-local-typedef'])
self.Append(CFLAGS=['-I/usr/local/include', 'pthread', '-Wno-shadow', '-Wno-nested-anon-types', '-Wno-unused-parameter', '-Wno-unused-local-typedef'])
self.Append(LDFLAGS=['-L/usr/local/lib'])
self.Append(LIBPATH=['/usr/local/lib'])

if sys.platform.startswith('netbsd'):
self.Append(CXXFLAGS=['-I/usr/pkg/include', '-Wno-shadow'])
self.Append(CFLAGS=['-I/usr/pkg/include', '-Wno-shadow'])
Expand Down
6 changes: 5 additions & 1 deletion apps/freelan/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ libraries = [
'crypto',
]

if sys.platform.startswith('darwin'):
if sys.platform.startswith('darwin') or sys.platform.startswith('openbsd'):
libraries.extend([
'boost_thread-mt',
])
Expand All @@ -47,6 +47,10 @@ else:
'pthread',
'c++',
])
if sys.platform.startswith('openbsd'):
libraries.extend([
'iconv',
])

if env.mongoose == 'yes':
libraries.extend([
Expand Down
1 change: 1 addition & 0 deletions apps/freelan/src/posix/pid_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <boost/system/system_error.hpp>
#include <boost/lexical_cast.hpp>

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
Expand Down
8 changes: 4 additions & 4 deletions libs/cryptoplus/include/cryptoplus/asn1/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,10 @@ namespace cryptoplus
}
inline const unsigned char* string::data()
{
#if OPENSSL_VERSION_NUMBER < 0x10100000L
return ASN1_STRING_data(ptr().get());
#else
#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
return ASN1_STRING_get0_data(ptr().get());
#else
return ASN1_STRING_data(ptr().get());
#endif
}
inline void string::set_data(const void* _data, size_t data_len) const
Expand Down Expand Up @@ -299,7 +299,7 @@ namespace cryptoplus
}
inline int compare(const string& lhs, const string& rhs)
{
#if OPENSSL_VERSION_NUMBER >= 0x01000000
#if OPENSSL_VERSION_NUMBER >= 0x01000000 && !defined(LIBRESSL_VERSION_NUMBER)
return ASN1_STRING_cmp(lhs.raw(), rhs.raw());
#else
return ASN1_STRING_cmp(const_cast<string::pointer>(lhs.raw()), const_cast<string::pointer>(rhs.raw()));
Expand Down
6 changes: 3 additions & 3 deletions libs/cryptoplus/include/cryptoplus/bio/bio_chain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ namespace cryptoplus
boost::shared_ptr<BIO> m_bio;
};

#if OPENSSL_VERSION_NUMBER < 0x10100000L
inline bio_chain::bio_chain(BIO_METHOD* _type) : m_bio(BIO_new(_type), BIO_free_all)
#else
#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
inline bio_chain::bio_chain(const BIO_METHOD* _type) : m_bio(BIO_new(_type), BIO_free_all)
#else
inline bio_chain::bio_chain(BIO_METHOD* _type) : m_bio(BIO_new(_type), BIO_free_all)
#endif
{
throw_error_if_not(m_bio != NULL);
Expand Down
2 changes: 1 addition & 1 deletion libs/cryptoplus/include/cryptoplus/bio/bio_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ namespace cryptoplus
{
return m_bio;
}
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
inline bool bio_ptr::set_method(BIO_METHOD* _type) const
{
return BIO_set(m_bio, _type) != 0;
Expand Down
4 changes: 2 additions & 2 deletions libs/cryptoplus/include/cryptoplus/cryptoplus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace cryptoplus
*
* Only one instance of this class should be created. When an instance exists, the library can proceed to name resolutions.
*/
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
typedef initializer<_OpenSSL_add_all_algorithms, _null_function> algorithms_initializer;
#else
typedef initializer<_OpenSSL_add_all_algorithms, EVP_cleanup> algorithms_initializer;
Expand All @@ -85,7 +85,7 @@ namespace cryptoplus
*
* Only one instance of this class should be created. When an instance exists, it will prevent memory leaks related to the libcrypto's internals.
*/
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
typedef initializer<_null_function, _null_function> crypto_initializer;
#else
typedef initializer<_null_function, CRYPTO_cleanup_all_ex_data> crypto_initializer;
Expand Down
2 changes: 1 addition & 1 deletion libs/cryptoplus/include/cryptoplus/error/error_strings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace cryptoplus
* Only one instance of this class should be created. When an instance exists, the library can provide more informative error strings.
*/

#if OPENSSL_VERSION_NUMBER >= 0x10100000L
#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
inline void _null_function()
{
}
Expand Down
6 changes: 3 additions & 3 deletions libs/cryptoplus/include/cryptoplus/hash/hmac_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ namespace cryptoplus

inline hmac_context::hmac_context()
{
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
m_ctx = new HMAC_CTX;
HMAC_CTX_init(m_ctx);
#else
Expand All @@ -154,7 +154,7 @@ namespace cryptoplus

inline hmac_context::~hmac_context()
{
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
HMAC_CTX_cleanup(m_ctx);
delete m_ctx;
#else
Expand Down Expand Up @@ -192,7 +192,7 @@ namespace cryptoplus

inline message_digest_algorithm hmac_context::algorithm() const
{
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
//WARNING: Here we directly use the undocumented HMAC_CTX.md field.
return message_digest_algorithm(m_ctx->md);
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace cryptoplus
*/
message_digest_context()
{
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
m_ctx = new EVP_MD_CTX;
EVP_MD_CTX_init(m_ctx);
#else
Expand All @@ -97,7 +97,7 @@ namespace cryptoplus
*/
~message_digest_context()
{
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
EVP_MD_CTX_cleanup(m_ctx);
delete m_ctx;
#else
Expand Down
2 changes: 1 addition & 1 deletion libs/cryptoplus/include/cryptoplus/pkey/dh_key.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ namespace cryptoplus
{
throw_error_if_not(PEM_write_DHparams(_file.raw(), ptr().get()) != 0);
}
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
inline bn::bignum dh_key::private_key() const
{
const BIGNUM* priv_key = NULL;
Expand Down
2 changes: 1 addition & 1 deletion libs/cryptoplus/include/cryptoplus/pkey/pkey.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ namespace cryptoplus
{
return EVP_PKEY_size(ptr().get());
}
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
inline int pkey::type() const
{
return EVP_PKEY_base_id(ptr().get());
Expand Down
4 changes: 2 additions & 2 deletions libs/cryptoplus/include/cryptoplus/random/random.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ namespace cryptoplus

inline bool get_pseudo_random_bytes(void* buf, size_t buf_len)
{
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
int result = RAND_pseudo_bytes(static_cast<unsigned char*>(buf), static_cast<int>(buf_len));

throw_error_if(result < 0);
Expand All @@ -242,7 +242,7 @@ namespace cryptoplus

inline buffer get_pseudo_random_bytes(size_t cnt)
{
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
buffer result(cnt);

get_pseudo_random_bytes(buffer_cast<uint8_t*>(result), buffer_size(result));
Expand Down
2 changes: 1 addition & 1 deletion libs/cryptoplus/src/dh_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace cryptoplus

dh_key dh_key::generate_parameters(int prime_len, int generator, generate_callback_type callback, void* callback_arg)
{
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
static_cast<void>(callback);
static_cast<void>(callback_arg);

Expand Down
2 changes: 1 addition & 1 deletion libs/cryptoplus/src/dsa_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace cryptoplus

dsa_key dsa_key::generate_parameters(int bits, void* seed, size_t seed_len, int* counter_ret, unsigned long *h_ret, generate_callback_type callback, void* callback_arg, bool must_take_ownership)
{
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
static_cast<void>(callback);
static_cast<void>(callback_arg);
static_cast<void>(must_take_ownership);
Expand Down

0 comments on commit e37227d

Please sign in to comment.