fix issue #3: packing error when "algorithm_type = 0"

pull/31/head
cfig 6 years ago
parent ec32a3750a
commit b4f5a2b5b3
No known key found for this signature in database
GPG Key ID: B104C307F0FDABB7

@ -321,7 +321,7 @@ class Avb {
val alg = Algorithms.get(ai.header!!.algorithm_type.toInt())!! val alg = Algorithms.get(ai.header!!.algorithm_type.toInt())!!
val encodedDesc = ai.auxBlob!!.encodeDescriptors() val encodedDesc = ai.auxBlob!!.encodeDescriptors()
//encoded pubkey //encoded pubkey
val encodedKey = Blob.encodePubKey(alg, Files.readAllBytes(Paths.get(alg.defaultKey))) val encodedKey = Blob.encodePubKey(alg)
//3 - whole aux blob //3 - whole aux blob
var auxBlob = byteArrayOf() var auxBlob = byteArrayOf()

@ -12,26 +12,18 @@ import java.security.MessageDigest
class Blob { class Blob {
companion object { companion object {
fun encodePubKey(alg: Algorithm): ByteArray { fun encodePubKey(alg: Algorithm, key: ByteArray? = null): ByteArray {
var encodedKey = byteArrayOf() var encodedKey = byteArrayOf()
var algKey: ByteArray? = key
if (alg.public_key_num_bytes > 0) { if (alg.public_key_num_bytes > 0) {
encodedKey = Helper.encodeRSAkey(Files.readAllBytes((Paths.get(alg.defaultKey)))) if (key == null) {
log.info("encodePubKey(): size = ${alg.public_key_num_bytes}, algorithm key size: ${encodedKey.size}") algKey = Files.readAllBytes((Paths.get(alg.defaultKey)))
Assert.assertEquals(alg.public_key_num_bytes, encodedKey.size)
} else {
log.info("encodePubKey(): No key to encode for algorithm " + alg.name)
}
return encodedKey
} }
encodedKey = Helper.encodeRSAkey(algKey!!)
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}") log.info("encodePubKey(): size = ${alg.public_key_num_bytes}, algorithm key size: ${encodedKey.size}")
Assert.assertEquals(alg.public_key_num_bytes, encodedKey.size) Assert.assertEquals(alg.public_key_num_bytes, encodedKey.size)
} else { } else {
log.info("encodePubKey(): No key to use") log.info("encodePubKey(): No key to encode for algorithm " + alg.name)
} }
return encodedKey return encodedKey
} }

Loading…
Cancel
Save