aboutsummaryrefslogtreecommitdiff
path: root/xcode/OLMKit
diff options
context:
space:
mode:
Diffstat (limited to 'xcode/OLMKit')
-rw-r--r--xcode/OLMKit/Info.plist26
-rw-r--r--xcode/OLMKit/OLMAccount.h37
-rw-r--r--xcode/OLMKit/OLMAccount.m116
-rw-r--r--xcode/OLMKit/OLMAccount_Private.h15
-rw-r--r--xcode/OLMKit/OLMKit.h23
-rw-r--r--xcode/OLMKit/OLMMessage.h24
-rw-r--r--xcode/OLMKit/OLMMessage.m13
-rw-r--r--xcode/OLMKit/OLMSerializable.h19
-rw-r--r--xcode/OLMKit/OLMSession.h29
-rw-r--r--xcode/OLMKit/OLMSession.m30
-rw-r--r--xcode/OLMKit/OLMUtility.h15
-rw-r--r--xcode/OLMKit/OLMUtility.m28
12 files changed, 375 insertions, 0 deletions
diff --git a/xcode/OLMKit/Info.plist b/xcode/OLMKit/Info.plist
new file mode 100644
index 0000000..d3de8ee
--- /dev/null
+++ b/xcode/OLMKit/Info.plist
@@ -0,0 +1,26 @@
+<?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>
diff --git a/xcode/OLMKit/OLMAccount.h b/xcode/OLMKit/OLMAccount.h
new file mode 100644
index 0000000..cfa7129
--- /dev/null
+++ b/xcode/OLMKit/OLMAccount.h
@@ -0,0 +1,37 @@
+//
+// 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
diff --git a/xcode/OLMKit/OLMAccount.m b/xcode/OLMKit/OLMAccount.m
new file mode 100644
index 0000000..58dd4ad
--- /dev/null
+++ b/xcode/OLMKit/OLMAccount.m
@@ -0,0 +1,116 @@
+//
+// 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
diff --git a/xcode/OLMKit/OLMAccount_Private.h b/xcode/OLMKit/OLMAccount_Private.h
new file mode 100644
index 0000000..4eb3e2b
--- /dev/null
+++ b/xcode/OLMKit/OLMAccount_Private.h
@@ -0,0 +1,15 @@
+//
+// 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
diff --git a/xcode/OLMKit/OLMKit.h b/xcode/OLMKit/OLMKit.h
new file mode 100644
index 0000000..745af43
--- /dev/null
+++ b/xcode/OLMKit/OLMKit.h
@@ -0,0 +1,23 @@
+//
+// 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
diff --git a/xcode/OLMKit/OLMMessage.h b/xcode/OLMKit/OLMMessage.h
new file mode 100644
index 0000000..2b747fb
--- /dev/null
+++ b/xcode/OLMKit/OLMMessage.h
@@ -0,0 +1,24 @@
+//
+// 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
diff --git a/xcode/OLMKit/OLMMessage.m b/xcode/OLMKit/OLMMessage.m
new file mode 100644
index 0000000..ce732ec
--- /dev/null
+++ b/xcode/OLMKit/OLMMessage.m
@@ -0,0 +1,13 @@
+//
+// OLMMessage.m
+// olm
+//
+// Created by Chris Ballinger on 4/8/16.
+//
+//
+
+#import "OLMMessage.h"
+
+@implementation OLMMessage
+
+@end
diff --git a/xcode/OLMKit/OLMSerializable.h b/xcode/OLMKit/OLMSerializable.h
new file mode 100644
index 0000000..afacdaa
--- /dev/null
+++ b/xcode/OLMKit/OLMSerializable.h
@@ -0,0 +1,19 @@
+//
+// 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
diff --git a/xcode/OLMKit/OLMSession.h b/xcode/OLMKit/OLMSession.h
new file mode 100644
index 0000000..196900f
--- /dev/null
+++ b/xcode/OLMKit/OLMSession.h
@@ -0,0 +1,29 @@
+//
+// 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
diff --git a/xcode/OLMKit/OLMSession.m b/xcode/OLMKit/OLMSession.m
new file mode 100644
index 0000000..24a8b36
--- /dev/null
+++ b/xcode/OLMKit/OLMSession.m
@@ -0,0 +1,30 @@
+//
+// 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
diff --git a/xcode/OLMKit/OLMUtility.h b/xcode/OLMKit/OLMUtility.h
new file mode 100644
index 0000000..0de9725
--- /dev/null
+++ b/xcode/OLMKit/OLMUtility.h
@@ -0,0 +1,15 @@
+//
+// OLMUtility.h
+// olm
+//
+// Created by Chris Ballinger on 4/8/16.
+//
+//
+
+#import <Foundation/Foundation.h>
+
+@interface OLMUtility : NSObject
+
++ (NSData*) randomBytesOfLength:(NSUInteger)length;
+
+@end
diff --git a/xcode/OLMKit/OLMUtility.m b/xcode/OLMKit/OLMUtility.m
new file mode 100644
index 0000000..0148932
--- /dev/null
+++ b/xcode/OLMKit/OLMUtility.m
@@ -0,0 +1,28 @@
+//
+// 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