From 719eb543a8d08c4f536ea7933ffb3af0a8553e87 Mon Sep 17 00:00:00 2001 From: Chris Ballinger Date: Fri, 8 Apr 2016 17:24:41 -0700 Subject: Xcode, podspec, wrapper --- xcode/OLMKitTests/Info.plist | 24 ++++++++++++++++++++++++ xcode/OLMKitTests/OLMKitTests.m | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 xcode/OLMKitTests/Info.plist create mode 100644 xcode/OLMKitTests/OLMKitTests.m (limited to 'xcode/OLMKitTests') diff --git a/xcode/OLMKitTests/Info.plist b/xcode/OLMKitTests/Info.plist new file mode 100644 index 0000000..ba72822 --- /dev/null +++ b/xcode/OLMKitTests/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/xcode/OLMKitTests/OLMKitTests.m b/xcode/OLMKitTests/OLMKitTests.m new file mode 100644 index 0000000..944d11c --- /dev/null +++ b/xcode/OLMKitTests/OLMKitTests.m @@ -0,0 +1,41 @@ +// +// OLMKitTests.m +// OLMKitTests +// +// Created by Chris Ballinger on 4/8/16. +// +// + +#import +@import OLMKit; + +@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)testExample { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct results. + OLMAccount *alice = [[OLMAccount alloc] initNewAccount]; + OLMAccount *bob = [[OLMAccount alloc] initNewAccount]; + [bob generateOneTimeKeys:5]; + NSDictionary *identityKeys = bob.identityKeys; + NSDictionary *oneTimeKeys = bob.oneTimeKeys; + NSParameterAssert(identityKeys != nil); + NSParameterAssert(oneTimeKeys != nil); +} + + +@end -- cgit v1.2.3 From f505113fb7a6d61015ad8050b3fb4e26df029150 Mon Sep 17 00:00:00 2001 From: Chris Ballinger Date: Sat, 9 Apr 2016 14:00:30 -0700 Subject: Initial test passing --- xcode/OLMKitTests/OLMKitTests.m | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'xcode/OLMKitTests') diff --git a/xcode/OLMKitTests/OLMKitTests.m b/xcode/OLMKitTests/OLMKitTests.m index 944d11c..7075057 100644 --- a/xcode/OLMKitTests/OLMKitTests.m +++ b/xcode/OLMKitTests/OLMKitTests.m @@ -31,10 +31,27 @@ OLMAccount *alice = [[OLMAccount alloc] initNewAccount]; OLMAccount *bob = [[OLMAccount alloc] initNewAccount]; [bob generateOneTimeKeys:5]; - NSDictionary *identityKeys = bob.identityKeys; - NSDictionary *oneTimeKeys = bob.oneTimeKeys; - NSParameterAssert(identityKeys != nil); - NSParameterAssert(oneTimeKeys != nil); + 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]; + NSString *message = @"Hello!"; + OLMMessage *aliceToBobMsg = [aliceSession encryptMessage:message]; + + OLMSession *bobSession = [[OLMSession alloc] initInboundSessionWithAccount:bob oneTimeKeyMessage:aliceToBobMsg.ciphertext]; + NSString *plaintext = [bobSession decryptMessage:aliceToBobMsg]; + XCTAssertEqualObjects(message, plaintext); + BOOL success = [bobSession removeOneTimeKeys]; + XCTAssertTrue(success); } -- cgit v1.2.3 From daab2a58af947cddd67fe9f30dd3a9fc327650c0 Mon Sep 17 00:00:00 2001 From: Chris Ballinger Date: Wed, 13 Apr 2016 16:53:47 -0700 Subject: OLMAccount and OLMSession serialization --- xcode/OLMKitTests/OLMKitTests.m | 111 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 107 insertions(+), 4 deletions(-) (limited to 'xcode/OLMKitTests') diff --git a/xcode/OLMKitTests/OLMKitTests.m b/xcode/OLMKitTests/OLMKitTests.m index 7075057..c76d636 100644 --- a/xcode/OLMKitTests/OLMKitTests.m +++ b/xcode/OLMKitTests/OLMKitTests.m @@ -25,9 +25,7 @@ [super tearDown]; } -- (void)testExample { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct results. +- (void)testAliceAndBob { OLMAccount *alice = [[OLMAccount alloc] initNewAccount]; OLMAccount *bob = [[OLMAccount alloc] initNewAccount]; [bob generateOneTimeKeys:5]; @@ -50,9 +48,114 @@ OLMSession *bobSession = [[OLMSession alloc] initInboundSessionWithAccount:bob oneTimeKeyMessage:aliceToBobMsg.ciphertext]; NSString *plaintext = [bobSession decryptMessage:aliceToBobMsg]; XCTAssertEqualObjects(message, plaintext); - BOOL success = [bobSession removeOneTimeKeys]; + 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]; + NSString *message = @"Hello I'm Alice!"; + OLMMessage *aliceToBobMsg = [aliceSession encryptMessage:message]; + + OLMSession *bobSession = [[OLMSession alloc] initInboundSessionWithAccount:bob oneTimeKeyMessage:aliceToBobMsg.ciphertext]; + NSString *plaintext = [bobSession decryptMessage:aliceToBobMsg]; + 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]; + OLMMessage *eMsg2 = [bobSession encryptMessage:msg2]; + OLMMessage *eMsg3 = [bobSession encryptMessage:msg3]; + + NSString *dMsg1 = [aliceSession decryptMessage:eMsg1]; + NSString *dMsg2 = [aliceSession decryptMessage:eMsg2]; + NSString *dMsg3 = [aliceSession decryptMessage:eMsg3]; + 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 = bob.oneTimeKeys; + + XCTAssertEqualObjects(bobIdKeys, bobIdKeys2); + XCTAssertEqualObjects(bobOneTimeKeys, bobOneTimeKeys2); +} + +- (void) testSessionSerialization { + 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]; + NSString *message = @"Hello I'm Alice!"; + OLMMessage *aliceToBobMsg = [aliceSession encryptMessage:message]; + + OLMSession *bobSession = [[OLMSession alloc] initInboundSessionWithAccount:bob oneTimeKeyMessage:aliceToBobMsg.ciphertext]; + NSString *plaintext = [bobSession decryptMessage:aliceToBobMsg]; + 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]; + OLMMessage *eMsg2 = [bobSession encryptMessage:msg2]; + OLMMessage *eMsg3 = [bobSession encryptMessage:msg3]; + + NSData *aliceData = [NSKeyedArchiver archivedDataWithRootObject:aliceSession]; + OLMSession *alice2 = [NSKeyedUnarchiver unarchiveObjectWithData:aliceData]; + + NSString *dMsg1 = [alice2 decryptMessage:eMsg1]; + NSString *dMsg2 = [alice2 decryptMessage:eMsg2]; + NSString *dMsg3 = [alice2 decryptMessage:eMsg3]; + XCTAssertEqualObjects(msg1, dMsg1); + XCTAssertEqualObjects(msg2, dMsg2); + XCTAssertEqualObjects(msg3, dMsg3); +} + @end -- cgit v1.2.3