Skip to content
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ff204f3
App Attest provider: attestation sequence (#7971)
maksymmalyhin Apr 26, 2021
869f87c
Implement app attest key ID storage (#8014)
ncooke3 May 3, 2021
f2b77f0
Merge branch 'master' into appcheck-appattest-main
maksymmalyhin May 4, 2021
39ae2d3
App Check App Attest workflow updates: initial handshake (#8032)
maksymmalyhin May 5, 2021
ccac49c
FIRAppAttestArtifactStorage implementation and tests (#8041)
maksymmalyhin May 5, 2021
c7558b5
Implement App Attest `getRandomChallenge` (#8033)
ncooke3 May 6, 2021
e7f1ff8
Merge branch 'master' into appcheck-appattest-main
maksymmalyhin May 6, 2021
ed07e4b
Define Exchange AppAttest Assertion for FAC token API (#8058)
ncooke3 May 11, 2021
67b5c3a
Merge branch 'master' into appcheck-appattest-main
maksymmalyhin May 11, 2021
786f613
App Check App Attest: attestation request (#8059)
maksymmalyhin May 12, 2021
6742e33
Merge branch 'master' into appcheck-appattest-main
maksymmalyhin May 12, 2021
a35d7bd
App Check App Attest initial handshake adjustments (#8067)
maksymmalyhin May 12, 2021
2b16a5f
Merge remote-tracking branch 'origin/master' into appcheck-appattest-…
maksymmalyhin May 13, 2021
c2bb06b
Implement API for ExchangeAppAttestAssertionRequest endpoint (#8065)
ncooke3 May 13, 2021
cd53ea8
Merge remote-tracking branch 'origin/master' into appcheck-appattest-…
maksymmalyhin May 14, 2021
e04a789
Merge branch 'appcheck-appattest-main' of github.com:firebase/firebas…
maksymmalyhin May 14, 2021
ac17a23
App Check App Attest assertion flow (#8083)
maksymmalyhin May 17, 2021
b9d638e
Merge remote-tracking branch 'origin/master' into appcheck-appattest-…
maksymmalyhin May 17, 2021
cea2f68
App Check: store App Attest artifact per key ID (#8097)
maksymmalyhin May 18, 2021
2b70bf0
App Check: prevent concurrent token requests (#8117)
maksymmalyhin May 21, 2021
f134778
Merge remote-tracking branch 'origin/master' into appcheck-appattest-…
maksymmalyhin May 21, 2021
2102187
Changelog
maksymmalyhin May 21, 2021
c0650aa
Merge branch 'master' into appcheck-appattest-main
maksymmalyhin May 31, 2021
b8f80f3
App Check App Attest: handle attestation rejection (#8170)
maksymmalyhin Jun 1, 2021
76486af
Add FIRAppAttestProvider.h the umbrella header
maksymmalyhin Jun 1, 2021
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 @@ -26,32 +26,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
.LaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()

guard let firebaseApp = FirebaseApp.app() else {
return true
}

FIRDeviceCheckProvider(app: firebaseApp)?.getToken(completion: { token, error in
if let token = token {
print("DeviceCheck token: \(token.token), expiration date: \(token.expirationDate)")
}

if let error = error {
print("DeviceCheck error: \((error as NSError).userInfo)")
}
})

if let debugProvider = FIRAppCheckDebugProvider(app: firebaseApp) {
print("Debug token: \(debugProvider.currentDebugToken())")
requestDeviceCheckToken()

debugProvider.getToken(completion: { token, error in
if let token = token {
print("Debug FAC token: \(token.token), expiration date: \(token.expirationDate)")
}
requestDebugToken()

if let error = error {
print("Debug error: \(error)")
}
})
if #available(iOS 14.0, *) {
requestAppAttestToken()
}

return true
Expand All @@ -76,4 +56,64 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}

// MARK: App Check providers

func requestDeviceCheckToken() {
guard let firebaseApp = FirebaseApp.app() else {
return
}

DeviceCheckProvider(app: firebaseApp)?.getToken { token, error in
if let token = token {
print("DeviceCheck token: \(token.token), expiration date: \(token.expirationDate)")
}

if let error = error {
print("DeviceCheck error: \((error as NSError).userInfo)")
}
}
}

func requestDebugToken() {
guard let firebaseApp = FirebaseApp.app() else {
return
}

if let debugProvider = AppCheckDebugProvider(app: firebaseApp) {
print("Debug token: \(debugProvider.currentDebugToken())")

debugProvider.getToken { token, error in
if let token = token {
print("Debug FAC token: \(token.token), expiration date: \(token.expirationDate)")
}

if let error = error {
print("Debug error: \(error)")
}
}
}
}

@available(iOS 14.0, *)
func requestAppAttestToken() {
guard let firebaseApp = FirebaseApp.app() else {
return
}

guard let appAttestProvider = AppAttestProvider(app: firebaseApp) else {
print("Failed to instantiate AppAttestProvider")
return
}

appAttestProvider.getToken { token, error in
if let token = token {
print("App Attest FAC token: \(token.token), expiration date: \(token.expirationDate)")
}

if let error = error {
print("App Attest error: \(error)")
}
}
}
}
2 changes: 0 additions & 2 deletions FirebaseAppCheck/Apps/FIRAppCheckTestApp/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ target 'FIRAppCheckTestApp' do
pod 'FirebaseAppCheck', :path => '../../../'

pod 'FirebaseCore', :path => '../../../'
Copy link
Member

Choose a reason for hiding this comment

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

Not for this PR, but there should be a build test in CI to keep this unstale.

pod 'GoogleUtilities', :path => '../../../'
pod 'FirebaseCoreDiagnostics', :path => '../../../'
pod 'GoogleDataTransport', :path => '../../../'
end
2 changes: 2 additions & 0 deletions FirebaseAppCheck/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# 8.1.0 -- M97
- [added] Apple's App Attest attestation provider support. (#8133)
# v8.0.0 -- M95
- [added] Firebase abuse reduction support SDK. (#7928, #7937, #7948)
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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.
*/

#import <Foundation/Foundation.h>

@class FBLPromise<Result>;
@class FIRAppAttestAttestationResponse;
@class FIRAppCheckToken;
@protocol FIRAppCheckAPIServiceProtocol;

NS_ASSUME_NONNULL_BEGIN

/// Methods to send API requests required for App Attest based attestation sequence.
@protocol FIRAppAttestAPIServiceProtocol <NSObject>

/// Request a random challenge from server.
- (FBLPromise<NSData *> *)getRandomChallenge;

/// Sends attestation data to Firebase backend for validation.
/// @param attestation The App Attest key attestation data obtained from the method
/// `-[DCAppAttestService attestKey:clientDataHash:completionHandler:]` using the random challenge
/// received from Firebase backend.
/// @param keyID The key ID used to generate the attestation.
/// @param challenge The challenge used to generate the attestation.
/// @return A promise that is fulfilled with a response object with an encrypted attestation
/// artifact and an Firebase App Check token or rejected with an error.
- (FBLPromise<FIRAppAttestAttestationResponse *> *)attestKeyWithAttestation:(NSData *)attestation
keyID:(NSString *)keyID
challenge:(NSData *)challenge;

/// Exchanges attestation data (artifact & assertion) and a challenge for a FAC token.
- (FBLPromise<FIRAppCheckToken *> *)getAppCheckTokenWithArtifact:(NSData *)artifact
Comment on lines +40 to +45
Copy link
Member

Choose a reason for hiding this comment

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

Following this conversation we had, I had changed appCheckTokenWith to getAppCheckTokenWith. Reevaluating now, are you content with the style of the APIs here? I wasn't sure if its preferred to do nothing, prefix attestKeyWithAttestatation with get, or revert getAppCheckTokenWith to appCheckTokenWith

Copy link
Member

Choose a reason for hiding this comment

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

This is obviously pretty minor, but I had remembered it and wanted to bring up in case you now feel more strongly about one way or another.

challenge:(NSData *)challenge
assertion:(NSData *)assertion;

@end

/// A default implementation of `FIRAppAttestAPIServiceProtocol`.
@interface FIRAppAttestAPIService : NSObject <FIRAppAttestAPIServiceProtocol>

/// Default initializer.
/// @param APIService An instance implementing `FIRAppCheckAPIServiceProtocol` to be used to send
/// network requests to Firebase App Check backend.
/// @param projectID A Firebase project ID for the requests (`FIRApp.options.projectID`).
/// @param appID A Firebase app ID for the requests (`FIRApp.options.googleAppID`).
- (instancetype)initWithAPIService:(id<FIRAppCheckAPIServiceProtocol>)APIService
projectID:(NSString *)projectID
appID:(NSString *)appID;

@end

NS_ASSUME_NONNULL_END
Loading