Skip to content

Commit

Permalink
fix: Use BKS instead of default signing provider to fix backwards c…
Browse files Browse the repository at this point in the history
…ompatibility
  • Loading branch information
oSumAtrIX committed Mar 4, 2024
1 parent 0e9939f commit 41805fc
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/main/kotlin/app/revanced/library/ApkSigner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.bouncycastle.asn1.x500.X500Name
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo
import org.bouncycastle.cert.X509v3CertificateBuilder
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder
import java.io.File
import java.io.IOException
Expand All @@ -24,7 +25,13 @@ import kotlin.time.Duration.Companion.days
*/
@Suppress("MemberVisibilityCanBePrivate", "unused")
object ApkSigner {
private val logger = Logger.getLogger(Signer::class.java.name)
private val logger = Logger.getLogger(ApkSigner::class.java.name)

init {
if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
Security.addProvider(BouncyCastleProvider())
}
}

/**
* Create a new [PrivateKeyCertificatePair].
Expand Down Expand Up @@ -117,7 +124,7 @@ object ApkSigner {
fun newKeyStore(entries: Set<KeyStoreEntry>): KeyStore {
logger.fine("Creating keystore")

return KeyStore.getInstance(KeyStore.getDefaultType()).apply {
return newKeyStoreInstance().apply {
load(null)

entries.forEach { entry ->
Expand All @@ -132,6 +139,8 @@ object ApkSigner {
}
}

private fun newKeyStoreInstance() = KeyStore.getInstance("BKS", BouncyCastleProvider.PROVIDER_NAME)

/**
* Create a new keystore with a new keypair and saves it to the given [keyStoreOutputStream].
*
Expand Down Expand Up @@ -164,7 +173,7 @@ object ApkSigner {
): KeyStore {
logger.fine("Reading keystore")

return KeyStore.getInstance(KeyStore.getDefaultType()).apply {
return newKeyStoreInstance().apply {
try {
load(keyStoreInputStream, keyStorePassword?.toCharArray())
} catch (exception: IOException) {
Expand Down

0 comments on commit 41805fc

Please sign in to comment.