ruby_olm 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/ext/ruby_olm/ext_lib_olm/ext_account.c +274 -0
- data/ext/ruby_olm/ext_lib_olm/ext_lib_olm.c +51 -0
- data/ext/ruby_olm/ext_lib_olm/ext_lib_olm.h +13 -0
- data/ext/ruby_olm/ext_lib_olm/ext_session.c +363 -0
- data/ext/ruby_olm/ext_lib_olm/ext_utility.c +69 -0
- data/ext/ruby_olm/ext_lib_olm/extconf.rb +69 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_account.cpp +695 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_account.h +56 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_inbound_group_session.cpp +654 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_inbound_group_session.h +51 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_jni.h +81 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_jni_helper.cpp +224 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_jni_helper.h +30 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_manager.cpp +35 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_manager.h +36 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_outbound_group_session.cpp +563 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_outbound_group_session.h +49 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_pk.cpp +716 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_pk.h +48 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_session.cpp +977 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_session.h +59 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_utility.cpp +236 -0
- data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_utility.h +40 -0
- data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_decode_message.cpp +14 -0
- data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_decrypt.cpp +65 -0
- data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_group_decrypt.cpp +73 -0
- data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_unpickle_account.cpp +14 -0
- data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_unpickle_session.cpp +14 -0
- data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/include/fuzzing.hh +82 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/account.hh +160 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/base64.h +77 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/base64.hh +63 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/cipher.h +138 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/crypto.h +202 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/error.h +72 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/inbound_group_session.h +235 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/list.hh +119 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/megolm.h +95 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/memory.h +41 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/memory.hh +90 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/message.h +93 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/message.hh +138 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/olm.h +451 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/olm.hh +4 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/outbound_group_session.h +181 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/pickle.h +90 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/pickle.hh +149 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/pickle_encoding.h +76 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/pk.h +214 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/ratchet.hh +184 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/session.hh +156 -0
- data/ext/ruby_olm/ext_lib_olm/olm/include/olm/utility.hh +61 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/aes.c +1073 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/aes.h +123 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/aes_test.c +276 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/arcfour.c +45 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/arcfour.h +30 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/arcfour_test.c +47 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/base64.c +135 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/base64.h +27 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/base64_test.c +54 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/blowfish.c +269 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/blowfish.h +32 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/blowfish_test.c +68 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/des.c +269 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/des.h +37 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/des_test.c +83 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md2.c +104 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md2.h +33 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md2_test.c +58 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md5.c +189 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md5.h +34 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md5_test.c +60 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/rot-13.c +35 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/rot-13.h +20 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/rot-13_test.c +44 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha1.c +149 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha1.h +35 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha1_test.c +58 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha256.c +159 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha256.h +34 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha256_test.c +61 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/contrib/Curve25519Donna.c +118 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/contrib/Curve25519Donna.h +53 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/curve25519-donna-c64.c +449 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/curve25519-donna.c +860 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/python-src/curve25519/curve25519module.c +105 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/speed-curve25519.c +50 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/test-curve25519.c +54 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/test-noncanon.c +39 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/test-sc-curve25519.c +72 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna.h +18 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/add_scalar.c +56 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/ed25519.h +38 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/fe.c +1493 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/fe.h +41 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/fixedint.h +72 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/ge.c +467 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/ge.h +74 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/key_exchange.c +79 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/keypair.c +16 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/precomp_data.h +1391 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sc.c +814 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sc.h +12 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/seed.c +40 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sha512.c +275 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sha512.h +21 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sign.c +31 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/verify.c +77 -0
- data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/test.c +150 -0
- data/ext/ruby_olm/ext_lib_olm/olm/python/dummy/stddef.h +0 -0
- data/ext/ruby_olm/ext_lib_olm/olm/python/dummy/stdint.h +0 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/account.cpp +380 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/base64.cpp +167 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/cipher.cpp +152 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/crypto.cpp +299 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/ed25519.c +22 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/error.c +44 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/inbound_group_session.c +524 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/megolm.c +150 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/memory.cpp +45 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/message.cpp +401 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/olm.cpp +738 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/outbound_group_session.c +363 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/pickle.cpp +242 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/pickle_encoding.c +92 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/pk.cpp +412 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/ratchet.cpp +625 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/session.cpp +462 -0
- data/ext/ruby_olm/ext_lib_olm/olm/src/utility.cpp +57 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/include/unittest.hh +107 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_base64.cpp +70 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_crypto.cpp +246 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_group_session.cpp +329 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_list.cpp +92 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_megolm.cpp +134 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_message.cpp +112 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm.cpp +405 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm_decrypt.cpp +90 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm_sha256.cpp +20 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm_signature.cpp +81 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm_using_malloc.cpp +210 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_pk.cpp +166 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_ratchet.cpp +221 -0
- data/ext/ruby_olm/ext_lib_olm/olm/tests/test_session.cpp +144 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMAccount.h +51 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMAccount_Private.h +25 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMInboundGroupSession.h +38 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMKit.h +37 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMMessage.h +38 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMOutboundGroupSession.h +32 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMPkDecryption.h +71 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMPkEncryption.h +42 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMPkMessage.h +31 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMSerializable.h +29 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMSession.h +44 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMSession_Private.h +26 -0
- data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMUtility.h +49 -0
- data/ext/ruby_olm/ext_lib_olm/staging/account.cpp +380 -0
- data/ext/ruby_olm/ext_lib_olm/staging/aes.c +1073 -0
- data/ext/ruby_olm/ext_lib_olm/staging/base64.cpp +167 -0
- data/ext/ruby_olm/ext_lib_olm/staging/cipher.cpp +152 -0
- data/ext/ruby_olm/ext_lib_olm/staging/crypto.cpp +299 -0
- data/ext/ruby_olm/ext_lib_olm/staging/curve25519-donna.c +860 -0
- data/ext/ruby_olm/ext_lib_olm/staging/ed25519.c +22 -0
- data/ext/ruby_olm/ext_lib_olm/staging/error.c +44 -0
- data/ext/ruby_olm/ext_lib_olm/staging/inbound_group_session.c +524 -0
- data/ext/ruby_olm/ext_lib_olm/staging/megolm.c +150 -0
- data/ext/ruby_olm/ext_lib_olm/staging/memory.cpp +45 -0
- data/ext/ruby_olm/ext_lib_olm/staging/message.cpp +401 -0
- data/ext/ruby_olm/ext_lib_olm/staging/olm.cpp +738 -0
- data/ext/ruby_olm/ext_lib_olm/staging/outbound_group_session.c +363 -0
- data/ext/ruby_olm/ext_lib_olm/staging/pickle.cpp +242 -0
- data/ext/ruby_olm/ext_lib_olm/staging/pickle_encoding.c +92 -0
- data/ext/ruby_olm/ext_lib_olm/staging/pk.cpp +412 -0
- data/ext/ruby_olm/ext_lib_olm/staging/ratchet.cpp +625 -0
- data/ext/ruby_olm/ext_lib_olm/staging/session.cpp +461 -0
- data/ext/ruby_olm/ext_lib_olm/staging/sha256.c +159 -0
- data/ext/ruby_olm/ext_lib_olm/staging/utility.cpp +57 -0
- data/lib/ruby_olm/account.rb +42 -0
- data/lib/ruby_olm/message.rb +6 -0
- data/lib/ruby_olm/olm_error.rb +70 -0
- data/lib/ruby_olm/olm_message.rb +25 -0
- data/lib/ruby_olm/pre_key_message.rb +6 -0
- data/lib/ruby_olm/session.rb +16 -0
- data/lib/ruby_olm/version.rb +5 -0
- data/lib/ruby_olm.rb +10 -0
- data/rakefile +18 -0
- data/test/examples/test_bob_no_answer.rb +62 -0
- data/test/examples/test_exchange.rb +60 -0
- data/test/spec/test_account.rb +152 -0
- data/test/unit/test_account_methods.rb +85 -0
- metadata +282 -0
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2016 OpenMarket Ltd
|
|
3
|
+
* Copyright 2016 Vector Creations Ltd
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#include "olm_outbound_group_session.h"
|
|
19
|
+
|
|
20
|
+
using namespace AndroidOlmSdk;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Release the session allocation made by initializeOutboundGroupSessionMemory().<br>
|
|
24
|
+
* This method MUST be called when java counter part account instance is done.
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
JNIEXPORT void OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz)
|
|
28
|
+
{
|
|
29
|
+
LOGD("## releaseSessionJni(): OutBound group session IN");
|
|
30
|
+
|
|
31
|
+
OlmOutboundGroupSession* sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz);
|
|
32
|
+
|
|
33
|
+
if (!sessionPtr)
|
|
34
|
+
{
|
|
35
|
+
LOGE(" ## releaseSessionJni(): failure - invalid outbound group session instance");
|
|
36
|
+
}
|
|
37
|
+
else
|
|
38
|
+
{
|
|
39
|
+
LOGD(" ## releaseSessionJni(): sessionPtr=%p",sessionPtr);
|
|
40
|
+
|
|
41
|
+
#ifdef ENABLE_JNI_LOG
|
|
42
|
+
size_t retCode = olm_clear_outbound_group_session(sessionPtr);
|
|
43
|
+
LOGD(" ## releaseSessionJni(): clear_outbound_group_session=%lu",static_cast<long unsigned int>(retCode));
|
|
44
|
+
#else
|
|
45
|
+
olm_clear_outbound_group_session(sessionPtr);
|
|
46
|
+
#endif
|
|
47
|
+
|
|
48
|
+
LOGD(" ## releaseSessionJni(): free IN");
|
|
49
|
+
free(sessionPtr);
|
|
50
|
+
LOGD(" ## releaseSessionJni(): free OUT");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Initialize a new outbound group session and return it to JAVA side.<br>
|
|
56
|
+
* Since a C prt is returned as a jlong, special care will be taken
|
|
57
|
+
* to make the cast (OlmOutboundGroupSession* => jlong) platform independent.
|
|
58
|
+
* @return the initialized OlmOutboundGroupSession* instance or throw an exception
|
|
59
|
+
**/
|
|
60
|
+
JNIEXPORT jlong OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *env, jobject thiz)
|
|
61
|
+
{
|
|
62
|
+
const char* errorMessage = NULL;
|
|
63
|
+
|
|
64
|
+
OlmOutboundGroupSession* sessionPtr = NULL;
|
|
65
|
+
size_t sessionSize = 0;
|
|
66
|
+
|
|
67
|
+
LOGD("## createNewSessionJni(): outbound group session IN");
|
|
68
|
+
sessionSize = olm_outbound_group_session_size();
|
|
69
|
+
|
|
70
|
+
if (0 == sessionSize)
|
|
71
|
+
{
|
|
72
|
+
LOGE(" ## createNewSessionJni(): failure - outbound group session size = 0");
|
|
73
|
+
errorMessage = "outbound group session size = 0";
|
|
74
|
+
}
|
|
75
|
+
else if (!(sessionPtr = (OlmOutboundGroupSession*)malloc(sessionSize)))
|
|
76
|
+
{
|
|
77
|
+
LOGE(" ## createNewSessionJni(): failure - outbound group session OOM");
|
|
78
|
+
errorMessage = "outbound group session OOM";
|
|
79
|
+
}
|
|
80
|
+
else
|
|
81
|
+
{
|
|
82
|
+
sessionPtr = olm_outbound_group_session(sessionPtr);
|
|
83
|
+
LOGD(" ## createNewSessionJni(): success - outbound group session size=%lu",static_cast<long unsigned int>(sessionSize));
|
|
84
|
+
|
|
85
|
+
// compute random buffer
|
|
86
|
+
size_t randomLength = olm_init_outbound_group_session_random_length(sessionPtr);
|
|
87
|
+
uint8_t *randomBuffPtr = NULL;
|
|
88
|
+
|
|
89
|
+
LOGW(" ## createNewSessionJni(): randomLength=%lu",static_cast<long unsigned int>(randomLength));
|
|
90
|
+
|
|
91
|
+
if ((0 != randomLength) && !setRandomInBuffer(env, &randomBuffPtr, randomLength))
|
|
92
|
+
{
|
|
93
|
+
LOGE(" ## createNewSessionJni(): failure - random buffer init");
|
|
94
|
+
errorMessage = "random buffer init";
|
|
95
|
+
}
|
|
96
|
+
else
|
|
97
|
+
{
|
|
98
|
+
if (0 == randomLength)
|
|
99
|
+
{
|
|
100
|
+
LOGW(" ## createNewSessionJni(): random buffer is not required");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
size_t sessionResult = olm_init_outbound_group_session(sessionPtr, randomBuffPtr, randomLength);
|
|
104
|
+
|
|
105
|
+
if (sessionResult == olm_error()) {
|
|
106
|
+
errorMessage = (const char *)olm_outbound_group_session_last_error(sessionPtr);
|
|
107
|
+
LOGE(" ## createNewSessionJni(): failure - init outbound session creation Msg=%s", errorMessage);
|
|
108
|
+
}
|
|
109
|
+
else
|
|
110
|
+
{
|
|
111
|
+
LOGD(" ## createNewSessionJni(): success - result=%lu", static_cast<long unsigned int>(sessionResult));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// clear the random buffer
|
|
115
|
+
memset(randomBuffPtr, 0, randomLength);
|
|
116
|
+
free(randomBuffPtr);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (errorMessage)
|
|
121
|
+
{
|
|
122
|
+
if (sessionPtr)
|
|
123
|
+
{
|
|
124
|
+
olm_clear_outbound_group_session(sessionPtr);
|
|
125
|
+
free(sessionPtr);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return (jlong)(intptr_t)sessionPtr;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Return the session identifier.
|
|
136
|
+
* An exception is thrown if the operation fails.
|
|
137
|
+
* @return the session identifier
|
|
138
|
+
*/
|
|
139
|
+
JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz)
|
|
140
|
+
{
|
|
141
|
+
LOGD("## sessionIdentifierJni(): outbound group session IN");
|
|
142
|
+
|
|
143
|
+
const char* errorMessage = NULL;
|
|
144
|
+
OlmOutboundGroupSession *sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz);
|
|
145
|
+
jbyteArray returnValue = 0;
|
|
146
|
+
|
|
147
|
+
if (!sessionPtr)
|
|
148
|
+
{
|
|
149
|
+
LOGE(" ## sessionIdentifierJni(): failure - invalid outbound group session instance");
|
|
150
|
+
errorMessage = "invalid outbound group session instance";
|
|
151
|
+
}
|
|
152
|
+
else
|
|
153
|
+
{
|
|
154
|
+
// get the size to alloc
|
|
155
|
+
size_t lengthSessionId = olm_outbound_group_session_id_length(sessionPtr);
|
|
156
|
+
LOGD(" ## sessionIdentifierJni(): outbound group session lengthSessionId=%lu",static_cast<long unsigned int>(lengthSessionId));
|
|
157
|
+
|
|
158
|
+
uint8_t *sessionIdPtr = (uint8_t*)malloc(lengthSessionId*sizeof(uint8_t));
|
|
159
|
+
|
|
160
|
+
if (!sessionIdPtr)
|
|
161
|
+
{
|
|
162
|
+
LOGE(" ## sessionIdentifierJni(): failure - outbound identifier allocation OOM");
|
|
163
|
+
errorMessage = "outbound identifier allocation OOM";
|
|
164
|
+
}
|
|
165
|
+
else
|
|
166
|
+
{
|
|
167
|
+
size_t result = olm_outbound_group_session_id(sessionPtr, sessionIdPtr, lengthSessionId);
|
|
168
|
+
|
|
169
|
+
if (result == olm_error())
|
|
170
|
+
{
|
|
171
|
+
errorMessage = reinterpret_cast<const char*>(olm_outbound_group_session_last_error(sessionPtr));
|
|
172
|
+
LOGE(" ## sessionIdentifierJni(): failure - outbound group session identifier failure Msg=%s", errorMessage);
|
|
173
|
+
}
|
|
174
|
+
else
|
|
175
|
+
{
|
|
176
|
+
returnValue = env->NewByteArray(result);
|
|
177
|
+
env->SetByteArrayRegion(returnValue, 0 , result, (jbyte*)sessionIdPtr);
|
|
178
|
+
|
|
179
|
+
LOGD(" ## sessionIdentifierJni(): success - outbound group session identifier result=%lu sessionId= %.*s",static_cast<long unsigned int>(result), static_cast<int>(result), reinterpret_cast<char*>(sessionIdPtr));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// free alloc
|
|
183
|
+
free(sessionIdPtr);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (errorMessage)
|
|
188
|
+
{
|
|
189
|
+
env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return returnValue;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Get the current message index for this session.<br>
|
|
198
|
+
* Each message is sent with an increasing index, this
|
|
199
|
+
* method returns the index for the next message.
|
|
200
|
+
* An exception is thrown if the operation fails.
|
|
201
|
+
* @return current session index
|
|
202
|
+
*/
|
|
203
|
+
JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(messageIndexJni)(JNIEnv *env, jobject thiz)
|
|
204
|
+
{
|
|
205
|
+
OlmOutboundGroupSession *sessionPtr = NULL;
|
|
206
|
+
jint indexRetValue = 0;
|
|
207
|
+
|
|
208
|
+
LOGD("## messageIndexJni(): IN");
|
|
209
|
+
|
|
210
|
+
if (!(sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
|
|
211
|
+
{
|
|
212
|
+
LOGE(" ## messageIndexJni(): failure - invalid outbound group session instance");
|
|
213
|
+
}
|
|
214
|
+
else
|
|
215
|
+
{
|
|
216
|
+
indexRetValue = static_cast<jint>(olm_outbound_group_session_message_index(sessionPtr));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
LOGD(" ## messageIndexJni(): success - index=%d",indexRetValue);
|
|
220
|
+
|
|
221
|
+
return indexRetValue;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Return the session key.
|
|
226
|
+
* An exception is thrown if the operation fails.
|
|
227
|
+
* @return the session key
|
|
228
|
+
*/
|
|
229
|
+
JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *env, jobject thiz)
|
|
230
|
+
{
|
|
231
|
+
LOGD("## sessionKeyJni(): outbound group session IN");
|
|
232
|
+
|
|
233
|
+
const char* errorMessage = NULL;
|
|
234
|
+
OlmOutboundGroupSession *sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz);
|
|
235
|
+
jbyteArray returnValue = 0;
|
|
236
|
+
|
|
237
|
+
if (!sessionPtr)
|
|
238
|
+
{
|
|
239
|
+
LOGE(" ## sessionKeyJni(): failure - invalid outbound group session instance");
|
|
240
|
+
errorMessage = "invalid outbound group session instance";
|
|
241
|
+
}
|
|
242
|
+
else
|
|
243
|
+
{
|
|
244
|
+
// get the size to alloc
|
|
245
|
+
size_t sessionKeyLength = olm_outbound_group_session_key_length(sessionPtr);
|
|
246
|
+
LOGD(" ## sessionKeyJni(): sessionKeyLength=%lu",static_cast<long unsigned int>(sessionKeyLength));
|
|
247
|
+
|
|
248
|
+
uint8_t *sessionKeyPtr = (uint8_t*)malloc(sessionKeyLength*sizeof(uint8_t));
|
|
249
|
+
|
|
250
|
+
if (!sessionKeyPtr)
|
|
251
|
+
{
|
|
252
|
+
LOGE(" ## sessionKeyJni(): failure - session key allocation OOM");
|
|
253
|
+
errorMessage = "session key allocation OOM";
|
|
254
|
+
}
|
|
255
|
+
else
|
|
256
|
+
{
|
|
257
|
+
size_t result = olm_outbound_group_session_key(sessionPtr, sessionKeyPtr, sessionKeyLength);
|
|
258
|
+
|
|
259
|
+
if (result == olm_error())
|
|
260
|
+
{
|
|
261
|
+
errorMessage = (const char *)olm_outbound_group_session_last_error(sessionPtr);
|
|
262
|
+
LOGE(" ## sessionKeyJni(): failure - session key failure Msg=%s", errorMessage);
|
|
263
|
+
}
|
|
264
|
+
else
|
|
265
|
+
{
|
|
266
|
+
LOGD(" ## sessionKeyJni(): success - outbound group session key result=%lu sessionKey=%.*s",static_cast<long unsigned int>(result), static_cast<int>(result), reinterpret_cast<char*>(sessionKeyPtr));
|
|
267
|
+
|
|
268
|
+
returnValue = env->NewByteArray(result);
|
|
269
|
+
env->SetByteArrayRegion(returnValue, 0 , result, (jbyte*)sessionKeyPtr);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// free alloc
|
|
273
|
+
free(sessionKeyPtr);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (errorMessage)
|
|
278
|
+
{
|
|
279
|
+
env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return returnValue;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Encrypt a bytes buffer messages.
|
|
287
|
+
* An exception is thrown if the operation fails.
|
|
288
|
+
* @param aClearMsgBuffer the message to encode
|
|
289
|
+
* @return the encoded message
|
|
290
|
+
*/
|
|
291
|
+
JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aClearMsgBuffer)
|
|
292
|
+
{
|
|
293
|
+
LOGD("## encryptMessageJni(): IN");
|
|
294
|
+
|
|
295
|
+
const char* errorMessage = NULL;
|
|
296
|
+
jbyteArray encryptedMsgRet = 0;
|
|
297
|
+
|
|
298
|
+
OlmOutboundGroupSession *sessionPtr = NULL;
|
|
299
|
+
jbyte* clearMsgPtr = NULL;
|
|
300
|
+
jboolean clearMsgIsCopied = JNI_FALSE;
|
|
301
|
+
|
|
302
|
+
if (!(sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
|
|
303
|
+
{
|
|
304
|
+
LOGE(" ## encryptMessageJni(): failure - invalid outbound group session ptr=NULL");
|
|
305
|
+
errorMessage = "invalid outbound group session ptr=NULL";
|
|
306
|
+
}
|
|
307
|
+
else if (!aClearMsgBuffer)
|
|
308
|
+
{
|
|
309
|
+
LOGE(" ## encryptMessageJni(): failure - invalid clear message");
|
|
310
|
+
errorMessage = "invalid clear message";
|
|
311
|
+
}
|
|
312
|
+
else if (!(clearMsgPtr = env->GetByteArrayElements(aClearMsgBuffer, &clearMsgIsCopied)))
|
|
313
|
+
{
|
|
314
|
+
LOGE(" ## encryptMessageJni(): failure - clear message JNI allocation OOM");
|
|
315
|
+
errorMessage = "clear message JNI allocation OOM";
|
|
316
|
+
}
|
|
317
|
+
else
|
|
318
|
+
{
|
|
319
|
+
// get clear message length
|
|
320
|
+
size_t clearMsgLength = (size_t)env->GetArrayLength(aClearMsgBuffer);
|
|
321
|
+
LOGD(" ## encryptMessageJni(): clearMsgLength=%lu",static_cast<long unsigned int>(clearMsgLength));
|
|
322
|
+
|
|
323
|
+
// compute max encrypted length
|
|
324
|
+
size_t encryptedMsgLength = olm_group_encrypt_message_length(sessionPtr,clearMsgLength);
|
|
325
|
+
uint8_t *encryptedMsgPtr = (uint8_t*)malloc(encryptedMsgLength*sizeof(uint8_t));
|
|
326
|
+
|
|
327
|
+
if (!encryptedMsgPtr)
|
|
328
|
+
{
|
|
329
|
+
LOGE(" ## encryptMessageJni(): failure - encryptedMsgPtr buffer OOM");
|
|
330
|
+
errorMessage = "encryptedMsgPtr buffer OOM";
|
|
331
|
+
}
|
|
332
|
+
else
|
|
333
|
+
{
|
|
334
|
+
LOGD(" ## encryptMessageJni(): estimated encryptedMsgLength=%lu",static_cast<long unsigned int>(encryptedMsgLength));
|
|
335
|
+
|
|
336
|
+
size_t encryptedLength = olm_group_encrypt(sessionPtr,
|
|
337
|
+
(uint8_t*)clearMsgPtr,
|
|
338
|
+
clearMsgLength,
|
|
339
|
+
encryptedMsgPtr,
|
|
340
|
+
encryptedMsgLength);
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
if (encryptedLength == olm_error())
|
|
344
|
+
{
|
|
345
|
+
errorMessage = olm_outbound_group_session_last_error(sessionPtr);
|
|
346
|
+
LOGE(" ## encryptMessageJni(): failure - olm_group_decrypt_max_plaintext_length Msg=%s", errorMessage);
|
|
347
|
+
}
|
|
348
|
+
else
|
|
349
|
+
{
|
|
350
|
+
LOGD(" ## encryptMessageJni(): encrypted returnedLg=%lu plainTextMsgPtr=%.*s",static_cast<long unsigned int>(encryptedLength), static_cast<int>(encryptedLength), reinterpret_cast<char*>(encryptedMsgPtr));
|
|
351
|
+
|
|
352
|
+
encryptedMsgRet = env->NewByteArray(encryptedLength);
|
|
353
|
+
env->SetByteArrayRegion(encryptedMsgRet, 0 , encryptedLength, (jbyte*)encryptedMsgPtr);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
free(encryptedMsgPtr);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// free alloc
|
|
361
|
+
if (clearMsgPtr)
|
|
362
|
+
{
|
|
363
|
+
if (clearMsgIsCopied)
|
|
364
|
+
{
|
|
365
|
+
memset(clearMsgPtr, 0, (size_t)env->GetArrayLength(aClearMsgBuffer));
|
|
366
|
+
}
|
|
367
|
+
env->ReleaseByteArrayElements(aClearMsgBuffer, clearMsgPtr, JNI_ABORT);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (errorMessage)
|
|
371
|
+
{
|
|
372
|
+
env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
return encryptedMsgRet;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Serialize and encrypt session instance into a base64 string.<br>
|
|
380
|
+
* An exception is thrown if the operation fails.
|
|
381
|
+
* @param aKey key used to encrypt the serialized session data
|
|
382
|
+
* @return a base64 string if operation succeed, null otherwise
|
|
383
|
+
**/
|
|
384
|
+
JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer)
|
|
385
|
+
{
|
|
386
|
+
const char* errorMessage = NULL;
|
|
387
|
+
jbyteArray returnValue = 0;
|
|
388
|
+
|
|
389
|
+
jbyte* keyPtr = NULL;
|
|
390
|
+
jboolean keyWasCopied = JNI_FALSE;
|
|
391
|
+
OlmOutboundGroupSession* sessionPtr = NULL;
|
|
392
|
+
|
|
393
|
+
LOGD("## outbound group session serializeJni(): IN");
|
|
394
|
+
|
|
395
|
+
if (!(sessionPtr = (OlmOutboundGroupSession*)getOutboundGroupSessionInstanceId(env,thiz)))
|
|
396
|
+
{
|
|
397
|
+
LOGE(" ## serializeJni(): failure - invalid session ptr");
|
|
398
|
+
errorMessage = "invalid session ptr";
|
|
399
|
+
}
|
|
400
|
+
else if (!aKeyBuffer)
|
|
401
|
+
{
|
|
402
|
+
LOGE(" ## serializeJni(): failure - invalid key");
|
|
403
|
+
errorMessage = "invalid key";
|
|
404
|
+
}
|
|
405
|
+
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, &keyWasCopied)))
|
|
406
|
+
{
|
|
407
|
+
LOGE(" ## serializeJni(): failure - keyPtr JNI allocation OOM");
|
|
408
|
+
errorMessage = "keyPtr JNI allocation OOM";
|
|
409
|
+
}
|
|
410
|
+
else
|
|
411
|
+
{
|
|
412
|
+
size_t pickledLength = olm_pickle_outbound_group_session_length(sessionPtr);
|
|
413
|
+
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
|
|
414
|
+
LOGD(" ## serializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
|
|
415
|
+
|
|
416
|
+
void *pickledPtr = malloc(pickledLength*sizeof(uint8_t));
|
|
417
|
+
|
|
418
|
+
if(!pickledPtr)
|
|
419
|
+
{
|
|
420
|
+
LOGE(" ## serializeJni(): failure - pickledPtr buffer OOM");
|
|
421
|
+
errorMessage = "pickledPtr buffer OOM";
|
|
422
|
+
}
|
|
423
|
+
else
|
|
424
|
+
{
|
|
425
|
+
size_t result = olm_pickle_outbound_group_session(sessionPtr,
|
|
426
|
+
(void const *)keyPtr,
|
|
427
|
+
keyLength,
|
|
428
|
+
(void*)pickledPtr,
|
|
429
|
+
pickledLength);
|
|
430
|
+
if (result == olm_error())
|
|
431
|
+
{
|
|
432
|
+
errorMessage = olm_outbound_group_session_last_error(sessionPtr);
|
|
433
|
+
LOGE(" ## serializeJni(): failure - olm_pickle_outbound_group_session() Msg=%s", errorMessage);
|
|
434
|
+
}
|
|
435
|
+
else
|
|
436
|
+
{
|
|
437
|
+
LOGD(" ## serializeJni(): success - result=%lu pickled=%.*s", static_cast<long unsigned int>(result), static_cast<int>(result), static_cast<char*>(pickledPtr));
|
|
438
|
+
|
|
439
|
+
returnValue = env->NewByteArray(pickledLength);
|
|
440
|
+
env->SetByteArrayRegion(returnValue, 0 , pickledLength, (jbyte*)pickledPtr);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
free(pickledPtr);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// free alloc
|
|
448
|
+
if (keyPtr)
|
|
449
|
+
{
|
|
450
|
+
if (keyWasCopied) {
|
|
451
|
+
memset(keyPtr, 0, (size_t)env->GetArrayLength(aKeyBuffer));
|
|
452
|
+
}
|
|
453
|
+
env->ReleaseByteArrayElements(aKeyBuffer, keyPtr, JNI_ABORT);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
if (errorMessage)
|
|
457
|
+
{
|
|
458
|
+
env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
return returnValue;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Allocate a new session and initialize it with the serialisation data.<br>
|
|
466
|
+
* An exception is thrown if the operation fails.
|
|
467
|
+
* @param aSerializedData the session serialisation buffer
|
|
468
|
+
* @param aKey the key used to encrypt the serialized account data
|
|
469
|
+
* @return the deserialized session
|
|
470
|
+
**/
|
|
471
|
+
JNIEXPORT jlong OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer)
|
|
472
|
+
{
|
|
473
|
+
const char* errorMessage = NULL;
|
|
474
|
+
size_t sessionSize = olm_outbound_group_session_size();
|
|
475
|
+
OlmOutboundGroupSession* sessionPtr = NULL;
|
|
476
|
+
|
|
477
|
+
jbyte* keyPtr = NULL;
|
|
478
|
+
jboolean keyWasCopied = JNI_FALSE;
|
|
479
|
+
jbyte* pickledPtr = NULL;
|
|
480
|
+
|
|
481
|
+
LOGD("## deserializeJni(): IN");
|
|
482
|
+
|
|
483
|
+
if (!sessionSize)
|
|
484
|
+
{
|
|
485
|
+
LOGE(" ## deserializeJni(): failure - outbound group session size = 0");
|
|
486
|
+
errorMessage = "outbound group session size = 0";
|
|
487
|
+
}
|
|
488
|
+
else if (!(sessionPtr = (OlmOutboundGroupSession*)malloc(sessionSize)))
|
|
489
|
+
{
|
|
490
|
+
LOGE(" ## deserializeJni(): failure - session failure OOM");
|
|
491
|
+
errorMessage = "session failure OOM";
|
|
492
|
+
}
|
|
493
|
+
else if (!aKeyBuffer)
|
|
494
|
+
{
|
|
495
|
+
LOGE(" ## deserializeJni(): failure - invalid key");
|
|
496
|
+
errorMessage = "invalid key";
|
|
497
|
+
}
|
|
498
|
+
else if (!aSerializedDataBuffer)
|
|
499
|
+
{
|
|
500
|
+
LOGE(" ## deserializeJni(): failure - serialized data");
|
|
501
|
+
errorMessage = "invalid serialized data";
|
|
502
|
+
}
|
|
503
|
+
else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, &keyWasCopied)))
|
|
504
|
+
{
|
|
505
|
+
LOGE(" ## deserializeJni(): failure - keyPtr JNI allocation OOM");
|
|
506
|
+
errorMessage = "keyPtr JNI allocation OOM";
|
|
507
|
+
}
|
|
508
|
+
else if (!(pickledPtr = env->GetByteArrayElements(aSerializedDataBuffer, 0)))
|
|
509
|
+
{
|
|
510
|
+
LOGE(" ## deserializeJni(): failure - pickledPtr JNI allocation OOM");
|
|
511
|
+
errorMessage = "pickledPtr JNI allocation OOM";
|
|
512
|
+
}
|
|
513
|
+
else
|
|
514
|
+
{
|
|
515
|
+
sessionPtr = olm_outbound_group_session(sessionPtr);
|
|
516
|
+
size_t pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer);
|
|
517
|
+
size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
|
|
518
|
+
LOGD(" ## deserializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
|
|
519
|
+
LOGD(" ## deserializeJni(): pickled=%.*s", static_cast<int>(pickledLength), (char const *)pickledPtr);
|
|
520
|
+
|
|
521
|
+
size_t result = olm_unpickle_outbound_group_session(sessionPtr,
|
|
522
|
+
(void const *)keyPtr,
|
|
523
|
+
keyLength,
|
|
524
|
+
(void*)pickledPtr,
|
|
525
|
+
pickledLength);
|
|
526
|
+
if (result == olm_error())
|
|
527
|
+
{
|
|
528
|
+
errorMessage = olm_outbound_group_session_last_error(sessionPtr);
|
|
529
|
+
LOGE(" ## deserializeJni(): failure - olm_unpickle_outbound_group_session() Msg=%s", errorMessage);
|
|
530
|
+
}
|
|
531
|
+
else
|
|
532
|
+
{
|
|
533
|
+
LOGD(" ## deserializeJni(): success - result=%lu ", static_cast<long unsigned int>(result));
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// free alloc
|
|
538
|
+
if (keyPtr)
|
|
539
|
+
{
|
|
540
|
+
if (keyWasCopied) {
|
|
541
|
+
memset(keyPtr, 0, (size_t)env->GetArrayLength(aKeyBuffer));
|
|
542
|
+
}
|
|
543
|
+
env->ReleaseByteArrayElements(aKeyBuffer, keyPtr, JNI_ABORT);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
if (pickledPtr)
|
|
547
|
+
{
|
|
548
|
+
env->ReleaseByteArrayElements(aSerializedDataBuffer, pickledPtr, JNI_ABORT);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
if (errorMessage)
|
|
552
|
+
{
|
|
553
|
+
if (sessionPtr)
|
|
554
|
+
{
|
|
555
|
+
olm_clear_outbound_group_session(sessionPtr);
|
|
556
|
+
free(sessionPtr);
|
|
557
|
+
}
|
|
558
|
+
env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
return (jlong)(intptr_t)sessionPtr;
|
|
562
|
+
}
|
|
563
|
+
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2016 OpenMarket Ltd
|
|
3
|
+
* Copyright 2016 Vector Creations Ltd
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#ifndef _OMLOUTBOUND_GROUP_SESSION_H
|
|
19
|
+
#define _OMLOUTBOUND_GROUP_SESSION_H
|
|
20
|
+
|
|
21
|
+
#include "olm_jni.h"
|
|
22
|
+
#include "olm/olm.h"
|
|
23
|
+
#include "olm/outbound_group_session.h"
|
|
24
|
+
|
|
25
|
+
#define OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(func_name) FUNC_DEF(OlmOutboundGroupSession,func_name)
|
|
26
|
+
|
|
27
|
+
#ifdef __cplusplus
|
|
28
|
+
extern "C" {
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
// session creation/destruction
|
|
32
|
+
JNIEXPORT void OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz);
|
|
33
|
+
JNIEXPORT jlong OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *env, jobject thiz);
|
|
34
|
+
|
|
35
|
+
JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz);
|
|
36
|
+
JNIEXPORT jint OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(messageIndexJni)(JNIEnv *env, jobject thiz);
|
|
37
|
+
JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(sessionKeyJni)(JNIEnv *env, jobject thiz);
|
|
38
|
+
|
|
39
|
+
JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aClearMsgBuffer);
|
|
40
|
+
|
|
41
|
+
// serialization
|
|
42
|
+
JNIEXPORT jbyteArray OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKey);
|
|
43
|
+
JNIEXPORT jlong OLM_OUTBOUND_GROUP_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedData, jbyteArray aKey);
|
|
44
|
+
|
|
45
|
+
#ifdef __cplusplus
|
|
46
|
+
}
|
|
47
|
+
#endif
|
|
48
|
+
|
|
49
|
+
#endif
|