Random dname

This commit is contained in:
topjohnwu 2019-11-01 18:52:37 -04:00
parent d8d72f92b3
commit 4cd154675f

View File

@ -38,7 +38,7 @@ class Keygen: CertKeyProvider {
private const val ALIAS = "magisk" private const val ALIAS = "magisk"
private val PASSWORD get() = "magisk".toCharArray() private val PASSWORD get() = "magisk".toCharArray()
private const val TESTKEY_CERT = "61ed377e85d386a8dfee6b864bd85b0bfaa5af81" private const val TESTKEY_CERT = "61ed377e85d386a8dfee6b864bd85b0bfaa5af81"
private const val DNAME = "C=US,ST=California,L=Mountain View,O=Google Inc.,OU=Android,CN=Android" private const val ALPHANUM = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
private const val BASE64_FLAG = Base64.NO_PADDING or Base64.NO_WRAP private const val BASE64_FLAG = Base64.NO_PADDING or Base64.NO_WRAP
} }
@ -88,6 +88,17 @@ class Keygen: CertKeyProvider {
} }
} }
private fun randomString(): String {
val rand = kotlin.random.Random.Default
val len = rand.nextInt(5, 10)
val sb = StringBuilder(len)
for (i in 0..len) {
val idx = rand.nextInt(ALPHANUM.length)
sb.append(ALPHANUM[idx])
}
return sb.toString()
}
private fun init(): KeyStore { private fun init(): KeyStore {
GlobalContext.getOrNull() ?: { GlobalContext.getOrNull() ?: {
// Invoked externally, do some basic initialization // Invoked externally, do some basic initialization
@ -113,7 +124,7 @@ class Keygen: CertKeyProvider {
// Generate new private key and certificate // Generate new private key and certificate
val kp = KeyPairGenerator.getInstance("RSA").apply { initialize(4096) }.genKeyPair() val kp = KeyPairGenerator.getInstance("RSA").apply { initialize(4096) }.genKeyPair()
val dname = X500Name(DNAME) val dname = X500Name("CN=${randomString()}")
val builder = JcaX509v3CertificateBuilder(dname, BigInteger(160, Random()), val builder = JcaX509v3CertificateBuilder(dname, BigInteger(160, Random()),
start.time, end.time, dname, kp.public) start.time, end.time, dname, kp.public)
val signer = JcaContentSignerBuilder("SHA256WithRSA").build(kp.private) val signer = JcaContentSignerBuilder("SHA256WithRSA").build(kp.private)