-
Notifications
You must be signed in to change notification settings - Fork 144
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
Conversation
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"); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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], |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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], |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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], |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this 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.
This is first PR of two to update SecureMessage Themis iOS wrapper for new SecureMessage API (#389).
Please check this PR by commits.
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).
Add more logs for developers about wrong / missing private and public keys.
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