From f19b7fa584f93d329c193037060202ee48a8fb0b Mon Sep 17 00:00:00 2001 From: Koen Date: Thu, 28 Sep 2023 16:21:29 +0200 Subject: [PATCH] Added script to generate private key. Modified source header view to show signature status. --- .../views/sources/SourceHeaderView.kt | 16 +++++++++++++ .../main/res/layout/view_source_header.xml | 23 +++++++++++++++++++ scripts/generate-pivate-key.sh | 7 ++++++ 3 files changed, 46 insertions(+) create mode 100755 scripts/generate-pivate-key.sh diff --git a/app/src/main/java/com/futo/platformplayer/views/sources/SourceHeaderView.kt b/app/src/main/java/com/futo/platformplayer/views/sources/SourceHeaderView.kt index 612b7168..39ee62cc 100644 --- a/app/src/main/java/com/futo/platformplayer/views/sources/SourceHeaderView.kt +++ b/app/src/main/java/com/futo/platformplayer/views/sources/SourceHeaderView.kt @@ -23,6 +23,7 @@ class SourceHeaderView : LinearLayout { private val _sourceVersion: TextView; private val _sourceRepositoryUrl: TextView; private val _sourceScriptUrl: TextView; + private val _sourceSignature: TextView; private var _config : SourcePluginConfig? = null; @@ -38,6 +39,7 @@ class SourceHeaderView : LinearLayout { _sourceVersion = findViewById(R.id.source_version); _sourceRepositoryUrl = findViewById(R.id.source_repo); _sourceScriptUrl = findViewById(R.id.source_script); + _sourceSignature = findViewById(R.id.source_signature); _sourceBy.setOnClickListener { if(!_config?.authorUrl.isNullOrEmpty()) @@ -76,6 +78,20 @@ class SourceHeaderView : LinearLayout { _sourceBy.setTextColor(resources.getColor(R.color.colorPrimary)); else _sourceBy.setTextColor(Color.WHITE); + + if (!config.scriptPublicKey.isNullOrEmpty() && !config.scriptSignature.isNullOrEmpty()) { + val script = StatePlugins.instance.getScript(config.id); + if (script != null && config.validate(script)) { + _sourceSignature.setTextColor(Color.rgb(0, 255, 0)); + _sourceSignature.text = "Signature is valid"; + } else { + _sourceSignature.setTextColor(Color.rgb(255, 0, 0)); + _sourceSignature.text = "Signature is invalid"; + } + } else { + _sourceSignature.setTextColor(Color.rgb(255, 0, 0)); + _sourceSignature.text = "No signature available"; + } } fun clear() { diff --git a/app/src/main/res/layout/view_source_header.xml b/app/src/main/res/layout/view_source_header.xml index 42dea7c6..5dfb5473 100644 --- a/app/src/main/res/layout/view_source_header.xml +++ b/app/src/main/res/layout/view_source_header.xml @@ -144,4 +144,27 @@ android:fontFamily="@font/inter_extra_light" android:text="https://some.repository.url/whatever/someScript.js" /> + + + + + + \ No newline at end of file diff --git a/scripts/generate-pivate-key.sh b/scripts/generate-pivate-key.sh new file mode 100755 index 00000000..22f5f8be --- /dev/null +++ b/scripts/generate-pivate-key.sh @@ -0,0 +1,7 @@ +#!/bin/sh +PRIVATE_KEY=$(openssl genpkey -algorithm RSA -outform PEM) +PUBLIC_KEY=$(echo "$PRIVATE_KEY" | openssl rsa -pubout -outform PEM) +echo -en "\nPrivate key:\n$PRIVATE_KEY\n" +echo -en "\nPrivate key (base64):\n$(echo "$PRIVATE_KEY" | base64 -w 0)\n" +echo -en "\nPublic key:\n$PUBLIC_KEY\n" +echo -en "\nPublic key (base64):\n$(echo "$PUBLIC_KEY" | base64 -w 0)\n" \ No newline at end of file