Display the app signer in the about bottom sheet

This commit is contained in:
Nicolas Pomepuy 2024-10-07 11:25:49 +02:00 committed by Duncan McNamara
parent 6aab963a4f
commit fbf1472a42
3 changed files with 69 additions and 1 deletions

View File

@ -293,6 +293,7 @@
<string name="about_license_text" translatable="false"></string>
<string name="vlc_authors">and VLC Authors.</string>
<string name="is_compiled_by">Compiled by</string>
<string name="is_signed_by">Signed by</string>
<string name="sources">Source code</string>
<string name="libraries">Libraries</string>
<string name="feedback_forum">Feedback forum</string>

View File

@ -105,6 +105,17 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/compiled_by" />
<TextView
android:id="@+id/textView31"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="@string/is_signed_by"
android:textColor="?attr/font_light"
app:layout_constraintBottom_toBottomOf="@+id/signed_by"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/signed_by" />
<View
android:id="@+id/divider"
android:layout_width="0dp"
@ -113,7 +124,7 @@
android:background="?attr/default_divider"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/compiled_by" />
app:layout_constraintTop_toBottomOf="@+id/signed_by" />
<TextView
android:id="@+id/textView29"
@ -219,6 +230,18 @@
app:layout_constraintTop_toBottomOf="@+id/revision"
tools:text="Gitlab runner" />
<TextView
android:id="@+id/signed_by"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="4dp"
android:textColor="?attr/font_default"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/compilation_barrier"
app:layout_constraintTop_toBottomOf="@+id/compiled_by"
tools:text="VideoLAN" />
<TextView
android:id="@+id/remote_access_version"
android:layout_width="0dp"

View File

@ -21,7 +21,10 @@
*/
package org.videolan.vlc.gui.dialogs
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -29,6 +32,8 @@ import com.google.android.material.bottomsheet.BottomSheetBehavior.STATE_EXPANDE
import org.videolan.vlc.BuildConfig
import org.videolan.vlc.R
import org.videolan.vlc.databinding.DialogAboutVersionBinding
import java.security.MessageDigest
/**
* Dialog showing the info of the current version
@ -77,6 +82,45 @@ class AboutVersionDialog : VLCBottomSheetDialogFragment() {
whatsNewDialog.show(requireActivity().supportFragmentManager, "fragment_whats_new")
dismiss()
}
val signatures =
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) requireActivity().packageManager.getPackageInfo(
requireActivity().packageName,
PackageManager.GET_SIGNATURES
).signatures
else
requireActivity().packageManager.getPackageInfo(
requireActivity().packageName,
PackageManager.GET_SIGNING_CERTIFICATES
).signingInfo.apkContentsSigners
var signer = requireActivity().getString(R.string.unknown)
signatures.forEach {
try {
val md = MessageDigest.getInstance("SHA1")
md.update(it.toByteArray())
val digest = md.digest()
val toRet = java.lang.StringBuilder()
for (i in digest.indices) {
if (i != 0) toRet.append(":")
val b = digest[i].toInt() and 0xff
val hex = Integer.toHexString(b)
if (hex.length == 1) toRet.append("0")
toRet.append(hex)
}
when (toRet.toString().uppercase()) {
"AC:5A:BC:F1:99:AC:86:61:6A:79:65:CB:84:59:94:89:A5:A7:3F:86" -> signer = "VideoLAN nightly"
"4D:D5:44:A7:51:D3:D5:4C:17:D8:7E:1D:D3:60:F0:C6:40:A5:C1:50" -> signer = "Google"
"EE:FB:C9:81:42:83:43:BB:DD:FF:F6:B2:3B:6B:D8:71:73:51:41:0C" -> signer = "VideoLAN"
"40:80:86:F9:AE:A6:52:A8:61:44:70:4F:11:79:9A:CA:BA:31:C7:A0" -> signer = "F-Droid"
}
Log.i(this::class.java.simpleName, "Found signature. Fingerprint: $toRet")
} catch (e: Exception) {
Log.e("Signature",e.message, e)
}
}
binding.signedBy.text = signer
}