Skip to content

Commit

Permalink
update pods after RI
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkirk committed Sep 15, 2018
1 parent 7195f2e commit e9fb539
Show file tree
Hide file tree
Showing 37 changed files with 6,707 additions and 6,176 deletions.
Expand Up @@ -58,10 +58,8 @@ - (instancetype)initWithWhisperMessage:(WhisperMessage *)whisperMessage
NSError *error;
NSData *_Nullable messageData = [messageBuilder buildSerializedDataAndReturnError:&error];
if (!messageData || error) {
SPKFail(@"%@ Could not serialize proto: %@.", self.logTag, error);
@throw [NSException exceptionWithName:InvalidMessageException
reason:@"could not serialize proto"
userInfo:@{}];
OWSFailDebug(@"Could not serialize proto: %@.", error);
OWSRaiseException(InvalidMessageException, @"Could not serialize proto.");
}
[serialized appendData:messageData];

Expand Down Expand Up @@ -90,8 +88,8 @@ - (instancetype)initWithData:(NSData *)serialized
SPKProtoTSProtoPreKeyWhisperMessage *_Nullable preKeyWhisperMessage =
[SPKProtoTSProtoPreKeyWhisperMessage parseData:messageData error:&error];
if (!preKeyWhisperMessage || error) {
SPKFail(@"%@ Could not parse proto: %@.", self.logTag, error);
@throw [NSException exceptionWithName:InvalidMessageException reason:@"Could not parse proto" userInfo:@{}];
OWSFailDebug(@"Could not parse proto: %@.", error);
OWSRaiseException(InvalidMessageException, @"Could not parse proto.");
}

_serialized = serialized;
Expand Down
27 changes: 13 additions & 14 deletions AxolotlKit/AxolotlKit/Classes/CipherMessage/WhisperMessage.m
@@ -1,10 +1,11 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//

#import "WhisperMessage.h"
#import "AxolotlExceptions.h"
#import "Constants.h"
#import "NSData+SPK.h"
#import "NSData+keyVersionByte.h"
#import "SerializationUtilities.h"
#import <AxolotlKit/AxolotlKit-Swift.h>
Expand Down Expand Up @@ -35,10 +36,8 @@ - (instancetype)initWithVersion:(int)version
NSError *error;
NSData *_Nullable messageData = [messageBuilder buildSerializedDataAndReturnError:&error];
if (!messageData || error) {
SPKFail(@"%@ Could not serialize proto: %@.", self.logTag, error);
@throw [NSException exceptionWithName:InvalidMessageException
reason:@"could not serialize proto"
userInfo:@{}];
OWSFailDebug(@"Could not serialize proto: %@.", error);
OWSRaiseException(InvalidMessageException, @"Could not serialize proto.");
}
[serialized appendData:messageData];

Expand Down Expand Up @@ -98,8 +97,8 @@ - (instancetype)initWithData:(NSData *)serialized
SPKProtoTSProtoWhisperMessage *_Nullable whisperMessage =
[SPKProtoTSProtoWhisperMessage parseData:messageData error:&error];
if (!whisperMessage || error) {
SPKFail(@"%@ Could not parse proto: %@.", self.logTag, error);
@throw [NSException exceptionWithName:InvalidMessageException reason:@"Could not parse proto" userInfo:@{}];
OWSFailDebug(@"Could not parse proto: %@.", error);
OWSRaiseException(InvalidMessageException, @"Could not parse proto.");
}

_serialized = serialized;
Expand All @@ -122,13 +121,13 @@ - (void)verifyMacWithVersion:(int)messageVersion
NSError *error;
NSData *_Nullable data = [dataParser nextDataWithLength:self.serialized.length - MAC_LENGTH error:&error];
if (!data || error) {
SPKFail(@"%@ Could not parse data: %@", self.logTag, error);
@throw [NSException exceptionWithName:InvalidMessageException reason:@"Could not parse data." userInfo:@{}];
OWSFailDebug(@"Could not parse data: %@.", error);
OWSRaiseException(InvalidMessageException, @"Could not parse data.");
}
NSData *_Nullable theirMac = [dataParser nextDataWithLength:MAC_LENGTH error:&error];
if (!theirMac || error) {
SPKFail(@"%@ Could not parse theirMac: %@", self.logTag, error);
@throw [NSException exceptionWithName:InvalidMessageException reason:@"Could not parse theirMac." userInfo:@{}];
OWSFailDebug(@"Could not parse their mac: %@.", error);
OWSRaiseException(InvalidMessageException, @"Could not parse their mac.");
}

NSData *ourMac = [SerializationUtilities macWithVersion:messageVersion
Expand All @@ -137,9 +136,9 @@ - (void)verifyMacWithVersion:(int)messageVersion
macKey:macKey
serialized:data];

if (![theirMac isEqualToData:ourMac]) {
SPKFail(@"%@ Bad Mac! Their Mac: %@ Our Mac: %@", self.logTag, theirMac, ourMac);
@throw [NSException exceptionWithName:InvalidMessageException reason:@"Bad Mac!" userInfo:@{}];
if (![theirMac ows_constantTimeIsEqualToData:ourMac]) {
OWSFailDebug(@"Bad Mac! Their Mac: %@ Our Mac: %@", theirMac, ourMac);
OWSRaiseException(InvalidMessageException, @"Bad Mac!");
}
}

Expand Down
2 changes: 1 addition & 1 deletion AxolotlKit/AxolotlKit/Classes/Crypto/AES-CBC.m
Expand Up @@ -80,7 +80,7 @@ + (NSData *)decryptCBCMode:(NSData *)data withKey:(NSData *)key withIV:(NSData *
size_t bufferSize = [data length] + kCCBlockSizeAES128;
NSMutableData *_Nullable bufferData = [NSMutableData dataWithLength:bufferSize];
if (!bufferData) {
@throw [NSException exceptionWithName:CipherException reason:@"Couldn't allocate buffer." userInfo:nil];
OWSFail(@"Couldn't allocate buffer.");
}

size_t bytesDecrypted = 0;
Expand Down
4 changes: 2 additions & 2 deletions AxolotlKit/AxolotlKit/Classes/Ratchet/ChainKey.m
Expand Up @@ -44,7 +44,7 @@ - (void)encodeWithCoder:(NSCoder *)aCoder

- (instancetype)initWithData:(NSData *)chainKey index:(int)index
{
SPKAssert(chainKey.length == ECCKeyLength);
OWSAssert(chainKey.length == ECCKeyLength);

self = [super init];

Expand Down Expand Up @@ -90,7 +90,7 @@ - (NSData *)baseMaterial:(NSData *)seed

NSMutableData *_Nullable bufferData = [NSMutableData dataWithLength:CC_SHA256_DIGEST_LENGTH];
if (!bufferData) {
@throw [NSException exceptionWithName:NSGenericException reason:@"Couldn't allocate buffer." userInfo:nil];
OWSFail(@"Couldn't allocate buffer.");
}

CCHmacContext ctx;
Expand Down
4 changes: 2 additions & 2 deletions AxolotlKit/AxolotlKit/Classes/Ratchet/RootKey.m
Expand Up @@ -33,7 +33,7 @@ - (id)initWithCoder:(NSCoder *)aDecoder{
- (instancetype)initWithData:(NSData *)data{
self = [super init];

SPKAssert(data.length == ECCKeyLength);
OWSAssert(data.length == ECCKeyLength);

if (self) {
_keyData = data;
Expand All @@ -44,7 +44,7 @@ - (instancetype)initWithData:(NSData *)data{

- (RKCK*)createChainWithTheirEphemeral:(NSData*)theirEphemeral ourEphemeral:(ECKeyPair*)ourEphemeral{
NSData *sharedSecret = [Curve25519 generateSharedSecretFromPublicKey:theirEphemeral andKeyPair:ourEphemeral];
SPKAssert(sharedSecret.length == ECCKeyLength);
OWSAssert(sharedSecret.length == ECCKeyLength);

TSDerivedSecrets *secrets = [TSDerivedSecrets derivedRatchetedSecretsWithSharedSecret:sharedSecret rootKey:_keyData];

Expand Down
4 changes: 2 additions & 2 deletions AxolotlKit/AxolotlKit/Classes/Ratchet/SendingChain.m
Expand Up @@ -35,8 +35,8 @@ - (void)encodeWithCoder:(NSCoder *)aCoder{
- (instancetype)initWithChainKey:(ChainKey *)chainKey senderRatchetKeyPair:(ECKeyPair *)keyPair{
self = [super init];

SPKAssert(chainKey.key.length == ECCKeyLength);
SPKAssert(keyPair);
OWSAssert(chainKey.key.length == ECCKeyLength);
OWSAssert(keyPair);

if (self) {
_chainKey = chainKey;
Expand Down
6 changes: 3 additions & 3 deletions AxolotlKit/AxolotlKit/Classes/Ratchet/TSDerivedSecrets.m
Expand Up @@ -11,7 +11,7 @@ @implementation TSDerivedSecrets
+ (instancetype)derivedSecretsWithSeed:(NSData*)masterKey salt:(NSData*)salt info:(NSData*)info{
TSDerivedSecrets *secrets = [[TSDerivedSecrets alloc] init];

SPKAssert(masterKey.length == ECCKeyLength);
OWSAssert(masterKey.length == ECCKeyLength);

if (!salt) {
const char *HKDFDefaultSalt[4] = {0};
Expand All @@ -28,8 +28,8 @@ + (instancetype)derivedSecretsWithSeed:(NSData*)masterKey salt:(NSData*)salt inf
@throw NSInvalidArgumentException;
}

SPKAssert(secrets.cipherKey.length == ECCKeyLength);
SPKAssert(secrets.macKey.length == ECCKeyLength);
OWSAssert(secrets.cipherKey.length == ECCKeyLength);
OWSAssert(secrets.macKey.length == ECCKeyLength);

return secrets;
}
Expand Down
76 changes: 0 additions & 76 deletions AxolotlKit/AxolotlKit/Classes/SPKAsserts.h

This file was deleted.

42 changes: 21 additions & 21 deletions AxolotlKit/AxolotlKit/Classes/SessionCipher.m
Expand Up @@ -73,7 +73,7 @@ - (instancetype)initWithSessionStore:(id<SessionStore>)sessionStore

- (id<CipherMessage>)encryptMessage:(NSData *)paddedMessage protocolContext:(nullable id)protocolContext
{
SPKAssert(paddedMessage);
OWSAssert(paddedMessage);

SessionRecord *sessionRecord =
[self.sessionStore loadSession:self.recipientId deviceId:self.deviceId protocolContext:protocolContext];
Expand Down Expand Up @@ -137,7 +137,7 @@ - (instancetype)initWithSessionStore:(id<SessionStore>)sessionStore

- (NSData *)decrypt:(id<CipherMessage>)whisperMessage protocolContext:(nullable id)protocolContext
{
SPKAssert(whisperMessage);
OWSAssert(whisperMessage);

if ([whisperMessage isKindOfClass:[PreKeyWhisperMessage class]]) {
return
Expand All @@ -150,7 +150,7 @@ - (NSData *)decrypt:(id<CipherMessage>)whisperMessage protocolContext:(nullable
- (NSData *)decryptPreKeyWhisperMessage:(PreKeyWhisperMessage *)preKeyWhisperMessage
protocolContext:(nullable id)protocolContext
{
SPKAssert(preKeyWhisperMessage);
OWSAssert(preKeyWhisperMessage);

SessionRecord *sessionRecord =
[self.sessionStore loadSession:self.recipientId deviceId:self.deviceId protocolContext:protocolContext];
Expand All @@ -174,7 +174,7 @@ - (NSData *)decryptPreKeyWhisperMessage:(PreKeyWhisperMessage *)preKeyWhisperMes

- (NSData *)decryptWhisperMessage:(WhisperMessage *)whisperMessage protocolContext:(nullable id)protocolContext
{
SPKAssert(whisperMessage);
OWSAssert(whisperMessage);

SessionRecord *sessionRecord =
[self.sessionStore loadSession:self.recipientId deviceId:self.deviceId protocolContext:protocolContext];
Expand Down Expand Up @@ -207,8 +207,8 @@ - (NSData *)decryptWithSessionRecord:(SessionRecord *)sessionRecord
whisperMessage:(WhisperMessage *)whisperMessage
protocolContext:(nullable id)protocolContext
{
SPKAssert(sessionRecord);
SPKAssert(whisperMessage);
OWSAssert(sessionRecord);
OWSAssert(whisperMessage);

SessionState *sessionState = [sessionRecord sessionState];
NSMutableArray *exceptions = [NSMutableArray array];
Expand Down Expand Up @@ -282,8 +282,8 @@ - (NSData *)decryptWithSessionState:(SessionState *)sessionState
whisperMessage:(WhisperMessage *)whisperMessage
protocolContext:(nullable id)protocolContext
{
SPKAssert(sessionState);
SPKAssert(whisperMessage);
OWSAssert(sessionState);
OWSAssert(whisperMessage);

if (![sessionState hasSenderChain]) {
@throw [NSException exceptionWithName:InvalidMessageException reason:@"Uninitialized session!" userInfo:nil];
Expand All @@ -301,9 +301,9 @@ - (NSData *)decryptWithSessionState:(SessionState *)sessionState
NSData *theirEphemeral = whisperMessage.senderRatchetKey.removeKeyType;
int counter = whisperMessage.counter;
ChainKey *chainKey = [self getOrCreateChainKeys:sessionState theirEphemeral:theirEphemeral];
SPKAssert(chainKey);
OWSAssert(chainKey);
MessageKeys *messageKeys = [self getOrCreateMessageKeysForSession:sessionState theirEphemeral:theirEphemeral chainKey:chainKey counter:counter];
SPKAssert(messageKeys);
OWSAssert(messageKeys);

[whisperMessage verifyMacWithVersion:messageVersion
senderIdentityKey:sessionState.remoteIdentityKey
Expand All @@ -321,9 +321,9 @@ - (NSData *)decryptWithSessionState:(SessionState *)sessionState
- (ChainKey *)getOrCreateChainKeys:(SessionState *)sessionState
theirEphemeral:(NSData *)theirEphemeral
{
SPKAssert(sessionState);
SPKAssert(theirEphemeral);
SPKAssert(theirEphemeral.length == ECCKeyLength);
OWSAssert(sessionState);
OWSAssert(theirEphemeral);
OWSAssert(theirEphemeral.length == ECCKeyLength);

@try {
if ([sessionState hasReceiverChain:theirEphemeral]) {
Expand All @@ -332,22 +332,22 @@ - (ChainKey *)getOrCreateChainKeys:(SessionState *)sessionState
} else{
DDLogInfo(@"%@ %@.%d creating new chains.", self.tag, self.recipientId, self.deviceId);
RootKey *rootKey = [sessionState rootKey];
SPKAssert(rootKey.keyData.length == ECCKeyLength);
OWSAssert(rootKey.keyData.length == ECCKeyLength);

ECKeyPair *ourEphemeral = [sessionState senderRatchetKeyPair];
SPKAssert(ourEphemeral.publicKey.length == ECCKeyLength);
OWSAssert(ourEphemeral.publicKey.length == ECCKeyLength);

RKCK *receiverChain = [rootKey createChainWithTheirEphemeral:theirEphemeral ourEphemeral:ourEphemeral];

ECKeyPair *ourNewEphemeral = [Curve25519 generateKeyPair];
SPKAssert(ourNewEphemeral.publicKey.length == ECCKeyLength);
OWSAssert(ourNewEphemeral.publicKey.length == ECCKeyLength);

RKCK *senderChain = [receiverChain.rootKey createChainWithTheirEphemeral:theirEphemeral ourEphemeral:ourNewEphemeral];

SPKAssert(senderChain.rootKey.keyData.length == ECCKeyLength);
OWSAssert(senderChain.rootKey.keyData.length == ECCKeyLength);
[sessionState setRootKey:senderChain.rootKey];

SPKAssert(receiverChain.chainKey.key.length == ECCKeyLength);
OWSAssert(receiverChain.chainKey.key.length == ECCKeyLength);
[sessionState addReceiverChain:theirEphemeral chainKey:receiverChain.chainKey];
[sessionState setPreviousCounter:MAX(sessionState.senderChainKey.index-1 , 0)];
[sessionState setSenderChain:ourNewEphemeral chainKey:senderChain.chainKey];
Expand All @@ -365,9 +365,9 @@ - (MessageKeys *)getOrCreateMessageKeysForSession:(SessionState *)sessionState
chainKey:(ChainKey *)chainKey
counter:(int)counter
{
SPKAssert(sessionState);
SPKAssert(theirEphemeral);
SPKAssert(chainKey);
OWSAssert(sessionState);
OWSAssert(theirEphemeral);
OWSAssert(chainKey);

if (chainKey.index > counter) {
if ([sessionState hasMessageKeys:theirEphemeral counter:counter]) {
Expand Down
6 changes: 3 additions & 3 deletions AxolotlKit/AxolotlKit/Classes/Sessions/SessionBuilder.m
Expand Up @@ -69,7 +69,7 @@ - (instancetype)initWithSessionStore:(id<SessionStore>)sessionStore

- (void)processPrekeyBundle:(PreKeyBundle *)preKeyBundle protocolContext:(nullable id)protocolContext
{
SPKAssert(preKeyBundle);
OWSAssert(preKeyBundle);

NSData *theirIdentityKey = preKeyBundle.identityKey.removeKeyType;
NSData *theirSignedPreKey = preKeyBundle.signedPreKeyPublic.removeKeyType;
Expand Down Expand Up @@ -135,8 +135,8 @@ - (int)processPrekeyWhisperMessage:(PreKeyWhisperMessage *)message
withSession:(SessionRecord *)sessionRecord
protocolContext:(nullable id)protocolContext
{
SPKAssert(message);
SPKAssert(sessionRecord);
OWSAssert(message);
OWSAssert(sessionRecord);

int messageVersion = message.version;
NSData *theirIdentityKey = message.identityKey.removeKeyType;
Expand Down
2 changes: 1 addition & 1 deletion AxolotlKit/AxolotlKit/Classes/Sessions/SessionState.m
Expand Up @@ -161,7 +161,7 @@ - (ChainKey *)receiverChainKey:(NSData *)senderEphemeral
if (receiverChain == nil) {
return nil;
} else{
SPKAssert(receiverChain.chainKey.key);
OWSAssert(receiverChain.chainKey.key);
return [[ChainKey alloc] initWithData:receiverChain.chainKey.key index:receiverChain.chainKey.index];
}
}
Expand Down

0 comments on commit e9fb539

Please sign in to comment.