Commit 719eb543 authored by Chris Ballinger's avatar Chris Ballinger
Browse files

Xcode, podspec, wrapper

parent 989056e0
build
.DS_Store
build
*.mode1v3
*.pbxuser
project.xcworkspace
xcuserdata
.svn
DerivedData
*.orig
*.xccheckout
xcode/Pods/
......@@ -25,9 +25,9 @@ extern "C" {
static const size_t OLM_MESSAGE_TYPE_PRE_KEY = 0;
static const size_t OLM_MESSAGE_TYPE_MESSAGE = 1;
struct OlmAccount;
struct OlmSession;
struct OlmUtility;
typedef struct OlmAccount OlmAccount;
typedef struct OlmSession OlmSession;
typedef struct OlmUtility OlmUtility;
/** The size of an account object in bytes */
size_t olm_account_size();
......@@ -51,7 +51,7 @@ OlmSession * olm_session(
);
/** Initialise a utility object using the supplied memory
* The supplied memory must be at least olm_session_size() bytes */
* The supplied memory must be at least olm_utility_size() bytes */
OlmUtility * olm_utility(
void * memory
);
......
......@@ -22,4 +22,4 @@ Example:
bob_session.create_inbound(bob, bob_message);
var plaintext = bob_session.decrypt(message_1.type, bob_message);
bob.remove_one_time_keys(bob_session);
bob.remove_one_time_keys(bob_session);
\ No newline at end of file
#
# Be sure to run `pod spec lint olm.podspec' to ensure this is a
# valid spec and to remove all comments including this before submitting the spec.
#
# To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#
Pod::Spec.new do |s|
# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# These will help people to find your library, and whilst it
# can feel like a chore to fill in it's definitely to your advantage. The
# summary should be tweet-length, and the description more in depth.
#
s.name = "olm"
s.version = "0.1.0"
s.summary = "olm"
# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!
s.description = <<-DESC
DESC
s.homepage = "http://EXAMPLE/olm"
# s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"
# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Licensing your code is important. See http://choosealicense.com for more info.
# CocoaPods will detect a license file if there is a named LICENSE*
# Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
#
s.license = "MIT (example)"
# s.license = { :type => "MIT", :file => "FILE_LICENSE" }
# ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the authors of the library, with email addresses. Email addresses
# of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
# accepts just a name if you'd rather not provide an email address.
#
# Specify a social_media_url where others can refer to, for example a twitter
# profile URL.
#
s.author = { "Chris Ballinger" => "chrisballinger@gmail.com" }
# Or just: s.author = "Chris Ballinger"
# s.authors = { "Chris Ballinger" => "chrisballinger@gmail.com" }
# s.social_media_url = "http://twitter.com/Chris Ballinger"
# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# If this Pod runs only on iOS or OS X, then specify the platform and
# the deployment target. You can optionally include the target after the platform.
#
# s.platform = :ios
# s.platform = :ios, "5.0"
# When using multiple platforms
# s.ios.deployment_target = "5.0"
# s.osx.deployment_target = "10.7"
# s.watchos.deployment_target = "2.0"
# s.tvos.deployment_target = "9.0"
# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the location from where the source should be retrieved.
# Supports git, hg, bzr, svn and HTTP.
#
s.source = { :git => "http://EXAMPLE/olm.git", :tag => "0.0.1" }
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# CocoaPods is smart about how it includes source code. For source files
# giving a folder will include any swift, h, m, mm, c & cpp files.
# For header files it will include any header in the folder.
# Not including the public_header_files will make all headers public.
#
s.source_files = ["include/olm/*.hh","src/*.cpp"]
s.public_header_files = "include/olm/olm.hh"
s.library = "c++"
s.xcconfig = { 'HEADER_SEARCH_PATHS' => '$(PODS_ROOT)/olm/include $(PODS_ROOT)/olm/lib $(PODS_ROOT)/../../include $(PODS_ROOT)/../../lib' }
end
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
//
// OLMAccount.h
// olm
//
// Created by Chris Ballinger on 4/8/16.
//
//
#import <Foundation/Foundation.h>
#import "OLMSerializable.h"
@interface OLMAccount : NSObject <OLMSerializable>
/** Creates new account */
- (instancetype) initNewAccount;
/** public identity keys. base64 encoded in "curve25519" and "ed25519" keys */
- (NSDictionary*) identityKeys;
/** signs message with ed25519 key for account */
- (NSData*) signMessage:(NSData*)messageData;
/** Public parts of the unpublished one time keys for the account */
- (NSDictionary*) oneTimeKeys;
/** Marks the current set of one time keys as being published. */
- (void) markKeysAsPublished;
/** The largest number of one time keys this account can store. */
- (NSUInteger) maxOneTimeKeys;
/** Generates a number of new one time keys. If the total number of keys stored
* by this account exceeds -maxOneTimeKeys then the old keys are
* discarded. */
- (void) generateOneTimeKeys:(NSUInteger)numberOfKeys;
@end
//
// OLMAccount.m
// olm
//
// Created by Chris Ballinger on 4/8/16.
//
//
#import "OLMAccount.h"
#import "OLMAccount_Private.h"
#import "OLMUtility.h"
@import Security;
@implementation OLMAccount
- (void) dealloc {
olm_clear_account(_account);
free(_account);
}
- (BOOL) initializeAccountMemory {
size_t accountSize = olm_account_size();
_account = malloc(accountSize);
NSParameterAssert(_account != nil);
if (!_account) {
return NO;
}
_account = olm_account(_account);
NSParameterAssert(_account != nil);
if (!_account) {
return NO;
}
return YES;
}
- (instancetype) initNewAccount {
self = [super init];
if (!self) {
return nil;
}
BOOL success = [self initializeAccountMemory];
if (!success) {
return nil;
}
size_t randomLength = olm_create_account_random_length(_account);
size_t accountResult = olm_create_account(_account, (void*)[OLMUtility randomBytesOfLength:randomLength].bytes, randomLength);
if (accountResult == olm_error()) {
const char *error = olm_account_last_error(_account);
NSLog(@"error creating account: %s", error);
return nil;
}
return self;
}
- (size_t) maxOneTimeKeys {
return olm_account_max_number_of_one_time_keys(_account);
}
/** public identity keys */
- (NSDictionary*) identityKeys {
size_t identityKeysLength = olm_account_identity_keys_length(_account);
uint8_t *identityKeysBytes = malloc(identityKeysLength);
if (!identityKeysBytes) {
return nil;
}
size_t result = olm_account_identity_keys(_account, identityKeysBytes, identityKeysLength);
if (result == olm_error()) {
const char *error = olm_account_last_error(_account);
NSLog(@"error getting id keys: %s", error);
free(identityKeysBytes);
return nil;
}
NSData *idKeyData = [NSData dataWithBytesNoCopy:identityKeysBytes length:identityKeysLength freeWhenDone:YES];
NSError *error = nil;
NSDictionary *keysDictionary = [NSJSONSerialization JSONObjectWithData:idKeyData options:0 error:&error];
if (error) {
NSLog(@"Could not decode JSON: %@", error.localizedDescription);
}
return keysDictionary;
}
- (NSDictionary*) oneTimeKeys {
size_t otkLength = olm_account_one_time_keys_length(_account);
uint8_t *otkBytes = malloc(otkLength);
if (!otkBytes) {
return nil;
}
size_t result = olm_account_one_time_keys(_account, otkBytes, otkLength);
if (result == olm_error()) {
const char *error = olm_account_last_error(_account);
NSLog(@"error getting id keys: %s", error);
free(otkBytes);
}
NSData *otk = [NSData dataWithBytesNoCopy:otkBytes length:otkLength freeWhenDone:YES];
NSError *error = nil;
NSDictionary *keysDictionary = [NSJSONSerialization JSONObjectWithData:otk options:0 error:&error];
if (error) {
NSLog(@"Could not decode JSON: %@", error.localizedDescription);
}
return keysDictionary;
}
- (void) generateOneTimeKeys:(NSUInteger)numberOfKeys {
size_t randomLength = olm_account_generate_one_time_keys_random_length(_account, numberOfKeys);
size_t result = olm_account_generate_one_time_keys(_account, numberOfKeys, (void*)[OLMUtility randomBytesOfLength:randomLength].bytes, randomLength);
if (result == olm_error()) {
const char *error = olm_account_last_error(_account);
NSLog(@"error generating keys: %s", error);
}
}
@end
//
// OLMAccount_Private.h
// olm
//
// Created by Chris Ballinger on 4/8/16.
//
//
@import olm;
@interface OLMAccount()
@property (nonatomic) OlmAccount *account;
@end
\ No newline at end of file
//
// OLMKit.h
// OLMKit
//
// Created by Chris Ballinger on 4/8/16.
//
//
#import <UIKit/UIKit.h>
//! Project version number for OLMKit.
FOUNDATION_EXPORT double OLMKitVersionNumber;
//! Project version string for OLMKit.
FOUNDATION_EXPORT const unsigned char OLMKitVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <OLMKit/PublicHeader.h>
#import "OLMAccount.h"
#import "OLMSession.h"
#import "OLMMessage.h"
#import "OLMUtility.h"
\ No newline at end of file
//
// OLMMessage.h
// olm
//
// Created by Chris Ballinger on 4/8/16.
//
//
#import <Foundation/Foundation.h>
typedef NS_ENUM(NSUInteger, OLMMessageType) {
OLMMessageTypeUnknown,
OLMMessageTypePreKey,
OLMMessageTypeMessage
};
@interface OLMMessage : NSObject
@property (nonatomic, readonly, nonnull) NSString *message;
@property (readonly) OLMMessageType type;
- (nonnull instancetype) initWithMessage:(nonnull NSString*)message type:(OLMMessageType)type;
@end
//
// OLMMessage.m
// olm
//
// Created by Chris Ballinger on 4/8/16.
//
//
#import "OLMMessage.h"
@implementation OLMMessage
@end
//
// OLMSerializable.h
// olm
//
// Created by Chris Ballinger on 4/8/16.
//
//
#import <Foundation/Foundation.h>
@protocol OLMSerializable <NSObject>
/** Initializes from encrypted serialized data. Will throw error if invalid key or invalid base64. */
- (instancetype) initWithSerializedData:(NSData*)serializedData key:(NSData*)key error:(NSError**)error;
/** Serializes and encrypts object data */
- (NSData*) serializeDataWithKey:(NSData*)key;
@end
//
// OLMSession.h
// olm
//
// Created by Chris Ballinger on 4/8/16.
//
//
#import <Foundation/Foundation.h>
#import "OLMSerializable.h"
#import "OLMAccount.h"
@interface OLMSession : NSObject <OLMSerializable>
- (instancetype) initOutboundSessionWithAccount:(OLMAccount*)account theirIdentityKey:(NSData*)theirIdentityKey theirOneTimeKey:(NSData*)theirOneTimeKey;
- (instancetype) initInboundSessionWithAccount:(OLMAccount*)account oneTimeKeyMessage:(NSData*)oneTimeKeyMessage;
- (instancetype) initInboundSessionWithAccount:(OLMAccount*)account theirIdentityKey:(NSData*)theirIdentityKey oneTimeKeyMessage:(NSData*)oneTimeKeyMessage;
- (NSData*) sessionIdentifier;
- (BOOL) matchesInboundSession:(NSData*)oneTimeKeyMessage;
- (BOOL) matchesInboundSessionFrom:(NSData*)theirIdentityKey oneTimeKeyMessage:(NSData *)oneTimeKeyMessage;
- (void) removeOneTimeKeys;
@end
//
// OLMSession.m
// olm
//
// Created by Chris Ballinger on 4/8/16.
//
//
#import "OLMSession.h"
@import olm;
@interface OLMSession()
@property (nonatomic) OlmSession *session;
@end
@implementation OLMSession
- (instancetype) initOutboundSessionWithAccount:(OLMAccount*)account theirIdentityKey:(NSData*)theirIdentityKey theirOneTimeKey:(NSData*)theirOneTimeKey {
}
- (instancetype) initInboundSessionWithAccount:(OLMAccount*)account oneTimeKeyMessage:(NSData*)oneTimeKeyMessage {
}
- (instancetype) initInboundSessionWithAccount:(OLMAccount*)account theirIdentityKey:(NSData*)theirIdentityKey oneTimeKeyMessage:(NSData*)oneTimeKeyMessage {
}
@end
//
// OLMUtility.h
// olm
//
// Created by Chris Ballinger on 4/8/16.
//
//
#import <Foundation/Foundation.h>
@interface OLMUtility : NSObject
+ (NSData*) randomBytesOfLength:(NSUInteger)length;
@end
//
// OLMUtility.m
// olm
//
// Created by Chris Ballinger on 4/8/16.
//
//
#import "OLMUtility.h"
@implementation OLMUtility
+ (NSData*) randomBytesOfLength:(NSUInteger)length {
uint8_t *randomBytes = malloc(length * sizeof(uint8_t));
NSParameterAssert(randomBytes != NULL);
if (!randomBytes) {
return nil;
}
int result = SecRandomCopyBytes(kSecRandomDefault, length, randomBytes);
if (result != 0) {
free(randomBytes);
return nil;
}
NSData *data = [NSData dataWithBytesNoCopy:randomBytes length:length freeWhenDone:YES];
return data;
}
@end
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
//
// OLMKitTests.m
// OLMKitTests
//
// Created by Chris Ballinger on 4/8/16.
//
//
#import <XCTest/XCTest.h>
@import OLMKit;
@interface OLMKitTests : XCTestCase
@end
@implementation OLMKitTests
- (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)testExample {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
OLMAccount *alice = [[OLMAccount alloc] initNewAccount];
OLMAccount *bob = [[OLMAccount alloc] initNewAccount];
[bob generateOneTimeKeys:5];
NSDictionary *identityKeys = bob.identityKeys;
NSDictionary *oneTimeKeys = bob.oneTimeKeys;
NSParameterAssert(identityKeys != nil);
NSParameterAssert(oneTimeKeys != nil);
}
@end
# Uncomment this line to define a global platform for your project
platform :ios, '8.0'
# Uncomment this line if you're using Swift
use_frameworks!
pod 'olm', :path => '../olm.podspec'
\ No newline at end of file
PODS:
- olm (0.1.0)
DEPENDENCIES:
- olm (from `../olm.podspec`)
EXTERNAL SOURCES:
olm:
:path: "../olm.podspec"
SPEC CHECKSUMS:
olm: ba8c1a7ca04486ec1ad958ec9feef73c0939ae27