diff --git a/AxolotlKit Tests/PreKeyBundleTests.m b/AxolotlKit Tests/PreKeyBundleTests.m new file mode 100644 index 0000000..0644055 --- /dev/null +++ b/AxolotlKit Tests/PreKeyBundleTests.m @@ -0,0 +1,59 @@ +// +// PreKeyBundleTests.m +// AxolotlKit +// +// Created by Frederic Jacobs on 15/02/15. +// Copyright (c) 2015 Frederic Jacobs. All rights reserved. +// + +#import + +#import "PreKeyBundle.h" +#import <25519/Curve25519.h> + +@interface PreKeyBundleTests : XCTestCase + +@end + +@implementation PreKeyBundleTests + +- (void)setUp { + [super setUp]; + // Put setup code here. This method is called before the invocation of each test method in the class. +} + +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. + [super tearDown]; +} + +- (void)testSerialization { + PreKeyBundle *bundle = [[PreKeyBundle alloc] initWithRegistrationId:1 + deviceId:2 + preKeyId:3 + preKeyPublic:[Curve25519 generateKeyPair].publicKey + signedPreKeyPublic:[Curve25519 generateKeyPair].publicKey + signedPreKeyId:4 + signedPreKeySignature:[Curve25519 generateKeyPair].publicKey + identityKey:[Curve25519 generateKeyPair].publicKey]; + + + NSData *data = [NSKeyedArchiver archivedDataWithRootObject:bundle]; + + PreKeyBundle *bundle2 = [NSKeyedUnarchiver unarchiveObjectWithData:data]; + + XCTAssertEqual(bundle.registrationId, bundle2.registrationId); + XCTAssertEqual(bundle.deviceId, bundle2.deviceId); + XCTAssertEqual(bundle.preKeyId, bundle2.preKeyId); + XCTAssertEqual(bundle.signedPreKeyId, bundle2.signedPreKeyId); + + + XCTAssert([bundle.preKeyPublic isEqualToData:bundle2.preKeyPublic]); + XCTAssert([bundle.signedPreKeyPublic isEqualToData:bundle2.signedPreKeyPublic]); + XCTAssert([bundle.signedPreKeySignature isEqualToData:bundle2.signedPreKeySignature]); + XCTAssert([bundle.identityKey isEqualToData:bundle2.identityKey]); + +} + + +@end diff --git a/AxolotlKit.podspec b/AxolotlKit.podspec index c7fe634..5806057 100644 --- a/AxolotlKit.podspec +++ b/AxolotlKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "AxolotlKit" - s.version = "0.6.1" + s.version = "0.6.2" s.summary = "AxolotlKit is a Free implementation of the Axolotl protocol in Objective-C" s.homepage = "https://github.com/WhisperSystems/AxolotlKit" s.license = "GPLv2" diff --git a/AxolotlKit.xcodeproj/project.pbxproj b/AxolotlKit.xcodeproj/project.pbxproj index c2f3317..262ba09 100644 --- a/AxolotlKit.xcodeproj/project.pbxproj +++ b/AxolotlKit.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 719C4E40588B7AD1F1DD22FC /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = AD9F87ECA041E727CC457415 /* libPods.a */; }; B619AF1419FC148D00E33198 /* ProtobuffsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B619AF1319FC148D00E33198 /* ProtobuffsTests.m */; }; B61E841E19D17C33004FC382 /* HKDFTest.m in Sources */ = {isa = PBXBuildFile; fileRef = B61E841C19D1780D004FC382 /* HKDFTest.m */; }; + B62EFBF01A9140190072ADD3 /* PreKeyBundleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B62EFBEF1A9140190072ADD3 /* PreKeyBundleTests.m */; }; B63B2F9F197D8AFD00E09F65 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B63B2F9E197D8AFD00E09F65 /* Foundation.framework */; }; B63B2FA1197D8AFD00E09F65 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B63B2FA0197D8AFD00E09F65 /* CoreGraphics.framework */; }; B63B2FA3197D8AFD00E09F65 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B63B2FA2197D8AFD00E09F65 /* UIKit.framework */; }; @@ -72,6 +73,7 @@ AD9F87ECA041E727CC457415 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; B619AF1319FC148D00E33198 /* ProtobuffsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProtobuffsTests.m; sourceTree = ""; }; B61E841C19D1780D004FC382 /* HKDFTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HKDFTest.m; sourceTree = ""; }; + B62EFBEF1A9140190072ADD3 /* PreKeyBundleTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PreKeyBundleTests.m; sourceTree = ""; }; B63B2F9D197D8AFD00E09F65 /* AxolotlKit.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AxolotlKit.app; sourceTree = BUILT_PRODUCTS_DIR; }; B63B2F9E197D8AFD00E09F65 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; B63B2FA0197D8AFD00E09F65 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; @@ -260,6 +262,7 @@ B63B2FDF197D8B9600E09F65 /* AxolotlKit Tests */ = { isa = PBXGroup; children = ( + B62EFBEF1A9140190072ADD3 /* PreKeyBundleTests.m */, B619AF1219FC147500E33198 /* Protobuffs */, B61E841719D172BC004FC382 /* ECC */, B61E841819D176D7004FC382 /* HKDF */, @@ -682,6 +685,7 @@ B6A3490319F1A4B4008A3E01 /* AxolotlInMemoryStore.m in Sources */, B63B2FE6197D8B9600E09F65 /* AxolotlKit_Tests.m in Sources */, B654B03419FACCB6000458F0 /* RatchetingSessionTest.m in Sources */, + B62EFBF01A9140190072ADD3 /* PreKeyBundleTests.m in Sources */, B6BB8C3519F7E773008A5895 /* SessionBuilderTests.m in Sources */, B6E37AE019CF107C00E619CA /* ECCTests.m in Sources */, B6B3E63C19FD3D8A0035422D /* WhisperMessageSerialization.m in Sources */, diff --git a/AxolotlKit/Classes/Prekeys/PreKeyBundle.h b/AxolotlKit/Classes/Prekeys/PreKeyBundle.h index e427228..d601c62 100644 --- a/AxolotlKit/Classes/Prekeys/PreKeyBundle.h +++ b/AxolotlKit/Classes/Prekeys/PreKeyBundle.h @@ -8,7 +8,7 @@ #import -@interface PreKeyBundle : NSObject +@interface PreKeyBundle : NSObject @property (nonatomic, readonly) NSData *identityKey; @property (nonatomic, readonly) int registrationId; diff --git a/AxolotlKit/Classes/Prekeys/PreKeyBundle.m b/AxolotlKit/Classes/Prekeys/PreKeyBundle.m index 1588697..dc56ac2 100644 --- a/AxolotlKit/Classes/Prekeys/PreKeyBundle.m +++ b/AxolotlKit/Classes/Prekeys/PreKeyBundle.m @@ -8,6 +8,16 @@ #import "PreKeyBundle.h" + +static NSString* const kCoderPKBIdentityKey = @"kCoderPKBIdentityKey"; +static NSString* const kCoderPKBregistrationId = @"kCoderPKBregistrationId"; +static NSString* const kCoderPKBdeviceId = @"kCoderPKBdeviceId"; +static NSString* const kCoderPKBsignedPreKeyPublic = @"kCoderPKBsignedPreKeyPublic"; +static NSString* const kCoderPKBpreKeyPublic = @"kCoderPKBpreKeyPublic"; +static NSString* const kCoderPKBpreKeyId = @"kCoderPKBpreKeyId"; +static NSString* const kCoderPKBsignedPreKeyId = @"kCoderPKBsignedPreKeyId"; +static NSString* const kCoderPKBsignedPreKeySignature = @"kCoderPKBsignedPreKeySignature"; + @implementation PreKeyBundle - (instancetype)initWithRegistrationId:(int)registrationId @@ -18,9 +28,9 @@ - (instancetype)initWithRegistrationId:(int)registrationId signedPreKeyId:(int)signedPreKeyId signedPreKeySignature:(NSData*)signedPreKeySignature identityKey:(NSData*)identityKey{ - + self = [super init]; - + if (self) { _identityKey = identityKey; _registrationId = registrationId; @@ -31,8 +41,48 @@ - (instancetype)initWithRegistrationId:(int)registrationId _signedPreKeyId = signedPreKeyId; _signedPreKeySignature = signedPreKeySignature; } + + return self; +} +- (id)initWithCoder:(NSCoder *)aDecoder{ + int registrationId = [aDecoder decodeIntForKey:kCoderPKBregistrationId]; + int deviceId = [aDecoder decodeIntForKey:kCoderPKBdeviceId]; + int preKeyId = [aDecoder decodeIntForKey:kCoderPKBpreKeyId]; + int signedPreKeyId = [aDecoder decodeIntForKey:kCoderPKBsignedPreKeyId]; + + NSData *preKeyPublic = [aDecoder decodeObjectOfClass:[NSData class] forKey:kCoderPKBpreKeyPublic]; + NSData *signedPreKeyPublic = [aDecoder decodeObjectOfClass:[NSData class] forKey:kCoderPKBsignedPreKeyPublic]; + NSData *signedPreKeySignature = [aDecoder decodeObjectOfClass:[NSData class] forKey:kCoderPKBsignedPreKeySignature]; + NSData *identityKey = [aDecoder decodeObjectOfClass:[NSData class] forKey:kCoderPKBIdentityKey]; + + + self = [self initWithRegistrationId:registrationId + deviceId:deviceId + preKeyId:preKeyId + preKeyPublic:preKeyPublic + signedPreKeyPublic:signedPreKeyPublic + signedPreKeyId:signedPreKeyId + signedPreKeySignature:signedPreKeySignature + identityKey:identityKey]; + return self; } +- (void)encodeWithCoder:(NSCoder *)aCoder{ + [aCoder encodeInt:_registrationId forKey:kCoderPKBregistrationId]; + [aCoder encodeInt:_deviceId forKey:kCoderPKBdeviceId]; + [aCoder encodeInt:_preKeyId forKey:kCoderPKBpreKeyId]; + [aCoder encodeInt:_signedPreKeyId forKey:kCoderPKBsignedPreKeyId]; + + [aCoder encodeObject:_preKeyPublic forKey:kCoderPKBpreKeyPublic]; + [aCoder encodeObject:_signedPreKeyPublic forKey:kCoderPKBsignedPreKeyPublic]; + [aCoder encodeObject:_signedPreKeySignature forKey:kCoderPKBsignedPreKeySignature]; + [aCoder encodeObject:_identityKey forKey:kCoderPKBIdentityKey]; +} + ++(BOOL)supportsSecureCoding{ + return YES; +} + @end