Signal-iOS/tests/Security/OWSFingerprintTest.m
Michael Kirk 60a39f93c6 Remove phone numbers from scannable QR Code
Initially they were there to offer richer error messages when the wrong
code was scanned.

However, we found that people were posting them publicly,
misunderstanding the QR codes to be a kind of personal identifier.

For one, this isn't useful because the QR codes, like safety numbers,
are unique *per* conversation. So they aren't useful in a generic sense.
And secondly this is bad because the QR code contains both parties phone
numbers.

// FREEBIE
2016-11-14 08:43:24 -05:00

79 lines
4.4 KiB
Objective-C

// Created by Michael Kirk on 9/14/16.
// Copyright © 2016 Open Whisper Systems. All rights reserved.
#import "OWSFingerprint.h"
#import <25519/Curve25519.h>
#import <XCTest/XCTest.h>
@interface OWSFingerprintTest : XCTestCase
@end
@implementation OWSFingerprintTest
- (void)testDisplayableTextInsertsSpaces
{
NSString *aliceStableId = @"+13231111111";
NSData *aliceIdentityKey = [Curve25519 generateKeyPair].publicKey;
NSString *bobStableId = @"+14152222222";
NSData *bobIdentityKey = [Curve25519 generateKeyPair].publicKey;
OWSFingerprint *aliceFingerprint = [OWSFingerprint fingerprintWithMyStableId:aliceStableId
myIdentityKey:aliceIdentityKey
theirStableId:bobStableId
theirIdentityKey:bobIdentityKey
theirName:@"Bob"
hashIterations:2];
NSString *displayableText = aliceFingerprint.displayableText;
XCTAssertNotEqualObjects(@" ", [displayableText substringWithRange:NSMakeRange(0, 1)]);
XCTAssertNotEqualObjects(@" ", [displayableText substringWithRange:NSMakeRange(1, 1)]);
XCTAssertNotEqualObjects(@" ", [displayableText substringWithRange:NSMakeRange(2, 1)]);
XCTAssertNotEqualObjects(@" ", [displayableText substringWithRange:NSMakeRange(3, 1)]);
XCTAssertNotEqualObjects(@" ", [displayableText substringWithRange:NSMakeRange(4, 1)]);
XCTAssertEqualObjects(@" ", [displayableText substringWithRange:NSMakeRange(5, 1)]);
XCTAssertNotEqualObjects(@" ", [displayableText substringWithRange:NSMakeRange(6, 1)]);
XCTAssertNotEqualObjects(@" ", [displayableText substringWithRange:NSMakeRange(7, 1)]);
XCTAssertNotEqualObjects(@" ", [displayableText substringWithRange:NSMakeRange(8, 1)]);
XCTAssertNotEqualObjects(@" ", [displayableText substringWithRange:NSMakeRange(9, 1)]);
XCTAssertNotEqualObjects(@" ", [displayableText substringWithRange:NSMakeRange(10, 1)]);
XCTAssertEqualObjects(@" ", [displayableText substringWithRange:NSMakeRange(11, 1)]);
}
- (void)testTextMatchesReciprocally
{
NSString *aliceStableId = @"+13231111111";
NSData *aliceIdentityKey = [Curve25519 generateKeyPair].publicKey;
NSString *bobStableId = @"+14152222222";
NSData *bobIdentityKey = [Curve25519 generateKeyPair].publicKey;
NSString *charlieStableId = @"+14153333333";
NSData *charlieIdentityKey = [Curve25519 generateKeyPair].publicKey;
OWSFingerprint *aliceFingerprint = [OWSFingerprint fingerprintWithMyStableId:aliceStableId
myIdentityKey:aliceIdentityKey
theirStableId:bobStableId
theirIdentityKey:bobIdentityKey
theirName:@"Bob"
hashIterations:2];
OWSFingerprint *bobFingerprint = [OWSFingerprint fingerprintWithMyStableId:bobStableId
myIdentityKey:bobIdentityKey
theirStableId:aliceStableId
theirIdentityKey:aliceIdentityKey
theirName:@"Alice"
hashIterations:2];
OWSFingerprint *charlieFingerprint = [OWSFingerprint fingerprintWithMyStableId:charlieStableId
myIdentityKey:charlieIdentityKey
theirStableId:aliceStableId
theirIdentityKey:aliceIdentityKey
theirName:@"Alice"
hashIterations:2];
XCTAssertEqualObjects(aliceFingerprint.displayableText, bobFingerprint.displayableText);
XCTAssertNotEqualObjects(aliceFingerprint.displayableText, charlieFingerprint.displayableText);
}
@end