From e47d9f4548ee6b96b94411872fd1499cb699530d Mon Sep 17 00:00:00 2001 From: Hardcore Sushi Date: Sun, 17 Oct 2021 13:46:10 +0200 Subject: [PATCH] XChaCha20-Ploy1305 support --- app/libgocryptfs | 2 +- .../sushi/hardcore/droidfs/CreateActivity.kt | 29 +++++++++++++++++-- .../sushi/hardcore/droidfs/GocryptfsVolume.kt | 2 +- app/src/main/native/gocryptfs_jni.c | 3 +- app/src/main/res/layout/activity_create.xml | 18 ++++++++++++ app/src/main/res/values/arrays.xml | 6 ++++ app/src/main/res/values/strings.xml | 3 ++ 7 files changed, 58 insertions(+), 5 deletions(-) diff --git a/app/libgocryptfs b/app/libgocryptfs index f0e45c7..bd5d53f 160000 --- a/app/libgocryptfs +++ b/app/libgocryptfs @@ -1 +1 @@ -Subproject commit f0e45c7b7e428f13667edd3b8d73501e15322a04 +Subproject commit bd5d53f50eb274ed084e9f363ccfbe30d9061039 diff --git a/app/src/main/java/sushi/hardcore/droidfs/CreateActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/CreateActivity.kt index 98b21fa..fe366bf 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/CreateActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/CreateActivity.kt @@ -4,7 +4,8 @@ import android.content.Intent import android.net.Uri import android.os.Build import android.os.Bundle -import android.widget.Toast +import android.view.View +import android.widget.* import androidx.appcompat.app.AppCompatActivity import sushi.hardcore.droidfs.databinding.ActivityCreateBinding import sushi.hardcore.droidfs.explorers.ExplorerActivity @@ -29,6 +30,25 @@ class CreateActivity : VolumeActionActivity() { createVolume() true } + binding.spinnerXchacha.adapter = ArrayAdapter( + this@CreateActivity, + android.R.layout.simple_spinner_item, + resources.getStringArray(R.array.encryption_cipher) + ).apply { + setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) + } + binding.spinnerXchacha.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { + if (position == 1) { + ColoredAlertDialogBuilder(this@CreateActivity) + .setTitle(R.string.warning) + .setMessage(R.string.xchacha_warning) + .setPositiveButton(R.string.ok, null) + .show() + } + } + override fun onNothingSelected(parent: AdapterView<*>?) {} + } binding.buttonCreate.setOnClickListener { createVolume() } @@ -112,7 +132,12 @@ class CreateActivity : VolumeActionActivity() { } } if (goodDirectory) { - if (GocryptfsVolume.createVolume(currentVolumePath, password, false, GocryptfsVolume.ScryptDefaultLogN, ConstValues.creator)) { + val xchacha = when (binding.spinnerXchacha.selectedItemPosition) { + 0 -> 0 + 1 -> 1 + else -> -1 + } + if (GocryptfsVolume.createVolume(currentVolumePath, password, false, xchacha, GocryptfsVolume.ScryptDefaultLogN, ConstValues.creator)) { var returnedHash: ByteArray? = null if (checkboxSavePassword.isChecked){ returnedHash = ByteArray(GocryptfsVolume.KeyLen) diff --git a/app/src/main/java/sushi/hardcore/droidfs/GocryptfsVolume.kt b/app/src/main/java/sushi/hardcore/droidfs/GocryptfsVolume.kt index 2ba0397..93242da 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/GocryptfsVolume.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/GocryptfsVolume.kt @@ -30,7 +30,7 @@ class GocryptfsVolume(var sessionID: Int) { const val KeyLen = 32 const val ScryptDefaultLogN = 16 const val DefaultBS = 4096 - external fun createVolume(root_cipher_dir: String, password: CharArray, plainTextNames: Boolean, logN: Int, creator: String): Boolean + external fun createVolume(root_cipher_dir: String, password: CharArray, plainTextNames: Boolean, xchacha: Int, logN: Int, creator: String): Boolean external fun init(root_cipher_dir: String, password: CharArray?, givenHash: ByteArray?, returnedHash: ByteArray?): Int external fun changePassword(root_cipher_dir: String, old_password: CharArray?, givenHash: ByteArray?, new_password: CharArray, returnedHash: ByteArray?): Boolean diff --git a/app/src/main/native/gocryptfs_jni.c b/app/src/main/native/gocryptfs_jni.c index 13d8e52..566f16d 100644 --- a/app/src/main/native/gocryptfs_jni.c +++ b/app/src/main/native/gocryptfs_jni.c @@ -33,6 +33,7 @@ JNIEXPORT jboolean JNICALL Java_sushi_hardcore_droidfs_GocryptfsVolume_00024Companion_createVolume(JNIEnv *env, jclass clazz, jstring jroot_cipher_dir, jcharArray jpassword, jboolean plainTextNames, + jint xchacha, jint logN, jstring jcreator) { const char* root_cipher_dir = (*env)->GetStringUTFChars(env, jroot_cipher_dir, NULL); @@ -45,7 +46,7 @@ Java_sushi_hardcore_droidfs_GocryptfsVolume_00024Companion_createVolume(JNIEnv * jcharArray_to_charArray(jchar_password, password, password_len); GoSlice go_password = {password, password_len, password_len}; - GoUint8 result = gcf_create_volume(gofilename, go_password, plainTextNames, logN, gocreator); + GoUint8 result = gcf_create_volume(gofilename, go_password, plainTextNames, xchacha, logN, gocreator); (*env)->ReleaseStringUTFChars(env, jroot_cipher_dir, root_cipher_dir); (*env)->ReleaseStringUTFChars(env, jcreator, creator); diff --git a/app/src/main/res/layout/activity_create.xml b/app/src/main/res/layout/activity_create.xml index fb4e442..96ca8f5 100644 --- a/app/src/main/res/layout/activity_create.xml +++ b/app/src/main/res/layout/activity_create.xml @@ -59,6 +59,24 @@ + + + + + + + + + + AES-GCM + XChaCha20-Poly1305 + @string/auto + + Name Size diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4d805ef..e08d7fa 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -206,4 +206,7 @@ Camera optimization Maximize quality Minimize latency + Auto + XChaCha20-Poly1305 is only supported since gocryptfs v2.2.0. Older versions won\'t be able to open a volume based on this cipher. + Encryption cipher: