Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ + (SFEncryptionKey *)getAESKeyFromSecret:(NSString *)secret error:(NSError **)er
}

CFRelease(privateKeyRef);
if (decryptedData == nil) {
if (decryptedData == nil || [decryptedData length] != 32) {
Copy link
Member Author

@bbirman bbirman Sep 26, 2025

Choose a reason for hiding this comment

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

From the comment in the flapping test (below), starting in 17.4 decrypting with a bad key returns data instead of nil so at the time I just changed our expected error in the test. But it looks like that data is also variable length (in my runs locally it was 72, 54, and 15). When the data length is less than 32, lines 209 or 210 crash so adding a length check before that

if (error) {
*error = [self pushErrorWithCode:SFSDKPushNotificationErrorSecretDecryptionFailed description:@"Failed to decrypt secret with RSA private key."];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member Author

Choose a reason for hiding this comment

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

I kept the check for both errors in case there's a chance that the bad data is 32 long and passes the check but still fails to decrypt later

}

- (void)testNotificationTransformMalformedContent {
Expand Down
Loading