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

Update Themis iOS wrapper for new SecureMessage API (1 Part) #393

Merged
merged 3 commits into from
Feb 28, 2019

Conversation

vixentael
Copy link
Contributor

@vixentael vixentael commented Feb 28, 2019

This is first PR of two to update SecureMessage Themis iOS wrapper for new SecureMessage API (#389).

Please check this PR by commits.

  1. Update SecureMessage wrapper to call encrypt/decrypt and sign/verify core functions instead of wrap/unwrap. This change doesn't affect SecureMessage iOS wrapper API itself (users won't notice).

  2. Add more logs for developers about wrong / missing private and public keys.

  3. Fix formatting of the whole Themis iOS wrapper, because it drives me crazy – this commit is about updating style only.

--

In next PR (#394): more tests on SecureMessage iOS wrapper that depends on this PR

self = [super init];
if (self) {
if (!privateKey || [privateKey length] == 0 || !peerPublicKey || [peerPublicKey length] == 0) {
NSLog(@"Error during init: Secure Message in Encrypt/Decrypt mode requires both private and public keys to be set");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new log


@end


@implementation TSMessage

- (nullable instancetype)initInEncryptModeWithPrivateKey:(NSData *)privateKey peerPublicKey:(NSData *)peerPublicKey {
- (nullable instancetype)initInEncryptModeWithPrivateKey:(nonnull NSData *)privateKey peerPublicKey:(nonnull NSData *)peerPublicKey {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use "nonnull" for keys in encrypt/decrypt mode

@@ -48,10 +49,11 @@ - (nullable instancetype)initInEncryptModeWithPrivateKey:(NSData *)privateKey pe
}


- (nullable instancetype)initInSignVerifyModeWithPrivateKey:(NSData *)privateKey peerPublicKey:(NSData *)peerPublicKey {
- (nullable instancetype)initInSignVerifyModeWithPrivateKey:(nullable NSData *)privateKey peerPublicKey:(nullable NSData *)peerPublicKey {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one key in sign/verify mode might be empty

result = (TSErrorType) themis_secure_message_wrap([self.privateKey bytes], [self.privateKey length],
[self.publicKey bytes], [self.publicKey length], [message bytes], [message length],
NULL, &wrappedMessageLength);
result = (TSErrorType) themis_secure_message_encrypt([self.privateKey bytes], [self.privateKey length],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API change

if (error) {
*error = SCERROR(TSErrorTypeFail, @"Secure Message failed wraping");
}
NSLog(@"Error during signing: private key is missing");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new log message

return nil;
}
result = (TSErrorType) themis_secure_message_wrap([self.privateKey bytes], [self.privateKey length], NULL, 0,
[message bytes], [message length], NULL, &wrappedMessageLength);
result = (TSErrorType) themis_secure_message_sign([self.privateKey bytes], [self.privateKey length],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API change

if (error) {
*error = SCERROR(result, @"Secure Message failed wraping");
}
NSLog(@"Error during wrapping data: either key is invalid of message is empty");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new log message

result = (TSErrorType) themis_secure_message_wrap([self.privateKey bytes], [self.privateKey length],
[self.publicKey bytes], [self.publicKey length], [message bytes], [message length],
wrappedMessage, &wrappedMessageLength);
result = (TSErrorType) themis_secure_message_encrypt([self.privateKey bytes], [self.privateKey length],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API change and below

size_t unwrappedMessageLength = 0;
TSErrorType result = TSErrorTypeFail;

switch (self.mode) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bit of refactoring here – previously this function didn't check the mode, now we do (and check keys)

result = (TSErrorType) themis_secure_message_unwrap([self.privateKey bytes], [self.privateKey length],
[self.publicKey bytes], [self.publicKey length], [message bytes], [message length],
unwrappedMessage, &unwrappedMessageLength);
switch (self.mode) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API changes here

return nil;
}
result = (TSErrorType) themis_secure_message_wrap([self.privateKey bytes], [self.privateKey length], NULL, 0,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

themis_secure_message_wrap wasn't as public method anywhere? only inside wrapData method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it was used only here

Copy link
Collaborator

@ilammy ilammy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

I'll note that Obj-C wrapper has correct formatting and will make sure that clang-format preserves it.

src/wrappers/themis/Obj-C/objcthemis/smessage.m Outdated Show resolved Hide resolved
@vixentael vixentael merged commit 8d8285c into master Feb 28, 2019
@vixentael vixentael deleted the vxtl/SM-ios branch February 28, 2019 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-iOS 📱 Operating system: iOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants