Skip to content

Commit

Permalink
Re-enable API key encryption. Bump version.
Browse files Browse the repository at this point in the history
  • Loading branch information
kukabi committed Jan 22, 2024
1 parent 77ca464 commit fb045c8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ information.
```gradle
dependencies {
// ...
implementation 'com.github.helikon-labs:subvt-data-android:0.22.1'
implementation 'com.github.helikon-labs:subvt-data-android:0.22.2'
// ...
}
```
Expand Down
4 changes: 2 additions & 2 deletions subvt-data/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ android {
defaultConfig {
minSdk 24
targetSdk 34
versionCode 221
versionName "0.22.1"
versionCode 222
versionName "0.22.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import java.io.FileInputStream
import java.io.FileOutputStream
import java.math.BigInteger
import java.security.KeyPairGenerator
import java.security.KeyStore
import java.util.Calendar
import javax.crypto.Cipher
import javax.crypto.CipherInputStream
import javax.crypto.CipherOutputStream
import javax.security.auth.x500.X500Principal

const val COMMS_KEY_ALIAS = "SubVTCommsKey"
Expand Down Expand Up @@ -82,14 +84,14 @@ private fun getPublicKeyEncryptedFilePath(context: Context): String {

private fun getCipherInstance() =
Cipher.getInstance(
"RSA/ECB/OAEPWithSHA-256AndMGF1Padding",
// "RSA/ECB/OAEPWithSHA-256AndMGF1Padding",
"AES/CBC/PKCS5Padding",
)

internal fun storeKeyPair(
context: Context,
keyPair: ECKeyPair,
) {
/*
val keyStore = KeyStore.getInstance("AndroidKeyStore")
keyStore.load(null)
if (!keyStore.containsAlias(COMMS_KEY_ALIAS)) {
Expand All @@ -112,15 +114,17 @@ internal fun storeKeyPair(
)
cipherOutputStream.write(keyPair.publicKey.toByteArray())
cipherOutputStream.close()

/*
val privateKeyStream = FileOutputStream(getPrivateKeyEncryptedFilePath(context))
privateKeyStream.write(keyPair.privateKey.toByteArray())
privateKeyStream.flush()
privateKeyStream.close()
val publicKeyStream = FileOutputStream(getPublicKeyEncryptedFilePath(context))
publicKeyStream.write(keyPair.publicKey.toByteArray())
publicKeyStream.flush()
publicKeyStream.close()
*/
val privateKeyStream = FileOutputStream(getPrivateKeyEncryptedFilePath(context))
privateKeyStream.write(keyPair.privateKey.toByteArray())
privateKeyStream.flush()
privateKeyStream.close()
val publicKeyStream = FileOutputStream(getPublicKeyEncryptedFilePath(context))
publicKeyStream.write(keyPair.publicKey.toByteArray())
publicKeyStream.flush()
publicKeyStream.close()
}

private fun getFileBytes(path: String): ByteArray {
Expand Down Expand Up @@ -160,7 +164,6 @@ internal fun getKeyPair(context: Context): ECKeyPair? {
if (!File(getPrivateKeyEncryptedFilePath(context)).exists()) {
return null
}
/*
val keyStore = KeyStore.getInstance("AndroidKeyStore")
keyStore.load(null)
val entry = keyStore.getEntry(COMMS_KEY_ALIAS, null) as KeyStore.PrivateKeyEntry
Expand All @@ -171,8 +174,10 @@ internal fun getKeyPair(context: Context): ECKeyPair? {
outCipher2.init(Cipher.DECRYPT_MODE, entry.privateKey)
val publicKeyBytes = getEncryptedFileBytes(getPublicKeyEncryptedFilePath(context), outCipher2)
return ECKeyPair(BigInteger(privateKeyBytes), BigInteger(publicKeyBytes))
*/

/*
val privateKeyBytes = getFileBytes(getPrivateKeyEncryptedFilePath(context))
val publicKeyBytes = getFileBytes(getPublicKeyEncryptedFilePath(context))
return ECKeyPair(BigInteger(privateKeyBytes), BigInteger(publicKeyBytes))
*/
}

0 comments on commit fb045c8

Please sign in to comment.