Skip to content

Commit eefb863

Browse files
authored
Add initial App Check headers and stubs (#1083)
* Initial app check work * Add the gradle logic * Update headers and stubs based on feedback * Address lint errors * Address more lint errors * Fix formatting issues * Update app_check.h * Update CMakeLists.txt * Update comment format * More header formatting * Clear app in the destructor * More header formatting
1 parent dba5401 commit eefb863

18 files changed

+1124
-0
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ option(FIREBASE_INCLUDE_ADMOB "Include the AdMob library."
3232
option(FIREBASE_INCLUDE_ANALYTICS
3333
"Include the Google Analytics for Firebase library."
3434
${FIREBASE_INCLUDE_LIBRARY_DEFAULT})
35+
option(FIREBASE_INCLUDE_APP_CHECK
36+
"Include the Firebase App Check library."
37+
${FIREBASE_INCLUDE_LIBRARY_DEFAULT})
3538
option(FIREBASE_INCLUDE_AUTH "Include the Firebase Authentication library."
3639
${FIREBASE_INCLUDE_LIBRARY_DEFAULT})
3740
option(FIREBASE_INCLUDE_DATABASE
@@ -586,6 +589,9 @@ if (FIREBASE_INCLUDE_ANALYTICS)
586589
add_subdirectory(analytics)
587590
add_dependencies(FIREBASE_GENERATED_HEADERS FIREBASE_ANALYTICS_GENERATED_HEADERS)
588591
endif()
592+
if (FIREBASE_INCLUDE_APP_CHECK)
593+
add_subdirectory(app_check)
594+
endif()
589595
if (FIREBASE_INCLUDE_AUTH)
590596
add_subdirectory(auth)
591597
endif()

app_check/CMakeLists.txt

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Copyright 2022 Google
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+
# CMake file for the firebase_app_check library
16+
17+
# Common source files used by all platforms
18+
set(common_SRCS
19+
src/common/app_check.cc
20+
src/common/common.h
21+
src/include/firebase/app_check.h
22+
src/include/firebase/app_check/debug_provider.h
23+
src/include/firebase/app_check/play_integrity_provider.h
24+
src/include/firebase/app_check/safety_net_provider.h
25+
src/include/firebase/app_check/device_check_provider.h
26+
src/include/firebase/app_check/app_attest_provider.h
27+
)
28+
29+
# Source files used by the Android implementation.
30+
set(android_SRCS
31+
src/android/app_check_android.cc
32+
src/android/app_check_android.h
33+
)
34+
35+
# Source files used by the iOS implementation.
36+
set(ios_SRCS
37+
src/ios/app_check_ios.mm
38+
src/ios/app_check_ios.h
39+
)
40+
41+
# Source files used by the desktop implementation.
42+
set(desktop_SRCS
43+
src/desktop/app_check_desktop.cc
44+
src/desktop/app_check_desktop.h
45+
)
46+
47+
if(ANDROID)
48+
set(app_check_platform_SRCS
49+
"${android_SRCS}")
50+
elseif(IOS)
51+
set(app_check_platform_SRCS
52+
"${ios_SRCS}")
53+
else()
54+
set(app_check_platform_SRCS
55+
"${desktop_SRCS}")
56+
endif()
57+
58+
if(ANDROID OR IOS)
59+
set(additional_link_LIB)
60+
else()
61+
set(additional_link_LIB
62+
firebase_rest_lib)
63+
endif()
64+
65+
add_library(firebase_app_check STATIC
66+
${common_SRCS}
67+
${app_check_platform_SRCS}
68+
${app_check_HDRS})
69+
70+
set_property(TARGET firebase_app_check PROPERTY FOLDER "Firebase Cpp")
71+
72+
# Set up the dependency on Firebase App.
73+
target_link_libraries(firebase_app_check
74+
PUBLIC
75+
firebase_app
76+
PRIVATE
77+
${additional_link_LIB}
78+
)
79+
# Public headers all refer to each other relative to the src/include directory,
80+
# while private headers are relative to the entire C++ SDK directory.
81+
target_include_directories(firebase_app_check
82+
PUBLIC
83+
${CMAKE_CURRENT_LIST_DIR}/src/include
84+
PRIVATE
85+
${FIREBASE_CPP_SDK_ROOT_DIR}
86+
${FIREBASE_CPP_SDK_ROOT_DIR}/ios_pod/swift_headers
87+
)
88+
target_compile_definitions(firebase_app_check
89+
PRIVATE
90+
-DINTERNAL_EXPERIMENTAL=1
91+
)
92+
# Automatically include headers that might not be declared.
93+
if(MSVC)
94+
add_definitions(/FI"assert.h" /FI"string.h" /FI"stdint.h")
95+
else()
96+
add_definitions(-include assert.h -include string.h)
97+
endif()
98+
99+
if(ANDROID)
100+
firebase_cpp_proguard_file(app_check)
101+
elseif(IOS)
102+
# Enable Automatic Reference Counting (ARC) and Bitcode.
103+
target_compile_options(firebase_app_check
104+
PUBLIC "-fobjc-arc" "-fembed-bitcode")
105+
target_link_libraries(firebase_app_check
106+
PUBLIC "-fembed-bitcode")
107+
108+
setup_pod_headers(
109+
firebase_app_check
110+
POD_NAMES
111+
FirebaseCore
112+
FirebaseAppCheck
113+
)
114+
115+
if (FIREBASE_XCODE_TARGET_FORMAT STREQUAL "frameworks")
116+
set_target_properties(firebase_app_check PROPERTIES
117+
FRAMEWORK TRUE
118+
)
119+
endif()
120+
endif()
121+
122+
cpp_pack_library(firebase_app_check "")
123+
cpp_pack_public_headers()

app_check/build.gradle

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright 2022 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+
buildscript {
16+
repositories {
17+
google()
18+
mavenCentral()
19+
}
20+
dependencies {
21+
classpath 'com.android.tools.build:gradle:3.3.3'
22+
}
23+
}
24+
allprojects {
25+
repositories {
26+
google()
27+
mavenCentral()
28+
}
29+
}
30+
31+
apply plugin: 'com.android.library'
32+
33+
android {
34+
compileSdkVersion 28
35+
buildToolsVersion '28.0.3'
36+
37+
sourceSets {
38+
main {
39+
manifest.srcFile '../android_build_files/AndroidManifest.xml'
40+
}
41+
}
42+
43+
externalNativeBuild {
44+
cmake {
45+
path '../CMakeLists.txt'
46+
}
47+
}
48+
49+
defaultConfig {
50+
minSdkVersion 19
51+
targetSdkVersion 28
52+
versionCode 1
53+
versionName "1.0"
54+
55+
buildTypes {
56+
release {
57+
minifyEnabled false
58+
}
59+
}
60+
61+
externalNativeBuild {
62+
cmake {
63+
targets 'firebase_app_check'
64+
// Args are: Re-use app library prebuilt by app gradle project.
65+
// Don't configure all the cmake subprojects.
66+
// Only include needed project.
67+
arguments '-DFIREBASE_CPP_USE_PRIOR_GRADLE_BUILD=ON',
68+
'-DFIREBASE_INCLUDE_LIBRARY_DEFAULT=OFF',
69+
'-DFIREBASE_INCLUDE_APP_CHECK=ON'
70+
}
71+
}
72+
}
73+
74+
lintOptions {
75+
abortOnError false
76+
}
77+
}
78+
79+
dependencies {
80+
implementation project(':app')
81+
}
82+
apply from: "$rootDir/android_build_files/android_abis.gradle"
83+
apply from: "$rootDir/android_build_files/generate_proguard.gradle"
84+
project.afterEvaluate {
85+
generateProguardFile('app_check')
86+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2022 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+
#include "app_check/src/android/app_check_android.h"
16+
17+
#include "app_check/src/common/common.h"
18+
19+
namespace firebase {
20+
namespace app_check {
21+
namespace internal {
22+
23+
static AppCheckProviderFactory* g_provider_factory = nullptr;
24+
25+
AppCheckInternal::AppCheckInternal(App* app) : app_(app) {
26+
future_manager().AllocFutureApi(this, kAppCheckFnCount);
27+
}
28+
29+
AppCheckInternal::~AppCheckInternal() {
30+
future_manager().ReleaseFutureApi(this);
31+
app_ = nullptr;
32+
}
33+
34+
::firebase::App* AppCheckInternal::app() const { return app_; }
35+
36+
ReferenceCountedFutureImpl* AppCheckInternal::future() {
37+
return future_manager().GetFutureApi(this);
38+
}
39+
40+
void AppCheckInternal::SetAppCheckProviderFactory(
41+
AppCheckProviderFactory* factory) {
42+
g_provider_factory = factory;
43+
}
44+
45+
void AppCheckInternal::SetTokenAutoRefreshEnabled(
46+
bool is_token_auto_refresh_enabled) {}
47+
48+
Future<AppCheckToken> AppCheckInternal::GetAppCheckToken(bool force_refresh) {
49+
auto handle = future()->SafeAlloc<AppCheckToken>(kAppCheckFnGetAppCheckToken);
50+
AppCheckToken token;
51+
future()->CompleteWithResult(handle, 0, token);
52+
return MakeFuture(future(), handle);
53+
}
54+
55+
Future<AppCheckToken> AppCheckInternal::GetAppCheckTokenLastResult() {
56+
return static_cast<const Future<AppCheckToken>&>(
57+
future()->LastResult(kAppCheckFnGetAppCheckToken));
58+
}
59+
60+
void AppCheckInternal::AddAppCheckListener(AppCheckListener* listener) {}
61+
62+
void AppCheckInternal::RemoveAppCheckListener(AppCheckListener* listener) {}
63+
64+
} // namespace internal
65+
} // namespace app_check
66+
} // namespace firebase
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2022 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+
#ifndef FIREBASE_APP_CHECK_SRC_ANDROID_APP_CHECK_ANDROID_H_
16+
#define FIREBASE_APP_CHECK_SRC_ANDROID_APP_CHECK_ANDROID_H_
17+
18+
#include "app/src/future_manager.h"
19+
#include "app/src/include/firebase/app.h"
20+
#include "app/src/include/firebase/future.h"
21+
#include "app_check/src/include/firebase/app_check.h"
22+
23+
namespace firebase {
24+
namespace app_check {
25+
namespace internal {
26+
27+
class AppCheckInternal {
28+
public:
29+
explicit AppCheckInternal(::firebase::App* app);
30+
31+
~AppCheckInternal();
32+
33+
App* app() const;
34+
35+
static void SetAppCheckProviderFactory(AppCheckProviderFactory* factory);
36+
37+
void SetTokenAutoRefreshEnabled(bool is_token_auto_refresh_enabled);
38+
39+
Future<AppCheckToken> GetAppCheckToken(bool force_refresh);
40+
41+
Future<AppCheckToken> GetAppCheckTokenLastResult();
42+
43+
void AddAppCheckListener(AppCheckListener* listener);
44+
45+
void RemoveAppCheckListener(AppCheckListener* listener);
46+
47+
FutureManager& future_manager() { return future_manager_; }
48+
49+
ReferenceCountedFutureImpl* future();
50+
51+
private:
52+
::firebase::App* app_;
53+
54+
FutureManager future_manager_;
55+
};
56+
57+
} // namespace internal
58+
} // namespace app_check
59+
} // namespace firebase
60+
61+
#endif // FIREBASE_APP_CHECK_SRC_ANDROID_APP_CHECK_ANDROID_H_

0 commit comments

Comments
 (0)