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
19 changes: 14 additions & 5 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);

int decrypted_length = RSA_private_decrypt((int)[decodedData length], [decodedData bytes], decrypted, rsa, RSA_PKCS1_PADDING);
if(decrypted_length == -1) {

// Try decrypting with RSA OAEP padding
int decrypted_length = RSA_private_decrypt((int)[decodedData length], [decodedData bytes], decrypted, rsa, RSA_PKCS1_OAEP_PADDING);
NSString *decryptString = decrypted_length == -1 ? nil : [[NSString alloc] initWithBytes:decrypted length:decrypted_length encoding:NSUTF8StringEncoding];

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

// 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