Skip to content

Commit aeab639

Browse files
authored
fix: Migration of keystore, by fixing mislabeling of alias as cn (#2769)
1 parent 4016ae7 commit aeab639

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

app/src/main/java/app/revanced/manager/domain/manager/KeystoreManager.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,25 @@ class KeystoreManager(app: Application, private val prefs: PreferencesManager) {
2727
private val keystorePath =
2828
app.getDir("signing", Context.MODE_PRIVATE).resolve("manager.keystore")
2929

30-
private suspend fun updatePrefs(cn: String, pass: String) = prefs.edit {
31-
prefs.keystoreCommonName.value = cn
30+
private suspend fun updatePrefs(alias: String, pass: String) = prefs.edit {
31+
prefs.keystoreAlias.value = alias
3232
prefs.keystorePass.value = pass
3333
}
3434

3535
private suspend fun signingDetails(path: File = keystorePath) = ApkUtils.KeyStoreDetails(
3636
keyStore = path,
3737
keyStorePassword = null,
38-
alias = prefs.keystoreCommonName.get(),
38+
alias = prefs.keystoreAlias.get(),
3939
password = prefs.keystorePass.get()
4040
)
4141

4242
suspend fun sign(input: File, output: File) = withContext(Dispatchers.Default) {
43-
ApkUtils.signApk(input, output, prefs.keystoreCommonName.get(), signingDetails())
43+
ApkUtils.signApk(input, output, prefs.keystoreAlias.get(), signingDetails())
4444
}
4545

4646
suspend fun regenerate() = withContext(Dispatchers.Default) {
4747
val keyCertPair = ApkSigner.newPrivateKeyCertificatePair(
48-
prefs.keystoreCommonName.get(),
48+
prefs.keystoreAlias.get(),
4949
eightYearsFromNow
5050
)
5151
val ks = ApkSigner.newKeyStore(
@@ -64,13 +64,13 @@ class KeystoreManager(app: Application, private val prefs: PreferencesManager) {
6464
updatePrefs(DEFAULT, DEFAULT)
6565
}
6666

67-
suspend fun import(cn: String, pass: String, keystore: InputStream): Boolean {
67+
suspend fun import(alias: String, pass: String, keystore: InputStream): Boolean {
6868
val keystoreData = withContext(Dispatchers.IO) { keystore.readBytes() }
6969

7070
try {
7171
val ks = ApkSigner.readKeyStore(ByteArrayInputStream(keystoreData), null)
7272

73-
ApkSigner.readPrivateKeyCertificatePair(ks, cn, pass)
73+
ApkSigner.readPrivateKeyCertificatePair(ks, alias, pass)
7474
} catch (_: UnrecoverableKeyException) {
7575
return false
7676
} catch (_: IllegalArgumentException) {
@@ -81,7 +81,7 @@ class KeystoreManager(app: Application, private val prefs: PreferencesManager) {
8181
Files.write(keystorePath.toPath(), keystoreData)
8282
}
8383

84-
updatePrefs(cn, pass)
84+
updatePrefs(alias, pass)
8585
return true
8686
}
8787

app/src/main/java/app/revanced/manager/domain/manager/PreferencesManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class PreferencesManager(
1616
val useProcessRuntime = booleanPreference("use_process_runtime", false)
1717
val patcherProcessMemoryLimit = intPreference("process_runtime_memory_limit", 700)
1818

19-
val keystoreCommonName = stringPreference("keystore_cn", KeystoreManager.DEFAULT)
19+
val keystoreAlias = stringPreference("keystore_alias", KeystoreManager.DEFAULT)
2020
val keystorePass = stringPreference("keystore_pass", KeystoreManager.DEFAULT)
2121

2222
val firstLaunch = booleanPreference("first_launch", true)

app/src/main/java/app/revanced/manager/ui/screen/settings/ImportExportSettingsScreen.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ fun ImportExportSettingsScreen(
104104
if (vm.showCredentialsDialog) {
105105
KeystoreCredentialsDialog(
106106
onDismissRequest = vm::cancelKeystoreImport,
107-
onSubmit = { cn, pass ->
107+
onSubmit = { alias, pass ->
108108
vm.viewModelScope.launch {
109109
uiSafe(context, R.string.failed_to_import_keystore, "Failed to import keystore") {
110-
val result = vm.tryKeystoreImport(cn, pass)
110+
val result = vm.tryKeystoreImport(alias, pass)
111111
if (!result) context.toast(context.getString(R.string.import_keystore_wrong_credentials))
112112
}
113113
}
@@ -382,15 +382,15 @@ fun KeystoreCredentialsDialog(
382382
onDismissRequest: () -> Unit,
383383
onSubmit: (String, String) -> Unit
384384
) {
385-
var cn by rememberSaveable { mutableStateOf("") }
385+
var alias by rememberSaveable { mutableStateOf("") }
386386
var pass by rememberSaveable { mutableStateOf("") }
387387

388388
AlertDialog(
389389
onDismissRequest = onDismissRequest,
390390
confirmButton = {
391391
TextButton(
392392
onClick = {
393-
onSubmit(cn, pass)
393+
onSubmit(alias, pass)
394394
}
395395
) {
396396
Text(stringResource(R.string.import_keystore_dialog_button))
@@ -422,8 +422,8 @@ fun KeystoreCredentialsDialog(
422422
color = MaterialTheme.colorScheme.onSurfaceVariant
423423
)
424424
OutlinedTextField(
425-
value = cn,
426-
onValueChange = { cn = it },
425+
value = alias,
426+
onValueChange = { alias = it },
427427
label = { Text(stringResource(R.string.import_keystore_dialog_alias_field)) }
428428
)
429429
PasswordField(

app/src/main/java/app/revanced/manager/ui/viewmodel/ImportExportViewModel.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ class ImportExportViewModel(
154154
keystoreImportPath = null
155155
}
156156

157-
suspend fun tryKeystoreImport(cn: String, pass: String) =
158-
tryKeystoreImport(cn, pass, keystoreImportPath!!)
157+
suspend fun tryKeystoreImport(alias: String, pass: String) =
158+
tryKeystoreImport(alias, pass, keystoreImportPath!!)
159159

160-
private suspend fun tryKeystoreImport(cn: String, pass: String, path: Path): Boolean {
160+
private suspend fun tryKeystoreImport(alias: String, pass: String, path: Path): Boolean {
161161
path.inputStream().use { stream ->
162-
if (keystoreManager.import(cn, pass, stream)) {
162+
if (keystoreManager.import(alias, pass, stream)) {
163163
app.toast(app.getString(R.string.import_keystore_success))
164164
cancelKeystoreImport()
165165
return true

app/src/main/java/app/revanced/manager/ui/viewmodel/MainViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class MainViewModel(
143143
settings.keystore?.let { keystore ->
144144
val keystoreBytes = Base64.decode(keystore, Base64.DEFAULT)
145145
keystoreManager.import(
146-
"ReVanced",
146+
"alias",
147147
settings.keystorePassword,
148148
keystoreBytes.inputStream()
149149
)

0 commit comments

Comments
 (0)