Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sample Application #9

Merged
merged 12 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/[email protected]
with:
distribution: 'temurin'
java-version: '11'
java-version: '17'
cache: gradle

- name: Grant execute permission for gradlew
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ jobs:
env:
GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }}
GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }}
run: ./gradlew -Dgradle.publish.key=$GRADLE_PUBLISH_KEY -Dgradle.publish.secret=$GRADLE_PUBLISH_SECRET publishPlugins
run: ./gradlew -Dgradle.publish.key=$GRADLE_PUBLISH_KEY -Dgradle.publish.secret=$GRADLE_PUBLISH_SECRET :secretsvaultplugin:publishPlugins
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ captures/
*.iml
.idea/

# Keystore files
*.jks

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

Expand Down
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ plugins {
alias(libs.plugins.gradle.publish).apply(false)
alias(libs.plugins.detekt).apply(false)
alias(libs.plugins.kotlin.serialization).apply(false)

// Sample App
alias(libs.plugins.android.application).apply(false)
alias(libs.plugins.kotlin.android).apply(false)
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
kotlin.code.style=official
android.useAndroidX=true
5 changes: 5 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-
detekt-formating = { group = "io.gitlab.arturbosch.detekt", name = "detekt-formatting", version.ref = "detekt" }
detekt-rules = { group = "io.gitlab.arturbosch.detekt", name = "detekt-rules", version.ref = "detekt" }

# Sample App
androidx-activityKtx = { module = "androidx.activity:activity-ktx", version = "1.7.2" }

[plugins]
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
gradle-publish = { id = "com.gradle.plugin-publish", version.ref = "gradlePublish" }
Expand Down
104 changes: 104 additions & 0 deletions sampleapp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
id("com.commencis.secretsvaultplugin")
}

android {
namespace = "com.commencis.secretsvaultplugin.sampleapp"
compileSdk = 33

defaultConfig {
applicationId = "com.commencis.secretsvaultplugin.sampleapp"
minSdk = 21
targetSdk = 33
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

signingConfigs {
getByName("debug") {
storeFile = file("keystore/debug.jks")
storePassword = "android"
keyAlias = "debug"
keyPassword = "android"
}
create("release") {
storeFile = file("keystore/release.jks")
storePassword = "android"
keyAlias = "release"
keyPassword = "android"
}
}

buildTypes {
debug {
applicationIdSuffix = ".debug"
signingConfig = signingConfigs.getByName("debug")
}
release {
signingConfig = signingConfigs.getByName("release")
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

externalNativeBuild {
cmake {
path("src/main/cpp/CMakeLists.txt")
}
}

flavorDimensions.add("stage")
productFlavors {
create("dev") {
dimension = "stage"
externalNativeBuild {
cmake {
arguments("-DsourceSet=dev")
}
}
}
create("prod") {
dimension = "stage"
externalNativeBuild {
cmake {
arguments("-DsourceSet=prod")
}
}
}
}

kotlinOptions {
jvmTarget = JvmTarget.JVM_11.target
}
}

secretsVault {
appSignatures.set(
listOf(
"1A:92:D7:89:8F:16:C4:D3:46:E2:6D:C5:0C:2F:42:B0", // keystore/debug.kjs
"45:4E:FD:58:87:C2:27:D2:5E:12:F4:C6:7F:CA:53:10", // keystore/release.kjs
)
)
obfuscationKey.set("chEYKrGb5PJx0I09oa1mlEuXE5FxPjX2")
cmake {
version.set("3.17")
}
}

dependencies {
implementation(libs.androidx.activityKtx)
}
Binary file added sampleapp/keystore/debug.jks
Binary file not shown.
Binary file added sampleapp/keystore/release.jks
Binary file not shown.
30 changes: 30 additions & 0 deletions sampleapp/secrets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"key": "generalKey1",
"value": "generalValue1"
},
{
"key": "generalKey2",
"value": "generalValue2"
},
{
"key": "commonFlavorKey1",
"value": "commonFlavorValue1Dev",
"sourceSet": "dev"
},
{
"key": "commonFlavorKey1",
"value": "commonFlavorValue1Prod",
"sourceSet": "prod"
},
{
"key": "devOnlyKey1",
"value": "devOnlyValue1",
"sourceSet": "dev"
},
{
"key": "prodOnlyKey1",
"value": "prodOnlyValue1",
"sourceSet": "prod"
}
]
4 changes: 4 additions & 0 deletions sampleapp/src/debug/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">CSV-DBG</string>
</resources>
19 changes: 19 additions & 0 deletions sampleapp/src/dev/cpp/secrets.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "../../main/cpp/common/secrets_util.cpp"

extern "C"
JNIEXPORT jstring JNICALL
Java_com_commencis_secretsvaultplugin_sampleapp_Secrets_a0(
JNIEnv* pEnv,
jobject pThis) {
char obfuscatedSecret[] = { 0x5a, 0xd, 0x8, 0x9, 0x56, 0xd, 0x7e, 0x59, 0x51, 0x4f, 0xd, 0x14, 0x66, 0x7, 0xf, 0x16, 0x3, 0x0, 0x73, 0x0, 0x44 };
return getOriginalKey(obfuscatedSecret, sizeof(obfuscatedSecret), pEnv);
}

extern "C"
JNIEXPORT jstring JNICALL
Java_com_commencis_secretsvaultplugin_sampleapp_Secrets_a1(
JNIEnv* pEnv,
jobject pThis) {
char obfuscatedSecret[] = { 0x5d, 0x7, 0x13, 0x2b, 0x57, 0xf, 0x41, 0x63, 0x51, 0x55, 0x17, 0x3, 0x1 };
return getOriginalKey(obfuscatedSecret, sizeof(obfuscatedSecret), pEnv);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.commencis.secretsvaultplugin.sampleapp;

import androidx.annotation.NonNull;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import kotlin.Pair;

class FlavorSecretProviderJava implements FlavorSecretProvider {

private final FlavorSecretProviderJavaHelper secretHelper = new FlavorSecretProviderJavaHelper();

@NonNull
@Override
public Collection<Pair<String, String>> getSecretPairs() {
final List<Pair<String, String>> list = new ArrayList<>();
list.add(new Pair<>("commonFlavorKey1", secretHelper.getCommonFlavorKey1()));
list.add(new Pair<>("devOnlyKey1", secretHelper.getDevOnlyKey1()));
return list;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.commencis.secretsvaultplugin.sampleapp

internal class FlavorSecretProviderJavaHelper {

private val secrets = Secrets()

val commonFlavorKey1: String
get() = secrets.getCommonFlavorKey1()

val devOnlyKey1: String
get() = secrets.getDevOnlyKey1()

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.commencis.secretsvaultplugin.sampleapp

internal class FlavorSecretProviderKotlin : FlavorSecretProvider {

private val secrets = Secrets()

override val secretPairs: Collection<Pair<String, String>>
get() = listOf(
"commonFlavorKey1" to secrets.getCommonFlavorKey1(),
"devOnlyKey1" to secrets.getDevOnlyKey1(),
)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.commencis.secretsvaultplugin.sampleapp

class Secrets {

@JvmName("a0")
external fun getCommonFlavorKey1(): String

@JvmName("a1")
external fun getDevOnlyKey1(): String

companion object {
init {
System.loadLibrary("secrets")
}
}
}
21 changes: 21 additions & 0 deletions sampleapp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true">

<activity
android:name="com.commencis.secretsvaultplugin.sampleapp.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

</manifest>
29 changes: 29 additions & 0 deletions sampleapp/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Sets the minimum version of CMake required to build your native library.
# This ensures that a certain set of CMake features is available to
# your build.
cmake_minimum_required(VERSION 3.17)
project(sampleapp)

# Specifies a library name, specifies whether the library is STATIC or
# SHARED, and provides relative paths to the source code. You can
# define multiple libraries by adding multiple add_library() commands,
# and CMake builds them for you. When you build your app, Gradle
# automatically packages shared libraries with your APK.
add_library(
mainsecrets
SHARED
secrets.cpp
)
if (sourceSet STREQUAL "dev")
add_library(
secrets
SHARED
../../dev/cpp/secrets.cpp
)
elseif (sourceSet STREQUAL "prod")
add_library(
secrets
SHARED
../../prod/cpp/secrets.cpp
)
endif()
Loading
Loading