Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove 13.0 deprecations #3786

Merged
merged 1 commit into from
Dec 20, 2024
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 @@ -153,22 +153,6 @@ extern NSUInteger const kSFPBKDFDefaultSaltByteLength;
*/
+ (nullable SecKeyRef)getRSAPrivateKeyRefWithName:(NSString *)keyName keyLength:(NSUInteger)length;

/**
* Encrypt data with given `SecKeyRef` using the RSA `pkcs1` algorithm.
* @param data Data to encrypt
* @param keyRef Keyref used in encryption
* @return `NSData` object containing the encrypted Data, or `nil` if encryption failed.
*/
+ (nullable NSData*)encryptUsingRSAforData:(NSData *)data withKeyRef:(SecKeyRef)keyRef SFSDK_DEPRECATED(12.0, 13.0, "Will be removed.");

/**
* Decrypt data with given `SecKeyRef` using the RSA `pkcs1` algorithm.
* @param data Data to decrypt
* @param keyRef Keyref used in decryption
* @return `NSData` object containing the decrypted Data, or `nil` if decryption failed.
*/
+ (nullable NSData*)decryptUsingRSAforData:(NSData *)data withKeyRef:(SecKeyRef)keyRef SFSDK_DEPRECATED(12.0, 13.0, "Will be removed.");

/**
* Check for availability of the secure enclave.
* @return YES if secure enclave is available.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,44 +193,6 @@ + (nullable SecKeyRef)getRSAPrivateKeyRefWithName:(NSString *)keyName keyLength:
return [self getRSAKeyRefWithTag:tagString keyLength:length];
}

+ (nullable NSData*)encryptUsingRSAforData:(NSData *)data withKeyRef:(SecKeyRef)keyRef
{
uint8_t *bytes = (uint8_t*)[data bytes];
size_t blockSize = SecKeyGetBlockSize(keyRef);

uint8_t cipherText[blockSize];
size_t cipherLength = blockSize;
OSStatus status = SecKeyEncrypt(keyRef, kSecPaddingPKCS1, bytes, [data length], &cipherText[0], &cipherLength);

if (status != errSecSuccess) {
[SFSDKCoreLogger e:[self class] format:@"encryptUsingRSAforData failed with status code: %d", status];
return nil;
}

NSData *encryptedData = [NSData dataWithBytes:cipherText length:cipherLength];
return encryptedData;

}

+ (nullable NSData*)decryptUsingRSAforData:(NSData *)data withKeyRef:(SecKeyRef)keyRef
{
size_t blockSize = SecKeyGetBlockSize(keyRef);
size_t cipherLength = [data length];
uint8_t *cipherText = (uint8_t*)[data bytes];

uint8_t plainText[blockSize];
size_t plainLength = blockSize;
OSStatus status = SecKeyDecrypt(keyRef, kSecPaddingPKCS1, &cipherText[0], cipherLength, &plainText[0], &plainLength );

if (status != errSecSuccess) {
[SFSDKCoreLogger e:[self class] format:@"decryptUsingRSAforData failed with status code: %d", status];
return nil;
}

NSData *decryptedData = [NSData dataWithBytes:plainText length:plainLength];
return decryptedData;
}

+ (BOOL) isSecureEnclaveAvailable
{
#if TARGET_OS_SIMULATOR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
+ (nullable UIApplication*)sharedApplication;

/** Opens the specified URL.
@param url The URL to be opened.
@return YES if the URL is successfully opened.
*/
+ (BOOL)openURL:(NSURL*)url SFSDK_DEPRECATED(12.2, 13.0, "Use openURL:options:completionHandler: instead.");

+ (void)openURL:(NSURL*)url options:(NSDictionary<UIApplicationOpenExternalURLOptionsKey, id> *)options completionHandler:(void (^ __nullable)(BOOL success))completion;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,6 @@ + (UIApplication*)sharedApplication {
return nil;
}

+ (BOOL)openURL:(NSURL*)url {
BOOL success = NO;
UIApplication *app = [self sharedApplication];

if (app) {
SEL selector = @selector(openURL:);
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[app class] instanceMethodSignatureForSelector:selector]];
[invocation setTarget:app];
[invocation setSelector:selector];
[invocation setArgument:&url atIndex:2];
[invocation invoke];
[invocation getReturnValue:&success];
}

return success;
}

+ (void)openURL:(NSURL*)url options:(NSDictionary<UIApplicationOpenExternalURLOptionsKey, id> *)options completionHandler:(void (^ __nullable)(BOOL success))completion {
UIApplication *app = [self sharedApplication];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)accessTokenForApprovalCode:(SFSDKOAuthTokenEndpointRequest *)endpointReq completion:(void (^)(SFSDKOAuthTokenEndpointResponse *))completionBlock;
- (void)accessTokenForRefresh:(SFSDKOAuthTokenEndpointRequest *)endpointReq completion:(void (^)(SFSDKOAuthTokenEndpointResponse *))completionBlock;
- (void)openIDTokenForRefresh:(SFSDKOAuthTokenEndpointRequest *)endpointReq completion:(void (^)(NSString *))completionBlock;
- (void)revokeRefreshToken:(SFOAuthCredentials *)credentials SFSDK_DEPRECATED(12.1, 13.0, "Will be replaced by revokeRefreshToken:reason:");

@optional
- (void)revokeRefreshToken:(SFOAuthCredentials *)credentials reason:(SFLogoutReason)reason;

@end

@protocol SFSDKOAuthSessionManaging<NSObject>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,7 @@
}
}

- (void)revokeRefreshToken:(SFOAuthCredentials *)credentials {
[self revokeRefreshToken:credentials reason:SFLogoutReasonUnknown];
}

- (void)revokeRefreshToken:(SFOAuthCredentials *)credentials reason:(SFLogoutReason)reason {

Check warning on line 388 in libs/SalesforceSDKCore/SalesforceSDKCore/Classes/Util/SFSDKOAuth2.m

View workflow job for this annotation

GitHub Actions / ios-pr (SalesforceSDKCore) / test-ios

implementing deprecated method [-Wdeprecated-implementations]
if (credentials.refreshToken != nil) {
NSMutableURLRequest *request = [SFSDKOAuth2 requestForRevokeRefreshToken:credentials reason:reason];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,4 @@
decryptedData = try XCTUnwrap(SFSDKCryptoUtils.decrypt(data: encryptedData, key: privateKey, algorithm: SecKeyAlgorithm.rsaEncryptionOAEPSHA256))
XCTAssertEqual(stringToEncrypt, String(bytes: decryptedData, encoding: .utf8))
}

func testEncryptWithOldPKCS1MethodDecryptWithNew() throws {
let stringToEncrypt = "Test string"
let data = try XCTUnwrap(stringToEncrypt.data(using: .utf8))

// Old encrypt
let encryptedData = try XCTUnwrap(SFSDKCryptoUtils.encrypt(usingRSAforData: data, withKeyRef: publicKey)) // Deprecated method
// New decrypt
let decryptedData = try XCTUnwrap(SFSDKCryptoUtils.decrypt(data: encryptedData, key: privateKey, algorithm: SecKeyAlgorithm.rsaEncryptionPKCS1))
XCTAssertEqual(stringToEncrypt, String(bytes: decryptedData, encoding: .utf8))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

// RSA-PKCS1 encryption for secret
let secret = key + iv
let encryptedSecret = try XCTUnwrap(SFSDKCryptoUtils.encrypt(usingRSAforData: secret, withKeyRef: publicKey))
let encryptedSecret = try SFSDKCryptoUtils.encrypt(data: secret, key: publicKey, algorithm: SecKeyAlgorithm.rsaEncryptionPKCS1)

Check warning on line 60 in libs/SalesforceSDKCore/SalesforceSDKCoreTests/PushNotificationDecryptionTests.swift

View workflow job for this annotation

GitHub Actions / ios-pr (SalesforceSDKCore) / test-ios

'encrypt(usingRSAforData:withKeyRef:)' is deprecated: Deprecated in Salesforce Mobile SDK 12.0 and will be removed in Salesforce Mobile SDK 13.0. Will be removed.
let secretString = encryptedSecret.base64EncodedString()

notificationContent.userInfo[kRemoteNotificationKeySecret] = secretString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

#import <XCTest/XCTest.h>
#import <SalesforceSDKCore/SalesforceSDKCore-Swift.h>
#import "SFSDKCryptoUtils.h"

@interface SFSDKCryptoUtilsTests : XCTestCase
Expand Down Expand Up @@ -219,43 +220,6 @@

}

- (void)testRSAEncryptionAndDecryption
Copy link
Member Author

Choose a reason for hiding this comment

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

new equivalent tests are in CryptoUtilsTests.swift

{
size_t keySize = 2048;

[SFSDKCryptoUtils createRSAKeyPairWithName:@"test" keyLength:keySize accessibleAttribute:kSecAttrAccessibleAfterFirstUnlock];

SecKeyRef publicKeyRef = [SFSDKCryptoUtils getRSAPublicKeyRefWithName:@"test" keyLength:keySize];
SecKeyRef privateKeyRef = [SFSDKCryptoUtils getRSAPrivateKeyRefWithName:@"test" keyLength:keySize];

// Encrypt data
NSString *testString = @"This is a test";
NSData *testData = [testString dataUsingEncoding:NSUTF8StringEncoding];
NSData *encryptedData = [SFSDKCryptoUtils encryptUsingRSAforData:testData withKeyRef:publicKeyRef];

// Decrypt data
NSData *decryptedData = [SFSDKCryptoUtils decryptUsingRSAforData:encryptedData withKeyRef:privateKeyRef];
NSString *result = [[NSString alloc] initWithData:decryptedData encoding:NSUTF8StringEncoding];
XCTAssertTrue([testString isEqualToString:result]);
}

- (void)testRSAEncryptionAndDecryptionForData
{
size_t keySize = 2048;

[SFSDKCryptoUtils createRSAKeyPairWithName:@"test" keyLength:keySize accessibleAttribute:kSecAttrAccessibleAfterFirstUnlock];

SecKeyRef publicKeyRef = [SFSDKCryptoUtils getRSAPublicKeyRefWithName:@"test" keyLength:keySize];
SecKeyRef privateKeyRef = [SFSDKCryptoUtils getRSAPrivateKeyRefWithName:@"test" keyLength:keySize];

NSUInteger byteDataInt = 123456;
NSData *testData = [NSData dataWithBytes:&byteDataInt length:sizeof(NSUInteger)];
NSData *encryptedData = [SFSDKCryptoUtils encryptUsingRSAforData:testData withKeyRef:publicKeyRef];

NSData *decryptedData = [SFSDKCryptoUtils decryptUsingRSAforData:encryptedData withKeyRef:privateKeyRef];
XCTAssertEqualObjects(testData, decryptedData, @"Data objects are not the same data.");
}

- (void)testRSAEncryptionAndDecryptionWrongKeys
{
size_t keySize = 2048;
Expand All @@ -267,12 +231,12 @@
SecKeyRef privateKeyRef = [SFSDKCryptoUtils getRSAPrivateKeyRefWithName:@"test" keyLength:keySize];

// Encrypt data
NSString *testString = @"This is a test";

Check warning on line 234 in libs/SalesforceSDKCore/SalesforceSDKCoreTests/SFSDKCryptoUtilsTests.m

View workflow job for this annotation

GitHub Actions / ios-pr (SalesforceSDKCore) / test-ios

'encryptUsingRSAforData:withKeyRef:' is deprecated: Deprecated in Salesforce Mobile SDK 12.0 and will be removed in Salesforce Mobile SDK 13.0. Will be removed. [-Wdeprecated-declarations]
NSData *testData = [testString dataUsingEncoding:NSUTF8StringEncoding];
NSData *encryptedData = [SFSDKCryptoUtils encryptUsingRSAforData:testData withKeyRef:publicKeyRef];
NSData *encryptedData = [SFSDKCryptoUtils encryptData:testData key:publicKeyRef algorithm:kSecKeyAlgorithmRSAEncryptionOAEPSHA256 error:nil];

Check warning on line 237 in libs/SalesforceSDKCore/SalesforceSDKCoreTests/SFSDKCryptoUtilsTests.m

View workflow job for this annotation

GitHub Actions / ios-pr (SalesforceSDKCore) / test-ios

'decryptUsingRSAforData:withKeyRef:' is deprecated: Deprecated in Salesforce Mobile SDK 12.0 and will be removed in Salesforce Mobile SDK 13.0. Will be removed. [-Wdeprecated-declarations]
// Decrypt data
NSData *decryptedData = [SFSDKCryptoUtils decryptUsingRSAforData:encryptedData withKeyRef:privateKeyRef];
NSData *decryptedData = [SFSDKCryptoUtils decryptData:encryptedData key:privateKeyRef algorithm:kSecKeyAlgorithmRSAEncryptionOAEPSHA256 error:nil];
NSString *result = [[NSString alloc] initWithData:decryptedData encoding:NSUTF8StringEncoding];
XCTAssertFalse([testString isEqualToString:result]);
}
Expand All @@ -286,9 +250,9 @@
XCTAssertFalse(publicKeyRef != NULL, @"Private key should not have been found");

// Create keys
[SFSDKCryptoUtils createECKeyPairWithName:@"test" accessibleAttribute:kSecAttrAccessibleAfterFirstUnlock useSecureEnclave:[SFSDKCryptoUtils isSecureEnclaveAvailable]];

Check warning on line 253 in libs/SalesforceSDKCore/SalesforceSDKCoreTests/SFSDKCryptoUtilsTests.m

View workflow job for this annotation

GitHub Actions / ios-pr (SalesforceSDKCore) / test-ios

'encryptUsingRSAforData:withKeyRef:' is deprecated: Deprecated in Salesforce Mobile SDK 12.0 and will be removed in Salesforce Mobile SDK 13.0. Will be removed. [-Wdeprecated-declarations]

// Keys should exist

Check warning on line 255 in libs/SalesforceSDKCore/SalesforceSDKCoreTests/SFSDKCryptoUtilsTests.m

View workflow job for this annotation

GitHub Actions / ios-pr (SalesforceSDKCore) / test-ios

'decryptUsingRSAforData:withKeyRef:' is deprecated: Deprecated in Salesforce Mobile SDK 12.0 and will be removed in Salesforce Mobile SDK 13.0. Will be removed. [-Wdeprecated-declarations]
privateKeyRef = [SFSDKCryptoUtils getECPrivateKeyRefWithName:@"test"];
publicKeyRef = [SFSDKCryptoUtils getECPublicKeyRefWithName:@"test"];
XCTAssertTrue(privateKeyRef != NULL, @"Public key should have been found");
Expand All @@ -305,10 +269,10 @@
}

- (void)testECEncryptionAndDecryptionForData
{

Check warning on line 272 in libs/SalesforceSDKCore/SalesforceSDKCoreTests/SFSDKCryptoUtilsTests.m

View workflow job for this annotation

GitHub Actions / ios-pr (SalesforceSDKCore) / test-ios

'encryptUsingRSAforData:withKeyRef:' is deprecated: Deprecated in Salesforce Mobile SDK 12.0 and will be removed in Salesforce Mobile SDK 13.0. Will be removed. [-Wdeprecated-declarations]
// Create keys
[SFSDKCryptoUtils createECKeyPairWithName:@"test" accessibleAttribute:kSecAttrAccessibleAfterFirstUnlock useSecureEnclave:[SFSDKCryptoUtils isSecureEnclaveAvailable]];
SecKeyRef privateKeyRef = [SFSDKCryptoUtils getECPrivateKeyRefWithName:@"test"];

Check warning on line 275 in libs/SalesforceSDKCore/SalesforceSDKCoreTests/SFSDKCryptoUtilsTests.m

View workflow job for this annotation

GitHub Actions / ios-pr (SalesforceSDKCore) / test-ios

'decryptUsingRSAforData:withKeyRef:' is deprecated: Deprecated in Salesforce Mobile SDK 12.0 and will be removed in Salesforce Mobile SDK 13.0. Will be removed. [-Wdeprecated-declarations]
SecKeyRef publicKeyRef = [SFSDKCryptoUtils getECPublicKeyRefWithName:@"test"];

NSData *testData = [@"test data" dataUsingEncoding:NSUTF8StringEncoding];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#import "SFSDKPushNotificationDataProvider.h"
#import "SFSDKPushNotificationEncryptionConstants.h"
#import "SFEncryptionKey.h"
#import <SalesforceSDKCore/SalesforceSDKCore-Swift.h>

static NSUInteger const kEncryptionKeyLengthBytes = 16;
static NSUInteger const kEncryptionIVLengthBytes = 16;
Expand Down Expand Up @@ -83,8 +84,8 @@
NSMutableData *fullKeyData = [[NSMutableData alloc] initWithData:key.key];
[fullKeyData appendData:key.initializationVector];

SecKeyRef publicKeyRef = [self getPublicKeyRef];

Check warning on line 87 in libs/SalesforceSDKCore/SalesforceSDKCoreTests/SFSDKPushNotificationDataProvider.m

View workflow job for this annotation

GitHub Actions / ios-pr (SalesforceSDKCore) / test-ios

'encryptUsingRSAforData:withKeyRef:' is deprecated: Deprecated in Salesforce Mobile SDK 12.0 and will be removed in Salesforce Mobile SDK 13.0. Will be removed. [-Wdeprecated-declarations]
NSData *encryptedKeyData = [SFSDKCryptoUtils encryptUsingRSAforData:fullKeyData withKeyRef:publicKeyRef];
NSData *encryptedKeyData = [SFSDKCryptoUtils encryptData:fullKeyData key:publicKeyRef algorithm:kSecKeyAlgorithmRSAEncryptionOAEPSHA256 error:nil];
CFRelease(publicKeyRef);
return [encryptedKeyData base64EncodedStringWithOptions:0];
}
Expand Down
Loading