Commit 619bb910 authored by Ghislain MARY's avatar Ghislain MARY
Browse files

Fix build for Android.

parent 3a232efe
......@@ -25,6 +25,7 @@
#
SET(_SOCI_ALL_PLUGINS mysql sqlite3)
SET(_SOCI_REQUIRED_VARS SOCI_INCLUDE_DIRS SOCI_LIBRARIES)
SET(_SOCI_VERSION "_4_0")
#
### FIRST STEP: Find the soci headers.
......@@ -37,7 +38,7 @@ MARK_AS_ADVANCED(SOCI_INCLUDE_DIRS)
### SECOND STEP: Find the soci core library. Respect LIB_SUFFIX
#
FIND_LIBRARY(SOCI_LIBRARIES
NAMES soci_core
NAMES soci_core soci_core${_SOCI_VERSION}
PATH_SUFFIXES lib lib64)
MARK_AS_ADVANCED(SOCI_LIBRARIES)
......@@ -54,13 +55,17 @@ IF(SOCI_INCLUDE_DIRS AND SOCI_LIBRARIES)
FIND_LIBRARY(
SOCI_${plugin}_PLUGIN
NAMES soci_${plugin}
NAMES soci_${plugin} soci_${plugin}${_SOCI_VERSION}
PATH_SUFFIXES lib lib64)
MARK_AS_ADVANCED(SOCI_${plugin}_PLUGIN)
IF(SOCI_${plugin}_PLUGIN)
MESSAGE(STATUS " * Plugin ${plugin} found ${SOCI_${plugin}_PLUGIN}.")
SET(SOCI_${plugin}_FOUND True)
if(IOS OR ANDROID)
list(APPEND SOCI_LIBRARIES ${SOCI_${plugin}_PLUGIN})
endif()
ELSE()
MESSAGE(STATUS " * Plugin ${plugin} not found.")
SET(SOCI_${plugin}_FOUND False)
......@@ -84,4 +89,3 @@ ENDIF()
#
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Soci DEFAULT_MSG ${_SOCI_REQUIRED_VARS})
......@@ -23,6 +23,7 @@
#include <unordered_map>
#include <vector>
#include <functional>
#include <string>
namespace lime {
......
......@@ -471,7 +471,6 @@ void HMAC_KDF(const std::vector<uint8_t> &salt, const std::vector<uint8_t> &ikm,
};
/* instanciate HMAC_KDF template with SHA512 and string or vector info */
template void HMAC<SHA512>(const uint8_t *const key, const size_t keySize, const uint8_t *const input, const size_t inputSize, uint8_t *hash, size_t hashSize);
template void HMAC_KDF<SHA512, std::vector<uint8_t>>(const uint8_t *const salt, const size_t saltSize, const uint8_t *const ikm, const size_t ikmSize, const std::vector<uint8_t> &info, uint8_t *output, size_t outputSize);
template void HMAC_KDF<SHA512, std::string>(const uint8_t *const salt, const size_t saltSize, const uint8_t *const ikm, const size_t ikmSize, const std::string &info, uint8_t *output, size_t outputSize);
template void HMAC_KDF<SHA512, std::vector<uint8_t>>(const std::vector<uint8_t> &salt, const std::vector<uint8_t> &ikm, const std::vector<uint8_t> &info, uint8_t *output, size_t outputSize);
......
......@@ -44,15 +44,38 @@ set(SOURCE_FILES_CXX
bc_apply_compile_flags(SOURCE_FILES_CXX STRICT_OPTIONS_CPP STRICT_OPTIONS_CXX)
include_directories(${BELLESIP_INCLUDE_DIRS})
add_executable(lime_tester ${SOURCE_FILES_CXX} ${HEADER_FILES_CXX})
set_target_properties(lime_tester PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(lime_tester PUBLIC ${BCTOOLBOX_TESTER_INCLUDE_DIRS})
target_link_libraries(lime_tester ${LIME_LIBRARIES_FOR_TESTER} ${BCTOOLBOX_LIBRARIES} ${BCTOOLBOX_TESTER_LIBRARIES} ${BELLESIP_LIBRARIES} ${SOCI_LIBRARIES} ${SOCI_sqlite3_PLUGIN})
if(ANDROID OR IOS)
add_library(limetester SHARED ${HEADER_FILES_CXX} ${SOURCE_FILES_CXX})
target_include_directories(limetester PUBLIC ${BCTOOLBOX_TESTER_INCLUDE_DIRS} ${BELLESIP_INCLUDE_DIRS})
target_link_libraries(limetester ${LIME_LIBRARIES_FOR_TESTER} ${BCTOOLBOX_LIBRARIES} ${BCTOOLBOX_TESTER_LIBRARIES} ${BELLESIP_LIBRARIES} ${SOCI_LIBRARIES} ${SOCI_sqlite3_PLUGIN})
if(IOS)
set_target_properties(limetester PROPERTIES
FRAMEWORK TRUE
MACOSX_FRAMEWORK_IDENTIFIER com.belledonne-communications.limetester
PUBLIC_HEADER "${HEADER_FILES_CXX}"
)
endif()
install(TARGETS limetester
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
FRAMEWORK DESTINATION Frameworks
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
install(FILES ${HEADER_FILES_CXX}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lime
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
else()
add_executable(lime_tester ${SOURCE_FILES_CXX} ${HEADER_FILES_CXX})
set_target_properties(lime_tester PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(lime_tester PUBLIC ${BCTOOLBOX_TESTER_INCLUDE_DIRS} ${BELLESIP_INCLUDE_DIRS})
target_link_libraries(lime_tester ${LIME_LIBRARIES_FOR_TESTER} ${BCTOOLBOX_LIBRARIES} ${BCTOOLBOX_TESTER_LIBRARIES} ${BELLESIP_LIBRARIES} ${SOCI_LIBRARIES} ${SOCI_sqlite3_PLUGIN})
if(APPLE)
set_target_properties(lime_tester PROPERTIES LINK_FLAGS "-stdlib=libc++")
endif()
if(APPLE)
set_target_properties(lime_tester PROPERTIES LINK_FLAGS "-stdlib=libc++")
# lime test suit request a local server to be launched, so keep testing double ratchet only for now
add_test(NAME double_ratchet COMMAND lime_tester --verbose --resource-dir ${CMAKE_CURRENT_SOURCE_DIR} --suite "double ratchet")
endif()
# lime test suit request a local server to be launched, so keep testing double ratchet only for now
add_test(NAME double_ratchet COMMAND lime_tester --verbose --resource-dir ${CMAKE_CURRENT_SOURCE_DIR} --suite "double ratchet")
......@@ -345,7 +345,7 @@ static void dr_simple_exchange(std::shared_ptr<DR<Curve>> &DRsessionAlice, std::
bool is_directEncryptionType = lime_tester::DR_message_payloadDirectEncrypt(recipients[0].DRmessage);
if (getEncryptionPolicyAlice == lime::EncryptionPolicy::DRMessage) {
BC_ASSERT_TRUE(is_directEncryptionType);
BC_ASSERT_EQUAL(aliceCipher.size(), 0, size_t, "%ld"); // in direct Encryption mode, cipherMessage is empty
BC_ASSERT_EQUAL((int)aliceCipher.size(), 0, int, "%d"); // in direct Encryption mode, cipherMessage is empty
} else {
BC_ASSERT_FALSE(is_directEncryptionType);
}
......@@ -371,10 +371,10 @@ static void dr_simple_exchange(std::shared_ptr<DR<Curve>> &DRsessionAlice, std::
bool is_directEncryptionType = lime_tester::DR_message_payloadDirectEncrypt(recipients[0].DRmessage);
if (getEncryptionPolicyBob == lime::EncryptionPolicy::DRMessage) {
BC_ASSERT_TRUE(is_directEncryptionType);
BC_ASSERT_EQUAL(bobCipher.size(), 0, size_t, "%ld"); // in direct Encryption mode, cipherMessage is empty
BC_ASSERT_EQUAL((int)bobCipher.size(), 0, int, "%d"); // in direct Encryption mode, cipherMessage is empty
} else {
BC_ASSERT_FALSE(is_directEncryptionType);
BC_ASSERT_NOT_EQUAL(bobCipher.size(), 0, size_t, "%ld"); // in cipher message Encryption mode, cipherMessage is not empty
BC_ASSERT_NOT_EQUAL((int)bobCipher.size(), 0, int, "%d"); // in cipher message Encryption mode, cipherMessage is not empty
}
}
......@@ -477,7 +477,7 @@ static void dr_multidevice_exchange(std::string db_filename,
bool is_directEncryptionType = lime_tester::DR_message_payloadDirectEncrypt(recipients[0].DRmessage); // check on recipients[0], they shall all be the same
if (getEncryptionPolicy == lime::EncryptionPolicy::DRMessage) {
BC_ASSERT_TRUE(is_directEncryptionType);
BC_ASSERT_EQUAL(cipherMessage.size(), 0, size_t, "%ld"); // in direct Encryption mode, cipherMessage is empty
BC_ASSERT_EQUAL((int)cipherMessage.size(), 0, int, "%d"); // in direct Encryption mode, cipherMessage is empty
} else {
BC_ASSERT_FALSE(is_directEncryptionType);
}
......
......@@ -326,12 +326,12 @@ static void lime_encryptionPolicyError_test(const lime::CurveId curve, const std
bool is_directEncryptionType = lime_tester::DR_message_payloadDirectEncrypt((*bobRecipients)[0].DRmessage);
if (setEncryptionPolicy == lime::EncryptionPolicy::DRMessage) {
BC_ASSERT_TRUE(is_directEncryptionType);
BC_ASSERT_EQUAL(bobCipherMessage->size(), 0, size_t, "%ld"); // in direct Encryption mode, cipherMessage is empty
BC_ASSERT_EQUAL((int)bobCipherMessage->size(), 0, int, "%d"); // in direct Encryption mode, cipherMessage is empty
bobCipherMessage->resize(32, 0xaa); // just create a 0xaa filled buffer, its presence shall prevent the perferctly correct DR message to be decrypted
} else {
BC_ASSERT_FALSE(is_directEncryptionType);
BC_ASSERT_NOT_EQUAL(bobCipherMessage->size(), 0, size_t, "%ld"); // in direct cipher message mode, cipherMessage is not empty
BC_ASSERT_NOT_EQUAL((int)bobCipherMessage->size(), 0, int, "%d"); // in direct cipher message mode, cipherMessage is not empty
bobCipherMessage->clear(); // delete the cipher message, the DR decryption will fail and will not return the random seed as plaintext
}
......@@ -467,10 +467,10 @@ static void lime_encryptionPolicy_test(std::shared_ptr<LimeManager> aliceManager
}
if (getEncryptionPolicy == lime::EncryptionPolicy::DRMessage) {
BC_ASSERT_TRUE(is_directEncryptionType);
BC_ASSERT_EQUAL(bobCipherMessage->size(), 0, size_t, "%ld"); // in direct Encryption mode, cipherMessage is empty
BC_ASSERT_EQUAL((int)bobCipherMessage->size(), 0, int, "%d"); // in direct Encryption mode, cipherMessage is empty
} else {
BC_ASSERT_FALSE(is_directEncryptionType);
BC_ASSERT_NOT_EQUAL(bobCipherMessage->size(), 0, size_t, "%ld"); // in direct cipher message mode, cipherMessage is not empty
BC_ASSERT_NOT_EQUAL((int)bobCipherMessage->size(), 0, int, "%d"); // in direct cipher message mode, cipherMessage is not empty
}
// alice1 decrypt
......@@ -1111,13 +1111,13 @@ static void lime_update_OPk_test(const lime::CurveId curve, const std::string &d
BC_ASSERT_TRUE(lime_tester::wait_for(stack,&counters.operation_success, ++expected_success,lime_tester::wait_for_timeout));
// check we have the expected count of OPk in base : the initial batch
BC_ASSERT_EQUAL(lime_tester::get_OPks(dbFilenameAlice, *aliceDeviceId), lime_tester::OPkInitialBatchSize, size_t, "%ld");
BC_ASSERT_EQUAL((int)lime_tester::get_OPks(dbFilenameAlice, *aliceDeviceId), lime_tester::OPkInitialBatchSize, int, "%d");
// call the update, set the serverLimit to initialBatch size and upload an other initial batch if needed
// As all the keys are still on server, it shall have no effect, check it then
aliceManager->update(callback, lime_tester::OPkInitialBatchSize, lime_tester::OPkInitialBatchSize);
BC_ASSERT_TRUE(lime_tester::wait_for(stack,&counters.operation_success, ++expected_success,lime_tester::wait_for_timeout));
BC_ASSERT_EQUAL(lime_tester::get_OPks(dbFilenameAlice, *aliceDeviceId), lime_tester::OPkInitialBatchSize, size_t, "%ld");
BC_ASSERT_EQUAL((int)lime_tester::get_OPks(dbFilenameAlice, *aliceDeviceId), lime_tester::OPkInitialBatchSize, int, "%d");
// We will create a bob device and encrypt for each new epoch
std::vector<std::unique_ptr<LimeManager>> bobManagers{};
......@@ -1146,14 +1146,14 @@ static void lime_update_OPk_test(const lime::CurveId curve, const std::string &d
}
// check we have the expected count of OPk in base : we shall still have the initial batch
BC_ASSERT_EQUAL(lime_tester::get_OPks(dbFilenameAlice, *aliceDeviceId), lime_tester::OPkInitialBatchSize, size_t, "%ld");
BC_ASSERT_EQUAL((int)lime_tester::get_OPks(dbFilenameAlice, *aliceDeviceId), lime_tester::OPkInitialBatchSize, int, "%d");
// call the update, set the serverLimit to initialBatch size and upload an other initial batch if needed
// As some keys were removed from server this time we shall generate and upload a new batch
aliceManager->update(callback, lime_tester::OPkInitialBatchSize, lime_tester::OPkInitialBatchSize);
BC_ASSERT_TRUE(lime_tester::wait_for(stack,&counters.operation_success, ++expected_success,lime_tester::wait_for_timeout));
// we uploaded a new batch but no key were removed from localStorage so we now have 2*batch size keys
BC_ASSERT_EQUAL(lime_tester::get_OPks(dbFilenameAlice, *aliceDeviceId), 2*lime_tester::OPkInitialBatchSize, size_t, "%ld");
BC_ASSERT_EQUAL((int)lime_tester::get_OPks(dbFilenameAlice, *aliceDeviceId), 2*lime_tester::OPkInitialBatchSize, int, "%d");
// forward time by OPK_limboTime_days
aliceManager=nullptr; // destroy manager before modifying DB
......@@ -1161,7 +1161,7 @@ static void lime_update_OPk_test(const lime::CurveId curve, const std::string &d
aliceManager = std::unique_ptr<LimeManager>(new LimeManager(dbFilenameAlice, X3DHServerPost));
// check nothing has changed on our local OPk count
BC_ASSERT_EQUAL(lime_tester::get_OPks(dbFilenameAlice, *aliceDeviceId), 2*lime_tester::OPkInitialBatchSize, size_t, "%ld");
BC_ASSERT_EQUAL((int)lime_tester::get_OPks(dbFilenameAlice, *aliceDeviceId), 2*lime_tester::OPkInitialBatchSize, int, "%d");
// decrypt Bob first message(he is then an unknown device)
std::vector<uint8_t> receivedMessage{};
......@@ -1170,14 +1170,14 @@ static void lime_update_OPk_test(const lime::CurveId curve, const std::string &d
BC_ASSERT_TRUE(receivedMessageString == lime_tester::messages_pattern[0]);
// check we have one less key
BC_ASSERT_EQUAL(lime_tester::get_OPks(dbFilenameAlice, *aliceDeviceId), 2*lime_tester::OPkInitialBatchSize - 1, size_t, "%ld");
BC_ASSERT_EQUAL((int)lime_tester::get_OPks(dbFilenameAlice, *aliceDeviceId), 2*lime_tester::OPkInitialBatchSize - 1, int, "%d");
// call the update, set the serverLimit to 0, we don't want to upload more keys, but too old unused local OPk dispatched by server long ago shall be deleted
aliceManager->update(callback, 0, 0);
BC_ASSERT_TRUE(lime_tester::wait_for(stack,&counters.operation_success, ++expected_success,lime_tester::wait_for_timeout));
// check the local OPk missing on server for a long time has been deleted
BC_ASSERT_EQUAL(lime_tester::get_OPks(dbFilenameAlice, *aliceDeviceId), 2*lime_tester::OPkInitialBatchSize - 2, size_t, "%ld");
BC_ASSERT_EQUAL((int)lime_tester::get_OPks(dbFilenameAlice, *aliceDeviceId), 2*lime_tester::OPkInitialBatchSize - 2, int, "%d");
// try to decrypt Bob's second message, it shall fail as we got rid of the OPk
receivedMessage.clear();
......@@ -1799,12 +1799,12 @@ static void x3dh_multiple_DRsessions_test(const lime::CurveId curve, const std::
std::vector<long int> aliceSessionsId{};
auto aliceActiveSessionId = lime_tester::get_DRsessionsId(dbFilenameAlice, *aliceDevice1, *bobDevice1, aliceSessionsId);
BC_ASSERT_EQUAL(aliceActiveSessionId, 1, long int, "%ld");
BC_ASSERT_EQUAL(aliceSessionsId.size(), 1, size_t, "%ld");
BC_ASSERT_EQUAL((int)aliceSessionsId.size(), 1, int, "%d");
std::vector<long int> bobSessionsId{};
auto bobActiveSessionId = lime_tester::get_DRsessionsId(dbFilenameBob, *bobDevice1, *aliceDevice1, bobSessionsId);
BC_ASSERT_EQUAL(bobActiveSessionId, 1, long int, "%ld");
BC_ASSERT_EQUAL(bobSessionsId.size(), 1, size_t, "%ld");
BC_ASSERT_EQUAL((int)bobSessionsId.size(), 1, int, "%d");
// destroy and reload the Managers(tests everything is correctly saved/load from local Storage)
if (!continuousSession) { managersClean (aliceManager, bobManager, dbFilenameAlice, dbFilenameBob);}
......@@ -1825,12 +1825,12 @@ static void x3dh_multiple_DRsessions_test(const lime::CurveId curve, const std::
aliceSessionsId.clear();
aliceActiveSessionId = lime_tester::get_DRsessionsId(dbFilenameAlice, *aliceDevice1, *bobDevice1, aliceSessionsId);
BC_ASSERT_EQUAL(aliceActiveSessionId, 2, long int, "%ld");
BC_ASSERT_EQUAL(aliceSessionsId.size(), 2, size_t, "%ld");
BC_ASSERT_EQUAL((int)aliceSessionsId.size(), 2, int, "%d");
bobSessionsId.clear();
bobActiveSessionId = lime_tester::get_DRsessionsId(dbFilenameBob, *bobDevice1, *aliceDevice1, bobSessionsId);
BC_ASSERT_EQUAL(bobActiveSessionId, 2, long int, "%ld");
BC_ASSERT_EQUAL(bobSessionsId.size(), 2, size_t, "%ld");
BC_ASSERT_EQUAL((int)bobSessionsId.size(), 2, int, "%d");
// destroy and reload the Managers(tests everything is correctly saved/load from local Storage)
if (!continuousSession) { managersClean (aliceManager, bobManager, dbFilenameAlice, dbFilenameBob);}
......@@ -1850,12 +1850,12 @@ static void x3dh_multiple_DRsessions_test(const lime::CurveId curve, const std::
aliceSessionsId.clear();
aliceActiveSessionId = lime_tester::get_DRsessionsId(dbFilenameAlice, *aliceDevice1, *bobDevice1, aliceSessionsId);
BC_ASSERT_EQUAL(aliceActiveSessionId, 2, long int, "%ld");
BC_ASSERT_EQUAL(aliceSessionsId.size(), 2, size_t, "%ld");
BC_ASSERT_EQUAL((int)aliceSessionsId.size(), 2, int, "%d");
bobSessionsId.clear();
bobActiveSessionId = lime_tester::get_DRsessionsId(dbFilenameBob, *bobDevice1, *aliceDevice1, bobSessionsId);
BC_ASSERT_EQUAL(bobActiveSessionId, 2, long int, "%ld");
BC_ASSERT_EQUAL(bobSessionsId.size(), 2, size_t, "%ld");
BC_ASSERT_EQUAL((int)bobSessionsId.size(), 2, int, "%d");
// alice decrypt the messages it shall set back session 1 to be the active one as bob used this one to encrypt to alice, they have now converged on a session
receivedMessage.clear();
......@@ -1868,12 +1868,12 @@ static void x3dh_multiple_DRsessions_test(const lime::CurveId curve, const std::
aliceSessionsId.clear();
aliceActiveSessionId = lime_tester::get_DRsessionsId(dbFilenameAlice, *aliceDevice1, *bobDevice1, aliceSessionsId);
BC_ASSERT_EQUAL(aliceActiveSessionId, 1, long int, "%ld");
BC_ASSERT_EQUAL(aliceSessionsId.size(), 2, size_t, "%ld");
BC_ASSERT_EQUAL((int)aliceSessionsId.size(), 2, int, "%d");
bobSessionsId.clear();
bobActiveSessionId = lime_tester::get_DRsessionsId(dbFilenameBob, *bobDevice1, *aliceDevice1, bobSessionsId);
BC_ASSERT_EQUAL(bobActiveSessionId, 2, long int, "%ld");
BC_ASSERT_EQUAL(bobSessionsId.size(), 2, size_t, "%ld");
BC_ASSERT_EQUAL((int)bobSessionsId.size(), 2, int, "%d");
// run the update function
aliceManager->update(callback, 0, lime_tester::OPkInitialBatchSize);
......@@ -1885,12 +1885,12 @@ static void x3dh_multiple_DRsessions_test(const lime::CurveId curve, const std::
aliceSessionsId.clear();
aliceActiveSessionId = lime_tester::get_DRsessionsId(dbFilenameAlice, *aliceDevice1, *bobDevice1, aliceSessionsId);
BC_ASSERT_EQUAL(aliceActiveSessionId, 1, long int, "%ld");
BC_ASSERT_EQUAL(aliceSessionsId.size(), 2, size_t, "%ld");
BC_ASSERT_EQUAL((int)aliceSessionsId.size(), 2, int, "%d");
bobSessionsId.clear();
bobActiveSessionId = lime_tester::get_DRsessionsId(dbFilenameBob, *bobDevice1, *aliceDevice1, bobSessionsId);
BC_ASSERT_EQUAL(bobActiveSessionId, 2, long int, "%ld");
BC_ASSERT_EQUAL(bobSessionsId.size(), 2, size_t, "%ld");
BC_ASSERT_EQUAL((int)bobSessionsId.size(), 2, int, "%d");
// fast forward enought time to get the session old enough to be cleared by update
// actually, move all timeStamps in local base back in time.
......@@ -1913,12 +1913,12 @@ static void x3dh_multiple_DRsessions_test(const lime::CurveId curve, const std::
aliceSessionsId.clear();
aliceActiveSessionId = lime_tester::get_DRsessionsId(dbFilenameAlice, *aliceDevice1, *bobDevice1, aliceSessionsId);
BC_ASSERT_EQUAL(aliceActiveSessionId, 1, long int, "%ld");
BC_ASSERT_EQUAL(aliceSessionsId.size(), 1, size_t, "%ld");
BC_ASSERT_EQUAL((int)aliceSessionsId.size(), 1, int, "%d");
bobSessionsId.clear();
bobActiveSessionId = lime_tester::get_DRsessionsId(dbFilenameBob, *bobDevice1, *aliceDevice1, bobSessionsId);
BC_ASSERT_EQUAL(bobActiveSessionId, 2, long int, "%ld");
BC_ASSERT_EQUAL(bobSessionsId.size(), 1, size_t, "%ld");
BC_ASSERT_EQUAL((int)bobSessionsId.size(), 1, int, "%d");
// delete the users so the remote DB will be clean too
if (cleanDatabase) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment