Skip to content

Commit

Permalink
Save storage iteration id for pin backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
cyb3rko committed Feb 6, 2023
1 parent 757542e commit 338bf1c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import kotlin.experimental.and
import kotlin.jvm.Throws

internal object CryptoManager {
internal const val PIN_CRYPTO_ITERATION = 0
private const val KEYSTORE_ALIAS = "iamsecure"
private const val ENC_ALGORITHM = KeyProperties.KEY_ALGORITHM_AES
private const val ENC_BLOCK_MODE = KeyProperties.BLOCK_MODE_CBC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ class PinCreatorFragment : Fragment() {
val newPinFile = File(myContext.filesDir, "p$hash")
return if (!newPinFile.exists()) {
newPinFile.createNewFile()
CryptoManager.encrypt(ObjectSerializer.serialize(pinTable), newPinFile)
val bytes = ObjectSerializer.serialize(pinTable)
val version = CryptoManager.PIN_CRYPTO_ITERATION.toByte()
CryptoManager.encrypt(bytes.plus(version), newPinFile)
true
} else {
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.cyb3rko.pincredible.fragments

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.drawable.Drawable
import android.os.Bundle
Expand Down Expand Up @@ -156,8 +157,11 @@ class PinViewerFragment : Fragment() {
@Throws(EnDecryptionException::class)
private fun decryptData(hash: String): PinTable {
val file = File(myContext.filesDir, "p$hash")
val secret = CryptoManager.decrypt(file)
return ObjectSerializer.deserialize(secret) as PinTable
val bytes = CryptoManager.decrypt(file)
val version = bytes[bytes.size - 1]
@SuppressLint("SetTextI18n")
binding.siidView.text = "SIID: $version"
return ObjectSerializer.deserialize(bytes.copyOfRange(0, bytes.size - 1)) as PinTable
}

override fun onDestroyView() {
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/layout/fragment_pin_viewer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@
layout="@layout/table_view"
android:id="@+id/table_layout" />

<TextView
android:id="@+id/siid_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textSize="9sp"
android:textStyle="italic"
android:layout_marginTop="4dp"
tools:text="SIID: 0"
tools:ignore="SmallSp" />

<Button
style="@style/Widget.Material3.Button.TonalButton"
android:id="@+id/delete_button"
Expand Down

0 comments on commit 338bf1c

Please sign in to comment.