diff options
author | Koushik Dutta <koushd@gmail.com> | 2012-12-12 14:11:48 -0800 |
---|---|---|
committer | Koushik Dutta <koushd@gmail.com> | 2012-12-12 14:11:48 -0800 |
commit | d205d4b383861aa6cb2c8cb518f5ef419d603104 (patch) | |
tree | 981eff7862eca8258c001b467dcf333f45b94c93 | |
parent | 50f5fb001f7781b621322c0330fd61407fa79e28 (diff) | |
download | bootable_recovery-d205d4b383861aa6cb2c8cb518f5ef419d603104.zip bootable_recovery-d205d4b383861aa6cb2c8cb518f5ef419d603104.tar.gz bootable_recovery-d205d4b383861aa6cb2c8cb518f5ef419d603104.tar.bz2 |
Fix up RSA key loading bug in jellybean.
Change-Id: Iaa6af3eceeac8a92e056abd0bcfffcc805426f61
-rw-r--r-- | install.c | 68 |
1 files changed, 44 insertions, 24 deletions
@@ -285,31 +285,48 @@ load_keys(const char* filename, int* numKeys) { goto exit; } - int i; - bool done = false; - while (!done) { - ++*numKeys; - out = realloc(out, *numKeys * sizeof(RSAPublicKey)); - RSAPublicKey* key = out + (*numKeys - 1); - if (fscanf(f, " { %i , 0x%x , { %u", - &(key->len), &(key->n0inv), &(key->n[0])) != 3) { - goto exit; - } - if (key->len != RSANUMWORDS) { - LOGE("key length (%d) does not match expected size\n", key->len); - goto exit; - } - for (i = 1; i < key->len; ++i) { - if (fscanf(f, " , %u", &(key->n[i])) != 1) goto exit; - } - if (fscanf(f, " } , { %u", &(key->rr[0])) != 1) goto exit; - for (i = 1; i < key->len; ++i) { - if (fscanf(f, " , %u", &(key->rr[i])) != 1) goto exit; - } - fscanf(f, " } } "); + { + int i; + bool done = false; + while (!done) { + ++*numKeys; + out = (RSAPublicKey*)realloc(out, *numKeys * sizeof(RSAPublicKey)); + RSAPublicKey* key = out + (*numKeys - 1); + + char start_char; + if (fscanf(f, " %c", &start_char) != 1) goto exit; + if (start_char == '{') { + // a version 1 key has no version specifier. + key->exponent = 3; + } else if (start_char == 'v') { + int version; + if (fscanf(f, "%d {", &version) != 1) goto exit; + if (version == 2) { + key->exponent = 65537; + } else { + goto exit; + } + } + + if (fscanf(f, " %i , 0x%x , { %u", + &(key->len), &(key->n0inv), &(key->n[0])) != 3) { + goto exit; + } + if (key->len != RSANUMWORDS) { + LOGE("key length (%d) does not match expected size\n", key->len); + goto exit; + } + for (i = 1; i < key->len; ++i) { + if (fscanf(f, " , %u", &(key->n[i])) != 1) goto exit; + } + if (fscanf(f, " } , { %u", &(key->rr[0])) != 1) goto exit; + for (i = 1; i < key->len; ++i) { + if (fscanf(f, " , %u", &(key->rr[i])) != 1) goto exit; + } + fscanf(f, " } } "); - // if the line ends in a comma, this file has more keys. - switch (fgetc(f)) { + // if the line ends in a comma, this file has more keys. + switch (fgetc(f)) { case ',': // more keys to come. break; @@ -321,6 +338,9 @@ load_keys(const char* filename, int* numKeys) { default: LOGE("unexpected character between keys\n"); goto exit; + } + + LOGI("read key e=%d\n", key->exponent); } } |