From b663a09c87b66d4db5eb515a0fcd961d1c61a6d7 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Mon, 25 Sep 2017 21:51:15 -0400 Subject: [PATCH 1/4] helpful tools for building ios11 // FREEBIE --- Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d23dfdd1eb..4064ddf4fa 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ SHELL=/bin/bash -o pipefail -o errexit WORKING_DIR = ./ SCHEME = Signal +XCODE_BUILD = xcrun xcodebuild -workspace $(SCHEME).xcworkspace -scheme $(SCHEME) -sdk iphonesimulator .PHONY: build test retest clean dependencies @@ -32,6 +33,8 @@ test: clean: cd $(WORKING_DIR) && \ rm -fr Carthage/Build && \ - $(XCODE_BUILD) \ - clean | xcpretty + $(XCODE_BUILD) clean | xcpretty +# Migrating across swift versions requires me to run this sometimes +clean_carthage_cache: + rm -fr ~/Library/Caches/org.carthage.CarthageKit/ From f8182cd3c2aca1ec113ab5bc7f5242e7f4727e01 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Mon, 25 Sep 2017 12:30:03 -0400 Subject: [PATCH 2/4] fix desktop linking for some users // FREEBIE --- .../src/Devices/OWSProvisioningCipher.m | 9 ++++---- .../src/Devices/OWSProvisioningMessage.m | 2 +- .../tests/Devices/OWSDeviceProvisionerTest.m | 6 +++++- .../tests/Devices/OWSProvisioningCipherTest.m | 21 +++++++++++++++++++ 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/SignalServiceKit/src/Devices/OWSProvisioningCipher.m b/SignalServiceKit/src/Devices/OWSProvisioningCipher.m index 1f2c2b77e0..9e23e09031 100644 --- a/SignalServiceKit/src/Devices/OWSProvisioningCipher.m +++ b/SignalServiceKit/src/Devices/OWSProvisioningCipher.m @@ -86,9 +86,8 @@ NS_ASSUME_NONNULL_BEGIN return nil; } - // allow space for message + padding any incomplete block - NSUInteger blockCount = ceil((double)dataToEncrypt.length / (double)kCCBlockSizeAES128); - size_t ciphertextBufferSize = blockCount * kCCBlockSizeAES128; + // allow space for message + padding any incomplete block. PKCS7 padding will always add at least one byte. + size_t ciphertextBufferSize = dataToEncrypt.length + kCCBlockSizeAES128; // message format is (iv || ciphertext) NSMutableData *encryptedMessage = [NSMutableData dataWithLength:iv.length + ciphertextBufferSize]; @@ -117,8 +116,8 @@ NS_ASSUME_NONNULL_BEGIN DDLogError(@"Encryption failed with status: %d", cryptStatus); return nil; } - - return [encryptedMessage copy]; + + return [encryptedMessage subdataWithRange:NSMakeRange(0, iv.length + bytesEncrypted)]; } - (NSData *)macForMessage:(NSData *)message withKey:(NSData *)macKey diff --git a/SignalServiceKit/src/Devices/OWSProvisioningMessage.m b/SignalServiceKit/src/Devices/OWSProvisioningMessage.m index 68022a7c12..abb02aeb4c 100644 --- a/SignalServiceKit/src/Devices/OWSProvisioningMessage.m +++ b/SignalServiceKit/src/Devices/OWSProvisioningMessage.m @@ -61,7 +61,7 @@ NS_ASSUME_NONNULL_BEGIN OWSProvisioningCipher *cipher = [[OWSProvisioningCipher alloc] initWithTheirPublicKey:self.theirPublicKey]; NSData *_Nullable encryptedProvisionMessage = [cipher encrypt:plainTextProvisionMessage]; if (encryptedProvisionMessage == nil) { - DDLogError(@"Failed to encrypt provision message"); + OWSFail(@"Failed to encrypt provision message"); return nil; } diff --git a/SignalServiceKit/tests/Devices/OWSDeviceProvisionerTest.m b/SignalServiceKit/tests/Devices/OWSDeviceProvisionerTest.m index 9d8c1d69ee..d74fb005bf 100644 --- a/SignalServiceKit/tests/Devices/OWSDeviceProvisionerTest.m +++ b/SignalServiceKit/tests/Devices/OWSDeviceProvisionerTest.m @@ -1,4 +1,6 @@ -// Copyright © 2016 Open Whisper Systems. All rights reserved. +// +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// #import "OWSDeviceProvisioner.h" #import "OWSDeviceProvisioningCodeService.h" @@ -62,6 +64,7 @@ NSData *myPublicKey = [nullKey copy]; NSData *myPrivateKey = [nullKey copy]; NSData *theirPublicKey = [nullKey copy]; + NSData *profileKey = [nullKey copy]; NSString *accountIdentifier; NSString *theirEphemeralDeviceId; @@ -72,6 +75,7 @@ theirPublicKey:theirPublicKey theirEphemeralDeviceId:theirEphemeralDeviceId accountIdentifier:accountIdentifier + profileKey:profileKey provisioningCodeService:[[OWSFakeDeviceProvisioningCodeService alloc] initWithNetworkManager:networkManager] provisioningService:[[OWSFakeDeviceProvisioningService alloc] initWithNetworkManager:networkManager]]; diff --git a/SignalServiceKit/tests/Devices/OWSProvisioningCipherTest.m b/SignalServiceKit/tests/Devices/OWSProvisioningCipherTest.m index edde5864cf..df7936386d 100644 --- a/SignalServiceKit/tests/Devices/OWSProvisioningCipherTest.m +++ b/SignalServiceKit/tests/Devices/OWSProvisioningCipherTest.m @@ -131,4 +131,25 @@ XCTAssertEqualObjects(expectedOutput, actualOutput); } +- (void)testPadding +{ + NSUInteger kBlockSize = 16; + for (int i = 0; i <= kBlockSize; i++) { + NSData *message = [Cryptography generateRandomBytes:i]; + + + NSData *theirPublicKey = [self knownPublicKey]; + ECKeyPair *ourKeyPair = [self knownKeyPair]; + NSData *initializationVector = [self knownInitializationVector]; + + OWSProvisioningCipher *cipher = [[OWSProvisioningCipher alloc] initWithTheirPublicKey:theirPublicKey + ourKeyPair:ourKeyPair + initializationVector:initializationVector]; + + + NSData *actualOutput = [cipher encrypt:message]; + XCTAssertNotNil(actualOutput, @"failed for message length: %d", i); + } +} + @end From bfaa7f2e0cb36b2734dcc99de7d893005dcc9c98 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Mon, 25 Sep 2017 21:51:41 -0400 Subject: [PATCH 3/4] On iOS11 doc picker requires system appearance. Otherwise nav items are illegible. // FREEBIE --- .../ConversationView/MessagesViewController.m | 16 +++++++++++++--- SignalServiceKit/src/Contacts/Contact.m | 1 - 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m index da3d2dce01..ad36d7c9b3 100644 --- a/Signal/src/ViewControllers/ConversationView/MessagesViewController.m +++ b/Signal/src/ViewControllers/ConversationView/MessagesViewController.m @@ -653,7 +653,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { [super viewWillAppear:animated]; - // In case we're dismissing a CNContactViewController which requires default system appearance + // In case we're dismissing a CNContactViewController, or DocumentPicker which requires default system appearance [UIUtil applySignalAppearence]; [self addVisibleListeners]; @@ -3073,7 +3073,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { #pragma mark - Attachment Picking: Documents -- (void)showAttachmentDocumentPicker +- (void)showAttachmentDocumentPickerMenu { NSString *allItems = (__bridge NSString *)kUTTypeItem; NSArray *documentTypes = @[ allItems ]; @@ -3083,6 +3083,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { UIDocumentMenuViewController *menuController = [[UIDocumentMenuViewController alloc] initWithDocumentTypes:documentTypes inMode:pickerMode]; menuController.delegate = self; + [self presentViewController:menuController animated:YES completion:nil]; } @@ -3092,6 +3093,10 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { didPickDocumentPicker:(UIDocumentPickerViewController *)documentPicker { documentPicker.delegate = self; + if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(11, 0)) { + // post iOS11, document picker has no blue header. + [UIUtil applyDefaultSystemAppearence]; + } [self presentViewController:documentPicker animated:YES completion:nil]; } @@ -3102,6 +3107,11 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { DDLogDebug(@"%@ Picked document at url: %@", self.tag, url); NSData *attachmentData = [NSData dataWithContentsOfURL:url]; + if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(11, 0)) { + // post iOS11, document picker has no blue header. + [UIUtil applySignalAppearence]; + } + NSString *type; NSError *typeError; [url getResourceValue:&type forKey:NSURLTypeIdentifierKey error:&typeError]; @@ -3914,7 +3924,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { @"action sheet button title when choosing attachment type") style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnull action) { - [self showAttachmentDocumentPicker]; + [self showAttachmentDocumentPickerMenu]; }]; UIImage *chooseDocumentImage = [UIImage imageNamed:@"actionsheet_document_black"]; OWSAssert(chooseDocumentImage); diff --git a/SignalServiceKit/src/Contacts/Contact.m b/SignalServiceKit/src/Contacts/Contact.m index 532b544c62..b784dc0528 100644 --- a/SignalServiceKit/src/Contacts/Contact.m +++ b/SignalServiceKit/src/Contacts/Contact.m @@ -80,7 +80,6 @@ NS_ASSUME_NONNULL_BEGIN } else if ([phoneNumberField.label isEqualToString:CNLabelPhoneNumberiPhone]) { phoneNumberNameMap[phoneNumber.stringValue] = NSLocalizedString(@"PHONE_NUMBER_TYPE_IPHONE", @"Label for 'IPhone' phone numbers."); - ; } else if ([phoneNumberField.label isEqualToString:CNLabelPhoneNumberMobile]) { phoneNumberNameMap[phoneNumber.stringValue] = NSLocalizedString(@"PHONE_NUMBER_TYPE_MOBILE", @"Label for 'Mobile' phone numbers."); From f4ab65b37bb3b2ac1e8780a283ce1234286fedcf Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Mon, 25 Sep 2017 21:54:21 -0400 Subject: [PATCH 4/4] bump version // FREEBIE --- Signal/Signal-Info.plist | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Signal/Signal-Info.plist b/Signal/Signal-Info.plist index 9383cfc81e..828653da7a 100644 --- a/Signal/Signal-Info.plist +++ b/Signal/Signal-Info.plist @@ -38,7 +38,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 2.16.1 + 2.16.2 CFBundleSignature ???? CFBundleURLTypes @@ -55,7 +55,7 @@ CFBundleVersion - 2.16.1.3 + 2.16.2.0 ITSAppUsesNonExemptEncryption LOGS_EMAIL