aboutsummaryrefslogtreecommitdiff
path: root/xcode
diff options
context:
space:
mode:
authormanuroe <manu@matrix.org>2016-11-14 17:35:24 +0100
committermanuroe <manu@matrix.org>2016-11-14 17:35:24 +0100
commit7ee17a295738f0db8cab74cec2343a577f2ade45 (patch)
treeab4dfe945e68ded9c92cb46e78c81032e40f30aa /xcode
parentaa70c8afbccdccd289a69fb513dd3664aa8e3fc7 (diff)
OLMKit: Add missing implementations for matchesInboundSession matchesInboundSessionFromolmkit-v2.0.0
Diffstat (limited to 'xcode')
-rw-r--r--xcode/OLMKit.xcodeproj/project.pbxproj8
-rw-r--r--xcode/OLMKit/OLMSession.m35
-rw-r--r--xcode/OLMKitTests/OLMKitTests.m11
-rw-r--r--xcode/Podfile.lock2
4 files changed, 50 insertions, 6 deletions
diff --git a/xcode/OLMKit.xcodeproj/project.pbxproj b/xcode/OLMKit.xcodeproj/project.pbxproj
index 0ec7587..a3b636f 100644
--- a/xcode/OLMKit.xcodeproj/project.pbxproj
+++ b/xcode/OLMKit.xcodeproj/project.pbxproj
@@ -182,7 +182,7 @@
3274F5EF1D9A633A005282E4 /* Project object */ = {
isa = PBXProject;
attributes = {
- LastUpgradeCheck = 0800;
+ LastUpgradeCheck = 0810;
ORGANIZATIONNAME = matrix.org;
TargetAttributes = {
3274F5F71D9A633A005282E4 = {
@@ -273,7 +273,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
- shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run \'pod install\' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
+ shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
793D0533290528B7C0E17CAD /* [CP] Copy Pods Resources */ = {
@@ -303,7 +303,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
- shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run \'pod install\' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
+ shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
@@ -354,6 +354,7 @@
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -405,6 +406,7 @@
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
diff --git a/xcode/OLMKit/OLMSession.m b/xcode/OLMKit/OLMSession.m
index a47deb1..eee65a9 100644
--- a/xcode/OLMKit/OLMSession.m
+++ b/xcode/OLMKit/OLMSession.m
@@ -156,6 +156,41 @@
return idString;
}
+- (BOOL)matchesInboundSession:(NSString *)oneTimeKeyMessage {
+ NSData *otk = [oneTimeKeyMessage dataUsingEncoding:NSUTF8StringEncoding];
+
+ size_t result = olm_matches_inbound_session(_session, otk.bytes, otk.length);
+ if (result == 1) {
+ return YES;
+ }
+ else {
+ if (result == olm_error()) {
+ const char *error = olm_session_last_error(_session);
+ NSLog(@"olm_matches_inbound_session error: %s", error);
+ }
+ return NO;
+ }
+}
+
+- (BOOL)matchesInboundSessionFrom:(NSString *)theirIdentityKey oneTimeKeyMessage:(NSString *)oneTimeKeyMessage {
+ NSData *idKey = [theirIdentityKey dataUsingEncoding:NSUTF8StringEncoding];
+ NSData *otk = [oneTimeKeyMessage dataUsingEncoding:NSUTF8StringEncoding];
+
+ size_t result = olm_matches_inbound_session_from(_session,
+ idKey.bytes, idKey.length,
+ otk.bytes, otk.length);
+ if (result == 1) {
+ return YES;
+ }
+ else {
+ if (result == olm_error()) {
+ const char *error = olm_session_last_error(_session);
+ NSLog(@"olm_matches_inbound_session error: %s", error);
+ }
+ return NO;
+ }
+}
+
- (OLMMessage*) encryptMessage:(NSString*)message error:(NSError**)error {
size_t messageType = olm_encrypt_message_type(_session);
size_t randomLength = olm_encrypt_random_length(_session);
diff --git a/xcode/OLMKitTests/OLMKitTests.m b/xcode/OLMKitTests/OLMKitTests.m
index 251c90e..1adbde2 100644
--- a/xcode/OLMKitTests/OLMKitTests.m
+++ b/xcode/OLMKitTests/OLMKitTests.m
@@ -52,6 +52,15 @@
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);
}
@@ -96,8 +105,6 @@
XCTAssertEqualObjects(msg1, dMsg1);
XCTAssertEqualObjects(msg2, dMsg2);
XCTAssertEqualObjects(msg3, dMsg3);
-
-
}
- (void) testAccountSerialization {
diff --git a/xcode/Podfile.lock b/xcode/Podfile.lock
index 3ac110a..2d69849 100644
--- a/xcode/Podfile.lock
+++ b/xcode/Podfile.lock
@@ -13,7 +13,7 @@ EXTERNAL SOURCES:
:path: ../OLMKit.podspec
SPEC CHECKSUMS:
- OLMKit: ed17cdf7695bc0de1e2bf98243eb65f5b9ddebc1
+ OLMKit: 5f2894a210ca99ad17128af4fd3beeeeb0eca404
PODFILE CHECKSUM: 4e261dae61d833ec5585ced2473023b98909fd35