ruby_olm 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. checksums.yaml +7 -0
  2. data/ext/ruby_olm/ext_lib_olm/ext_account.c +274 -0
  3. data/ext/ruby_olm/ext_lib_olm/ext_lib_olm.c +51 -0
  4. data/ext/ruby_olm/ext_lib_olm/ext_lib_olm.h +13 -0
  5. data/ext/ruby_olm/ext_lib_olm/ext_session.c +363 -0
  6. data/ext/ruby_olm/ext_lib_olm/ext_utility.c +69 -0
  7. data/ext/ruby_olm/ext_lib_olm/extconf.rb +69 -0
  8. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_account.cpp +695 -0
  9. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_account.h +56 -0
  10. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_inbound_group_session.cpp +654 -0
  11. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_inbound_group_session.h +51 -0
  12. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_jni.h +81 -0
  13. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_jni_helper.cpp +224 -0
  14. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_jni_helper.h +30 -0
  15. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_manager.cpp +35 -0
  16. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_manager.h +36 -0
  17. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_outbound_group_session.cpp +563 -0
  18. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_outbound_group_session.h +49 -0
  19. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_pk.cpp +716 -0
  20. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_pk.h +48 -0
  21. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_session.cpp +977 -0
  22. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_session.h +59 -0
  23. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_utility.cpp +236 -0
  24. data/ext/ruby_olm/ext_lib_olm/olm/android/olm-sdk/src/main/jni/olm_utility.h +40 -0
  25. data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_decode_message.cpp +14 -0
  26. data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_decrypt.cpp +65 -0
  27. data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_group_decrypt.cpp +73 -0
  28. data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_unpickle_account.cpp +14 -0
  29. data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/fuzz_unpickle_session.cpp +14 -0
  30. data/ext/ruby_olm/ext_lib_olm/olm/fuzzers/include/fuzzing.hh +82 -0
  31. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/account.hh +160 -0
  32. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/base64.h +77 -0
  33. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/base64.hh +63 -0
  34. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/cipher.h +138 -0
  35. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/crypto.h +202 -0
  36. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/error.h +72 -0
  37. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/inbound_group_session.h +235 -0
  38. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/list.hh +119 -0
  39. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/megolm.h +95 -0
  40. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/memory.h +41 -0
  41. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/memory.hh +90 -0
  42. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/message.h +93 -0
  43. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/message.hh +138 -0
  44. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/olm.h +451 -0
  45. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/olm.hh +4 -0
  46. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/outbound_group_session.h +181 -0
  47. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/pickle.h +90 -0
  48. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/pickle.hh +149 -0
  49. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/pickle_encoding.h +76 -0
  50. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/pk.h +214 -0
  51. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/ratchet.hh +184 -0
  52. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/session.hh +156 -0
  53. data/ext/ruby_olm/ext_lib_olm/olm/include/olm/utility.hh +61 -0
  54. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/aes.c +1073 -0
  55. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/aes.h +123 -0
  56. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/aes_test.c +276 -0
  57. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/arcfour.c +45 -0
  58. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/arcfour.h +30 -0
  59. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/arcfour_test.c +47 -0
  60. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/base64.c +135 -0
  61. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/base64.h +27 -0
  62. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/base64_test.c +54 -0
  63. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/blowfish.c +269 -0
  64. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/blowfish.h +32 -0
  65. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/blowfish_test.c +68 -0
  66. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/des.c +269 -0
  67. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/des.h +37 -0
  68. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/des_test.c +83 -0
  69. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md2.c +104 -0
  70. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md2.h +33 -0
  71. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md2_test.c +58 -0
  72. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md5.c +189 -0
  73. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md5.h +34 -0
  74. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/md5_test.c +60 -0
  75. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/rot-13.c +35 -0
  76. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/rot-13.h +20 -0
  77. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/rot-13_test.c +44 -0
  78. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha1.c +149 -0
  79. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha1.h +35 -0
  80. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha1_test.c +58 -0
  81. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha256.c +159 -0
  82. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha256.h +34 -0
  83. data/ext/ruby_olm/ext_lib_olm/olm/lib/crypto-algorithms/sha256_test.c +61 -0
  84. data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/contrib/Curve25519Donna.c +118 -0
  85. data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/contrib/Curve25519Donna.h +53 -0
  86. data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/curve25519-donna-c64.c +449 -0
  87. data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/curve25519-donna.c +860 -0
  88. data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/python-src/curve25519/curve25519module.c +105 -0
  89. data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/speed-curve25519.c +50 -0
  90. data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/test-curve25519.c +54 -0
  91. data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/test-noncanon.c +39 -0
  92. data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna/test-sc-curve25519.c +72 -0
  93. data/ext/ruby_olm/ext_lib_olm/olm/lib/curve25519-donna.h +18 -0
  94. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/add_scalar.c +56 -0
  95. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/ed25519.h +38 -0
  96. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/fe.c +1493 -0
  97. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/fe.h +41 -0
  98. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/fixedint.h +72 -0
  99. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/ge.c +467 -0
  100. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/ge.h +74 -0
  101. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/key_exchange.c +79 -0
  102. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/keypair.c +16 -0
  103. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/precomp_data.h +1391 -0
  104. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sc.c +814 -0
  105. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sc.h +12 -0
  106. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/seed.c +40 -0
  107. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sha512.c +275 -0
  108. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sha512.h +21 -0
  109. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/sign.c +31 -0
  110. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/src/verify.c +77 -0
  111. data/ext/ruby_olm/ext_lib_olm/olm/lib/ed25519/test.c +150 -0
  112. data/ext/ruby_olm/ext_lib_olm/olm/python/dummy/stddef.h +0 -0
  113. data/ext/ruby_olm/ext_lib_olm/olm/python/dummy/stdint.h +0 -0
  114. data/ext/ruby_olm/ext_lib_olm/olm/src/account.cpp +380 -0
  115. data/ext/ruby_olm/ext_lib_olm/olm/src/base64.cpp +167 -0
  116. data/ext/ruby_olm/ext_lib_olm/olm/src/cipher.cpp +152 -0
  117. data/ext/ruby_olm/ext_lib_olm/olm/src/crypto.cpp +299 -0
  118. data/ext/ruby_olm/ext_lib_olm/olm/src/ed25519.c +22 -0
  119. data/ext/ruby_olm/ext_lib_olm/olm/src/error.c +44 -0
  120. data/ext/ruby_olm/ext_lib_olm/olm/src/inbound_group_session.c +524 -0
  121. data/ext/ruby_olm/ext_lib_olm/olm/src/megolm.c +150 -0
  122. data/ext/ruby_olm/ext_lib_olm/olm/src/memory.cpp +45 -0
  123. data/ext/ruby_olm/ext_lib_olm/olm/src/message.cpp +401 -0
  124. data/ext/ruby_olm/ext_lib_olm/olm/src/olm.cpp +738 -0
  125. data/ext/ruby_olm/ext_lib_olm/olm/src/outbound_group_session.c +363 -0
  126. data/ext/ruby_olm/ext_lib_olm/olm/src/pickle.cpp +242 -0
  127. data/ext/ruby_olm/ext_lib_olm/olm/src/pickle_encoding.c +92 -0
  128. data/ext/ruby_olm/ext_lib_olm/olm/src/pk.cpp +412 -0
  129. data/ext/ruby_olm/ext_lib_olm/olm/src/ratchet.cpp +625 -0
  130. data/ext/ruby_olm/ext_lib_olm/olm/src/session.cpp +462 -0
  131. data/ext/ruby_olm/ext_lib_olm/olm/src/utility.cpp +57 -0
  132. data/ext/ruby_olm/ext_lib_olm/olm/tests/include/unittest.hh +107 -0
  133. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_base64.cpp +70 -0
  134. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_crypto.cpp +246 -0
  135. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_group_session.cpp +329 -0
  136. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_list.cpp +92 -0
  137. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_megolm.cpp +134 -0
  138. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_message.cpp +112 -0
  139. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm.cpp +405 -0
  140. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm_decrypt.cpp +90 -0
  141. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm_sha256.cpp +20 -0
  142. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm_signature.cpp +81 -0
  143. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_olm_using_malloc.cpp +210 -0
  144. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_pk.cpp +166 -0
  145. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_ratchet.cpp +221 -0
  146. data/ext/ruby_olm/ext_lib_olm/olm/tests/test_session.cpp +144 -0
  147. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMAccount.h +51 -0
  148. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMAccount_Private.h +25 -0
  149. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMInboundGroupSession.h +38 -0
  150. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMKit.h +37 -0
  151. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMMessage.h +38 -0
  152. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMOutboundGroupSession.h +32 -0
  153. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMPkDecryption.h +71 -0
  154. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMPkEncryption.h +42 -0
  155. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMPkMessage.h +31 -0
  156. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMSerializable.h +29 -0
  157. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMSession.h +44 -0
  158. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMSession_Private.h +26 -0
  159. data/ext/ruby_olm/ext_lib_olm/olm/xcode/OLMKit/OLMUtility.h +49 -0
  160. data/ext/ruby_olm/ext_lib_olm/staging/account.cpp +380 -0
  161. data/ext/ruby_olm/ext_lib_olm/staging/aes.c +1073 -0
  162. data/ext/ruby_olm/ext_lib_olm/staging/base64.cpp +167 -0
  163. data/ext/ruby_olm/ext_lib_olm/staging/cipher.cpp +152 -0
  164. data/ext/ruby_olm/ext_lib_olm/staging/crypto.cpp +299 -0
  165. data/ext/ruby_olm/ext_lib_olm/staging/curve25519-donna.c +860 -0
  166. data/ext/ruby_olm/ext_lib_olm/staging/ed25519.c +22 -0
  167. data/ext/ruby_olm/ext_lib_olm/staging/error.c +44 -0
  168. data/ext/ruby_olm/ext_lib_olm/staging/inbound_group_session.c +524 -0
  169. data/ext/ruby_olm/ext_lib_olm/staging/megolm.c +150 -0
  170. data/ext/ruby_olm/ext_lib_olm/staging/memory.cpp +45 -0
  171. data/ext/ruby_olm/ext_lib_olm/staging/message.cpp +401 -0
  172. data/ext/ruby_olm/ext_lib_olm/staging/olm.cpp +738 -0
  173. data/ext/ruby_olm/ext_lib_olm/staging/outbound_group_session.c +363 -0
  174. data/ext/ruby_olm/ext_lib_olm/staging/pickle.cpp +242 -0
  175. data/ext/ruby_olm/ext_lib_olm/staging/pickle_encoding.c +92 -0
  176. data/ext/ruby_olm/ext_lib_olm/staging/pk.cpp +412 -0
  177. data/ext/ruby_olm/ext_lib_olm/staging/ratchet.cpp +625 -0
  178. data/ext/ruby_olm/ext_lib_olm/staging/session.cpp +461 -0
  179. data/ext/ruby_olm/ext_lib_olm/staging/sha256.c +159 -0
  180. data/ext/ruby_olm/ext_lib_olm/staging/utility.cpp +57 -0
  181. data/lib/ruby_olm/account.rb +42 -0
  182. data/lib/ruby_olm/message.rb +6 -0
  183. data/lib/ruby_olm/olm_error.rb +70 -0
  184. data/lib/ruby_olm/olm_message.rb +25 -0
  185. data/lib/ruby_olm/pre_key_message.rb +6 -0
  186. data/lib/ruby_olm/session.rb +16 -0
  187. data/lib/ruby_olm/version.rb +5 -0
  188. data/lib/ruby_olm.rb +10 -0
  189. data/rakefile +18 -0
  190. data/test/examples/test_bob_no_answer.rb +62 -0
  191. data/test/examples/test_exchange.rb +60 -0
  192. data/test/spec/test_account.rb +152 -0
  193. data/test/unit/test_account_methods.rb +85 -0
  194. metadata +282 -0
@@ -0,0 +1,654 @@
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_inbound_group_session.h"
19
+
20
+ using namespace AndroidOlmSdk;
21
+
22
+ /**
23
+ * Release the session allocation made by initializeInboundGroupSessionMemory().<br>
24
+ * This method MUST be called when java counter part account instance is done.
25
+ */
26
+ JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz)
27
+ {
28
+ OlmInboundGroupSession* sessionPtr = getInboundGroupSessionInstanceId(env,thiz);
29
+
30
+ LOGD("## releaseSessionJni(): InBound group session IN");
31
+
32
+ if (!sessionPtr)
33
+ {
34
+ LOGE("## releaseSessionJni(): failure - invalid inbound group session instance");
35
+ }
36
+ else
37
+ {
38
+ LOGD(" ## releaseSessionJni(): sessionPtr=%p", sessionPtr);
39
+ #ifdef ENABLE_JNI_LOG
40
+ size_t retCode = olm_clear_inbound_group_session(sessionPtr);
41
+ LOGD(" ## releaseSessionJni(): clear_inbound_group_session=%lu",static_cast<long unsigned int>(retCode));
42
+ #else
43
+ olm_clear_inbound_group_session(sessionPtr);
44
+ #endif
45
+
46
+ LOGD(" ## releaseSessionJni(): free IN");
47
+ free(sessionPtr);
48
+ LOGD(" ## releaseSessionJni(): free OUT");
49
+ }
50
+ }
51
+
52
+ /**
53
+ * Initialize a new inbound group session and return it to JAVA side.<br>
54
+ * Since a C prt is returned as a jlong, special care will be taken
55
+ * to make the cast (OlmInboundGroupSession* => jlong) platform independent.
56
+ * @param aSessionKeyBuffer session key from an outbound session
57
+ * @param isImported true when the session key has been retrieved from a backup
58
+ * @return the initialized OlmInboundGroupSession* instance or throw an exception it fails.
59
+ **/
60
+ JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *env, jobject thiz, jbyteArray aSessionKeyBuffer, jboolean isImported)
61
+ {
62
+ const char* errorMessage = NULL;
63
+ OlmInboundGroupSession* sessionPtr = NULL;
64
+ jbyte* sessionKeyPtr = NULL;
65
+ jboolean sessionWasCopied = JNI_FALSE;
66
+ size_t sessionSize = olm_inbound_group_session_size();
67
+
68
+ LOGD("## createNewSessionJni(): inbound group session IN");
69
+
70
+ if (!sessionSize)
71
+ {
72
+ LOGE(" ## createNewSessionJni(): failure - inbound group session size = 0");
73
+ errorMessage = "inbound group session size = 0";
74
+ }
75
+ else if (!(sessionPtr = (OlmInboundGroupSession*)malloc(sessionSize)))
76
+ {
77
+ LOGE(" ## createNewSessionJni(): failure - inbound group session OOM");
78
+ errorMessage = "inbound group session OOM";
79
+ }
80
+ else if (!aSessionKeyBuffer)
81
+ {
82
+ LOGE(" ## createNewSessionJni(): failure - invalid aSessionKey");
83
+ errorMessage = "invalid aSessionKey";
84
+ }
85
+ else if (!(sessionKeyPtr = env->GetByteArrayElements(aSessionKeyBuffer, &sessionWasCopied)))
86
+ {
87
+ LOGE(" ## createNewSessionJni(): failure - session key JNI allocation OOM");
88
+ errorMessage = "Session key JNI allocation OOM";
89
+ }
90
+ else
91
+ {
92
+ sessionPtr = olm_inbound_group_session(sessionPtr);
93
+
94
+ size_t sessionKeyLength = (size_t)env->GetArrayLength(aSessionKeyBuffer);
95
+ LOGD(" ## createNewSessionJni(): sessionKeyLength=%lu", static_cast<long unsigned int>(sessionKeyLength));
96
+
97
+ size_t sessionResult;
98
+
99
+ if (JNI_FALSE == isImported)
100
+ {
101
+ LOGD(" ## createNewSessionJni(): init");
102
+ sessionResult = olm_init_inbound_group_session(sessionPtr, (const uint8_t*)sessionKeyPtr, sessionKeyLength);
103
+ }
104
+ else
105
+ {
106
+ LOGD(" ## createNewSessionJni(): import");
107
+ sessionResult = olm_import_inbound_group_session(sessionPtr, (const uint8_t*)sessionKeyPtr, sessionKeyLength);
108
+ }
109
+
110
+ if (sessionResult == olm_error())
111
+ {
112
+ errorMessage = olm_inbound_group_session_last_error(sessionPtr);
113
+ LOGE(" ## createNewSessionJni(): failure - init inbound session creation Msg=%s", errorMessage);
114
+ }
115
+ else
116
+ {
117
+ LOGD(" ## createNewSessionJni(): success - result=%lu", static_cast<long unsigned int>(sessionResult));
118
+ }
119
+ }
120
+
121
+ if (sessionKeyPtr)
122
+ {
123
+ if (sessionWasCopied) {
124
+ memset(sessionKeyPtr, 0, (size_t)env->GetArrayLength(aSessionKeyBuffer));
125
+ }
126
+ env->ReleaseByteArrayElements(aSessionKeyBuffer, sessionKeyPtr, JNI_ABORT);
127
+ }
128
+
129
+ if (errorMessage)
130
+ {
131
+ // release the allocated session
132
+ if (sessionPtr)
133
+ {
134
+ olm_clear_inbound_group_session(sessionPtr);
135
+ free(sessionPtr);
136
+ }
137
+ env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
138
+ }
139
+
140
+ return (jlong)(intptr_t)sessionPtr;
141
+ }
142
+
143
+ /**
144
+ * Get a base64-encoded identifier for this inbound group session.
145
+ * An exception is thrown if the operation fails.
146
+ * @return the base64-encoded identifier
147
+ */
148
+ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz)
149
+ {
150
+ const char* errorMessage = NULL;
151
+ OlmInboundGroupSession *sessionPtr = getInboundGroupSessionInstanceId(env, thiz);
152
+ jbyteArray returnValue = 0;
153
+
154
+ LOGD("## sessionIdentifierJni(): inbound group session IN");
155
+
156
+ if (!sessionPtr)
157
+ {
158
+ LOGE(" ## sessionIdentifierJni(): failure - invalid inbound group session instance");
159
+ errorMessage = "invalid inbound group session instance";
160
+ }
161
+ else
162
+ {
163
+ // get the size to alloc
164
+ size_t lengthSessionId = olm_inbound_group_session_id_length(sessionPtr);
165
+ LOGD(" ## sessionIdentifierJni(): inbound group session lengthSessionId=%lu",static_cast<long unsigned int>(lengthSessionId));
166
+
167
+ uint8_t *sessionIdPtr = (uint8_t*)malloc(lengthSessionId*sizeof(uint8_t));
168
+
169
+ if (!sessionIdPtr)
170
+ {
171
+ LOGE(" ## sessionIdentifierJni(): failure - inbound group session identifier allocation OOM");
172
+ errorMessage = "inbound group session identifier allocation OOM";
173
+ }
174
+ else
175
+ {
176
+ size_t result = olm_inbound_group_session_id(sessionPtr, sessionIdPtr, lengthSessionId);
177
+
178
+ if (result == olm_error())
179
+ {
180
+ errorMessage = (const char *)olm_inbound_group_session_last_error(sessionPtr);
181
+ LOGE(" ## sessionIdentifierJni(): failure - get inbound group session identifier failure Msg=%s",(const char *)olm_inbound_group_session_last_error(sessionPtr));
182
+ }
183
+ else
184
+ {
185
+ LOGD(" ## sessionIdentifierJni(): success - inbound group session result=%lu sessionId=%.*s",static_cast<long unsigned int>(result), static_cast<int>(result), (char*)sessionIdPtr);
186
+
187
+ returnValue = env->NewByteArray(result);
188
+ env->SetByteArrayRegion(returnValue, 0 , result, (jbyte*)sessionIdPtr);
189
+ }
190
+
191
+ free(sessionIdPtr);
192
+ }
193
+ }
194
+
195
+ if (errorMessage)
196
+ {
197
+ env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
198
+ }
199
+
200
+ return returnValue;
201
+ }
202
+
203
+ /**
204
+ * Decrypt a message.
205
+ * An exception is thrown if the operation fails.
206
+ * @param aEncryptedMsg the encrypted message
207
+ * @param aDecryptMessageResult the decryptMessage information
208
+ * @return the decrypted message
209
+ */
210
+ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aEncryptedMsgBuffer, jobject aDecryptionResult)
211
+ {
212
+ jbyteArray decryptedMsgBuffer = 0;
213
+ const char* errorMessage = NULL;
214
+
215
+ OlmInboundGroupSession *sessionPtr = getInboundGroupSessionInstanceId(env, thiz);
216
+ jbyte *encryptedMsgPtr = NULL;
217
+ jclass indexObjJClass = 0;
218
+ jfieldID indexMsgFieldId;
219
+
220
+ LOGD("## decryptMessageJni(): inbound group session IN");
221
+
222
+ if (!sessionPtr)
223
+ {
224
+ LOGE(" ## decryptMessageJni(): failure - invalid inbound group session ptr=NULL");
225
+ errorMessage = "invalid inbound group session ptr=NULL";
226
+ }
227
+ else if (!aEncryptedMsgBuffer)
228
+ {
229
+ LOGE(" ## decryptMessageJni(): failure - invalid encrypted message");
230
+ errorMessage = "invalid encrypted message";
231
+ }
232
+ else if (!aDecryptionResult)
233
+ {
234
+ LOGE(" ## decryptMessageJni(): failure - invalid index object");
235
+ errorMessage = "invalid index object";
236
+ }
237
+ else if (!(encryptedMsgPtr = env->GetByteArrayElements(aEncryptedMsgBuffer, 0)))
238
+ {
239
+ LOGE(" ## decryptMessageJni(): failure - encrypted message JNI allocation OOM");
240
+ errorMessage = "encrypted message JNI allocation OOM";
241
+ }
242
+ else if (!(indexObjJClass = env->GetObjectClass(aDecryptionResult)))
243
+ {
244
+ LOGE("## decryptMessageJni(): failure - unable to get index class");
245
+ errorMessage = "unable to get index class";
246
+ }
247
+ else if (!(indexMsgFieldId = env->GetFieldID(indexObjJClass,"mIndex","J")))
248
+ {
249
+ LOGE("## decryptMessageJni(): failure - unable to get index type field");
250
+ errorMessage = "unable to get index type field";
251
+ }
252
+ else
253
+ {
254
+ // get encrypted message length
255
+ size_t encryptedMsgLength = (size_t)env->GetArrayLength(aEncryptedMsgBuffer);
256
+ uint8_t *tempEncryptedPtr = static_cast<uint8_t*>(malloc(encryptedMsgLength*sizeof(uint8_t)));
257
+
258
+ // create a dedicated temp buffer to be used in next Olm API calls
259
+ if (!tempEncryptedPtr)
260
+ {
261
+ LOGE(" ## decryptMessageJni(): failure - tempEncryptedPtr allocation OOM");
262
+ errorMessage = "tempEncryptedPtr allocation OOM";
263
+ }
264
+ else
265
+ {
266
+ memcpy(tempEncryptedPtr, encryptedMsgPtr, encryptedMsgLength);
267
+ LOGD(" ## decryptMessageJni(): encryptedMsgLength=%lu encryptedMsg=%.*s",static_cast<long unsigned int>(encryptedMsgLength), static_cast<int>(encryptedMsgLength), encryptedMsgPtr);
268
+
269
+ // get max plaintext length
270
+ size_t maxPlainTextLength = olm_group_decrypt_max_plaintext_length(sessionPtr,
271
+ tempEncryptedPtr,
272
+ encryptedMsgLength);
273
+ if (maxPlainTextLength == olm_error())
274
+ {
275
+ errorMessage = olm_inbound_group_session_last_error(sessionPtr);
276
+ LOGE(" ## decryptMessageJni(): failure - olm_group_decrypt_max_plaintext_length Msg=%s", errorMessage);
277
+ }
278
+ else
279
+ {
280
+ LOGD(" ## decryptMessageJni(): maxPlaintextLength=%lu",static_cast<long unsigned int>(maxPlainTextLength));
281
+
282
+ uint32_t messageIndex = 0;
283
+
284
+ // allocate output decrypted message
285
+ uint8_t *plainTextMsgPtr = static_cast<uint8_t*>(malloc(maxPlainTextLength*sizeof(uint8_t)));
286
+
287
+ // decrypt, but before reload encrypted buffer (previous one was destroyed)
288
+ memcpy(tempEncryptedPtr, encryptedMsgPtr, encryptedMsgLength);
289
+ size_t plaintextLength = olm_group_decrypt(sessionPtr,
290
+ tempEncryptedPtr,
291
+ encryptedMsgLength,
292
+ plainTextMsgPtr,
293
+ maxPlainTextLength,
294
+ &messageIndex);
295
+ if (plaintextLength == olm_error())
296
+ {
297
+ errorMessage = olm_inbound_group_session_last_error(sessionPtr);
298
+ LOGE(" ## decryptMessageJni(): failure - olm_group_decrypt Msg=%s", errorMessage);
299
+ }
300
+ else
301
+ {
302
+ // update index
303
+ env->SetLongField(aDecryptionResult, indexMsgFieldId, (jlong)messageIndex);
304
+
305
+ decryptedMsgBuffer = env->NewByteArray(plaintextLength);
306
+ env->SetByteArrayRegion(decryptedMsgBuffer, 0 , plaintextLength, (jbyte*)plainTextMsgPtr);
307
+
308
+ LOGD(" ## decryptMessageJni(): UTF-8 Conversion - decrypted returnedLg=%lu OK",static_cast<long unsigned int>(plaintextLength));
309
+ }
310
+
311
+ if (plainTextMsgPtr)
312
+ {
313
+ memset(plainTextMsgPtr, 0, maxPlainTextLength*sizeof(uint8_t));
314
+ free(plainTextMsgPtr);
315
+ }
316
+ }
317
+
318
+ if (tempEncryptedPtr)
319
+ {
320
+ free(tempEncryptedPtr);
321
+ }
322
+ }
323
+ }
324
+
325
+ // free alloc
326
+ if (encryptedMsgPtr)
327
+ {
328
+ env->ReleaseByteArrayElements(aEncryptedMsgBuffer, encryptedMsgPtr, JNI_ABORT);
329
+ }
330
+
331
+ if (errorMessage)
332
+ {
333
+ env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
334
+ }
335
+
336
+ return decryptedMsgBuffer;
337
+ }
338
+
339
+ /**
340
+ * Provides the first known index.
341
+ * An exception is thrown if the operation fails.
342
+ * @return the first known index
343
+ */
344
+ JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(firstKnownIndexJni)(JNIEnv *env, jobject thiz)
345
+ {
346
+ const char* errorMessage = NULL;
347
+ OlmInboundGroupSession *sessionPtr = getInboundGroupSessionInstanceId(env, thiz);
348
+ long returnValue = 0;
349
+
350
+ LOGD("## firstKnownIndexJni(): inbound group session IN");
351
+
352
+ if (!sessionPtr)
353
+ {
354
+ LOGE(" ## firstKnownIndexJni(): failure - invalid inbound group session instance");
355
+ errorMessage = "invalid inbound group session instance";
356
+ }
357
+ else
358
+ {
359
+ returnValue = olm_inbound_group_session_first_known_index(sessionPtr);
360
+ }
361
+
362
+ if (errorMessage)
363
+ {
364
+ env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
365
+ }
366
+
367
+ return returnValue;
368
+ }
369
+
370
+ /**
371
+ * Tells if the session is verified.
372
+ * An exception is thrown if the operation fails.
373
+ * @return true if the session is verified
374
+ */
375
+ JNIEXPORT jboolean OLM_INBOUND_GROUP_SESSION_FUNC_DEF(isVerifiedJni)(JNIEnv *env, jobject thiz)
376
+ {
377
+ const char* errorMessage = NULL;
378
+ OlmInboundGroupSession *sessionPtr = getInboundGroupSessionInstanceId(env, thiz);
379
+ jboolean returnValue = JNI_FALSE;
380
+
381
+ LOGD("## isVerifiedJni(): inbound group session IN");
382
+
383
+ if (!sessionPtr)
384
+ {
385
+ LOGE(" ## isVerifiedJni(): failure - invalid inbound group session instance");
386
+ errorMessage = "invalid inbound group session instance";
387
+ }
388
+ else
389
+ {
390
+ LOGE(" ## isVerifiedJni(): faaa %d", olm_inbound_group_session_is_verified(sessionPtr));
391
+
392
+ returnValue = (0 != olm_inbound_group_session_is_verified(sessionPtr)) ? JNI_TRUE : JNI_FALSE;
393
+ }
394
+
395
+ if (errorMessage)
396
+ {
397
+ env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
398
+ }
399
+
400
+ return returnValue;
401
+ }
402
+
403
+ /**
404
+ * Exports the session as byte array from a message index
405
+ * An exception is thrown if the operation fails.
406
+ * @param messageIndex key used to encrypt the serialized session data
407
+ * @return the session saved as bytes array
408
+ **/
409
+ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(exportJni)(JNIEnv *env, jobject thiz, jlong messageIndex) {
410
+ jbyteArray exportedByteArray = 0;
411
+ const char* errorMessage = NULL;
412
+ OlmInboundGroupSession *sessionPtr = getInboundGroupSessionInstanceId(env, thiz);
413
+
414
+ LOGD("## exportJni(): inbound group session IN");
415
+
416
+ if (!sessionPtr)
417
+ {
418
+ LOGE(" ## exportJni (): failure - invalid inbound group session instance");
419
+ errorMessage = "invalid inbound group session instance";
420
+ }
421
+ else
422
+ {
423
+ size_t length = olm_export_inbound_group_session_length(sessionPtr);
424
+
425
+ LOGD(" ## exportJni(): length =%lu", static_cast<long unsigned int>(length));
426
+
427
+ void *bufferPtr = malloc(length * sizeof(uint8_t));
428
+
429
+ if (!bufferPtr)
430
+ {
431
+ LOGE(" ## exportJni(): failure - pickledPtr buffer OOM");
432
+ errorMessage = "pickledPtr buffer OOM";
433
+ }
434
+ else
435
+ {
436
+ size_t result = olm_export_inbound_group_session(sessionPtr,
437
+ (uint8_t*)bufferPtr,
438
+ length,
439
+ (long) messageIndex);
440
+
441
+ if (result == olm_error())
442
+ {
443
+ errorMessage = olm_inbound_group_session_last_error(sessionPtr);
444
+ LOGE(" ## exportJni(): failure - olm_export_inbound_group_session() Msg=%s", errorMessage);
445
+ }
446
+ else
447
+ {
448
+ LOGD(" ## exportJni(): success - result=%lu buffer=%.*s", static_cast<long unsigned int>(result), static_cast<int>(length), static_cast<char*>(bufferPtr));
449
+
450
+ exportedByteArray = env->NewByteArray(length);
451
+ env->SetByteArrayRegion(exportedByteArray, 0 , length, (jbyte*)bufferPtr);
452
+
453
+ // clean before leaving
454
+ memset(bufferPtr, 0, length);
455
+ }
456
+
457
+ free(bufferPtr);
458
+ }
459
+ }
460
+
461
+ if (errorMessage)
462
+ {
463
+ env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
464
+ }
465
+
466
+ return exportedByteArray;
467
+ }
468
+
469
+ /**
470
+ * Serialize and encrypt session instance into a base64 string.<br>
471
+ * An exception is thrown if the operation fails.
472
+ * @param aKeyBuffer key used to encrypt the serialized session data
473
+ * @return a base64 string if operation succeed, null otherwise
474
+ **/
475
+ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKeyBuffer)
476
+ {
477
+ const char* errorMessage = NULL;
478
+
479
+ jbyteArray pickledDataRet = 0;
480
+ jbyte* keyPtr = NULL;
481
+ jboolean keyWasCopied = JNI_FALSE;
482
+ OlmInboundGroupSession* sessionPtr = getInboundGroupSessionInstanceId(env, thiz);
483
+
484
+ LOGD("## inbound group session serializeJni(): IN");
485
+
486
+ if (!sessionPtr)
487
+ {
488
+ LOGE(" ## serializeJni(): failure - invalid session ptr");
489
+ errorMessage = "invalid session ptr";
490
+ }
491
+ else if (!aKeyBuffer)
492
+ {
493
+ LOGE(" ## serializeJni(): failure - invalid key");
494
+ errorMessage = "invalid key";
495
+ }
496
+ else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, &keyWasCopied)))
497
+ {
498
+ LOGE(" ## serializeJni(): failure - keyPtr JNI allocation OOM");
499
+ errorMessage = "keyPtr JNI allocation OOM";
500
+ }
501
+ else
502
+ {
503
+ size_t pickledLength = olm_pickle_inbound_group_session_length(sessionPtr);
504
+ size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
505
+ LOGD(" ## serializeJni(): pickledLength=%lu keyLength=%lu", static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
506
+
507
+ void *pickledPtr = malloc(pickledLength*sizeof(uint8_t));
508
+
509
+ if (!pickledPtr)
510
+ {
511
+ LOGE(" ## serializeJni(): failure - pickledPtr buffer OOM");
512
+ errorMessage = "pickledPtr buffer OOM";
513
+ }
514
+ else
515
+ {
516
+ size_t result = olm_pickle_inbound_group_session(sessionPtr,
517
+ (void const *)keyPtr,
518
+ keyLength,
519
+ (void*)pickledPtr,
520
+ pickledLength);
521
+ if (result == olm_error())
522
+ {
523
+ errorMessage = olm_inbound_group_session_last_error(sessionPtr);
524
+ LOGE(" ## serializeJni(): failure - olm_pickle_outbound_group_session() Msg=%s", errorMessage);
525
+ }
526
+ else
527
+ {
528
+ LOGD(" ## serializeJni(): success - result=%lu pickled=%.*s", static_cast<long unsigned int>(result), static_cast<int>(pickledLength), static_cast<char*>(pickledPtr));
529
+
530
+ pickledDataRet = env->NewByteArray(pickledLength);
531
+ env->SetByteArrayRegion(pickledDataRet, 0 , pickledLength, (jbyte*)pickledPtr);
532
+ }
533
+
534
+ free(pickledPtr);
535
+ }
536
+ }
537
+
538
+ // free alloc
539
+ if (keyPtr)
540
+ {
541
+ if (keyWasCopied) {
542
+ memset(keyPtr, 0, (size_t)env->GetArrayLength(aKeyBuffer));
543
+ }
544
+ env->ReleaseByteArrayElements(aKeyBuffer, keyPtr, JNI_ABORT);
545
+ }
546
+
547
+ if (errorMessage)
548
+ {
549
+ env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
550
+ }
551
+
552
+ return pickledDataRet;
553
+ }
554
+
555
+ /**
556
+ * Allocate a new session and initialize it with the serialisation data.<br>
557
+ * An exception is thrown if the operation fails.
558
+ * @param aSerializedData the session serialisation buffer
559
+ * @param aKey the key used to encrypt the serialized account data
560
+ * @return the deserialized session
561
+ **/
562
+ JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedDataBuffer, jbyteArray aKeyBuffer)
563
+ {
564
+ const char* errorMessage = NULL;
565
+
566
+ OlmInboundGroupSession* sessionPtr = NULL;
567
+ size_t sessionSize = olm_inbound_group_session_size();
568
+ jbyte* keyPtr = NULL;
569
+ jboolean keyWasCopied = JNI_FALSE;
570
+ jbyte* pickledPtr = NULL;
571
+
572
+ LOGD("## deserializeJni(): IN");
573
+
574
+ if (!sessionSize)
575
+ {
576
+ LOGE(" ## deserializeJni(): failure - inbound group session size = 0");
577
+ errorMessage = "inbound group session size = 0";
578
+ }
579
+ else if (!(sessionPtr = (OlmInboundGroupSession*)malloc(sessionSize)))
580
+ {
581
+ LOGE(" ## deserializeJni(): failure - session failure OOM");
582
+ errorMessage = "session failure OOM";
583
+ }
584
+ else if (!aKeyBuffer)
585
+ {
586
+ LOGE(" ## deserializeJni(): failure - invalid key");
587
+ errorMessage = "invalid key";
588
+ }
589
+ else if (!aSerializedDataBuffer)
590
+ {
591
+ LOGE(" ## deserializeJni(): failure - serialized data");
592
+ errorMessage = "serialized data";
593
+ }
594
+ else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, &keyWasCopied)))
595
+ {
596
+ LOGE(" ## deserializeJni(): failure - keyPtr JNI allocation OOM");
597
+ errorMessage = "keyPtr JNI allocation OOM";
598
+ }
599
+ else if (!(pickledPtr = env->GetByteArrayElements(aSerializedDataBuffer, 0)))
600
+ {
601
+ LOGE(" ## deserializeJni(): failure - pickledPtr JNI allocation OOM");
602
+ errorMessage = "pickledPtr JNI allocation OOM";
603
+ }
604
+ else
605
+ {
606
+ sessionPtr = olm_inbound_group_session(sessionPtr);
607
+
608
+ size_t pickledLength = (size_t)env->GetArrayLength(aSerializedDataBuffer);
609
+ size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
610
+ LOGD(" ## deserializeJni(): pickledLength=%lu keyLength=%lu",static_cast<long unsigned int>(pickledLength), static_cast<long unsigned int>(keyLength));
611
+ LOGD(" ## deserializeJni(): pickled=%.*s", static_cast<int>(pickledLength), (char const *)pickledPtr);
612
+
613
+ size_t result = olm_unpickle_inbound_group_session(sessionPtr,
614
+ (void const *)keyPtr,
615
+ keyLength,
616
+ (void*)pickledPtr,
617
+ pickledLength);
618
+ if (result == olm_error())
619
+ {
620
+ errorMessage = olm_inbound_group_session_last_error(sessionPtr);
621
+ LOGE(" ## deserializeJni(): failure - olm_unpickle_inbound_group_session() Msg=%s", errorMessage);
622
+ }
623
+ else
624
+ {
625
+ LOGD(" ## deserializeJni(): success - result=%lu ", static_cast<long unsigned int>(result));
626
+ }
627
+ }
628
+
629
+ // free alloc
630
+ if (keyPtr)
631
+ {
632
+ if (keyWasCopied) {
633
+ memset(keyPtr, 0, (size_t)env->GetArrayLength(aKeyBuffer));
634
+ }
635
+ env->ReleaseByteArrayElements(aKeyBuffer, keyPtr, JNI_ABORT);
636
+ }
637
+
638
+ if (pickledPtr)
639
+ {
640
+ env->ReleaseByteArrayElements(aSerializedDataBuffer, pickledPtr, JNI_ABORT);
641
+ }
642
+
643
+ if (errorMessage)
644
+ {
645
+ if (sessionPtr)
646
+ {
647
+ olm_clear_inbound_group_session(sessionPtr);
648
+ free(sessionPtr);
649
+ }
650
+ env->ThrowNew(env->FindClass("java/lang/Exception"), errorMessage);
651
+ }
652
+
653
+ return (jlong)(intptr_t)sessionPtr;
654
+ }
@@ -0,0 +1,51 @@
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 _OMLINBOUND_GROUP_SESSION_H
19
+ #define _OMLINBOUND_GROUP_SESSION_H
20
+
21
+ #include "olm_jni.h"
22
+ #include "olm/olm.h"
23
+ #include "olm/inbound_group_session.h"
24
+
25
+ #define OLM_INBOUND_GROUP_SESSION_FUNC_DEF(func_name) FUNC_DEF(OlmInboundGroupSession,func_name)
26
+
27
+ #ifdef __cplusplus
28
+ extern "C" {
29
+ #endif
30
+
31
+ // session creation/destruction
32
+ JNIEXPORT void OLM_INBOUND_GROUP_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz);
33
+ JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *env, jobject thiz, jbyteArray aSessionKeyBuffer, jboolean isImported);
34
+
35
+ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(sessionIdentifierJni)(JNIEnv *env, jobject thiz);
36
+ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aEncryptedMsg, jobject aDecryptIndex);
37
+
38
+ JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(firstKnownIndexJni)(JNIEnv *env, jobject thiz);
39
+ JNIEXPORT jboolean OLM_INBOUND_GROUP_SESSION_FUNC_DEF(isVerifiedJni)(JNIEnv *env, jobject thiz);
40
+
41
+ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(exportJni)(JNIEnv *env, jobject thiz, jlong messageIndex);
42
+
43
+ // serialization
44
+ JNIEXPORT jbyteArray OLM_INBOUND_GROUP_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKey);
45
+ JNIEXPORT jlong OLM_INBOUND_GROUP_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedData, jbyteArray aKey);
46
+
47
+ #ifdef __cplusplus
48
+ }
49
+ #endif
50
+
51
+ #endif