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.
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,59 @@
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 _OMLSESSION_H
19
+ #define _OMLSESSION_H
20
+
21
+ #include "olm_jni.h"
22
+ #include "olm/olm.h"
23
+
24
+ #define OLM_SESSION_FUNC_DEF(func_name) FUNC_DEF(OlmSession,func_name)
25
+
26
+ #ifdef __cplusplus
27
+ extern "C" {
28
+ #endif
29
+
30
+ // session creation/destruction
31
+ JNIEXPORT void OLM_SESSION_FUNC_DEF(releaseSessionJni)(JNIEnv *env, jobject thiz);
32
+ JNIEXPORT jlong OLM_SESSION_FUNC_DEF(createNewSessionJni)(JNIEnv *env, jobject thiz);
33
+
34
+ // outbound session
35
+ JNIEXPORT void OLM_SESSION_FUNC_DEF(initOutboundSessionJni)(JNIEnv *env, jobject thiz, jlong aOlmAccountId, jbyteArray aTheirIdentityKey, jbyteArray aTheirOneTimeKey);
36
+
37
+ // inbound sessions: establishment based on PRE KEY message
38
+ JNIEXPORT void OLM_SESSION_FUNC_DEF(initInboundSessionJni)(JNIEnv *env, jobject thiz, jlong aOlmAccountId, jbyteArray aOneTimeKeyMsg);
39
+ JNIEXPORT void OLM_SESSION_FUNC_DEF(initInboundSessionFromIdKeyJni)(JNIEnv *env, jobject thiz, jlong aOlmAccountId, jbyteArray aTheirIdentityKey, jbyteArray aOneTimeKeyMsg);
40
+
41
+ // match inbound sessions: based on PRE KEY message
42
+ JNIEXPORT jboolean OLM_SESSION_FUNC_DEF(matchesInboundSessionJni)(JNIEnv *env, jobject thiz, jbyteArray aOneTimeKeyMsg);
43
+ JNIEXPORT jboolean OLM_SESSION_FUNC_DEF(matchesInboundSessionFromIdKeyJni)(JNIEnv *env, jobject thiz, jbyteArray aTheirIdentityKey, jbyteArray aOneTimeKeyMsg);
44
+
45
+ // encrypt/decrypt
46
+ JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(encryptMessageJni)(JNIEnv *env, jobject thiz, jbyteArray aClearMsg, jobject aEncryptedMsg);
47
+ JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(decryptMessageJni)(JNIEnv *env, jobject thiz, jobject aEncryptedMsg);
48
+
49
+ JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(getSessionIdentifierJni)(JNIEnv *env, jobject thiz);
50
+
51
+ // serialization
52
+ JNIEXPORT jbyteArray OLM_SESSION_FUNC_DEF(serializeJni)(JNIEnv *env, jobject thiz, jbyteArray aKey);
53
+ JNIEXPORT jlong OLM_SESSION_FUNC_DEF(deserializeJni)(JNIEnv *env, jobject thiz, jbyteArray aSerializedData, jbyteArray aKey);
54
+
55
+ #ifdef __cplusplus
56
+ }
57
+ #endif
58
+
59
+ #endif
@@ -0,0 +1,236 @@
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_utility.h"
19
+
20
+ using namespace AndroidOlmSdk;
21
+
22
+ OlmUtility* initializeUtilityMemory()
23
+ {
24
+ size_t utilitySize = olm_utility_size();
25
+ OlmUtility* utilityPtr = (OlmUtility*)malloc(utilitySize);
26
+
27
+ if (utilityPtr)
28
+ {
29
+ utilityPtr = olm_utility(utilityPtr);
30
+ LOGD("## initializeUtilityMemory(): success - OLM utility size=%lu",static_cast<long unsigned int>(utilitySize));
31
+ }
32
+ else
33
+ {
34
+ LOGE("## initializeUtilityMemory(): failure - OOM");
35
+ }
36
+
37
+ return utilityPtr;
38
+ }
39
+
40
+ JNIEXPORT jlong OLM_UTILITY_FUNC_DEF(createUtilityJni)(JNIEnv *env, jobject thiz)
41
+ {
42
+ OlmUtility* utilityPtr = initializeUtilityMemory();
43
+
44
+ LOGD("## createUtilityJni(): IN");
45
+
46
+ // init account memory allocation
47
+ if (!utilityPtr)
48
+ {
49
+ LOGE(" ## createUtilityJni(): failure - init OOM");
50
+ env->ThrowNew(env->FindClass("java/lang/Exception"), "init OOM");
51
+ }
52
+ else
53
+ {
54
+ LOGD(" ## createUtilityJni(): success");
55
+ }
56
+
57
+ return (jlong)(intptr_t)utilityPtr;
58
+ }
59
+
60
+
61
+ JNIEXPORT void OLM_UTILITY_FUNC_DEF(releaseUtilityJni)(JNIEnv *env, jobject thiz)
62
+ {
63
+ OlmUtility* utilityPtr = getUtilityInstanceId(env, thiz);
64
+
65
+ LOGD("## releaseUtilityJni(): IN");
66
+
67
+ if (!utilityPtr)
68
+ {
69
+ LOGE("## releaseUtilityJni(): failure - utility ptr=NULL");
70
+ }
71
+ else
72
+ {
73
+ olm_clear_utility(utilityPtr);
74
+ free(utilityPtr);
75
+ }
76
+ }
77
+
78
+
79
+ /**
80
+ * Verify an ed25519 signature.
81
+ * @param aSignature the base64-encoded message signature to be checked.
82
+ * @param aKey the ed25519 key (fingerprint key)
83
+ * @param aMessage the message which was signed
84
+ * @return 0 if validation succeed, an error message string if operation failed
85
+ */
86
+ JNIEXPORT jstring OLM_UTILITY_FUNC_DEF(verifyEd25519SignatureJni)(JNIEnv *env, jobject thiz, jbyteArray aSignatureBuffer, jbyteArray aKeyBuffer, jbyteArray aMessageBuffer)
87
+ {
88
+ jstring errorMessageRetValue = 0;
89
+ OlmUtility* utilityPtr = getUtilityInstanceId(env, thiz);
90
+ jbyte* signaturePtr = NULL;
91
+ jbyte* keyPtr = NULL;
92
+ jbyte* messagePtr = NULL;
93
+ jboolean messageWasCopied = JNI_FALSE;
94
+
95
+ LOGD("## verifyEd25519SignatureJni(): IN");
96
+
97
+ if (!utilityPtr)
98
+ {
99
+ LOGE(" ## verifyEd25519SignatureJni(): failure - invalid utility ptr=NULL");
100
+ }
101
+ else if (!aSignatureBuffer || !aKeyBuffer || !aMessageBuffer)
102
+ {
103
+ LOGE(" ## verifyEd25519SignatureJni(): failure - invalid input parameters ");
104
+ }
105
+ else if (!(signaturePtr = env->GetByteArrayElements(aSignatureBuffer, 0)))
106
+ {
107
+ LOGE(" ## verifyEd25519SignatureJni(): failure - signature JNI allocation OOM");
108
+ }
109
+ else if (!(keyPtr = env->GetByteArrayElements(aKeyBuffer, 0)))
110
+ {
111
+ LOGE(" ## verifyEd25519SignatureJni(): failure - key JNI allocation OOM");
112
+ }
113
+ else if (!(messagePtr = env->GetByteArrayElements(aMessageBuffer, &messageWasCopied)))
114
+ {
115
+ LOGE(" ## verifyEd25519SignatureJni(): failure - message JNI allocation OOM");
116
+ }
117
+ else
118
+ {
119
+ size_t signatureLength = (size_t)env->GetArrayLength(aSignatureBuffer);
120
+ size_t keyLength = (size_t)env->GetArrayLength(aKeyBuffer);
121
+ size_t messageLength = (size_t)env->GetArrayLength(aMessageBuffer);
122
+ LOGD(" ## verifyEd25519SignatureJni(): signatureLength=%lu keyLength=%lu messageLength=%lu",static_cast<long unsigned int>(signatureLength),static_cast<long unsigned int>(keyLength),static_cast<long unsigned int>(messageLength));
123
+ LOGD(" ## verifyEd25519SignatureJni(): key=%.*s", static_cast<int>(keyLength), keyPtr);
124
+
125
+ size_t result = olm_ed25519_verify(utilityPtr,
126
+ (void const *)keyPtr,
127
+ keyLength,
128
+ (void const *)messagePtr,
129
+ messageLength,
130
+ (void*)signaturePtr,
131
+ signatureLength);
132
+ if (result == olm_error()) {
133
+ const char *errorMsgPtr = olm_utility_last_error(utilityPtr);
134
+ errorMessageRetValue = env->NewStringUTF(errorMsgPtr);
135
+ LOGE("## verifyEd25519SignatureJni(): failure - olm_ed25519_verify Msg=%s",errorMsgPtr);
136
+ }
137
+ else
138
+ {
139
+ LOGD("## verifyEd25519SignatureJni(): success - result=%lu", static_cast<long unsigned int>(result));
140
+ }
141
+ }
142
+
143
+ // free alloc
144
+ if (signaturePtr)
145
+ {
146
+ env->ReleaseByteArrayElements(aSignatureBuffer, signaturePtr, JNI_ABORT);
147
+ }
148
+
149
+ if (keyPtr)
150
+ {
151
+ env->ReleaseByteArrayElements(aKeyBuffer, keyPtr, JNI_ABORT);
152
+ }
153
+
154
+ if (messagePtr)
155
+ {
156
+ if (messageWasCopied) {
157
+ memset(messagePtr, 0, (size_t)env->GetArrayLength(aMessageBuffer));
158
+ }
159
+ env->ReleaseByteArrayElements(aMessageBuffer, messagePtr, JNI_ABORT);
160
+ }
161
+
162
+ return errorMessageRetValue;
163
+ }
164
+
165
+ /**
166
+ * Compute the digest (SHA 256) for the message passed in parameter.<br>
167
+ * The digest value is the function return value.
168
+ * An exception is thrown if the operation fails.
169
+ * @param aMessage the message
170
+ * @return digest of the message.
171
+ **/
172
+ JNIEXPORT jbyteArray OLM_UTILITY_FUNC_DEF(sha256Jni)(JNIEnv *env, jobject thiz, jbyteArray aMessageToHashBuffer)
173
+ {
174
+ jbyteArray sha256Ret = 0;
175
+
176
+ OlmUtility* utilityPtr = getUtilityInstanceId(env, thiz);
177
+ jbyte* messagePtr = NULL;
178
+ jboolean messageWasCopied = JNI_FALSE;
179
+
180
+ LOGD("## sha256Jni(): IN");
181
+
182
+ if (!utilityPtr)
183
+ {
184
+ LOGE(" ## sha256Jni(): failure - invalid utility ptr=NULL");
185
+ }
186
+ else if(!aMessageToHashBuffer)
187
+ {
188
+ LOGE(" ## sha256Jni(): failure - invalid message parameters ");
189
+ }
190
+ else if(!(messagePtr = env->GetByteArrayElements(aMessageToHashBuffer, &messageWasCopied)))
191
+ {
192
+ LOGE(" ## sha256Jni(): failure - message JNI allocation OOM");
193
+ }
194
+ else
195
+ {
196
+ // get lengths
197
+ size_t messageLength = (size_t)env->GetArrayLength(aMessageToHashBuffer);
198
+ size_t hashLength = olm_sha256_length(utilityPtr);
199
+ void* hashValuePtr = malloc((hashLength)*sizeof(uint8_t));
200
+
201
+ if (!hashValuePtr)
202
+ {
203
+ LOGE("## sha256Jni(): failure - hash value allocation OOM");
204
+ }
205
+ else
206
+ {
207
+ size_t result = olm_sha256(utilityPtr,
208
+ (void const *)messagePtr,
209
+ messageLength,
210
+ (void *)hashValuePtr,
211
+ hashLength);
212
+ if (result == olm_error())
213
+ {
214
+ LOGE("## sha256Jni(): failure - hash creation Msg=%s",(const char *)olm_utility_last_error(utilityPtr));
215
+ }
216
+ else
217
+ {
218
+ LOGD("## sha256Jni(): success - result=%lu hashValue=%.*s",static_cast<long unsigned int>(result), static_cast<int>(result), (char*)hashValuePtr);
219
+ sha256Ret = env->NewByteArray(result);
220
+ env->SetByteArrayRegion(sha256Ret, 0 , result, (jbyte*)hashValuePtr);
221
+ }
222
+
223
+ free(hashValuePtr);
224
+ }
225
+ }
226
+
227
+ if (messagePtr)
228
+ {
229
+ if (messageWasCopied) {
230
+ memset(messagePtr, 0, (size_t)env->GetArrayLength(aMessageToHashBuffer));
231
+ }
232
+ env->ReleaseByteArrayElements(aMessageToHashBuffer, messagePtr, JNI_ABORT);
233
+ }
234
+
235
+ return sha256Ret;
236
+ }
@@ -0,0 +1,40 @@
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 _OMLUTILITY_H
19
+ #define _OMLUTILITY_H
20
+
21
+ #include "olm_jni.h"
22
+ #include "olm/olm.h"
23
+
24
+ #define OLM_UTILITY_FUNC_DEF(func_name) FUNC_DEF(OlmUtility,func_name)
25
+
26
+
27
+ #ifdef __cplusplus
28
+ extern "C" {
29
+ #endif
30
+ JNIEXPORT jlong OLM_UTILITY_FUNC_DEF(createUtilityJni)(JNIEnv *env, jobject thiz);
31
+ JNIEXPORT void OLM_UTILITY_FUNC_DEF(releaseUtilityJni)(JNIEnv *env, jobject thiz);
32
+ JNIEXPORT jstring OLM_UTILITY_FUNC_DEF(verifyEd25519SignatureJni)(JNIEnv *env, jobject thiz, jbyteArray aSignature, jbyteArray aKey, jbyteArray aMessage);
33
+ JNIEXPORT jbyteArray OLM_UTILITY_FUNC_DEF(sha256Jni)(JNIEnv *env, jobject thiz, jbyteArray aMessageToHash);
34
+ #ifdef __cplusplus
35
+ }
36
+ #endif
37
+
38
+
39
+
40
+ #endif
@@ -0,0 +1,14 @@
1
+ #include "olm/message.hh"
2
+ #include "fuzzing.hh"
3
+
4
+ int main(int argc, const char *argv[]) {
5
+ int message_fd = STDIN_FILENO;
6
+ uint8_t * message_buffer;
7
+ ssize_t message_length = check_errno(
8
+ "Error reading message file", read_file(message_fd, &message_buffer)
9
+ );
10
+ olm::MessageReader * reader = new olm::MessageReader;
11
+ decode_message(*reader, message_buffer, message_length, 8);
12
+ free(message_buffer);
13
+ delete reader;
14
+ }
@@ -0,0 +1,65 @@
1
+ #include "olm/olm.hh"
2
+
3
+ #include "fuzzing.hh"
4
+
5
+ int main(int argc, const char *argv[]) {
6
+ size_t ignored;
7
+ if (argc <= 3) {
8
+ const char * message = "Usage: decrypt: <session_key> <session_file>"
9
+ " <message_type>\n";
10
+ ignored = write(STDERR_FILENO, message, strlen(message));
11
+ exit(3);
12
+ }
13
+
14
+ const char * key = argv[1];
15
+ size_t key_length = strlen(key);
16
+
17
+
18
+ int session_fd = check_errno(
19
+ "Error opening session file", open(argv[2], O_RDONLY)
20
+ );
21
+
22
+ int message_type = atoi(argv[3]);
23
+
24
+ uint8_t *session_buffer;
25
+ ssize_t session_length = check_errno(
26
+ "Error reading session file", read_file(session_fd, &session_buffer)
27
+ );
28
+
29
+ int message_fd = STDIN_FILENO;
30
+ uint8_t * message_buffer;
31
+ ssize_t message_length = check_errno(
32
+ "Error reading message file", read_file(message_fd, &message_buffer)
33
+ );
34
+
35
+ uint8_t * tmp_buffer = (uint8_t *) malloc(message_length);
36
+ memcpy(tmp_buffer, message_buffer, message_length);
37
+
38
+ uint8_t session_memory[olm_session_size()];
39
+ OlmSession * session = olm_session(session_memory);
40
+ check_session(session, "Error unpickling session", olm_unpickle_session(
41
+ session, key, key_length, session_buffer, session_length
42
+ ));
43
+
44
+ size_t max_length = check_session(
45
+ session,
46
+ "Error getting plaintext length",
47
+ olm_decrypt_max_plaintext_length(
48
+ session, message_type, tmp_buffer, message_length
49
+ )
50
+ );
51
+
52
+ uint8_t plaintext[max_length];
53
+
54
+ size_t length = check_session(
55
+ session, "Error decrypting message", olm_decrypt(
56
+ session, message_type,
57
+ message_buffer, message_length,
58
+ plaintext, max_length
59
+ )
60
+ );
61
+
62
+ ignored = write(STDOUT_FILENO, plaintext, length);
63
+ ignored = write(STDOUT_FILENO, "\n", 1);
64
+ return ignored;
65
+ }
@@ -0,0 +1,73 @@
1
+ #include "olm/olm.hh"
2
+
3
+ #include "fuzzing.hh"
4
+
5
+ int main(int argc, const char *argv[]) {
6
+ size_t ignored;
7
+ if (argc <= 2) {
8
+ const char * message = "Usage: decrypt <pickle_key> <group_session>\n";
9
+ ignored = write(STDERR_FILENO, message, strlen(message));
10
+ exit(3);
11
+ }
12
+
13
+ const char * key = argv[1];
14
+ size_t key_length = strlen(key);
15
+
16
+
17
+ int session_fd = check_errno(
18
+ "Error opening session file", open(argv[2], O_RDONLY)
19
+ );
20
+
21
+ uint8_t *session_buffer;
22
+ ssize_t session_length = check_errno(
23
+ "Error reading session file", read_file(session_fd, &session_buffer)
24
+ );
25
+
26
+ int message_fd = STDIN_FILENO;
27
+ uint8_t * message_buffer;
28
+ ssize_t message_length = check_errno(
29
+ "Error reading message file", read_file(message_fd, &message_buffer)
30
+ );
31
+
32
+ uint8_t * tmp_buffer = (uint8_t *) malloc(message_length);
33
+ memcpy(tmp_buffer, message_buffer, message_length);
34
+
35
+ uint8_t session_memory[olm_inbound_group_session_size()];
36
+ OlmInboundGroupSession * session = olm_inbound_group_session(session_memory);
37
+ check_error(
38
+ olm_inbound_group_session_last_error,
39
+ session,
40
+ "Error unpickling session",
41
+ olm_unpickle_inbound_group_session(
42
+ session, key, key_length, session_buffer, session_length
43
+ )
44
+ );
45
+
46
+ size_t max_length = check_error(
47
+ olm_inbound_group_session_last_error,
48
+ session,
49
+ "Error getting plaintext length",
50
+ olm_group_decrypt_max_plaintext_length(
51
+ session, tmp_buffer, message_length
52
+ )
53
+ );
54
+
55
+ uint8_t plaintext[max_length];
56
+
57
+ uint32_t ratchet_index;
58
+
59
+ size_t length = check_error(
60
+ olm_inbound_group_session_last_error,
61
+ session,
62
+ "Error decrypting message",
63
+ olm_group_decrypt(
64
+ session,
65
+ message_buffer, message_length,
66
+ plaintext, max_length, &ratchet_index
67
+ )
68
+ );
69
+
70
+ ignored = write(STDOUT_FILENO, plaintext, length);
71
+ ignored = write(STDOUT_FILENO, "\n", 1);
72
+ return ignored;
73
+ }
@@ -0,0 +1,14 @@
1
+ #include "olm/account.hh"
2
+ #include "fuzzing.hh"
3
+
4
+ int main(int argc, const char *argv[]) {
5
+ int pickle_fd = STDIN_FILENO;
6
+ uint8_t * pickle_buffer;
7
+ ssize_t pickle_length = check_errno(
8
+ "Error reading pickle file", read_file(pickle_fd, &pickle_buffer)
9
+ );
10
+ olm::Account * account = new olm::Account;
11
+ unpickle(pickle_buffer, pickle_buffer + pickle_length, *account);
12
+ free(pickle_buffer);
13
+ delete account;
14
+ }
@@ -0,0 +1,14 @@
1
+ #include "olm/session.hh"
2
+ #include "fuzzing.hh"
3
+
4
+ int main(int argc, const char *argv[]) {
5
+ int pickle_fd = STDIN_FILENO;
6
+ uint8_t * pickle_buffer;
7
+ ssize_t pickle_length = check_errno(
8
+ "Error reading pickle file", read_file(pickle_fd, &pickle_buffer)
9
+ );
10
+ olm::Session * session = new olm::Session;
11
+ unpickle(pickle_buffer, pickle_buffer + pickle_length, *session);
12
+ free(pickle_buffer);
13
+ delete session;
14
+ }
@@ -0,0 +1,82 @@
1
+ #include "olm/olm.hh"
2
+
3
+ #include <stdio.h>
4
+ #include <stdlib.h>
5
+ #include <unistd.h>
6
+ #include <stddef.h>
7
+ #include <string.h>
8
+ #include <sys/types.h>
9
+ #include <sys/stat.h>
10
+ #include <fcntl.h>
11
+
12
+
13
+ ssize_t read_file(
14
+ int fd,
15
+ uint8_t **buffer
16
+ ) {
17
+ size_t buffer_size = 4096;
18
+ uint8_t * current_buffer = (uint8_t *) malloc(buffer_size);
19
+ if (current_buffer == NULL) return -1;
20
+ size_t buffer_pos = 0;
21
+ while (1) {
22
+ ssize_t count = read(
23
+ fd, current_buffer + buffer_pos, buffer_size - buffer_pos
24
+ );
25
+ if (count < 0) break;
26
+ if (count == 0) {
27
+ uint8_t * return_buffer = (uint8_t *) realloc(current_buffer, buffer_pos);
28
+ if (return_buffer == NULL) break;
29
+ *buffer = return_buffer;
30
+ return buffer_pos;
31
+ }
32
+ buffer_pos += count;
33
+ if (buffer_pos == buffer_size) {
34
+ buffer_size *= 2;
35
+ uint8_t * new_buffer = (uint8_t *) realloc(current_buffer, buffer_size);
36
+ if (new_buffer == NULL) break;
37
+ current_buffer = new_buffer;
38
+ }
39
+ }
40
+ free(current_buffer);
41
+ return -1;
42
+ }
43
+
44
+ template<typename T>
45
+ T check_errno(
46
+ const char * message,
47
+ T value
48
+ ) {
49
+ if (value == T(-1)) {
50
+ perror(message);
51
+ exit(1);
52
+ }
53
+ return value;
54
+ }
55
+
56
+ template<typename T, typename F>
57
+ size_t check_error(
58
+ F f,
59
+ T * object,
60
+ const char * message,
61
+ size_t value
62
+ ) {
63
+ if (value == olm_error()) {
64
+ const char * olm_message = f(object);
65
+ ssize_t ignored;
66
+ ignored = write(STDERR_FILENO, message, strlen(message));
67
+ ignored = write(STDERR_FILENO, ": ", 2);
68
+ ignored = write(STDERR_FILENO, olm_message, strlen(olm_message));
69
+ ignored = write(STDERR_FILENO, "\n", 1);
70
+ exit(2);
71
+ return ignored;
72
+ }
73
+ return value;
74
+ }
75
+
76
+ size_t check_session(
77
+ OlmSession * session,
78
+ const char * message,
79
+ size_t value
80
+ ) {
81
+ return check_error(olm_session_last_error, session, message, value);
82
+ }