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,246 @@
|
|
|
1
|
+
/* Copyright 2015 OpenMarket Ltd
|
|
2
|
+
*
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
#include "olm/crypto.h"
|
|
16
|
+
|
|
17
|
+
#include "unittest.hh"
|
|
18
|
+
|
|
19
|
+
int main() {
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
{ /* Curve25529 Test Case 1 */
|
|
23
|
+
|
|
24
|
+
TestCase test_case("Curve25529 Test Case 1");
|
|
25
|
+
|
|
26
|
+
std::uint8_t alice_private[32] = {
|
|
27
|
+
0x77, 0x07, 0x6D, 0x0A, 0x73, 0x18, 0xA5, 0x7D,
|
|
28
|
+
0x3C, 0x16, 0xC1, 0x72, 0x51, 0xB2, 0x66, 0x45,
|
|
29
|
+
0xDF, 0x4C, 0x2F, 0x87, 0xEB, 0xC0, 0x99, 0x2A,
|
|
30
|
+
0xB1, 0x77, 0xFB, 0xA5, 0x1D, 0xB9, 0x2C, 0x2A
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
std::uint8_t alice_public[32] = {
|
|
34
|
+
0x85, 0x20, 0xF0, 0x09, 0x89, 0x30, 0xA7, 0x54,
|
|
35
|
+
0x74, 0x8B, 0x7D, 0xDC, 0xB4, 0x3E, 0xF7, 0x5A,
|
|
36
|
+
0x0D, 0xBF, 0x3A, 0x0D, 0x26, 0x38, 0x1A, 0xF4,
|
|
37
|
+
0xEB, 0xA4, 0xA9, 0x8E, 0xAA, 0x9B, 0x4E, 0x6A
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
std::uint8_t bob_private[32] = {
|
|
41
|
+
0x5D, 0xAB, 0x08, 0x7E, 0x62, 0x4A, 0x8A, 0x4B,
|
|
42
|
+
0x79, 0xE1, 0x7F, 0x8B, 0x83, 0x80, 0x0E, 0xE6,
|
|
43
|
+
0x6F, 0x3B, 0xB1, 0x29, 0x26, 0x18, 0xB6, 0xFD,
|
|
44
|
+
0x1C, 0x2F, 0x8B, 0x27, 0xFF, 0x88, 0xE0, 0xEB
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
std::uint8_t bob_public[32] = {
|
|
48
|
+
0xDE, 0x9E, 0xDB, 0x7D, 0x7B, 0x7D, 0xC1, 0xB4,
|
|
49
|
+
0xD3, 0x5B, 0x61, 0xC2, 0xEC, 0xE4, 0x35, 0x37,
|
|
50
|
+
0x3F, 0x83, 0x43, 0xC8, 0x5B, 0x78, 0x67, 0x4D,
|
|
51
|
+
0xAD, 0xFC, 0x7E, 0x14, 0x6F, 0x88, 0x2B, 0x4F
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
std::uint8_t expected_agreement[32] = {
|
|
55
|
+
0x4A, 0x5D, 0x9D, 0x5B, 0xA4, 0xCE, 0x2D, 0xE1,
|
|
56
|
+
0x72, 0x8E, 0x3B, 0xF4, 0x80, 0x35, 0x0F, 0x25,
|
|
57
|
+
0xE0, 0x7E, 0x21, 0xC9, 0x47, 0xD1, 0x9E, 0x33,
|
|
58
|
+
0x76, 0xF0, 0x9B, 0x3C, 0x1E, 0x16, 0x17, 0x42
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
_olm_curve25519_key_pair alice_pair;
|
|
62
|
+
_olm_crypto_curve25519_generate_key(alice_private, &alice_pair);
|
|
63
|
+
|
|
64
|
+
assert_equals(alice_private, alice_pair.private_key.private_key, 32);
|
|
65
|
+
assert_equals(alice_public, alice_pair.public_key.public_key, 32);
|
|
66
|
+
|
|
67
|
+
_olm_curve25519_key_pair bob_pair;
|
|
68
|
+
_olm_crypto_curve25519_generate_key(bob_private, &bob_pair);
|
|
69
|
+
|
|
70
|
+
assert_equals(bob_private, bob_pair.private_key.private_key, 32);
|
|
71
|
+
assert_equals(bob_public, bob_pair.public_key.public_key, 32);
|
|
72
|
+
|
|
73
|
+
std::uint8_t actual_agreement[CURVE25519_SHARED_SECRET_LENGTH] = {};
|
|
74
|
+
|
|
75
|
+
_olm_crypto_curve25519_shared_secret(&alice_pair, &bob_pair.public_key, actual_agreement);
|
|
76
|
+
|
|
77
|
+
assert_equals(expected_agreement, actual_agreement, 32);
|
|
78
|
+
|
|
79
|
+
_olm_crypto_curve25519_shared_secret(&bob_pair, &alice_pair.public_key, actual_agreement);
|
|
80
|
+
|
|
81
|
+
assert_equals(expected_agreement, actual_agreement, 32);
|
|
82
|
+
|
|
83
|
+
} /* Curve25529 Test Case 1 */
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
{
|
|
87
|
+
TestCase test_case("Ed25519 Signature Test Case 1");
|
|
88
|
+
std::uint8_t private_key[33] = "This key is a string of 32 bytes";
|
|
89
|
+
|
|
90
|
+
std::uint8_t message[] = "Hello, World";
|
|
91
|
+
std::size_t message_length = sizeof(message) - 1;
|
|
92
|
+
|
|
93
|
+
_olm_ed25519_key_pair key_pair;
|
|
94
|
+
_olm_crypto_ed25519_generate_key(private_key, &key_pair);
|
|
95
|
+
|
|
96
|
+
std::uint8_t signature[64];
|
|
97
|
+
_olm_crypto_ed25519_sign(
|
|
98
|
+
&key_pair, message, message_length, signature
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
bool result = _olm_crypto_ed25519_verify(
|
|
102
|
+
&key_pair.public_key, message, message_length, signature
|
|
103
|
+
);
|
|
104
|
+
assert_equals(true, result);
|
|
105
|
+
|
|
106
|
+
message[0] = 'n';
|
|
107
|
+
result = _olm_crypto_ed25519_verify(
|
|
108
|
+
&key_pair.public_key, message, message_length, signature
|
|
109
|
+
);
|
|
110
|
+
assert_equals(false, result);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
{ /* AES Test Case 1 */
|
|
115
|
+
|
|
116
|
+
TestCase test_case("AES Test Case 1");
|
|
117
|
+
|
|
118
|
+
_olm_aes256_key key = {};
|
|
119
|
+
_olm_aes256_iv iv = {};
|
|
120
|
+
std::uint8_t input[16] = {};
|
|
121
|
+
|
|
122
|
+
std::uint8_t expected[32] = {
|
|
123
|
+
0xDC, 0x95, 0xC0, 0x78, 0xA2, 0x40, 0x89, 0x89,
|
|
124
|
+
0xAD, 0x48, 0xA2, 0x14, 0x92, 0x84, 0x20, 0x87,
|
|
125
|
+
0xF3, 0xC0, 0x03, 0xDD, 0xC4, 0xA7, 0xB8, 0xA9,
|
|
126
|
+
0x4B, 0xAE, 0xDF, 0xFC, 0x3D, 0x21, 0x4C, 0x38
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
std::size_t length = _olm_crypto_aes_encrypt_cbc_length(sizeof(input));
|
|
130
|
+
assert_equals(std::size_t(32), length);
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
std::uint8_t actual[32] = {};
|
|
134
|
+
|
|
135
|
+
_olm_crypto_aes_encrypt_cbc(&key, &iv, input, sizeof(input), actual);
|
|
136
|
+
assert_equals(expected, actual, 32);
|
|
137
|
+
|
|
138
|
+
length = _olm_crypto_aes_decrypt_cbc(&key, &iv, expected, sizeof(expected), actual);
|
|
139
|
+
assert_equals(std::size_t(16), length);
|
|
140
|
+
assert_equals(input, actual, length);
|
|
141
|
+
|
|
142
|
+
} /* AES Test Case 1 */
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
{ /* SHA 256 Test Case 1 */
|
|
146
|
+
|
|
147
|
+
TestCase test_case("SHA 256 Test Case 1");
|
|
148
|
+
|
|
149
|
+
std::uint8_t input[0] = {};
|
|
150
|
+
|
|
151
|
+
std::uint8_t expected[32] = {
|
|
152
|
+
0xE3, 0xB0, 0xC4, 0x42, 0x98, 0xFC, 0x1C, 0x14,
|
|
153
|
+
0x9A, 0xFB, 0xF4, 0xC8, 0x99, 0x6F, 0xB9, 0x24,
|
|
154
|
+
0x27, 0xAE, 0x41, 0xE4, 0x64, 0x9B, 0x93, 0x4C,
|
|
155
|
+
0xA4, 0x95, 0x99, 0x1B, 0x78, 0x52, 0xB8, 0x55
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
std::uint8_t actual[32];
|
|
159
|
+
|
|
160
|
+
_olm_crypto_sha256(input, sizeof(input), actual);
|
|
161
|
+
|
|
162
|
+
assert_equals(expected, actual, 32);
|
|
163
|
+
|
|
164
|
+
} /* SHA 256 Test Case 1 */
|
|
165
|
+
|
|
166
|
+
{ /* HMAC Test Case 1 */
|
|
167
|
+
|
|
168
|
+
TestCase test_case("HMAC Test Case 1");
|
|
169
|
+
|
|
170
|
+
std::uint8_t input[0] = {};
|
|
171
|
+
|
|
172
|
+
std::uint8_t expected[32] = {
|
|
173
|
+
0xb6, 0x13, 0x67, 0x9a, 0x08, 0x14, 0xd9, 0xec,
|
|
174
|
+
0x77, 0x2f, 0x95, 0xd7, 0x78, 0xc3, 0x5f, 0xc5,
|
|
175
|
+
0xff, 0x16, 0x97, 0xc4, 0x93, 0x71, 0x56, 0x53,
|
|
176
|
+
0xc6, 0xc7, 0x12, 0x14, 0x42, 0x92, 0xc5, 0xad
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
std::uint8_t actual[32];
|
|
180
|
+
|
|
181
|
+
_olm_crypto_hmac_sha256(input, sizeof(input), input, sizeof(input), actual);
|
|
182
|
+
|
|
183
|
+
assert_equals(expected, actual, 32);
|
|
184
|
+
|
|
185
|
+
} /* HMAC Test Case 1 */
|
|
186
|
+
|
|
187
|
+
{ /* HDKF Test Case 1 */
|
|
188
|
+
|
|
189
|
+
TestCase test_case("HDKF Test Case 1");
|
|
190
|
+
|
|
191
|
+
std::uint8_t input[22] = {
|
|
192
|
+
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
|
|
193
|
+
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
|
|
194
|
+
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
std::uint8_t salt[13] = {
|
|
198
|
+
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
|
199
|
+
0x08, 0x09, 0x0a, 0x0b, 0x0c
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
std::uint8_t info[10] = {
|
|
203
|
+
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
|
|
204
|
+
0xf8, 0xf9
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
std::uint8_t hmac_expected_output[32] = {
|
|
208
|
+
0x07, 0x77, 0x09, 0x36, 0x2c, 0x2e, 0x32, 0xdf,
|
|
209
|
+
0x0d, 0xdc, 0x3f, 0x0d, 0xc4, 0x7b, 0xba, 0x63,
|
|
210
|
+
0x90, 0xb6, 0xc7, 0x3b, 0xb5, 0x0f, 0x9c, 0x31,
|
|
211
|
+
0x22, 0xec, 0x84, 0x4a, 0xd7, 0xc2, 0xb3, 0xe5,
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
std::uint8_t hmac_actual_output[32] = {};
|
|
215
|
+
|
|
216
|
+
_olm_crypto_hmac_sha256(
|
|
217
|
+
salt, sizeof(salt),
|
|
218
|
+
input, sizeof(input),
|
|
219
|
+
hmac_actual_output
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
assert_equals(hmac_expected_output, hmac_actual_output, 32);
|
|
223
|
+
|
|
224
|
+
std::uint8_t hkdf_expected_output[42] = {
|
|
225
|
+
0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a,
|
|
226
|
+
0x90, 0x43, 0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a,
|
|
227
|
+
0x2d, 0x2d, 0x0a, 0x90, 0xcf, 0x1a, 0x5a, 0x4c,
|
|
228
|
+
0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4, 0xc5, 0xbf,
|
|
229
|
+
0x34, 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18,
|
|
230
|
+
0x58, 0x65
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
std::uint8_t hkdf_actual_output[42] = {};
|
|
234
|
+
|
|
235
|
+
_olm_crypto_hkdf_sha256(
|
|
236
|
+
input, sizeof(input),
|
|
237
|
+
salt, sizeof(salt),
|
|
238
|
+
info, sizeof(info),
|
|
239
|
+
hkdf_actual_output, sizeof(hkdf_actual_output)
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
assert_equals(hkdf_expected_output, hkdf_actual_output, 42);
|
|
243
|
+
|
|
244
|
+
} /* HDKF Test Case 1 */
|
|
245
|
+
|
|
246
|
+
}
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
/* Copyright 2016 OpenMarket Ltd
|
|
2
|
+
*
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
#include "olm/inbound_group_session.h"
|
|
16
|
+
#include "olm/outbound_group_session.h"
|
|
17
|
+
#include "unittest.hh"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
int main() {
|
|
21
|
+
|
|
22
|
+
{
|
|
23
|
+
TestCase test_case("Pickle outbound group session");
|
|
24
|
+
|
|
25
|
+
size_t size = olm_outbound_group_session_size();
|
|
26
|
+
uint8_t memory[size];
|
|
27
|
+
OlmOutboundGroupSession *session = olm_outbound_group_session(memory);
|
|
28
|
+
|
|
29
|
+
size_t pickle_length = olm_pickle_outbound_group_session_length(session);
|
|
30
|
+
uint8_t pickle1[pickle_length];
|
|
31
|
+
size_t res = olm_pickle_outbound_group_session(
|
|
32
|
+
session, "secret_key", 10, pickle1, pickle_length
|
|
33
|
+
);
|
|
34
|
+
assert_equals(pickle_length, res);
|
|
35
|
+
|
|
36
|
+
uint8_t pickle2[pickle_length];
|
|
37
|
+
memcpy(pickle2, pickle1, pickle_length);
|
|
38
|
+
|
|
39
|
+
uint8_t buffer2[size];
|
|
40
|
+
OlmOutboundGroupSession *session2 = olm_outbound_group_session(buffer2);
|
|
41
|
+
res = olm_unpickle_outbound_group_session(
|
|
42
|
+
session2, "secret_key", 10, pickle2, pickle_length
|
|
43
|
+
);
|
|
44
|
+
assert_not_equals((size_t)-1, res);
|
|
45
|
+
assert_equals(pickle_length,
|
|
46
|
+
olm_pickle_outbound_group_session_length(session2));
|
|
47
|
+
res = olm_pickle_outbound_group_session(
|
|
48
|
+
session2, "secret_key", 10, pickle2, pickle_length
|
|
49
|
+
);
|
|
50
|
+
assert_equals(pickle_length, res);
|
|
51
|
+
|
|
52
|
+
assert_equals(pickle1, pickle2, pickle_length);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
{
|
|
57
|
+
TestCase test_case("Pickle inbound group session");
|
|
58
|
+
|
|
59
|
+
size_t size = olm_inbound_group_session_size();
|
|
60
|
+
uint8_t memory[size];
|
|
61
|
+
OlmInboundGroupSession *session = olm_inbound_group_session(memory);
|
|
62
|
+
|
|
63
|
+
size_t pickle_length = olm_pickle_inbound_group_session_length(session);
|
|
64
|
+
uint8_t pickle1[pickle_length];
|
|
65
|
+
size_t res = olm_pickle_inbound_group_session(
|
|
66
|
+
session, "secret_key", 10, pickle1, pickle_length
|
|
67
|
+
);
|
|
68
|
+
assert_equals(pickle_length, res);
|
|
69
|
+
|
|
70
|
+
uint8_t pickle2[pickle_length];
|
|
71
|
+
memcpy(pickle2, pickle1, pickle_length);
|
|
72
|
+
|
|
73
|
+
uint8_t buffer2[size];
|
|
74
|
+
OlmInboundGroupSession *session2 = olm_inbound_group_session(buffer2);
|
|
75
|
+
res = olm_unpickle_inbound_group_session(
|
|
76
|
+
session2, "secret_key", 10, pickle2, pickle_length
|
|
77
|
+
);
|
|
78
|
+
assert_not_equals((size_t)-1, res);
|
|
79
|
+
assert_equals(pickle_length,
|
|
80
|
+
olm_pickle_inbound_group_session_length(session2));
|
|
81
|
+
res = olm_pickle_inbound_group_session(
|
|
82
|
+
session2, "secret_key", 10, pickle2, pickle_length
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
assert_equals(pickle1, pickle2, pickle_length);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
{
|
|
89
|
+
TestCase test_case("Group message send/receive");
|
|
90
|
+
|
|
91
|
+
uint8_t random_bytes[] =
|
|
92
|
+
"0123456789ABDEF0123456789ABCDEF"
|
|
93
|
+
"0123456789ABDEF0123456789ABCDEF"
|
|
94
|
+
"0123456789ABDEF0123456789ABCDEF"
|
|
95
|
+
"0123456789ABDEF0123456789ABCDEF"
|
|
96
|
+
"0123456789ABDEF0123456789ABCDEF"
|
|
97
|
+
"0123456789ABDEF0123456789ABCDEF";
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
/* build the outbound session */
|
|
101
|
+
size_t size = olm_outbound_group_session_size();
|
|
102
|
+
uint8_t memory[size];
|
|
103
|
+
OlmOutboundGroupSession *session = olm_outbound_group_session(memory);
|
|
104
|
+
|
|
105
|
+
assert_equals((size_t)160,
|
|
106
|
+
olm_init_outbound_group_session_random_length(session));
|
|
107
|
+
|
|
108
|
+
size_t res = olm_init_outbound_group_session(
|
|
109
|
+
session, random_bytes, sizeof(random_bytes));
|
|
110
|
+
assert_equals((size_t)0, res);
|
|
111
|
+
|
|
112
|
+
assert_equals(0U, olm_outbound_group_session_message_index(session));
|
|
113
|
+
size_t session_key_len = olm_outbound_group_session_key_length(session);
|
|
114
|
+
uint8_t session_key[session_key_len];
|
|
115
|
+
olm_outbound_group_session_key(session, session_key, session_key_len);
|
|
116
|
+
|
|
117
|
+
/* encode the message */
|
|
118
|
+
uint8_t plaintext[] = "Message";
|
|
119
|
+
size_t plaintext_length = sizeof(plaintext) - 1;
|
|
120
|
+
|
|
121
|
+
size_t msglen = olm_group_encrypt_message_length(
|
|
122
|
+
session, plaintext_length);
|
|
123
|
+
|
|
124
|
+
uint8_t msg[msglen];
|
|
125
|
+
res = olm_group_encrypt(session, plaintext, plaintext_length,
|
|
126
|
+
msg, msglen);
|
|
127
|
+
assert_equals(msglen, res);
|
|
128
|
+
assert_equals(1U, olm_outbound_group_session_message_index(session));
|
|
129
|
+
|
|
130
|
+
/* build the inbound session */
|
|
131
|
+
size = olm_inbound_group_session_size();
|
|
132
|
+
uint8_t inbound_session_memory[size];
|
|
133
|
+
OlmInboundGroupSession *inbound_session =
|
|
134
|
+
olm_inbound_group_session(inbound_session_memory);
|
|
135
|
+
|
|
136
|
+
assert_equals(0, olm_inbound_group_session_is_verified(inbound_session));
|
|
137
|
+
|
|
138
|
+
res = olm_init_inbound_group_session(
|
|
139
|
+
inbound_session, session_key, session_key_len);
|
|
140
|
+
assert_equals((size_t)0, res);
|
|
141
|
+
assert_equals(1, olm_inbound_group_session_is_verified(inbound_session));
|
|
142
|
+
|
|
143
|
+
/* Check the session ids */
|
|
144
|
+
|
|
145
|
+
size_t out_session_id_len = olm_outbound_group_session_id_length(session);
|
|
146
|
+
uint8_t out_session_id[out_session_id_len];
|
|
147
|
+
assert_equals(out_session_id_len, olm_outbound_group_session_id(
|
|
148
|
+
session, out_session_id, out_session_id_len
|
|
149
|
+
));
|
|
150
|
+
|
|
151
|
+
size_t in_session_id_len = olm_inbound_group_session_id_length(
|
|
152
|
+
inbound_session
|
|
153
|
+
);
|
|
154
|
+
uint8_t in_session_id[in_session_id_len];
|
|
155
|
+
assert_equals(in_session_id_len, olm_inbound_group_session_id(
|
|
156
|
+
inbound_session, in_session_id, in_session_id_len
|
|
157
|
+
));
|
|
158
|
+
|
|
159
|
+
assert_equals(in_session_id_len, out_session_id_len);
|
|
160
|
+
assert_equals(out_session_id, in_session_id, in_session_id_len);
|
|
161
|
+
|
|
162
|
+
/* decode the message */
|
|
163
|
+
|
|
164
|
+
/* olm_group_decrypt_max_plaintext_length destroys the input so we have to
|
|
165
|
+
copy it. */
|
|
166
|
+
uint8_t msgcopy[msglen];
|
|
167
|
+
memcpy(msgcopy, msg, msglen);
|
|
168
|
+
size = olm_group_decrypt_max_plaintext_length(inbound_session, msgcopy, msglen);
|
|
169
|
+
uint8_t plaintext_buf[size];
|
|
170
|
+
uint32_t message_index;
|
|
171
|
+
res = olm_group_decrypt(inbound_session, msg, msglen,
|
|
172
|
+
plaintext_buf, size, &message_index);
|
|
173
|
+
assert_equals(plaintext_length, res);
|
|
174
|
+
assert_equals(plaintext, plaintext_buf, res);
|
|
175
|
+
assert_equals(message_index, uint32_t(0));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
{
|
|
179
|
+
TestCase test_case("Inbound group session export/import");
|
|
180
|
+
|
|
181
|
+
uint8_t session_key[] =
|
|
182
|
+
"AgAAAAAwMTIzNDU2Nzg5QUJERUYwMTIzNDU2Nzg5QUJDREVGMDEyMzQ1Njc4OUFCREVGM"
|
|
183
|
+
"DEyMzQ1Njc4OUFCQ0RFRjAxMjM0NTY3ODlBQkRFRjAxMjM0NTY3ODlBQkNERUYwMTIzND"
|
|
184
|
+
"U2Nzg5QUJERUYwMTIzNDU2Nzg5QUJDREVGMDEyMw0bdg1BDq4Px/slBow06q8n/B9WBfw"
|
|
185
|
+
"WYyNOB8DlUmXGGwrFmaSb9bR/eY8xgERrxmP07hFmD9uqA2p8PMHdnV5ysmgufE6oLZ5+"
|
|
186
|
+
"8/mWQOW3VVTnDIlnwd8oHUYRuk8TCQ";
|
|
187
|
+
|
|
188
|
+
const uint8_t message[] =
|
|
189
|
+
"AwgAEhAcbh6UpbByoyZxufQ+h2B+8XHMjhR69G8F4+qjMaFlnIXusJZX3r8LnRORG9T3D"
|
|
190
|
+
"XFdbVuvIWrLyRfm4i8QRbe8VPwGRFG57B1CtmxanuP8bHtnnYqlwPsD";
|
|
191
|
+
const std::size_t msglen = sizeof(message)-1;
|
|
192
|
+
|
|
193
|
+
/* init first inbound group session, and decrypt */
|
|
194
|
+
std::size_t size = olm_inbound_group_session_size();
|
|
195
|
+
uint8_t session_memory1[size];
|
|
196
|
+
OlmInboundGroupSession *session1 =
|
|
197
|
+
olm_inbound_group_session(session_memory1);
|
|
198
|
+
assert_equals(0, olm_inbound_group_session_is_verified(session1));
|
|
199
|
+
|
|
200
|
+
std::size_t res = olm_init_inbound_group_session(
|
|
201
|
+
session1, session_key, sizeof(session_key)-1
|
|
202
|
+
);
|
|
203
|
+
assert_equals((size_t)0, res);
|
|
204
|
+
assert_equals(1, olm_inbound_group_session_is_verified(session1));
|
|
205
|
+
|
|
206
|
+
/* olm_group_decrypt_max_plaintext_length destroys the input so we have to
|
|
207
|
+
copy it. */
|
|
208
|
+
uint8_t msgcopy[msglen];
|
|
209
|
+
memcpy(msgcopy, message, msglen);
|
|
210
|
+
size = olm_group_decrypt_max_plaintext_length(session1, msgcopy, msglen);
|
|
211
|
+
uint8_t plaintext_buf[size];
|
|
212
|
+
uint32_t message_index;
|
|
213
|
+
memcpy(msgcopy, message, msglen);
|
|
214
|
+
res = olm_group_decrypt(
|
|
215
|
+
session1, msgcopy, msglen, plaintext_buf, size, &message_index
|
|
216
|
+
);
|
|
217
|
+
assert_equals((std::size_t)7, res);
|
|
218
|
+
assert_equals((const uint8_t *)"Message", plaintext_buf, res);
|
|
219
|
+
assert_equals(uint32_t(0), message_index);
|
|
220
|
+
|
|
221
|
+
/* export the keys */
|
|
222
|
+
size = olm_export_inbound_group_session_length(session1);
|
|
223
|
+
uint8_t export_memory[size];
|
|
224
|
+
res = olm_export_inbound_group_session(
|
|
225
|
+
session1, export_memory, size, 0
|
|
226
|
+
);
|
|
227
|
+
assert_equals(size, res);
|
|
228
|
+
|
|
229
|
+
/* free the old session to check there is no shared data */
|
|
230
|
+
olm_clear_inbound_group_session(session1);
|
|
231
|
+
|
|
232
|
+
/* import the keys into another inbound group session */
|
|
233
|
+
size = olm_inbound_group_session_size();
|
|
234
|
+
uint8_t session_memory2[size];
|
|
235
|
+
OlmInboundGroupSession *session2 =
|
|
236
|
+
olm_inbound_group_session(session_memory2);
|
|
237
|
+
res = olm_import_inbound_group_session(
|
|
238
|
+
session2, export_memory, sizeof(export_memory)
|
|
239
|
+
);
|
|
240
|
+
assert_equals((size_t)0, res);
|
|
241
|
+
assert_equals(0, olm_inbound_group_session_is_verified(session2));
|
|
242
|
+
|
|
243
|
+
/* decrypt the message with the new session */
|
|
244
|
+
memcpy(msgcopy, message, msglen);
|
|
245
|
+
size = olm_group_decrypt_max_plaintext_length(session2, msgcopy, msglen);
|
|
246
|
+
uint8_t plaintext_buf2[size];
|
|
247
|
+
memcpy(msgcopy, message, msglen);
|
|
248
|
+
res = olm_group_decrypt(
|
|
249
|
+
session2, msgcopy, msglen, plaintext_buf2, size, &message_index
|
|
250
|
+
);
|
|
251
|
+
assert_equals((std::size_t)7, res);
|
|
252
|
+
assert_equals((const uint8_t *)"Message", plaintext_buf2, res);
|
|
253
|
+
assert_equals(uint32_t(0), message_index);
|
|
254
|
+
assert_equals(1, olm_inbound_group_session_is_verified(session2));
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
{
|
|
258
|
+
TestCase test_case("Invalid signature group message");
|
|
259
|
+
|
|
260
|
+
uint8_t plaintext[] = "Message";
|
|
261
|
+
size_t plaintext_length = sizeof(plaintext) - 1;
|
|
262
|
+
|
|
263
|
+
uint8_t session_key[] =
|
|
264
|
+
"AgAAAAAwMTIzNDU2Nzg5QUJERUYwMTIzNDU2Nzg5QUJDREVGMDEyMzQ1Njc4OUFCREVGM"
|
|
265
|
+
"DEyMzQ1Njc4OUFCQ0RFRjAxMjM0NTY3ODlBQkRFRjAxMjM0NTY3ODlBQkNERUYwMTIzND"
|
|
266
|
+
"U2Nzg5QUJERUYwMTIzNDU2Nzg5QUJDREVGMDEyMztqJ7zOtqQtYqOo0CpvDXNlMhV3HeJ"
|
|
267
|
+
"DpjrASKGLWdop4lx1cSN3Xv1TgfLPW8rhGiW+hHiMxd36nRuxscNv9k4oJA/KP+o0mi1w"
|
|
268
|
+
"v44StrEJ1wwx9WZHBUIWkQbaBSuBDw";
|
|
269
|
+
|
|
270
|
+
uint8_t message[] =
|
|
271
|
+
"AwgAEhAcbh6UpbByoyZxufQ+h2B+8XHMjhR69G8nP4pNZGl/3QMgrzCZPmP+F2aPLyKPz"
|
|
272
|
+
"xRPBMUkeXRJ6Iqm5NeOdx2eERgTW7P20CM+lL3Xpk+ZUOOPvsSQNaAL";
|
|
273
|
+
size_t msglen = sizeof(message)-1;
|
|
274
|
+
|
|
275
|
+
/* build the inbound session */
|
|
276
|
+
size_t size = olm_inbound_group_session_size();
|
|
277
|
+
uint8_t inbound_session_memory[size];
|
|
278
|
+
OlmInboundGroupSession *inbound_session =
|
|
279
|
+
olm_inbound_group_session(inbound_session_memory);
|
|
280
|
+
|
|
281
|
+
size_t res = olm_init_inbound_group_session(
|
|
282
|
+
inbound_session, session_key, sizeof(session_key)-1
|
|
283
|
+
);
|
|
284
|
+
assert_equals((size_t)0, res);
|
|
285
|
+
|
|
286
|
+
/* decode the message */
|
|
287
|
+
|
|
288
|
+
/* olm_group_decrypt_max_plaintext_length destroys the input so we have to
|
|
289
|
+
copy it. */
|
|
290
|
+
uint8_t msgcopy[msglen];
|
|
291
|
+
memcpy(msgcopy, message, msglen);
|
|
292
|
+
size = olm_group_decrypt_max_plaintext_length(
|
|
293
|
+
inbound_session, msgcopy, msglen
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
memcpy(msgcopy, message, msglen);
|
|
297
|
+
uint8_t plaintext_buf[size];
|
|
298
|
+
uint32_t message_index;
|
|
299
|
+
res = olm_group_decrypt(
|
|
300
|
+
inbound_session, msgcopy, msglen, plaintext_buf, size, &message_index
|
|
301
|
+
);
|
|
302
|
+
assert_equals(message_index, uint32_t(0));
|
|
303
|
+
assert_equals(plaintext_length, res);
|
|
304
|
+
assert_equals(plaintext, plaintext_buf, res);
|
|
305
|
+
|
|
306
|
+
/* now twiddle the signature */
|
|
307
|
+
message[msglen-1] = 'E';
|
|
308
|
+
memcpy(msgcopy, message, msglen);
|
|
309
|
+
assert_equals(
|
|
310
|
+
size,
|
|
311
|
+
olm_group_decrypt_max_plaintext_length(
|
|
312
|
+
inbound_session, msgcopy, msglen
|
|
313
|
+
)
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
memcpy(msgcopy, message, msglen);
|
|
317
|
+
res = olm_group_decrypt(
|
|
318
|
+
inbound_session, msgcopy, msglen,
|
|
319
|
+
plaintext_buf, size, &message_index
|
|
320
|
+
);
|
|
321
|
+
assert_equals((size_t)-1, res);
|
|
322
|
+
assert_equals(
|
|
323
|
+
std::string("BAD_SIGNATURE"),
|
|
324
|
+
std::string(olm_inbound_group_session_last_error(inbound_session))
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/* Copyright 2015 OpenMarket Ltd
|
|
2
|
+
*
|
|
3
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License.
|
|
5
|
+
* You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
* See the License for the specific language governing permissions and
|
|
13
|
+
* limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
#include "olm/list.hh"
|
|
16
|
+
#include "unittest.hh"
|
|
17
|
+
|
|
18
|
+
int main() {
|
|
19
|
+
|
|
20
|
+
{ /** List insert test **/
|
|
21
|
+
|
|
22
|
+
TestCase test_case("List insert");
|
|
23
|
+
|
|
24
|
+
olm::List<int, 4> test_list;
|
|
25
|
+
|
|
26
|
+
assert_equals(std::size_t(0), test_list.size());
|
|
27
|
+
|
|
28
|
+
for (int i = 0; i < 4; ++i) {
|
|
29
|
+
test_list.insert(test_list.end(), i);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
assert_equals(std::size_t(4), test_list.size());
|
|
33
|
+
|
|
34
|
+
int i = 0;
|
|
35
|
+
for (auto item : test_list) {
|
|
36
|
+
assert_equals(i++, item);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
assert_equals(4, i);
|
|
40
|
+
|
|
41
|
+
test_list.insert(test_list.end(), 4);
|
|
42
|
+
|
|
43
|
+
assert_equals(4, test_list[3]);
|
|
44
|
+
|
|
45
|
+
} /** List insert test **/
|
|
46
|
+
|
|
47
|
+
{ /** List insert beginning test **/
|
|
48
|
+
|
|
49
|
+
TestCase test_case("List insert beginning");
|
|
50
|
+
|
|
51
|
+
olm::List<int, 4> test_list;
|
|
52
|
+
|
|
53
|
+
assert_equals(std::size_t(0), test_list.size());
|
|
54
|
+
|
|
55
|
+
for (int i = 0; i < 4; ++i) {
|
|
56
|
+
test_list.insert(test_list.begin(), i);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
assert_equals(std::size_t(4), test_list.size());
|
|
60
|
+
|
|
61
|
+
int i = 4;
|
|
62
|
+
for (auto item : test_list) {
|
|
63
|
+
assert_equals(--i, item);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
} /** List insert test **/
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
{ /** List erase test **/
|
|
70
|
+
TestCase test_case("List erase");
|
|
71
|
+
|
|
72
|
+
olm::List<int, 4> test_list;
|
|
73
|
+
assert_equals(std::size_t(0), test_list.size());
|
|
74
|
+
|
|
75
|
+
for (int i = 0; i < 4; ++i) {
|
|
76
|
+
test_list.insert(test_list.end(), i);
|
|
77
|
+
}
|
|
78
|
+
assert_equals(std::size_t(4), test_list.size());
|
|
79
|
+
|
|
80
|
+
test_list.erase(test_list.begin());
|
|
81
|
+
assert_equals(std::size_t(3), test_list.size());
|
|
82
|
+
|
|
83
|
+
int i = 0;
|
|
84
|
+
for (auto item : test_list) {
|
|
85
|
+
assert_equals(i + 1, item);
|
|
86
|
+
++i;
|
|
87
|
+
}
|
|
88
|
+
assert_equals(3, i);
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
}
|