ruby_olm 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- 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,42 @@
|
|
1
|
+
module RubyOlm
|
2
|
+
|
3
|
+
class Account
|
4
|
+
|
5
|
+
# @param pickle [String] pickled state
|
6
|
+
# @param password [String] password used to encrypt pickled state
|
7
|
+
# @return [Account]
|
8
|
+
def self.from_pickle(pickle, password="")
|
9
|
+
Account.new(pickle: pickle, password: password)
|
10
|
+
end
|
11
|
+
|
12
|
+
# @param [type] defaults to 'curve25519'
|
13
|
+
# @return [String]
|
14
|
+
def ik(type='curve25519')
|
15
|
+
raise RangeError unless identity_keys[type]
|
16
|
+
identity_keys[type]
|
17
|
+
end
|
18
|
+
|
19
|
+
# @param [type] defaults to 'curve25519'
|
20
|
+
# @param [value] return only the key values and not the ids
|
21
|
+
#
|
22
|
+
# @return [Array<Hash>] if !values
|
23
|
+
# @return [Array<String>] if values
|
24
|
+
def otk(values=true, type='curve25519')
|
25
|
+
if values
|
26
|
+
one_time_keys[type].values
|
27
|
+
else
|
28
|
+
one_time_keys[type]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def gen_otk(number=1)
|
33
|
+
generate_one_time_keys(number)
|
34
|
+
end
|
35
|
+
|
36
|
+
alias_method :mark_otk, :mark_keys_as_published
|
37
|
+
alias_method :max_otk, :max_number_of_one_time_keys
|
38
|
+
alias_method :update_otk, :remove_one_time_keys
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module RubyOlm
|
2
|
+
|
3
|
+
module OlmError
|
4
|
+
|
5
|
+
class SUCCESS < StandardError
|
6
|
+
end
|
7
|
+
|
8
|
+
class NOT_ENOUGH_RANDOM < StandardError
|
9
|
+
end
|
10
|
+
|
11
|
+
class OUTPUT_BUFFER_TOO_SMALL < StandardError
|
12
|
+
end
|
13
|
+
|
14
|
+
class BAD_MESSAGE_VERSION < StandardError
|
15
|
+
end
|
16
|
+
|
17
|
+
class BAD_MESSAGE_FORMAT < StandardError
|
18
|
+
end
|
19
|
+
|
20
|
+
class BAD_MESSAGE_MAC < StandardError
|
21
|
+
end
|
22
|
+
|
23
|
+
class BAD_MESSAGE_KEY_ID < StandardError
|
24
|
+
end
|
25
|
+
|
26
|
+
class INVALID_BASE64 < StandardError
|
27
|
+
end
|
28
|
+
|
29
|
+
class BAD_ACCOUNT_KEY < StandardError
|
30
|
+
end
|
31
|
+
|
32
|
+
class UNKNOWN_PICKLE_VERSION < StandardError
|
33
|
+
end
|
34
|
+
|
35
|
+
class CORRUPTED_PICKLE < StandardError
|
36
|
+
end
|
37
|
+
|
38
|
+
class BAD_SESSION_KEY < StandardError
|
39
|
+
end
|
40
|
+
|
41
|
+
class UNKNOWN_MESSAGE_INDEX < StandardError
|
42
|
+
end
|
43
|
+
|
44
|
+
class BAD_LEGACY_ACCOUNT_PICKLE < StandardError
|
45
|
+
end
|
46
|
+
|
47
|
+
class BAD_SIGNATURE < StandardError
|
48
|
+
end
|
49
|
+
|
50
|
+
class OLM_INPUT_BUFFER_TOO_SMALL < StandardError
|
51
|
+
end
|
52
|
+
|
53
|
+
class UnknownError < StandardError
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.from_string(str)
|
57
|
+
begin
|
58
|
+
OlmError.const_get(str)
|
59
|
+
rescue NameError
|
60
|
+
UnknownError.new str
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.raise_from_string(str)
|
65
|
+
raise from_string(str)
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'base64'
|
2
|
+
|
3
|
+
module RubyOlm
|
4
|
+
|
5
|
+
class OlmMessage
|
6
|
+
|
7
|
+
# @param msg [String] base64 or bytes
|
8
|
+
def initialize(msg)
|
9
|
+
raise "abstract class" if self.class == OlmMessage
|
10
|
+
@value = msg
|
11
|
+
end
|
12
|
+
|
13
|
+
# @return [String] bytes
|
14
|
+
def to_bytes
|
15
|
+
Base64.decode64(value)
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [String] base64
|
19
|
+
def to_s
|
20
|
+
@value.dup
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module RubyOlm
|
2
|
+
|
3
|
+
class Session
|
4
|
+
|
5
|
+
# @param pickle [String] pickled state
|
6
|
+
# @param password [String] password used to encrypt pickled state
|
7
|
+
# @return [Session]
|
8
|
+
def self.from_pickle(pickle, password="")
|
9
|
+
Session.new(pickle, password)
|
10
|
+
end
|
11
|
+
|
12
|
+
alias_method :has_received?, :has_received_message
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/lib/ruby_olm.rb
ADDED
data/rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rake/testtask'
|
2
|
+
require 'rake/extensiontask'
|
3
|
+
|
4
|
+
Rake::ExtensionTask.new do |ext|
|
5
|
+
ext.name = "ext_lib_olm"
|
6
|
+
ext.ext_dir = "ext/ruby_olm/ext_lib_olm"
|
7
|
+
ext.lib_dir = "lib/ruby_olm"
|
8
|
+
end
|
9
|
+
|
10
|
+
task :test => :compile
|
11
|
+
|
12
|
+
Rake::TestTask.new do |t|
|
13
|
+
t.name = :test
|
14
|
+
t.libs << "lib"
|
15
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
16
|
+
end
|
17
|
+
|
18
|
+
task :default => :test
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'ruby_olm'
|
3
|
+
|
4
|
+
class TestExchange < Minitest::Test
|
5
|
+
|
6
|
+
include RubyOlm
|
7
|
+
|
8
|
+
# Alice -> Bob
|
9
|
+
# Alice -> Bob
|
10
|
+
#
|
11
|
+
def test_bob_no_answer
|
12
|
+
|
13
|
+
alice = Account.new
|
14
|
+
bob = Account.new
|
15
|
+
|
16
|
+
# Alice wants to send a message to Bob
|
17
|
+
alice_msg = "hi bob"
|
18
|
+
|
19
|
+
# Bob generates a one-time-key
|
20
|
+
bob.gen_otk
|
21
|
+
|
22
|
+
# Alice must have Bob's identity and one-time-key to make a session
|
23
|
+
alice_session = alice.outbound_session(bob.ik, bob.otk.first)
|
24
|
+
|
25
|
+
# Bob marks all one-time-keys as published
|
26
|
+
bob.mark_otk
|
27
|
+
|
28
|
+
# Alice can encrypt
|
29
|
+
encrypted = alice_session.encrypt(alice_msg)
|
30
|
+
assert_instance_of PreKeyMessage, encrypted
|
31
|
+
|
32
|
+
# Bob can create a session from this first message
|
33
|
+
bob_session = bob.inbound_session(encrypted)
|
34
|
+
|
35
|
+
# Bob can now update his list of marked otk (since he knows one has been used)
|
36
|
+
bob.update_otk(bob_session)
|
37
|
+
|
38
|
+
# Bob can decrypt Alice's message
|
39
|
+
bob_msg = bob_session.decrypt(encrypted)
|
40
|
+
|
41
|
+
assert_equal alice_msg, bob_msg
|
42
|
+
|
43
|
+
# At this point Bob has received but Alice hasn't
|
44
|
+
assert bob_session.has_received?
|
45
|
+
refute alice_session.has_received?
|
46
|
+
|
47
|
+
###
|
48
|
+
|
49
|
+
# Alice sends another message before reply from Bob
|
50
|
+
alice_msg = "BOB!"
|
51
|
+
|
52
|
+
encrypted = alice_session.encrypt(alice_msg)
|
53
|
+
assert_instance_of PreKeyMessage, encrypted
|
54
|
+
|
55
|
+
# Bob needs to check if this is the same session or a new one
|
56
|
+
same_session = bob_session.will_receive? encrypted
|
57
|
+
|
58
|
+
assert same_session
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'ruby_olm'
|
3
|
+
|
4
|
+
class TestExchange < Minitest::Test
|
5
|
+
|
6
|
+
include RubyOlm
|
7
|
+
|
8
|
+
# Alice -> Bob
|
9
|
+
# Alice <- Bob
|
10
|
+
def test_exchange
|
11
|
+
|
12
|
+
alice = Account.new
|
13
|
+
bob = Account.new
|
14
|
+
|
15
|
+
# Alice wants to send a message to Bob
|
16
|
+
alice_msg = "hi bob"
|
17
|
+
|
18
|
+
# Bob generates a one-time-key
|
19
|
+
bob.gen_otk
|
20
|
+
|
21
|
+
# Alice must have Bob's identity and one-time-key to make a session
|
22
|
+
alice_session = alice.outbound_session(bob.ik, bob.otk.first)
|
23
|
+
|
24
|
+
# Bob marks all one-time-keys as published
|
25
|
+
bob.mark_otk
|
26
|
+
|
27
|
+
# Alice can encrypt
|
28
|
+
encrypted = alice_session.encrypt(alice_msg)
|
29
|
+
assert_instance_of PreKeyMessage, encrypted
|
30
|
+
|
31
|
+
# Bob can create a session from this first message
|
32
|
+
bob_session = bob.inbound_session(encrypted)
|
33
|
+
|
34
|
+
# Bob can now update his list of marked otk (since he knows one has been used)
|
35
|
+
bob.update_otk(bob_session)
|
36
|
+
|
37
|
+
# Bob can decrypt Alice's message
|
38
|
+
bob_msg = bob_session.decrypt(encrypted)
|
39
|
+
|
40
|
+
assert_equal alice_msg, bob_msg
|
41
|
+
|
42
|
+
# At this point Bob has received but Alice hasn't
|
43
|
+
assert bob_session.has_received?
|
44
|
+
refute alice_session.has_received?
|
45
|
+
|
46
|
+
####
|
47
|
+
|
48
|
+
# Bob can send messages back to Alice
|
49
|
+
bob_msg = "hi alice"
|
50
|
+
|
51
|
+
encrypted = bob_session.encrypt(bob_msg)
|
52
|
+
assert_instance_of Message, encrypted
|
53
|
+
|
54
|
+
alice_msg = alice_session.decrypt(encrypted)
|
55
|
+
|
56
|
+
assert_equal alice_msg, bob_msg
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'ruby_olm'
|
3
|
+
|
4
|
+
describe "Account" do
|
5
|
+
|
6
|
+
let(:account){ RubyOlm::Account.new }
|
7
|
+
|
8
|
+
# returns curve2599 identity key
|
9
|
+
#
|
10
|
+
describe "#ik" do
|
11
|
+
|
12
|
+
let(:rv){ account.ik }
|
13
|
+
|
14
|
+
it("returns a String"){ rv.must_be_instance_of String }
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#identity_keys" do
|
19
|
+
|
20
|
+
let(:rv){ account.identity_keys }
|
21
|
+
|
22
|
+
it("returns a Hash"){ rv.must_be_instance_of Hash }
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
# returns the maximum number of one-time-keys able to be
|
27
|
+
# cached by account
|
28
|
+
#
|
29
|
+
describe "#max_otk" do
|
30
|
+
|
31
|
+
let(:rv){ account.max_otk }
|
32
|
+
|
33
|
+
it("returns an unsigned integer") do
|
34
|
+
rv.must_be_kind_of Integer
|
35
|
+
rv.must_be :'>=', 0
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
# generates zero or more one-time-keys which will then be cached
|
41
|
+
# by account until such time they are:
|
42
|
+
#
|
43
|
+
# - overwritten by future calls to #generate_otk
|
44
|
+
# - removed by session establishment
|
45
|
+
#
|
46
|
+
describe "#gen_otk" do
|
47
|
+
|
48
|
+
it("returns self"){ account.gen_otk.must_equal account }
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
# marks one-time-keys as published
|
53
|
+
#
|
54
|
+
describe "#mark_otk" do
|
55
|
+
|
56
|
+
it("returns self"){ account.mark_otk.must_equal account }
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
# returns cached one-time-keys which have not yet been marked as published
|
61
|
+
#
|
62
|
+
describe "#otk" do
|
63
|
+
|
64
|
+
let(:rv){ account.otk }
|
65
|
+
|
66
|
+
it("returns an Array"){ rv.must_be_kind_of Array }
|
67
|
+
|
68
|
+
describe "return value" do
|
69
|
+
|
70
|
+
describe "before #gen_otk" do
|
71
|
+
|
72
|
+
describe "before #mark_otk" do
|
73
|
+
|
74
|
+
it("is empty"){ rv.size.must_equal 0 }
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "after #mark_otk" do
|
79
|
+
|
80
|
+
before{ account.mark_otk }
|
81
|
+
|
82
|
+
it("is empty"){ rv.size.must_equal 0 }
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "after #gen_otk" do
|
89
|
+
|
90
|
+
let(:max){ account.max_otk }
|
91
|
+
let(:n){ rand(0..max) }
|
92
|
+
|
93
|
+
before{ account.gen_otk(n) }
|
94
|
+
|
95
|
+
describe "before #mark_otk" do
|
96
|
+
|
97
|
+
it("has n keys"){ rv.size.must_equal n }
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "after #mark_otk" do
|
102
|
+
|
103
|
+
before{ account.mark_otk }
|
104
|
+
|
105
|
+
it("is empty"){ rv.size.must_equal 0 }
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
# creates inbound and outbound sessions
|
116
|
+
#
|
117
|
+
describe "session factory" do
|
118
|
+
|
119
|
+
let(:remote){ RubyOlm::Account.new }
|
120
|
+
|
121
|
+
before do
|
122
|
+
remote.gen_otk
|
123
|
+
account.gen_otk
|
124
|
+
end
|
125
|
+
|
126
|
+
describe "#outbound_session" do
|
127
|
+
|
128
|
+
it("creates session") { account.outbound_session(remote.ik, remote.otk.first).must_be_kind_of RubyOlm::Session }
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "#inbound_session" do
|
133
|
+
|
134
|
+
let(:remote_session){ remote.outbound_session(account.ik, account.otk.first) }
|
135
|
+
let(:remote_message){ remote_session.encrypt("hello") }
|
136
|
+
|
137
|
+
it("creates session") { account.inbound_session(remote_message).must_be_kind_of RubyOlm::Session }
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
describe "#inbound_session from known remote" do
|
142
|
+
|
143
|
+
let(:remote_session){ remote.outbound_session(account.ik, account.otk.first) }
|
144
|
+
let(:remote_message){ remote_session.encrypt("hello") }
|
145
|
+
|
146
|
+
it("creates session") { account.inbound_session(remote_message, remote.ik).must_be_kind_of RubyOlm::Session }
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'ruby_olm'
|
3
|
+
|
4
|
+
class TestAccount < Minitest::Test
|
5
|
+
|
6
|
+
include RubyOlm
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@state = Account.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_identity_keys
|
13
|
+
assert_instance_of Hash, @state.identity_keys
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_ik_default
|
17
|
+
assert_equal @state.identity_keys['curve25519'], @state.ik
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_one_time_keys
|
21
|
+
assert_instance_of Hash, @state.one_time_keys
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_otk_default
|
25
|
+
assert_instance_of Array, @state.otk
|
26
|
+
assert_equal @state.one_time_keys['curve25519'].values, @state.otk
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_generate_one_time_keys
|
30
|
+
assert_equal @state, @state.generate_one_time_keys(rand(1..10))
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_gen_otk
|
34
|
+
test_generate_one_time_keys
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_last_error
|
38
|
+
assert_equal OlmError::SUCCESS, @state.last_error
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_sign
|
42
|
+
assert_instance_of String, @state.sign("hello")
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_mark_keys_as_published
|
46
|
+
assert_equal @state, @state.mark_keys_as_published
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_mark_otk
|
50
|
+
test_mark_keys_as_published
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_max_number_of_one_time_keys
|
54
|
+
assert_kind_of Integer, @state.max_number_of_one_time_keys
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_max_otk
|
58
|
+
test_max_number_of_one_time_keys
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_to_pickle
|
62
|
+
assert_kind_of String, @state.to_pickle
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_from_pickle
|
66
|
+
Account.from_pickle(@state.to_pickle)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_from_pickle_with_key
|
70
|
+
Account.from_pickle(@state.to_pickle("hey"), "hey")
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_from_pickle_invalid
|
74
|
+
assert_raises OlmError::BAD_ACCOUNT_KEY do
|
75
|
+
Account.from_pickle("")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_from_pickle_bad_key
|
80
|
+
assert_raises OlmError::BAD_ACCOUNT_KEY do
|
81
|
+
Account.from_pickle(@state.to_pickle, "hey")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|