Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions iOSClient/PushNotification/NCPushNotificationEncryption.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,26 @@ - (NSString *)decryptPushNotification:(NSString *)message withDevicePrivateKey:(

// Decrypt the message
unsigned char *decrypted = (unsigned char *) malloc(4096);


// Try decrypting with RSA PKCS#1 v1.5 padding
int decrypted_length = RSA_private_decrypt((int)[decodedData length], [decodedData bytes], decrypted, rsa, RSA_PKCS1_PADDING);
if(decrypted_length == -1) {
NSString *decryptString = decrypted_length == -1 ? nil : [[NSString alloc] initWithBytes:decrypted length:decrypted_length encoding:NSUTF8StringEncoding];

// Try decrypting with RSA OAEP padding
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since oaep will be the future, please switch it around.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Will do. Just FYI talk also checks PKCS first: https://github.com/nextcloud/talk-ios/pull/2491/changes

if(decrypted_length == -1 || decryptString == nil) {
ERR_clear_error();
decrypted_length = RSA_private_decrypt((int)[decodedData length], [decodedData bytes], decrypted, rsa, RSA_PKCS1_OAEP_PADDING);
decryptString = decrypted_length == -1 ? nil : [[NSString alloc] initWithBytes:decrypted length:decrypted_length encoding:NSUTF8StringEncoding];
}
Comment thread
mpivchev marked this conversation as resolved.

// Could not decrypt
if(decrypted_length == -1 || decryptString == nil) {
char buffer[500];
ERR_error_string(ERR_get_error(), buffer);
NSLog(@"%@",[NSString stringWithUTF8String:buffer]);
return nil;
}
Comment thread
mpivchev marked this conversation as resolved.

NSString *decryptString = [[NSString alloc] initWithBytes:decrypted length:decrypted_length encoding:NSUTF8StringEncoding];

if (decrypted)
free(decrypted);
free(bio);
Expand Down
Loading