Skip to content

Commit

Permalink
Add pkipath back
Browse files Browse the repository at this point in the history
  • Loading branch information
vvb2060 committed Nov 15, 2023
1 parent bb82068 commit 6af8785
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ class HomeFragment : AppFragment(), HomeAdapter.Listener, MenuProvider {
}

private val save = registerForActivityResult(CreateDocument("application/x-pkcs7-certificates")) {
viewModel.save(requireContext().contentResolver, it)
viewModel.save(requireContext().contentResolver, it, "PKCS7")
}

private val save2 = registerForActivityResult(CreateDocument("application/pkix-pkipath")) {
viewModel.save(requireContext().contentResolver, it, "PkiPath")
}

private val load = registerForActivityResult(OpenDocument()) {
Expand Down Expand Up @@ -167,6 +171,7 @@ class HomeFragment : AppFragment(), HomeAdapter.Listener, MenuProvider {
isChecked = viewModel.preferShowAll
}
menu.findItem(R.id.menu_save).isVisible = viewModel.currentCerts != null
menu.findItem(R.id.menu_save2).isVisible = viewModel.currentCerts != null
}

override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
Expand Down Expand Up @@ -202,6 +207,9 @@ class HomeFragment : AppFragment(), HomeAdapter.Listener, MenuProvider {
R.id.menu_save -> {
save.launch("${Build.PRODUCT}-${AppApplication.TAG}.p7b")
}
R.id.menu_save2 -> {
save2.launch("${Build.PRODUCT}-${AppApplication.TAG}.pkipath")
}
R.id.menu_load -> {
load.launch(arrayOf("application/*"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class HomeViewModel(pm: PackageManager, private val sp: SharedPreferences) : Vie
return parseCertificateChain(certs)
}

fun save(cr: ContentResolver, uri: Uri?) = AppApplication.executor.execute {
fun save(cr: ContentResolver, uri: Uri?, encoding: String) = AppApplication.executor.execute {
val certs = currentCerts
if (uri == null || certs == null) return@execute
var name = uri.toString()
Expand All @@ -199,7 +199,7 @@ class HomeViewModel(pm: PackageManager, private val sp: SharedPreferences) : Vie
try {
val cf = CertificateFactory.getInstance("X.509")
cr.openOutputStream(uri)?.use {
it.write(cf.generateCertPath(certs).getEncoded("PKCS7"))
it.write(cf.generateCertPath(certs).getEncoded(encoding))
} ?: throw IOException("openOutputStream $uri failed")
AppApplication.mainHandler.post {
Toast.makeText(AppApplication.app, name, Toast.LENGTH_SHORT).show()
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/menu/home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
android:showAsAction="never"
android:title="@string/save_certs" />

<item
android:id="@+id/menu_save2"
android:showAsAction="never"
android:title="@string/save_certs2" />

<item
android:id="@+id/menu_load"
android:showAsAction="never"
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<string name="attest_device_props">认证设备属性</string>
<string name="show_all">显示全部</string>
<string name="load_certs">从文件加载</string>
<string name="save_certs">保存到文件</string>
<string name="save_certs">保存到文件(p7b)</string>
<string name="save_certs2">保存到文件(pkipath)</string>
<string name="about">关于</string>
<string name="open_source_info"><![CDATA[
此软件是 %2$s 下的开源软件(%1$s)。
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<string name="attest_device_props">Attest device props</string>
<string name="show_all">Show all</string>
<string name="load_certs">Load from file</string>
<string name="save_certs">Save to file</string>
<string name="save_certs">Save to file (p7b)</string>
<string name="save_certs2">Save to file (pkipath)</string>
<string name="about">About</string>
<string name="open_source_info"><![CDATA[
This software is open source under %2$s (%1$s).
Expand Down

0 comments on commit 6af8785

Please sign in to comment.