Skip to content
A noise protocol framework implementation in Objective-C and Swift friendly.
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Carthage Added OuterCorner/OpenSSL as a Carthage dependency. Oct 17, 2018
Compat Using a single target for both macOS and iOS Oct 18, 2018
Config Version is now 0.9.5 (190114.0) Jan 14, 2019
Dependencies Using a single target for both macOS and iOS Oct 18, 2018
EchoTests Now running tests in all supported platforms (echo tests moved to a d… Oct 19, 2018
Noise-C Not buffering stdout on echo-client to help with testing Sep 25, 2018
Noise.xcodeproj Distinguishing between reading an EOF and an actual logic error Jan 22, 2019
Noise Distinguishing between reading an EOF and an actual logic error Jan 22, 2019
NoiseTests Distinguishing between reading an EOF and an actual logic error Jan 22, 2019
Cartfile Added OuterCorner/OpenSSL as a Carthage dependency. Oct 17, 2018
Cartfile.resolved Added OuterCorner/OpenSSL as a Carthage dependency. Oct 17, 2018
LICENSE
README.md Fixed copy/paste typo Nov 13, 2018

README.md

Noise.framework

Platforms Carthage License

This project provides an macOS and iOS compatible framework to develop protocol based on the Noise Protocol Framework. It wraps the noise-c library in an easy to use object-oriented fashion.

It's written in Objective-C and is Swift friendly.

Installation

You have a few different options:

Manual installation

  • Include the Noise.xcodeproj as a dependency in your project.
  • Use a pre-built Noise.framework. You can find them under Releases.

In either case you'll also need to add the OpenSSL.framework dependency.

Carthage

Add Noise as a dependency on your Cartfile:

github "OuterCorner/Noise"

And run:

carthage update

By default Carthage will download the pre-build binaries (faster), if you want to compile from source pass --no-use-binaries to the update command above.

Usage

The public headers are extensively documented and should be fairly easy to grasp. Here's a quick overview on how to use the framework.

Start by importing the umbrella header:

// Objective-C
#import <Noise/Noise.h>
// Swift
import Noise

Noise session

The NPFSession class is central to the framework. You start by creating a session with the noise protocol you want to use:

// Objective-C
NPFSession *session = [[NPFSession alloc] initWithProtocolName:@"Noise_NK_25519_AESGCM_SHA256" role:NPFSessionRoleInitiator];
// Swift
let session = NoiseSession(protocolName: "Noise_NK_25519_AESGCM_SHA256", role: .initiator)

After that you must call setup before starting a session, even if you're using an NN handshake pattern where no setup is required:

// Objective-C
[session setup:^(id<NPFSessionSetup> setup) {
  NPFKey *pubKey = [keyManager remotePublicKeyFor:@"some responder" ofType:NPFKeyAlgoCurve25519];
  setup.remotePublicKey = pubKey;
}];
// Swift
session.setup { setup in
  let pubKey = keyManager.remotePublicKey(for: "some responder", type: .curve25519);
  setup.remotePublicKey = pubKey
}

You're now ready to start the session:

// Objective-C
NSError *error = nil;
if (![session start:&error]){
  // handle error
}
// Swift
try session.start()

After starting a session, both the sendingHandle and receivingHandle properties are ready to be bound to your transport channel. You must read from sendingHandle and send any data to your peer, be it via TCP, Unix sockets, smoke signals… Conversely any data you receive from your peer you should write to receivingHandle.

Since these are NSFileHandles you can install a readability handler to run everytime the session has data to send:

// Objective-C
session.sendingHandle.readabilityHandler = ^(NSFileHandle * fh) {
  NSData *data = [fh availableData];
  // write data to your transport channel
}
// Swift
session.sendingHandle!.readabilityHandler = { fh in
  let data = fh.availableData
  // write data to your transport channel
}

Handshake

When starting a session the first step is to perform the chosen handshake. You can either implement the delegate method -session:handshakeComplete: or observe the session s state to know when the handshake is complete.

If you're using a handshake pattern where you don't know the peer's public key beforehand, you can consult the NPFHandshakeState object passed to the delegate on handshake completion.

// Objective-C
- (void)session:(NPFSession *)session handshakeComplete:(NPFHandshakeState *)handshakeState
{
    NPFKey *remotePubKey = [handshakeState remotePublicKey]
    // do something with remotePubKey
}
// Swift
func session(_ session: NoiseSession, handshakeComplete handshakeState: NoiseHandshakeState) {
  let remotePubKey = handshakeState.remotePublicKey
  // do something with remotePubKey
}

Send and receiving messages

After the handshake is complete you can send messages via the -sendData: method and receive via the -session:didReceiveData: delegate method.

Dependencies

This projects depends on OpenSSL.framework. If you're using Carthage it will be downloaded automatically.

License

This project is licensed under the MIT License - see LICENSE.

You can’t perform that action at this time.