Skip to content

Commit

Permalink
Add a blank space after all // in code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Pohl committed May 17, 2022
1 parent f08cae7 commit 2884915
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ detekt {
}

tasks.withType<Copy> {
//Required by Gradle 7.0
// Required by Gradle 7.0
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

tasks.withType<Test> {
useJUnitPlatform()
}
}
40 changes: 20 additions & 20 deletions src/main/kotlin/com/klaxit/hiddensecrets/HiddenSecretsPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ open class HiddenSecretsPlugin : Plugin<Project> {
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"
Expand All @@ -32,12 +32,12 @@ open class HiddenSecretsPlugin : Plugin<Project> {
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'"
}
Expand Down Expand Up @@ -65,7 +65,7 @@ open class HiddenSecretsPlugin : Plugin<Project> {
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)
Expand All @@ -80,11 +80,11 @@ open class HiddenSecretsPlugin : Plugin<Project> {
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()) {
Expand All @@ -99,10 +99,10 @@ open class HiddenSecretsPlugin : Plugin<Project> {
@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'")
Expand Down Expand Up @@ -194,7 +194,7 @@ open class HiddenSecretsPlugin : Plugin<Project> {
object : Action<Copy?> {
@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)
Expand Down Expand Up @@ -239,20 +239,20 @@ open class HiddenSecretsPlugin : Plugin<Project> {
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()

val keyName = getKeyNameParam()
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()) {
Expand All @@ -267,31 +267,31 @@ open class HiddenSecretsPlugin : Plugin<Project> {
} 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())
if (text.contains(obfuscatedKey)) {
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)
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/klaxit/hiddensecrets/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Byte>()
var i = 0
key.toByteArray(Charset.defaultCharset()).forEach { secretByte ->
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/cpp/secrets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/cpp/secrets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#define TESTAPPSIGNATURE_SECRETS_H


#endif //TESTAPPSIGNATURE_SECRETS_H
#endif // TESTAPPSIGNATURE_SECRETS_H
4 changes: 2 additions & 2 deletions src/main/resources/kotlin/Secrets.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/test/kotlin/HiddenSecretsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class HiddenSecretsTest : WordSpec({
.withProjectDir(testProjectDir.root)
.withTestKitDir(testProjectDir.newFolder())

//Properties
// Properties
val key = "thisIsATestKey"
val packageName = "com.package.test"

Expand All @@ -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 }"
}

Expand Down

0 comments on commit 2884915

Please sign in to comment.