Skip to content
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

Added view of trusted issuer certificates to verifier app #391

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.android.mdl.appreader.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedCard
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.unit.dp
import androidx.fragment.app.Fragment
import com.android.mdl.appreader.theme.ReaderAppTheme
import com.android.mdl.appreader.util.KeysAndCertificates
import java.security.cert.X509Certificate
import java.time.Instant

class ViewTruststoreFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
): View {
val trustedCertificates = KeysAndCertificates.getTrustedIssuerCertificates(requireContext())
return ComposeView(requireContext()).apply {
setContent {
ReaderAppTheme {
CertificatesList(trustedCertificates)
}
}
}
}
}

@Composable
private fun CertificatesList(certificates: List<X509Certificate>) {
val now = Instant.now()
val padding = Modifier.padding(horizontal = 2.dp)
val colorRegular = MaterialTheme.colorScheme.onBackground
val colorError = MaterialTheme.colorScheme.error

Column(modifier = Modifier.verticalScroll(state = rememberScrollState())) {
certificates.forEach { certificate ->
OutlinedCard(modifier = Modifier.fillMaxWidth()) {
Text(
text = certificate.subjectDN.toString(),
style = MaterialTheme.typography.bodyMedium,
color = colorRegular,
modifier = padding
)
Text(
text = "Not before: " + certificate.notBefore.toString(),
style = MaterialTheme.typography.bodyMedium,
color = if (now > certificate.notBefore.toInstant()) colorRegular else colorError,
modifier = padding
)
Text(
text = "Not after: " + certificate.notAfter.toString(),
style = MaterialTheme.typography.bodyMedium,
color = if (now < certificate.notAfter.toInstant()) colorRegular else colorError,
modifier = padding
)
}
}
}
}
7 changes: 7 additions & 0 deletions appverifier/src/main/res/drawable/ic_truststore.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="@android:color/white" android:pathData="M12.65,10C11.83,7.67 9.61,6 7,6c-3.31,0 -6,2.69 -6,6s2.69,6 6,6c2.61,0 4.83,-1.67 5.65,-4H17v4h4v-4h2v-4H12.65zM7,14c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2z"/>
</vector>
7 changes: 6 additions & 1 deletion appverifier/src/main/res/menu/side_navigation_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
android:enabled="true"
android:icon="@drawable/ic_present_document"
android:title="@string/menu_reverse_engagement" />

<item
android:id="@+id/viewTruststore"
android:checkable="true"
android:enabled="true"
android:icon="@drawable/ic_truststore"
android:title="@string/menu_view_truststore" />
<item
android:id="@+id/settings"
android:checkable="true"
Expand Down
8 changes: 8 additions & 0 deletions appverifier/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,12 @@
android:id="@+id/action_ShowQr_to_Transfer"
app:destination="@id/transfer" />
</fragment>
<fragment
android:id="@+id/viewTruststore"
android:name="com.android.mdl.appreader.fragment.ViewTruststoreFragment"
android:label="View Truststore">
<action
android:id="@+id/action_viewTruststoreFragment_to_RequestOptions"
app:destination="@id/requestOptions" />
</fragment>
</navigation>
1 change: 1 addition & 0 deletions appverifier/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,6 @@
<string name="menu_reader_home">Home</string>
<string name="menu_reverse_engagement">Reverse Engagement</string>
<string name="menu_settings">Settings</string>
<string name="menu_view_truststore">View Truststore</string>

</resources>
Loading