-> the byte[] to String conversions are done on Java level (when it is possible)
-> remove javaCStringToUtf8
This commit is contained in:
parent
765647cda5
commit
9552e14fda
17 changed files with 178 additions and 159 deletions
|
@ -118,7 +118,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
|
||||||
} else {
|
} else {
|
||||||
aErrorMsg.setLength(0);
|
aErrorMsg.setLength(0);
|
||||||
try {
|
try {
|
||||||
pickleRetValue = serializeDataWithKeyJni(aKey.getBytes("UTF-8"), aErrorMsg);
|
pickleRetValue = new String(serializeDataWithKeyJni(aKey.getBytes("UTF-8"), aErrorMsg), "UTF-8");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(LOG_TAG, "## serializeDataWithKey() failed " + e.getMessage());
|
Log.e(LOG_TAG, "## serializeDataWithKey() failed " + e.getMessage());
|
||||||
aErrorMsg.append(e.getMessage());
|
aErrorMsg.append(e.getMessage());
|
||||||
|
@ -127,7 +127,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
|
||||||
|
|
||||||
return pickleRetValue;
|
return pickleRetValue;
|
||||||
}
|
}
|
||||||
private native String serializeDataWithKeyJni(byte[] aKey, StringBuffer aErrorMsg);
|
private native byte[] serializeDataWithKeyJni(byte[] aKey, StringBuffer aErrorMsg);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -164,6 +164,7 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
|
||||||
|
|
||||||
return retCode;
|
return retCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private native String initWithSerializedDataJni(byte[] aSerializedDataBuffer, byte[] aKeyBuffer);
|
private native String initWithSerializedDataJni(byte[] aSerializedDataBuffer, byte[] aKeyBuffer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -363,25 +364,34 @@ public class OlmAccount extends CommonSerializeUtils implements Serializable {
|
||||||
* @return the signed message if operation succeed, null otherwise
|
* @return the signed message if operation succeed, null otherwise
|
||||||
*/
|
*/
|
||||||
public String signMessage(String aMessage) {
|
public String signMessage(String aMessage) {
|
||||||
if (null == aMessage) {
|
String result = null;
|
||||||
return null;
|
|
||||||
|
if (null != aMessage) {
|
||||||
|
byte[] utf8String = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
utf8String = aMessage.getBytes("UTF-8");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(LOG_TAG, "## signMessage(): failed =" + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null != utf8String) {
|
||||||
|
byte[] signedMessage = signMessageJni(utf8String);
|
||||||
|
|
||||||
|
if (null != signedMessage) {
|
||||||
|
try {
|
||||||
|
result = new String(signedMessage, "UTF-8");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(LOG_TAG, "## signMessage(): failed =" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] utf8String = null;
|
return result;
|
||||||
|
|
||||||
try {
|
|
||||||
utf8String = aMessage.getBytes("UTF-8");
|
|
||||||
} catch (Exception e) {
|
|
||||||
Log.d(LOG_TAG,"## signMessage(): failed ="+e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null == utf8String) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return signMessageJni(utf8String);
|
|
||||||
}
|
}
|
||||||
private native String signMessageJni(byte[] aMessage);
|
|
||||||
|
private native byte[] signMessageJni(byte[] aMessage);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true the object resources have been released.<br>
|
* Return true the object resources have been released.<br>
|
||||||
|
|
|
@ -144,10 +144,16 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
|
||||||
* @return the session ID if operation succeed, null otherwise
|
* @return the session ID if operation succeed, null otherwise
|
||||||
*/
|
*/
|
||||||
public String sessionIdentifier() {
|
public String sessionIdentifier() {
|
||||||
return sessionIdentifierJni();
|
try {
|
||||||
}
|
return new String(sessionIdentifierJni(), "UTF-8");
|
||||||
private native String sessionIdentifierJni();
|
} catch (Exception e) {
|
||||||
|
Log.e(LOG_TAG, "## sessionIdentifier() failed " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private native byte[] sessionIdentifierJni();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrypt the message passed in parameter.<br>
|
* Decrypt the message passed in parameter.<br>
|
||||||
|
@ -161,9 +167,14 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
|
||||||
|
|
||||||
StringBuffer errorMsg = new StringBuffer();
|
StringBuffer errorMsg = new StringBuffer();
|
||||||
try {
|
try {
|
||||||
result.mDecryptedMessage = decryptMessageJni(aEncryptedMsg.getBytes("UTF-8"), result, errorMsg);
|
byte[] decryptedMessageBuffer = decryptMessageJni(aEncryptedMsg.getBytes("UTF-8"), result, errorMsg);
|
||||||
|
|
||||||
|
if (null != decryptedMessageBuffer) {
|
||||||
|
result.mDecryptedMessage = new String(decryptedMessageBuffer, "UTF-8");
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(LOG_TAG, "## decryptMessage() failed " + e.getMessage());
|
Log.e(LOG_TAG, "## decryptMessage() failed " + e.getMessage());
|
||||||
|
errorMsg.append(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if there is an error while decrypting
|
// check if there is an error while decrypting
|
||||||
|
@ -174,7 +185,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private native String decryptMessageJni(byte[] aEncryptedMsg, DecryptMessageResult aDecryptMessageResult, StringBuffer aErrorMsg);
|
private native byte[] decryptMessageJni(byte[] aEncryptedMsg, DecryptMessageResult aDecryptMessageResult, StringBuffer aErrorMsg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kick off the serialization mechanism.
|
* Kick off the serialization mechanism.
|
||||||
|
@ -226,9 +237,10 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
|
||||||
} else {
|
} else {
|
||||||
aErrorMsg.setLength(0);
|
aErrorMsg.setLength(0);
|
||||||
try {
|
try {
|
||||||
pickleRetValue = serializeDataWithKeyJni(aKey.getBytes("UTF-8"), aErrorMsg);
|
pickleRetValue = new String(serializeDataWithKeyJni(aKey.getBytes("UTF-8"), aErrorMsg), "UTF-8");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(LOG_TAG, "## serializeDataWithKey() failed " + e.getMessage());
|
Log.e(LOG_TAG, "## serializeDataWithKey() failed " + e.getMessage());
|
||||||
|
aErrorMsg.append(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,7 +252,7 @@ public class OlmInboundGroupSession extends CommonSerializeUtils implements Seri
|
||||||
* @param aErrorMsg error message description
|
* @param aErrorMsg error message description
|
||||||
* @return pickled base64 string if operation succeed, null otherwise
|
* @return pickled base64 string if operation succeed, null otherwise
|
||||||
*/
|
*/
|
||||||
private native String serializeDataWithKeyJni(byte[] aKey, StringBuffer aErrorMsg);
|
private native byte[] serializeDataWithKeyJni(byte[] aKey, StringBuffer aErrorMsg);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -208,10 +208,16 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
|
||||||
* @return session identifier if operation succeed, null otherwise.
|
* @return session identifier if operation succeed, null otherwise.
|
||||||
*/
|
*/
|
||||||
public String sessionIdentifier() {
|
public String sessionIdentifier() {
|
||||||
return sessionIdentifierJni();
|
try {
|
||||||
|
return new String(sessionIdentifierJni(), "UTF-8");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(LOG_TAG, "## sessionIdentifier() failed " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private native String sessionIdentifierJni();
|
private native byte[] sessionIdentifierJni();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current message index for this session.<br>
|
* Get the current message index for this session.<br>
|
||||||
|
@ -231,9 +237,16 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
|
||||||
* @return outbound session key
|
* @return outbound session key
|
||||||
*/
|
*/
|
||||||
public String sessionKey() {
|
public String sessionKey() {
|
||||||
return sessionKeyJni();
|
try {
|
||||||
|
return new String(sessionKeyJni(), "UTF-8");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(LOG_TAG, "## sessionKey() failed " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
private native String sessionKeyJni();
|
|
||||||
|
private native byte[] sessionKeyJni();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encrypt some plain-text message.<br>
|
* Encrypt some plain-text message.<br>
|
||||||
|
@ -246,7 +259,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
|
||||||
|
|
||||||
if(!TextUtils.isEmpty(aClearMsg)) {
|
if(!TextUtils.isEmpty(aClearMsg)) {
|
||||||
try {
|
try {
|
||||||
retValue = encryptMessageJni(aClearMsg.getBytes("UTF-8"));
|
retValue = new String(encryptMessageJni(aClearMsg.getBytes("UTF-8")), "UTF-8");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(LOG_TAG, "## encryptMessage() failed " + e.getMessage());
|
Log.e(LOG_TAG, "## encryptMessage() failed " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -254,7 +267,7 @@ public class OlmOutboundGroupSession extends CommonSerializeUtils implements Ser
|
||||||
|
|
||||||
return retValue;
|
return retValue;
|
||||||
}
|
}
|
||||||
private native String encryptMessageJni(byte[] aClearMsgBuffer);
|
private native byte[] encryptMessageJni(byte[] aClearMsgBuffer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true the object resources have been released.<br>
|
* Return true the object resources have been released.<br>
|
||||||
|
|
|
@ -302,10 +302,16 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
|
||||||
* @return the session ID as a String if operation succeed, null otherwise
|
* @return the session ID as a String if operation succeed, null otherwise
|
||||||
*/
|
*/
|
||||||
public String sessionIdentifier() {
|
public String sessionIdentifier() {
|
||||||
return getSessionIdentifierJni();
|
try {
|
||||||
|
return new String(getSessionIdentifierJni(), "UTF-8");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(LOG_TAG, "## sessionIdentifier(): " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private native String getSessionIdentifierJni();
|
private native byte[] getSessionIdentifierJni();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the PRE_KEY({@link OlmMessage#MESSAGE_TYPE_PRE_KEY}) message is for this in-bound session.<br>
|
* Checks if the PRE_KEY({@link OlmMessage#MESSAGE_TYPE_PRE_KEY}) message is for this in-bound session.<br>
|
||||||
|
@ -383,10 +389,16 @@ public class OlmSession extends CommonSerializeUtils implements Serializable {
|
||||||
* @return the decrypted message if operation succeed, null otherwise
|
* @return the decrypted message if operation succeed, null otherwise
|
||||||
*/
|
*/
|
||||||
public String decryptMessage(OlmMessage aEncryptedMsg) {
|
public String decryptMessage(OlmMessage aEncryptedMsg) {
|
||||||
return decryptMessageJni(aEncryptedMsg);
|
try {
|
||||||
|
return new String(decryptMessageJni(aEncryptedMsg), "UTF-8");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(LOG_TAG, "## decryptMessage(): failed " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private native String decryptMessageJni(OlmMessage aEncryptedMsg);
|
private native byte[] decryptMessageJni(OlmMessage aEncryptedMsg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true the object resources have been released.<br>
|
* Return true the object resources have been released.<br>
|
||||||
|
|
|
@ -121,7 +121,7 @@ public class OlmUtility {
|
||||||
|
|
||||||
if (null != aMessageToHash) {
|
if (null != aMessageToHash) {
|
||||||
try {
|
try {
|
||||||
hashRetValue = sha256Jni(aMessageToHash.getBytes("UTF-8"));
|
hashRetValue = new String(sha256Jni(aMessageToHash.getBytes("UTF-8")), "UTF-8");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(LOG_TAG, "## sha256(): failed " + e.getMessage());
|
Log.e(LOG_TAG, "## sha256(): failed " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ public class OlmUtility {
|
||||||
return hashRetValue;
|
return hashRetValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private native String sha256Jni(byte[] aMessage);
|
private native byte[] sha256Jni(byte[] aMessage);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -405,10 +405,10 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(markOneTimeKeysAsPublishedJni)(JNIEnv *env,
|
||||||
* @param aMessage message to sign
|
* @param aMessage message to sign
|
||||||
* @return the signed message, null otherwise
|
* @return the signed message, null otherwise
|
||||||
**/
|
**/
|
||||||
JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aMessage)
|
JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aMessage)
|
||||||
{
|
{
|
||||||
OlmAccount* accountPtr = NULL;
|
OlmAccount* accountPtr = NULL;
|
||||||
jstring signedMsgRetValue = NULL;
|
jbyteArray signedMsgRetValueBuffer = NULL;
|
||||||
|
|
||||||
if (!aMessage)
|
if (!aMessage)
|
||||||
{
|
{
|
||||||
|
@ -425,7 +425,8 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
|
||||||
|
|
||||||
// signature memory allocation
|
// signature memory allocation
|
||||||
size_t signatureLength = olm_account_signature_length(accountPtr);
|
size_t signatureLength = olm_account_signature_length(accountPtr);
|
||||||
void* signedMsgPtr = malloc((signatureLength+1)*sizeof(uint8_t));
|
size_t bufferLen = signatureLength + 1;
|
||||||
|
void* signedMsgPtr = malloc(bufferLen * sizeof(uint8_t));
|
||||||
|
|
||||||
if (!signedMsgPtr)
|
if (!signedMsgPtr)
|
||||||
{
|
{
|
||||||
|
@ -448,9 +449,12 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
|
||||||
{
|
{
|
||||||
// info: signatureLength is always equal to resultSign
|
// info: signatureLength is always equal to resultSign
|
||||||
(static_cast<char*>(signedMsgPtr))[signatureLength] = static_cast<char>('\0');
|
(static_cast<char*>(signedMsgPtr))[signatureLength] = static_cast<char>('\0');
|
||||||
// convert to jstring
|
|
||||||
signedMsgRetValue = env->NewStringUTF((const char*)signedMsgPtr); // UTF8
|
|
||||||
LOGD("## signMessageJni(): success - retCode=%lu signatureLength=%lu", static_cast<long unsigned int>(resultSign), static_cast<long unsigned int>(signatureLength));
|
LOGD("## signMessageJni(): success - retCode=%lu signatureLength=%lu", static_cast<long unsigned int>(resultSign), static_cast<long unsigned int>(signatureLength));
|
||||||
|
|
||||||
|
signedMsgRetValueBuffer = env->NewByteArray(signatureLength);
|
||||||
|
env->SetByteArrayRegion(signedMsgRetValueBuffer, 0 , signatureLength, (jbyte*)signedMsgPtr);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(signedMsgPtr);
|
free(signedMsgPtr);
|
||||||
|
@ -463,7 +467,7 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return signedMsgRetValue;
|
return signedMsgRetValueBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -472,9 +476,9 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz
|
||||||
* @param[out] aErrorMsg error message set if operation failed
|
* @param[out] aErrorMsg error message set if operation failed
|
||||||
* @return a base64 string if operation succeed, null otherwise
|
* @return a base64 string if operation succeed, null otherwise
|
||||||
**/
|
**/
|
||||||
JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
|
JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
|
||||||
{
|
{
|
||||||
jstring pickledDataRetValue = 0;
|
jbyteArray pickledDataRetValue = 0;
|
||||||
jclass errorMsgJClass = 0;
|
jclass errorMsgJClass = 0;
|
||||||
jmethodID errorMsgMethodId = 0;
|
jmethodID errorMsgMethodId = 0;
|
||||||
jstring errorJstring = 0;
|
jstring errorJstring = 0;
|
||||||
|
@ -541,8 +545,11 @@ JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, job
|
||||||
{
|
{
|
||||||
// build success output
|
// build success output
|
||||||
(static_cast<char*>(pickledPtr))[pickledLength] = static_cast<char>('\0');
|
(static_cast<char*>(pickledPtr))[pickledLength] = static_cast<char>('\0');
|
||||||
pickledDataRetValue = env->NewStringUTF((const char*)pickledPtr);
|
|
||||||
LOGD(" ## serializeDataWithKeyJni(): success - result=%lu pickled=%s", static_cast<long unsigned int>(result), static_cast<char*>(pickledPtr));
|
LOGD(" ## serializeDataWithKeyJni(): success - result=%lu pickled=%s", static_cast<long unsigned int>(result), static_cast<char*>(pickledPtr));
|
||||||
|
|
||||||
|
pickledDataRetValue = env->NewByteArray(pickledLength+1);
|
||||||
|
env->SetByteArrayRegion(pickledDataRetValue, 0 , pickledLength+1, (jbyte*)pickledPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(pickledPtr);
|
free(pickledPtr);
|
||||||
|
|
|
@ -44,10 +44,10 @@ JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(removeOneTimeKeysForSessionJni)(JNIEnv *env,
|
||||||
JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(markOneTimeKeysAsPublishedJni)(JNIEnv *env, jobject thiz);
|
JNIEXPORT jint OLM_ACCOUNT_FUNC_DEF(markOneTimeKeysAsPublishedJni)(JNIEnv *env, jobject thiz);
|
||||||
|
|
||||||
// signing
|
// signing
|
||||||
JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aMessage);
|
JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(signMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aMessage);
|
||||||
|
|
||||||
// serialization
|
// serialization
|
||||||
JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg);
|
JNIEXPORT jbyteArray OLM_ACCOUNT_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg);
|
||||||
JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer);
|
JNIEXPORT jstring OLM_ACCOUNT_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -137,10 +137,10 @@ JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSes
|
||||||
/**
|
/**
|
||||||
* Get a base64-encoded identifier for this inbound group session.
|
* Get a base64-encoded identifier for this inbound group session.
|
||||||
*/
|
*/
|
||||||
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz)
|
JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz)
|
||||||
{
|
{
|
||||||
OlmInboundGroupSession *sessionPtr = NULL;
|
OlmInboundGroupSession *sessionPtr = NULL;
|
||||||
jstring returnValueStr=0;
|
jbyteArray returnValue = 0;
|
||||||
|
|
||||||
LOGD("## sessionIdentifierJni(): inbound group session IN");
|
LOGD("## sessionIdentifierJni(): inbound group session IN");
|
||||||
|
|
||||||
|
@ -170,22 +170,26 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEn
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// update length
|
|
||||||
sessionIdPtr[result] = static_cast<char>('\0');
|
sessionIdPtr[result] = static_cast<char>('\0');
|
||||||
LOGD(" ## sessionIdentifierJni(): success - inbound group session result=%lu sessionId=%s",static_cast<long unsigned int>(result), (char*)sessionIdPtr);
|
LOGD(" ## sessionIdentifierJni(): success - inbound group session result=%lu sessionId=%s",static_cast<long unsigned int>(result), (char*)sessionIdPtr);
|
||||||
returnValueStr = env->NewStringUTF((const char*)sessionIdPtr);
|
|
||||||
|
returnValue = env->NewByteArray(result);
|
||||||
|
env->SetByteArrayRegion(returnValue, 0 , result, (jbyte*)sessionIdPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(sessionIdPtr);
|
free(sessionIdPtr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnValueStr;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aEncryptedMsgBuffer, jobject aDecryptionResult, jobject aErrorMsg)
|
JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aEncryptedMsgBuffer, jobject aDecryptionResult, jobject aErrorMsg)
|
||||||
{
|
{
|
||||||
jstring decryptedMsgRetValue = 0;
|
jbyteArray decryptedMsgBuffer = 0;
|
||||||
|
|
||||||
OlmInboundGroupSession *sessionPtr = NULL;
|
OlmInboundGroupSession *sessionPtr = NULL;
|
||||||
jbyte *encryptedMsgPtr = NULL;
|
jbyte *encryptedMsgPtr = NULL;
|
||||||
jclass indexObjJClass = 0;
|
jclass indexObjJClass = 0;
|
||||||
|
@ -298,17 +302,10 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *
|
||||||
// update index
|
// update index
|
||||||
env->SetLongField(aDecryptionResult, indexMsgFieldId, (jlong)messageIndex);
|
env->SetLongField(aDecryptionResult, indexMsgFieldId, (jlong)messageIndex);
|
||||||
|
|
||||||
// convert to utf8
|
decryptedMsgBuffer = env->NewByteArray(plaintextLength);
|
||||||
decryptedMsgRetValue = javaCStringToUtf8(env, plainTextMsgPtr, plaintextLength);
|
env->SetByteArrayRegion(decryptedMsgBuffer, 0 , plaintextLength, (jbyte*)plainTextMsgPtr);
|
||||||
|
|
||||||
if (!decryptedMsgRetValue)
|
LOGD(" ## decryptMessageJni(): UTF-8 Conversion - decrypted returnedLg=%lu OK",static_cast<long unsigned int>(plaintextLength));
|
||||||
{
|
|
||||||
LOGE(" ## decryptMessageJni(): UTF-8 Conversion failure - javaCStringToUtf8() returns null");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LOGD(" ## decryptMessageJni(): UTF-8 Conversion - decrypted returnedLg=%lu OK",static_cast<long unsigned int>(plaintextLength));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plainTextMsgPtr)
|
if (plainTextMsgPtr)
|
||||||
|
@ -330,7 +327,7 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *
|
||||||
env->ReleaseByteArrayElements(aEncryptedMsgBuffer, encryptedMsgPtr, JNI_ABORT);
|
env->ReleaseByteArrayElements(aEncryptedMsgBuffer, encryptedMsgPtr, JNI_ABORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
return decryptedMsgRetValue;
|
return decryptedMsgBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -340,9 +337,10 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *
|
||||||
* @param[out] aErrorMsg error message set if operation failed
|
* @param[out] aErrorMsg error message set if operation failed
|
||||||
* @return a base64 string if operation succeed, null otherwise
|
* @return a base64 string if operation succeed, null otherwise
|
||||||
**/
|
**/
|
||||||
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
|
JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer, jobject aErrorMsg)
|
||||||
{
|
{
|
||||||
jstring pickledDataRetValue = 0;
|
jbyteArray pickledDataRet = 0;
|
||||||
|
|
||||||
jclass errorMsgJClass = 0;
|
jclass errorMsgJClass = 0;
|
||||||
jmethodID errorMsgMethodId = 0;
|
jmethodID errorMsgMethodId = 0;
|
||||||
jbyte* keyPtr = NULL;
|
jbyte* keyPtr = NULL;
|
||||||
|
@ -408,10 +406,11 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JN
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// build success output
|
(static_cast<char*>(pickledPtr))[pickledLength] = static_cast<char>('\0');
|
||||||
(static_cast<char*>(pickledPtr))[pickledLength] = static_cast<char>('\0');
|
|
||||||
pickledDataRetValue = env->NewStringUTF((const char*)pickledPtr);
|
|
||||||
LOGD(" ## serializeDataWithKeyJni(): success - result=%lu pickled=%s", static_cast<long unsigned int>(result), static_cast<char*>(pickledPtr));
|
LOGD(" ## serializeDataWithKeyJni(): success - result=%lu pickled=%s", static_cast<long unsigned int>(result), static_cast<char*>(pickledPtr));
|
||||||
|
|
||||||
|
pickledDataRet = env->NewByteArray(pickledLength);
|
||||||
|
env->SetByteArrayRegion(pickledDataRet, 0 , pickledLength, (jbyte*)pickledPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(pickledPtr);
|
free(pickledPtr);
|
||||||
|
@ -424,7 +423,7 @@ JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JN
|
||||||
env->ReleaseByteArrayElements(aKeyBuffer, keyPtr, JNI_ABORT);
|
env->ReleaseByteArrayElements(aKeyBuffer, keyPtr, JNI_ABORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pickledDataRetValue;
|
return pickledDataRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,11 +33,11 @@ JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env
|
||||||
JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *env, jobject thiz);
|
JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *env, jobject thiz);
|
||||||
|
|
||||||
JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSessionKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aSessionKeyBuffer);
|
JNIEXPORT jint OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initInboundGroupSessionWithSessionKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aSessionKeyBuffer);
|
||||||
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz);
|
JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz);
|
||||||
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aEncryptedMsg, jobject aDecryptIndex, jobject aErrorMsg);
|
JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aEncryptedMsg, jobject aDecryptIndex, jobject aErrorMsg);
|
||||||
|
|
||||||
// serialization
|
// serialization
|
||||||
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKey, jobject aErrorMsg);
|
JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKey, jobject aErrorMsg);
|
||||||
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedData, jbyteArray aKey);
|
JNIEXPORT jstring OLM_INBOUND_GROUP_SESSION_FUNC_DEF(initWithSerializedDataJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedData, jbyteArray aKey);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,6 @@ jlong getAccountInstanceId(JNIEnv* aJniEnv, jobject aJavaObject);
|
||||||
jlong getInboundGroupSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject);
|
jlong getInboundGroupSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject);
|
||||||
jlong getOutboundGroupSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject);
|
jlong getOutboundGroupSessionInstanceId(JNIEnv* aJniEnv, jobject aJavaObject);
|
||||||
jlong getUtilityInstanceId(JNIEnv* aJniEnv, jobject aJavaObject);
|
jlong getUtilityInstanceId(JNIEnv* aJniEnv, jobject aJavaObject);
|
||||||
jstring javaCStringToUtf8(JNIEnv *env, uint8_t *aCStringMsgPtr, size_t aMsgLength);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,45 +213,3 @@ jlong getUtilityInstanceId(JNIEnv* aJniEnv, jobject aJavaObject)
|
||||||
jlong instanceId = getInstanceId(aJniEnv, aJavaObject, CLASS_OLM_UTILITY);
|
jlong instanceId = getInstanceId(aJniEnv, aJavaObject, CLASS_OLM_UTILITY);
|
||||||
return instanceId;
|
return instanceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert a C string into a UTF-8 format string.
|
|
||||||
* The conversion is performed in JAVA side to workaround the issue in NewStringUTF().
|
|
||||||
* The problem is described here: https://github.com/eclipsesource/J2V8/issues/142
|
|
||||||
*/
|
|
||||||
jstring javaCStringToUtf8(JNIEnv *env, uint8_t *aCStringMsgPtr, size_t aMsgLength)
|
|
||||||
{
|
|
||||||
jstring convertedRetValue = 0;
|
|
||||||
jbyteArray tempByteArray = NULL;
|
|
||||||
|
|
||||||
if (!aCStringMsgPtr || !env)
|
|
||||||
{
|
|
||||||
LOGE("## javaCStringToUtf8(): failure - invalid parameters (null)");
|
|
||||||
}
|
|
||||||
else if (!(tempByteArray = env->NewByteArray(aMsgLength)))
|
|
||||||
{
|
|
||||||
LOGE("## javaCStringToUtf8(): failure - return byte array OOM");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
env->SetByteArrayRegion(tempByteArray, 0, aMsgLength, (const jbyte*)aCStringMsgPtr);
|
|
||||||
|
|
||||||
// UTF-8 conversion from JAVA
|
|
||||||
jstring strEncode = (env)->NewStringUTF("UTF-8");
|
|
||||||
jclass jClass = env->FindClass("java/lang/String");
|
|
||||||
jmethodID cstor = env->GetMethodID(jClass, "<init>", "([BLjava/lang/String;)V");
|
|
||||||
|
|
||||||
if (jClass && strEncode)
|
|
||||||
{
|
|
||||||
convertedRetValue = (jstring) env->NewObject(jClass, cstor, tempByteArray, strEncode);
|
|
||||||
LOGD(" ## javaCStringToUtf8(): succeed");
|
|
||||||
env->DeleteLocalRef(tempByteArray);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LOGE(" ## javaCStringToUtf8(): failure - invalid Java references");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return convertedRetValue;
|
|
||||||
}
|
|
||||||
|
|
|
@ -138,11 +138,12 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(
|
||||||
/**
|
/**
|
||||||
* Get a base64-encoded identifier for this outbound group session.
|
* Get a base64-encoded identifier for this outbound group session.
|
||||||
*/
|
*/
|
||||||
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz)
|
JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz)
|
||||||
{
|
{
|
||||||
LOGD("## sessionIdentifierJni(): outbound group session IN");
|
LOGD("## sessionIdentifierJni(): outbound group session IN");
|
||||||
|
|
||||||
OlmOutboundGroupSession *sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz);
|
OlmOutboundGroupSession *sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz);
|
||||||
jstring returnValueStr=0;
|
jbyteArray returnValue = 0;
|
||||||
|
|
||||||
if (!sessionPtr)
|
if (!sessionPtr)
|
||||||
{
|
{
|
||||||
|
@ -172,8 +173,11 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIE
|
||||||
{
|
{
|
||||||
// update length
|
// update length
|
||||||
sessionIdPtr[result] = static_cast<char>('\0');
|
sessionIdPtr[result] = static_cast<char>('\0');
|
||||||
|
|
||||||
|
returnValue = env->NewByteArray(result);
|
||||||
|
env->SetByteArrayRegion(returnValue, 0 , result, (jbyte*)sessionIdPtr);
|
||||||
|
|
||||||
LOGD(" ## sessionIdentifierJni(): success - outbound group session identifier result=%lu sessionId=%s",static_cast<long unsigned int>(result), reinterpret_cast<char*>(sessionIdPtr));
|
LOGD(" ## sessionIdentifierJni(): success - outbound group session identifier result=%lu sessionId=%s",static_cast<long unsigned int>(result), reinterpret_cast<char*>(sessionIdPtr));
|
||||||
returnValueStr = env->NewStringUTF((const char*)sessionIdPtr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// free alloc
|
// free alloc
|
||||||
|
@ -181,7 +185,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnValueStr;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -215,11 +219,12 @@ JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(messageIndexJni)(JNIEnv *env,
|
||||||
/**
|
/**
|
||||||
* Get the base64-encoded current ratchet key for this session.<br>
|
* Get the base64-encoded current ratchet key for this session.<br>
|
||||||
*/
|
*/
|
||||||
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *env, jobject thiz)
|
JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *env, jobject thiz)
|
||||||
{
|
{
|
||||||
LOGD("## sessionKeyJni(): outbound group session IN");
|
LOGD("## sessionKeyJni(): outbound group session IN");
|
||||||
|
|
||||||
OlmOutboundGroupSession *sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz);
|
OlmOutboundGroupSession *sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz);
|
||||||
jstring returnValueStr = 0;
|
jbyteArray returnValue = 0;
|
||||||
|
|
||||||
if (!sessionPtr)
|
if (!sessionPtr)
|
||||||
{
|
{
|
||||||
|
@ -250,7 +255,9 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *env
|
||||||
// update length
|
// update length
|
||||||
sessionKeyPtr[result] = static_cast<char>('\0');
|
sessionKeyPtr[result] = static_cast<char>('\0');
|
||||||
LOGD(" ## sessionKeyJni(): success - outbound group session key result=%lu sessionKey=%s",static_cast<long unsigned int>(result), reinterpret_cast<char*>(sessionKeyPtr));
|
LOGD(" ## sessionKeyJni(): success - outbound group session key result=%lu sessionKey=%s",static_cast<long unsigned int>(result), reinterpret_cast<char*>(sessionKeyPtr));
|
||||||
returnValueStr = env->NewStringUTF((const char*)sessionKeyPtr);
|
|
||||||
|
returnValue = env->NewByteArray(result);
|
||||||
|
env->SetByteArrayRegion(returnValue, 0 , result, (jbyte*)sessionKeyPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// free alloc
|
// free alloc
|
||||||
|
@ -258,15 +265,15 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *env
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnValueStr;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aClearMsgBuffer)
|
||||||
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aClearMsgBuffer)
|
|
||||||
{
|
{
|
||||||
LOGD("## encryptMessageJni(): IN");
|
LOGD("## encryptMessageJni(): IN");
|
||||||
|
|
||||||
jstring encryptedMsgRetValue = 0;
|
jbyteArray encryptedMsgRet = 0;
|
||||||
|
|
||||||
OlmOutboundGroupSession *sessionPtr = NULL;
|
OlmOutboundGroupSession *sessionPtr = NULL;
|
||||||
jbyte* clearMsgPtr = NULL;
|
jbyte* clearMsgPtr = NULL;
|
||||||
|
|
||||||
|
@ -315,7 +322,9 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv
|
||||||
encryptedMsgPtr[encryptedLength] = static_cast<char>('\0');
|
encryptedMsgPtr[encryptedLength] = static_cast<char>('\0');
|
||||||
|
|
||||||
LOGD(" ## encryptMessageJni(): encrypted returnedLg=%lu plainTextMsgPtr=%s",static_cast<long unsigned int>(encryptedLength), reinterpret_cast<char*>(encryptedMsgPtr));
|
LOGD(" ## encryptMessageJni(): encrypted returnedLg=%lu plainTextMsgPtr=%s",static_cast<long unsigned int>(encryptedLength), reinterpret_cast<char*>(encryptedMsgPtr));
|
||||||
encryptedMsgRetValue = env->NewStringUTF((const char*)encryptedMsgPtr);
|
|
||||||
|
encryptedMsgRet = env->NewByteArray(encryptedLength);
|
||||||
|
env->SetByteArrayRegion(encryptedMsgRet, 0 , encryptedLength, (jbyte*)encryptedMsgPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(encryptedMsgPtr);
|
free(encryptedMsgPtr);
|
||||||
|
@ -328,7 +337,7 @@ JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv
|
||||||
env->ReleaseByteArrayElements(aClearMsgBuffer, clearMsgPtr, JNI_ABORT);
|
env->ReleaseByteArrayElements(aClearMsgBuffer, clearMsgPtr, JNI_ABORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
return encryptedMsgRetValue;
|
return encryptedMsgRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -33,11 +33,11 @@ JNIEXPORT void OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *en
|
||||||
JNIEXPORT jlong OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *env, jobject thiz);
|
JNIEXPORT jlong OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *env, jobject thiz);
|
||||||
|
|
||||||
JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(JNIEnv *env, jobject thiz);
|
JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(initOutboundGroupSessionJni)(JNIEnv *env, jobject thiz);
|
||||||
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz);
|
JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz);
|
||||||
JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(messageIndexJni)(JNIEnv *env, jobject thiz);
|
JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(messageIndexJni)(JNIEnv *env, jobject thiz);
|
||||||
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *env, jobject thiz);
|
JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *env, jobject thiz);
|
||||||
|
|
||||||
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aClearMsgBuffer);
|
JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aClearMsgBuffer);
|
||||||
|
|
||||||
// serialization
|
// serialization
|
||||||
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKey, jobject aErrorMsg);
|
JNIEXPORT jstring OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKey, jobject aErrorMsg);
|
||||||
|
|
|
@ -580,9 +580,10 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz
|
||||||
* @param aEncryptedMsg message to decrypt
|
* @param aEncryptedMsg message to decrypt
|
||||||
* @return decrypted message if operation succeed, null otherwise
|
* @return decrypted message if operation succeed, null otherwise
|
||||||
*/
|
*/
|
||||||
JNIEXPORT jstring OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jobject aEncryptedMsg)
|
JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jobject aEncryptedMsg)
|
||||||
{
|
{
|
||||||
jstring decryptedMsgRetValue = 0;
|
jbyteArray decryptedMsgRet = 0;
|
||||||
|
|
||||||
jclass encryptedMsgJClass = 0;
|
jclass encryptedMsgJClass = 0;
|
||||||
jstring encryptedMsgJstring = 0; // <= obtained from encryptedMsgFieldId
|
jstring encryptedMsgJstring = 0; // <= obtained from encryptedMsgFieldId
|
||||||
// field IDs
|
// field IDs
|
||||||
|
@ -668,16 +669,10 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject t
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
decryptedMsgRetValue = javaCStringToUtf8(env, plainTextMsgPtr, plaintextLength);
|
decryptedMsgRet = env->NewByteArray(plaintextLength);
|
||||||
|
env->SetByteArrayRegion(decryptedMsgRet, 0 , plaintextLength, (jbyte*)plainTextMsgPtr);
|
||||||
|
|
||||||
if (!decryptedMsgRetValue)
|
LOGD(" ## decryptMessageJni(): UTF-8 Conversion - decrypted returnedLg=%lu OK",static_cast<long unsigned int>(plaintextLength));
|
||||||
{
|
|
||||||
LOGE(" ## decryptMessageJni(): UTF-8 Conversion failure - javaCStringToUtf8() returns null");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LOGD(" ## decryptMessageJni(): UTF-8 Conversion - decrypted returnedLg=%lu OK",static_cast<long unsigned int>(plaintextLength));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -698,7 +693,7 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject t
|
||||||
free(plainTextMsgPtr);
|
free(plainTextMsgPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return decryptedMsgRetValue;
|
return decryptedMsgRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -706,9 +701,9 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject t
|
||||||
* Get the session identifier for this session.
|
* Get the session identifier for this session.
|
||||||
* @return the session identifier if operation succeed, null otherwise
|
* @return the session identifier if operation succeed, null otherwise
|
||||||
*/
|
*/
|
||||||
JNIEXPORT jstring OLM_SESSION_FUNC_DEF(getSessionIdentifierJni)(JNIEnv *env, jobject thiz)
|
JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(getSessionIdentifierJni)(JNIEnv *env, jobject thiz)
|
||||||
{
|
{
|
||||||
jstring returnValueStr=0;
|
jbyteArray returnValue = 0;
|
||||||
|
|
||||||
LOGD("## getSessionIdentifierJni(): IN ");
|
LOGD("## getSessionIdentifierJni(): IN ");
|
||||||
|
|
||||||
|
@ -744,13 +739,16 @@ JNIEXPORT jstring OLM_SESSION_FUNC_DEF(getSessionIdentifierJni)(JNIEnv *env, job
|
||||||
(static_cast<char*>(sessionIdPtr))[result] = static_cast<char>('\0');
|
(static_cast<char*>(sessionIdPtr))[result] = static_cast<char>('\0');
|
||||||
|
|
||||||
LOGD("## getSessionIdentifierJni(): success - result=%lu sessionId=%s",static_cast<long unsigned int>(result), (char*)sessionIdPtr);
|
LOGD("## getSessionIdentifierJni(): success - result=%lu sessionId=%s",static_cast<long unsigned int>(result), (char*)sessionIdPtr);
|
||||||
returnValueStr = env->NewStringUTF((const char*)sessionIdPtr);
|
|
||||||
|
returnValue = env->NewByteArray(result);
|
||||||
|
env->SetByteArrayRegion(returnValue, 0 , result, (jbyte*)sessionIdPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(sessionIdPtr);
|
free(sessionIdPtr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return returnValueStr;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -45,9 +45,9 @@ JNIEXPORT jint OLM_SESSION_FUNC_DEF(matchesInboundSessionFromIdKeyJni)(JNIEnv *e
|
||||||
|
|
||||||
// encrypt/decrypt
|
// encrypt/decrypt
|
||||||
JNIEXPORT jint OLM_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aClearMsg, jobject aEncryptedMsg);
|
JNIEXPORT jint OLM_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aClearMsg, jobject aEncryptedMsg);
|
||||||
JNIEXPORT jstring OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jobject aEncryptedMsg);
|
JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jobject aEncryptedMsg);
|
||||||
|
|
||||||
JNIEXPORT jstring OLM_SESSION_FUNC_DEF(getSessionIdentifierJni)(JNIEnv *env, jobject thiz);
|
JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(getSessionIdentifierJni)(JNIEnv *env, jobject thiz);
|
||||||
|
|
||||||
// serialization
|
// serialization
|
||||||
JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKey, jobject aErrorMsg);
|
JNIEXPORT jstring OLM_SESSION_FUNC_DEF(serializeDataWithKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aKey, jobject aErrorMsg);
|
||||||
|
|
|
@ -166,9 +166,10 @@ JNIEXPORT jstring OLM_UTILITY_FUNC_DEF(verifyEd25519SignatureJni)(JNIEnv *env, j
|
||||||
* @param aMessage
|
* @param aMessage
|
||||||
* @return digest of the message if operation succeed, null otherwise
|
* @return digest of the message if operation succeed, null otherwise
|
||||||
**/
|
**/
|
||||||
JNIEXPORT jstring OLM_UTILITY_FUNC_DEF(sha256Jni)(JNIEnv *env, jobject thiz, jbyteArray aMessageToHashBuffer)
|
JNIEXPORT jbyteArray OLM_UTILITY_FUNC_DEF(sha256Jni)(JNIEnv *env, jobject thiz, jbyteArray aMessageToHashBuffer)
|
||||||
{
|
{
|
||||||
jstring sha256RetValue = 0;
|
jbyteArray sha256Ret = 0;
|
||||||
|
|
||||||
OlmUtility* utilityPtr = NULL;
|
OlmUtility* utilityPtr = NULL;
|
||||||
jbyte* messagePtr = NULL;
|
jbyte* messagePtr = NULL;
|
||||||
|
|
||||||
|
@ -212,9 +213,10 @@ JNIEXPORT jstring OLM_UTILITY_FUNC_DEF(sha256Jni)(JNIEnv *env, jobject thiz, jby
|
||||||
{
|
{
|
||||||
// update length
|
// update length
|
||||||
(static_cast<char*>(hashValuePtr))[result] = static_cast<char>('\0');
|
(static_cast<char*>(hashValuePtr))[result] = static_cast<char>('\0');
|
||||||
|
|
||||||
LOGD("## sha256Jni(): success - result=%lu hashValue=%s",static_cast<long unsigned int>(result), (char*)hashValuePtr);
|
LOGD("## sha256Jni(): success - result=%lu hashValue=%s",static_cast<long unsigned int>(result), (char*)hashValuePtr);
|
||||||
sha256RetValue = env->NewStringUTF((const char*)hashValuePtr);
|
|
||||||
|
sha256Ret = env->NewByteArray(result);
|
||||||
|
env->SetByteArrayRegion(sha256Ret, 0 , result, (jbyte*)hashValuePtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(hashValuePtr);
|
free(hashValuePtr);
|
||||||
|
@ -226,5 +228,5 @@ JNIEXPORT jstring OLM_UTILITY_FUNC_DEF(sha256Jni)(JNIEnv *env, jobject thiz, jby
|
||||||
env->ReleaseByteArrayElements(aMessageToHashBuffer, messagePtr, JNI_ABORT);
|
env->ReleaseByteArrayElements(aMessageToHashBuffer, messagePtr, JNI_ABORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sha256RetValue;
|
return sha256Ret;
|
||||||
}
|
}
|
|
@ -30,7 +30,7 @@ extern "C" {
|
||||||
JNIEXPORT jlong OLM_UTILITY_FUNC_DEF(initUtilityJni)(JNIEnv *env, jobject thiz);
|
JNIEXPORT jlong OLM_UTILITY_FUNC_DEF(initUtilityJni)(JNIEnv *env, jobject thiz);
|
||||||
JNIEXPORT void OLM_UTILITY_FUNC_DEF(releaseUtilityJni)(JNIEnv *env, jobject thiz);
|
JNIEXPORT void OLM_UTILITY_FUNC_DEF(releaseUtilityJni)(JNIEnv *env, jobject thiz);
|
||||||
JNIEXPORT jstring OLM_UTILITY_FUNC_DEF(verifyEd25519SignatureJni)(JNIEnv *env, jobject thiz, jbyteArray aSignature, jbyteArray aKey, jbyteArray aMessage);
|
JNIEXPORT jstring OLM_UTILITY_FUNC_DEF(verifyEd25519SignatureJni)(JNIEnv *env, jobject thiz, jbyteArray aSignature, jbyteArray aKey, jbyteArray aMessage);
|
||||||
JNIEXPORT jstring OLM_UTILITY_FUNC_DEF(sha256Jni)(JNIEnv *env, jobject thiz, jbyteArray aMessageToHash);
|
JNIEXPORT jbyteArray OLM_UTILITY_FUNC_DEF(sha256Jni)(JNIEnv *env, jobject thiz, jbyteArray aMessageToHash);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue