From 17495277b1a6328f5cae68523ad00be1f1107950 Mon Sep 17 00:00:00 2001 From: Doug Zongker Date: Wed, 25 Jul 2012 13:10:58 -0700 Subject: support version 2 (2048-bit e=65537) keys in recovery Change-Id: I9849c69777d513bb12926c8c622d1c12d2da568a --- install.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'install.cpp') diff --git a/install.cpp b/install.cpp index 4d73aa9b0..819650e1f 100644 --- a/install.cpp +++ b/install.cpp @@ -180,6 +180,12 @@ try_update_binary(const char *path, ZipArchive *zip, int* wipe_cache) { // // "{64,0xc926ad21,{1795090719,...,-695002876},{-857949815,...,1175080310}}" // +// For key versions newer than the original 2048-bit e=3 keys +// supported by Android, the string is preceded by a version +// identifier, eg: +// +// "v2 {64,0xc926ad21,{1795090719,...,-695002876},{-857949815,...,1175080310}}" +// // (Note that the braces and commas in this example are actual // characters the parser expects to find in the file; the ellipses // indicate more numbers omitted from this example.) @@ -206,7 +212,23 @@ load_keys(const char* filename, int* numKeys) { ++*numKeys; out = (RSAPublicKey*)realloc(out, *numKeys * sizeof(RSAPublicKey)); RSAPublicKey* key = out + (*numKeys - 1); - if (fscanf(f, " { %i , 0x%x , { %u", + + 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; } @@ -237,6 +259,8 @@ load_keys(const char* filename, int* numKeys) { LOGE("unexpected character between keys\n"); goto exit; } + + LOGI("read key e=%d\n", key->exponent); } } -- cgit v1.2.3