Put public kit headers to own dir for SPM

SPM expects the public headers dir to only have a single
directory. Which is why we can't use "xcode" as the pubdir
header.
We also can't use OLMKit as the dir, because then imports
will fail due to "<OLMKit/" not being available.
This commit is contained in:
Helge Heß 2020-04-10 18:55:37 +02:00
parent a22cffdd29
commit dc1b0d9c54
14 changed files with 584 additions and 1 deletions

View file

@ -37,7 +37,7 @@ let package = Package(
path: "xcode", path: "xcode",
exclude: [ "OLMKit/Info.plist" ], exclude: [ "OLMKit/Info.plist" ],
sources: [ "OLMKit" ], sources: [ "OLMKit" ],
publicHeadersPath: "OLMKit", publicHeadersPath: "PublicHeaders",
cSettings: [ cSettings: [
.headerSearchPath("."), .headerSearchPath("."),
.unsafeFlags([ .unsafeFlags([

View file

@ -0,0 +1,51 @@
/*
Copyright 2016 Chris Ballinger
Copyright 2016 OpenMarket Ltd
Copyright 2016 Vector Creations Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import <Foundation/Foundation.h>
#import "OLMSerializable.h"
@class OLMSession;
@interface OLMAccount : NSObject <OLMSerializable, NSSecureCoding>
/** Creates new account */
- (instancetype) initNewAccount;
/** public identity keys. base64 encoded in "curve25519" and "ed25519" keys */
- (NSDictionary*) identityKeys;
/** signs message with ed25519 key for account */
- (NSString*) signMessage:(NSData*)messageData;
/** Public parts of the unpublished one time keys for the account */
- (NSDictionary*) oneTimeKeys;
- (BOOL) removeOneTimeKeysForSession:(OLMSession*)session;
/** Marks the current set of one time keys as being published. */
- (void) markOneTimeKeysAsPublished;
/** 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

View file

@ -0,0 +1,38 @@
/*
Copyright 2016 OpenMarket Ltd
Copyright 2016 Vector Creations Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import <Foundation/Foundation.h>
#import "OLMSerializable.h"
@interface OLMInboundGroupSession : NSObject <OLMSerializable, NSSecureCoding>
- (instancetype)initInboundGroupSessionWithSessionKey:(NSString*)sessionKey error:(NSError**)error;
- (instancetype)initInboundGroupSessionWithImportedSession:(NSString*)sessionKey error:(NSError**)error;
- (NSString*)sessionIdentifier;
/** base64 ciphertext -> UTF-8 plaintext */
- (NSString*)decryptMessage:(NSString*)message messageIndex:(NSUInteger*)messageIndex error:(NSError**)error;
- (NSUInteger)firstKnownIndex;
- (BOOL)isVerified;
- (NSString*)exportSessionAtMessageIndex:(NSUInteger)messageIndex error:(NSError**)error;
@end

View file

@ -0,0 +1,39 @@
/*
Copyright 2016 Chris Ballinger
Copyright 2016 OpenMarket Ltd
Copyright 2016 Vector Creations Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import <Foundation/Foundation.h>
// In this header, you should import all the public headers of your framework using statements like #import <OLMKit/PublicHeader.h>
#import <OLMKit/OLMAccount.h>
#import <OLMKit/OLMSession.h>
#import <OLMKit/OLMMessage.h>
#import <OLMKit/OLMUtility.h>
#import <OLMKit/OLMInboundGroupSession.h>
#import <OLMKit/OLMOutboundGroupSession.h>
#import <OLMKit/OLMPkEncryption.h>
#import <OLMKit/OLMPkDecryption.h>
#import <OLMKit/OLMPkSigning.h>
#import <OLMKit/OLMSAS.h>
@interface OLMKit : NSObject
//! Project version string for OLMKit, the same as libolm.
+ (NSString*)versionString;
@end

View file

@ -0,0 +1,38 @@
/*
Copyright 2016 Chris Ballinger
Copyright 2016 OpenMarket Ltd
Copyright 2016 Vector Creations Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import <Foundation/Foundation.h>
/*
from olm.hh
static const size_t OLM_MESSAGE_TYPE_PRE_KEY = 0;
static const size_t OLM_MESSAGE_TYPE_MESSAGE = 1;
*/
typedef NS_ENUM(NSInteger, OLMMessageType) {
OLMMessageTypePreKey = 0,
OLMMessageTypeMessage = 1
};
@interface OLMMessage : NSObject
@property (nonatomic, copy, readonly, nonnull) NSString *ciphertext;
@property (readonly) OLMMessageType type;
- (nullable instancetype) initWithCiphertext:(nonnull NSString*)ciphertext type:(OLMMessageType)type;
@end

View file

@ -0,0 +1,32 @@
/*
Copyright 2016 OpenMarket Ltd
Copyright 2016 Vector Creations Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import <Foundation/Foundation.h>
#import "OLMSerializable.h"
@interface OLMOutboundGroupSession : NSObject <OLMSerializable, NSSecureCoding>
- (instancetype) initOutboundGroupSession;
- (NSString*)sessionIdentifier;
- (NSUInteger)messageIndex;
- (NSString*)sessionKey;
/** UTF-8 plaintext -> base64 ciphertext */
- (NSString*)encryptMessage:(NSString*)message error:(NSError**)error;
@end

View file

@ -0,0 +1,71 @@
/*
Copyright 2018 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import <Foundation/Foundation.h>
#import "OLMSerializable.h"
#import "OLMPkMessage.h"
NS_ASSUME_NONNULL_BEGIN
@interface OLMPkDecryption : NSObject <OLMSerializable, NSSecureCoding>
/**
Initialise the key from the private part of a key as returned by `privateKey`.
Note that the pubkey is a base64 encoded string, but the private key is
an unencoded byte array.
@param privateKey the private key part.
@param error the error if any.
@return the associated public key.
*/
- (NSString *)setPrivateKey:(NSData*)privateKey error:(NSError* _Nullable *)error;
/**
Generate a new key to use for decrypting messages.
@param error the error if any.
@return the public part of the generated key.
*/
- (NSString *)generateKey:(NSError* _Nullable *)error;
/**
Get the private key.
@return the private key;
*/
- (NSData *)privateKey;
/**
Decrypt a ciphertext.
@param message the cipher message to decrypt.
@param error the error if any.
@return the decrypted message.
*/
- (NSString *)decryptMessage:(OLMPkMessage*)message error:(NSError* _Nullable *)error;
/**
Private key length.
@return the length in bytes.
*/
+ (NSUInteger)privateKeyLength;
@end
NS_ASSUME_NONNULL_END

View file

@ -0,0 +1,42 @@
/*
Copyright 2018 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import <Foundation/Foundation.h>
#import "OLMPkMessage.h"
NS_ASSUME_NONNULL_BEGIN
@interface OLMPkEncryption : NSObject
/**
Set the recipient's public key for encrypting to.
@param recipientKey the recipient's public key.
*/
- (void)setRecipientKey:(NSString*)recipientKey;
/**
Encrypt a plaintext for the recipient.
@param message the message to encrypt.
@param error the error if any.
@return the encrypted message.
*/
- (OLMPkMessage *)encryptMessage:(NSString*)message error:(NSError* _Nullable *)error;
@end
NS_ASSUME_NONNULL_END

View file

@ -0,0 +1,31 @@
/*
Copyright 2018 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface OLMPkMessage : NSObject
@property (nonatomic, copy, readonly) NSString *ciphertext;
@property (nonatomic, copy, readonly,) NSString *mac;
@property (nonatomic, copy, readonly) NSString *ephemeralKey;
- (instancetype) initWithCiphertext:(NSString*)ciphertext mac:(NSString*)mac ephemeralKey:(NSString*)ephemeralKey;
@end
NS_ASSUME_NONNULL_END

View file

@ -0,0 +1,49 @@
/*
Copyright 2019 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface OLMPkSigning : NSObject
/**
Initialise the signing object with a public/private keypair from a seed.
@param seed the seed.
@param error the error if any.
@return the public key
*/
- (NSString *)doInitWithSeed:(NSData*)seed error:(NSError* _Nullable *)error;
/**
Sign a message.
@param message the message to sign.
@param error the error if any.
@return the signature.
*/
- (NSString *)sign:(NSString*)message error:(NSError* _Nullable *)error;
/**
Generate a seed.
@return the generated seed.
*/
+ (NSData *)generateSeed;
@end
NS_ASSUME_NONNULL_END

View file

@ -0,0 +1,70 @@
/*
Copyright 2019 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
Short Authentication String verification utility class.
*/
@interface OLMSAS : NSObject
/**
Get the public key of the SAS object.
*/
- (NSString * _Nullable)publicKey;
/**
Set the public key of other user.
@param theirPublicKey the other user's public key.
@return error the error if any.
*/
- (NSError* _Nullable)setTheirPublicKey:(NSString*)theirPublicKey;
/**
Generate bytes to use for the short authentication string.
@param info extra information to mix in when generating the bytes, as per the Matrix spec.
@param length the size of the output buffer. For hex-based SAS as in the Matrix spec, this will be 5.
@return generated bytes
*/
- (NSData *)generateBytes:(NSString*)info length:(NSUInteger)length;
/**
Generate a message authentication code (MAC) based on the shared secret.
@param input the message to produce the authentication code for.
@param info extra information to mix in when generating the MAC, as per the Matrix spec.
@param error the error if any.
@return the MAC.
*/
- (NSString *)calculateMac:(NSString*)input info:(NSString*)info error:(NSError* _Nullable *)error;
/**
Generate a message authentication code (MAC) based on the shared secret.
For compatibility with an old version of olm.js.
@param input the message to produce the authentication code for.
@param info extra information to mix in when generating the MAC, as per the Matrix spec.
@param error the error if any.
@return the MAC.
*/
- (NSString *)calculateMacLongKdf:(NSString*)input info:(NSString*)info error:(NSError* _Nullable *)error;
@end
NS_ASSUME_NONNULL_END

View file

@ -0,0 +1,29 @@
/*
Copyright 2016 Chris Ballinger
Copyright 2016 OpenMarket Ltd
Copyright 2016 Vector Creations Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import <Foundation/Foundation.h>
@protocol OLMSerializable <NSObject>
/** Initializes from encrypted serialized data. Will throw error if invalid key or invalid base64. */
- (instancetype) initWithSerializedData:(NSString*)serializedData key:(NSData*)key error:(NSError**)error;
/** Serializes and encrypts object data, outputs base64 blob */
- (NSString*) serializeDataWithKey:(NSData*)key error:(NSError**)error;
@end

View file

@ -0,0 +1,44 @@
/*
Copyright 2016 Chris Ballinger
Copyright 2016 OpenMarket Ltd
Copyright 2016 Vector Creations Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import <Foundation/Foundation.h>
#import "OLMSerializable.h"
#import "OLMAccount.h"
#import "OLMMessage.h"
@interface OLMSession : NSObject <OLMSerializable, NSSecureCoding>
- (instancetype) initOutboundSessionWithAccount:(OLMAccount*)account theirIdentityKey:(NSString*)theirIdentityKey theirOneTimeKey:(NSString*)theirOneTimeKey error:(NSError**)error;
- (instancetype) initInboundSessionWithAccount:(OLMAccount*)account oneTimeKeyMessage:(NSString*)oneTimeKeyMessage error:(NSError**)error;
- (instancetype) initInboundSessionWithAccount:(OLMAccount*)account theirIdentityKey:(NSString*)theirIdentityKey oneTimeKeyMessage:(NSString*)oneTimeKeyMessage error:(NSError**)error;
- (NSString*) sessionIdentifier;
- (BOOL) matchesInboundSession:(NSString*)oneTimeKeyMessage;
- (BOOL) matchesInboundSessionFrom:(NSString*)theirIdentityKey oneTimeKeyMessage:(NSString *)oneTimeKeyMessage;
/** UTF-8 plaintext -> base64 ciphertext */
- (OLMMessage*) encryptMessage:(NSString*)message error:(NSError**)error;
/** base64 ciphertext -> UTF-8 plaintext */
- (NSString*) decryptMessage:(OLMMessage*)message error:(NSError**)error;
@end

View file

@ -0,0 +1,49 @@
/*
Copyright 2016 Chris Ballinger
Copyright 2016 OpenMarket Ltd
Copyright 2016 Vector Creations Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import <Foundation/Foundation.h>
FOUNDATION_EXPORT NSString *const OLMErrorDomain;
@interface OLMUtility : NSObject
/**
Calculate the SHA-256 hash of the input and encodes it as base64.
@param message the message to hash.
@return the base64-encoded hash value.
*/
- (NSString*)sha256:(NSData*)message;
/**
Verify an ed25519 signature.
@param signature the base64-encoded signature to be checked.
@param key the ed25519 key.
@param message the message which was signed.
@param error if there is a problem with the verification.
If the key was too small then the message will be "OLM.INVALID_BASE64".
If the signature was invalid then the message will be "OLM.BAD_MESSAGE_MAC".
@return YES if valid.
*/
- (BOOL)verifyEd25519Signature:(NSString*)signature key:(NSString*)key message:(NSData*)message error:(NSError**)error;
+ (NSMutableData*) randomBytesOfLength:(NSUInteger)length;
@end