diff --git a/attestation/src/main/java/com/stripe/attestation/IntegrityStandardRequestManager.kt b/attestation/src/main/java/com/stripe/attestation/IntegrityStandardRequestManager.kt index 4f427a41d83..f896675061c 100644 --- a/attestation/src/main/java/com/stripe/attestation/IntegrityStandardRequestManager.kt +++ b/attestation/src/main/java/com/stripe/attestation/IntegrityStandardRequestManager.kt @@ -17,7 +17,7 @@ import kotlin.coroutines.resume @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) class IntegrityStandardRequestManager( // TODO figure out GCP. - private val cloudProjectNumber: Long = 123456789L, + private val cloudProjectNumber: Long = 161414635700, private val buildRequestIdentifier: BuildRequestIdentifier = BuildRequestIdentifier(), appContext: Context ) { diff --git a/financial-connections/src/main/java/com/stripe/android/financialconnections/di/FinancialConnectionsSheetSharedModule.kt b/financial-connections/src/main/java/com/stripe/android/financialconnections/di/FinancialConnectionsSheetSharedModule.kt index 68854543db7..94269a6059b 100644 --- a/financial-connections/src/main/java/com/stripe/android/financialconnections/di/FinancialConnectionsSheetSharedModule.kt +++ b/financial-connections/src/main/java/com/stripe/android/financialconnections/di/FinancialConnectionsSheetSharedModule.kt @@ -92,7 +92,6 @@ internal interface FinancialConnectionsSheetSharedModule { context: Application ): IntegrityStandardRequestManager { return IntegrityStandardRequestManager( - cloudProjectNumber = 123456789L, buildRequestIdentifier = BuildRequestIdentifier(), appContext = context ) diff --git a/financial-connections/src/main/java/com/stripe/android/financialconnections/features/consent/ConsentViewModel.kt b/financial-connections/src/main/java/com/stripe/android/financialconnections/features/consent/ConsentViewModel.kt index 8cfcec85202..e5723077cb0 100644 --- a/financial-connections/src/main/java/com/stripe/android/financialconnections/features/consent/ConsentViewModel.kt +++ b/financial-connections/src/main/java/com/stripe/android/financialconnections/features/consent/ConsentViewModel.kt @@ -5,11 +5,8 @@ import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewmodel.initializer import androidx.lifecycle.viewmodel.viewModelFactory import com.stripe.android.core.Logger -import com.stripe.android.financialconnections.FinancialConnections -import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsEvent.ConsentAgree import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsEvent.PaneLoaded import com.stripe.android.financialconnections.analytics.FinancialConnectionsAnalyticsTracker -import com.stripe.android.financialconnections.analytics.FinancialConnectionsEvent.Name import com.stripe.android.financialconnections.analytics.logError import com.stripe.android.financialconnections.di.FinancialConnectionsSheetNativeComponent import com.stripe.android.financialconnections.domain.AcceptConsent @@ -26,7 +23,6 @@ import com.stripe.android.financialconnections.navigation.Destination.Companion. import com.stripe.android.financialconnections.navigation.Destination.ManualEntry import com.stripe.android.financialconnections.navigation.Destination.NetworkingLinkLoginWarmup import com.stripe.android.financialconnections.navigation.NavigationManager -import com.stripe.android.financialconnections.navigation.destination import com.stripe.android.financialconnections.navigation.topappbar.TopAppBarStateUpdate import com.stripe.android.financialconnections.presentation.FinancialConnectionsViewModel import com.stripe.android.financialconnections.ui.HandleClickableUrl @@ -34,6 +30,7 @@ import com.stripe.android.financialconnections.utils.Experiment.CONNECTIONS_CONS import com.stripe.android.financialconnections.utils.error import com.stripe.android.financialconnections.utils.experimentAssignment import com.stripe.android.financialconnections.utils.trackExposure +import com.stripe.attestation.IntegrityStandardRequestManager import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject @@ -48,6 +45,7 @@ internal class ConsentViewModel @AssistedInject constructor( private val navigationManager: NavigationManager, private val eventTracker: FinancialConnectionsAnalyticsTracker, private val handleClickableUrl: HandleClickableUrl, + private val standardRequestManager: IntegrityStandardRequestManager, private val logger: Logger, private val presentSheet: PresentSheet, ) : FinancialConnectionsViewModel(initialState, nativeAuthFlowCoordinator) { @@ -95,13 +93,24 @@ internal class ConsentViewModel @AssistedInject constructor( } fun onContinueClick() { - suspend { - eventTracker.track(ConsentAgree) - val updatedManifest: FinancialConnectionsSessionManifest = acceptConsent() - FinancialConnections.emitEvent(Name.CONSENT_ACQUIRED) - navigationManager.tryNavigateTo(updatedManifest.nextPane.destination(referrer = Pane.CONSENT)) - updatedManifest - }.execute { copy(acceptConsent = it) } + viewModelScope.launch { + val token: Result = standardRequestManager.requestToken("random_token") + runCatching { + verifyIntegrity(token.getOrThrow(), "com.random") + }.onFailure { + logger.error("Error verifying integrity", it) + }.onSuccess { + logger.info("Integrity verified successfully") + } + } + +// suspend { +// eventTracker.track(ConsentAgree) +// val updatedManifest: FinancialConnectionsSessionManifest = acceptConsent() +// FinancialConnections.emitEvent(Name.CONSENT_ACQUIRED) +// navigationManager.tryNavigateTo(updatedManifest.nextPane.destination(referrer = Pane.CONSENT)) +// updatedManifest +// }.execute { copy(acceptConsent = it) } } fun onClickableTextClick(uri: String) = viewModelScope.launch { diff --git a/financial-connections/src/main/java/com/stripe/android/financialconnections/features/consent/verifyIntegrity.kt b/financial-connections/src/main/java/com/stripe/android/financialconnections/features/consent/verifyIntegrity.kt new file mode 100644 index 00000000000..7a03e669a4b --- /dev/null +++ b/financial-connections/src/main/java/com/stripe/android/financialconnections/features/consent/verifyIntegrity.kt @@ -0,0 +1,51 @@ +package com.stripe.android.financialconnections.features.consent + +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext +import java.io.OutputStreamWriter +import java.net.HttpURLConnection +import java.net.URL +import java.net.URLEncoder + + +suspend fun verifyIntegrity(integrityToken: String, packageName: String) = withContext(Dispatchers.IO) { + val url = URL("https://attestation-android.glitch.me/verify-integrity") + val connection = url.openConnection() as HttpURLConnection + connection.requestMethod = "POST" + connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") + connection.setRequestProperty("Accept", "application/json") + connection.doOutput = true + connection.connectTimeout = 15000 + connection.readTimeout = 15000 + + // Constructing URL-encoded form data + val requestBody = "integrityToken=${URLEncoder.encode(integrityToken, "UTF-8")}" + + "&packageName=${URLEncoder.encode(packageName, "UTF-8")}" + + println("Request Payload: $requestBody") // Log the URL-encoded form data + + connection.outputStream.use { os -> + OutputStreamWriter(os, "UTF-8").use { writer -> + writer.write(requestBody) + writer.flush() + } + } + + val responseCode = connection.responseCode + val responseMessage: String + + if (responseCode == HttpURLConnection.HTTP_OK) { + responseMessage = connection.inputStream.bufferedReader().use { it.readText() } + } else { + responseMessage = connection.errorStream?.bufferedReader()?.use { + it.readText() + } ?: "Error occurred with response code: $responseCode" + println("Error response code: $responseCode - $responseMessage") + } + + connection.disconnect() + + println("Response Message: $responseMessage") + + responseMessage +} \ No newline at end of file diff --git a/financial-connections/src/main/java/com/stripe/android/financialconnections/repository/FinancialConnectionsManifestRepository.kt b/financial-connections/src/main/java/com/stripe/android/financialconnections/repository/FinancialConnectionsManifestRepository.kt index 6bf1df8f61e..b8d0a05698a 100644 --- a/financial-connections/src/main/java/com/stripe/android/financialconnections/repository/FinancialConnectionsManifestRepository.kt +++ b/financial-connections/src/main/java/com/stripe/android/financialconnections/repository/FinancialConnectionsManifestRepository.kt @@ -252,7 +252,7 @@ private class FinancialConnectionsManifestRepositoryImpl( ) ) - val token: Result = standardRequestManager.requestToken(financialConnectionsRequest) +// val token: Result = standardRequestManager.requestToken(financialConnectionsRequest) return requestExecutor.execute( financialConnectionsRequest,