Skip to content

Commit a27a8ce

Browse files
committed
Fork App Check dir for use outside of Firebase (#11247)
1 parent 1259294 commit a27a8ce

File tree

122 files changed

+13503
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+13503
-0
lines changed

AppCheck.podspec

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
Pod::Spec.new do |s|
2+
s.name = 'AppCheck'
3+
s.version = '10.10.0'
4+
s.summary = 'App Check SDK.'
5+
6+
s.description = <<-DESC
7+
SDK for anti-abuse compatibility.
8+
DESC
9+
10+
s.homepage = 'https://firebase.google.com'
11+
s.license = { :type => 'Apache-2.0', :file => 'LICENSE' }
12+
s.authors = 'Google, Inc.'
13+
14+
s.source = {
15+
:git => 'https://github.com/firebase/firebase-ios-sdk.git',
16+
:tag => 'CocoaPods-' + s.version.to_s
17+
}
18+
s.social_media_url = 'https://twitter.com/Firebase'
19+
20+
ios_deployment_target = '11.0'
21+
osx_deployment_target = '10.13'
22+
tvos_deployment_target = '12.0'
23+
watchos_deployment_target = '6.0'
24+
25+
s.swift_version = '5.3'
26+
27+
s.ios.deployment_target = ios_deployment_target
28+
s.osx.deployment_target = osx_deployment_target
29+
s.tvos.deployment_target = tvos_deployment_target
30+
s.watchos.deployment_target = watchos_deployment_target
31+
32+
s.cocoapods_version = '>= 1.4.0'
33+
s.prefix_header_file = false
34+
35+
base_dir = "AppCheck/"
36+
37+
s.source_files = [
38+
base_dir + 'Sources/**/*.[mh]',
39+
base_dir + 'Interop/*.h',
40+
'FirebaseCore/Extension/*.h',
41+
]
42+
s.public_header_files = base_dir + 'Sources/Public/AppCheck/*.h'
43+
44+
s.ios.weak_framework = 'DeviceCheck'
45+
s.osx.weak_framework = 'DeviceCheck'
46+
s.tvos.weak_framework = 'DeviceCheck'
47+
48+
s.dependency 'FirebaseCore', '~> 10.0'
49+
s.dependency 'PromisesObjC', '~> 2.1'
50+
s.dependency 'GoogleUtilities/Environment', '~> 7.8'
51+
52+
s.pod_target_xcconfig = {
53+
'GCC_C_LANGUAGE_STANDARD' => 'c99',
54+
'HEADER_SEARCH_PATHS' => '"${PODS_TARGET_SRCROOT}"'
55+
}
56+
57+
# Using environment variable because of the dependency on the unpublished
58+
# HeartbeatLoggingTestUtils.
59+
if ENV['POD_LIB_LINT_ONLY'] && ENV['POD_LIB_LINT_ONLY'] == '1' then
60+
s.test_spec 'unit' do |unit_tests|
61+
unit_tests.platforms = {
62+
:ios => ios_deployment_target,
63+
:osx => osx_deployment_target,
64+
:tvos => tvos_deployment_target
65+
}
66+
unit_tests.source_files = [
67+
base_dir + 'Tests/Unit/**/*.[mh]',
68+
base_dir + 'Tests/Utils/**/*.[mh]',
69+
'SharedTestUtilities/AppCheckFake/*',
70+
'SharedTestUtilities/AppCheckBackoffWrapperFake/*',
71+
'SharedTestUtilities/Date/*',
72+
'SharedTestUtilities/URLSession/*',
73+
]
74+
75+
unit_tests.resources = base_dir + 'Tests/Fixture/**/*'
76+
unit_tests.dependency 'OCMock'
77+
unit_tests.dependency 'HeartbeatLoggingTestUtils'
78+
unit_tests.requires_app_host = true
79+
end
80+
end
81+
82+
s.test_spec 'integration' do |integration_tests|
83+
integration_tests.platforms = {
84+
:ios => ios_deployment_target,
85+
:osx => osx_deployment_target,
86+
:tvos => tvos_deployment_target
87+
}
88+
integration_tests.source_files = [
89+
base_dir + 'Tests/Integration/**/*.[mh]',
90+
base_dir + 'Tests/Integration/**/*.[mh]',
91+
]
92+
integration_tests.resources = base_dir + 'Tests/Fixture/**/*'
93+
integration_tests.requires_app_host = true
94+
end
95+
96+
s.test_spec 'swift-unit' do |swift_unit_tests|
97+
swift_unit_tests.platforms = {
98+
:ios => ios_deployment_target,
99+
:osx => osx_deployment_target,
100+
:tvos => tvos_deployment_target
101+
}
102+
swift_unit_tests.source_files = [
103+
base_dir + 'Tests/Unit/Swift/**/*.swift',
104+
base_dir + 'Tests/Unit/Swift/**/*.h',
105+
]
106+
end
107+
108+
end

AppCheck/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# unreleased
2+
- [added] Add generic (non-Firebase) App Check SDK.

AppCheck/Interop/CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
if(NOT APPLE)
16+
return()
17+
endif()
18+
19+
file(GLOB headers *.h)
20+
firebase_ios_generate_dummy_source(AppCheckInterop sources)
21+
22+
firebase_ios_add_framework(
23+
AppCheckInterop DISABLE_STRICT_WARNINGS EXCLUDE_FROM_ALL
24+
${headers} ${sources}
25+
)
26+
27+
firebase_ios_framework_public_headers(AppCheckInterop ${headers})

AppCheck/Interop/GACAppCheckInterop.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <Foundation/Foundation.h>
18+
19+
@protocol GACAppCheckTokenResultInterop;
20+
21+
NS_ASSUME_NONNULL_BEGIN
22+
23+
NS_SWIFT_NAME(InternalAppCheckTokenHandlerInterop)
24+
typedef void (^GACAppCheckTokenHandlerInterop)(id<GACAppCheckTokenResultInterop> tokenResult);
25+
26+
NS_SWIFT_NAME(InternalAppCheckInterop) @protocol GACAppCheckInterop
27+
28+
/// Retrieve a cached or generate a new FAA Token. If forcingRefresh == YES always generates a new
29+
/// token and updates the cache.
30+
- (void)getTokenForcingRefresh:(BOOL)forcingRefresh
31+
completion:(GACAppCheckTokenHandlerInterop)handler
32+
NS_SWIFT_NAME(getToken(forcingRefresh:completion:));
33+
34+
/// A notification with the specified name is sent to the default notification center
35+
/// (`NotificationCenter.default`) each time a Firebase app check token is refreshed.
36+
/// The user info dictionary contains `-[self notificationTokenKey]` and
37+
/// `-[self notificationAppNameKey]` keys.
38+
- (NSString *)tokenDidChangeNotificationName;
39+
40+
/// `userInfo` key for the FAC token in a notification for `tokenDidChangeNotificationName`.
41+
- (NSString *)notificationTokenKey;
42+
/// `userInfo` key for the `FirebaseApp.name` in a notification for
43+
/// `tokenDidChangeNotificationName`.
44+
- (NSString *)notificationAppNameKey;
45+
46+
@end
47+
48+
NS_ASSUME_NONNULL_END
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <Foundation/Foundation.h>
18+
19+
NS_ASSUME_NONNULL_BEGIN
20+
21+
@protocol GACAppCheckTokenResultInterop <NSObject>
22+
23+
/// App Check token in the case of success or a dummy token in the case of a failure.
24+
/// In general, the value of the token should always be set to the request header.
25+
@property(nonatomic, readonly) NSString *token;
26+
27+
/// A token fetch error in the case of a failure or `nil` in the case of success.
28+
@property(nonatomic, readonly, nullable) NSError *error;
29+
30+
@end
31+
32+
NS_ASSUME_NONNULL_END

AppCheck/Interop/dummy.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// Swift Package Manager needs at least one source file.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright 2021 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <Foundation/Foundation.h>
18+
19+
@class FBLPromise<Result>;
20+
@class FIRAppAttestAttestationResponse;
21+
@class GACAppCheckToken;
22+
@protocol GACAppCheckAPIServiceProtocol;
23+
24+
NS_ASSUME_NONNULL_BEGIN
25+
26+
/// Methods to send API requests required for App Attest based attestation sequence.
27+
@protocol FIRAppAttestAPIServiceProtocol <NSObject>
28+
29+
/// Request a random challenge from server.
30+
- (FBLPromise<NSData *> *)getRandomChallenge;
31+
32+
/// Sends attestation data to Firebase backend for validation.
33+
/// @param attestation The App Attest key attestation data obtained from the method
34+
/// `-[DCAppAttestService attestKey:clientDataHash:completionHandler:]` using the random challenge
35+
/// received from Firebase backend.
36+
/// @param keyID The key ID used to generate the attestation.
37+
/// @param challenge The challenge used to generate the attestation.
38+
/// @return A promise that is fulfilled with a response object with an encrypted attestation
39+
/// artifact and an Firebase App Check token or rejected with an error.
40+
- (FBLPromise<FIRAppAttestAttestationResponse *> *)attestKeyWithAttestation:(NSData *)attestation
41+
keyID:(NSString *)keyID
42+
challenge:(NSData *)challenge;
43+
44+
/// Exchanges attestation data (artifact & assertion) and a challenge for a FAC token.
45+
- (FBLPromise<GACAppCheckToken *> *)getAppCheckTokenWithArtifact:(NSData *)artifact
46+
challenge:(NSData *)challenge
47+
assertion:(NSData *)assertion;
48+
49+
@end
50+
51+
/// A default implementation of `FIRAppAttestAPIServiceProtocol`.
52+
@interface FIRAppAttestAPIService : NSObject <FIRAppAttestAPIServiceProtocol>
53+
54+
/// Default initializer.
55+
/// @param APIService An instance implementing `GACAppCheckAPIServiceProtocol` to be used to send
56+
/// network requests to Firebase App Check backend.
57+
/// @param projectID A Firebase project ID for the requests (`FIRApp.options.projectID`).
58+
/// @param appID A Firebase app ID for the requests (`FIRApp.options.googleAppID`).
59+
- (instancetype)initWithAPIService:(id<GACAppCheckAPIServiceProtocol>)APIService
60+
projectID:(NSString *)projectID
61+
appID:(NSString *)appID;
62+
63+
@end
64+
65+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)