diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml new file mode 100644 index 0000000..6ea8d73 --- /dev/null +++ b/.github/workflows/android.yml @@ -0,0 +1,30 @@ +name: Android + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Java + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 17 + + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Run unit tests + run: bash ./gradlew test diff --git a/.github/workflows/deno.yml b/.github/workflows/deno.yml deleted file mode 100644 index 782af35..0000000 --- a/.github/workflows/deno.yml +++ /dev/null @@ -1,42 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -# This workflow will install Deno then run `deno lint` and `deno test`. -# For more information see: https://github.com/denoland/setup-deno - -name: Deno - -on: - push: - branches: ["main"] - pull_request: - branches: ["main"] - -permissions: - contents: read - -jobs: - test: - runs-on: ubuntu-latest - - steps: - - name: Setup repo - uses: actions/checkout@v4 - - - name: Setup Deno - # uses: denoland/setup-deno@v1 - uses: denoland/setup-deno@61fe2df320078202e33d7d5ad347e7dcfa0e8f31 # v1.1.2 - with: - deno-version: v1.x - - # Uncomment this step to verify the use of 'deno fmt' on each commit. - # - name: Verify formatting - # run: deno fmt --check - - - name: Run linter - run: deno lint - - - name: Run tests - run: deno test -A diff --git a/app/src/main/java/hu/regelo/app/data/EncryptedLocalDatabase.kt b/app/src/main/java/hu/regelo/app/data/EncryptedLocalDatabase.kt index 22b133a..3673d19 100644 --- a/app/src/main/java/hu/regelo/app/data/EncryptedLocalDatabase.kt +++ b/app/src/main/java/hu/regelo/app/data/EncryptedLocalDatabase.kt @@ -95,6 +95,9 @@ internal object EncryptedLocalDatabase { } finally { plainDb.close() } + check(temporary.createNewFile()) { + "A titkosított adatbázis ideiglenes fájlja nem hozható létre." + } listOf("-wal", "-shm").forEach { suffix -> val sidecar = File(database.absolutePath + suffix) check(!sidecar.exists() || sidecar.delete()) { @@ -103,22 +106,38 @@ internal object EncryptedLocalDatabase { } try { - database.copyTo(temporary, overwrite = true) val migrationDb = SQLiteDatabase.openDatabase( - temporary.absolutePath, + database.absolutePath, null, SQLiteDatabase.OPEN_READWRITE, ) try { verifyReadable(migrationDb) - migrationDb.changePassword(passphrase) - verifyReadable(migrationDb) + val schemaVersion = migrationDb.version + migrationDb.execSQL( + "ATTACH DATABASE ? AS encrypted KEY ?", + arrayOf(temporary.absolutePath, passphrase), + ) + try { + migrationDb.rawQuery("SELECT sqlcipher_export('encrypted')", null).use { cursor -> + check(cursor.moveToFirst() && cursor.getInt(0) == 0) { + "Az SQLite-adatbázis titkosított exportja sikertelen." + } + } + migrationDb.execSQL("PRAGMA encrypted.user_version = $schemaVersion") + migrationDb.rawQuery("PRAGMA encrypted.user_version", null).use { cursor -> + check(cursor.moveToFirst() && cursor.getInt(0) == schemaVersion) { + "Az adatbázis sémaverziójának exportja sikertelen." + } + } + } finally { + migrationDb.execSQL("DETACH DATABASE encrypted") + } } finally { migrationDb.close() } verifyEncryptedDatabase(temporary, passphrase) Os.rename(temporary.absolutePath, database.absolutePath) - verifyEncryptedDatabase(database, passphrase) } catch (e: Exception) { temporary.delete() throw IllegalStateException(