FIRAppAttestAPIService.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #import <Foundation/Foundation.h>
  17. @class FBLPromise<Result>;
  18. @class FIRAppAttestAttestationResponse;
  19. @class FIRAppCheckToken;
  20. @protocol FIRAppCheckAPIServiceProtocol;
  21. NS_ASSUME_NONNULL_BEGIN
  22. /// Methods to send API requests required for App Attest based attestation sequence.
  23. @protocol FIRAppAttestAPIServiceProtocol <NSObject>
  24. /// Request a random challenge from server.
  25. - (FBLPromise<NSData *> *)getRandomChallenge;
  26. /// Sends attestation data to Firebase backend for validation.
  27. /// @param attestation The App Attest key attestation data obtained from the method
  28. /// `-[DCAppAttestService attestKey:clientDataHash:completionHandler:]` using the random challenge
  29. /// received from Firebase backend.
  30. /// @param keyID The key ID used to generate the attestation.
  31. /// @param challenge The challenge used to generate the attestation.
  32. /// @return A promise that is fulfilled with a response object with an encrypted attestation
  33. /// artifact and an Firebase App Check token or rejected with an error.
  34. - (FBLPromise<FIRAppAttestAttestationResponse *> *)attestKeyWithAttestation:(NSData *)attestation
  35. keyID:(NSString *)keyID
  36. challenge:(NSData *)challenge;
  37. /// Exchanges attestation data (artifact & assertion) and a challenge for a FAC token.
  38. - (FBLPromise<FIRAppCheckToken *> *)getAppCheckTokenWithArtifact:(NSData *)artifact
  39. challenge:(NSData *)challenge
  40. assertion:(NSData *)assertion;
  41. @end
  42. /// A default implementation of `FIRAppAttestAPIServiceProtocol`.
  43. @interface FIRAppAttestAPIService : NSObject <FIRAppAttestAPIServiceProtocol>
  44. /// Default initializer.
  45. /// @param APIService An instance implementing `FIRAppCheckAPIServiceProtocol` to be used to send
  46. /// network requests to Firebase App Check backend.
  47. /// @param projectID A Firebase project ID for the requests (`FIRApp.options.projectID`).
  48. /// @param appID A Firebase app ID for the requests (`FIRApp.options.googleAppID`).
  49. - (instancetype)initWithAPIService:(id<FIRAppCheckAPIServiceProtocol>)APIService
  50. projectID:(NSString *)projectID
  51. appID:(NSString *)appID;
  52. @end
  53. NS_ASSUME_NONNULL_END