diff --git a/bbootimg/src/main/kotlin/Avb.kt b/bbootimg/src/main/kotlin/Avb.kt index dca9013..ad04498 100755 --- a/bbootimg/src/main/kotlin/Avb.kt +++ b/bbootimg/src/main/kotlin/Avb.kt @@ -321,7 +321,7 @@ class Avb { val alg = Algorithms.get(ai.header!!.algorithm_type.toInt())!! val encodedDesc = ai.auxBlob!!.encodeDescriptors() //encoded pubkey - val encodedKey = Blob.encodePubKey(alg, Files.readAllBytes(Paths.get(alg.defaultKey))) + val encodedKey = Blob.encodePubKey(alg) //3 - whole aux blob var auxBlob = byteArrayOf() diff --git a/bbootimg/src/main/kotlin/avb/Blob.kt b/bbootimg/src/main/kotlin/avb/Blob.kt index 177c3f6..2a7f3b9 100644 --- a/bbootimg/src/main/kotlin/avb/Blob.kt +++ b/bbootimg/src/main/kotlin/avb/Blob.kt @@ -12,10 +12,14 @@ import java.security.MessageDigest class Blob { companion object { - fun encodePubKey(alg: Algorithm): ByteArray { + fun encodePubKey(alg: Algorithm, key: ByteArray? = null): ByteArray { var encodedKey = byteArrayOf() + var algKey: ByteArray? = key if (alg.public_key_num_bytes > 0) { - encodedKey = Helper.encodeRSAkey(Files.readAllBytes((Paths.get(alg.defaultKey)))) + if (key == null) { + algKey = Files.readAllBytes((Paths.get(alg.defaultKey))) + } + encodedKey = Helper.encodeRSAkey(algKey!!) log.info("encodePubKey(): size = ${alg.public_key_num_bytes}, algorithm key size: ${encodedKey.size}") Assert.assertEquals(alg.public_key_num_bytes, encodedKey.size) } else { @@ -24,18 +28,6 @@ class Blob { return encodedKey } - fun encodePubKey(alg: Algorithm, key: ByteArray): ByteArray { - var encodedKey = byteArrayOf() - if (alg.public_key_num_bytes > 0) { - encodedKey = Helper.encodeRSAkey(key) - log.info("encodePubKey(): size = ${alg.public_key_num_bytes}, algorithm key size: ${encodedKey.size}") - Assert.assertEquals(alg.public_key_num_bytes, encodedKey.size) - } else { - log.info("encodePubKey(): No key to use") - } - return encodedKey - } - //TODO: support pkmd_blob //encoded_descriptors + encoded_key + pkmd_blob + (padding) fun getAuxDataBlob(encodedDesc: ByteArray, encodedKey: ByteArray): ByteArray {