Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
There is no longer a distinction between redphone/text secure users. (#…
Browse files Browse the repository at this point in the history
…12)

We only support voice+text clients 

* remove voice parameter since we always support voice
* test TSAttributes

Plus re-styled touched code:
* don't access ivars outside of init/dealloc
* remove unused code


// FREEBIE
  • Loading branch information
michaelkirk committed Jun 28, 2016
1 parent 8058951 commit 9ab38ef
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
45458B7A1CC342B600A02153 /* TSStorageSignedPreKeyStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 45458B711CC342B600A02153 /* TSStorageSignedPreKeyStore.m */; };
45458B7B1CC342B600A02153 /* CryptographyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 45458B731CC342B600A02153 /* CryptographyTests.m */; };
45458B7C1CC342B600A02153 /* MessagePaddingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 45458B741CC342B600A02153 /* MessagePaddingTests.m */; };
45A856AC1D220BFF0056CD4D /* TSAttributesTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45A856AB1D220BFF0056CD4D /* TSAttributesTest.m */; };
51520592F83F2440F2DE4D67 /* libPods-TSKitiOSTestApp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B8362AB8E280E0F64352F08A /* libPods-TSKitiOSTestApp.a */; };
B6273DD61C13A2E500738558 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = B6273DD51C13A2E500738558 /* main.m */; };
B6273DD91C13A2E500738558 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = B6273DD81C13A2E500738558 /* AppDelegate.m */; };
Expand Down Expand Up @@ -47,6 +48,7 @@
45458B711CC342B600A02153 /* TSStorageSignedPreKeyStore.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TSStorageSignedPreKeyStore.m; sourceTree = "<group>"; };
45458B731CC342B600A02153 /* CryptographyTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CryptographyTests.m; sourceTree = "<group>"; };
45458B741CC342B600A02153 /* MessagePaddingTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MessagePaddingTests.m; sourceTree = "<group>"; };
45A856AB1D220BFF0056CD4D /* TSAttributesTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TSAttributesTest.m; sourceTree = "<group>"; };
B6273DD11C13A2E500738558 /* TSKitiOSTestApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TSKitiOSTestApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
B6273DD51C13A2E500738558 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
B6273DD71C13A2E500738558 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -88,6 +90,7 @@
isa = PBXGroup;
children = (
45458B6A1CC342B600A02153 /* SignedPreKeyDeletionTests.m */,
45A856AB1D220BFF0056CD4D /* TSAttributesTest.m */,
);
name = Account;
path = ../../../tests/Account;
Expand Down Expand Up @@ -417,6 +420,7 @@
45458B7A1CC342B600A02153 /* TSStorageSignedPreKeyStore.m in Sources */,
45458B771CC342B600A02153 /* TSMessageStorageTests.m in Sources */,
45458B7C1CC342B600A02153 /* MessagePaddingTests.m in Sources */,
45A856AC1D220BFF0056CD4D /* TSAttributesTest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
1 change: 0 additions & 1 deletion src/Account/TSAccountManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ typedef void (^failedBlock)(NSError *error);
+ (void)verifyAccountWithCode:(NSString *)verificationCode
pushToken:(NSString *)pushToken
voipToken:(NSString *)voipToken
supportsVoice:(BOOL)voice
success:(successCompletionBlock)successBlock
failure:(failedBlock)failureBlock;

Expand Down
4 changes: 1 addition & 3 deletions src/Account/TSAccountManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ + (void)rerequestVoiceWithSuccess:(successCompletionBlock)successBlock failure:(
+ (void)verifyAccountWithCode:(NSString *)verificationCode
pushToken:(NSString *)pushToken
voipToken:(NSString *)voipToken
supportsVoice:(BOOL)voice
success:(successCompletionBlock)successBlock
failure:(failedBlock)failureBlock {
NSString *authToken = [self generateNewAccountAuthenticationToken];
Expand All @@ -158,8 +157,7 @@ + (void)verifyAccountWithCode:(NSString *)verificationCode
TSVerifyCodeRequest *request = [[TSVerifyCodeRequest alloc] initWithVerificationCode:verificationCode
forNumber:phoneNumber
signalingKey:signalingKey
authKey:authToken
supportsVoice:voice];
authKey:authToken];

[[TSNetworkManager sharedManager] makeRequest:request
success:^(NSURLSessionDataTask *task, id responseObject) {
Expand Down
5 changes: 2 additions & 3 deletions src/Account/TSAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@

@interface TSAttributes : NSObject

+ (NSDictionary *)attributesFromStorageWithVoiceSupport:(BOOL)voice;
+ (NSDictionary *)attributesFromStorageWithVoiceSupport;

+ (NSDictionary *)attributesWithSignalingKey:(NSString *)signalingKey
serverAuthToken:(NSString *)authToken
supportsVoice:(BOOL)voice;
serverAuthToken:(NSString *)authToken;

@end
9 changes: 3 additions & 6 deletions src/Account/TSAttributes.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,18 @@

@implementation TSAttributes

+ (NSDictionary *)attributesFromStorageWithVoiceSupport:(BOOL)voice {
+ (NSDictionary *)attributesFromStorageWithVoiceSupport {
return [self attributesWithSignalingKey:[TSStorageManager signalingKey]
serverAuthToken:[TSStorageManager serverAuthToken]
supportsVoice:voice];
serverAuthToken:[TSStorageManager serverAuthToken]];
}

+ (NSDictionary *)attributesWithSignalingKey:(NSString *)signalingKey
serverAuthToken:(NSString *)authToken
supportsVoice:(BOOL)voice

{
return @{
@"signalingKey" : signalingKey,
@"AuthKey" : authToken,
@"voice" : [NSNumber numberWithBool:voice],
@"voice" : [NSNumber numberWithBool:YES], // all Signal-iOS clients support voice
@"registrationId" : [NSString stringWithFormat:@"%i", [TSAccountManager getOrGenerateRegistrationId]]
};
}
Expand Down
7 changes: 2 additions & 5 deletions src/Contacts/Contact.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@
@property (readonly, nonatomic) NSString *notes;

- (NSString *)fullName;
- (NSString *)allPhoneNumbers;

- (BOOL)isTextSecureContact;
- (BOOL)isRedPhoneContact;

- (NSArray *)textSecureIdentifiers;
- (NSArray *)redPhoneIdentifiers;
- (BOOL)isSignalContact;
- (NSArray<NSString *> *)textSecureIdentifiers;

#if TARGET_OS_IOS

Expand Down
60 changes: 8 additions & 52 deletions src/Contacts/Contact.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
#import "SignalRecipient.h"
#import "TSStorageManager.h"

static NSString *const DEFAULTS_KEY_CONTACT = @"DefaultsKeyContact";
static NSString *const DEFAULTS_KEY_PHONE_NUMBER = @"DefaultsKeyPhoneNumber";
static NSString *const DEFAULTS_KEY_CALL_TYPE = @"DefaultsKeycallType";
static NSString *const DEFAULTS_KEY_DATE = @"DefaultsKeyDate";

@implementation Contact

#if TARGET_OS_IOS
Expand Down Expand Up @@ -42,38 +37,25 @@ - (instancetype)initWithContactWithFirstName:(NSString *)firstName

- (NSString *)fullName {
NSMutableString *fullName = [NSMutableString string];
if (_firstName)
[fullName appendString:_firstName];
if (_lastName) {
[fullName appendString:[NSString stringWithFormat:@" %@", _lastName]];
if (self.firstName)
[fullName appendString:self.firstName];
if (self.lastName) {
[fullName appendString:[NSString stringWithFormat:@" %@", self.lastName]];
}
return fullName;
}

- (NSString *)allPhoneNumbers {
NSString *allNumbers = @"";
for (PhoneNumber *number in self.parsedPhoneNumbers) {
allNumbers = [allNumbers stringByAppendingString:number.toE164];
allNumbers = [allNumbers stringByAppendingString:@";"];
}
return allNumbers;
}

- (NSString *)description {
return [NSString stringWithFormat:@"%@ %@: %@", _firstName, _lastName, _userTextPhoneNumbers];
return [NSString stringWithFormat:@"%@ %@: %@", self.firstName, self.lastName, self.userTextPhoneNumbers];
}

- (BOOL)isTextSecureContact {
- (BOOL)isSignalContact {
NSArray *identifiers = [self textSecureIdentifiers];

if ([identifiers count] > 0) {
return YES;
}

return NO;
return [identifiers count] > 0;
}

- (NSArray *)textSecureIdentifiers {
- (NSArray<NSString *> *)textSecureIdentifiers {
__block NSMutableArray *identifiers = [NSMutableArray array];

[[TSStorageManager sharedManager]
Expand All @@ -87,30 +69,4 @@ - (NSArray *)textSecureIdentifiers {
return identifiers;
}

- (BOOL)isRedPhoneContact {
NSArray *identifiers = [self redPhoneIdentifiers];

if ([identifiers count] > 0) {
return YES;
}

return NO;
}

- (NSArray *)redPhoneIdentifiers {
__block NSMutableArray *identifiers = [NSMutableArray array];

[[TSStorageManager sharedManager]
.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
for (PhoneNumber *number in self.parsedPhoneNumbers) {
SignalRecipient *recipient =
[SignalRecipient recipientWithTextSecureIdentifier:number.toE164 withTransaction:transaction];
if (recipient && recipient.supportsVoice) {
[identifiers addObject:number.toE164];
}
}
}];
return identifiers;
}

@end
2 changes: 1 addition & 1 deletion src/Network/API/Requests/TSUpdateAttributesRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

@interface TSUpdateAttributesRequest : TSRequest

- (instancetype)initWithUpdatedAttributesWithVoice:(BOOL)supportsVoice;
- (instancetype)initWithUpdatedAttributesWithVoice;

@end
4 changes: 2 additions & 2 deletions src/Network/API/Requests/TSUpdateAttributesRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

@implementation TSUpdateAttributesRequest

- (instancetype)initWithUpdatedAttributesWithVoice:(BOOL)supportsVoice {
- (instancetype)initWithUpdatedAttributesWithVoice {
NSString *endPoint = [textSecureAccountsAPI stringByAppendingString:textSecureAttributesAPI];
self = [super initWithURL:[NSURL URLWithString:endPoint]];

if (self) {
[self setHTTPMethod:@"PUT"];
[self.parameters addEntriesFromDictionary:[TSAttributes attributesFromStorageWithVoiceSupport:supportsVoice]];
[self.parameters addEntriesFromDictionary:[TSAttributes attributesFromStorageWithVoiceSupport]];
}

return self;
Expand Down
3 changes: 1 addition & 2 deletions src/Network/API/Requests/TSVerifyCodeRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
- (TSRequest *)initWithVerificationCode:(NSString *)verificationCode
forNumber:(NSString *)phoneNumber
signalingKey:(NSString *)signalingKey
authKey:(NSString *)authKey
supportsVoice:(BOOL)voice;
authKey:(NSString *)authKey;

@property (nonatomic, readonly) NSString *numberToValidate;

Expand Down
5 changes: 2 additions & 3 deletions src/Network/API/Requests/TSVerifyCodeRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ @implementation TSVerifyCodeRequest
- (TSRequest *)initWithVerificationCode:(NSString *)verificationCode
forNumber:(NSString *)phoneNumber
signalingKey:(NSString *)signalingKey
authKey:(NSString *)authKey
supportsVoice:(BOOL)voice {
authKey:(NSString *)authKey {
self = [super
initWithURL:[NSURL URLWithString:[NSString
stringWithFormat:@"%@/code/%@", textSecureAccountsAPI, verificationCode]]];

NSDictionary *attributes =
[TSAttributes attributesWithSignalingKey:signalingKey serverAuthToken:authKey supportsVoice:voice];
[TSAttributes attributesWithSignalingKey:signalingKey serverAuthToken:authKey];

_numberToValidate = phoneNumber;
[self.parameters addEntriesFromDictionary:attributes];
Expand Down
44 changes: 44 additions & 0 deletions tests/Account/TSAttributesTest.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// TSAttributesTest.m
// Signal
//
// Created by Michael Kirk on 6/27/16.
// Copyright © 2016 Open Whisper Systems. All rights reserved.
//

#import <XCTest/XCTest.h>

#import "TSAttributes.h"
#import "TSAccountManager.h"

@interface TSAttributesTest : XCTestCase

@end

@implementation TSAttributesTest

- (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)testAttributesWithSignalingKey {

NSString *registrationId = [NSString stringWithFormat:@"%i", [TSAccountManager getOrGenerateRegistrationId]];
NSDictionary *expected = @{ @"AuthKey": @"fake-server-auth-token",
@"registrationId": registrationId,
@"signalingKey": @"fake-signaling-key",
@"voice": @1 };

NSDictionary *actual = [TSAttributes attributesWithSignalingKey:@"fake-signaling-key"
serverAuthToken:@"fake-server-auth-token"];

XCTAssertEqualObjects(expected, actual);
}

@end

0 comments on commit 9ab38ef

Please sign in to comment.