Home | History | Annotate | Download | only in recovery
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include <stdio.h>
     18 #include <stdlib.h>
     19 #include <stdarg.h>
     20 
     21 #include "verifier.h"
     22 #include "ui.h"
     23 
     24 // This is build/target/product/security/testkey.x509.pem after being
     25 // dumped out by dumpkey.jar.
     26 RSAPublicKey test_key =
     27     { 64, 0xc926ad21,
     28       { 1795090719, 2141396315, 950055447, -1713398866,
     29         -26044131, 1920809988, 546586521, -795969498,
     30         1776797858, -554906482, 1805317999, 1429410244,
     31         129622599, 1422441418, 1783893377, 1222374759,
     32         -1731647369, 323993566, 28517732, 609753416,
     33         1826472888, 215237850, -33324596, -245884705,
     34         -1066504894, 774857746, 154822455, -1797768399,
     35         -1536767878, -1275951968, -1500189652, 87251430,
     36         -1760039318, 120774784, 571297800, -599067824,
     37         -1815042109, -483341846, -893134306, -1900097649,
     38         -1027721089, 950095497, 555058928, 414729973,
     39         1136544882, -1250377212, 465547824, -236820568,
     40         -1563171242, 1689838846, -404210357, 1048029507,
     41         895090649, 247140249, 178744550, -747082073,
     42         -1129788053, 109881576, -350362881, 1044303212,
     43         -522594267, -1309816990, -557446364, -695002876},
     44       { -857949815, -510492167, -1494742324, -1208744608,
     45         251333580, 2131931323, 512774938, 325948880,
     46         -1637480859, 2102694287, -474399070, 792812816,
     47         1026422502, 2053275343, -1494078096, -1181380486,
     48         165549746, -21447327, -229719404, 1902789247,
     49         772932719, -353118870, -642223187, 216871947,
     50         -1130566647, 1942378755, -298201445, 1055777370,
     51         964047799, 629391717, -2062222979, -384408304,
     52         191868569, -1536083459, -612150544, -1297252564,
     53         -1592438046, -724266841, -518093464, -370899750,
     54         -739277751, -1536141862, 1323144535, 61311905,
     55         1997411085, 376844204, 213777604, -217643712,
     56         9135381, 1625809335, -1490225159, -1342673351,
     57         1117190829, -57654514, 1825108855, -1281819325,
     58         1111251351, -1726129724, 1684324211, -1773988491,
     59         367251975, 810756730, -1941182952, 1175080310 }
     60     };
     61 
     62 RecoveryUI* ui = NULL;
     63 
     64 // verifier expects to find a UI object; we provide one that does
     65 // nothing but print.
     66 class FakeUI : public RecoveryUI {
     67     void Init() { }
     68     void SetBackground(Icon icon) { }
     69 
     70     void SetProgressType(ProgressType determinate) { }
     71     void ShowProgress(float portion, float seconds) { }
     72     void SetProgress(float fraction) { }
     73 
     74     void ShowText(bool visible) { }
     75     bool IsTextVisible() { return false; }
     76     bool WasTextEverVisible() { return false; }
     77     void Print(const char* fmt, ...) {
     78         char buf[256];
     79         va_list ap;
     80         va_start(ap, fmt);
     81         vsnprintf(buf, 256, fmt, ap);
     82         va_end(ap);
     83 
     84         fputs(buf, stderr);
     85     }
     86 
     87     void StartMenu(const char* const * headers, const char* const * items,
     88                            int initial_selection) { }
     89     int SelectMenu(int sel) { return 0; }
     90     void EndMenu() { }
     91 };
     92 
     93 int main(int argc, char **argv) {
     94     if (argc != 2) {
     95         fprintf(stderr, "Usage: %s <package>\n", argv[0]);
     96         return 2;
     97     }
     98 
     99     ui = new FakeUI();
    100 
    101     int result = verify_file(argv[1], &test_key, 1);
    102     if (result == VERIFY_SUCCESS) {
    103         printf("SUCCESS\n");
    104         return 0;
    105     } else if (result == VERIFY_FAILURE) {
    106         printf("FAILURE\n");
    107         return 1;
    108     } else {
    109         printf("bad return value\n");
    110         return 3;
    111     }
    112 }
    113