From 1f3f990fb5ab916117bf9bc38a2c98ae26a6a8f5 Mon Sep 17 00:00:00 2001 From: Milen Pivchev Date: Thu, 7 May 2026 18:50:18 +0200 Subject: [PATCH 1/2] Add OAEP notification decryption Signed-off-by: Milen Pivchev --- .../NCPushNotificationEncryption.m | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/iOSClient/PushNotification/NCPushNotificationEncryption.m b/iOSClient/PushNotification/NCPushNotificationEncryption.m index 28b913d2ec..b24c955100 100644 --- a/iOSClient/PushNotification/NCPushNotificationEncryption.m +++ b/iOSClient/PushNotification/NCPushNotificationEncryption.m @@ -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 + 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]; + } + + // 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; } - NSString *decryptString = [[NSString alloc] initWithBytes:decrypted length:decrypted_length encoding:NSUTF8StringEncoding]; - if (decrypted) free(decrypted); free(bio); From c28ca1b9ce08f98824ff944e1a4e49f57a67b29c Mon Sep 17 00:00:00 2001 From: Milen Pivchev Date: Mon, 11 May 2026 15:08:14 +0200 Subject: [PATCH 2/2] Flip paddings Signed-off-by: Milen Pivchev --- iOSClient/PushNotification/NCPushNotificationEncryption.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iOSClient/PushNotification/NCPushNotificationEncryption.m b/iOSClient/PushNotification/NCPushNotificationEncryption.m index b24c955100..f904648e09 100644 --- a/iOSClient/PushNotification/NCPushNotificationEncryption.m +++ b/iOSClient/PushNotification/NCPushNotificationEncryption.m @@ -109,14 +109,14 @@ - (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); + // 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 OAEP padding + // 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_OAEP_PADDING); + 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]; }