aboutsummaryrefslogtreecommitdiff
path: root/java/com/android/libraries/entitlement/EapAkaHelper.java
diff options
context:
space:
mode:
authorMeng Wang <mewan@google.com>2021-05-21 19:16:40 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-05-21 19:16:40 +0000
commit3ca49542c51320b53304f5b3ddffe6794d2a8d3b (patch)
tree8de3a4a4bb98799d6c17b94f7e1b092619913045 /java/com/android/libraries/entitlement/EapAkaHelper.java
parent8ea26fc1a78f0d0c0bed13340bf0fb17c2ed4664 (diff)
parenta20e0b1f99b544318cdb7db413250ad9f3234b04 (diff)
downloadservice_entitlement-3ca49542c51320b53304f5b3ddffe6794d2a8d3b.tar.gz
Support Synchronization-Failure handling am: 9b3163d05b am: 9d405073c5 am: a20e0b1f99
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/libs/service_entitlement/+/14652377 Change-Id: I5486ef9028f31e88530686b4ecbeefbf19353c88
Diffstat (limited to 'java/com/android/libraries/entitlement/EapAkaHelper.java')
-rw-r--r--java/com/android/libraries/entitlement/EapAkaHelper.java63
1 files changed, 58 insertions, 5 deletions
diff --git a/java/com/android/libraries/entitlement/EapAkaHelper.java b/java/com/android/libraries/entitlement/EapAkaHelper.java
index 05c3964..3db48e1 100644
--- a/java/com/android/libraries/entitlement/EapAkaHelper.java
+++ b/java/com/android/libraries/entitlement/EapAkaHelper.java
@@ -16,6 +16,8 @@
package com.android.libraries.entitlement;
+import static com.android.libraries.entitlement.eapaka.EapAkaResponse.respondToEapAkaChallenge;
+
import android.content.Context;
import android.telephony.TelephonyManager;
@@ -23,7 +25,6 @@ import androidx.annotation.Nullable;
import com.android.libraries.entitlement.eapaka.EapAkaApi;
import com.android.libraries.entitlement.eapaka.EapAkaChallenge;
-import com.android.libraries.entitlement.eapaka.EapAkaResponse;
/**
* Some utility methods used in EAP-AKA authentication in service entitlement, and could be
@@ -73,17 +74,69 @@ public class EapAkaHelper {
*
* <p>Both the challange and response are base-64 encoded EAP-AKA message: refer to
* RFC 4187 Section 8.1 Message Format/RFC 3748 Session 4 EAP Packet Format.
+ *
+ * @deprecated use {@link getEapAkaResponse(String)} which additionally supports
+ * Synchronization-Failure case.
*/
+ @Deprecated
@Nullable
public String getEapAkaChallengeResponse(String challenge) {
+ EapAkaResponse eapAkaResponse = getEapAkaResponse(challenge);
+ return (eapAkaResponse == null)
+ ? null
+ : eapAkaResponse.response(); // Would be null on synchrinization failure
+ }
+
+ /**
+ * Returns the {@link EapAkaResponse} to the given EAP-AKA {@code challenge}, or
+ * {@code null} if failed.
+ *
+ * <p>Both the challange and response are base-64 encoded EAP-AKA message: refer to
+ * RFC 4187 Section 8.1 Message Format/RFC 3748 Session 4 EAP Packet Format.
+ */
+ @Nullable
+ public EapAkaResponse getEapAkaResponse(String challenge) {
try {
EapAkaChallenge eapAkaChallenge = EapAkaChallenge.parseEapAkaChallenge(challenge);
- EapAkaResponse response =
- EapAkaResponse.respondToEapAkaChallenge(
- mContext, mSimSubscriptionId, eapAkaChallenge);
- return response.response(); // Would be null on synchrinization failure
+ com.android.libraries.entitlement.eapaka.EapAkaResponse eapAkaResponse =
+ respondToEapAkaChallenge(mContext, mSimSubscriptionId, eapAkaChallenge);
+ return new EapAkaResponse(
+ eapAkaResponse.response(), eapAkaResponse.synchronizationFailureResponse());
} catch (ServiceEntitlementException e) {
return null;
}
}
+
+ // Similar to .eapaka.EapAkaResponse but with simplfied API surface for external usage.
+ /** EAP-AKA response */
+ public static class EapAkaResponse {
+ // RFC 4187 Section 9.4 EAP-Response/AKA-Challenge
+ @Nullable private final String mResponse;
+ // RFC 4187 Section 9.6 EAP-Response/AKA-Synchronization-Failure
+ @Nullable private final String mSynchronizationFailureResponse;
+
+ private EapAkaResponse(
+ @Nullable String response, @Nullable String synchronizationFailureResponse) {
+ mResponse = response;
+ mSynchronizationFailureResponse = synchronizationFailureResponse;
+ }
+
+ /**
+ * Returns EAP-Response/AKA-Challenge, if authentication success.
+ * Otherwise {@code null}.
+ */
+ @Nullable
+ public String response() {
+ return mResponse;
+ }
+
+ /**
+ * Returns EAP-Response/AKA-Synchronization-Failure, if synchronization failure detected.
+ * Otherwise {@code null}.
+ */
+ @Nullable
+ public String synchronizationFailureResponse() {
+ return mSynchronizationFailureResponse;
+ }
+ }
}