package com.facebook; import android.os.Parcel; import android.os.Parcelable; import com.facebook.AuthenticationTokenClaims; import com.facebook.internal.Validate; import com.facebook.internal.security.OidcSecurityUtil; import com.ironsource.mediationsdk.logger.IronSourceError; import csdk.gluads.Consts; import java.io.IOException; import java.security.spec.InvalidKeySpecException; import java.util.List; import kotlin.jvm.internal.DefaultConstructorMarker; import kotlin.jvm.internal.Intrinsics; import kotlin.text.StringsKt__StringsKt; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes2.dex */ public final class AuthenticationToken implements Parcelable { public static final String AUTHENTICATION_TOKEN_KEY = "id_token"; private static final String CLAIMS_KEY = "claims"; private static final String EXPECTED_NONCE_KEY = "expected_nonce"; private static final String HEADER_KEY = "header"; private static final String SIGNATURE_KEY = "signature"; private static final String TOKEN_STRING_KEY = "token_string"; private final AuthenticationTokenClaims claims; private final String expectedNonce; private final AuthenticationTokenHeader header; private final String signature; private final String token; public static final Companion Companion = new Companion(null); public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { // from class: com.facebook.AuthenticationToken$Companion$CREATOR$1 /* JADX WARN: Can't rename method to resolve collision */ @Override // android.os.Parcelable.Creator public AuthenticationToken createFromParcel(Parcel source) { Intrinsics.checkNotNullParameter(source, "source"); return new AuthenticationToken(source); } /* JADX WARN: Can't rename method to resolve collision */ @Override // android.os.Parcelable.Creator public AuthenticationToken[] newArray(int i) { return new AuthenticationToken[i]; } }; public static final AuthenticationToken getCurrentAuthenticationToken() { return Companion.getCurrentAuthenticationToken(); } public static final void setCurrentAuthenticationToken(AuthenticationToken authenticationToken) { Companion.setCurrentAuthenticationToken(authenticationToken); } @Override // android.os.Parcelable public int describeContents() { return 0; } public final AuthenticationTokenClaims getClaims() { return this.claims; } public final String getExpectedNonce() { return this.expectedNonce; } public final AuthenticationTokenHeader getHeader() { return this.header; } public final String getSignature() { return this.signature; } public final String getToken() { return this.token; } public AuthenticationToken(String token, String expectedNonce) { List split$default; Intrinsics.checkNotNullParameter(token, "token"); Intrinsics.checkNotNullParameter(expectedNonce, "expectedNonce"); Validate.notEmpty(token, "token"); Validate.notEmpty(expectedNonce, "expectedNonce"); split$default = StringsKt__StringsKt.split$default((CharSequence) token, new String[]{Consts.STRING_PERIOD}, false, 0, 6, (Object) null); if (!(split$default.size() == 3)) { throw new IllegalArgumentException("Invalid IdToken string".toString()); } String str = (String) split$default.get(0); String str2 = (String) split$default.get(1); String str3 = (String) split$default.get(2); this.token = token; this.expectedNonce = expectedNonce; AuthenticationTokenHeader authenticationTokenHeader = new AuthenticationTokenHeader(str); this.header = authenticationTokenHeader; this.claims = new AuthenticationTokenClaims(str2, expectedNonce); if (!isValidSignature(str, str2, str3, authenticationTokenHeader.getKid())) { throw new IllegalArgumentException("Invalid Signature".toString()); } this.signature = str3; } public AuthenticationToken(Parcel parcel) { Intrinsics.checkNotNullParameter(parcel, "parcel"); this.token = Validate.notNullOrEmpty(parcel.readString(), "token"); this.expectedNonce = Validate.notNullOrEmpty(parcel.readString(), "expectedNonce"); Parcelable readParcelable = parcel.readParcelable(AuthenticationTokenHeader.class.getClassLoader()); if (readParcelable == null) { throw new IllegalStateException("Required value was null.".toString()); } this.header = (AuthenticationTokenHeader) readParcelable; Parcelable readParcelable2 = parcel.readParcelable(AuthenticationTokenClaims.class.getClassLoader()); if (readParcelable2 == null) { throw new IllegalStateException("Required value was null.".toString()); } this.claims = (AuthenticationTokenClaims) readParcelable2; this.signature = Validate.notNullOrEmpty(parcel.readString(), "signature"); } public AuthenticationToken(JSONObject jsonObject) throws JSONException { Intrinsics.checkNotNullParameter(jsonObject, "jsonObject"); String string = jsonObject.getString(TOKEN_STRING_KEY); Intrinsics.checkNotNullExpressionValue(string, "jsonObject.getString(TOKEN_STRING_KEY)"); this.token = string; String string2 = jsonObject.getString(EXPECTED_NONCE_KEY); Intrinsics.checkNotNullExpressionValue(string2, "jsonObject.getString(EXPECTED_NONCE_KEY)"); this.expectedNonce = string2; String string3 = jsonObject.getString("signature"); Intrinsics.checkNotNullExpressionValue(string3, "jsonObject.getString(SIGNATURE_KEY)"); this.signature = string3; JSONObject headerJSONObject = jsonObject.getJSONObject(HEADER_KEY); JSONObject claimsJSONObject = jsonObject.getJSONObject(CLAIMS_KEY); Intrinsics.checkNotNullExpressionValue(headerJSONObject, "headerJSONObject"); this.header = new AuthenticationTokenHeader(headerJSONObject); AuthenticationTokenClaims.Companion companion = AuthenticationTokenClaims.Companion; Intrinsics.checkNotNullExpressionValue(claimsJSONObject, "claimsJSONObject"); this.claims = companion.createFromJSONObject$facebook_core_release(claimsJSONObject); } public final JSONObject toJSONObject$facebook_core_release() throws JSONException { JSONObject jSONObject = new JSONObject(); jSONObject.put(TOKEN_STRING_KEY, this.token); jSONObject.put(EXPECTED_NONCE_KEY, this.expectedNonce); jSONObject.put(HEADER_KEY, this.header.toJSONObject$facebook_core_release()); jSONObject.put(CLAIMS_KEY, this.claims.toJSONObject$facebook_core_release()); jSONObject.put("signature", this.signature); return jSONObject; } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof AuthenticationToken)) { return false; } AuthenticationToken authenticationToken = (AuthenticationToken) obj; return Intrinsics.areEqual(this.token, authenticationToken.token) && Intrinsics.areEqual(this.expectedNonce, authenticationToken.expectedNonce) && Intrinsics.areEqual(this.header, authenticationToken.header) && Intrinsics.areEqual(this.claims, authenticationToken.claims) && Intrinsics.areEqual(this.signature, authenticationToken.signature); } public int hashCode() { return ((((((((IronSourceError.ERROR_NON_EXISTENT_INSTANCE + this.token.hashCode()) * 31) + this.expectedNonce.hashCode()) * 31) + this.header.hashCode()) * 31) + this.claims.hashCode()) * 31) + this.signature.hashCode(); } @Override // android.os.Parcelable public void writeToParcel(Parcel dest, int i) { Intrinsics.checkNotNullParameter(dest, "dest"); dest.writeString(this.token); dest.writeString(this.expectedNonce); dest.writeParcelable(this.header, i); dest.writeParcelable(this.claims, i); dest.writeString(this.signature); } private final boolean isValidSignature(String str, String str2, String str3, String str4) { try { String rawKeyFromEndPoint = OidcSecurityUtil.getRawKeyFromEndPoint(str4); if (rawKeyFromEndPoint == null) { return false; } return OidcSecurityUtil.verify(OidcSecurityUtil.getPublicKeyFromString(rawKeyFromEndPoint), str + '.' + str2, str3); } catch (IOException | InvalidKeySpecException unused) { return false; } } public static final class Companion { public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } private Companion() { } public final AuthenticationToken getCurrentAuthenticationToken() { return AuthenticationTokenManager.Companion.getInstance().getCurrentAuthenticationToken(); } public final void setCurrentAuthenticationToken(AuthenticationToken authenticationToken) { AuthenticationTokenManager.Companion.getInstance().setCurrentAuthenticationToken(authenticationToken); } } }