OLMKit: Add missing implementations for matchesInboundSession matchesInboundSessionFrom

release-v2.1.0 olmkit-v2.0.0
manuroe 2016-11-14 17:35:24 +01:00
parent aa70c8afbc
commit 7ee17a2957
4 changed files with 50 additions and 6 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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 {

View File

@ -13,7 +13,7 @@ EXTERNAL SOURCES:
:path: ../OLMKit.podspec
SPEC CHECKSUMS:
OLMKit: ed17cdf7695bc0de1e2bf98243eb65f5b9ddebc1
OLMKit: 5f2894a210ca99ad17128af4fd3beeeeb0eca404
PODFILE CHECKSUM: 4e261dae61d833ec5585ced2473023b98909fd35