From 2884915ac57ab83e730878c9b7927997ddc855d3 Mon Sep 17 00:00:00 2001 From: Michael Pohl Date: Tue, 17 May 2022 10:03:40 +0200 Subject: [PATCH 1/2] Add a blank space after all // in code comments --- build.gradle.kts | 4 +- .../hiddensecrets/HiddenSecretsPlugin.kt | 40 +++++++++---------- .../kotlin/com/klaxit/hiddensecrets/Utils.kt | 4 +- src/main/resources/cpp/secrets.cpp | 4 +- src/main/resources/cpp/secrets.hpp | 2 +- src/main/resources/kotlin/Secrets.kt | 4 +- src/test/kotlin/HiddenSecretsTest.kt | 4 +- 7 files changed, 31 insertions(+), 31 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 3015c96..4df9ad1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -51,10 +51,10 @@ detekt { } tasks.withType { - //Required by Gradle 7.0 + // Required by Gradle 7.0 duplicatesStrategy = DuplicatesStrategy.INCLUDE } tasks.withType { useJUnitPlatform() -} +} \ No newline at end of file diff --git a/src/main/kotlin/com/klaxit/hiddensecrets/HiddenSecretsPlugin.kt b/src/main/kotlin/com/klaxit/hiddensecrets/HiddenSecretsPlugin.kt index 3a099f5..0d755ef 100644 --- a/src/main/kotlin/com/klaxit/hiddensecrets/HiddenSecretsPlugin.kt +++ b/src/main/kotlin/com/klaxit/hiddensecrets/HiddenSecretsPlugin.kt @@ -23,7 +23,7 @@ open class HiddenSecretsPlugin : Plugin { private const val PACKAGE_PLACEHOLDER = "YOUR_PACKAGE_GOES_HERE" private const val KOTLIN_FILE_NAME = "Secrets.kt" - //Tasks + // Tasks const val TASK_UNZIP_HIDDEN_SECRETS = "unzipHiddenSecrets" const val TASK_COPY_CPP = "copyCpp" const val TASK_COPY_KOTLIN = "copyKotlin" @@ -32,12 +32,12 @@ open class HiddenSecretsPlugin : Plugin { const val TASK_PACKAGE_NAME = "packageName" const val TASK_FIND_KOTLIN_FILE = "findKotlinFile" - //Properties + // Properties private const val KEY = "key" private const val KEY_NAME = "keyName" private const val PACKAGE = "package" - //Errors + // Errors private const val ERROR_EMPTY_KEY = "No key provided, use argument '-Pkey=yourKey'" private const val ERROR_EMPTY_PACKAGE = "Empty package name, use argument '-Ppackage=your.package.name'" } @@ -65,7 +65,7 @@ open class HiddenSecretsPlugin : Plugin { fun getKeyParam(): String { val key: String if (project.hasProperty(KEY)) { - //From command line + // From command line key = project.property(KEY) as String } else { throw InvalidUserDataException(ERROR_EMPTY_KEY) @@ -80,11 +80,11 @@ open class HiddenSecretsPlugin : Plugin { fun getPackageNameParam(): String { var packageName: String? = null if (project.hasProperty(PACKAGE)) { - //From command line + // From command line packageName = project.property(PACKAGE) as String? } if (packageName.isNullOrEmpty()) { - //From Android app + // From Android app packageName = getAppPackageName() } if (packageName.isNullOrEmpty()) { @@ -99,10 +99,10 @@ open class HiddenSecretsPlugin : Plugin { @Input fun getKeyNameParam(): String { val chars = ('a'..'z') + ('A'..'Z') - // Default random key name + // Default random key name var keyName = List(DEFAULT_KEY_NAME_LENGTH) { chars.random() }.joinToString("") if (project.hasProperty(KEY_NAME)) { - //From command line + // From command line keyName = project.property(KEY_NAME) as String } else { println("Key name has been randomized, chose your own key name by adding argument '-PkeyName=yourName'") @@ -194,7 +194,7 @@ open class HiddenSecretsPlugin : Plugin { object : Action { @TaskAction override fun execute(copy: Copy) { - // in the case of buildSrc dir + // in the case of buildSrc dir copy.from(project.zipTree(javaClass.protectionDomain.codeSource.location!!.toExternalForm())) println("Unzip jar to $tmpFolder") copy.into(tmpFolder) @@ -239,9 +239,9 @@ open class HiddenSecretsPlugin : Plugin { dependsOn(TASK_UNZIP_HIDDEN_SECRETS) doLast { - //Assert that the key is present + // Assert that the key is present getKeyParam() - //Copy files if they don't exist + // Copy files if they don't exist copyCppFiles() copyKotlinFile() @@ -249,10 +249,10 @@ open class HiddenSecretsPlugin : Plugin { val packageName = getPackageNameParam() val obfuscatedKey = getObfuscatedKey() - //Add method in Kotlin code + // Add method in Kotlin code var secretsKotlin = getKotlinFile() if (secretsKotlin == null) { - //File not found in project + // File not found in project secretsKotlin = getKotlinDestination(packageName, KOTLIN_FILE_NAME) } if (secretsKotlin.exists()) { @@ -267,14 +267,14 @@ open class HiddenSecretsPlugin : Plugin { } else { error("Missing Kotlin file, please run gradle task : $TASK_COPY_KOTLIN") } - //Resolve package name for C++ from the one used in Kotlin file + // Resolve package name for C++ from the one used in Kotlin file var kotlinPackage = Utils.getKotlinFilePackage(secretsKotlin) if (kotlinPackage.isEmpty()) { println("Empty package in $KOTLIN_FILE_NAME") kotlinPackage = packageName } - //Add obfuscated key in C++ code + // Add obfuscated key in C++ code val secretsCpp = getCppDestination("secrets.cpp") if (secretsCpp.exists()) { var text = secretsCpp.readText(Charset.defaultCharset()) @@ -282,16 +282,16 @@ open class HiddenSecretsPlugin : Plugin { println("⚠️ Key already added in C++ !") } if (text.contains(KEY_PLACEHOLDER)) { - //Edit placeholder key - //Replace package name + // Edit placeholder key + // Replace package name text = text.replace(PACKAGE_PLACEHOLDER, Utils.getCppPackageName(kotlinPackage)) - //Replace key name + // Replace key name text = text.replace("YOUR_KEY_NAME_GOES_HERE", keyName) - //Replace demo key + // Replace demo key text = text.replace(KEY_PLACEHOLDER, obfuscatedKey) secretsCpp.writeText(text) } else { - //Add new key + // Add new key text += CodeGenerator.getCppCode(kotlinPackage, keyName, obfuscatedKey) secretsCpp.writeText(text) } diff --git a/src/main/kotlin/com/klaxit/hiddensecrets/Utils.kt b/src/main/kotlin/com/klaxit/hiddensecrets/Utils.kt index 36ab3ab..418d7ae 100644 --- a/src/main/kotlin/com/klaxit/hiddensecrets/Utils.kt +++ b/src/main/kotlin/com/klaxit/hiddensecrets/Utils.kt @@ -37,11 +37,11 @@ object Utils { * Encode a string key to and hex array using package name */ fun encodeSecret(key: String, packageName: String): String { - //Generate the obfuscator as the SHA256 of the app package name + // Generate the obfuscator as the SHA256 of the app package name val obfuscator = sha256(packageName) val obfuscatorBytes = obfuscator.toByteArray() - //Generate the obfuscated secret bytes array by applying a XOR between the secret and the obfuscator + // Generate the obfuscated secret bytes array by applying a XOR between the secret and the obfuscator val obfuscatedSecretBytes = arrayListOf() var i = 0 key.toByteArray(Charset.defaultCharset()).forEach { secretByte -> diff --git a/src/main/resources/cpp/secrets.cpp b/src/main/resources/cpp/secrets.cpp index 32f3f1d..a881813 100644 --- a/src/main/resources/cpp/secrets.cpp +++ b/src/main/resources/cpp/secrets.cpp @@ -59,7 +59,7 @@ jstring getOriginalKey( // Add string terminal delimiter out[obfuscatedSecretSize] = 0x0; - //(Optional) To improve key security + // (Optional) To improve key security return pEnv->NewStringUTF(customDecode(out)); } @@ -71,4 +71,4 @@ Java_YOUR_PACKAGE_GOES_HERE_Secrets_getYOUR_KEY_NAME_GOES_HERE( jstring packageName) { char obfuscatedSecret[] = YOUR_KEY_GOES_HERE; return getOriginalKey(obfuscatedSecret, sizeof(obfuscatedSecret), packageName, pEnv); -} +} \ No newline at end of file diff --git a/src/main/resources/cpp/secrets.hpp b/src/main/resources/cpp/secrets.hpp index 626228c..66c50e6 100644 --- a/src/main/resources/cpp/secrets.hpp +++ b/src/main/resources/cpp/secrets.hpp @@ -2,4 +2,4 @@ #define TESTAPPSIGNATURE_SECRETS_H -#endif //TESTAPPSIGNATURE_SECRETS_H +#endif // TESTAPPSIGNATURE_SECRETS_H \ No newline at end of file diff --git a/src/main/resources/kotlin/Secrets.kt b/src/main/resources/kotlin/Secrets.kt index 679ffc4..470aece 100644 --- a/src/main/resources/kotlin/Secrets.kt +++ b/src/main/resources/kotlin/Secrets.kt @@ -2,8 +2,8 @@ package YOUR_PACKAGE_GOES_HERE class Secrets { - //Method calls will be added by gradle task hideSecret - //Example : external fun getWellHiddenSecret(packageName: String): String + // Method calls will be added by gradle task hideSecret + // Example : external fun getWellHiddenSecret(packageName: String): String companion object { init { diff --git a/src/test/kotlin/HiddenSecretsTest.kt b/src/test/kotlin/HiddenSecretsTest.kt index 9cff916..b5eecac 100644 --- a/src/test/kotlin/HiddenSecretsTest.kt +++ b/src/test/kotlin/HiddenSecretsTest.kt @@ -27,7 +27,7 @@ class HiddenSecretsTest : WordSpec({ .withProjectDir(testProjectDir.root) .withTestKitDir(testProjectDir.newFolder()) - //Properties + // Properties val key = "thisIsATestKey" val packageName = "com.package.test" @@ -44,7 +44,7 @@ class HiddenSecretsTest : WordSpec({ "Make command ${HiddenSecretsPlugin.TASK_OBFUSCATE} succeed" { val result = gradleRunner.withArguments(HiddenSecretsPlugin.TASK_OBFUSCATE, "-Pkey=$key", "-Ppackage=$packageName").build() println(result.output) - //Should contain obfuscated key + // Should contain obfuscated key result.output shouldContain "{ 0x15, 0x58, 0xb, 0x43, 0x78, 0x4a, 0x23, 0x6d, 0x1, 0x4b, 0x46, 0x7c, 0x57, 0x41 }" } From 4dd84a8eeaf6d721acd2edf48209f4d08ff5633e Mon Sep 17 00:00:00 2001 From: Michael Pohl Date: Wed, 18 May 2022 09:54:44 +0200 Subject: [PATCH 2/2] Remove unwanted double spaces --- .../kotlin/com/klaxit/hiddensecrets/HiddenSecretsPlugin.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/klaxit/hiddensecrets/HiddenSecretsPlugin.kt b/src/main/kotlin/com/klaxit/hiddensecrets/HiddenSecretsPlugin.kt index 0d755ef..388525d 100644 --- a/src/main/kotlin/com/klaxit/hiddensecrets/HiddenSecretsPlugin.kt +++ b/src/main/kotlin/com/klaxit/hiddensecrets/HiddenSecretsPlugin.kt @@ -99,7 +99,7 @@ open class HiddenSecretsPlugin : Plugin { @Input fun getKeyNameParam(): String { val chars = ('a'..'z') + ('A'..'Z') - // Default random key name + // Default random key name var keyName = List(DEFAULT_KEY_NAME_LENGTH) { chars.random() }.joinToString("") if (project.hasProperty(KEY_NAME)) { // From command line @@ -194,7 +194,7 @@ open class HiddenSecretsPlugin : Plugin { object : Action { @TaskAction override fun execute(copy: Copy) { - // in the case of buildSrc dir + // in the case of buildSrc dir copy.from(project.zipTree(javaClass.protectionDomain.codeSource.location!!.toExternalForm())) println("Unzip jar to $tmpFolder") copy.into(tmpFolder)