summaryrefslogtreecommitdiffstats
path: root/verifier.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'verifier.cpp')
-rw-r--r--verifier.cpp40
1 files changed, 33 insertions, 7 deletions
diff --git a/verifier.cpp b/verifier.cpp
index 5f4c981e5..a93e8d18b 100644
--- a/verifier.cpp
+++ b/verifier.cpp
@@ -25,7 +25,9 @@
#include <stdio.h>
#include <errno.h>
-extern RecoveryUI* ui;
+//extern RecoveryUI* ui;
+
+#define PUBLIC_KEYS_FILE "/res/keys"
// Look for an RSA signature embedded in the .ZIP file comment given
// the path to the zip. Verify it matches one of the given public
@@ -33,9 +35,26 @@ extern RecoveryUI* ui;
//
// Return VERIFY_SUCCESS, VERIFY_FAILURE (if any error is encountered
// or no key matches the signature).
+int verify_file(const char* path) {
+ //ui->SetProgress(0.0);
-int verify_file(const char* path, const RSAPublicKey *pKeys, unsigned int numKeys) {
- ui->SetProgress(0.0);
+ int numKeys;
+ RSAPublicKey* loadedKeys = load_keys(PUBLIC_KEYS_FILE, &numKeys);
+ if (loadedKeys == NULL) {
+ LOGE("Failed to load keys\n");
+ return VERIFY_FAILURE;
+ }
+ /*
+ LOGI("%d key(s) loaded from %s\n\n RSA Key:\n\n", numKeys, PUBLIC_KEYS_FILE);
+ int rsa_size = sizeof(RSAPublicKey);
+ unsigned char* ptr = (unsigned char*) loadedKeys;
+ unsigned int valuedees;
+ for (int dees2 = 0; dees2 < rsa_size; dees2++) {
+ valuedees = *ptr;
+ printf("%02x ", valuedees);
+ ptr++;
+ }
+ printf("\n\n");*/
FILE* f = fopen(path, "rb");
if (f == NULL) {
@@ -163,7 +182,7 @@ int verify_file(const char* path, const RSAPublicKey *pKeys, unsigned int numKey
so_far += size;
double f = so_far / (double)signed_len;
if (f > frac + 0.02 || size == so_far) {
- ui->SetProgress(f);
+ //ui->SetProgress(f);
frac = f;
}
}
@@ -174,14 +193,16 @@ int verify_file(const char* path, const RSAPublicKey *pKeys, unsigned int numKey
for (i = 0; i < numKeys; ++i) {
// The 6 bytes is the "(signature_start) $ff $ff (comment_size)" that
// the signing tool appends after the signature itself.
- if (RSA_verify(pKeys+i, eocd + eocd_size - 6 - RSANUMBYTES,
- RSANUMBYTES, sha1)) {
+ int dees = RSA_verify(loadedKeys+i, eocd + eocd_size - 6 - RSANUMBYTES,
+ RSANUMBYTES, sha1);
+ if (dees) {
LOGI("whole-file signature verified against key %d\n", i);
free(eocd);
return VERIFY_SUCCESS;
} else {
LOGI("failed to verify against key %d\n", i);
}
+ LOGI("i: %i, eocd_size: %i, RSANUMBYTES: %i, returned %i\n", i, eocd_size, RSANUMBYTES, dees);
}
free(eocd);
LOGE("failed to verify whole-file signature\n");
@@ -227,6 +248,7 @@ load_keys(const char* filename, int* numKeys) {
out = (RSAPublicKey*)realloc(out, *numKeys * sizeof(RSAPublicKey));
RSAPublicKey* key = out + (*numKeys - 1);
+#ifdef HAS_EXPONENT
char start_char;
if (fscanf(f, " %c", &start_char) != 1) goto exit;
if (start_char == '{') {
@@ -243,6 +265,9 @@ load_keys(const char* filename, int* numKeys) {
}
if (fscanf(f, " %i , 0x%x , { %u",
+#else
+ if (fscanf(f, " { %i , 0x%x , { %u",
+#endif
&(key->len), &(key->n0inv), &(key->n[0])) != 3) {
goto exit;
}
@@ -273,8 +298,9 @@ load_keys(const char* filename, int* numKeys) {
LOGE("unexpected character between keys\n");
goto exit;
}
-
+#ifdef HAS_EXPONENT
LOGI("read key e=%d\n", key->exponent);
+#endif
}
}