Commit c59a6382 authored by Matthieu Tanon's avatar Matthieu Tanon

Merge branch 'dev_ffi' into 'master'

C interface minor fix and better tests

See merge request !3
parents e9081dcd 293944fe
......@@ -37,7 +37,7 @@ option(ENABLE_CURVE25519 "Enable support of Curve 25519." YES)
option(ENABLE_CURVE448 "Enable support of Curve 448(goldilock)." YES)
option(ENABLE_UNIT_TESTS "Enable compilation of unit tests." YES)
option(ENABLE_PROFILING "Enable profiling, GCC only" NO)
option(ENABLE_C_INTERFACE "Enable support of C function foreign interface" NO)
option(ENABLE_C_INTERFACE "Enable support of C89 foreign function interface" NO)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
......
......@@ -68,7 +68,7 @@ Options
- `ENABLE_Curve25519` : Enable support of Curve 25519.
- `ENABLE_Curve448` : Enable support of Curve 448.
- `ENABLE_PROFILING` : Enable code profiling for GCC
- `ENABLE_C_INTERFACE` : Enable support of C89 function foreign interface
- `ENABLE_C_INTERFACE` : Enable support of C89 foreign function interface
------------------
......
......@@ -144,6 +144,7 @@ typedef void (*lime_ffi_X3DHServerPostData)(void *userData, lime_ffi_data_t lime
* @param[in] response binary buffered server response
* @param[in] response_size size of previous buffer
*
* @return LIME_FFI_SUCCESS or a negative error code
*/
int lime_ffi_processX3DHServerResponse(lime_ffi_data_t limeData, const int code, const uint8_t *response, const size_t response_size);
......@@ -154,6 +155,8 @@ int lime_ffi_processX3DHServerResponse(lime_ffi_data_t limeData, const int code,
* @param[in] db string used to access DB (shall be filename for sqlite3), directly forwarded to SOCI session opening
* @param[in] X3DH_post_data A function to send data to the X3DH server. The server response must be forwarded to lime using the lime_ffi_processX3DHServerResponse function
* @param[in] userData pointer passed back to the X3DH_post_data callback
*
* @return LIME_FFI_SUCCESS or a negative error code
*/
int lime_ffi_manager_init(lime_manager_t * const manager, const char *db, const lime_ffi_X3DHServerPostData X3DH_post_data, void *userData);
......@@ -161,6 +164,8 @@ int lime_ffi_manager_init(lime_manager_t * const manager, const char *db, const
* @brief Destroy the internal structure used to interact with lime
*
* @param[in,out] manager pointer to the opaque structure used to interact with lime
*
* @return LIME_FFI_SUCCESS or a negative error code
*/
int lime_ffi_manager_destroy(lime_manager_t manager);
......@@ -177,6 +182,7 @@ int lime_ffi_manager_destroy(lime_manager_t manager);
* this callback will be called giving the exit status and an error message in case of failure
* @param[in] callbackUserData this pointer will be forwarded to the callback as first parameter
*
* @return LIME_FFI_SUCCESS or a negative error code
*/
int lime_ffi_create_user(lime_manager_t manager, const char *localDeviceId,
const char *x3dhServerUrl, const enum lime_ffi_CurveId curve, const uint16_t OPkInitialBatchSize,
......@@ -193,6 +199,7 @@ int lime_ffi_create_user(lime_manager_t manager, const char *localDeviceId,
* this callback will be called giving the exit status and an error message in case of failure
* @param[in] callbackUserData this pointer will be forwarded to the callback as first parameter
*
* @return LIME_FFI_SUCCESS or a negative error code
*/
int lime_ffi_delete_user(lime_manager_t manager, const char *localDeviceId, const lime_ffi_Callback callback, void *callbackUserData);
......@@ -204,6 +211,8 @@ int lime_ffi_delete_user(lime_manager_t manager, const char *localDeviceId, cons
* @param[in] curve Choice of elliptic curve to use as base for ECDH and EdDSA operation involved. Can be lime_ffi_CurveId_c25519 or lime_ffi_CurveId_c448.
* @param[out] DRmessageSize maximum size of the DRmessage produced by the encrypt function
* @param[out] cipherMessageSize maximum size of the cipherMessage produced by the encrypt function
*
* @return LIME_FFI_SUCCESS or a negative error code
*/
int lime_ffi_encryptOutBuffersMaximumSize(const size_t plainMessageSize, const enum lime_ffi_CurveId curve, size_t *DRmessageSize, size_t *cipherMessageSize);
......@@ -250,6 +259,8 @@ int lime_ffi_encryptOutBuffersMaximumSize(const size_t plainMessageSize, const
* @param[in] callbackUserData this pointer will be forwarded to the callback as first parameter
* @param[in] encryptionPolicy select how to manage the encryption: direct use of Double Ratchet message or encrypt in the cipher message and use the DR message to share the cipher message key
* default is optimized output size mode.
*
* @return LIME_FFI_SUCCESS or a negative error code
*/
int lime_ffi_encrypt(lime_manager_t manager, const char *localDeviceId,
const char *recipientUserId, lime_ffi_RecipientData_t *const recipients, const size_t recipientsSize,
......@@ -298,6 +309,8 @@ enum lime_ffi_PeerDeviceStatus lime_ffi_decrypt(lime_manager_t manager, const ch
* @param[in] localDeviceId used to identify which local account we're dealing with, shall be the GRUU
* @param[out] Ik the EdDSA public identity key, formatted as in RFC8032
* @param[in,out] IkSize size of the previous buffer, updated with the size of data actually written
*
* @return LIME_FFI_SUCCESS or a negative error code
*/
int lime_ffi_get_selfIdentityKey(lime_manager_t manager, const char *localDeviceId, uint8_t *const Ik, size_t *IkSize);
......@@ -330,6 +343,8 @@ int lime_ffi_get_selfIdentityKey(lime_manager_t manager, const char *localDevice
* -status is unsafe
* - ignore Ik
* - insert/update the status. If inserted, insert an invalid Ik
*
* @return LIME_FFI_SUCCESS or a negative error code
*/
int lime_ffi_set_peerDeviceStatus(lime_manager_t manager, const char *peerDeviceId, const uint8_t *const Ik, const size_t IkSize, enum lime_ffi_PeerDeviceStatus status);
......@@ -351,6 +366,8 @@ enum lime_ffi_PeerDeviceStatus lime_ffi_get_peerDeviceStatus(lime_manager_t mana
* @param[in] peerDeviceId The device Id to be removed from local storage, shall be its GRUU
*
* Call is silently ignored if the device is not found in local storage
*
* @return LIME_FFI_SUCCESS or a negative error code
*/
int lime_ffi_delete_peerDevice(lime_manager_t manager, const char *peerDeviceId);
......@@ -370,6 +387,7 @@ int lime_ffi_delete_peerDevice(lime_manager_t manager, const char *peerDeviceId)
* @param[in] OPkServerLowLimit If server holds less OPk than this limit, generate and upload a batch of OPks
* @param[in] OPkBatchSize Number of OPks in a batch uploaded to server
*
* @return LIME_FFI_SUCCESS or a negative error code
*/
int lime_ffi_update(lime_manager_t manager, const lime_ffi_Callback callback, void *callbackUserData, uint16_t OPkServerLowLimit, uint16_t OPkBatchSize);
......
......@@ -18,8 +18,6 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include "lime/lime_ffi.h"
#include "lime/lime.hpp"
#include "lime_log.hpp"
......@@ -226,8 +224,8 @@ int lime_ffi_encryptOutBuffersMaximumSize(const size_t plainMessageSize, const e
*cipherMessageSize = plainMessageSize + lime::settings::DRMessageAuthTagSize;
/* DRmessage maximum size is :
* DRmessage header size + X3DH init size + plain message size + auth tag size */
*DRmessageSize = plainMessageSize + lime::settings::DRMessageAuthTagSize;
* DRmessage header size + X3DH init size + MAX(plain message size, RandomSeed Size) + auth tag size */
*DRmessageSize = std::max(plainMessageSize, lime::settings::DRrandomSeedSize) + lime::settings::DRMessageAuthTagSize;
switch (curve) {
case lime_ffi_CurveId_c25519:
......
......@@ -166,4 +166,15 @@ int wait_for(belle_sip_stack_t*s1,int* counter,int value,int timeout);
#endif
} // namespace lime_tester
#endif
/* some shared variable defined in lime_ff-tester, used only when FFI is enabled
* and they are duplicate of command line arguments variable already existing in C++ from lime_tester-utils.cpp
* but it's easier to read and implement this way */
// ffi default url and ports of X3DH servers
extern char ffi_test_x3dh_server_url[512];
extern char ffi_test_x3dh_c25519_server_port[16];
extern char ffi_test_x3dh_c448_server_port[16];
// ffi default value for the timeout
extern int ffi_wait_for_timeout;
#endif //lime_tester_utils_hpp
......@@ -25,6 +25,7 @@
static FILE * log_file = NULL;
static const char *log_domain = "lime";
bool cleanDatabase = true;
uint8_t ffi_cleanDatabase = 1;
bool bench = false;
static void log_handler(int lev, const char *fmt, va_list args) {
......@@ -132,17 +133,22 @@ int main(int argc, char *argv[]) {
} else if (strcmp(argv[i],"--x3dh-server-name")==0){
CHECK_ARG("--x3dh-server-name", ++i, argc);
lime_tester::test_x3dh_server_url=std::string(argv[i]);
strncpy(ffi_test_x3dh_server_url, argv[i], sizeof(ffi_test_x3dh_server_url));
} else if (strcmp(argv[i],"--c255-x3dh-server-port")==0){
CHECK_ARG("--c255-x3dh-server-port", ++i, argc);
lime_tester::test_x3dh_c25519_server_port=std::string(argv[i]);
strncpy(ffi_test_x3dh_c25519_server_port, argv[i], sizeof(ffi_test_x3dh_c25519_server_port));
} else if (strcmp(argv[i],"--c448-x3dh-server-port")==0){
CHECK_ARG("--c448-x3dh-server-port", ++i, argc);
lime_tester::test_x3dh_c448_server_port=std::string(argv[i]);
strncpy(ffi_test_x3dh_c448_server_port, argv[i], sizeof(ffi_test_x3dh_c448_server_port));
} else if (strcmp(argv[i],"--operation-timeout")==0){
CHECK_ARG("--operation-timeout", ++i, argc);
lime_tester::wait_for_timeout=std::atoi(argv[i]);
ffi_wait_for_timeout=lime_tester::wait_for_timeout;
} else if (strcmp(argv[i],"--keep-tmp-db")==0){
cleanDatabase=false;
ffi_cleanDatabase=0;
} else if (strcmp(argv[i],"--bench")==0){
bench=true;
}else {
......
This diff is collapsed.
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