diff --git a/libs/SalesforceSDKCore/SalesforceSDKCore/Classes/PushNotification/SFSDKPushNotificationDecryption.m b/libs/SalesforceSDKCore/SalesforceSDKCore/Classes/PushNotification/SFSDKPushNotificationDecryption.m index 77e6dd7db5..663317306d 100644 --- a/libs/SalesforceSDKCore/SalesforceSDKCore/Classes/PushNotification/SFSDKPushNotificationDecryption.m +++ b/libs/SalesforceSDKCore/SalesforceSDKCore/Classes/PushNotification/SFSDKPushNotificationDecryption.m @@ -199,7 +199,7 @@ + (SFEncryptionKey *)getAESKeyFromSecret:(NSString *)secret error:(NSError **)er } CFRelease(privateKeyRef); - if (decryptedData == nil) { + if (decryptedData == nil || [decryptedData length] != 32) { if (error) { *error = [self pushErrorWithCode:SFSDKPushNotificationErrorSecretDecryptionFailed description:@"Failed to decrypt secret with RSA private key."]; } diff --git a/libs/SalesforceSDKCore/SalesforceSDKCoreTests/SFSDKEncryptedPushNotificationTests.m b/libs/SalesforceSDKCore/SalesforceSDKCoreTests/SFSDKEncryptedPushNotificationTests.m index 41b3848e05..c5a1a845c9 100644 --- a/libs/SalesforceSDKCore/SalesforceSDKCoreTests/SFSDKEncryptedPushNotificationTests.m +++ b/libs/SalesforceSDKCore/SalesforceSDKCoreTests/SFSDKEncryptedPushNotificationTests.m @@ -190,13 +190,9 @@ - (void)testNotificationTransformNonRSASecret { NSError *nonRSASecretError = nil; BOOL result = [SFSDKPushNotificationDecryption decryptNotificationContent:notifContent error:&nonRSASecretError]; XCTAssertFalse(result); - if (@available(iOS 17.4, *)) { - // As of 17.4, decrypting a bad key with PKCS1 returns data instead of nil, so the secret decryption doesn't fail - // at the same point as before but using it later to decrypt the content still fails - XCTAssertEqual(nonRSASecretError.code, SFSDKPushNotificationErrorContentDecryptionFailed); - } else { - XCTAssertEqual(nonRSASecretError.code, SFSDKPushNotificationErrorSecretDecryptionFailed); - } + // As of 17.4, decrypting a bad key with PKCS1 returns data instead of nil, so the secret decryption doesn't fail + // at the same point as before but using it later to decrypt the content still fails + XCTAssert(nonRSASecretError.code == SFSDKPushNotificationErrorContentDecryptionFailed || nonRSASecretError.code == SFSDKPushNotificationErrorSecretDecryptionFailed); } - (void)testNotificationTransformMalformedContent {