feat: Do not generate a new keystore each time Patcher runs

This commit is contained in:
Alberto Ponces 2022-09-07 18:25:12 +01:00
parent 825a57ee69
commit 63c1fdf9c5
3 changed files with 13 additions and 6 deletions

View File

@ -45,6 +45,7 @@ class MainActivity : FlutterActivity() {
val cacheDirPath = call.argument<String>("cacheDirPath")
val mergeIntegrations = call.argument<Boolean>("mergeIntegrations")
val resourcePatching = call.argument<Boolean>("resourcePatching")
val keyStoreFilePath = call.argument<String>("keyStoreFilePath")
if (patchBundleFilePath != null &&
originalFilePath != null &&
inputFilePath != null &&
@ -54,7 +55,8 @@ class MainActivity : FlutterActivity() {
selectedPatches != null &&
cacheDirPath != null &&
mergeIntegrations != null &&
resourcePatching != null
resourcePatching != null &&
keyStoreFilePath != null
) {
runPatcher(
result,
@ -67,7 +69,8 @@ class MainActivity : FlutterActivity() {
selectedPatches,
cacheDirPath,
mergeIntegrations,
resourcePatching
resourcePatching,
keyStoreFilePath
)
} else {
result.notImplemented()
@ -89,13 +92,15 @@ class MainActivity : FlutterActivity() {
selectedPatches: List<String>,
cacheDirPath: String,
mergeIntegrations: Boolean,
resourcePatching: Boolean
resourcePatching: Boolean,
keyStoreFilePath: String
) {
val originalFile = File(originalFilePath)
val inputFile = File(inputFilePath)
val patchedFile = File(patchedFilePath)
val outFile = File(outFilePath)
val integrations = File(integrationsPath)
val keyStoreFile = File(keyStoreFilePath)
val patches =
DexPatchBundle(
@ -314,7 +319,7 @@ class MainActivity : FlutterActivity() {
)
)
}
Signer("ReVanced", "s3cur3p@ssw0rd").signApk(patchedFile, outFile)
Signer("ReVanced", "s3cur3p@ssw0rd").signApk(patchedFile, outFile, keyStoreFile)
handler.post {
installerChannel.invokeMethod(

View File

@ -49,10 +49,9 @@ internal class Signer(
return JcaX509CertificateConverter().getCertificate(builder.build(signer)) to pair.private
}
fun signApk(input: File, output: File) {
fun signApk(input: File, output: File, ks: File) {
Security.addProvider(BouncyCastleProvider())
val ks = File(input.parent, "revanced-cli.keystore")
if (!ks.exists()) newKeystore(ks)
val keyStore = KeyStore.getInstance("BKS", "BC")

View File

@ -18,6 +18,7 @@ class PatcherAPI {
final ManagerAPI _managerAPI = locator<ManagerAPI>();
final RootAPI _rootAPI = RootAPI();
late Directory _tmpDir;
late File _keyStoreFile;
List<Patch> _patches = [];
File? _outFile;
@ -25,6 +26,7 @@ class PatcherAPI {
await _loadPatches();
Directory appCache = await getTemporaryDirectory();
_tmpDir = Directory('${appCache.path}/patcher');
_keyStoreFile = File('${appCache.path}/revanced-manager.keystore');
cleanPatcher();
}
@ -138,6 +140,7 @@ class PatcherAPI {
'cacheDirPath': cacheDir.path,
'mergeIntegrations': mergeIntegrations,
'resourcePatching': resourcePatching,
'keyStoreFilePath': _keyStoreFile.path,
},
);
}