-
Notifications
You must be signed in to change notification settings - Fork 617
Implement Play Integrity attestation flow. #3618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2ddbaf3
Add method to call the `GeneratePlayIntegrityChallenge` endpoint to `…
rosalyntan 1341ce7
Implement Play Integrity attestation flow.
rosalyntan 4847c42
Add project number to IntegrityTokenRequest.
rosalyntan 5fc39cd
Fix `PlayIntegrityAppCheckProviderTest`s.
rosalyntan db5b277
Add unit tests.
rosalyntan cd7b81e
Address review comments.
rosalyntan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...oogle/firebase/appcheck/playintegrity/internal/GeneratePlayIntegrityChallengeRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2022 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. | ||
|
||
package com.google.firebase.appcheck.playintegrity.internal; | ||
|
||
import androidx.annotation.NonNull; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
/** | ||
* Client-side model of the GeneratePlayIntegrityChallengeRequest payload from the Firebase App | ||
* Check Token Exchange API. | ||
*/ | ||
public class GeneratePlayIntegrityChallengeRequest { | ||
|
||
public GeneratePlayIntegrityChallengeRequest() {} | ||
|
||
@NonNull | ||
public String toJsonString() throws JSONException { | ||
JSONObject jsonObject = new JSONObject(); | ||
|
||
return jsonObject.toString(); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...ogle/firebase/appcheck/playintegrity/internal/GeneratePlayIntegrityChallengeResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2022 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. | ||
|
||
package com.google.firebase.appcheck.playintegrity.internal; | ||
|
||
import static com.google.android.gms.common.internal.Preconditions.checkNotNull; | ||
import static com.google.android.gms.common.util.Strings.emptyToNull; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.VisibleForTesting; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
/** | ||
* Client-side model of the GeneratePlayIntegrityChallengeResponse payload from the Firebase App | ||
* Check Token Exchange API. | ||
*/ | ||
public class GeneratePlayIntegrityChallengeResponse { | ||
|
||
@VisibleForTesting static final String CHALLENGE_KEY = "challenge"; | ||
@VisibleForTesting static final String TIME_TO_LIVE_KEY = "ttl"; | ||
|
||
private String challenge; | ||
private String timeToLive; | ||
|
||
@NonNull | ||
public static GeneratePlayIntegrityChallengeResponse fromJsonString(@NonNull String jsonString) | ||
throws JSONException { | ||
JSONObject jsonObject = new JSONObject(jsonString); | ||
String challenge = emptyToNull(jsonObject.optString(CHALLENGE_KEY)); | ||
rosalyntan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
String timeToLive = emptyToNull(jsonObject.optString(TIME_TO_LIVE_KEY)); | ||
return new GeneratePlayIntegrityChallengeResponse(challenge, timeToLive); | ||
} | ||
|
||
private GeneratePlayIntegrityChallengeResponse( | ||
@NonNull String challenge, @NonNull String timeToLive) { | ||
checkNotNull(challenge); | ||
checkNotNull(timeToLive); | ||
this.challenge = challenge; | ||
this.timeToLive = timeToLive; | ||
} | ||
|
||
@NonNull | ||
public String getChallenge() { | ||
return challenge; | ||
} | ||
|
||
@NonNull | ||
public String getTimeToLive() { | ||
return timeToLive; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...e/firebase/appcheck/playintegrity/internal/GeneratePlayIntegrityChallengeRequestTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2022 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. | ||
|
||
package com.google.firebase.appcheck.playintegrity.internal; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.annotation.Config; | ||
|
||
/** Tests for {@link GeneratePlayIntegrityChallengeRequest}. */ | ||
@RunWith(RobolectricTestRunner.class) | ||
@Config(manifest = Config.NONE) | ||
public class GeneratePlayIntegrityChallengeRequestTest { | ||
private static final String EMPTY_JSON = "{}"; | ||
|
||
@Test | ||
public void toJsonString_expectSerialized() throws Exception { | ||
GeneratePlayIntegrityChallengeRequest generatePlayIntegrityChallengeRequest = | ||
new GeneratePlayIntegrityChallengeRequest(); | ||
|
||
assertThat(generatePlayIntegrityChallengeRequest.toJsonString()).isEqualTo(EMPTY_JSON); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
.../firebase/appcheck/playintegrity/internal/GeneratePlayIntegrityChallengeResponseTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2022 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. | ||
|
||
package com.google.firebase.appcheck.playintegrity.internal; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
import org.json.JSONObject; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.annotation.Config; | ||
|
||
/** Tests for {@link GeneratePlayIntegrityChallengeResponse}. */ | ||
@RunWith(RobolectricTestRunner.class) | ||
@Config(manifest = Config.NONE) | ||
public class GeneratePlayIntegrityChallengeResponseTest { | ||
private static final String CHALLENGE = "testChallenge"; | ||
private static final String TIME_TO_LIVE = "3600s"; | ||
|
||
@Test | ||
public void fromJsonString_expectDeserialized() throws Exception { | ||
JSONObject jsonObject = new JSONObject(); | ||
jsonObject.put(GeneratePlayIntegrityChallengeResponse.CHALLENGE_KEY, CHALLENGE); | ||
jsonObject.put(GeneratePlayIntegrityChallengeResponse.TIME_TO_LIVE_KEY, TIME_TO_LIVE); | ||
|
||
GeneratePlayIntegrityChallengeResponse generatePlayIntegrityChallengeResponse = | ||
GeneratePlayIntegrityChallengeResponse.fromJsonString(jsonObject.toString()); | ||
assertThat(generatePlayIntegrityChallengeResponse.getChallenge()).isEqualTo(CHALLENGE); | ||
assertThat(generatePlayIntegrityChallengeResponse.getTimeToLive()).isEqualTo(TIME_TO_LIVE); | ||
} | ||
|
||
@Test | ||
public void fromJsonString_nullChallenge_throwsException() throws Exception { | ||
JSONObject jsonObject = new JSONObject(); | ||
jsonObject.put(GeneratePlayIntegrityChallengeResponse.TIME_TO_LIVE_KEY, TIME_TO_LIVE); | ||
|
||
assertThrows( | ||
NullPointerException.class, | ||
() -> GeneratePlayIntegrityChallengeResponse.fromJsonString(jsonObject.toString())); | ||
} | ||
|
||
@Test | ||
public void fromJsonString_nullTimeToLive_throwsException() throws Exception { | ||
JSONObject jsonObject = new JSONObject(); | ||
jsonObject.put(GeneratePlayIntegrityChallengeResponse.CHALLENGE_KEY, CHALLENGE); | ||
|
||
assertThrows( | ||
NullPointerException.class, | ||
() -> GeneratePlayIntegrityChallengeResponse.fromJsonString(jsonObject.toString())); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.