Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated example projects to support v3 naming, CocoaPod libsodium #19

Open
wants to merge 4 commits into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
telehash.xcodeproj/project.xcworkspace/xcshareddata/

#####
# CocoaPods installed Pods directory
# This one is debatable, as many prefer to have Pods cached for non-CocoaPods users
#
# Discussion: http://stackoverflow.com/questions/9446644/what-goes-into-your-gitignore-if-youre-using-cocoapods

Pods

#########################
# .gitignore file for Xcode4 and Xcode5 Source projects
#
Expand Down
7 changes: 7 additions & 0 deletions Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Uncomment this line to define a global platform for your project
platform :ios, '7.0'

pod 'libsodium', '~> 1.0'



6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ Using as a standalone library
-----------------------------

See the sub-project thFieldTest for an example of using the library.

To install the pre-requisite libsodium, simply type the following CocoaPods command:

pod install --no-integrate

NB: --no-integrate avoids CocoaPods generating an xcodeworkspace for this project.
42 changes: 14 additions & 28 deletions Telehash Playground/Telehash Playground/Base.lproj/MainMenu.xib

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Telehash Playground/Telehash Playground/THAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import <THMesh.h>
#import <E3XChannel.h>

@interface THAppDelegate : NSObject <THSwitchDelegate, THChannelDelegate, NSTableViewDataSource, NSTableViewDelegate> {
@interface THAppDelegate : NSObject <THMeshDelegate, E3XChannelDelegate, NSTableViewDataSource, NSTableViewDelegate> {
IBOutlet NSTableView* tableView;
IBOutlet NSTextField* hashnameField;
IBOutlet NSTextField* addressField;
Expand All @@ -25,7 +25,7 @@
@property NSString* identityPath;
@property (assign) IBOutlet NSWindow *window;

-(void)channelReady:(E3XChannel *)channel type:(THChannelType)type firstPacket:(THPacket *)packet;
-(void)channelReady:(E3XChannel *)channel type:(E3XChannelType)type firstPacket:(THPacket *)packet;
-(BOOL)channel:(E3XChannel*)channel handlePacket:(THPacket *)packet;

-(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView;
Expand Down
10 changes: 5 additions & 5 deletions Telehash Playground/Telehash Playground/THAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ -(void)openedLine:(E3XExchange *)line;
[tableView reloadData];
}

-(void)channelReady:(E3XChannel *)channel type:(THChannelType)type firstPacket:(THPacket *)packet;
-(void)channelReady:(E3XChannel *)channel type:(E3XChannelType)type firstPacket:(THPacket *)packet;
{
NSLog(@"Channel is ready");
NSLog(@"First packet is %@", packet.json);
Expand All @@ -147,7 +147,7 @@ -(IBAction)connectToHashname:(id)sender
if (key.length > 0) {
/*
NSData* keyData = [[NSData alloc] initWithBase64EncodedString:key options:0];
connectToIdentity = [THIdentity identityFromPublicKey:keyData];
connectToIdentity = [THLink identityFromPublicKey:keyData];
NSString* address = [addressField stringValue];
NSInteger port = [portField integerValue];
if (address && port > 0) {
Expand All @@ -164,17 +164,17 @@ -(IBAction)connectToHashname:(id)sender
}
}

-(void)thSwitch:(THMesh *)inSwitch status:(THSwitchStatus)status
-(void)thSwitch:(THMesh *)inSwitch status:(THMeshStatus)status
{
NSLog(@"Switch status is now %d", status);
if (status == THSwitchOnline && !pingChannel) {
if (status == THMeshOnline && !pingChannel) {
#if 0
if (![inSwitch.identity.hashname isEqualToString:@"ee5dc2630603638dfb980cbe7062378bdc70091947d9fa6dac5cf9b072296aad"]) {

THPacket* pingPacket = [THPacket new];
[pingPacket.json setObject:@"ping" forKey:@"type"];

pingChannel = [[THReliableChannel alloc] initToIdentity:[THIdentity identityFromHashname:@"ee5dc2630603638dfb980cbe7062378bdc70091947d9fa6dac5cf9b072296aad"]];
pingChannel = [[THReliableChannel alloc] initToIdentity:[THLink identityFromHashname:@"ee5dc2630603638dfb980cbe7062378bdc70091947d9fa6dac5cf9b072296aad"]];
pingChannel.delegate = self;

[inSwitch openChannel:pingChannel firstPacket:pingPacket];
Expand Down
30 changes: 15 additions & 15 deletions common/E3XChannel.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// THChannel.h
// E3XChannel.h
// telehash
//
// Created by Thomas Muldowney on 10/5/13.
Expand All @@ -17,21 +17,21 @@
@class THPacketBuffer;

typedef enum {
THChannelOpening,
THChannelOpen,
THChannelPaused,
THChannelEnded,
THChannelErrored
} THChannelState;
E3XChannelOpening,
E3XChannelOpen,
E3XChannelPaused,
E3XChannelEnded,
E3XChannelErrored
} E3XChannelState;

typedef enum {
THChannelInbound,
THChannelOutbound
} THChannelDirection;
E3XChannelInbound,
E3XChannelOutbound
} E3XChannelDirection;

@protocol THChannelDelegate <NSObject>
@protocol E3XChannelDelegate <NSObject>
#pragma mark State Handling
-(void)channel:(E3XChannel*)channel didChangeStateTo:(THChannelState)channelState;
-(void)channel:(E3XChannel*)channel didChangeStateTo:(E3XChannelState)channelState;
#pragma mark Error Handling
-(void)channel:(E3XChannel*)channel didFailWithError:(NSError*)error;
-(BOOL)channel:(E3XChannel*)channel handlePacket:(THPacket*)packet;
Expand All @@ -41,12 +41,12 @@ typedef enum {

@property NSNumber* maxSeen;
@property NSArray* missing;
@property (nonatomic, strong) id<THChannelDelegate> delegate;
@property (nonatomic, strong) id<E3XChannelDelegate> delegate;
@property THLink* toIdentity;
@property E3XExchange* line;
@property NSNumber* channelId;
@property THChannelState state;
@property THChannelDirection direction;
@property E3XChannelState state;
@property E3XChannelDirection direction;
@property NSString* type;
@property NSUInteger createdAt;
@property NSUInteger lastInActivity;
Expand Down
22 changes: 11 additions & 11 deletions common/E3XChannel.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// THChannel.m
// E3XChannel.m
// telehash
//
// Created by Thomas Muldowney on 10/5/13.
Expand All @@ -19,15 +19,15 @@

@implementation E3XChannel
{
THChannelState _state;
E3XChannelState _state;
}

-(id)initToIdentity:(THLink*)identity
{
self = [super init];
if (self) {
_state = THChannelOpening;
self.direction = THChannelOutbound;
_state = E3XChannelOpening;
self.direction = E3XChannelOutbound;
self.toIdentity = identity;
self.channelId = 0; // We'll just go ahead and make one
self.createdAt = time(NULL);
Expand All @@ -39,12 +39,12 @@ -(id)initToIdentity:(THLink*)identity
return self;
}

-(THChannelState)state
-(E3XChannelState)state
{
return _state;
}

-(void)setState:(THChannelState)state
-(void)setState:(E3XChannelState)state
{
_state = state;
if ([self.delegate respondsToSelector:@selector(channel:didChangeStateTo:)]) {
Expand All @@ -54,9 +54,9 @@ -(void)setState:(THChannelState)state

-(void)sendPacket:(THPacket *)packet;
{
if (self.state == THChannelEnded) {
if (self.state == E3XChannelEnded) {
// XXX Error that we're trying to send on an ended channel
} else if (self.state == THChannelErrored) {
} else if (self.state == E3XChannelErrored) {
// XXX Error that we're trying to send on an errored channel
}

Expand All @@ -72,7 +72,7 @@ -(void)handlePacket:(THPacket *)packet;
NSString* err = [packet.json objectForKey:@"err"];
if (err) {
[self.delegate channel:self didFailWithError:[NSError errorWithDomain:@"telehash" code:100 userInfo:@{NSLocalizedDescriptionKey:err}]];
self.state = THChannelErrored;
self.state = E3XChannelErrored;
[self.toIdentity.channels removeObjectForKey:self.channelId];
}
}
Expand All @@ -81,11 +81,11 @@ -(void)close
{
if (!self.channelId) return;

if (self.state != THChannelOpening && self.state != THChannelEnded) {
if (self.state != E3XChannelOpening && self.state != E3XChannelEnded) {
THPacket* endPacket = [THPacket new];
[endPacket.json setObject:@YES forKey:@"end"];
[self sendPacket:endPacket];
self.state = THChannelEnded;
self.state = E3XChannelEnded;
}

[self.toIdentity.channels removeObjectForKey:self.channelId];
Expand Down
4 changes: 2 additions & 2 deletions common/E3XCipherSet.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// THCipherSet.h
// E3XCipherSet.h
// telehash
//
// Created by Thomas Muldowney on 2/27/14.
Expand All @@ -24,7 +24,7 @@
-(NSString*)identifier;
@end

@interface THCipherSetLineInfo : NSObject
@interface E3XCipherSetLineInfo : NSObject
@property E3XCipherSet* cipherSet;
-(NSData*)encryptLinePacket:(THPacket*)packet;
-(void)decryptLinePacket:(THPacket*)packet;
Expand Down
10 changes: 5 additions & 5 deletions common/E3XCipherSet.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// THCipherSet.m
// E3XCipherSet.m
// telehash
//
// Created by Thomas Muldowney on 2/27/14.
Expand Down Expand Up @@ -42,20 +42,20 @@ -(NSString*)identifier

-(void)finalizeLineKeys:(E3XExchange *)line
{
CLCLogError(@"Not implemented THCipherSet finalizeKeys");
CLCLogError(@"Not implemented E3XCipherSet finalizeKeys");
}
@end

@implementation THCipherSetLineInfo
@implementation E3XCipherSetLineInfo
-(NSData*)encryptLinePacket:(THPacket*)packet
{
CLCLogError(@"Not implemented THCipherSetLineInfo encryptLinePacket:");
CLCLogError(@"Not implemented E3XCipherSetLineInfo encryptLinePacket:");
return nil;
}

-(void)decryptLinePacket:(THPacket *)packet
{
CLCLogError(@"Not implemented THCipherSetLineInfo decryptLinePacket:");
CLCLogError(@"Not implemented E3XCipherSetLineInfo decryptLinePacket:");
}
@end

Expand Down
4 changes: 2 additions & 2 deletions common/E3XCipherSet2a.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// THCipherSet2a.h
// E3XCipherSet2a.h
// telehash
//
// Created by Thomas Muldowney on 4/21/14.
Expand All @@ -21,7 +21,7 @@
-(THPacket*)generateOpen:(E3XExchange*)line from:(THLink*)fromIdentity;
@end

@interface THCipherSetLineInfo2a : THCipherSetLineInfo
@interface E3XCipherSetLineInfo2a : E3XCipherSetLineInfo
@property ECDH* ecdh;
@property NSData* remoteECCKey;
@property NSData* encryptorKey;
Expand Down
14 changes: 7 additions & 7 deletions common/E3XCipherSet2a.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// THCipherSet2a.m
// E3XCipherSet2a.m
// telehash
//
// Created by Thomas Muldowney on 4/21/14.
Expand All @@ -26,7 +26,7 @@
static unsigned char csId2a[] = {0x2a};
static unsigned char eccHeader[] = {0x04};

@implementation THCipherSetLineInfo2a
@implementation E3XCipherSetLineInfo2a
-(NSData*)encryptLinePacket:(THPacket*)packet iv:(NSData*)iv
{
// So broken...
Expand Down Expand Up @@ -166,7 +166,7 @@ -(E3XExchange*)processOpen:(THPacket *)openPacket

if (newLine) {
// This is a partially opened line
THCipherSetLineInfo2a* lineInfo = (THCipherSetLineInfo2a*)newLine.cipherSetInfo;
E3XCipherSetLineInfo2a* lineInfo = (E3XCipherSetLineInfo2a*)newLine.cipherSetInfo;
lineInfo.remoteECCKey = prefixedRemoteEccKey;

// TODO temas review
Expand All @@ -176,7 +176,7 @@ -(E3XExchange*)processOpen:(THPacket *)openPacket
newLine.toIdentity = senderIdentity;
senderIdentity.currentLine = newLine;

THCipherSetLineInfo2a* lineInfo = [THCipherSetLineInfo2a new];
E3XCipherSetLineInfo2a* lineInfo = [E3XCipherSetLineInfo2a new];
lineInfo.cipherSet = incomingCS;
lineInfo.remoteECCKey = prefixedRemoteEccKey;

Expand All @@ -189,7 +189,7 @@ -(E3XExchange*)processOpen:(THPacket *)openPacket

-(void)finalizeLineKeys:(E3XExchange*)line
{
THCipherSetLineInfo2a* lineInfo = (THCipherSetLineInfo2a*)line.cipherSetInfo;
E3XCipherSetLineInfo2a* lineInfo = (E3XCipherSetLineInfo2a*)line.cipherSetInfo;
// Make sure we have a valid ECDH context
if (!lineInfo.ecdh) {
lineInfo.ecdh = [ECDH new];
Expand All @@ -216,11 +216,11 @@ -(THPacket*)generateOpen:(E3XExchange*)line from:(THLink*)fromIdentity
{
if (!line.cipherSetInfo) {
// FIXME, should be the remote cipherSet
THCipherSetLineInfo2a* lineInfo =[THCipherSetLineInfo2a new];
E3XCipherSetLineInfo2a* lineInfo =[E3XCipherSetLineInfo2a new];
lineInfo.cipherSet = [line.toIdentity.cipherParts objectForKey:[self identifier]];
line.cipherSetInfo = lineInfo;
}
THCipherSetLineInfo2a* lineInfo = (THCipherSetLineInfo2a*)line.cipherSetInfo;
E3XCipherSetLineInfo2a* lineInfo = (E3XCipherSetLineInfo2a*)line.cipherSetInfo;
E3XCipherSet2a* remoteCS = (E3XCipherSet2a*)lineInfo.cipherSet;

THPacket* openPacket = [THPacket new];
Expand Down
4 changes: 2 additions & 2 deletions common/E3XCipherSet3a.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// THCipherSet3a.h
// E3XCipherSet3a.h
// telehash
//
// Created by Thomas Muldowney on 4/21/14.
Expand All @@ -19,7 +19,7 @@
-(void)savePublicKeyPath:(NSString*)publicKeyPath privateKeyPath:(NSString*)privateKeyPath;
@end

@interface THCipherSetLineInfo3a : THCipherSetLineInfo
@interface E3XCipherSetLineInfo3a : E3XCipherSetLineInfo
@property (readonly) NSMutableData* publicLineKey;
@property (readonly) NSMutableData* secretLineKey;
@property NSData* remoteLineKey;
Expand Down
Loading