Commit f2e36fe8 authored by johan's avatar johan

Code cleaning

parent eff05bef
############################################################################
# CMakeLists.txt
# Copyright (C) 2017 Belledonne Communications, Grenoble France
#
############################################################################
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
############################################################################
set(LIME_HEADER_FILES
lime_utils.hpp
lime_keys.hpp
lime_impl.hpp
lime_x3dh_protocol.hpp
lime_localStorage.hpp
lime_double_ratchet.hpp
lime_double_ratchet_protocol.hpp
lime_lime.hpp
)
set(LIME_SOURCE_FILES_C )
set(LIME_SOURCE_FILES_CXX
lime.cpp
lime_keys.cpp
lime_x3dh.cpp
lime_x3dh_protocol.cpp
lime_localStorage.cpp
lime_double_ratchet.cpp
lime_double_ratchet_protocol.cpp
lime_manager.cpp
)
bc_apply_compile_flags(LIME_SOURCE_FILES_C STRICT_OPTIONS_CPP STRICT_OPTIONS_C)
bc_apply_compile_flags(LIME_SOURCE_FILES_CXX STRICT_OPTIONS_CPP STRICT_OPTIONS_CXX)
if(ENABLE_STATIC)
add_library(lime-static STATIC ${LIME_HEADER_FILES} ${LIME_SOURCE_FILES_C} ${LIME_SOURCE_FILES_CXX})
set_target_properties(lime-static PROPERTIES OUTPUT_NAME lime)
target_include_directories(lime-static PUBLIC ${BCTOOLBOX_INCLUDE_DIRS} ${SOCI_INCLUDE_DIRS} ${SOCI_INCLUDE_DIRS}/soci)
target_link_libraries(lime-static INTERFACE ${BCTOOLBOX_CORE_LIBRARIES} ${BELLESIP_LIBRARIES} ${SOCI_LIBRARIES} ${SOCI_sqlite3_PLUGIN} ${SQLITE3_LIBRARIES})
endif()
if(ENABLE_SHARED)
add_library(lime SHARED ${LIME_HEADER_FILES} ${LIME_SOURCE_FILES_C} ${LIME_SOURCE_FILES_CXX})
if(APPLE)
set_target_properties(lime PROPERTIES LINK_FLAGS "-stdlib=libc++")
endif()
set_target_properties(lime PROPERTIES VERSION ${LIME_SO_VERSION})
target_include_directories(lime PUBLIC ${BCTOOLBOX_INCLUDE_DIRS} ${SOCI_INCLUDE_DIRS} ${SOCI_INCLUDE_DIRS}/soci)
target_link_libraries(lime PRIVATE ${BCTOOLBOX_CORE_LIBRARIES} ${BELLESIP_LIBRARIES} ${SOCI_LIBRARIES} ${SOCI_sqlite3_PLUGIN} ${SQLITE3_LIBRARIES})
if(MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lime.pdb
DESTINATION ${CMAKE_INSTALL_BINDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
endif()
endif()
if(ENABLE_STATIC)
install(TARGETS lime-static EXPORT ${EXPORT_TARGETS_NAME}Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
if(ENABLE_SHARED)
install(TARGETS lime EXPORT ${EXPORT_TARGETS_NAME}Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
install(FILES ${LIME_HEADER_FILES}
DESTINATION include/lime
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
############################################################################
# CMakeLists.txt
# Copyright (C) 2017 Belledonne Communications, Grenoble France
#
############################################################################
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
############################################################################
set(LIME_HEADER_FILES
lime_settings.hpp
lime_defines.hpp
lime_keys.hpp
lime_impl.hpp
lime_x3dh_protocol.hpp
lime_localStorage.hpp
lime_double_ratchet.hpp
lime_double_ratchet_protocol.hpp
lime_lime.hpp
)
set(LIME_SOURCE_FILES_C )
set(LIME_SOURCE_FILES_CXX
lime.cpp
lime_keys.cpp
lime_x3dh.cpp
lime_x3dh_protocol.cpp
lime_localStorage.cpp
lime_double_ratchet.cpp
lime_double_ratchet_protocol.cpp
lime_manager.cpp
)
bc_apply_compile_flags(LIME_SOURCE_FILES_C STRICT_OPTIONS_CPP STRICT_OPTIONS_C)
bc_apply_compile_flags(LIME_SOURCE_FILES_CXX STRICT_OPTIONS_CPP STRICT_OPTIONS_CXX)
if(ENABLE_STATIC)
add_library(lime-static STATIC ${LIME_HEADER_FILES} ${LIME_SOURCE_FILES_C} ${LIME_SOURCE_FILES_CXX})
set_target_properties(lime-static PROPERTIES OUTPUT_NAME lime)
target_include_directories(lime-static PUBLIC ${BCTOOLBOX_INCLUDE_DIRS} ${SOCI_INCLUDE_DIRS} ${SOCI_INCLUDE_DIRS}/soci)
target_link_libraries(lime-static INTERFACE ${BCTOOLBOX_CORE_LIBRARIES} ${BELLESIP_LIBRARIES} ${SOCI_LIBRARIES} ${SOCI_sqlite3_PLUGIN} ${SQLITE3_LIBRARIES})
endif()
if(ENABLE_SHARED)
add_library(lime SHARED ${LIME_HEADER_FILES} ${LIME_SOURCE_FILES_C} ${LIME_SOURCE_FILES_CXX})
if(APPLE)
set_target_properties(lime PROPERTIES LINK_FLAGS "-stdlib=libc++")
endif()
set_target_properties(lime PROPERTIES VERSION ${LIME_SO_VERSION})
target_include_directories(lime PUBLIC ${BCTOOLBOX_INCLUDE_DIRS} ${SOCI_INCLUDE_DIRS} ${SOCI_INCLUDE_DIRS}/soci)
target_link_libraries(lime PRIVATE ${BCTOOLBOX_CORE_LIBRARIES} ${BELLESIP_LIBRARIES} ${SOCI_LIBRARIES} ${SOCI_sqlite3_PLUGIN} ${SQLITE3_LIBRARIES})
if(MSVC)
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lime.pdb
DESTINATION ${CMAKE_INSTALL_BINDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
endif()
endif()
if(ENABLE_STATIC)
install(TARGETS lime-static EXPORT ${EXPORT_TARGETS_NAME}Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
if(ENABLE_SHARED)
install(TARGETS lime EXPORT ${EXPORT_TARGETS_NAME}Targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endif()
install(FILES ${LIME_HEADER_FILES}
DESTINATION include/lime
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)
/*
lime_defines.hpp
Copyright (C) 2017 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef lime_defines_hpp
#define lime_defines_hpp
namespace lime {
// this namespace hold constants definition used as settings in all components of the lime library
// the constants defined in this file cannot be modified without some work on the source code
// unless you really know what you're doing, just leave them alone
namespace settings {
/******************************************************************************/
/* */
/* Double Ratchet related definitions */
/* */
/******************************************************************************/
// Sending, Receiving and Root key chain use 32 bytes keys (spec 3.2)
constexpr size_t DRChainKeySize=32;
// DR Message Key are composed of a 32 bytes key and 16 bytes of IV
constexpr size_t DRMessageKeySize=32;
constexpr size_t DRMessageIVSize=16;
// Message Key is based on a message seed(sent in the DR message)
// Message key and nonce are derived from this seed and have the same length as DR Message Key
constexpr size_t DRrandomSeedSize=32;
const std::string hkdf_randomSeed_info{"DR Message Key Derivation"};
// AEAD generates tag 16 bytes long
constexpr size_t DRMessageAuthTagSize=16;
/******************************************************************************/
/* */
/* Local Storage related definitions */
/* */
/******************************************************************************/
/* define a version number for the DB schema as an integer 0xMMmmpp */
/* current version is 0.0.1 */
constexpr int DBuserVersion=0x000001;
/******************************************************************************/
/* */
/* X3DH related definitions */
/* */
/******************************************************************************/
const std::string X3DH_SK_info{"Lime"}; // shall be an ASCII string identifying the application (X3DH spec section 2.1)
const std::string X3DH_AD_info{"X3DH Associated Data"}; // used to generate a shared AD based on Ik and deviceID
} // namespace settings
} // namespace lime
#endif /* lime_defines_hpp */
......@@ -25,7 +25,8 @@
#include <vector>
#include <memory>
#include "lime_utils.hpp"
#include "lime_settings.hpp"
#include "lime_defines.hpp"
#include "lime_keys.hpp"
namespace lime {
......
......@@ -25,7 +25,7 @@
#include "lime/lime.hpp"
#include "lime_lime.hpp"
#include "lime_localStorage.hpp"
#include "lime_utils.hpp"
#include "lime_settings.hpp"
using namespace::std;
......
/*
lime_utils.hpp
lime_settings.hpp
Copyright (C) 2017 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
......@@ -16,11 +16,14 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef lime_utils_hpp
#define lime_utils_hpp
#ifndef lime_settings_hpp
#define lime_settings_hpp
namespace lime {
// this namespace hold constants definition used as settings in all components of the lime library
// Here you can tweak the behavior of the library
// No compatibility break between clients shall result by modifying this definitions
// Note : you can tweak values but not the types, uint16_t values are intended to be bounded by 2^16 -1.
namespace settings {
/******************************************************************************/
......@@ -29,29 +32,15 @@ namespace settings {
/* */
/******************************************************************************/
// Sending, Receiving and Root key chain use 32 bytes keys (spec 3.2)
constexpr size_t DRChainKeySize=32;
// DR Message Key are composed of a 32 bytes key and 16 bytes of IV
constexpr size_t DRMessageKeySize=32;
constexpr size_t DRMessageIVSize=16;
// Message Key is based on a message seed(sent in the DR message)
// Message key and nonce are derived from this seed and have the same length as DR Message Key
constexpr size_t DRrandomSeedSize=32;
const std::string hkdf_randomSeed_info{"DR Message Key Derivation"};
// AEAD generates tag 16 bytes long
constexpr size_t DRMessageAuthTagSize=16;
// Each session stores a shared AD given at built and derived from Identity keys of sender and receiver
// SharedAD is computed by X3DH HKDF(session Initiator Ik || session receiver Ik || session Initiator device Id || session receiver device Id)
constexpr size_t DRSessionSharedADSize=32;
// SharedAD is computed by HKDF-Sha511(session Initiator Ik || session receiver Ik || session Initiator device Id || session receiver device Id)
constexpr size_t DRSessionSharedADSize=31;
static_assert(DRSessionSharedADSize<64, "Shared AD is generated through HKDF-Sha512 with only one round implemented so its size can't be more than Sha512 max output size");
// Maximum number of Message we can skip(and store their keys) at reception of one message
constexpr std::uint16_t maxMessageSkip=1024;
// after a message key is stored, count how many messages we can receive from peer before deleting the key
// after a message key is stored, count how many messages we can receive from peer before deleting the key at next update
// Note: implemented by receiving key chain, so any new skipped message in a chain will reset the counter to 0
constexpr std::uint16_t maxMessagesReceivedAfterSkip = 128;
......@@ -63,32 +52,23 @@ namespace settings {
// Lifetime of a session once not active anymore, unit is day
constexpr unsigned int DRSession_limboTime_days=30;
/******************************************************************************/
/* */
/* Local Storage related definitions */
/* */
/******************************************************************************/
/* define a version number for the DB schema as an integer 0xMMmmpp */
/* current version is 0.0.1 */
constexpr int DBuserVersion=0x000001;
/******************************************************************************/
/* */
/* X3DH related definitions */
/* */
/******************************************************************************/
const std::string X3DH_SK_info{"Lime"}; // shall be an ASCII string identifying the application (X3DH spec section 2.1)
const std::string X3DH_AD_info{"X3DH Associated Data"}; // used to generate a shared AD based on Ik and deviceID
constexpr unsigned int SPK_lifeTime_days=7; // in days, Life time of a signed pre-key, it will be set to stale after that period
constexpr unsigned int SPK_limboTime_days=30; // in days, How long shall we keep a signed pre-key once it has been replaced by a new one
// Note: the three following values can be overriden by call parameters when creating the user or calling update
constexpr uint16_t OPk_batchSize = 25; // default batch size when uploading OPks to X3DH server
constexpr uint16_t OPk_initialBatchSize = 2*OPk_batchSize; // default batch size when creating a new user
constexpr uint16_t OPk_serverLowLimit = 50; // this is a default value but it can be set by parameter to the update function
constexpr uint16_t OPk_initialBatchSize = 4*OPk_batchSize; // default batch size when creating a new user
constexpr uint16_t OPk_serverLowLimit = 100; // default limit for keys on server to trigger generation/upload of a new batch of OPks
constexpr unsigned int OPk_limboTime_days=SPK_lifeTime_days+SPK_limboTime_days; // in days, How long shall we keep an OPk in localStorage once we've noticed X3DH server dispatched it
}
}
} // namespace settings
} // namespace lime
#endif /* lime_utils_hpp */
#endif /* lime_settings_hpp */
......@@ -24,7 +24,7 @@
#include "lime/lime.hpp"
#include "lime_x3dh_protocol.hpp"
#include "lime_utils.hpp"
#include "lime_settings.hpp"
#include "lime_impl.hpp"
#include "belle-sip/belle-sip.h"
......
......@@ -24,7 +24,7 @@
#include <vector>
#include <string>
#include "lime_utils.hpp"
#include "lime_settings.hpp"
#include "lime/lime.hpp"
#include "lime_keys.hpp"
#include "lime_double_ratchet_protocol.hpp"
......
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