From 9581ae824511d85ae209bf597c5548f8a29b25c8 Mon Sep 17 00:00:00 2001 From: RikkaW Date: Mon, 25 Apr 2022 17:35:53 +0800 Subject: [PATCH] Use Locale.ROOT in JcaX509v3CertificateBuilder (X509v3CertificateBuilder) Or in languages like Arabic, an "IllegalArgumentException: invalid date string" will be thrown. Since JcaX509v3CertificateBuilder does not accepts Locales, we must switch to its super class, X509v3CertificateBuilder. --- .../java/com/topjohnwu/magisk/core/utils/Keygen.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/utils/Keygen.kt b/app/src/main/java/com/topjohnwu/magisk/core/utils/Keygen.kt index 9d8091961..f4e834815 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/utils/Keygen.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/utils/Keygen.kt @@ -4,8 +4,9 @@ import android.util.Base64 import android.util.Base64OutputStream import com.topjohnwu.magisk.core.Config 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.cert.jcajce.JcaX509v3CertificateBuilder import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder import java.io.ByteArrayOutputStream import java.math.BigInteger @@ -56,8 +57,11 @@ class Keygen : CertKeyProvider { // Generate new private key and certificate val kp = KeyPairGenerator.getInstance("RSA").apply { initialize(4096) }.genKeyPair() val dname = X500Name(DNAME) - val builder = JcaX509v3CertificateBuilder(dname, BigInteger(160, Random()), - start.time, end.time, dname, kp.public) + val builder = X509v3CertificateBuilder( + dname, BigInteger(160, Random()), + start.time, end.time, Locale.ROOT, dname, + SubjectPublicKeyInfo.getInstance(kp.public.encoded) + ) val signer = JcaContentSignerBuilder("SHA1WithRSA").build(kp.private) val cert = JcaX509CertificateConverter().getCertificate(builder.build(signer))