Skip to content

Commit

Permalink
Make App Check core availability for all supported platforms (#8388)
Browse files Browse the repository at this point in the history
* Update App Check availability to match Core

* AppAttest availability update

* Fix watchOS

* watchOS

* style

* fix import

* Fix Xcode support before 12.5

* changelog

* Comments

* Use week linking for DeviceCheck framework

* Fix mac catalyts version
  • Loading branch information
maksymmalyhin authored Jul 15, 2021
1 parent 5268705 commit 85c42dc
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 35 deletions.
10 changes: 6 additions & 4 deletions FirebaseAppCheck.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ Pod::Spec.new do |s|
}
s.social_media_url = 'https://twitter.com/Firebase'

ios_deployment_target = '11.0'
osx_deployment_target = '10.15'
tvos_deployment_target = '11.0'
ios_deployment_target = '9.0'
osx_deployment_target = '10.12'
tvos_deployment_target = '10.0'
watchos_deployment_target = '6.0'

s.ios.deployment_target = ios_deployment_target
s.osx.deployment_target = osx_deployment_target
s.tvos.deployment_target = tvos_deployment_target
s.watchos.deployment_target = watchos_deployment_target

s.cocoapods_version = '>= 1.4.0'
s.prefix_header_file = false
Expand All @@ -36,7 +38,7 @@ Pod::Spec.new do |s|
]
s.public_header_files = base_dir + 'Sources/Public/FirebaseAppCheck/*.h'

s.framework = 'DeviceCheck'
s.weak_framework = 'DeviceCheck'

s.dependency 'FirebaseCore', '~> 8.0'
s.dependency 'PromisesObjC', '>= 1.2', '< 3.0'
Expand Down
3 changes: 3 additions & 0 deletions FirebaseAppCheck/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# v8.5.0 -- Unreleased
- [changed] App Check SDK available for all supported platforms/OS versions, but App Attest and
DeviceCheck providers availability changed to match underlying platfrom API availability. (#8388)
# v8.4.0 -- M100
- [fixed] Bump Promises dependency. (#8365)
# v8.3.0 -- M99
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,22 @@

#import <TargetConditionals.h>

#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRAppCheckAvailability.h"

// Currently DCAppAttestService is available on iOS only.
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST // Catalyst should be possible with Xcode 12.5+
#if FIR_APP_ATTEST_SUPPORTED_TARGETS

#import <DeviceCheck/DeviceCheck.h>

#import "FirebaseAppCheck/Sources/AppAttestProvider/FIRAppAttestService.h"

NS_ASSUME_NONNULL_BEGIN

API_AVAILABLE(ios(14.0))
API_UNAVAILABLE(macos, tvos, watchos)
FIR_APP_ATTEST_PROVIDER_AVAILABILITY
@interface DCAppAttestService (FIRAppAttestService) <FIRAppAttestService>

@end

NS_ASSUME_NONNULL_END

#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
#endif // FIR_APP_ATTEST_SUPPORTED_TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
#import "FirebaseAppCheck/Sources/AppAttestProvider/DCAppAttestService+FIRAppAttestService.h"

// Currently DCAppAttestService is available on iOS only.
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST // Catalyst should be possible with Xcode 12.5+
#if FIR_APP_ATTEST_SUPPORTED_TARGETS

@implementation DCAppAttestService (FIRAppAttestService)

@end

#endif // TARGET_OS_IOS
#endif // FIR_APP_ATTEST_SUPPORTED_TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ - (instancetype)initWithAppAttestService:(id<FIRAppAttestService>)appAttestServi
}

- (nullable instancetype)initWithApp:(FIRApp *)app {
#if TARGET_OS_IOS && !TARGET_OS_MACCATALYST // Catalyst should be possible with Xcode 12.5+
#if FIR_APP_ATTEST_SUPPORTED_TARGETS
NSURLSession *URLSession = [NSURLSession
sessionWithConfiguration:[NSURLSessionConfiguration ephemeralSessionConfiguration]];

Expand All @@ -159,9 +159,9 @@ - (nullable instancetype)initWithApp:(FIRApp *)app {
APIService:appAttestAPIService
keyIDStorage:keyIDStorage
artifactStorage:artifactStorage];
#else // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
#else // FIR_APP_ATTEST_SUPPORTED_TARGETS
return nil;
#endif // TARGET_OS_IOS && !TARGET_OS_MACCATALYST
#endif // FIR_APP_ATTEST_SUPPORTED_TARGETS
}

#pragma mark - FIRAppCheckProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
* limitations under the License.
*/

#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRAppCheckAvailability.h"

#if FIR_DEVICE_CHECK_SUPPORTED_TARGETS

#import <DeviceCheck/DeviceCheck.h>

#import "FirebaseAppCheck/Sources/DeviceCheckProvider/FIRDeviceCheckTokenGenerator.h"
Expand All @@ -25,3 +29,5 @@ NS_ASSUME_NONNULL_BEGIN
@end

NS_ASSUME_NONNULL_END

#endif // FIR_DEVICE_CHECK_SUPPORTED_TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

#import "FirebaseAppCheck/Sources/DeviceCheckProvider/DCDevice+FIRDeviceCheckTokenGenerator.h"

#if FIR_DEVICE_CHECK_SUPPORTED_TARGETS

@implementation DCDevice (FIRDeviceCheckTokenGenerator)

@end

#endif // FIR_DEVICE_CHECK_SUPPORTED_TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
* limitations under the License.
*/

#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRAppCheckAvailability.h"

#if FIR_DEVICE_CHECK_SUPPORTED_TARGETS

#import <Foundation/Foundation.h>

#if __has_include(<FBLPromises/FBLPromises.h>)
Expand Down Expand Up @@ -119,3 +123,5 @@ - (void)getTokenWithCompletion:(void (^)(FIRAppCheckToken *_Nullable token,
@end

NS_ASSUME_NONNULL_END

#endif // FIR_DEVICE_CHECK_SUPPORTED_TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
* limitations under the License.
*/

#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRAppCheckAvailability.h"

#if FIR_DEVICE_CHECK_SUPPORTED_TARGETS

#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRDeviceCheckProviderFactory.h"

#import "FirebaseAppCheck/Sources/Public/FirebaseAppCheck/FIRAppCheck.h"
Expand All @@ -30,3 +34,5 @@ + (void)load {
}

@end

#endif // FIR_DEVICE_CHECK_SUPPORTED_TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@

#import "FIRAppCheckProvider.h"

#import "FIRAppCheckAvailability.h"

@class FIRApp;

NS_ASSUME_NONNULL_BEGIN

API_AVAILABLE(ios(14.0))
API_UNAVAILABLE(macos, tvos, watchos)
FIR_APP_ATTEST_PROVIDER_AVAILABILITY
NS_SWIFT_NAME(AppAttestProvider)
@interface FIRAppAttestProvider : NSObject <FIRAppCheckProvider>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Availability conditions for different App Check SDK components.

#import <TargetConditionals.h>

#pragma mark - DeviceCheck

// Targets where DeviceCheck framework is available to be used in preprocessor conditions.
#define FIR_DEVICE_CHECK_SUPPORTED_TARGETS TARGET_OS_IOS || TARGET_OS_OSX || TARGET_OS_TV

// `DeviceCheckProvider` availability.
#define FIR_DEVICE_CHECK_PROVIDER_AVAILABILITY \
API_AVAILABLE(ios(11.0), macos(10.15), tvos(11.0)) API_UNAVAILABLE(watchos)

#pragma mark - App Attest

// App Attest availability was extended to macOS and Mac Catalyst in Xcode 12.5.
#if (defined(__IPHONE_14_5) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_5) || \
(defined(__MAC_11_3) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_11_3) || \
(defined(__TVOS_14_5) && __TV_OS_VERSION_MAX_ALLOWED >= __TVOS_14_5)

// Targets where `DCAppAttestService` is available to be used in preprocessor conditions.
#define FIR_APP_ATTEST_SUPPORTED_TARGETS TARGET_OS_IOS || TARGET_OS_OSX

// `AppAttestProvider` availability annotations
#define FIR_APP_ATTEST_PROVIDER_AVAILABILITY \
API_AVAILABLE(macos(11.0), ios(14.0)) API_UNAVAILABLE(tvos, watchos)

#else // (defined(__IPHONE_14_5) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_5) || \
(defined(__MAC_11_3) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_11_3) || \
(defined(__TVOS_14_5) && __TV_OS_VERSION_MAX_ALLOWED >= __TVOS_14_5)

// Targets where `DCAppAttestService` is available to be used in preprocessor conditions.
#define FIR_APP_ATTEST_SUPPORTED_TARGETS TARGET_OS_IOS && !TARGET_OS_MACCATALYST

// `AppAttestProvider` availability annotations
#define FIR_APP_ATTEST_PROVIDER_AVAILABILITY \
API_AVAILABLE(ios(14.0)) API_UNAVAILABLE(macos, tvos, watchos)

#endif // (defined(__IPHONE_14_5) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_14_5) || \
(defined(__MAC_11_3) && __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_11_3) || \
(defined(__TVOS_14_5) && __TV_OS_VERSION_MAX_ALLOWED >= __TVOS_14_5)
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

#import "FIRAppCheckProvider.h"

#import "FIRAppCheckAvailability.h"

#if FIR_DEVICE_CHECK_SUPPORTED_TARGETS

@class FIRApp;
@protocol FIRDeviceCheckAPIServiceProtocol;
@protocol FIRDeviceCheckTokenGenerator;
Expand All @@ -26,8 +30,7 @@ NS_ASSUME_NONNULL_BEGIN

/// Firebase App Check provider that verifies app integrity using the
/// [DeviceCheck](https://developer.apple.com/documentation/devicecheck) API.
API_AVAILABLE(ios(11.0), macos(10.15), tvos(11.0))
API_UNAVAILABLE(watchos)
FIR_DEVICE_CHECK_PROVIDER_AVAILABILITY
NS_SWIFT_NAME(DeviceCheckProvider)
@interface FIRDeviceCheckProvider : NSObject <FIRAppCheckProvider>

Expand All @@ -42,3 +45,5 @@ NS_SWIFT_NAME(DeviceCheckProvider)
@end

NS_ASSUME_NONNULL_END

#endif // FIR_DEVICE_CHECK_SUPPORTED_TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
* limitations under the License.
*/

#import "FIRAppCheckAvailability.h"

#if FIR_DEVICE_CHECK_SUPPORTED_TARGETS

#import <Foundation/Foundation.h>

#import "FIRAppCheckProviderFactory.h"
Expand All @@ -24,11 +28,12 @@ NS_ASSUME_NONNULL_BEGIN
/// `DeviceCheckProvider` for the specified `FirebaseApp` on request. Currently
/// `DeviceCheckProviderFactory` is the default that will be used by Firebase App Check if no other
/// provider is specified. See `AppCheck` class for more details.
API_AVAILABLE(ios(11.0), macos(10.15), tvos(11.0))
API_UNAVAILABLE(watchos)
FIR_DEVICE_CHECK_PROVIDER_AVAILABILITY
NS_SWIFT_NAME(DeviceCheckProviderFactory)
@interface FIRDeviceCheckProviderFactory : NSObject <FIRAppCheckProviderFactory>

@end

NS_ASSUME_NONNULL_END

#endif // FIR_DEVICE_CHECK_SUPPORTED_TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,17 @@

#import "FirebaseCore/Sources/Private/FirebaseCoreInternal.h"

// Currently FIRAppAttestProvider is available only on iOS.
#if TARGET_OS_IOS
#if FIR_APP_ATTEST_SUPPORTED_TARGETS

API_AVAILABLE(ios(14.0))
FIR_APP_ATTEST_PROVIDER_AVAILABILITY
@interface FIRAppAttestProvider (Tests)
- (instancetype)initWithAppAttestService:(id<FIRAppAttestService>)appAttestService
APIService:(id<FIRAppAttestAPIServiceProtocol>)APIService
keyIDStorage:(id<FIRAppAttestKeyIDStorageProtocol>)keyIDStorage
artifactStorage:(id<FIRAppAttestArtifactStorageProtocol>)artifactStorage;
@end

API_AVAILABLE(ios(14.0))
FIR_APP_ATTEST_PROVIDER_AVAILABILITY
@interface FIRAppAttestProviderTests : XCTestCase

@property(nonatomic) FIRAppAttestProvider *provider;
Expand Down Expand Up @@ -92,7 +91,7 @@ - (void)tearDown {

#pragma mark - Init tests

#if !TARGET_OS_MACCATALYST // Catalyst should be possible with Xcode 12.5+
#if !TARGET_OS_MACCATALYST
// Keychain dependent logic require additional configuration on Catalyst (enabling Keychain
// sharing). For now, keychain dependent tests are disabled for Catalyst.
- (void)testInitWithValidApp {
Expand Down Expand Up @@ -971,4 +970,4 @@ - (void)expectAttestationReset {

@end

#endif // TARGET_OS_IOS
#endif // FIR_APP_ATTEST_SUPPORTED_TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ - (void)setUp {

- (void)tearDown {
[FIRApp resetApps];
// Recover default provider factory.
[FIRAppCheck setAppCheckProviderFactory:[[FIRDeviceCheckProviderFactory alloc] init]];

if (@available(iOS 11.0, macOS 10.15, macCatalyst 13.0, tvOS 11.0, *)) {
// Recover default provider factory.
[FIRAppCheck setAppCheckProviderFactory:[[FIRDeviceCheckProviderFactory alloc] init]];
}

[self.mockTokenRefresher stopMocking];
self.mockTokenRefresher = nil;
Expand Down
17 changes: 9 additions & 8 deletions FirebaseAppCheck/Tests/Unit/Swift/AppCheckAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,17 @@ final class AppCheckAPITests {
// MARK: - DeviceCheckProvider

// `DeviceCheckProvider` initializer
if let app = FirebaseApp.app(), let deviceCheckProvider = DeviceCheckProvider(app: app) {
// Get token
deviceCheckProvider.getToken { token, error in
if let _ /* error */ = error {
// ...
} else if let _ /* token */ = token {
// ...
if #available(iOS 11.0, macOS 10.15, macCatalyst 13.0, tvOS 11.0, *) {
if let app = FirebaseApp.app(), let deviceCheckProvider = DeviceCheckProvider(app: app) {
// Get token
deviceCheckProvider.getToken { token, error in
if let _ /* error */ = error {
// ...
} else if let _ /* token */ = token {
// ...
}
}
}

// Get token (async/await)
#if swift(>=5.5)
if #available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) {
Expand Down

0 comments on commit 85c42dc

Please sign in to comment.