Commit 0aa08b45 authored by johan's avatar johan
Browse files

Add Java interface

+add license files to clarify the status of the files copyright mapbox introduced.

Work in Progress, TODO:
- better testing
- add peer device status management functions
- complete doc
parent de7e3446
......@@ -26,7 +26,7 @@ include(CMakePushCheckState)
include(CMakePackageConfigHelpers)
cmake_minimum_required(VERSION 3.0)
project(lime VERSION 0.0.1 LANGUAGES CXX C)
project(lime VERSION 0.0.1 LANGUAGES CXX C Java)
set(LIME_SO_VERSION "0")
set(LIME_VERSION ${PROJECT_VERSION})
......@@ -39,6 +39,7 @@ 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 C89 foreign function interface" NO)
option(ENABLE_JNI "Enable support of Java foreign function interface" NO)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
......@@ -93,7 +94,7 @@ else()
if (ENABLE_PROFILING)
list(APPEND STRICT_OPTIONS_CXX "-g -pg")
endif()
list(APPEND STRICT_OPTIONS_CXX "-std=c++11")
list(APPEND STRICT_OPTIONS_CXX "-std=c++14")
#list(APPEND STRICT_OPTIONS_CPP "-Wall" "-Wuninitialized" "-Wno-error=deprecated-declarations") # turn off deprecated-declaration warning to avoid being flooded by soci.h
list(APPEND STRICT_OPTIONS_CPP "-Wall" "-Wuninitialized" "-Wno-deprecated-declarations" "-Wno-missing-field-initializers")
if(ENABLE_C_INTERFACE)
......@@ -134,6 +135,15 @@ if(ENABLE_C_INTERFACE)
message(STATUS "Provide C89 interface")
endif()
if(ENABLE_JNI)
find_package(JNI REQUIRED)
if (JNI_FOUND)
message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
message (STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}")
endif()
endif()
add_subdirectory(include)
add_subdirectory(src)
if(ENABLE_UNIT_TESTS AND BCTOOLBOX_TESTER_FOUND)
......
This diff is collapsed.
......@@ -8,6 +8,14 @@ Lime can run the Signal Protocol using elliptic curve 25519 or curve 448-goldilo
It is designed to work jointly with *Linphone*[1] in a multiple devices per user and multiple users per device environment.
License
--------
Copyright (c) 2019 Belledonne Communications SARL under GNU GPLv3 (see *LICENSE.txt*)
The above license excludes the content of *src/jni* directory Copyright (c) 2016 Mapbox covered by its respective license,
see *src/jni/LICENSE.txt*
Dependencies
------------
- *bctoolbox[2]* : portability layer, built with Elliptic Curve Cryptography
......@@ -23,7 +31,6 @@ Build instrucitons
make install
```
Documentation
-------------
......@@ -38,23 +45,42 @@ Comprehensive documentation on implementation choices and built-in protocols in
Testing
-------
To test on local machine, you must run a local X3DH server.
To test on local machine, you must run a local X3DH server.
- A nodejs/sqlite version of UNSECURE X3DH server is provided in *tester/server/nodejs*
See README from this directory for instructions.
- A php/mysql (on docker) version of UNSECURE X3DH server is provided in *tester/server/php*
See README from this directory for instructions.
If a local X3DH server is running with default parameter just run
```
make test
```
To launch a particular test suite, use ctest, running:
```
ctest -R <Test suite name> [--verbose]
```
Test suite names are
- *crypto*: Test the crypto primitives
- *double_ratchet*: Specific to the Double Ratchet protocol
- *hello_world*: Basic Lime test, mostly a demo code. Requires a live X3DH server on localhost
- *lime*: Complete testing of all features provided by the library. Requires a live X3DH server on localhost
- *C_ffi*: Available only if C interface is enabled, test the C89 foreign function interface
- *JNI*: Available only if JNI is enabled, test the Java foreign function interface
Library settings
----------------
Some mostly harmless settings are available in *src/lime_settings.hpp*
Library API
Library APIs
-----------
The C++11 API is available in *include/lime/lime.hpp*
if enabled (see Options), a C89 FFI is provided by *include/lime/lime_ffi.h*
if enabled (see Options), a java FFI is provided by *Lime.jar* located in the build directory in *src/java* subdirectory
Options
-------
......@@ -69,6 +95,7 @@ Options
- `ENABLE_Curve448` : Enable support of Curve 448.
- `ENABLE_PROFILING` : Enable code profiling for GCC
- `ENABLE_C_INTERFACE` : Enable support of C89 foreign function interface
- `ENABLE_JNI` : Enable support of Java foreign function interface
------------------
......
......@@ -48,13 +48,18 @@ if (ENABLE_C_INTERFACE)
set(LIME_SOURCE_FILES_CXX ${LIME_SOURCE_FILES_CXX} lime_ffi.cpp)
endif()
if (ENABLE_JNI)
set(LIME_SOURCE_FILES_CXX ${LIME_SOURCE_FILES_CXX} lime_jni.cpp)
add_subdirectory(java)
endif()
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_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} ${SOCI_LIBRARIES} ${SOCI_sqlite3_PLUGIN})
target_include_directories(lime-static PUBLIC ${BCTOOLBOX_INCLUDE_DIRS} ${SOCI_INCLUDE_DIRS} ${SOCI_INCLUDE_DIRS}/soci ${JNI_INCLUDE_DIRS})
target_link_libraries(lime-static INTERFACE ${BCTOOLBOX_CORE_LIBRARIES} ${SOCI_LIBRARIES} ${SOCI_sqlite3_PLUGIN} ${JNI_LIBRARIES})
if(ENABLE_PROFILING)
set_target_properties(lime-static PROPERTIES LINK_FLAGS "-pg")
endif()
......@@ -62,8 +67,8 @@ endif()
if(ENABLE_SHARED)
add_library(lime SHARED ${LIME_HEADER_FILES} ${LIME_SOURCE_FILES_CXX})
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} ${SOCI_LIBRARIES} ${SOCI_sqlite3_PLUGIN})
target_include_directories(lime PUBLIC ${BCTOOLBOX_INCLUDE_DIRS} ${SOCI_INCLUDE_DIRS} ${SOCI_INCLUDE_DIRS}/soci ${JNI_INCLUDE_DIRS})
target_link_libraries(lime PRIVATE ${BCTOOLBOX_CORE_LIBRARIES} ${SOCI_LIBRARIES} ${SOCI_sqlite3_PLUGIN} ${JNI_LIBRARIES})
# TODO: replace by if(APPLE) when we want to make apple framework on linphone-desktop too
if(IOS)
if(IOS)
......
############################################################################
# CMakeLists.txt
# Copyright (C) 2019 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.
#
############################################################################
find_package(Java REQUIRED)
include(UseJava)
set (LIME_SOURCE_FILES_JAVA
org/linphone/lime/LimeCurveId.java
org/linphone/lime/LimeEncryptionPolicy.java
org/linphone/lime/LimeOutputBuffer.java
org/linphone/lime/LimePeerDeviceStatus.java
org/linphone/lime/LimeCallbackReturn.java
org/linphone/lime/LimeStatusCallback.java
org/linphone/lime/RecipientData.java
org/linphone/lime/PostToX3DH.java
org/linphone/lime/LimeManager.java
)
add_jar(Lime ${LIME_SOURCE_FILES_JAVA})
get_target_property(Lime_jarFile Lime JAR_FILE)
message(STATUS "Lime Jar file ${Lime_jarFile}")
/*
LimeCallbackReturn.java
@author Johan Pascal
@copyright Copyright (C) 2019 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/>.
*/
package org.linphone.lime;
/** @brief Enumeration remapping the lime::CallbackReturn
* - java enumeration is mapped to an int
* - jni code map the same int to the original lime::CallbackReturn
*/
public enum LimeCallbackReturn {
SUCCESS(0),
FAIL(1);
private int native_val; /* Store the native(used by jni) integer value */
LimeCallbackReturn(int val) {
native_val = val;
}
/**
* @brief static method to get an enum value from the native jni integer(used as returned value by native function)
*
* @param[in] val integer value mapped to the jni enum
*
* @return one of the enumeration value, unknown input will silently default to FAIL
*/
public static LimeCallbackReturn fromNative(int val) {
switch (val) {
case 0:
return LimeCallbackReturn.SUCCESS;
case 1:
default:
return LimeCallbackReturn.FAIL;
}
}
}
/*
LimeCurveId.java
@author Johan Pascal
@copyright Copyright (C) 2019 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/>.
*/
package org.linphone.lime;
public enum LimeCurveId {
C25519(1), /**< Curve 25519 */
C448(2); /**< Curve 448-goldilocks */
private int native_val; /* Store the native(used by jni) integer value */
/**
* @brief get the native value (used to give input parameter values)
* @return the native value associated
*/
public int getNative() {return native_val;}
LimeCurveId(int val) {
native_val = val;
}
}
/*
LimeEncryptionPolicy.java
@author Johan Pascal
@copyright Copyright (C) 2019 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/>.
*/
package org.linphone.lime;
public enum LimeEncryptionPolicy {
DRMESSAGE(0), /**< the plaintext input is encrypted inside the Double Ratchet message (each recipient get a different encryption): not optimal for messages with numerous recipient */
CIPHERMESSAGE(1), /**< the plaintext input is encrypted with a random key and this random key is encrypted to each participant inside the Double Ratchet message(for a single recipient the overhead is 48 bytes) */
OPTIMIZEUPLOADSIZE(2), /**< optimize upload size: encrypt in DR message if plaintext is short enougth to beat the overhead introduced by cipher message scheme, otherwise use cipher message. Selection is made on upload size only. This is the default policy used */
OPTIMIZEGLOBALBANDWIDTH(3); /**< optimize bandwith usage: encrypt in DR message if plaintext is short enougth to beat the overhead introduced by cipher message scheme, otherwise use cipher message. Selection is made on uploadand download (from server to recipients) sizes added. */
private int native_val; /* Store the native(used by jni) integer value */
/**
* @brief get the native value (used to give input parameter values)
* @return the native value associated
*/
public int getNative() {return native_val;}
LimeEncryptionPolicy(int val) {
native_val = val;
}
}
/*
LimeManager.java
@author Johan Pascal
@copyright Copyright (C) 2019 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/>.
*/
package org.linphone.lime;
public class LimeManager {
public LimeManager(String db_access) {
initialize(db_access);
}
private long peer;
protected native void initialize(String db_access);
protected native void finalize() throws Throwable;
// Native functions involving enumerated paremeters not public
// Enumeration translation is done on java side
private native int n_decrypt(String localDeviceId, String recipientUserId, String senderDeviceId, byte[] DRmessage, byte[] cipherMessage, LimeOutputBuffer plainMessage);
private native void n_encrypt(String localDeviceId, String recipientUserId, RecipientData[] recipients, byte[] plainMessage, LimeOutputBuffer cipherMessage, LimeStatusCallback statusObj, int encryptionPolicy);
private native void n_create_user(String localDeviceId, String serverURL, int curveId, int OPkInitialBatchSize, LimeStatusCallback statusObj);
private native void n_update(LimeStatusCallback statusObj, int OPkServerLowLimit, int OPkBatchSize);
/* default value for OPkInitialBatchSize is 100 */
public void create_user(String localDeviceId, String serverURL, LimeCurveId curveId, LimeStatusCallback statusObj) {
this.n_create_user(localDeviceId, serverURL, curveId.getNative(), 100, statusObj);
}
public void create_user(String localDeviceId, String serverURL, LimeCurveId curveId, int OPkInitialBatchSize, LimeStatusCallback statusObj) {
this.n_create_user(localDeviceId, serverURL, curveId.getNative(), OPkInitialBatchSize, statusObj);
}
public native void delete_user(String localDeviceId, LimeStatusCallback statusObj);
/**
* @brief Encrypt a buffer (text or file) for a given list of recipient devices
*
* if specified localDeviceId is not found in local Storage, throw an exception
*
* Clarification on recipients:
*
* recipients information needed are a list of the device Id and one userId. The device Id shall be their GRUU while the userId is a sip:uri.
*
* recipient User Id is used to identify the actual intended recipient. Example: alice have two devices and is signed up on a conference having
* bob and claire as other members. The recipientUserId will be the conference sip:uri and device list will include:
* - alice other device
* - bob devices
* - claire devices
* If Alice write to Bob only, the recipientUserId will be bob sip:uri and recipient devices list :
* - alice other device
* - bob devices
*
* In all cases, the identified source of the message will be the localDeviceId
*
* If the X3DH server can't provide keys for a peer device, its status is set to fail and its DRmessage is empty. Other devices get their encrypted message
* If no peer device could get encrypted for all of them are missing keys on the X3DH server, the callback will still be called with success exit status
*
* @note nearly all parameters are shared pointers as the process being asynchronous, the ownership will be taken internally exempting caller to manage the buffers.
*
* @param[in] localDeviceId used to identify which local acount to use and also as the identified source of the message, shall be the GRUU
* @param[in] recipientUserId the Id of intended recipient, shall be a sip:uri of user or conference, is used as associated data to ensure no-one can mess with intended recipient
* @param[in,out] recipients a list of RecipientData holding:
* - the recipient device Id(GRUU)
* - an empty buffer to store the DRmessage which must then be routed to that recipient
* - the peer Status. If peerStatus is set to fail, this entry is ignored otherwise the peerStatus is set by the encrypt, see ::PeerDeviceStatus definition for details
* @param[in] plainMessage a buffer holding the message to encrypt, can be text or data.
* @param[out] cipherMessage points to the buffer to store the encrypted message which must be routed to all recipients(if one is produced, depends on encryption policy)
* @param[in] callback Performing encryption may involve the X3DH server and is thus asynchronous, when the operation is completed,
* this callback will be called giving the exit status and an error message in case of failure.
* It is advised to capture a copy of cipherMessage and recipients shared_ptr in this callback so they can access
* the output of encryption as it won't be part of the callback parameters.
* @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.
*/
public void encrypt(String localDeviceId, String recipientUserId, RecipientData[] recipients, byte[] plainMessage, LimeOutputBuffer cipherMessage, LimeStatusCallback statusObj, LimeEncryptionPolicy encryptionPolicy) {
this.n_encrypt(localDeviceId, recipientUserId, recipients, plainMessage, cipherMessage, statusObj, encryptionPolicy.getNative());
}
/**
* @overload encrypt(String localDeviceId, String recipientUserId, RecipientData[] recipients, byte[] plainMessage, LimeOutputBuffer cipherMessage, LimeStatusCallback statusObj
* convenience form using LimeEncryptionPolicy.OPTIMIZEUPLOADSIZE as default policy
*/
public void encrypt(String localDeviceId, String recipientUserId, RecipientData[] recipients, byte[] plainMessage, LimeOutputBuffer cipherMessage, LimeStatusCallback statusObj) {
this.n_encrypt(localDeviceId, recipientUserId, recipients, plainMessage, cipherMessage, statusObj, LimeEncryptionPolicy.OPTIMIZEUPLOADSIZE.getNative());
}
/**
* @brief Decrypt the given message
*
* if specified localDeviceId is not found in local Storage, throw an exception
*
* @param[in] localDeviceId used to identify which local acount to use and also as the recipient device ID of the message, shall be the GRUU
* @param[in] recipientUserId the Id of intended recipient, shall be a sip:uri of user or conference, is used as associated data to ensure no-one can mess with intended recipient
* it is not necessarily the sip:uri base of the GRUU as this could be a message from alice first device intended to bob being decrypted on alice second device
* @param[in] senderDeviceId Identify sender Device. This field shall be extracted from signaling data in transport protocol, is used to rebuild the authenticated data associated to the encrypted message
* @param[in] DRmessage Double Ratchet message targeted to current device
* @param[in] cipherMessage when present (depends on encryption policy) holds a common part of the encrypted message. Can be ignored or set to empty vector if not present in the incoming message.
* @param[out] plainMessage the output buffer
*
* @return LimePeerDeviceStatus.FAIL if we cannot decrypt the message, LimePeerDeviceStatus.UNKNOWN when it is the first message we ever receive from the sender device, LimePeerDeviceStatus.UNTRUSTED for known but untrusted sender device, or LimePeerDeviceStatus.TRUSTED if it is
*/
public LimePeerDeviceStatus decrypt(String localDeviceId, String recipientUserId, String senderDeviceId, byte[] DRmessage, byte[] cipherMessage, LimeOutputBuffer plainMessage) {
int native_status = this.n_decrypt(localDeviceId, recipientUserId, senderDeviceId, DRmessage, cipherMessage, plainMessage);
return LimePeerDeviceStatus.fromNative(native_status);
}
/**
* @overload decrypt(String localDeviceId, String recipientUserId, String senderDeviceId, byte[] DRmessage, LimeOutputBuffer plainMessage)
* convenience form to be called when no cipher message is received
*/
public LimePeerDeviceStatus decrypt(String localDeviceId, String recipientUserId, String senderDeviceId, byte[] DRmessage, LimeOutputBuffer plainMessage) {
// can't easily overload the native function and the native decrypt support empty cipherMessage buffer
byte[] dummyCipherMessage = new byte[0];
int native_status = this.n_decrypt(localDeviceId, recipientUserId, senderDeviceId, DRmessage, dummyCipherMessage, plainMessage);
return LimePeerDeviceStatus.fromNative(native_status);
}
/**
* @brief Update: shall be called once a day at least, performs checks, updates and cleaning operations
*
* - check if we shall update a new SPk to X3DH server(SPk lifetime is set in settings)
* - check if we need to upload OPks to X3DH server
* - remove old SPks, clean double ratchet sessions (remove staled, clean their stored keys for skipped messages)
*
* Is performed for all users founds in local storage
*
* @param[in] callback This operation may contact the X3DH server and is thus asynchronous, when server responds,
* this callback will be called giving the exit status and an error message in case of failure.
* @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
*
* @note
* The last two parameters are optional, if not used, set to defaults defined in lime::settings
* (not done with param default value as the lime::settings shall not be available in public include)
*/
public void update(LimeStatusCallback statusObj, int OPkServerLowLimit, int OPkBatchSize) {
this.n_update(statusObj, OPkServerLowLimit, OPkBatchSize);
}
/**
* @overload update(LimeStatusCallback statusObj)
* convenience form using default server limit(100) and batch size(25)
*/
public void update(LimeStatusCallback statusObj) {
this.n_update(statusObj, 100, 25);
}
}
/*
LimeOutputBuffer.java
@author Johan Pascal
@copyright Copyright (C) 2019 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/>.
*/
package org.linphone.lime;
/* encapsulate a byte buffer so this object is instanciated in java and passed as output parameter to the native function
* but the encapsulated byte buffer is created and populated by the native function */
public class LimeOutputBuffer {
public byte[] buffer;
}
/*
LimePeerDeviceStatus.java
@author Johan Pascal
@copyright Copyright (C) 2019 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/>.
*/
package org.linphone.lime;
/** @brief Enumeration remapping the lime::PeerDeviceStatus
* - java enumeration is mapped to an int
* - jni code map the same int to the original lime::PeerDeviceStatus
*/
public enum LimePeerDeviceStatus {
UNTRUSTED(0), /**< we know this device but do not trust it, that information shall be displayed to the end user, a colour code shall be enough */
TRUSTED(1), /**< this peer device already got its public identity key validated, that information shall be displayed to the end user too */
UNSAFE(2), /**< this status is a helper for the library user. It is used only by the peerDeviceStatus accessor functions */
FAIL(3), /**< when returned by decrypt : we could not decrypt the incoming message\n
when returned by encrypt in the peerStatus: we could not encrypt to this recipient(probably because it does not published keys on the X3DH server) */
UNKNOWN(4); /**< when returned after encryption or decryption, means it is the first time we communicate with this device (and thus create a DR session with it)\n
when returned by a get_peerDeviceStatus: this device is not in localStorage */
private int native_val; /* Store the native(used by jni) integer value */
/**
* @brief get the native value (used to give input parameter values)
* @return the native value associated
*/
public int getNative() {return native_val;}
/**
* @brief static method to get an enum value from the native jni integer(used as returned value by native function)
*
* @param[in] val integer value mapped to the jni enum
*
* @return one of the enumeration value, unknown input will silently default to UNKNOWN
*/
public static LimePeerDeviceStatus fromNative(int val) {
switch (val) {
case 0:
return LimePeerDeviceStatus.UNTRUSTED;
case 1:
return LimePeerDeviceStatus.TRUSTED;
case 2:
return LimePeerDeviceStatus.UNSAFE;
case 3:
return LimePeerDeviceStatus.FAIL;
case 4:
default:
return LimePeerDeviceStatus.UNKNOWN;
}
}
LimePeerDeviceStatus(int val) {
native_val = val;
}
}
/*
LimeStatusCallback.java
@author Johan Pascal
@copyright Copyright (C) 2019 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/>.