Skip to content

Commit

Permalink
updated target SDK, dependencies and SQLCipher
Browse files Browse the repository at this point in the history
updated target SDK, dependencies and SQLCipher
make sure you check this commit for migration to sqlcipher-android
  • Loading branch information
sonique6784 committed Nov 12, 2023
1 parent 12b3ea7 commit 85380ba
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 73 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ jobs:
- run: echo "* SQLCipher Performance Build & Test *"

- name: Check out repository code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up JDK 11
uses: actions/setup-java@v1
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 11
java-version: 17
distribution: 'temurin'

- name: Setup Android SDK
uses: android-actions/setup-android@v2
uses: android-actions/setup-android@v3

- name: Build the app
run: ./gradlew assembleDebug
Expand Down
48 changes: 24 additions & 24 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'org.owasp.dependencycheck'


android {
compileSdkVersion 31
buildToolsVersion "31.0.0"
compileSdkVersion 34
buildToolsVersion "34.0.0"

namespace "fr.sonique.sqlcipherperformance"

buildFeatures {
dataBinding = true
}

defaultConfig {
applicationId "fr.sonique.sqlcipherperformance"
minSdkVersion 19
targetSdkVersion 30
versionCode 7
versionName "1.1"
minSdkVersion 21
targetSdkVersion 34
versionCode 8
versionName "2.0"
multiDexEnabled true

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -32,48 +33,47 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "17"
}
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.fragment:fragment-ktx:1.4.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.fragment:fragment-ktx:1.6.2'
implementation 'androidx.navigation:navigation-fragment-ktx:2.7.5'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'
implementation 'com.google.android.material:material:1.11.0-beta01'
implementation 'androidx.navigation:navigation-ui-ktx:2.7.5'

// Firebase
implementation 'com.google.firebase:firebase-core:20.0.0'
implementation 'com.google.firebase:firebase-core:21.1.1'
implementation 'com.google.firebase:firebase-appindexing:20.0.0'


def multidex_version = "2.0.1"
implementation "androidx.multidex:multidex:$multidex_version"

def room_version = "2.3.0"
def room_version = "2.6.0"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version" // For Kotlin use kapt instead of annotationProcessor
// optional - Kotlin Extensions and Coroutines support for Room
implementation "androidx.room:room-ktx:$room_version"


implementation 'net.zetetic:android-database-sqlcipher:4.5.0@aar'
implementation 'net.zetetic:sqlcipher-android:4.5.5@aar'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/AppTheme.NoActionBar">
android:theme="@style/AppTheme.NoActionBar"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

Expand Down
52 changes: 36 additions & 16 deletions app/src/main/java/fr/sonique/sqlcipherperformance/Database.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import net.sqlcipher.database.SQLiteDatabase
import net.sqlcipher.database.SQLiteDatabaseHook
import net.sqlcipher.database.SupportFactory
import net.zetetic.database.sqlcipher.SQLiteConnection
import net.zetetic.database.sqlcipher.SQLiteDatabase
import net.zetetic.database.sqlcipher.SQLiteDatabaseHook
import net.zetetic.database.sqlcipher.SupportOpenHelperFactory
import java.nio.charset.StandardCharsets

//import net.sqlcipher.database.SQLiteDatabase
//import net.sqlcipher.database.SQLiteDatabaseHook
//import net.sqlcipher.database.SupportFactory


@Database(entities = [Person::class], version = 1)
Expand All @@ -32,8 +38,10 @@ abstract class AppDatabase : RoomDatabase() {
companion object {
@Volatile
private var personDB: AppDatabase? = null

@Volatile
private var personDBSecure: AppDatabase? = null

@Volatile
private var personDBSecureWithMemorySecurity: AppDatabase? = null

Expand All @@ -43,13 +51,21 @@ abstract class AppDatabase : RoomDatabase() {
memorySecure: Boolean = false
): AppDatabase {
return if (secure) {
if(!memorySecure) {
if (!memorySecure) {
personDBSecure ?: synchronized(this) {
personDBSecure ?: buildDatabase(context, secure, memorySecure).also { personDBSecure = it }
personDBSecure ?: buildDatabase(
context,
secure,
memorySecure
).also { personDBSecure = it }
}
} else {
personDBSecureWithMemorySecurity ?: synchronized(this) {
personDBSecureWithMemorySecurity ?: buildDatabase(context, secure, memorySecure).also { personDBSecureWithMemorySecurity = it }
personDBSecureWithMemorySecurity ?: buildDatabase(
context,
secure,
memorySecure
).also { personDBSecureWithMemorySecurity = it }
}
}
} else {
Expand All @@ -64,9 +80,9 @@ abstract class AppDatabase : RoomDatabase() {
secure: Boolean,
memorySecure: Boolean = false
): AppDatabase {
val dbname = if(secure && memorySecure) {
val dbname = if (secure && memorySecure) {
"encrypted-with-mem"
} else if(secure && !memorySecure) {
} else if (secure && !memorySecure) {
"encrypted"
} else {
"not-encrypted"
Expand All @@ -77,20 +93,24 @@ abstract class AppDatabase : RoomDatabase() {
)
if (secure) {
val passphrase: ByteArray =
SQLiteDatabase.getBytes("P@s5P4ras3VeryL0n9".toCharArray())
val factory = SupportFactory(passphrase, object : SQLiteDatabaseHook {
override fun preKey(database: SQLiteDatabase?) = Unit
"P@s5P4ras3VeryL0n9".encodeToByteArray()

override fun postKey(database: SQLiteDatabase?) {
val factory = SupportOpenHelperFactory(passphrase, object : SQLiteDatabaseHook {
override fun preKey(connection: SQLiteConnection) = Unit

override fun postKey(connection: SQLiteConnection) {
if (memorySecure) {
database?.rawExecSQL(
"PRAGMA cipher_memory_security = ON"
connection.execute(
"PRAGMA cipher_memory_security = ON", null, null
)
} else {
database?.rawExecSQL("PRAGMA cipher_memory_security = OFF")
connection.execute(
"PRAGMA cipher_memory_security = OFF", null, null
)
}
}
})
}, false)

builder.openHelperFactory(factory)
}

Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/fr/sonique/sqlcipherperformance/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,19 @@ class MainActivity : AppCompatActivity() {
MainActivityViewModelFactory(this, baseContext)
}

private var isSQLCipherLoaded = false
private fun loadSQLCipherLibrary() {
if (!isSQLCipherLoaded) {
System.loadLibrary("sqlcipher")
isSQLCipherLoaded = true
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

loadSQLCipherLibrary()

binding = DataBindingUtil.setContentView(this, R.layout.activity_main)

binding.insertsButton.setOnClickListener { _ ->
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.32"
ext.kotlin_version = "1.9.20"
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
classpath 'com.android.tools.build:gradle:8.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'org.owasp:dependency-check-gradle:6.5.0.1'
// NOTE: Do not place your application dependencies here; they belong
Expand Down
27 changes: 4 additions & 23 deletions config/owasp/suppressions.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<suppressions xmlns="https://jeremylong.github.io/DependencyCheck/dependency-suppression.1.3.xsd">
<suppress>
<notes><![CDATA[suppresses false positive see (https://github.com/jeremylong/DependencyCheck/issues/2785)]]></notes>
<cve>CVE-2020-29582</cve>
<cpe>cpe:/2.3:a:jetbrains:kotlin:1.4.0:milestone1:*:*:*:*:*:*</cpe>
</suppress>
<suppress>
<notes><![CDATA[
file name: kotlin-stdlib-common-1.4.0.jar
]]></notes>
<packageUrl regex="true">^pkg:maven/org\.jetbrains\.kotlin/kotlin\-stdlib\-common@.*$</packageUrl>
<cpe>cpe:/a:jetbrains:kotlin</cpe>
</suppress>
<suppress>
<notes><![CDATA[
file name: kotlin-stdlib-1.4.0.jar
]]></notes>
<packageUrl regex="true">^pkg:maven/org\.jetbrains\.kotlin/kotlin\-stdlib@.*$</packageUrl>
<cve>CVE-2020-29582</cve>
</suppress>
<suppress>
<notes><![CDATA[
file name: kotlin-stdlib-1.4.0.jar
]]></notes>
<packageUrl regex="true">^pkg:maven/org\.jetbrains\.kotlin/kotlin\-stdlib@.*$</packageUrl>
<cve>CVE-2020-15824</cve>
file name: legacy-support-core-utils-1.0.0.aar
]]></notes>
<packageUrl regex="true">^pkg:maven/androidx\.legacy/legacy\-support\-core\-utils@.*$</packageUrl>
<cpe>cpe:/a:utils_project:utils</cpe>
</suppress>
</suppressions>
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip

0 comments on commit 85380ba

Please sign in to comment.