diff --git a/AxolotlKit/Classes/CipherMessage/PreKeyWhisperMessage.h b/AxolotlKit/Classes/CipherMessage/PreKeyWhisperMessage.h index d29e348..d64aaa2 100644 --- a/AxolotlKit/Classes/CipherMessage/PreKeyWhisperMessage.h +++ b/AxolotlKit/Classes/CipherMessage/PreKeyWhisperMessage.h @@ -9,15 +9,15 @@ NS_ASSUME_NONNULL_BEGIN @interface PreKeyWhisperMessage : NSObject -- (instancetype)init_try_withData:(NSData *)serialized NS_SWIFT_UNAVAILABLE("throws objc exceptions"); +- (instancetype)init_throws_withData:(NSData *)serialized NS_SWIFT_UNAVAILABLE("throws objc exceptions"); - (nullable instancetype)initWithData:(NSData *)serialized error:(NSError **)outError; -- (instancetype)init_try_withWhisperMessage:(WhisperMessage *)whisperMessage - registrationId:(int)registrationId - prekeyId:(int)prekeyId - signedPrekeyId:(int)signedPrekeyId - baseKey:(NSData *)baseKey - identityKey:(NSData *)identityKey NS_SWIFT_UNAVAILABLE("throws objc exceptions"); +- (instancetype)init_throws_withWhisperMessage:(WhisperMessage *)whisperMessage + registrationId:(int)registrationId + prekeyId:(int)prekeyId + signedPrekeyId:(int)signedPrekeyId + baseKey:(NSData *)baseKey + identityKey:(NSData *)identityKey NS_SWIFT_UNAVAILABLE("throws objc exceptions"); @property (nonatomic, readonly) int registrationId; @property (nonatomic, readonly) int version; diff --git a/AxolotlKit/Classes/CipherMessage/PreKeyWhisperMessage.m b/AxolotlKit/Classes/CipherMessage/PreKeyWhisperMessage.m index df72fcf..6794dee 100644 --- a/AxolotlKit/Classes/CipherMessage/PreKeyWhisperMessage.m +++ b/AxolotlKit/Classes/CipherMessage/PreKeyWhisperMessage.m @@ -23,12 +23,12 @@ NS_ASSUME_NONNULL_BEGIN @implementation PreKeyWhisperMessage -- (instancetype)init_try_withWhisperMessage:(WhisperMessage *)whisperMessage - registrationId:(int)registrationId - prekeyId:(int)prekeyId - signedPrekeyId:(int)signedPrekeyId - baseKey:(NSData *)baseKey - identityKey:(NSData *)identityKey +- (instancetype)init_throws_withWhisperMessage:(WhisperMessage *)whisperMessage + registrationId:(int)registrationId + prekeyId:(int)prekeyId + signedPrekeyId:(int)signedPrekeyId + baseKey:(NSData *)baseKey + identityKey:(NSData *)identityKey { OWSAssert(whisperMessage); OWSAssert(baseKey); @@ -73,7 +73,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable instancetype)initWithData:(NSData *)serialized error:(NSError **)outError { @try { - self = [self init_try_withData:serialized]; + self = [self init_throws_withData:serialized]; return self; } @catch (NSException *exception) { *outError = SCKExceptionWrapperErrorMake(exception); @@ -81,7 +81,7 @@ NS_ASSUME_NONNULL_BEGIN } } -- (instancetype)init_try_withData:(NSData *)serialized +- (instancetype)init_throws_withData:(NSData *)serialized { if (self = [super init]) { if (serialized.length < 1) { @@ -121,7 +121,7 @@ NS_ASSUME_NONNULL_BEGIN _signedPrekeyId = preKeyWhisperMessage.signedPreKeyID; _baseKey = preKeyWhisperMessage.baseKey; _identityKey = preKeyWhisperMessage.identityKey; - _message = [[WhisperMessage alloc] init_try_withData:preKeyWhisperMessage.message]; + _message = [[WhisperMessage alloc] init_throws_withData:preKeyWhisperMessage.message]; } return self; diff --git a/AxolotlKit/Classes/CipherMessage/WhisperMessage.h b/AxolotlKit/Classes/CipherMessage/WhisperMessage.h index c9d6c32..7ab3544 100644 --- a/AxolotlKit/Classes/CipherMessage/WhisperMessage.h +++ b/AxolotlKit/Classes/CipherMessage/WhisperMessage.h @@ -18,22 +18,22 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) NSData *cipherText; @property (nonatomic, readonly) NSData *serialized; -- (instancetype)init_try_withData:(NSData *)serialized NS_SWIFT_UNAVAILABLE("throws objc exceptions"); +- (instancetype)init_throws_withData:(NSData *)serialized NS_SWIFT_UNAVAILABLE("throws objc exceptions"); - (nullable instancetype)initWithData:(NSData *)serialized error:(NSError **)outError; -- (instancetype)init_try_withVersion:(int)version - macKey:(NSData *)macKey - senderRatchetKey:(NSData *)senderRatchetKey - counter:(int)counter - previousCounter:(int)previousCounter - cipherText:(NSData *)cipherText - senderIdentityKey:(NSData *)senderIdentityKey - receiverIdentityKey:(NSData *)receiverIdentityKey NS_SWIFT_UNAVAILABLE("throws objc exceptions"); +- (instancetype)init_throws_withVersion:(int)version + macKey:(NSData *)macKey + senderRatchetKey:(NSData *)senderRatchetKey + counter:(int)counter + previousCounter:(int)previousCounter + cipherText:(NSData *)cipherText + senderIdentityKey:(NSData *)senderIdentityKey + receiverIdentityKey:(NSData *)receiverIdentityKey NS_SWIFT_UNAVAILABLE("throws objc exceptions"); -- (void)try_verifyMacWithVersion:(int)messageVersion - senderIdentityKey:(NSData *)senderIdentityKey - receiverIdentityKey:(NSData *)receiverIdentityKey - macKey:(NSData *)macKey NS_SWIFT_UNAVAILABLE("throws objc exceptions"); +- (void)throws_verifyMacWithVersion:(int)messageVersion + senderIdentityKey:(NSData *)senderIdentityKey + receiverIdentityKey:(NSData *)receiverIdentityKey + macKey:(NSData *)macKey NS_SWIFT_UNAVAILABLE("throws objc exceptions"); @end diff --git a/AxolotlKit/Classes/CipherMessage/WhisperMessage.m b/AxolotlKit/Classes/CipherMessage/WhisperMessage.m index 0cfb220..dea25d1 100644 --- a/AxolotlKit/Classes/CipherMessage/WhisperMessage.m +++ b/AxolotlKit/Classes/CipherMessage/WhisperMessage.m @@ -18,14 +18,14 @@ NS_ASSUME_NONNULL_BEGIN @implementation WhisperMessage -- (instancetype)init_try_withVersion:(int)version - macKey:(NSData *)macKey - senderRatchetKey:(NSData *)senderRatchetKey - counter:(int)counter - previousCounter:(int)previousCounter - cipherText:(NSData *)cipherText - senderIdentityKey:(NSData *)senderIdentityKey - receiverIdentityKey:(NSData *)receiverIdentityKey +- (instancetype)init_throws_withVersion:(int)version + macKey:(NSData *)macKey + senderRatchetKey:(NSData *)senderRatchetKey + counter:(int)counter + previousCounter:(int)previousCounter + cipherText:(NSData *)cipherText + senderIdentityKey:(NSData *)senderIdentityKey + receiverIdentityKey:(NSData *)receiverIdentityKey { OWSAssert(macKey); OWSAssert(senderRatchetKey); @@ -50,11 +50,11 @@ NS_ASSUME_NONNULL_BEGIN } [serialized appendData:messageData]; - NSData *mac = [SerializationUtilities try_macWithVersion:version - identityKey:[senderIdentityKey prependKeyType] - receiverIdentityKey:[receiverIdentityKey prependKeyType] - macKey:macKey - serialized:serialized]; + NSData *mac = [SerializationUtilities throws_macWithVersion:version + identityKey:[senderIdentityKey prependKeyType] + receiverIdentityKey:[receiverIdentityKey prependKeyType] + macKey:macKey + serialized:serialized]; [serialized appendData:mac]; @@ -72,7 +72,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable instancetype)initWithData:(NSData *)serialized error:(NSError **)outError { @try { - self = [self init_try_withData:serialized]; + self = [self init_throws_withData:serialized]; return self; } @catch (NSException *exception) { *outError = SCKExceptionWrapperErrorMake(exception); @@ -80,7 +80,7 @@ NS_ASSUME_NONNULL_BEGIN } } -- (instancetype)init_try_withData:(NSData *)serialized +- (instancetype)init_throws_withData:(NSData *)serialized { if (self = [super init]) { if (serialized.length <= (VERSION_LENGTH + MAC_LENGTH)) { @@ -125,7 +125,7 @@ NS_ASSUME_NONNULL_BEGIN } _serialized = serialized; - _senderRatchetKey = [whisperMessage.ratchetKey try_removeKeyType]; + _senderRatchetKey = [whisperMessage.ratchetKey throws_removeKeyType]; _version = [SerializationUtilities highBitsToIntFromByte:version]; _counter = whisperMessage.counter; _previousCounter = whisperMessage.previousCounter; @@ -135,10 +135,10 @@ NS_ASSUME_NONNULL_BEGIN return self; } -- (void)try_verifyMacWithVersion:(int)messageVersion - senderIdentityKey:(NSData *)senderIdentityKey - receiverIdentityKey:(NSData *)receiverIdentityKey - macKey:(NSData *)macKey +- (void)throws_verifyMacWithVersion:(int)messageVersion + senderIdentityKey:(NSData *)senderIdentityKey + receiverIdentityKey:(NSData *)receiverIdentityKey + macKey:(NSData *)macKey { OWSAssert(senderIdentityKey); OWSAssert(receiverIdentityKey); @@ -167,11 +167,11 @@ NS_ASSUME_NONNULL_BEGIN OWSRaiseException(InvalidMessageException, @"Could not parse their mac."); } - NSData *ourMac = [SerializationUtilities try_macWithVersion:messageVersion - identityKey:[senderIdentityKey prependKeyType] - receiverIdentityKey:[receiverIdentityKey prependKeyType] - macKey:macKey - serialized:data]; + NSData *ourMac = [SerializationUtilities throws_macWithVersion:messageVersion + identityKey:[senderIdentityKey prependKeyType] + receiverIdentityKey:[receiverIdentityKey prependKeyType] + macKey:macKey + serialized:data]; if (![theirMac ows_constantTimeIsEqualToData:ourMac]) { OWSFailDebug(@"Bad Mac! Their Mac: %@ Our Mac: %@", theirMac, ourMac); diff --git a/AxolotlKit/Classes/Crypto/AES-CBC.h b/AxolotlKit/Classes/Crypto/AES-CBC.h index 3741475..7862f09 100644 --- a/AxolotlKit/Classes/Crypto/AES-CBC.h +++ b/AxolotlKit/Classes/Crypto/AES-CBC.h @@ -18,9 +18,9 @@ NS_ASSUME_NONNULL_BEGIN * @return ciphertext */ -+ (NSData *)try_encryptCBCMode:(NSData *)data - withKey:(NSData *)key - withIV:(NSData *)iv NS_SWIFT_UNAVAILABLE("throws objc exceptions"); ++ (NSData *)throws_encryptCBCMode:(NSData *)data + withKey:(NSData *)key + withIV:(NSData *)iv NS_SWIFT_UNAVAILABLE("throws objc exceptions"); /** * Decrypts with AES in CBC mode @@ -32,9 +32,9 @@ NS_ASSUME_NONNULL_BEGIN * @return plaintext */ -+ (NSData *)try_decryptCBCMode:(NSData *)data - withKey:(NSData *)key - withIV:(NSData *)iv NS_SWIFT_UNAVAILABLE("throws objc exceptions"); ++ (NSData *)throws_decryptCBCMode:(NSData *)data + withKey:(NSData *)key + withIV:(NSData *)iv NS_SWIFT_UNAVAILABLE("throws objc exceptions"); @end diff --git a/AxolotlKit/Classes/Crypto/AES-CBC.m b/AxolotlKit/Classes/Crypto/AES-CBC.m index 92a1d42..14215ac 100644 --- a/AxolotlKit/Classes/Crypto/AES-CBC.m +++ b/AxolotlKit/Classes/Crypto/AES-CBC.m @@ -15,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark AESCBC Mode -+ (NSData *)try_encryptCBCMode:(NSData *)data withKey:(NSData *)key withIV:(NSData *)iv ++ (NSData *)throws_encryptCBCMode:(NSData *)data withKey:(NSData *)key withIV:(NSData *)iv { if (!data) { @throw [NSException exceptionWithName:CipherException reason:@"Missing data to encrypt." userInfo:nil]; @@ -57,7 +57,7 @@ NS_ASSUME_NONNULL_BEGIN } } -+ (NSData *)try_decryptCBCMode:(NSData *)data withKey:(NSData *)key withIV:(NSData *)iv ++ (NSData *)throws_decryptCBCMode:(NSData *)data withKey:(NSData *)key withIV:(NSData *)iv { if (!data) { @throw [NSException exceptionWithName:CipherException reason:@"Missing data to decrypt." userInfo:nil]; diff --git a/AxolotlKit/Classes/Ratchet/ChainKey.h b/AxolotlKit/Classes/Ratchet/ChainKey.h index 1b09d1d..aad87af 100644 --- a/AxolotlKit/Classes/Ratchet/ChainKey.h +++ b/AxolotlKit/Classes/Ratchet/ChainKey.h @@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)nextChainKey; -- (MessageKeys *)try_messageKeys NS_SWIFT_UNAVAILABLE("throws objc exceptions"); +- (MessageKeys *)throws_messageKeys NS_SWIFT_UNAVAILABLE("throws objc exceptions"); @end diff --git a/AxolotlKit/Classes/Ratchet/ChainKey.m b/AxolotlKit/Classes/Ratchet/ChainKey.m index 406b0f6..3d7f422 100644 --- a/AxolotlKit/Classes/Ratchet/ChainKey.m +++ b/AxolotlKit/Classes/Ratchet/ChainKey.m @@ -63,10 +63,10 @@ static uint8_t kChainKeySeed[kTSKeySeedLength] = { 02 }; return [[ChainKey alloc] initWithData:nextCK index:nextIndex]; } -- (MessageKeys *)try_messageKeys +- (MessageKeys *)throws_messageKeys { NSData *inputKeyMaterial = [self baseMaterial:[NSData dataWithBytes:kMessageKeySeed length:kTSKeySeedLength]]; - TSDerivedSecrets *derivedSecrets = [TSDerivedSecrets try_derivedMessageKeysWithData:inputKeyMaterial]; + TSDerivedSecrets *derivedSecrets = [TSDerivedSecrets throws_derivedMessageKeysWithData:inputKeyMaterial]; return [[MessageKeys alloc] initWithCipherKey:derivedSecrets.cipherKey macKey:derivedSecrets.macKey iv:derivedSecrets.iv diff --git a/AxolotlKit/Classes/Ratchet/RKCK.h b/AxolotlKit/Classes/Ratchet/RKCK.h index 7f6f722..8957171 100644 --- a/AxolotlKit/Classes/Ratchet/RKCK.h +++ b/AxolotlKit/Classes/Ratchet/RKCK.h @@ -1,15 +1,12 @@ // -// RKCK.h -// AxolotlKit -// -// Created by Frederic Jacobs on 1/15/14. -// Copyright (c) 2014 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // -#import -#import "SessionState.h" #import "Chain.h" #import "RootKey.h" +#import "SessionState.h" +#import + @class ECKeyPair; @interface RKCK : NSObject @@ -19,4 +16,4 @@ -(instancetype) initWithRK:(RootKey*)rootKey CK:(ChainKey*)chainKey; -@end \ No newline at end of file +@end diff --git a/AxolotlKit/Classes/Ratchet/RatchetingSession.h b/AxolotlKit/Classes/Ratchet/RatchetingSession.h index 958a940..d141123 100644 --- a/AxolotlKit/Classes/Ratchet/RatchetingSession.h +++ b/AxolotlKit/Classes/Ratchet/RatchetingSession.h @@ -11,18 +11,18 @@ @interface RatchetingSession : NSObject -+ (void)try_initializeSession:(SessionState *)session - sessionVersion:(int)sessionVersion - AliceParameters:(AliceAxolotlParameters *)parameters NS_SWIFT_UNAVAILABLE("throws objc exceptions"); ++ (void)throws_initializeSession:(SessionState *)session + sessionVersion:(int)sessionVersion + AliceParameters:(AliceAxolotlParameters *)parameters NS_SWIFT_UNAVAILABLE("throws objc exceptions"); + (BOOL)initializeSession:(SessionState *)session sessionVersion:(int)sessionVersion aliceParameters:(AliceAxolotlParameters *)aliceParameters error:(NSError **)outError; -+ (void)try_initializeSession:(SessionState *)session - sessionVersion:(int)sessionVersion - BobParameters:(BobAxolotlParameters *)parameters NS_SWIFT_UNAVAILABLE("throws objc exceptions"); ++ (void)throws_initializeSession:(SessionState *)session + sessionVersion:(int)sessionVersion + BobParameters:(BobAxolotlParameters *)parameters NS_SWIFT_UNAVAILABLE("throws objc exceptions"); + (BOOL)initializeSession:(SessionState *)session sessionVersion:(int)sessionVersion @@ -33,9 +33,9 @@ * For testing purposes */ -+ (void)try_initializeSession:(SessionState *)session - sessionVersion:(int)sessionVersion - AliceParameters:(AliceAxolotlParameters *)parameters - senderRatchet:(ECKeyPair *)ratchet NS_SWIFT_UNAVAILABLE("throws objc exceptions"); ++ (void)throws_initializeSession:(SessionState *)session + sessionVersion:(int)sessionVersion + AliceParameters:(AliceAxolotlParameters *)parameters + senderRatchet:(ECKeyPair *)ratchet NS_SWIFT_UNAVAILABLE("throws objc exceptions"); @end diff --git a/AxolotlKit/Classes/Ratchet/RatchetingSession.m b/AxolotlKit/Classes/Ratchet/RatchetingSession.m index dc8de4d..11e909d 100644 --- a/AxolotlKit/Classes/Ratchet/RatchetingSession.m +++ b/AxolotlKit/Classes/Ratchet/RatchetingSession.m @@ -17,13 +17,13 @@ @property (nonatomic, readonly) RootKey *rootKey; @property (nonatomic, readonly) NSData *chainKey; -- (instancetype)init_try_withMasterKey:(NSData *)data NS_SWIFT_UNAVAILABLE("throws objc exceptions"); +- (instancetype)init_throws_withMasterKey:(NSData *)data NS_SWIFT_UNAVAILABLE("throws objc exceptions"); @end @implementation DHEResult -- (instancetype)init_try_withMasterKey:(NSData *)data +- (instancetype)init_throws_withMasterKey:(NSData *)data { // DHE Result is expected to be the result of 3 or 4 DHEs outputting 32 bytes each, // plus the 32 discontinuity bytes added to make V3 incompatible with V2 @@ -33,7 +33,7 @@ const char *HKDFDefaultSalt[4] = {0}; NSData *salt = [NSData dataWithBytes:HKDFDefaultSalt length:sizeof(HKDFDefaultSalt)]; NSData *info = [@"WhisperText" dataUsingEncoding:NSUTF8StringEncoding]; - NSData *derivedMaterial = [HKDFKit try_deriveKey:data info:info salt:salt outputSize:64]; + NSData *derivedMaterial = [HKDFKit throws_deriveKey:data info:info salt:salt outputSize:64]; OWSAssert(derivedMaterial.length == 64); _rootKey = [[RootKey alloc] initWithData:[derivedMaterial subdataWithRange:NSMakeRange(0, 32)]]; _chainKey = [derivedMaterial subdataWithRange:NSMakeRange(32, 32)]; @@ -46,19 +46,19 @@ @implementation RatchetingSession -+ (void)try_initializeSession:(SessionState *)session - sessionVersion:(int)sessionVersion - AliceParameters:(AliceAxolotlParameters *)parameters ++ (void)throws_initializeSession:(SessionState *)session + sessionVersion:(int)sessionVersion + AliceParameters:(AliceAxolotlParameters *)parameters { OWSAssert(session); OWSAssert(parameters); ECKeyPair *sendingRatchetKey = [Curve25519 generateKeyPair]; OWSAssert(sendingRatchetKey); - [self try_initializeSession:session - sessionVersion:sessionVersion - AliceParameters:parameters - senderRatchet:sendingRatchetKey]; + [self throws_initializeSession:session + sessionVersion:sessionVersion + AliceParameters:parameters + senderRatchet:sendingRatchetKey]; } + (BOOL)initializeSession:(SessionState *)session @@ -68,14 +68,14 @@ { return [SCKExceptionWrapper tryBlock:^{ - [self try_initializeSession:session sessionVersion:sessionVersion BobParameters:bobParameters]; + [self throws_initializeSession:session sessionVersion:sessionVersion BobParameters:bobParameters]; } error:outError]; } -+ (void)try_initializeSession:(SessionState *)session - sessionVersion:(int)sessionVersion - BobParameters:(BobAxolotlParameters *)parameters ++ (void)throws_initializeSession:(SessionState *)session + sessionVersion:(int)sessionVersion + BobParameters:(BobAxolotlParameters *)parameters { OWSAssert(session); OWSAssert(parameters); @@ -84,7 +84,7 @@ [session setRemoteIdentityKey:parameters.theirIdentityKey]; [session setLocalIdentityKey:parameters.ourIdentityKeyPair.publicKey]; - DHEResult *result = [self try_DHEKeyAgreement:parameters]; + DHEResult *result = [self throws_DHEKeyAgreement:parameters]; OWSAssert(result); [session setSenderChain:parameters.ourRatchetKey chainKey:[[ChainKey alloc]initWithData:result.chainKey index:0]]; @@ -98,15 +98,15 @@ { return [SCKExceptionWrapper tryBlock:^{ - [self try_initializeSession:session sessionVersion:sessionVersion AliceParameters:aliceParameters]; + [self throws_initializeSession:session sessionVersion:sessionVersion AliceParameters:aliceParameters]; } error:outError]; } -+ (void)try_initializeSession:(SessionState *)session - sessionVersion:(int)sessionVersion - AliceParameters:(AliceAxolotlParameters *)parameters - senderRatchet:(ECKeyPair *)sendingRatchet ++ (void)throws_initializeSession:(SessionState *)session + sessionVersion:(int)sessionVersion + AliceParameters:(AliceAxolotlParameters *)parameters + senderRatchet:(ECKeyPair *)sendingRatchet { OWSAssert(session); @@ -117,10 +117,10 @@ [session setRemoteIdentityKey:parameters.theirIdentityKey]; [session setLocalIdentityKey:parameters.ourIdentityKeyPair.publicKey]; - DHEResult *result = [self try_DHEKeyAgreement:parameters]; + DHEResult *result = [self throws_DHEKeyAgreement:parameters]; OWSAssert(result); RKCK *sendingChain = - [result.rootKey try_createChainWithTheirEphemeral:parameters.theirRatchetKey ourEphemeral:sendingRatchet]; + [result.rootKey throws_createChainWithTheirEphemeral:parameters.theirRatchetKey ourEphemeral:sendingRatchet]; OWSAssert(sendingChain); [session addReceiverChain:parameters.theirRatchetKey chainKey:[[ChainKey alloc]initWithData:result.chainKey index:0]]; @@ -128,7 +128,7 @@ [session setRootKey:sendingChain.rootKey]; } -+ (DHEResult *)try_DHEKeyAgreement:(id)parameters ++ (DHEResult *)throws_DHEKeyAgreement:(id)parameters { OWSAssert(parameters); @@ -139,32 +139,32 @@ if ([parameters isKindOfClass:[AliceAxolotlParameters class]]) { AliceAxolotlParameters *params = (AliceAxolotlParameters*)parameters; - [masterKey appendData:[Curve25519 try_generateSharedSecretFromPublicKey:params.theirSignedPreKey - andKeyPair:params.ourIdentityKeyPair]]; - [masterKey appendData:[Curve25519 try_generateSharedSecretFromPublicKey:params.theirIdentityKey - andKeyPair:params.ourBaseKey]]; - [masterKey appendData:[Curve25519 try_generateSharedSecretFromPublicKey:params.theirSignedPreKey - andKeyPair:params.ourBaseKey]]; + [masterKey appendData:[Curve25519 throws_generateSharedSecretFromPublicKey:params.theirSignedPreKey + andKeyPair:params.ourIdentityKeyPair]]; + [masterKey appendData:[Curve25519 throws_generateSharedSecretFromPublicKey:params.theirIdentityKey + andKeyPair:params.ourBaseKey]]; + [masterKey appendData:[Curve25519 throws_generateSharedSecretFromPublicKey:params.theirSignedPreKey + andKeyPair:params.ourBaseKey]]; if (params.theirOneTimePrekey) { - [masterKey appendData:[Curve25519 try_generateSharedSecretFromPublicKey:params.theirOneTimePrekey - andKeyPair:params.ourBaseKey]]; + [masterKey appendData:[Curve25519 throws_generateSharedSecretFromPublicKey:params.theirOneTimePrekey + andKeyPair:params.ourBaseKey]]; } } else if ([parameters isKindOfClass:[BobAxolotlParameters class]]){ BobAxolotlParameters *params = (BobAxolotlParameters*)parameters; - [masterKey appendData:[Curve25519 try_generateSharedSecretFromPublicKey:params.theirIdentityKey - andKeyPair:params.ourSignedPrekey]]; - [masterKey appendData:[Curve25519 try_generateSharedSecretFromPublicKey:params.theirBaseKey - andKeyPair:params.ourIdentityKeyPair]]; - [masterKey appendData:[Curve25519 try_generateSharedSecretFromPublicKey:params.theirBaseKey - andKeyPair:params.ourSignedPrekey]]; + [masterKey appendData:[Curve25519 throws_generateSharedSecretFromPublicKey:params.theirIdentityKey + andKeyPair:params.ourSignedPrekey]]; + [masterKey appendData:[Curve25519 throws_generateSharedSecretFromPublicKey:params.theirBaseKey + andKeyPair:params.ourIdentityKeyPair]]; + [masterKey appendData:[Curve25519 throws_generateSharedSecretFromPublicKey:params.theirBaseKey + andKeyPair:params.ourSignedPrekey]]; if (params.ourOneTimePrekey) { - [masterKey appendData:[Curve25519 try_generateSharedSecretFromPublicKey:params.theirBaseKey - andKeyPair:params.ourOneTimePrekey]]; + [masterKey appendData:[Curve25519 throws_generateSharedSecretFromPublicKey:params.theirBaseKey + andKeyPair:params.ourOneTimePrekey]]; } } - return [[DHEResult alloc] init_try_withMasterKey:masterKey]; + return [[DHEResult alloc] init_throws_withMasterKey:masterKey]; } /** diff --git a/AxolotlKit/Classes/Ratchet/RootKey.h b/AxolotlKit/Classes/Ratchet/RootKey.h index d5d57fa..7882d7b 100644 --- a/AxolotlKit/Classes/Ratchet/RootKey.h +++ b/AxolotlKit/Classes/Ratchet/RootKey.h @@ -10,7 +10,8 @@ @interface RootKey : NSObject - (instancetype)initWithData:(NSData *)data; -- (RKCK *)try_createChainWithTheirEphemeral:(NSData *)theirEphemeral ourEphemeral:(ECKeyPair *)ourEphemeral NS_SWIFT_UNAVAILABLE("throws objc exceptions"); +- (RKCK *)throws_createChainWithTheirEphemeral:(NSData *)theirEphemeral + ourEphemeral:(ECKeyPair *)ourEphemeral NS_SWIFT_UNAVAILABLE("throws objc exceptions"); @property (nonatomic, readonly) NSData *keyData; diff --git a/AxolotlKit/Classes/Ratchet/RootKey.m b/AxolotlKit/Classes/Ratchet/RootKey.m index 5b0420b..9ea605c 100644 --- a/AxolotlKit/Classes/Ratchet/RootKey.m +++ b/AxolotlKit/Classes/Ratchet/RootKey.m @@ -42,16 +42,16 @@ static NSString* const kCoderData = @"kCoderData"; return self; } -- (RKCK *)try_createChainWithTheirEphemeral:(NSData *)theirEphemeral ourEphemeral:(ECKeyPair *)ourEphemeral +- (RKCK *)throws_createChainWithTheirEphemeral:(NSData *)theirEphemeral ourEphemeral:(ECKeyPair *)ourEphemeral { OWSAssert(theirEphemeral); OWSAssert(ourEphemeral); - NSData *sharedSecret = [Curve25519 try_generateSharedSecretFromPublicKey:theirEphemeral andKeyPair:ourEphemeral]; + NSData *sharedSecret = [Curve25519 throws_generateSharedSecretFromPublicKey:theirEphemeral andKeyPair:ourEphemeral]; OWSAssert(sharedSecret.length == 32); TSDerivedSecrets *secrets = - [TSDerivedSecrets try_derivedRatchetedSecretsWithSharedSecret:sharedSecret rootKey:_keyData]; + [TSDerivedSecrets throws_derivedRatchetedSecretsWithSharedSecret:sharedSecret rootKey:_keyData]; OWSAssert(secrets); RKCK *newRKCK = [[RKCK alloc] initWithRK:[[RootKey alloc] initWithData:secrets.cipherKey] diff --git a/AxolotlKit/Classes/Ratchet/TSDerivedSecrets.h b/AxolotlKit/Classes/Ratchet/TSDerivedSecrets.h index 7a3ef90..9497dfe 100644 --- a/AxolotlKit/Classes/Ratchet/TSDerivedSecrets.h +++ b/AxolotlKit/Classes/Ratchet/TSDerivedSecrets.h @@ -6,9 +6,12 @@ @interface TSDerivedSecrets : NSData -+ (instancetype)try_derivedInitialSecretsWithMasterKey:(NSData *)masterKey NS_SWIFT_UNAVAILABLE("throws objc exceptions"); -+ (instancetype)try_derivedRatchetedSecretsWithSharedSecret:(NSData *)masterKey rootKey:(NSData *)rootKey NS_SWIFT_UNAVAILABLE("throws objc exceptions"); -+ (instancetype)try_derivedMessageKeysWithData:(NSData *)data NS_SWIFT_UNAVAILABLE("throws objc exceptions"); ++ (instancetype)throws_derivedInitialSecretsWithMasterKey:(NSData *)masterKey + NS_SWIFT_UNAVAILABLE("throws objc exceptions"); ++ (instancetype)throws_derivedRatchetedSecretsWithSharedSecret:(NSData *)masterKey + rootKey:(NSData *)rootKey + NS_SWIFT_UNAVAILABLE("throws objc exceptions"); ++ (instancetype)throws_derivedMessageKeysWithData:(NSData *)data NS_SWIFT_UNAVAILABLE("throws objc exceptions"); @property NSData *cipherKey; @property NSData *macKey; diff --git a/AxolotlKit/Classes/Ratchet/TSDerivedSecrets.m b/AxolotlKit/Classes/Ratchet/TSDerivedSecrets.m index bbc4a3d..dd1ba5d 100644 --- a/AxolotlKit/Classes/Ratchet/TSDerivedSecrets.m +++ b/AxolotlKit/Classes/Ratchet/TSDerivedSecrets.m @@ -8,7 +8,7 @@ @implementation TSDerivedSecrets -+ (instancetype)try_derivedSecretsWithSeed:(NSData *)masterKey salt:(NSData *)salt info:(NSData *)info ++ (instancetype)throws_derivedSecretsWithSeed:(NSData *)masterKey salt:(NSData *)salt info:(NSData *)info { OWSAssert(masterKey.length == 32); OWSAssert(info); @@ -22,7 +22,7 @@ } @try { - NSData *derivedMaterial = [HKDFKit try_deriveKey:masterKey info:info salt:salt outputSize:96]; + NSData *derivedMaterial = [HKDFKit throws_deriveKey:masterKey info:info salt:salt outputSize:96]; secrets.cipherKey = [derivedMaterial subdataWithRange:NSMakeRange(0, 32)]; secrets.macKey = [derivedMaterial subdataWithRange:NSMakeRange(32, 32)]; secrets.iv = [derivedMaterial subdataWithRange:NSMakeRange(64, 16)]; @@ -38,29 +38,29 @@ return secrets; } -+ (instancetype)try_derivedInitialSecretsWithMasterKey:(NSData *)masterKey ++ (instancetype)throws_derivedInitialSecretsWithMasterKey:(NSData *)masterKey { OWSAssert(masterKey); NSData *info = [@"WhisperText" dataUsingEncoding:NSUTF8StringEncoding]; - return [self try_derivedSecretsWithSeed:masterKey salt:nil info:info]; + return [self throws_derivedSecretsWithSeed:masterKey salt:nil info:info]; } -+ (instancetype)try_derivedRatchetedSecretsWithSharedSecret:(NSData *)masterKey rootKey:(NSData *)rootKey ++ (instancetype)throws_derivedRatchetedSecretsWithSharedSecret:(NSData *)masterKey rootKey:(NSData *)rootKey { OWSAssert(masterKey); OWSAssert(rootKey); NSData *info = [@"WhisperRatchet" dataUsingEncoding:NSUTF8StringEncoding]; - return [self try_derivedSecretsWithSeed:masterKey salt:rootKey info:info]; + return [self throws_derivedSecretsWithSeed:masterKey salt:rootKey info:info]; } -+ (instancetype)try_derivedMessageKeysWithData:(NSData *)data ++ (instancetype)throws_derivedMessageKeysWithData:(NSData *)data { OWSAssert(data); NSData *info = [@"WhisperMessageKeys" dataUsingEncoding:NSUTF8StringEncoding]; - return [self try_derivedSecretsWithSeed:data salt:nil info:info]; + return [self throws_derivedSecretsWithSeed:data salt:nil info:info]; } @end diff --git a/AxolotlKit/Classes/SessionCipher.h b/AxolotlKit/Classes/SessionCipher.h index f732031..80e3309 100644 --- a/AxolotlKit/Classes/SessionCipher.h +++ b/AxolotlKit/Classes/SessionCipher.h @@ -23,21 +23,21 @@ NS_ASSUME_NONNULL_BEGIN // protocolContext is an optional parameter that can be used to ensure that all // identity and session store writes are coordinated and/or occur within a single // transaction. -- (id)try_encryptMessage:(NSData *)paddedMessage - protocolContext:(nullable id)protocolContext NS_SWIFT_UNAVAILABLE("throws objc exceptions"); +- (id)throws_encryptMessage:(NSData *)paddedMessage + protocolContext:(nullable id)protocolContext NS_SWIFT_UNAVAILABLE("throws objc exceptions"); - (nullable id)encryptMessage:(NSData *)paddedMessage protocolContext:(nullable id)protocolContext error:(NSError **)outError; -- (NSData *)try_decrypt:(id)whisperMessage - protocolContext:(nullable id)protocolContext NS_SWIFT_UNAVAILABLE("throws objc exceptions"); +- (NSData *)throws_decrypt:(id)whisperMessage + protocolContext:(nullable id)protocolContext NS_SWIFT_UNAVAILABLE("throws objc exceptions"); - (nullable NSData *)decrypt:(id)whisperMessage protocolContext:(nullable id)protocolContext error:(NSError **)outError; -- (int)try_remoteRegistrationId:(nullable id)protocolContext NS_SWIFT_UNAVAILABLE("throws objc exceptions"); +- (int)throws_remoteRegistrationId:(nullable id)protocolContext NS_SWIFT_UNAVAILABLE("throws objc exceptions"); -- (int)try_sessionVersion:(nullable id)protocolContext NS_SWIFT_UNAVAILABLE("throws objc exceptions"); +- (int)throws_sessionVersion:(nullable id)protocolContext NS_SWIFT_UNAVAILABLE("throws objc exceptions"); @end diff --git a/AxolotlKit/Classes/SessionCipher.m b/AxolotlKit/Classes/SessionCipher.m index 2a8c914..2ce6714 100644 --- a/AxolotlKit/Classes/SessionCipher.m +++ b/AxolotlKit/Classes/SessionCipher.m @@ -87,14 +87,14 @@ NS_ASSUME_NONNULL_BEGIN __block id result; [SCKExceptionWrapper tryBlock:^{ - result = [self try_encryptMessage:paddedMessage protocolContext:protocolContext]; + result = [self throws_encryptMessage:paddedMessage protocolContext:protocolContext]; } error:outError]; return result; } -- (id)try_encryptMessage:(NSData *)paddedMessage protocolContext:(nullable id)protocolContext +- (id)throws_encryptMessage:(NSData *)paddedMessage protocolContext:(nullable id)protocolContext { OWSAssert(paddedMessage); @@ -102,7 +102,7 @@ NS_ASSUME_NONNULL_BEGIN [self.sessionStore loadSession:self.recipientId deviceId:self.deviceId protocolContext:protocolContext]; SessionState *sessionState = sessionRecord.sessionState; ChainKey *chainKey = sessionState.senderChainKey; - MessageKeys *messageKeys = [chainKey try_messageKeys]; + MessageKeys *messageKeys = [chainKey throws_messageKeys]; NSData *senderRatchetKey = sessionState.senderRatchetKey; int previousCounter = sessionState.previousCounter; int sessionVersion = sessionState.version; @@ -123,17 +123,17 @@ NS_ASSUME_NONNULL_BEGIN protocolContext:protocolContext]; NSData *ciphertextBody = - [AES_CBC try_encryptCBCMode:paddedMessage withKey:messageKeys.cipherKey withIV:messageKeys.iv]; + [AES_CBC throws_encryptCBCMode:paddedMessage withKey:messageKeys.cipherKey withIV:messageKeys.iv]; id cipherMessage = - [[WhisperMessage alloc] init_try_withVersion:sessionVersion - macKey:messageKeys.macKey - senderRatchetKey:senderRatchetKey.prependKeyType - counter:chainKey.index - previousCounter:previousCounter - cipherText:ciphertextBody - senderIdentityKey:sessionState.localIdentityKey.prependKeyType - receiverIdentityKey:sessionState.remoteIdentityKey.prependKeyType]; + [[WhisperMessage alloc] init_throws_withVersion:sessionVersion + macKey:messageKeys.macKey + senderRatchetKey:senderRatchetKey.prependKeyType + counter:chainKey.index + previousCounter:previousCounter + cipherText:ciphertextBody + senderIdentityKey:sessionState.localIdentityKey.prependKeyType + receiverIdentityKey:sessionState.remoteIdentityKey.prependKeyType]; if ([sessionState hasUnacknowledgedPreKeyMessage]) { PendingPreKey *items = [sessionState unacknowledgedPreKeyMessageItems]; @@ -142,12 +142,12 @@ NS_ASSUME_NONNULL_BEGIN DDLogInfo(@"Building PreKeyWhisperMessage for: %@ with preKeyId: %d", self.recipientId, items.preKeyId); cipherMessage = - [[PreKeyWhisperMessage alloc] init_try_withWhisperMessage:cipherMessage - registrationId:localRegistrationId - prekeyId:items.preKeyId - signedPrekeyId:items.signedPreKeyId - baseKey:items.baseKey.prependKeyType - identityKey:sessionState.localIdentityKey.prependKeyType]; + [[PreKeyWhisperMessage alloc] init_throws_withWhisperMessage:cipherMessage + registrationId:localRegistrationId + prekeyId:items.preKeyId + signedPrekeyId:items.signedPreKeyId + baseKey:items.baseKey.prependKeyType + identityKey:sessionState.localIdentityKey.prependKeyType]; } [sessionState setSenderChainKey:[chainKey nextChainKey]]; @@ -166,14 +166,14 @@ NS_ASSUME_NONNULL_BEGIN __block NSData *_Nullable result; [SCKExceptionWrapper tryBlock:^{ - result = [self try_decrypt:whisperMessage protocolContext:protocolContext]; + result = [self throws_decrypt:whisperMessage protocolContext:protocolContext]; } error:outError]; return result; } -- (NSData *)try_decrypt:(id)whisperMessage protocolContext:(nullable id)protocolContext +- (NSData *)throws_decrypt:(id)whisperMessage protocolContext:(nullable id)protocolContext { OWSAssert(whisperMessage); @@ -183,31 +183,33 @@ NS_ASSUME_NONNULL_BEGIN OWSFail(@"Unexpected message type: %@", [whisperMessage class]); return nil; } - return [self try_decryptWhisperMessage:(WhisperMessage *)whisperMessage protocolContext:protocolContext]; + return [self throws_decryptWhisperMessage:(WhisperMessage *)whisperMessage protocolContext:protocolContext]; case CipherMessageType_Prekey: if (![whisperMessage isKindOfClass:[PreKeyWhisperMessage class]]) { OWSFail(@"Unexpected message type: %@", [whisperMessage class]); return nil; } - return [self try_decryptPreKeyWhisperMessage:(PreKeyWhisperMessage *)whisperMessage - protocolContext:protocolContext]; + return [self throws_decryptPreKeyWhisperMessage:(PreKeyWhisperMessage *)whisperMessage + protocolContext:protocolContext]; default: OWSFailDebug(@"Unexpected message type: %@", [whisperMessage class]); break; } } -- (NSData *)try_decryptPreKeyWhisperMessage:(PreKeyWhisperMessage *)preKeyWhisperMessage - protocolContext:(nullable id)protocolContext +- (NSData *)throws_decryptPreKeyWhisperMessage:(PreKeyWhisperMessage *)preKeyWhisperMessage + protocolContext:(nullable id)protocolContext { OWSAssert(preKeyWhisperMessage); SessionRecord *sessionRecord = [self.sessionStore loadSession:self.recipientId deviceId:self.deviceId protocolContext:protocolContext]; - int unsignedPreKeyId = [self.sessionBuilder try_processPrekeyWhisperMessage:preKeyWhisperMessage withSession:sessionRecord protocolContext:protocolContext]; - NSData *plaintext = [self try_decryptWithSessionRecord:sessionRecord - whisperMessage:preKeyWhisperMessage.message - protocolContext:protocolContext]; + int unsignedPreKeyId = [self.sessionBuilder throws_processPrekeyWhisperMessage:preKeyWhisperMessage + withSession:sessionRecord + protocolContext:protocolContext]; + NSData *plaintext = [self throws_decryptWithSessionRecord:sessionRecord + whisperMessage:preKeyWhisperMessage.message + protocolContext:protocolContext]; [self.sessionStore storeSession:self.recipientId deviceId:self.deviceId @@ -222,14 +224,15 @@ NS_ASSUME_NONNULL_BEGIN return plaintext; } -- (NSData *)try_decryptWhisperMessage:(WhisperMessage *)whisperMessage protocolContext:(nullable id)protocolContext +- (NSData *)throws_decryptWhisperMessage:(WhisperMessage *)whisperMessage protocolContext:(nullable id)protocolContext { OWSAssert(whisperMessage); SessionRecord *sessionRecord = [self.sessionStore loadSession:self.recipientId deviceId:self.deviceId protocolContext:protocolContext]; - NSData *plaintext = - [self try_decryptWithSessionRecord:sessionRecord whisperMessage:whisperMessage protocolContext:protocolContext]; + NSData *plaintext = [self throws_decryptWithSessionRecord:sessionRecord + whisperMessage:whisperMessage + protocolContext:protocolContext]; if (![self.identityKeyStore isTrustedIdentityKey:sessionRecord.sessionState.remoteIdentityKey recipientId:self.recipientId @@ -253,9 +256,9 @@ NS_ASSUME_NONNULL_BEGIN return plaintext; } -- (NSData *)try_decryptWithSessionRecord:(SessionRecord *)sessionRecord - whisperMessage:(WhisperMessage *)whisperMessage - protocolContext:(nullable id)protocolContext +- (NSData *)throws_decryptWithSessionRecord:(SessionRecord *)sessionRecord + whisperMessage:(WhisperMessage *)whisperMessage + protocolContext:(nullable id)protocolContext { OWSAssert(sessionRecord); OWSAssert(whisperMessage); @@ -264,9 +267,9 @@ NS_ASSUME_NONNULL_BEGIN NSMutableArray *exceptions = [NSMutableArray array]; @try { - NSData *decryptedData = [self try_decryptWithSessionState:sessionState - whisperMessage:whisperMessage - protocolContext:protocolContext]; + NSData *decryptedData = [self throws_decryptWithSessionState:sessionState + whisperMessage:whisperMessage + protocolContext:protocolContext]; DDLogDebug(@"%@ successfully decrypted with current session state: %@", self.tag, sessionState); return decryptedData; } @@ -285,9 +288,9 @@ NS_ASSUME_NONNULL_BEGIN [[sessionRecord previousSessionStates] enumerateObjectsUsingBlock:^(SessionState *_Nonnull previousState, NSUInteger idx, BOOL *_Nonnull stop) { @try { - decryptedData = [self try_decryptWithSessionState:previousState - whisperMessage:whisperMessage - protocolContext:protocolContext]; + decryptedData = [self throws_decryptWithSessionState:previousState + whisperMessage:whisperMessage + protocolContext:protocolContext]; DDLogInfo(@"%@ successfully decrypted with PREVIOUS session state: %@", self.tag, previousState); OWSAssert(decryptedData != nil); stateToPromoteIdx = idx; @@ -329,9 +332,9 @@ NS_ASSUME_NONNULL_BEGIN } } -- (NSData *)try_decryptWithSessionState:(SessionState *)sessionState - whisperMessage:(WhisperMessage *)whisperMessage - protocolContext:(nullable id)protocolContext +- (NSData *)throws_decryptWithSessionState:(SessionState *)sessionState + whisperMessage:(WhisperMessage *)whisperMessage + protocolContext:(nullable id)protocolContext { OWSAssert(sessionState); OWSAssert(whisperMessage); @@ -349,30 +352,30 @@ NS_ASSUME_NONNULL_BEGIN } int messageVersion = whisperMessage.version; - NSData *theirEphemeral = whisperMessage.senderRatchetKey.try_removeKeyType; + NSData *theirEphemeral = whisperMessage.senderRatchetKey.throws_removeKeyType; int counter = whisperMessage.counter; - ChainKey *chainKey = [self try_getOrCreateChainKeys:sessionState theirEphemeral:theirEphemeral]; + ChainKey *chainKey = [self throws_getOrCreateChainKeys:sessionState theirEphemeral:theirEphemeral]; OWSAssert(chainKey); - MessageKeys *messageKeys = [self try_getOrCreateMessageKeysForSession:sessionState - theirEphemeral:theirEphemeral - chainKey:chainKey - counter:counter]; + MessageKeys *messageKeys = [self throws_getOrCreateMessageKeysForSession:sessionState + theirEphemeral:theirEphemeral + chainKey:chainKey + counter:counter]; OWSAssert(messageKeys); - [whisperMessage try_verifyMacWithVersion:messageVersion - senderIdentityKey:sessionState.remoteIdentityKey - receiverIdentityKey:sessionState.localIdentityKey - macKey:messageKeys.macKey]; + [whisperMessage throws_verifyMacWithVersion:messageVersion + senderIdentityKey:sessionState.remoteIdentityKey + receiverIdentityKey:sessionState.localIdentityKey + macKey:messageKeys.macKey]; NSData *plaintext = - [AES_CBC try_decryptCBCMode:whisperMessage.cipherText withKey:messageKeys.cipherKey withIV:messageKeys.iv]; + [AES_CBC throws_decryptCBCMode:whisperMessage.cipherText withKey:messageKeys.cipherKey withIV:messageKeys.iv]; [sessionState clearUnacknowledgedPreKeyMessage]; return plaintext; } -- (ChainKey *)try_getOrCreateChainKeys:(SessionState *)sessionState theirEphemeral:(NSData *)theirEphemeral +- (ChainKey *)throws_getOrCreateChainKeys:(SessionState *)sessionState theirEphemeral:(NSData *)theirEphemeral { OWSAssert(sessionState); OWSGuardWithException(theirEphemeral, InvalidMessageException); @@ -390,13 +393,14 @@ NS_ASSUME_NONNULL_BEGIN ECKeyPair *ourEphemeral = [sessionState senderRatchetKeyPair]; OWSAssert(ourEphemeral.publicKey.length == 32); - RKCK *receiverChain = [rootKey try_createChainWithTheirEphemeral:theirEphemeral ourEphemeral:ourEphemeral]; + RKCK *receiverChain = + [rootKey throws_createChainWithTheirEphemeral:theirEphemeral ourEphemeral:ourEphemeral]; ECKeyPair *ourNewEphemeral = [Curve25519 generateKeyPair]; OWSAssert(ourNewEphemeral.publicKey.length == 32); - RKCK *senderChain = - [receiverChain.rootKey try_createChainWithTheirEphemeral:theirEphemeral ourEphemeral:ourNewEphemeral]; + RKCK *senderChain = [receiverChain.rootKey throws_createChainWithTheirEphemeral:theirEphemeral + ourEphemeral:ourNewEphemeral]; OWSAssert(senderChain.rootKey.keyData.length == 32); [sessionState setRootKey:senderChain.rootKey]; @@ -417,10 +421,10 @@ NS_ASSUME_NONNULL_BEGIN } } -- (MessageKeys *)try_getOrCreateMessageKeysForSession:(SessionState *)sessionState - theirEphemeral:(NSData *)theirEphemeral - chainKey:(ChainKey *)chainKey - counter:(int)counter +- (MessageKeys *)throws_getOrCreateMessageKeysForSession:(SessionState *)sessionState + theirEphemeral:(NSData *)theirEphemeral + chainKey:(ChainKey *)chainKey + counter:(int)counter { OWSAssert(sessionState); OWSGuardWithException(theirEphemeral, InvalidMessageException); @@ -459,13 +463,13 @@ NS_ASSUME_NONNULL_BEGIN } while (chainKey.index < counter) { - MessageKeys *messageKeys = [chainKey try_messageKeys]; + MessageKeys *messageKeys = [chainKey throws_messageKeys]; [sessionState setMessageKeys:theirEphemeral messageKeys:messageKeys]; chainKey = chainKey.nextChainKey; } [sessionState setReceiverChainKey:theirEphemeral chainKey:[chainKey nextChainKey]]; - return [chainKey try_messageKeys]; + return [chainKey throws_messageKeys]; } /** @@ -480,7 +484,7 @@ NS_ASSUME_NONNULL_BEGIN return versionByte; } -- (int)try_remoteRegistrationId:(nullable id)protocolContext +- (int)throws_remoteRegistrationId:(nullable id)protocolContext { SessionRecord *_Nullable record = [self.sessionStore loadSession:self.recipientId deviceId:_deviceId protocolContext:protocolContext]; @@ -492,7 +496,7 @@ NS_ASSUME_NONNULL_BEGIN return record.sessionState.remoteRegistrationId; } -- (int)try_sessionVersion:(nullable id)protocolContext +- (int)throws_sessionVersion:(nullable id)protocolContext { SessionRecord *_Nullable record = [self.sessionStore loadSession:self.recipientId deviceId:_deviceId protocolContext:protocolContext]; diff --git a/AxolotlKit/Classes/Sessions/SessionBuilder.h b/AxolotlKit/Classes/Sessions/SessionBuilder.h index dc73dbe..80dde71 100644 --- a/AxolotlKit/Classes/Sessions/SessionBuilder.h +++ b/AxolotlKit/Classes/Sessions/SessionBuilder.h @@ -29,15 +29,15 @@ extern const int kPreKeyOfLastResortId; recipientId:(NSString *)recipientId deviceId:(int)deviceId; -- (void)try_processPrekeyBundle:(PreKeyBundle *)preKeyBundle - protocolContext:(nullable id)protocolContext NS_SWIFT_UNAVAILABLE("throws objc exceptions"); +- (void)throws_processPrekeyBundle:(PreKeyBundle *)preKeyBundle + protocolContext:(nullable id)protocolContext NS_SWIFT_UNAVAILABLE("throws objc exceptions"); - (BOOL)processPrekeyBundle:(PreKeyBundle *)preKeyBundle protocolContext:(nullable id)protocolContext error:(NSError **)outError; -- (int)try_processPrekeyWhisperMessage:(PreKeyWhisperMessage *)message - withSession:(SessionRecord *)sessionRecord - protocolContext:(nullable id)protocolContext NS_SWIFT_UNAVAILABLE("throws objc exceptions"); +- (int)throws_processPrekeyWhisperMessage:(PreKeyWhisperMessage *)message + withSession:(SessionRecord *)sessionRecord + protocolContext:(nullable id)protocolContext NS_SWIFT_UNAVAILABLE("throws objc exceptions"); @end diff --git a/AxolotlKit/Classes/Sessions/SessionBuilder.m b/AxolotlKit/Classes/Sessions/SessionBuilder.m index fd973a1..31d0932 100644 --- a/AxolotlKit/Classes/Sessions/SessionBuilder.m +++ b/AxolotlKit/Classes/Sessions/SessionBuilder.m @@ -85,17 +85,17 @@ const int kPreKeyOfLastResortId = 0xFFFFFF; { return [SCKExceptionWrapper tryBlock:^{ - [self try_processPrekeyBundle:preKeyBundle protocolContext:protocolContext]; + [self throws_processPrekeyBundle:preKeyBundle protocolContext:protocolContext]; } error:outError]; } -- (void)try_processPrekeyBundle:(PreKeyBundle *)preKeyBundle protocolContext:(nullable id)protocolContext +- (void)throws_processPrekeyBundle:(PreKeyBundle *)preKeyBundle protocolContext:(nullable id)protocolContext { OWSAssert(preKeyBundle); - NSData *theirIdentityKey = preKeyBundle.identityKey.try_removeKeyType; - NSData *theirSignedPreKey = preKeyBundle.signedPreKeyPublic.try_removeKeyType; + NSData *theirIdentityKey = preKeyBundle.identityKey.throws_removeKeyType; + NSData *theirSignedPreKey = preKeyBundle.signedPreKeyPublic.throws_removeKeyType; if (![self.identityStore isTrustedIdentityKey:theirIdentityKey recipientId:self.recipientId @@ -105,16 +105,16 @@ const int kPreKeyOfLastResortId = 0xFFFFFF; } // NOTE: we use preKeyBundle.signedPreKeyPublic which has the key type byte. - if (![Ed25519 try_verifySignature:preKeyBundle.signedPreKeySignature - publicKey:theirIdentityKey - data:preKeyBundle.signedPreKeyPublic]) { + if (![Ed25519 throws_verifySignature:preKeyBundle.signedPreKeySignature + publicKey:theirIdentityKey + data:preKeyBundle.signedPreKeyPublic]) { @throw [NSException exceptionWithName:InvalidKeyException reason:@"KeyIsNotValidlySigned" userInfo:nil]; } SessionRecord *sessionRecord = [self.sessionStore loadSession:self.recipientId deviceId:preKeyBundle.deviceId protocolContext:protocolContext]; ECKeyPair *ourBaseKey = [Curve25519 generateKeyPair]; - NSData *theirOneTimePreKey = preKeyBundle.preKeyPublic.try_removeKeyType; + NSData *theirOneTimePreKey = preKeyBundle.preKeyPublic.throws_removeKeyType; int theirOneTimePreKeyId = preKeyBundle.preKeyId; int theirSignedPreKeyId = preKeyBundle.signedPreKeyId; @@ -131,9 +131,9 @@ const int kPreKeyOfLastResortId = 0xFFFFFF; [sessionRecord archiveCurrentState]; } - [RatchetingSession try_initializeSession:[sessionRecord sessionState] - sessionVersion:CURRENT_VERSION - AliceParameters:params]; + [RatchetingSession throws_initializeSession:[sessionRecord sessionState] + sessionVersion:CURRENT_VERSION + AliceParameters:params]; DDLogInfo(@"setUnacknowledgedPreKeyMessage for: %@ with preKeyId: %d", self.recipientId, theirOneTimePreKeyId); @@ -159,15 +159,15 @@ const int kPreKeyOfLastResortId = 0xFFFFFF; protocolContext:protocolContext]; } -- (int)try_processPrekeyWhisperMessage:(PreKeyWhisperMessage *)message - withSession:(SessionRecord *)sessionRecord - protocolContext:(nullable id)protocolContext +- (int)throws_processPrekeyWhisperMessage:(PreKeyWhisperMessage *)message + withSession:(SessionRecord *)sessionRecord + protocolContext:(nullable id)protocolContext { OWSAssert(message); OWSAssert(sessionRecord); int messageVersion = message.version; - NSData *theirIdentityKey = message.identityKey.try_removeKeyType; + NSData *theirIdentityKey = message.identityKey.throws_removeKeyType; if (![self.identityStore isTrustedIdentityKey:theirIdentityKey recipientId:self.recipientId @@ -180,7 +180,8 @@ const int kPreKeyOfLastResortId = 0xFFFFFF; switch (messageVersion) { case 3: - unSignedPrekeyId = [self try_processPrekeyV3:message withSession:sessionRecord protocolContext:protocolContext]; + unSignedPrekeyId = + [self throws_processPrekeyV3:message withSession:sessionRecord protocolContext:protocolContext]; break; default: @throw [NSException exceptionWithName:InvalidVersionException reason:@"Trying to initialize with unknown version" userInfo:@{}]; @@ -194,31 +195,31 @@ const int kPreKeyOfLastResortId = 0xFFFFFF; return unSignedPrekeyId; } -- (int)try_processPrekeyV3:(PreKeyWhisperMessage *)message - withSession:(SessionRecord *)sessionRecord - protocolContext:(nullable id)protocolContext +- (int)throws_processPrekeyV3:(PreKeyWhisperMessage *)message + withSession:(SessionRecord *)sessionRecord + protocolContext:(nullable id)protocolContext { OWSAssert(message); OWSAssert(sessionRecord); - NSData *baseKey = message.baseKey.try_removeKeyType; + NSData *baseKey = message.baseKey.throws_removeKeyType; if ([sessionRecord hasSessionState:message.version baseKey:baseKey]) { return -1; } - - ECKeyPair *ourSignedPrekey = [self.signedPreKeyStore try_loadSignedPrekey:message.signedPrekeyId].keyPair; + + ECKeyPair *ourSignedPrekey = [self.signedPreKeyStore throws_loadSignedPrekey:message.signedPrekeyId].keyPair; ECKeyPair *_Nullable ourOneTimePreKey; if (message.prekeyID >= 0) { - ourOneTimePreKey = [self.prekeyStore try_loadPreKey:message.prekeyID].keyPair; + ourOneTimePreKey = [self.prekeyStore throws_loadPreKey:message.prekeyID].keyPair; } else { DDLogWarn(@"%@ Processing PreKey message which had no one-time prekey.", self.tag); } BobAxolotlParameters *params = [[BobAxolotlParameters alloc] initWithMyIdentityKeyPair:[self.identityStore identityKeyPair:protocolContext] - theirIdentityKey:message.identityKey.try_removeKeyType + theirIdentityKey:message.identityKey.throws_removeKeyType ourSignedPrekey:ourSignedPrekey ourRatchetKey:ourSignedPrekey ourOneTimePrekey:ourOneTimePreKey @@ -228,9 +229,9 @@ const int kPreKeyOfLastResortId = 0xFFFFFF; [sessionRecord archiveCurrentState]; } - [RatchetingSession try_initializeSession:sessionRecord.sessionState - sessionVersion:message.version - BobParameters:params]; + [RatchetingSession throws_initializeSession:sessionRecord.sessionState + sessionVersion:message.version + BobParameters:params]; [sessionRecord.sessionState setLocalRegistrationId:[self.identityStore localRegistrationId:protocolContext]]; [sessionRecord.sessionState setRemoteRegistrationId:message.registrationId]; diff --git a/AxolotlKit/Classes/State/PreKeyStore.h b/AxolotlKit/Classes/State/PreKeyStore.h index b3c0f3c..27d356a 100644 --- a/AxolotlKit/Classes/State/PreKeyStore.h +++ b/AxolotlKit/Classes/State/PreKeyStore.h @@ -9,7 +9,7 @@ NS_ASSUME_NONNULL_BEGIN @protocol PreKeyStore -- (PreKeyRecord *)try_loadPreKey:(int)preKeyId NS_SWIFT_UNAVAILABLE("throws objc exceptions"); +- (PreKeyRecord *)throws_loadPreKey:(int)preKeyId NS_SWIFT_UNAVAILABLE("throws objc exceptions"); - (void)storePreKey:(int)preKeyId preKeyRecord:(PreKeyRecord *)record; diff --git a/AxolotlKit/Classes/State/SignedPreKeyStore.h b/AxolotlKit/Classes/State/SignedPreKeyStore.h index 72397be..1efb143 100644 --- a/AxolotlKit/Classes/State/SignedPreKeyStore.h +++ b/AxolotlKit/Classes/State/SignedPreKeyStore.h @@ -9,7 +9,7 @@ NS_ASSUME_NONNULL_BEGIN @protocol SignedPreKeyStore -- (SignedPreKeyRecord *)try_loadSignedPrekey:(int)signedPreKeyId NS_SWIFT_UNAVAILABLE("throws objc exceptions"); +- (SignedPreKeyRecord *)throws_loadSignedPrekey:(int)signedPreKeyId NS_SWIFT_UNAVAILABLE("throws objc exceptions"); - (nullable SignedPreKeyRecord *)loadSignedPrekeyOrNil:(int)signedPreKeyId; diff --git a/AxolotlKit/Classes/Utility/NSData+keyVersionByte.h b/AxolotlKit/Classes/Utility/NSData+keyVersionByte.h index 2e8ae2d..a4c6f1b 100644 --- a/AxolotlKit/Classes/Utility/NSData+keyVersionByte.h +++ b/AxolotlKit/Classes/Utility/NSData+keyVersionByte.h @@ -8,7 +8,7 @@ - (instancetype)prependKeyType; -- (instancetype)try_removeKeyType NS_SWIFT_UNAVAILABLE("throws objc exceptions"); +- (instancetype)throws_removeKeyType NS_SWIFT_UNAVAILABLE("throws objc exceptions"); - (nullable instancetype)removeKeyTypeAndReturnError:(NSError **)outError; @end diff --git a/AxolotlKit/Classes/Utility/NSData+keyVersionByte.m b/AxolotlKit/Classes/Utility/NSData+keyVersionByte.m index 606bc1a..ba06f40 100644 --- a/AxolotlKit/Classes/Utility/NSData+keyVersionByte.m +++ b/AxolotlKit/Classes/Utility/NSData+keyVersionByte.m @@ -24,14 +24,14 @@ const Byte DJB_TYPE = 0x05; - (nullable instancetype)removeKeyTypeAndReturnError:(NSError **)outError { @try { - return self.try_removeKeyType; + return self.throws_removeKeyType; } @catch (NSException *exception) { *outError = SCKExceptionWrapperErrorMake(exception); return nil; } } -- (instancetype)try_removeKeyType +- (instancetype)throws_removeKeyType { if (self.length == 33) { if ([[self subdataWithRange:NSMakeRange(0, 1)] isEqualToData:[NSData dataWithBytes:&DJB_TYPE length:1]]) { diff --git a/AxolotlKit/Classes/Utility/SerializationUtilities.h b/AxolotlKit/Classes/Utility/SerializationUtilities.h index a43797d..a108969 100644 --- a/AxolotlKit/Classes/Utility/SerializationUtilities.h +++ b/AxolotlKit/Classes/Utility/SerializationUtilities.h @@ -16,11 +16,11 @@ NS_ASSUME_NONNULL_BEGIN + (Byte)intsToByteHigh:(int)highValue low:(int)lowValue; -+ (NSData *)try_macWithVersion:(int)version - identityKey:(NSData *)senderIdentityKey - receiverIdentityKey:(NSData *)receiverIdentityKey - macKey:(NSData *)macKey - serialized:(NSData *)serialized NS_SWIFT_UNAVAILABLE("throws objc exceptions"); ++ (NSData *)throws_macWithVersion:(int)version + identityKey:(NSData *)senderIdentityKey + receiverIdentityKey:(NSData *)receiverIdentityKey + macKey:(NSData *)macKey + serialized:(NSData *)serialized NS_SWIFT_UNAVAILABLE("throws objc exceptions"); @end diff --git a/AxolotlKit/Classes/Utility/SerializationUtilities.m b/AxolotlKit/Classes/Utility/SerializationUtilities.m index 38d5503..dcbb1b7 100644 --- a/AxolotlKit/Classes/Utility/SerializationUtilities.m +++ b/AxolotlKit/Classes/Utility/SerializationUtilities.m @@ -24,11 +24,11 @@ NS_ASSUME_NONNULL_BEGIN return (Byte)((highValue << 4 | lowValue) & 0xFF); } -+ (NSData *)try_macWithVersion:(int)version - identityKey:(NSData *)senderIdentityKey - receiverIdentityKey:(NSData *)receiverIdentityKey - macKey:(NSData *)macKey - serialized:(NSData *)serialized ++ (NSData *)throws_macWithVersion:(int)version + identityKey:(NSData *)senderIdentityKey + receiverIdentityKey:(NSData *)receiverIdentityKey + macKey:(NSData *)macKey + serialized:(NSData *)serialized { if (!macKey) { @throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Missing macKey." userInfo:nil]; diff --git a/AxolotlKitTests/AxolotlInMemoryStore.m b/AxolotlKitTests/AxolotlInMemoryStore.m index ebc49d9..33b800d 100644 --- a/AxolotlKitTests/AxolotlInMemoryStore.m +++ b/AxolotlKitTests/AxolotlInMemoryStore.m @@ -46,7 +46,8 @@ NS_ASSUME_NONNULL_BEGIN # pragma mark Signed PreKey Store -- (SignedPreKeyRecord *)try_loadSignedPrekey:(int)signedPreKeyId{ +- (SignedPreKeyRecord *)throws_loadSignedPrekey:(int)signedPreKeyId +{ if (![[self.signedPreKeyStore allKeys] containsObject:[NSNumber numberWithInt:signedPreKeyId]]) { @throw [NSException exceptionWithName:InvalidKeyIdException reason:@"No such signedprekeyrecord" userInfo:nil]; } @@ -59,7 +60,7 @@ NS_ASSUME_NONNULL_BEGIN if ([self containsSignedPreKey:signedPreKeyId]) { @try { // Given that we've checked for `contains` this really shouldn't fail. - return [self try_loadSignedPrekey:signedPreKeyId]; + return [self throws_loadSignedPrekey:signedPreKeyId]; } @catch (NSException *exception) { OWSFailDebug(@"unexpected exception: %@", exception); return nil; @@ -98,7 +99,8 @@ NS_ASSUME_NONNULL_BEGIN # pragma mark PreKey Store -- (PreKeyRecord *)try_loadPreKey:(int)preKeyId{ +- (PreKeyRecord *)throws_loadPreKey:(int)preKeyId +{ if (![[self.preKeyStore allKeys] containsObject:[NSNumber numberWithInt:preKeyId]]) { @throw [NSException exceptionWithName:InvalidKeyIdException reason:@"No such signedprekeyrecord" userInfo:nil]; } diff --git a/AxolotlKitTests/ECCTests.m b/AxolotlKitTests/ECCTests.m index e6c4ef2..11bbcf8 100644 --- a/AxolotlKitTests/ECCTests.m +++ b/AxolotlKitTests/ECCTests.m @@ -74,14 +74,14 @@ (Byte) 0xe6, (Byte) 0x29}; NSData *sharedSecret = [NSData dataWithBytes:sharedBytes length:32]; - - ECKeyPair *aliceKeyPair = [ECKeyPair try_keyPairWithPrivateKey:alicePrivateKey publicKey:alicePublicKey]; - ECKeyPair *bobKeyPair = [ECKeyPair try_keyPairWithPrivateKey:bobPrivateKey publicKey:bobPublicKey]; + + ECKeyPair *aliceKeyPair = [ECKeyPair throws_keyPairWithPrivateKey:alicePrivateKey publicKey:alicePublicKey]; + ECKeyPair *bobKeyPair = [ECKeyPair throws_keyPairWithPrivateKey:bobPrivateKey publicKey:bobPublicKey]; NSData *aliceShared = - [Curve25519 try_generateSharedSecretFromPublicKey:[bobKeyPair publicKey] andKeyPair:aliceKeyPair]; + [Curve25519 throws_generateSharedSecretFromPublicKey:[bobKeyPair publicKey] andKeyPair:aliceKeyPair]; NSData *bobShared = - [Curve25519 try_generateSharedSecretFromPublicKey:[aliceKeyPair publicKey] andKeyPair:bobKeyPair]; + [Curve25519 throws_generateSharedSecretFromPublicKey:[aliceKeyPair publicKey] andKeyPair:bobKeyPair]; XCTAssert([aliceShared isEqualToData:sharedSecret], @"Alice's shared secret is equal to the expected one."); XCTAssert([bobShared isEqualToData:sharedSecret], @"Bob's shared secret is equal to the expected one."); @@ -92,9 +92,9 @@ ECKeyPair *aliceKeyPair = [Curve25519 generateKeyPair]; ECKeyPair *bobKeyPair = [Curve25519 generateKeyPair]; - XCTAssert([[Curve25519 try_generateSharedSecretFromPublicKey:[aliceKeyPair publicKey] andKeyPair:bobKeyPair] - isEqualToData:[Curve25519 try_generateSharedSecretFromPublicKey:[bobKeyPair publicKey] - andKeyPair:aliceKeyPair]], + XCTAssert([[Curve25519 throws_generateSharedSecretFromPublicKey:[aliceKeyPair publicKey] andKeyPair:bobKeyPair] + isEqualToData:[Curve25519 throws_generateSharedSecretFromPublicKey:[bobKeyPair publicKey] + andKeyPair:aliceKeyPair]], @"Randomly generated keypairs produce same shared secret."); } } @@ -145,7 +145,7 @@ NSData *signature = [NSData dataWithBytes:aliceSignature length:ECCSignatureLength]; - if (![Ed25519 try_verifySignature:signature publicKey:alicePublic data:ephemPublic]) { + if (![Ed25519 throws_verifySignature:signature publicKey:alicePublic data:ephemPublic]) { XCTAssert(NO, @"Sig verification failed!"); } @@ -161,7 +161,7 @@ [modifiedSignature replaceBytesInRange:NSMakeRange(i, 1) withBytes:&replacedByte length:1]; - if ([Ed25519 try_verifySignature:modifiedSignature publicKey:alicePublic data:ephemPublic]) { + if ([Ed25519 throws_verifySignature:modifiedSignature publicKey:alicePublic data:ephemPublic]) { XCTAssert(NO, @"Modified signature shouldn't be verified correctly"); } } diff --git a/AxolotlKitTests/RatchetingSessionTest.m b/AxolotlKitTests/RatchetingSessionTest.m index 19afa2b..5fc99d7 100644 --- a/AxolotlKitTests/RatchetingSessionTest.m +++ b/AxolotlKitTests/RatchetingSessionTest.m @@ -296,18 +296,23 @@ (Byte) 0x8D, (Byte) 0xF7, (Byte) 0x22, (Byte) 0xDC, (Byte) 0x22, (Byte) 0x76, (Byte) 0xC3, (Byte) 0xA6}; NSData *aliceCipherTextData = [NSData dataWithBytes:aliceCipherText length:32]; - - - ECKeyPair *aliceIdentityKey = [ECKeyPair try_keyPairWithPrivateKey:aliceIdentityPrivateKeyData publicKey:aliceIdentityPublicKeyData]; - - ECKeyPair *bobIdentityKey = [ECKeyPair try_keyPairWithPrivateKey:bobIdentityPrivateKeyData publicKey:bobIdentityPublicKeyData]; - - ECKeyPair *aliceBaseKey = [ECKeyPair try_keyPairWithPrivateKey:aliceBasePrivateKeyData publicKey:aliceBasePublicKeyData]; - - ECKeyPair *bobBaseKey = [ECKeyPair try_keyPairWithPrivateKey:bobBasePrivateKeyData publicKey:bobBasePublicKeyData]; - - ECKeyPair *aliceSendingRatchet = [ECKeyPair try_keyPairWithPrivateKey:aliceSendingRatchetPrivateData publicKey:aliceSendingRatchetPublicData]; - + + + ECKeyPair *aliceIdentityKey = + [ECKeyPair throws_keyPairWithPrivateKey:aliceIdentityPrivateKeyData publicKey:aliceIdentityPublicKeyData]; + + ECKeyPair *bobIdentityKey = + [ECKeyPair throws_keyPairWithPrivateKey:bobIdentityPrivateKeyData publicKey:bobIdentityPublicKeyData]; + + ECKeyPair *aliceBaseKey = + [ECKeyPair throws_keyPairWithPrivateKey:aliceBasePrivateKeyData publicKey:aliceBasePublicKeyData]; + + ECKeyPair *bobBaseKey = + [ECKeyPair throws_keyPairWithPrivateKey:bobBasePrivateKeyData publicKey:bobBasePublicKeyData]; + + ECKeyPair *aliceSendingRatchet = + [ECKeyPair throws_keyPairWithPrivateKey:aliceSendingRatchetPrivateData publicKey:aliceSendingRatchetPublicData]; + // --- AxolotlInMemoryStore *aliceStore = [AxolotlInMemoryStore new]; @@ -319,12 +324,15 @@ AliceAxolotlParameters *aliceAxolotlParams = [[AliceAxolotlParameters alloc] initWithIdentityKey:aliceIdentityKey theirIdentityKey:bobIdentityKey.publicKey ourBaseKey:aliceBaseKey theirSignedPreKey:bobBaseKey.publicKey theirOneTimePreKey:nil theirRatchetKey:bobBaseKey.publicKey]; BobAxolotlParameters *bobAxolotlParams = [[BobAxolotlParameters alloc] initWithMyIdentityKeyPair:bobIdentityKey theirIdentityKey:aliceIdentityKey.publicKey ourSignedPrekey:bobBaseKey ourRatchetKey:bobBaseKey ourOneTimePrekey:nil theirBaseKey:aliceBaseKey.publicKey]; - - [RatchetingSession try_initializeSession:aliceSessionRecord.sessionState sessionVersion:3 AliceParameters:aliceAxolotlParams senderRatchet:aliceSendingRatchet]; - [RatchetingSession try_initializeSession:bobSessionRecord.sessionState - sessionVersion:3 - BobParameters:bobAxolotlParams]; + [RatchetingSession throws_initializeSession:aliceSessionRecord.sessionState + sessionVersion:3 + AliceParameters:aliceAxolotlParams + senderRatchet:aliceSendingRatchet]; + + [RatchetingSession throws_initializeSession:bobSessionRecord.sessionState + sessionVersion:3 + BobParameters:bobAxolotlParams]; NSString *aliceIdentifier = @"+483294823482"; NSString *bobIdentifier = @"+389424728942"; @@ -333,14 +341,17 @@ XCTAssert([[@"This is a plaintext message." dataUsingEncoding:NSUTF8StringEncoding] isEqualToData:alicePlaintextData], @"Encoding is not correct"); XCTAssert([aliceSessionRecord.sessionState.rootKey.keyData isEqualToData:aliceSessionRecordRootKeyData]); XCTAssert([aliceSessionRecord.sessionState.senderChainKey.key isEqualToData:aliceSendingChainKeyData]); - XCTAssert([aliceSendingCipherKeyData isEqualToData:aliceSessionRecord.sessionState.senderChainKey.try_messageKeys.cipherKey]); - XCTAssert([aliceSendingIVKeyData isEqualToData:aliceSessionRecord.sessionState.senderChainKey.try_messageKeys.iv]); - XCTAssert([aliceSendingMacKeyData isEqualToData:aliceSessionRecord.sessionState.senderChainKey.try_messageKeys.macKey]); - + XCTAssert([aliceSendingCipherKeyData + isEqualToData:aliceSessionRecord.sessionState.senderChainKey.throws_messageKeys.cipherKey]); + XCTAssert( + [aliceSendingIVKeyData isEqualToData:aliceSessionRecord.sessionState.senderChainKey.throws_messageKeys.iv]); + XCTAssert([aliceSendingMacKeyData + isEqualToData:aliceSessionRecord.sessionState.senderChainKey.throws_messageKeys.macKey]); + [aliceStore storeSession:bobIdentifier deviceId:1 session:aliceSessionRecord protocolContext:nil]; SessionCipher *aliceSessionCipher = [[SessionCipher alloc] initWithAxolotlStore:aliceStore recipientId:bobIdentifier deviceId:1]; - - WhisperMessage *message = [aliceSessionCipher try_encryptMessage:alicePlaintextData protocolContext:nil]; + + WhisperMessage *message = [aliceSessionCipher throws_encryptMessage:alicePlaintextData protocolContext:nil]; XCTAssert([aliceCipherTextData isEqualToData:message.cipherText]); // Logging's Bob's Session initialization and first message decryption @@ -350,25 +361,25 @@ [bobStore storeSession:aliceIdentifier deviceId:1 session:bobSessionRecord protocolContext:nil]; SessionCipher *bobSessionCipher = [[SessionCipher alloc] initWithAxolotlStore:bobStore recipientId:aliceIdentifier deviceId:1]; - - NSData *plainData = [bobSessionCipher try_decrypt:message protocolContext:nil]; - + + NSData *plainData = [bobSessionCipher throws_decrypt:message protocolContext:nil]; + XCTAssert([plainData isEqualToData:alicePlaintextData]); for (int i = 0; i<100; i++) { NSData *message = [[NSString stringWithFormat:@"Message: %i", i] dataUsingEncoding:NSUTF8StringEncoding]; - - WhisperMessage *encrypted = [aliceSessionCipher try_encryptMessage:message protocolContext:nil]; - - XCTAssert([message isEqualToData:[bobSessionCipher try_decrypt:encrypted protocolContext:nil]]); + + WhisperMessage *encrypted = [aliceSessionCipher throws_encryptMessage:message protocolContext:nil]; + + XCTAssert([message isEqualToData:[bobSessionCipher throws_decrypt:encrypted protocolContext:nil]]); } for (int i = 0; i<100; i++) { NSData *message = [[NSString stringWithFormat:@"Message: %i", i] dataUsingEncoding:NSUTF8StringEncoding]; - - WhisperMessage *encrypted = [bobSessionCipher try_encryptMessage:message protocolContext:nil]; - - XCTAssert([message isEqualToData:[aliceSessionCipher try_decrypt:encrypted protocolContext:nil]]); + + WhisperMessage *encrypted = [bobSessionCipher throws_encryptMessage:message protocolContext:nil]; + + XCTAssert([message isEqualToData:[aliceSessionCipher throws_decrypt:encrypted protocolContext:nil]]); } NSMutableArray *plainTexts = [NSMutableArray new]; @@ -377,12 +388,12 @@ for (int i = 0 ; i < 100; i++) { NSData *message = [[NSString stringWithFormat:@"Message: %i", i] dataUsingEncoding:NSUTF8StringEncoding]; [plainTexts addObject:message]; - [cipherMessages addObject:[bobSessionCipher try_encryptMessage:message protocolContext:nil]]; + [cipherMessages addObject:[bobSessionCipher throws_encryptMessage:message protocolContext:nil]]; } for (int i = 0; i < plainTexts.count; i++) { - XCTAssert([[aliceSessionCipher try_decrypt:[cipherMessages objectAtIndex:i] protocolContext:nil] - isEqualToData:[plainTexts objectAtIndex:i]]); + XCTAssert([[aliceSessionCipher throws_decrypt:[cipherMessages objectAtIndex:i] protocolContext:nil] + isEqualToData:[plainTexts objectAtIndex:i]]); } } @@ -647,18 +658,23 @@ (Byte) 0x8D, (Byte) 0xF7, (Byte) 0x22, (Byte) 0xDC, (Byte) 0x22, (Byte) 0x76, (Byte) 0xC3, (Byte) 0xA6}; NSData *aliceCipherTextData = [NSData dataWithBytes:aliceCipherText length:32]; - - - ECKeyPair *aliceIdentityKey = [ECKeyPair try_keyPairWithPrivateKey:aliceIdentityPrivateKeyData publicKey:aliceIdentityPublicKeyData]; - - ECKeyPair *bobIdentityKey = [ECKeyPair try_keyPairWithPrivateKey:bobIdentityPrivateKeyData publicKey:bobIdentityPublicKeyData]; - - ECKeyPair *aliceBaseKey = [ECKeyPair try_keyPairWithPrivateKey:aliceBasePrivateKeyData publicKey:aliceBasePublicKeyData]; - - ECKeyPair *bobBaseKey = [ECKeyPair try_keyPairWithPrivateKey:bobBasePrivateKeyData publicKey:bobBasePublicKeyData]; - - ECKeyPair *aliceSendingRatchet = [ECKeyPair try_keyPairWithPrivateKey:aliceSendingRatchetPrivateData publicKey:aliceSendingRatchetPublicData]; - + + + ECKeyPair *aliceIdentityKey = + [ECKeyPair throws_keyPairWithPrivateKey:aliceIdentityPrivateKeyData publicKey:aliceIdentityPublicKeyData]; + + ECKeyPair *bobIdentityKey = + [ECKeyPair throws_keyPairWithPrivateKey:bobIdentityPrivateKeyData publicKey:bobIdentityPublicKeyData]; + + ECKeyPair *aliceBaseKey = + [ECKeyPair throws_keyPairWithPrivateKey:aliceBasePrivateKeyData publicKey:aliceBasePublicKeyData]; + + ECKeyPair *bobBaseKey = + [ECKeyPair throws_keyPairWithPrivateKey:bobBasePrivateKeyData publicKey:bobBasePublicKeyData]; + + ECKeyPair *aliceSendingRatchet = + [ECKeyPair throws_keyPairWithPrivateKey:aliceSendingRatchetPrivateData publicKey:aliceSendingRatchetPublicData]; + // --- AxolotlInMemoryStore *aliceStore = [AxolotlInMemoryStore new]; @@ -670,12 +686,15 @@ AliceAxolotlParameters *aliceAxolotlParams = [[AliceAxolotlParameters alloc] initWithIdentityKey:aliceIdentityKey theirIdentityKey:bobIdentityKey.publicKey ourBaseKey:aliceBaseKey theirSignedPreKey:bobBaseKey.publicKey theirOneTimePreKey:nil theirRatchetKey:bobBaseKey.publicKey]; BobAxolotlParameters *bobAxolotlParams = [[BobAxolotlParameters alloc] initWithMyIdentityKeyPair:bobIdentityKey theirIdentityKey:aliceIdentityKey.publicKey ourSignedPrekey:bobBaseKey ourRatchetKey:bobBaseKey ourOneTimePrekey:nil theirBaseKey:aliceBaseKey.publicKey]; - - [RatchetingSession try_initializeSession:aliceSessionRecord.sessionState sessionVersion:3 AliceParameters:aliceAxolotlParams senderRatchet:aliceSendingRatchet]; - [RatchetingSession try_initializeSession:bobSessionRecord.sessionState - sessionVersion:3 - BobParameters:bobAxolotlParams]; + [RatchetingSession throws_initializeSession:aliceSessionRecord.sessionState + sessionVersion:3 + AliceParameters:aliceAxolotlParams + senderRatchet:aliceSendingRatchet]; + + [RatchetingSession throws_initializeSession:bobSessionRecord.sessionState + sessionVersion:3 + BobParameters:bobAxolotlParams]; NSString *aliceIdentifier = @"+483294823482"; NSString *bobIdentifier = @"+389424728942"; @@ -684,14 +703,17 @@ XCTAssert([[@"This is a plaintext message." dataUsingEncoding:NSUTF8StringEncoding] isEqualToData:alicePlaintextData], @"Encoding is not correct"); XCTAssert([aliceSessionRecord.sessionState.rootKey.keyData isEqualToData:aliceSessionRecordRootKeyData]); XCTAssert([aliceSessionRecord.sessionState.senderChainKey.key isEqualToData:aliceSendingChainKeyData]); - XCTAssert([aliceSendingCipherKeyData isEqualToData:aliceSessionRecord.sessionState.senderChainKey.try_messageKeys.cipherKey]); - XCTAssert([aliceSendingIVKeyData isEqualToData:aliceSessionRecord.sessionState.senderChainKey.try_messageKeys.iv]); - XCTAssert([aliceSendingMacKeyData isEqualToData:aliceSessionRecord.sessionState.senderChainKey.try_messageKeys.macKey]); - + XCTAssert([aliceSendingCipherKeyData + isEqualToData:aliceSessionRecord.sessionState.senderChainKey.throws_messageKeys.cipherKey]); + XCTAssert( + [aliceSendingIVKeyData isEqualToData:aliceSessionRecord.sessionState.senderChainKey.throws_messageKeys.iv]); + XCTAssert([aliceSendingMacKeyData + isEqualToData:aliceSessionRecord.sessionState.senderChainKey.throws_messageKeys.macKey]); + [aliceStore storeSession:bobIdentifier deviceId:1 session:aliceSessionRecord protocolContext:nil]; SessionCipher *aliceSessionCipher = [[SessionCipher alloc] initWithAxolotlStore:aliceStore recipientId:bobIdentifier deviceId:1]; - - WhisperMessage *message = [aliceSessionCipher try_encryptMessage:alicePlaintextData protocolContext:nil]; + + WhisperMessage *message = [aliceSessionCipher throws_encryptMessage:alicePlaintextData protocolContext:nil]; XCTAssert([aliceCipherTextData isEqualToData:message.cipherText]); // Logging's Bob's Session initialization and first message decryption @@ -701,9 +723,9 @@ [bobStore storeSession:aliceIdentifier deviceId:1 session:bobSessionRecord protocolContext:nil]; SessionCipher *bobSessionCipher = [[SessionCipher alloc] initWithAxolotlStore:bobStore recipientId:aliceIdentifier deviceId:1]; - - NSData *plainData = [bobSessionCipher try_decrypt:message protocolContext:nil]; - + + NSData *plainData = [bobSessionCipher throws_decrypt:message protocolContext:nil]; + XCTAssert([plainData isEqualToData:alicePlaintextData]); @@ -713,12 +735,12 @@ for (int i = 0 ; i < 30; i++) { NSData *message = [[NSString stringWithFormat:@"Message: %i", i] dataUsingEncoding:NSUTF8StringEncoding]; [plainTexts addObject:message]; - [cipherMessages addObject:[bobSessionCipher try_encryptMessage:message protocolContext:nil]]; + [cipherMessages addObject:[bobSessionCipher throws_encryptMessage:message protocolContext:nil]]; } for (NSUInteger i = plainTexts.count-1; i > 0; i--) { - XCTAssert([[aliceSessionCipher try_decrypt:[cipherMessages objectAtIndex:i] protocolContext:nil] - isEqualToData:[plainTexts objectAtIndex:i]]); + XCTAssert([[aliceSessionCipher throws_decrypt:[cipherMessages objectAtIndex:i] protocolContext:nil] + isEqualToData:[plainTexts objectAtIndex:i]]); } } diff --git a/AxolotlKitTests/SessionBuilderTests.m b/AxolotlKitTests/SessionBuilderTests.m index bc43f85..045067c 100644 --- a/AxolotlKitTests/SessionBuilderTests.m +++ b/AxolotlKitTests/SessionBuilderTests.m @@ -54,7 +54,7 @@ ECKeyPair *bobPreKeyPair = [Curve25519 generateKeyPair]; ECKeyPair *bobSignedPreKeyPair = [Curve25519 generateKeyPair]; NSData *bobSignedPreKeySignature = - [Ed25519 try_sign:bobSignedPreKeyPair.publicKey.prependKeyType withKeyPair:[bobStore identityKeyPair:nil]]; + [Ed25519 throws_sign:bobSignedPreKeyPair.publicKey.prependKeyType withKeyPair:[bobStore identityKeyPair:nil]]; PreKeyBundle *bobPreKey = [[PreKeyBundle alloc]initWithRegistrationId:[bobStore localRegistrationId:nil] deviceId:1 @@ -64,17 +64,19 @@ signedPreKeyId:22 signedPreKeySignature:bobSignedPreKeySignature identityKey:[bobStore identityKeyPair:nil].publicKey.prependKeyType]; - - [aliceSessionBuilder try_processPrekeyBundle:bobPreKey protocolContext:nil]; - + + [aliceSessionBuilder throws_processPrekeyBundle:bobPreKey protocolContext:nil]; + XCTAssert([aliceStore containsSession:BOB_RECIPIENT_ID deviceId:1 protocolContext:nil]); XCTAssert([aliceStore loadSession:BOB_RECIPIENT_ID deviceId:1 protocolContext:nil].sessionState.version == 3); NSString *originalMessage = @"Freedom is the right to tell people what they do not want to hear."; SessionCipher *aliceSessionCipher = [[SessionCipher alloc] initWithAxolotlStore:aliceStore recipientId:BOB_RECIPIENT_ID deviceId:1]; - - WhisperMessage *outgoingMessage = [aliceSessionCipher try_encryptMessage:[originalMessage dataUsingEncoding:NSUTF8StringEncoding] protocolContext:nil]; - + + WhisperMessage *outgoingMessage = + [aliceSessionCipher throws_encryptMessage:[originalMessage dataUsingEncoding:NSUTF8StringEncoding] + protocolContext:nil]; + XCTAssert([outgoingMessage isKindOfClass:[PreKeyWhisperMessage class]], @"Message should be PreKey type"); PreKeyWhisperMessage *incomingMessage = (PreKeyWhisperMessage*)outgoingMessage; @@ -82,8 +84,8 @@ [bobStore storeSignedPreKey:22 signedPreKeyRecord:[[SignedPreKeyRecord alloc] initWithId:22 keyPair:bobSignedPreKeyPair signature:bobSignedPreKeySignature generatedAt:[NSDate date]]]; SessionCipher *bobSessionCipher = [[SessionCipher alloc] initWithAxolotlStore:bobStore recipientId:ALICE_RECIPIENT_ID deviceId:1]; - [bobSessionCipher try_decrypt:incomingMessage protocolContext:nil]; - + [bobSessionCipher throws_decrypt:incomingMessage protocolContext:nil]; + XCTAssert([bobStore containsSession:ALICE_RECIPIENT_ID deviceId:1 protocolContext:nil]); XCTAssert([bobStore loadSession:ALICE_RECIPIENT_ID deviceId:1 protocolContext:nil].sessionState.version == 3); XCTAssert([bobStore loadSession:ALICE_RECIPIENT_ID deviceId:1 protocolContext:nil].sessionState.aliceBaseKey != nil); @@ -105,7 +107,7 @@ ECKeyPair *bobPreKeyPair1 = [Curve25519 generateKeyPair]; ECKeyPair *bobSignedPreKeyPair1 = [Curve25519 generateKeyPair]; NSData *bobSignedPreKeySignature1 = - [Ed25519 try_sign:bobSignedPreKeyPair1.publicKey.prependKeyType withKeyPair:bobIdentityKeyPair1]; + [Ed25519 throws_sign:bobSignedPreKeyPair1.publicKey.prependKeyType withKeyPair:bobIdentityKeyPair1]; PreKeyBundle *bobPreKey1 = [[PreKeyBundle alloc] initWithRegistrationId:[bobStore localRegistrationId:nil] deviceId:1 @@ -116,7 +118,7 @@ signedPreKeySignature:bobSignedPreKeySignature1 identityKey:bobIdentityKeyPair1.publicKey.prependKeyType]; - [aliceSessionBuilder try_processPrekeyBundle:bobPreKey1 protocolContext:nil]; + [aliceSessionBuilder throws_processPrekeyBundle:bobPreKey1 protocolContext:nil]; XCTAssert([aliceStore containsSession:BOB_RECIPIENT_ID deviceId:1 protocolContext:nil]); XCTAssert([aliceStore loadSession:BOB_RECIPIENT_ID deviceId:1 protocolContext:nil].sessionState.version == 3); @@ -125,7 +127,8 @@ SessionCipher *aliceSessionCipher = [[SessionCipher alloc] initWithAxolotlStore:aliceStore recipientId:BOB_RECIPIENT_ID deviceId:1]; WhisperMessage *outgoingMessage1 = - [aliceSessionCipher try_encryptMessage:[messageText dataUsingEncoding:NSUTF8StringEncoding] protocolContext:nil]; + [aliceSessionCipher throws_encryptMessage:[messageText dataUsingEncoding:NSUTF8StringEncoding] + protocolContext:nil]; XCTAssert([outgoingMessage1 isKindOfClass:[PreKeyWhisperMessage class]], @"Message should be PreKey type"); @@ -133,7 +136,7 @@ ECKeyPair *bobPreKeyPair2 = [Curve25519 generateKeyPair]; ECKeyPair *bobSignedPreKeyPair2 = [Curve25519 generateKeyPair]; NSData *bobSignedPreKeySignature2 = - [Ed25519 try_sign:bobSignedPreKeyPair2.publicKey.prependKeyType withKeyPair:bobIdentityKeyPair2]; + [Ed25519 throws_sign:bobSignedPreKeyPair2.publicKey.prependKeyType withKeyPair:bobIdentityKeyPair2]; PreKeyBundle *bobPreKey2 = [[PreKeyBundle alloc] initWithRegistrationId:[bobStore localRegistrationId:nil] deviceId:1 @@ -144,8 +147,9 @@ signedPreKeySignature:bobSignedPreKeySignature2 identityKey:bobIdentityKeyPair2.publicKey.prependKeyType]; - XCTAssertThrowsSpecificNamed( - [aliceSessionBuilder try_processPrekeyBundle:bobPreKey2 protocolContext:nil], NSException, UntrustedIdentityKeyException); + XCTAssertThrowsSpecificNamed([aliceSessionBuilder throws_processPrekeyBundle:bobPreKey2 protocolContext:nil], + NSException, + UntrustedIdentityKeyException); } diff --git a/AxolotlKitTests/SessionCipherTest.m b/AxolotlKitTests/SessionCipherTest.m index 8a2e647..642e0be 100644 --- a/AxolotlKitTests/SessionCipherTest.m +++ b/AxolotlKitTests/SessionCipherTest.m @@ -50,7 +50,7 @@ SessionRecord *aliceSessionRecord = [SessionRecord new]; SessionRecord *bobSessionRecord = [SessionRecord new]; - [self try_sessionInitializationWithAliceSessionRecord:aliceSessionRecord bobSessionRecord:bobSessionRecord]; + [self throws_sessionInitializationWithAliceSessionRecord:aliceSessionRecord bobSessionRecord:bobSessionRecord]; [self runInteractionWithAliceRecord:aliceSessionRecord bobRecord:bobSessionRecord]; } @@ -61,7 +61,7 @@ // 1.) Given Alice and Bob have initialized some session together SessionState *initialSessionState = bobSessionRecord.sessionState; - [self try_sessionInitializationWithAliceSessionRecord:aliceSessionRecord bobSessionRecord:bobSessionRecord]; + [self throws_sessionInitializationWithAliceSessionRecord:aliceSessionRecord bobSessionRecord:bobSessionRecord]; SessionRecord *activeSession = [self.bobStore loadSession:self.aliceIdentifier deviceId:1 protocolContext:nil]; XCTAssertNotNil(activeSession); @@ -86,8 +86,8 @@ XCTAssertEqual(0, aliceSessionRecord.previousSessionStates.count); } -- (void)try_sessionInitializationWithAliceSessionRecord:(SessionRecord *)aliceSessionRecord - bobSessionRecord:(SessionRecord *)bobSessionRecord +- (void)throws_sessionInitializationWithAliceSessionRecord:(SessionRecord *)aliceSessionRecord + bobSessionRecord:(SessionRecord *)bobSessionRecord { SessionState *aliceSessionState = aliceSessionRecord.sessionState; @@ -104,9 +104,9 @@ BobAxolotlParameters *bobParams = [[BobAxolotlParameters alloc] initWithMyIdentityKeyPair:bobIdentityKeyPair theirIdentityKey:[aliceIdentityKeyPair publicKey] ourSignedPrekey:bobBaseKey ourRatchetKey:bobBaseKey ourOneTimePrekey:bobOneTimePK theirBaseKey:[aliceBaseKey publicKey]]; - [RatchetingSession try_initializeSession:bobSessionState sessionVersion:3 BobParameters:bobParams]; + [RatchetingSession throws_initializeSession:bobSessionState sessionVersion:3 BobParameters:bobParams]; - [RatchetingSession try_initializeSession:aliceSessionState sessionVersion:3 AliceParameters:aliceParams]; + [RatchetingSession throws_initializeSession:aliceSessionState sessionVersion:3 AliceParameters:aliceParams]; [self.aliceStore saveRemoteIdentity:bobIdentityKeyPair.publicKey recipientId:self.bobIdentifier protocolContext:nil]; [self.aliceStore storeSession:self.bobIdentifier deviceId:1 session:aliceSessionRecord protocolContext:nil]; @@ -124,10 +124,10 @@ [[SessionCipher alloc] initWithAxolotlStore:self.bobStore recipientId:self.aliceIdentifier deviceId:1]; NSData *alicePlainText = [@"This is a plaintext message!" dataUsingEncoding:NSUTF8StringEncoding]; - WhisperMessage *cipherText = [aliceSessionCipher try_encryptMessage:alicePlainText protocolContext:nil]; - - NSData *bobPlaintext = [bobSessionCipher try_decrypt:cipherText protocolContext:nil]; - + WhisperMessage *cipherText = [aliceSessionCipher throws_encryptMessage:alicePlainText protocolContext:nil]; + + NSData *bobPlaintext = [bobSessionCipher throws_decrypt:cipherText protocolContext:nil]; + XCTAssert([bobPlaintext isEqualToData:alicePlainText]); } diff --git a/AxolotlKitTests/Util/ECKeyPair+ECKeyPairTesting.h b/AxolotlKitTests/Util/ECKeyPair+ECKeyPairTesting.h index b27f46d..e8cacab 100644 --- a/AxolotlKitTests/Util/ECKeyPair+ECKeyPairTesting.h +++ b/AxolotlKitTests/Util/ECKeyPair+ECKeyPairTesting.h @@ -8,7 +8,8 @@ NS_ASSUME_NONNULL_BEGIN @interface ECKeyPair (ECKeyPairTesting) -+ (ECKeyPair *)try_keyPairWithPrivateKey:(NSData *)privateKey publicKey:(NSData *)publicKey NS_SWIFT_UNAVAILABLE("throws objc exceptions"); ++ (ECKeyPair *)throws_keyPairWithPrivateKey:(NSData *)privateKey + publicKey:(NSData *)publicKey NS_SWIFT_UNAVAILABLE("throws objc exceptions"); @end diff --git a/AxolotlKitTests/Util/ECKeyPair+ECKeyPairTesting.m b/AxolotlKitTests/Util/ECKeyPair+ECKeyPairTesting.m index 9b37fc5..02b35d5 100644 --- a/AxolotlKitTests/Util/ECKeyPair+ECKeyPairTesting.m +++ b/AxolotlKitTests/Util/ECKeyPair+ECKeyPairTesting.m @@ -17,10 +17,10 @@ NS_ASSUME_NONNULL_BEGIN @implementation ECKeyPair (testing) -+ (ECKeyPair *)try_keyPairWithPrivateKey:(NSData *)privateKey publicKey:(NSData *)publicKey ++ (ECKeyPair *)throws_keyPairWithPrivateKey:(NSData *)privateKey publicKey:(NSData *)publicKey { if (([publicKey length] == 33)) { - publicKey = [publicKey try_removeKeyType]; + publicKey = [publicKey throws_removeKeyType]; } if ([privateKey length] != ECCKeyLength && [publicKey length] != ECCKeyLength) { diff --git a/AxolotlKitTests/WhisperMessageSerialization.m b/AxolotlKitTests/WhisperMessageSerialization.m index fc9b257..71d768e 100644 --- a/AxolotlKitTests/WhisperMessageSerialization.m +++ b/AxolotlKitTests/WhisperMessageSerialization.m @@ -30,28 +30,28 @@ ECKeyPair *senderIdentityKey = [Curve25519 generateKeyPair]; ECKeyPair *receiverIdentityKey = [Curve25519 generateKeyPair]; - WhisperMessage *message = [[WhisperMessage alloc] init_try_withVersion:3 - macKey:fakeMacKey.publicKey - senderRatchetKey:keyPair.publicKey - counter:counter - previousCounter:0 - cipherText:cipherText - senderIdentityKey:senderIdentityKey.publicKey - receiverIdentityKey:receiverIdentityKey.publicKey]; + WhisperMessage *message = [[WhisperMessage alloc] init_throws_withVersion:3 + macKey:fakeMacKey.publicKey + senderRatchetKey:keyPair.publicKey + counter:counter + previousCounter:0 + cipherText:cipherText + senderIdentityKey:senderIdentityKey.publicKey + receiverIdentityKey:receiverIdentityKey.publicKey]; + + WhisperMessage *deserializedMessage = [[WhisperMessage alloc] init_throws_withData:message.serialized]; + - WhisperMessage *deserializedMessage = [[WhisperMessage alloc] init_try_withData:message.serialized]; - - XCTAssert([[message.serialized subdataWithRange:NSMakeRange(0, message.serialized.length-8)] isEqualToData:[deserializedMessage.serialized subdataWithRange:NSMakeRange(0, deserializedMessage.serialized.length-8)]]); - [message try_verifyMacWithVersion:3 - senderIdentityKey:senderIdentityKey.publicKey - receiverIdentityKey:receiverIdentityKey.publicKey - macKey:fakeMacKey.publicKey]; - [deserializedMessage try_verifyMacWithVersion:3 - senderIdentityKey:senderIdentityKey.publicKey - receiverIdentityKey:receiverIdentityKey.publicKey - macKey:fakeMacKey.publicKey]; + [message throws_verifyMacWithVersion:3 + senderIdentityKey:senderIdentityKey.publicKey + receiverIdentityKey:receiverIdentityKey.publicKey + macKey:fakeMacKey.publicKey]; + [deserializedMessage throws_verifyMacWithVersion:3 + senderIdentityKey:senderIdentityKey.publicKey + receiverIdentityKey:receiverIdentityKey.publicKey + macKey:fakeMacKey.publicKey]; XCTAssert([message.cipherText isEqualToData:deserializedMessage.cipherText]); XCTAssert(message.version == deserializedMessage.version);