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,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2018 New Vector Ltd
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
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
|
+
|
|
16
|
+
#import <Foundation/Foundation.h>
|
|
17
|
+
|
|
18
|
+
#import "OLMPkMessage.h"
|
|
19
|
+
|
|
20
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
21
|
+
|
|
22
|
+
@interface OLMPkEncryption : NSObject
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
Set the recipient's public key for encrypting to.
|
|
26
|
+
|
|
27
|
+
@param recipientKey the recipient's public key.
|
|
28
|
+
*/
|
|
29
|
+
- (void)setRecipientKey:(NSString*)recipientKey;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
Encrypt a plaintext for the recipient.
|
|
33
|
+
|
|
34
|
+
@param message the message to encrypt.
|
|
35
|
+
@param error the error if any.
|
|
36
|
+
@return the encrypted message.
|
|
37
|
+
*/
|
|
38
|
+
- (OLMPkMessage *)encryptMessage:(NSString*)message error:(NSError* _Nullable *)error;
|
|
39
|
+
|
|
40
|
+
@end
|
|
41
|
+
|
|
42
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2018 New Vector Ltd
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#import <Foundation/Foundation.h>
|
|
18
|
+
|
|
19
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
20
|
+
|
|
21
|
+
@interface OLMPkMessage : NSObject
|
|
22
|
+
|
|
23
|
+
@property (nonatomic, copy, readonly) NSString *ciphertext;
|
|
24
|
+
@property (nonatomic, copy, readonly,) NSString *mac;
|
|
25
|
+
@property (nonatomic, copy, readonly) NSString *ephemeralKey;
|
|
26
|
+
|
|
27
|
+
- (instancetype) initWithCiphertext:(NSString*)ciphertext mac:(NSString*)mac ephemeralKey:(NSString*)ephemeralKey;
|
|
28
|
+
|
|
29
|
+
@end
|
|
30
|
+
|
|
31
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2016 Chris Ballinger
|
|
3
|
+
Copyright 2016 OpenMarket Ltd
|
|
4
|
+
Copyright 2016 Vector Creations Ltd
|
|
5
|
+
|
|
6
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
you may not use this file except in compliance with the License.
|
|
8
|
+
You may obtain a copy of the License at
|
|
9
|
+
|
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
|
|
12
|
+
Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
See the License for the specific language governing permissions and
|
|
16
|
+
limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#import <Foundation/Foundation.h>
|
|
20
|
+
|
|
21
|
+
@protocol OLMSerializable <NSObject>
|
|
22
|
+
|
|
23
|
+
/** Initializes from encrypted serialized data. Will throw error if invalid key or invalid base64. */
|
|
24
|
+
- (instancetype) initWithSerializedData:(NSString*)serializedData key:(NSData*)key error:(NSError**)error;
|
|
25
|
+
|
|
26
|
+
/** Serializes and encrypts object data, outputs base64 blob */
|
|
27
|
+
- (NSString*) serializeDataWithKey:(NSData*)key error:(NSError**)error;
|
|
28
|
+
|
|
29
|
+
@end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2016 Chris Ballinger
|
|
3
|
+
Copyright 2016 OpenMarket Ltd
|
|
4
|
+
Copyright 2016 Vector Creations Ltd
|
|
5
|
+
|
|
6
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
you may not use this file except in compliance with the License.
|
|
8
|
+
You may obtain a copy of the License at
|
|
9
|
+
|
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
|
|
12
|
+
Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
See the License for the specific language governing permissions and
|
|
16
|
+
limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#import <Foundation/Foundation.h>
|
|
20
|
+
#import "OLMSerializable.h"
|
|
21
|
+
#import "OLMAccount.h"
|
|
22
|
+
#import "OLMMessage.h"
|
|
23
|
+
|
|
24
|
+
@interface OLMSession : NSObject <OLMSerializable, NSSecureCoding>
|
|
25
|
+
|
|
26
|
+
- (instancetype) initOutboundSessionWithAccount:(OLMAccount*)account theirIdentityKey:(NSString*)theirIdentityKey theirOneTimeKey:(NSString*)theirOneTimeKey error:(NSError**)error;
|
|
27
|
+
|
|
28
|
+
- (instancetype) initInboundSessionWithAccount:(OLMAccount*)account oneTimeKeyMessage:(NSString*)oneTimeKeyMessage error:(NSError**)error;
|
|
29
|
+
|
|
30
|
+
- (instancetype) initInboundSessionWithAccount:(OLMAccount*)account theirIdentityKey:(NSString*)theirIdentityKey oneTimeKeyMessage:(NSString*)oneTimeKeyMessage error:(NSError**)error;
|
|
31
|
+
|
|
32
|
+
- (NSString*) sessionIdentifier;
|
|
33
|
+
|
|
34
|
+
- (BOOL) matchesInboundSession:(NSString*)oneTimeKeyMessage;
|
|
35
|
+
|
|
36
|
+
- (BOOL) matchesInboundSessionFrom:(NSString*)theirIdentityKey oneTimeKeyMessage:(NSString *)oneTimeKeyMessage;
|
|
37
|
+
|
|
38
|
+
/** UTF-8 plaintext -> base64 ciphertext */
|
|
39
|
+
- (OLMMessage*) encryptMessage:(NSString*)message error:(NSError**)error;
|
|
40
|
+
|
|
41
|
+
/** base64 ciphertext -> UTF-8 plaintext */
|
|
42
|
+
- (NSString*) decryptMessage:(OLMMessage*)message error:(NSError**)error;
|
|
43
|
+
|
|
44
|
+
@end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2016 Chris Ballinger
|
|
3
|
+
Copyright 2016 OpenMarket Ltd
|
|
4
|
+
Copyright 2016 Vector Creations Ltd
|
|
5
|
+
|
|
6
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
you may not use this file except in compliance with the License.
|
|
8
|
+
You may obtain a copy of the License at
|
|
9
|
+
|
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
|
|
12
|
+
Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
See the License for the specific language governing permissions and
|
|
16
|
+
limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#include "olm/olm.h"
|
|
20
|
+
|
|
21
|
+
@interface OLMSession()
|
|
22
|
+
|
|
23
|
+
@property (nonatomic) OlmSession *session;
|
|
24
|
+
@property (nonatomic, strong) OLMAccount *account;
|
|
25
|
+
|
|
26
|
+
@end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2016 Chris Ballinger
|
|
3
|
+
Copyright 2016 OpenMarket Ltd
|
|
4
|
+
Copyright 2016 Vector Creations Ltd
|
|
5
|
+
|
|
6
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
you may not use this file except in compliance with the License.
|
|
8
|
+
You may obtain a copy of the License at
|
|
9
|
+
|
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
|
|
12
|
+
Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
See the License for the specific language governing permissions and
|
|
16
|
+
limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#import <Foundation/Foundation.h>
|
|
20
|
+
|
|
21
|
+
FOUNDATION_EXPORT NSString *const OLMErrorDomain;
|
|
22
|
+
|
|
23
|
+
@interface OLMUtility : NSObject
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
Calculate the SHA-256 hash of the input and encodes it as base64.
|
|
27
|
+
|
|
28
|
+
@param message the message to hash.
|
|
29
|
+
@return the base64-encoded hash value.
|
|
30
|
+
*/
|
|
31
|
+
- (NSString*)sha256:(NSData*)message;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
Verify an ed25519 signature.
|
|
35
|
+
|
|
36
|
+
@param signature the base64-encoded signature to be checked.
|
|
37
|
+
@param key the ed25519 key.
|
|
38
|
+
@param message the message which was signed.
|
|
39
|
+
@param error if there is a problem with the verification.
|
|
40
|
+
If the key was too small then the message will be "OLM.INVALID_BASE64".
|
|
41
|
+
If the signature was invalid then the message will be "OLM.BAD_MESSAGE_MAC".
|
|
42
|
+
|
|
43
|
+
@return YES if valid.
|
|
44
|
+
*/
|
|
45
|
+
- (BOOL)verifyEd25519Signature:(NSString*)signature key:(NSString*)key message:(NSData*)message error:(NSError**)error;
|
|
46
|
+
|
|
47
|
+
+ (NSMutableData*) randomBytesOfLength:(NSUInteger)length;
|
|
48
|
+
|
|
49
|
+
@end
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
/* Copyright 2015, 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/account.hh"
|
|
16
|
+
#include "olm/base64.hh"
|
|
17
|
+
#include "olm/pickle.h"
|
|
18
|
+
#include "olm/pickle.hh"
|
|
19
|
+
#include "olm/memory.hh"
|
|
20
|
+
|
|
21
|
+
olm::Account::Account(
|
|
22
|
+
) : next_one_time_key_id(0),
|
|
23
|
+
last_error(OlmErrorCode::OLM_SUCCESS) {
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
olm::OneTimeKey const * olm::Account::lookup_key(
|
|
28
|
+
_olm_curve25519_public_key const & public_key
|
|
29
|
+
) {
|
|
30
|
+
for (olm::OneTimeKey const & key : one_time_keys) {
|
|
31
|
+
if (olm::array_equal(key.key.public_key.public_key, public_key.public_key)) {
|
|
32
|
+
return &key;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
std::size_t olm::Account::remove_key(
|
|
39
|
+
_olm_curve25519_public_key const & public_key
|
|
40
|
+
) {
|
|
41
|
+
OneTimeKey * i;
|
|
42
|
+
for (i = one_time_keys.begin(); i != one_time_keys.end(); ++i) {
|
|
43
|
+
if (olm::array_equal(i->key.public_key.public_key, public_key.public_key)) {
|
|
44
|
+
std::uint32_t id = i->id;
|
|
45
|
+
one_time_keys.erase(i);
|
|
46
|
+
return id;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return std::size_t(-1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
std::size_t olm::Account::new_account_random_length() {
|
|
53
|
+
return ED25519_RANDOM_LENGTH + CURVE25519_RANDOM_LENGTH;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
std::size_t olm::Account::new_account(
|
|
57
|
+
uint8_t const * random, std::size_t random_length
|
|
58
|
+
) {
|
|
59
|
+
if (random_length < new_account_random_length()) {
|
|
60
|
+
last_error = OlmErrorCode::OLM_NOT_ENOUGH_RANDOM;
|
|
61
|
+
return std::size_t(-1);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
_olm_crypto_ed25519_generate_key(random, &identity_keys.ed25519_key);
|
|
65
|
+
random += ED25519_RANDOM_LENGTH;
|
|
66
|
+
_olm_crypto_curve25519_generate_key(random, &identity_keys.curve25519_key);
|
|
67
|
+
|
|
68
|
+
return 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
namespace {
|
|
72
|
+
|
|
73
|
+
uint8_t KEY_JSON_ED25519[] = "\"ed25519\":";
|
|
74
|
+
uint8_t KEY_JSON_CURVE25519[] = "\"curve25519\":";
|
|
75
|
+
|
|
76
|
+
template<typename T>
|
|
77
|
+
static std::uint8_t * write_string(
|
|
78
|
+
std::uint8_t * pos,
|
|
79
|
+
T const & value
|
|
80
|
+
) {
|
|
81
|
+
std::memcpy(pos, value, sizeof(T) - 1);
|
|
82
|
+
return pos + (sizeof(T) - 1);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
std::size_t olm::Account::get_identity_json_length() {
|
|
89
|
+
std::size_t length = 0;
|
|
90
|
+
length += 1; /* { */
|
|
91
|
+
length += sizeof(KEY_JSON_CURVE25519) - 1;
|
|
92
|
+
length += 1; /* " */
|
|
93
|
+
length += olm::encode_base64_length(
|
|
94
|
+
sizeof(identity_keys.curve25519_key.public_key)
|
|
95
|
+
);
|
|
96
|
+
length += 2; /* ", */
|
|
97
|
+
length += sizeof(KEY_JSON_ED25519) - 1;
|
|
98
|
+
length += 1; /* " */
|
|
99
|
+
length += olm::encode_base64_length(
|
|
100
|
+
sizeof(identity_keys.ed25519_key.public_key)
|
|
101
|
+
);
|
|
102
|
+
length += 2; /* "} */
|
|
103
|
+
return length;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
std::size_t olm::Account::get_identity_json(
|
|
108
|
+
std::uint8_t * identity_json, std::size_t identity_json_length
|
|
109
|
+
) {
|
|
110
|
+
std::uint8_t * pos = identity_json;
|
|
111
|
+
size_t expected_length = get_identity_json_length();
|
|
112
|
+
|
|
113
|
+
if (identity_json_length < expected_length) {
|
|
114
|
+
last_error = OlmErrorCode::OLM_OUTPUT_BUFFER_TOO_SMALL;
|
|
115
|
+
return std::size_t(-1);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
*(pos++) = '{';
|
|
119
|
+
pos = write_string(pos, KEY_JSON_CURVE25519);
|
|
120
|
+
*(pos++) = '\"';
|
|
121
|
+
pos = olm::encode_base64(
|
|
122
|
+
identity_keys.curve25519_key.public_key.public_key,
|
|
123
|
+
sizeof(identity_keys.curve25519_key.public_key.public_key),
|
|
124
|
+
pos
|
|
125
|
+
);
|
|
126
|
+
*(pos++) = '\"'; *(pos++) = ',';
|
|
127
|
+
pos = write_string(pos, KEY_JSON_ED25519);
|
|
128
|
+
*(pos++) = '\"';
|
|
129
|
+
pos = olm::encode_base64(
|
|
130
|
+
identity_keys.ed25519_key.public_key.public_key,
|
|
131
|
+
sizeof(identity_keys.ed25519_key.public_key.public_key),
|
|
132
|
+
pos
|
|
133
|
+
);
|
|
134
|
+
*(pos++) = '\"'; *(pos++) = '}';
|
|
135
|
+
return pos - identity_json;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
std::size_t olm::Account::signature_length(
|
|
140
|
+
) {
|
|
141
|
+
return ED25519_SIGNATURE_LENGTH;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
std::size_t olm::Account::sign(
|
|
146
|
+
std::uint8_t const * message, std::size_t message_length,
|
|
147
|
+
std::uint8_t * signature, std::size_t signature_length
|
|
148
|
+
) {
|
|
149
|
+
if (signature_length < this->signature_length()) {
|
|
150
|
+
last_error = OlmErrorCode::OLM_OUTPUT_BUFFER_TOO_SMALL;
|
|
151
|
+
return std::size_t(-1);
|
|
152
|
+
}
|
|
153
|
+
_olm_crypto_ed25519_sign(
|
|
154
|
+
&identity_keys.ed25519_key, message, message_length, signature
|
|
155
|
+
);
|
|
156
|
+
return this->signature_length();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
std::size_t olm::Account::get_one_time_keys_json_length(
|
|
161
|
+
) {
|
|
162
|
+
std::size_t length = 0;
|
|
163
|
+
bool is_empty = true;
|
|
164
|
+
for (auto const & key : one_time_keys) {
|
|
165
|
+
if (key.published) {
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
is_empty = false;
|
|
169
|
+
length += 2; /* {" */
|
|
170
|
+
length += olm::encode_base64_length(_olm_pickle_uint32_length(key.id));
|
|
171
|
+
length += 3; /* ":" */
|
|
172
|
+
length += olm::encode_base64_length(sizeof(key.key.public_key));
|
|
173
|
+
length += 1; /* " */
|
|
174
|
+
}
|
|
175
|
+
if (is_empty) {
|
|
176
|
+
length += 1; /* { */
|
|
177
|
+
}
|
|
178
|
+
length += 3; /* }{} */
|
|
179
|
+
length += sizeof(KEY_JSON_CURVE25519) - 1;
|
|
180
|
+
return length;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
std::size_t olm::Account::get_one_time_keys_json(
|
|
185
|
+
std::uint8_t * one_time_json, std::size_t one_time_json_length
|
|
186
|
+
) {
|
|
187
|
+
std::uint8_t * pos = one_time_json;
|
|
188
|
+
if (one_time_json_length < get_one_time_keys_json_length()) {
|
|
189
|
+
last_error = OlmErrorCode::OLM_OUTPUT_BUFFER_TOO_SMALL;
|
|
190
|
+
return std::size_t(-1);
|
|
191
|
+
}
|
|
192
|
+
*(pos++) = '{';
|
|
193
|
+
pos = write_string(pos, KEY_JSON_CURVE25519);
|
|
194
|
+
std::uint8_t sep = '{';
|
|
195
|
+
for (auto const & key : one_time_keys) {
|
|
196
|
+
if (key.published) {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
*(pos++) = sep;
|
|
200
|
+
*(pos++) = '\"';
|
|
201
|
+
std::uint8_t key_id[_olm_pickle_uint32_length(key.id)];
|
|
202
|
+
_olm_pickle_uint32(key_id, key.id);
|
|
203
|
+
pos = olm::encode_base64(key_id, sizeof(key_id), pos);
|
|
204
|
+
*(pos++) = '\"'; *(pos++) = ':'; *(pos++) = '\"';
|
|
205
|
+
pos = olm::encode_base64(
|
|
206
|
+
key.key.public_key.public_key, sizeof(key.key.public_key.public_key), pos
|
|
207
|
+
);
|
|
208
|
+
*(pos++) = '\"';
|
|
209
|
+
sep = ',';
|
|
210
|
+
}
|
|
211
|
+
if (sep != ',') {
|
|
212
|
+
/* The list was empty */
|
|
213
|
+
*(pos++) = sep;
|
|
214
|
+
}
|
|
215
|
+
*(pos++) = '}';
|
|
216
|
+
*(pos++) = '}';
|
|
217
|
+
return pos - one_time_json;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
std::size_t olm::Account::mark_keys_as_published(
|
|
222
|
+
) {
|
|
223
|
+
std::size_t count = 0;
|
|
224
|
+
for (auto & key : one_time_keys) {
|
|
225
|
+
if (!key.published) {
|
|
226
|
+
key.published = true;
|
|
227
|
+
count++;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return count;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
std::size_t olm::Account::max_number_of_one_time_keys(
|
|
235
|
+
) {
|
|
236
|
+
return olm::MAX_ONE_TIME_KEYS;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
std::size_t olm::Account::generate_one_time_keys_random_length(
|
|
240
|
+
std::size_t number_of_keys
|
|
241
|
+
) {
|
|
242
|
+
return CURVE25519_RANDOM_LENGTH * number_of_keys;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
std::size_t olm::Account::generate_one_time_keys(
|
|
246
|
+
std::size_t number_of_keys,
|
|
247
|
+
std::uint8_t const * random, std::size_t random_length
|
|
248
|
+
) {
|
|
249
|
+
if (random_length < generate_one_time_keys_random_length(number_of_keys)) {
|
|
250
|
+
last_error = OlmErrorCode::OLM_NOT_ENOUGH_RANDOM;
|
|
251
|
+
return std::size_t(-1);
|
|
252
|
+
}
|
|
253
|
+
for (unsigned i = 0; i < number_of_keys; ++i) {
|
|
254
|
+
OneTimeKey & key = *one_time_keys.insert(one_time_keys.begin());
|
|
255
|
+
key.id = ++next_one_time_key_id;
|
|
256
|
+
key.published = false;
|
|
257
|
+
_olm_crypto_curve25519_generate_key(random, &key.key);
|
|
258
|
+
random += CURVE25519_RANDOM_LENGTH;
|
|
259
|
+
}
|
|
260
|
+
return number_of_keys;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
namespace olm {
|
|
264
|
+
|
|
265
|
+
static std::size_t pickle_length(
|
|
266
|
+
olm::IdentityKeys const & value
|
|
267
|
+
) {
|
|
268
|
+
size_t length = 0;
|
|
269
|
+
length += _olm_pickle_ed25519_key_pair_length(&value.ed25519_key);
|
|
270
|
+
length += olm::pickle_length(value.curve25519_key);
|
|
271
|
+
return length;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
static std::uint8_t * pickle(
|
|
276
|
+
std::uint8_t * pos,
|
|
277
|
+
olm::IdentityKeys const & value
|
|
278
|
+
) {
|
|
279
|
+
pos = _olm_pickle_ed25519_key_pair(pos, &value.ed25519_key);
|
|
280
|
+
pos = olm::pickle(pos, value.curve25519_key);
|
|
281
|
+
return pos;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
static std::uint8_t const * unpickle(
|
|
286
|
+
std::uint8_t const * pos, std::uint8_t const * end,
|
|
287
|
+
olm::IdentityKeys & value
|
|
288
|
+
) {
|
|
289
|
+
pos = _olm_unpickle_ed25519_key_pair(pos, end, &value.ed25519_key);
|
|
290
|
+
pos = olm::unpickle(pos, end, value.curve25519_key);
|
|
291
|
+
return pos;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
static std::size_t pickle_length(
|
|
296
|
+
olm::OneTimeKey const & value
|
|
297
|
+
) {
|
|
298
|
+
std::size_t length = 0;
|
|
299
|
+
length += olm::pickle_length(value.id);
|
|
300
|
+
length += olm::pickle_length(value.published);
|
|
301
|
+
length += olm::pickle_length(value.key);
|
|
302
|
+
return length;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
static std::uint8_t * pickle(
|
|
307
|
+
std::uint8_t * pos,
|
|
308
|
+
olm::OneTimeKey const & value
|
|
309
|
+
) {
|
|
310
|
+
pos = olm::pickle(pos, value.id);
|
|
311
|
+
pos = olm::pickle(pos, value.published);
|
|
312
|
+
pos = olm::pickle(pos, value.key);
|
|
313
|
+
return pos;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
static std::uint8_t const * unpickle(
|
|
318
|
+
std::uint8_t const * pos, std::uint8_t const * end,
|
|
319
|
+
olm::OneTimeKey & value
|
|
320
|
+
) {
|
|
321
|
+
pos = olm::unpickle(pos, end, value.id);
|
|
322
|
+
pos = olm::unpickle(pos, end, value.published);
|
|
323
|
+
pos = olm::unpickle(pos, end, value.key);
|
|
324
|
+
return pos;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
} // namespace olm
|
|
328
|
+
|
|
329
|
+
namespace {
|
|
330
|
+
// pickle version 1 used only 32 bytes for the ed25519 private key.
|
|
331
|
+
// Any keys thus used should be considered compromised.
|
|
332
|
+
static const std::uint32_t ACCOUNT_PICKLE_VERSION = 2;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
std::size_t olm::pickle_length(
|
|
337
|
+
olm::Account const & value
|
|
338
|
+
) {
|
|
339
|
+
std::size_t length = 0;
|
|
340
|
+
length += olm::pickle_length(ACCOUNT_PICKLE_VERSION);
|
|
341
|
+
length += olm::pickle_length(value.identity_keys);
|
|
342
|
+
length += olm::pickle_length(value.one_time_keys);
|
|
343
|
+
length += olm::pickle_length(value.next_one_time_key_id);
|
|
344
|
+
return length;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
std::uint8_t * olm::pickle(
|
|
349
|
+
std::uint8_t * pos,
|
|
350
|
+
olm::Account const & value
|
|
351
|
+
) {
|
|
352
|
+
pos = olm::pickle(pos, ACCOUNT_PICKLE_VERSION);
|
|
353
|
+
pos = olm::pickle(pos, value.identity_keys);
|
|
354
|
+
pos = olm::pickle(pos, value.one_time_keys);
|
|
355
|
+
pos = olm::pickle(pos, value.next_one_time_key_id);
|
|
356
|
+
return pos;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
std::uint8_t const * olm::unpickle(
|
|
361
|
+
std::uint8_t const * pos, std::uint8_t const * end,
|
|
362
|
+
olm::Account & value
|
|
363
|
+
) {
|
|
364
|
+
uint32_t pickle_version;
|
|
365
|
+
pos = olm::unpickle(pos, end, pickle_version);
|
|
366
|
+
switch (pickle_version) {
|
|
367
|
+
case ACCOUNT_PICKLE_VERSION:
|
|
368
|
+
break;
|
|
369
|
+
case 1:
|
|
370
|
+
value.last_error = OlmErrorCode::OLM_BAD_LEGACY_ACCOUNT_PICKLE;
|
|
371
|
+
return end;
|
|
372
|
+
default:
|
|
373
|
+
value.last_error = OlmErrorCode::OLM_UNKNOWN_PICKLE_VERSION;
|
|
374
|
+
return end;
|
|
375
|
+
}
|
|
376
|
+
pos = olm::unpickle(pos, end, value.identity_keys);
|
|
377
|
+
pos = olm::unpickle(pos, end, value.one_time_keys);
|
|
378
|
+
pos = olm::unpickle(pos, end, value.next_one_time_key_id);
|
|
379
|
+
return pos;
|
|
380
|
+
}
|