GACAppAttestAPIService.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 GACAppAttestAttestationResponse;
  19. @class GACAppCheckToken;
  20. @protocol GACAppCheckAPIServiceProtocol;
  21. NS_ASSUME_NONNULL_BEGIN
  22. /// Methods to send API requests required for App Attest based attestation sequence.
  23. @protocol GACAppAttestAPIServiceProtocol <NSObject>
  24. /// Request a random challenge from server.
  25. - (FBLPromise<NSData *> *)getRandomChallenge;
  26. /// Sends attestation data to the App Check 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 App Check 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 App Check token or rejected with an error.
  34. - (FBLPromise<GACAppAttestAttestationResponse *> *)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<GACAppCheckToken *> *)getAppCheckTokenWithArtifact:(NSData *)artifact
  39. challenge:(NSData *)challenge
  40. assertion:(NSData *)assertion;
  41. @end
  42. /// A default implementation of `GACAppAttestAPIServiceProtocol`.
  43. @interface GACAppAttestAPIService : NSObject <GACAppAttestAPIServiceProtocol>
  44. /// Default initializer.
  45. ///
  46. /// TODO(andrewheard): Remove or refactor the `limitedUse` parameter from this constructor when the
  47. /// short-lived (limited-use) token feature is fully implemented.
  48. ///
  49. /// @param APIService An instance implementing `GACAppCheckAPIServiceProtocol` to be used to send
  50. /// network requests to the App Check backend.
  51. /// @param resourceName The name of the resource protected by App Check; for a Firebase App this is
  52. /// "projects/{project_id}/apps/{app_id}".
  53. /// @param limitedUse If YES, forces a short-lived token with a 5 minute TTL.
  54. - (instancetype)initWithAPIService:(id<GACAppCheckAPIServiceProtocol>)APIService
  55. resourceName:(NSString *)resourceName
  56. limitedUse:(BOOL)limitedUse NS_DESIGNATED_INITIALIZER;
  57. - (instancetype)init NS_UNAVAILABLE;
  58. @end
  59. NS_ASSUME_NONNULL_END