aboutsummaryrefslogtreecommitdiff
path: root/xcode/OLMKitTests
diff options
context:
space:
mode:
Diffstat (limited to 'xcode/OLMKitTests')
-rw-r--r--xcode/OLMKitTests/Info.plist22
-rw-r--r--xcode/OLMKitTests/OLMKitGroupTests.m146
-rw-r--r--xcode/OLMKitTests/OLMKitPkTests.m142
-rw-r--r--xcode/OLMKitTests/OLMKitSASTests.m86
-rw-r--r--xcode/OLMKitTests/OLMKitTests.m206
5 files changed, 0 insertions, 602 deletions
diff --git a/xcode/OLMKitTests/Info.plist b/xcode/OLMKitTests/Info.plist
deleted file mode 100644
index 6c6c23c..0000000
--- a/xcode/OLMKitTests/Info.plist
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0">
-<dict>
- <key>CFBundleDevelopmentRegion</key>
- <string>en</string>
- <key>CFBundleExecutable</key>
- <string>$(EXECUTABLE_NAME)</string>
- <key>CFBundleIdentifier</key>
- <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
- <key>CFBundleInfoDictionaryVersion</key>
- <string>6.0</string>
- <key>CFBundleName</key>
- <string>$(PRODUCT_NAME)</string>
- <key>CFBundlePackageType</key>
- <string>BNDL</string>
- <key>CFBundleShortVersionString</key>
- <string>1.0</string>
- <key>CFBundleVersion</key>
- <string>1</string>
-</dict>
-</plist>
diff --git a/xcode/OLMKitTests/OLMKitGroupTests.m b/xcode/OLMKitTests/OLMKitGroupTests.m
deleted file mode 100644
index 39ad400..0000000
--- a/xcode/OLMKitTests/OLMKitGroupTests.m
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- Copyright 2016 OpenMarket Ltd
- Copyright 2016 Vector Creations Ltd
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-#import <XCTest/XCTest.h>
-
-#import <OLMKit/OLMKit.h>
-
-#include "olm/olm.h"
-
-@interface OLMKitGroupTests : XCTestCase
-
-@end
-
-@implementation OLMKitGroupTests
-
-- (void)setUp {
- [super setUp];
- // Put setup code here. This method is called before the invocation of each test method in the class.
-}
-
-- (void)tearDown {
- // Put teardown code here. This method is called after the invocation of each test method in the class.
- [super tearDown];
-}
-
-- (void)testAliceAndBob {
- NSError *error;
-
- OLMOutboundGroupSession *aliceSession = [[OLMOutboundGroupSession alloc] initOutboundGroupSession];
- XCTAssertGreaterThan(aliceSession.sessionIdentifier.length, 0);
- XCTAssertGreaterThan(aliceSession.sessionKey.length, 0);
- XCTAssertEqual(aliceSession.messageIndex, 0);
-
- // Store the session key before starting encrypting
- NSString *sessionKey = aliceSession.sessionKey;
-
- NSString *message = @"Hello!";
- NSString *aliceToBobMsg = [aliceSession encryptMessage:message error:&error];
-
- XCTAssertEqual(aliceSession.messageIndex, 1);
- XCTAssertGreaterThanOrEqual(aliceToBobMsg.length, 0);
- XCTAssertNil(error);
-
- OLMInboundGroupSession *bobSession = [[OLMInboundGroupSession alloc] initInboundGroupSessionWithSessionKey:sessionKey error:&error];
- XCTAssertEqualObjects(aliceSession.sessionIdentifier, bobSession.sessionIdentifier);
- XCTAssertNil(error);
-
- NSUInteger messageIndex;
-
- NSString *plaintext = [bobSession decryptMessage:aliceToBobMsg messageIndex:&messageIndex error:&error];
- XCTAssertEqualObjects(message, plaintext);
-
- XCTAssertEqual(messageIndex, 0);
- XCTAssertNil(error);
-}
-
-- (void)testOutboundGroupSessionSerialization {
-
- OLMOutboundGroupSession *aliceSession = [[OLMOutboundGroupSession alloc] initOutboundGroupSession];
-
- NSData *aliceData = [NSKeyedArchiver archivedDataWithRootObject:aliceSession];
- OLMOutboundGroupSession *aliceSession2 = [NSKeyedUnarchiver unarchiveObjectWithData:aliceData];
-
- XCTAssertEqualObjects(aliceSession2.sessionKey, aliceSession.sessionKey);
- XCTAssertEqualObjects(aliceSession2.sessionIdentifier, aliceSession.sessionIdentifier);
-}
-
-- (void)testInboundGroupSessionSerialization {
-
- OLMOutboundGroupSession *aliceSession = [[OLMOutboundGroupSession alloc] initOutboundGroupSession];
-
- OLMInboundGroupSession *bobSession = [[OLMInboundGroupSession alloc] initInboundGroupSessionWithSessionKey:aliceSession.sessionKey error:nil];
-
- NSData *bobData = [NSKeyedArchiver archivedDataWithRootObject:bobSession];
- OLMInboundGroupSession *bobSession2 = [NSKeyedUnarchiver unarchiveObjectWithData:bobData];
-
- XCTAssertEqualObjects(bobSession2.sessionIdentifier, aliceSession.sessionIdentifier);
-}
-
-- (void)testInboundGroupSessionImportExport {
-
- NSError *error;
-
- NSString *sessionKey = @"AgAAAAAwMTIzNDU2Nzg5QUJERUYwMTIzNDU2Nzg5QUJDREVGMDEyMzQ1Njc4OUFCREVGM" \
- "DEyMzQ1Njc4OUFCQ0RFRjAxMjM0NTY3ODlBQkRFRjAxMjM0NTY3ODlBQkNERUYwMTIzND" \
- "U2Nzg5QUJERUYwMTIzNDU2Nzg5QUJDREVGMDEyMw0bdg1BDq4Px/slBow06q8n/B9WBfw" \
- "WYyNOB8DlUmXGGwrFmaSb9bR/eY8xgERrxmP07hFmD9uqA2p8PMHdnV5ysmgufE6oLZ5+" \
- "8/mWQOW3VVTnDIlnwd8oHUYRuk8TCQ";
-
- NSString *message = @"AwgAEhAcbh6UpbByoyZxufQ+h2B+8XHMjhR69G8F4+qjMaFlnIXusJZX3r8LnRORG9T3D" \
- "XFdbVuvIWrLyRfm4i8QRbe8VPwGRFG57B1CtmxanuP8bHtnnYqlwPsD";
-
- // init first inbound group session, and decrypt */
- OLMInboundGroupSession *session1 = [[OLMInboundGroupSession alloc] initInboundGroupSessionWithSessionKey:sessionKey error:&error];
-
- XCTAssertNil(error);
- XCTAssertTrue(session1.isVerified);
-
- // decrypt the message
- NSUInteger messageIndex;
- NSString *plaintext = [session1 decryptMessage:message messageIndex:&messageIndex error:&error];
-
- XCTAssertNil(error);
- XCTAssertEqualObjects(plaintext, @"Message");
- XCTAssertEqual(messageIndex, 0);
-
- // export the keys
- NSString *export = [session1 exportSessionAtMessageIndex:0 error:&error];
-
- XCTAssertNil(error);
- XCTAssertGreaterThan(export.length, 0);
-
- // free the old session to check there is no shared data
- session1 = nil;
-
- // import the keys into another inbound group session
- OLMInboundGroupSession *session2 = [[OLMInboundGroupSession alloc] initInboundGroupSessionWithImportedSession:export error:&error];
-
- XCTAssertNil(error);
- XCTAssert(session2);
- XCTAssertFalse(session2.isVerified);
-
- // decrypt the message with the new session
- NSString *plaintext2 = [session2 decryptMessage:message messageIndex:&messageIndex error:&error];
-
- XCTAssertNil(error);
- XCTAssertEqualObjects(plaintext2, @"Message");
- XCTAssertEqual(messageIndex, 0);
- XCTAssertTrue(session2.isVerified);
-}
-
-@end
diff --git a/xcode/OLMKitTests/OLMKitPkTests.m b/xcode/OLMKitTests/OLMKitPkTests.m
deleted file mode 100644
index 7a09130..0000000
--- a/xcode/OLMKitTests/OLMKitPkTests.m
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- Copyright 2018 New Vector Ltd
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-#import <XCTest/XCTest.h>
-#import <OLMKit/OLMKit.h>
-
-/**
- Tests are inspired from js tests.
- */
-@interface OLMKitPkTests : XCTestCase {
- OLMPkEncryption *encryption;
- OLMPkDecryption *decryption;
-}
-
-@end
-
-@implementation OLMKitPkTests
-
-- (void)setUp {
- encryption = [OLMPkEncryption new];
- decryption = [OLMPkDecryption new];
-}
-
-- (void)tearDown {
- encryption = nil;
- decryption = nil;
-}
-
-- (void)testImportExportKeys {
- UInt8 alicePrivateBytes[] = {
- 0x77, 0x07, 0x6D, 0x0A, 0x73, 0x18, 0xA5, 0x7D,
- 0x3C, 0x16, 0xC1, 0x72, 0x51, 0xB2, 0x66, 0x45,
- 0xDF, 0x4C, 0x2F, 0x87, 0xEB, 0xC0, 0x99, 0x2A,
- 0xB1, 0x77, 0xFB, 0xA5, 0x1D, 0xB9, 0x2C, 0x2A
- };
-
- NSData *alicePrivate = [NSData dataWithBytes:alicePrivateBytes length:sizeof(alicePrivateBytes)];
-
- NSError *error;
- NSString *alicePublic = [decryption setPrivateKey:alicePrivate error:&error];
- XCTAssertNil(error);
- XCTAssertEqualObjects(alicePublic, @"hSDwCYkwp1R0i33ctD73Wg2/Og0mOBr066SpjqqbTmo");
-
- NSData *alicePrivateOut = decryption.privateKey;
- XCTAssertNil(error);
- XCTAssertEqualObjects(alicePrivateOut, alicePrivate);
-}
-
-- (void)testEncryptAndDecrypt {
-
- NSString *pubKey = [decryption generateKey:nil];
- NSLog(@"Ephemeral Key: %@", pubKey);
- XCTAssertNotNil(pubKey);
-
- NSString *TEST_TEXT = @"têst1";
- NSError *error;
- [encryption setRecipientKey:pubKey];
- OLMPkMessage *message = [encryption encryptMessage:TEST_TEXT error:&error];
- NSLog(@"message: %@ %@ %@", message.ciphertext, message.mac, message.ephemeralKey);
- XCTAssertNil(error);
- XCTAssertNotNil(message);
- XCTAssertNotNil(message.ciphertext);
- XCTAssertNotNil(message.mac);
- XCTAssertNotNil(message.ephemeralKey);
-
- NSString *decrypted = [decryption decryptMessage:message error:&error];
- XCTAssertNil(error);
- XCTAssertEqualObjects(decrypted, TEST_TEXT);
-
- TEST_TEXT = @"hot beverage: ☕";
- [encryption setRecipientKey:pubKey];
- message = [encryption encryptMessage:TEST_TEXT error:&error];
- decrypted = [decryption decryptMessage:message error:&error];
- XCTAssertEqualObjects(decrypted, TEST_TEXT);
-}
-
-- (void)testOLMPkDecryptionSerialization {
- NSString *TEST_TEXT = @"têst1";
- NSString *pubKey = [decryption generateKey:nil];
- [encryption setRecipientKey:pubKey];
- OLMPkMessage *encrypted = [encryption encryptMessage:TEST_TEXT error:nil];
-
-
- NSData *pickle = [NSKeyedArchiver archivedDataWithRootObject:decryption];
- decryption = nil;
-
- OLMPkDecryption *newDecryption = [NSKeyedUnarchiver unarchiveObjectWithData:pickle];
-
- NSError *error;
- NSString *decrypted = [newDecryption decryptMessage:encrypted error:&error];
- XCTAssertEqualObjects(decrypted, TEST_TEXT);
-}
-
-- (void)testSignAndVerify {
-
- UInt8 seedBytes[] = {
- 0x77, 0x07, 0x6D, 0x0A, 0x73, 0x18, 0xA5, 0x7D,
- 0x3C, 0x16, 0xC1, 0x72, 0x51, 0xB2, 0x66, 0x45,
- 0xDF, 0x4C, 0x2F, 0x87, 0xEB, 0xC0, 0x99, 0x2A,
- 0xB1, 0x77, 0xFB, 0xA5, 0x1D, 0xB9, 0x2C, 0x2A
- };
-
- NSData *seed = [NSData dataWithBytes:seedBytes length:sizeof(seedBytes)];
-
- NSString *TEST_TEXT = @"We hold these truths to be self-evident, that all men are created equal, that they are endowed by their Creator with certain unalienable Rights, that among these are Life, Liberty and the pursuit of Happiness.";
-
- OLMPkSigning *signing = [OLMPkSigning new];
-
- NSError *error;
- NSString *pubKey = [signing doInitWithSeed:seed error:&error];
- XCTAssertNotNil(pubKey);
- XCTAssertNil(error);
-
- NSString *sig = [signing sign:TEST_TEXT error:&error];
- XCTAssertNotNil(sig);
- XCTAssertNil(error);
-
- OLMUtility *util = [OLMUtility new];
- BOOL verify = [util verifyEd25519Signature:sig key:pubKey message:[TEST_TEXT dataUsingEncoding:NSUTF8StringEncoding] error:&error];
- XCTAssertTrue(verify);
- XCTAssertNil(error);
-
- NSString *badSig = [sig stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:@"p"];
- verify = [util verifyEd25519Signature:badSig key:pubKey message:[TEST_TEXT dataUsingEncoding:NSUTF8StringEncoding] error:&error];
- XCTAssertFalse(verify);
- XCTAssertNotNil(error);
-}
-
-@end
diff --git a/xcode/OLMKitTests/OLMKitSASTests.m b/xcode/OLMKitTests/OLMKitSASTests.m
deleted file mode 100644
index e250a67..0000000
--- a/xcode/OLMKitTests/OLMKitSASTests.m
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- Copyright 2019 New Vector Ltd
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- */
-
-#import <XCTest/XCTest.h>
-#import <OLMKit/OLMKit.h>
-
-@interface OLMKitSASTests : XCTestCase {
- OLMSAS *alice;
- OLMSAS *bob;
-}
-
-@end
-
-@implementation OLMKitSASTests
-
-- (void)setUp {
- alice = [OLMSAS new];
- bob = [OLMSAS new];
-}
-
-- (void)tearDown {
- alice = nil;
- bob = nil;
-}
-
-- (void)testSASRandomness
-{
- XCTAssertNotEqualObjects(alice.publicKey, bob.publicKey);
-}
-
-- (void)testSASBytesMatch {
- [alice setTheirPublicKey:bob.publicKey];
- [bob setTheirPublicKey:alice.publicKey];
-
- NSString *sas = @"SAS";
- NSUInteger length = 5;
-
- XCTAssertEqualObjects([alice generateBytes:sas length:length],
- [bob generateBytes:sas length:length]);
-}
-
-- (void)testMACsMatch {
- [alice setTheirPublicKey:bob.publicKey];
- [bob setTheirPublicKey:alice.publicKey];
-
- NSString *string = @"test";
- NSString *info = @"MAC";
-
- NSError *aliceError, *bobError;
- XCTAssertEqualObjects([alice calculateMac:string info:info error:&aliceError],
- [bob calculateMac:string info:info error:&bobError]);
- XCTAssertNil(aliceError);
- XCTAssertNil(bobError);
-}
-
-- (void)testMACLongKdfsMatch {
- [alice setTheirPublicKey:bob.publicKey];
- [bob setTheirPublicKey:alice.publicKey];
-
- NSString *string = @"test";
- NSString *info = @"MAC";
-
- NSError *aliceError, *bobError;
- XCTAssertEqualObjects([alice calculateMacLongKdf:string info:info error:&aliceError],
- [bob calculateMacLongKdf:string info:info error:&bobError]);
- XCTAssertNotEqualObjects([alice calculateMacLongKdf:string info:info error:&aliceError],
- [bob calculateMac:string info:info error:&bobError]);
- XCTAssertNil(aliceError);
- XCTAssertNil(bobError);
-}
-
-
-@end
diff --git a/xcode/OLMKitTests/OLMKitTests.m b/xcode/OLMKitTests/OLMKitTests.m
deleted file mode 100644
index ee02420..0000000
--- a/xcode/OLMKitTests/OLMKitTests.m
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
-Copyright 2016 Chris Ballinger
-Copyright 2016 OpenMarket Ltd
-Copyright 2016 Vector Creations Ltd
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-#import <XCTest/XCTest.h>
-#import <OLMKit/OLMKit.h>
-
-@interface OLMKitTests : XCTestCase
-
-@end
-
-@implementation OLMKitTests
-
-- (void)setUp {
- [super setUp];
- // Put setup code here. This method is called before the invocation of each test method in the class.
-}
-
-- (void)tearDown {
- // Put teardown code here. This method is called after the invocation of each test method in the class.
- [super tearDown];
-}
-
-- (void)testAliceAndBob {
- NSError *error;
-
- OLMAccount *alice = [[OLMAccount alloc] initNewAccount];
- OLMAccount *bob = [[OLMAccount alloc] initNewAccount];
- [bob generateOneTimeKeys:5];
- NSDictionary *bobIdKeys = bob.identityKeys;
- NSString *bobIdKey = bobIdKeys[@"curve25519"];
- NSDictionary *bobOneTimeKeys = bob.oneTimeKeys;
- NSParameterAssert(bobIdKey != nil);
- NSParameterAssert(bobOneTimeKeys != nil);
- __block NSString *bobOneTimeKey = nil;
- NSDictionary *bobOtkCurve25519 = bobOneTimeKeys[@"curve25519"];
- [bobOtkCurve25519 enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
- bobOneTimeKey = obj;
- }];
- XCTAssert([bobOneTimeKey isKindOfClass:[NSString class]]);
-
- OLMSession *aliceSession = [[OLMSession alloc] initOutboundSessionWithAccount:alice theirIdentityKey:bobIdKey theirOneTimeKey:bobOneTimeKey error:nil];
- NSString *message = @"Hello!";
- OLMMessage *aliceToBobMsg = [aliceSession encryptMessage:message error:&error];
- XCTAssertNil(error);
-
- OLMSession *bobSession = [[OLMSession alloc] initInboundSessionWithAccount:bob oneTimeKeyMessage:aliceToBobMsg.ciphertext error:nil];
- NSString *plaintext = [bobSession decryptMessage:aliceToBobMsg error:&error];
- XCTAssertEqualObjects(message, plaintext);
- XCTAssertNil(error);
-
- XCTAssert([bobSession matchesInboundSession:aliceToBobMsg.ciphertext]);
- XCTAssertFalse([aliceSession matchesInboundSession:@"ARandomOtkMessage"]);
-
- NSString *aliceIdKey = alice.identityKeys[@"curve25519"];
- XCTAssert([bobSession matchesInboundSessionFrom:aliceIdKey oneTimeKeyMessage:aliceToBobMsg.ciphertext]);
- XCTAssertFalse([bobSession matchesInboundSessionFrom:@"ARandomIdKey" oneTimeKeyMessage:aliceToBobMsg.ciphertext]);
- XCTAssertFalse([bobSession matchesInboundSessionFrom:aliceIdKey oneTimeKeyMessage:@"ARandomOtkMessage"]);
-
- BOOL success = [bob removeOneTimeKeysForSession:bobSession];
- XCTAssertTrue(success);
-}
-
-- (void) testBackAndForth {
- OLMAccount *alice = [[OLMAccount alloc] initNewAccount];
- OLMAccount *bob = [[OLMAccount alloc] initNewAccount];
- [bob generateOneTimeKeys:1];
- NSDictionary *bobIdKeys = bob.identityKeys;
- NSString *bobIdKey = bobIdKeys[@"curve25519"];
- NSDictionary *bobOneTimeKeys = bob.oneTimeKeys;
- NSParameterAssert(bobIdKey != nil);
- NSParameterAssert(bobOneTimeKeys != nil);
- __block NSString *bobOneTimeKey = nil;
- NSDictionary *bobOtkCurve25519 = bobOneTimeKeys[@"curve25519"];
- [bobOtkCurve25519 enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
- bobOneTimeKey = obj;
- }];
- XCTAssert([bobOneTimeKey isKindOfClass:[NSString class]]);
-
- OLMSession *aliceSession = [[OLMSession alloc] initOutboundSessionWithAccount:alice theirIdentityKey:bobIdKey theirOneTimeKey:bobOneTimeKey error:nil];
- NSString *message = @"Hello I'm Alice!";
- OLMMessage *aliceToBobMsg = [aliceSession encryptMessage:message error:nil];
-
- OLMSession *bobSession = [[OLMSession alloc] initInboundSessionWithAccount:bob oneTimeKeyMessage:aliceToBobMsg.ciphertext error:nil];
- NSString *plaintext = [bobSession decryptMessage:aliceToBobMsg error:nil];
- XCTAssertEqualObjects(message, plaintext);
- BOOL success = [bob removeOneTimeKeysForSession:bobSession];
- XCTAssertTrue(success);
-
- NSString *msg1 = @"Hello I'm Bob!";
- NSString *msg2 = @"Isn't life grand?";
- NSString *msg3 = @"Let's go to the opera.";
-
- OLMMessage *eMsg1 = [bobSession encryptMessage:msg1 error:nil];
- OLMMessage *eMsg2 = [bobSession encryptMessage:msg2 error:nil];
- OLMMessage *eMsg3 = [bobSession encryptMessage:msg3 error:nil];
-
- NSString *dMsg1 = [aliceSession decryptMessage:eMsg1 error:nil];
- NSString *dMsg2 = [aliceSession decryptMessage:eMsg2 error:nil];
- NSString *dMsg3 = [aliceSession decryptMessage:eMsg3 error:nil];
- XCTAssertEqualObjects(msg1, dMsg1);
- XCTAssertEqualObjects(msg2, dMsg2);
- XCTAssertEqualObjects(msg3, dMsg3);
-}
-
-- (void) testAccountSerialization {
- OLMAccount *bob = [[OLMAccount alloc] initNewAccount];
- [bob generateOneTimeKeys:5];
- NSDictionary *bobIdKeys = bob.identityKeys;
- NSDictionary *bobOneTimeKeys = bob.oneTimeKeys;
-
- NSData *bobData = [NSKeyedArchiver archivedDataWithRootObject:bob];
-
- OLMAccount *bob2 = [NSKeyedUnarchiver unarchiveObjectWithData:bobData];
- NSDictionary *bobIdKeys2 = bob2.identityKeys;
- NSDictionary *bobOneTimeKeys2 = bob2.oneTimeKeys;
-
- XCTAssertEqualObjects(bobIdKeys, bobIdKeys2);
- XCTAssertEqualObjects(bobOneTimeKeys, bobOneTimeKeys2);
-}
-
-- (void) testSessionSerialization {
- NSError *error;
-
- OLMAccount *alice = [[OLMAccount alloc] initNewAccount];
- OLMAccount *bob = [[OLMAccount alloc] initNewAccount];
- [bob generateOneTimeKeys:1];
- NSDictionary *bobIdKeys = bob.identityKeys;
- NSString *bobIdKey = bobIdKeys[@"curve25519"];
- NSDictionary *bobOneTimeKeys = bob.oneTimeKeys;
- NSParameterAssert(bobIdKey != nil);
- NSParameterAssert(bobOneTimeKeys != nil);
- __block NSString *bobOneTimeKey = nil;
- NSDictionary *bobOtkCurve25519 = bobOneTimeKeys[@"curve25519"];
- [bobOtkCurve25519 enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
- bobOneTimeKey = obj;
- }];
- XCTAssert([bobOneTimeKey isKindOfClass:[NSString class]]);
-
- OLMSession *aliceSession = [[OLMSession alloc] initOutboundSessionWithAccount:alice theirIdentityKey:bobIdKey theirOneTimeKey:bobOneTimeKey error:nil];
- NSString *message = @"Hello I'm Alice!";
- OLMMessage *aliceToBobMsg = [aliceSession encryptMessage:message error:&error];
- XCTAssertNil(error);
-
-
- OLMSession *bobSession = [[OLMSession alloc] initInboundSessionWithAccount:bob oneTimeKeyMessage:aliceToBobMsg.ciphertext error:nil];
- NSString *plaintext = [bobSession decryptMessage:aliceToBobMsg error:nil];
- XCTAssertEqualObjects(message, plaintext);
- BOOL success = [bob removeOneTimeKeysForSession:bobSession];
- XCTAssertTrue(success);
-
- NSString *msg1 = @"Hello I'm Bob!";
- NSString *msg2 = @"Isn't life grand?";
- NSString *msg3 = @"Let's go to the opera.";
-
- OLMMessage *eMsg1 = [bobSession encryptMessage:msg1 error:nil];
- OLMMessage *eMsg2 = [bobSession encryptMessage:msg2 error:nil];
- OLMMessage *eMsg3 = [bobSession encryptMessage:msg3 error:nil];
-
- NSData *aliceData = [NSKeyedArchiver archivedDataWithRootObject:aliceSession];
- OLMSession *alice2 = [NSKeyedUnarchiver unarchiveObjectWithData:aliceData];
-
- NSString *dMsg1 = [alice2 decryptMessage:eMsg1 error:nil];
- NSString *dMsg2 = [alice2 decryptMessage:eMsg2 error:nil];
- NSString *dMsg3 = [alice2 decryptMessage:eMsg3 error:nil];
- XCTAssertEqualObjects(msg1, dMsg1);
- XCTAssertEqualObjects(msg2, dMsg2);
- XCTAssertEqualObjects(msg3, dMsg3);
-}
-
-- (void)testEd25519Signing {
-
- OLMUtility *olmUtility = [[OLMUtility alloc] init];
- OLMAccount *alice = [[OLMAccount alloc] initNewAccount];
-
- NSDictionary *aJSON = @{
- @"key1": @"value1",
- @"key2": @"value2"
- };
- NSData *message = [NSKeyedArchiver archivedDataWithRootObject:aJSON];
- NSString *signature = [alice signMessage:message];
-
-
- NSString *aliceEd25519Key = alice.identityKeys[@"ed25519"];
-
- NSError *error;
- BOOL result = [olmUtility verifyEd25519Signature:signature key:aliceEd25519Key message:message error:&error];
- XCTAssert(result);
- XCTAssertNil(error);
-}
-
-@end