Doug Zongker | 73ae31c | 2009-12-09 17:01:45 -0800 | [diff] [blame] | 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 | |
Doug Zongker | 7c3ae45 | 2013-05-14 11:03:02 -0700 | [diff] [blame] | 21 | #include "common.h" |
Doug Zongker | 73ae31c | 2009-12-09 17:01:45 -0800 | [diff] [blame] | 22 | #include "verifier.h" |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 23 | #include "ui.h" |
Doug Zongker | 73ae31c | 2009-12-09 17:01:45 -0800 | [diff] [blame] | 24 | |
| 25 | // This is build/target/product/security/testkey.x509.pem after being |
| 26 | // dumped out by dumpkey.jar. |
| 27 | RSAPublicKey test_key = |
| 28 | { 64, 0xc926ad21, |
| 29 | { 1795090719, 2141396315, 950055447, -1713398866, |
| 30 | -26044131, 1920809988, 546586521, -795969498, |
| 31 | 1776797858, -554906482, 1805317999, 1429410244, |
| 32 | 129622599, 1422441418, 1783893377, 1222374759, |
| 33 | -1731647369, 323993566, 28517732, 609753416, |
| 34 | 1826472888, 215237850, -33324596, -245884705, |
| 35 | -1066504894, 774857746, 154822455, -1797768399, |
| 36 | -1536767878, -1275951968, -1500189652, 87251430, |
| 37 | -1760039318, 120774784, 571297800, -599067824, |
| 38 | -1815042109, -483341846, -893134306, -1900097649, |
| 39 | -1027721089, 950095497, 555058928, 414729973, |
| 40 | 1136544882, -1250377212, 465547824, -236820568, |
| 41 | -1563171242, 1689838846, -404210357, 1048029507, |
| 42 | 895090649, 247140249, 178744550, -747082073, |
| 43 | -1129788053, 109881576, -350362881, 1044303212, |
| 44 | -522594267, -1309816990, -557446364, -695002876}, |
| 45 | { -857949815, -510492167, -1494742324, -1208744608, |
| 46 | 251333580, 2131931323, 512774938, 325948880, |
| 47 | -1637480859, 2102694287, -474399070, 792812816, |
| 48 | 1026422502, 2053275343, -1494078096, -1181380486, |
| 49 | 165549746, -21447327, -229719404, 1902789247, |
| 50 | 772932719, -353118870, -642223187, 216871947, |
| 51 | -1130566647, 1942378755, -298201445, 1055777370, |
| 52 | 964047799, 629391717, -2062222979, -384408304, |
| 53 | 191868569, -1536083459, -612150544, -1297252564, |
| 54 | -1592438046, -724266841, -518093464, -370899750, |
| 55 | -739277751, -1536141862, 1323144535, 61311905, |
| 56 | 1997411085, 376844204, 213777604, -217643712, |
| 57 | 9135381, 1625809335, -1490225159, -1342673351, |
| 58 | 1117190829, -57654514, 1825108855, -1281819325, |
| 59 | 1111251351, -1726129724, 1684324211, -1773988491, |
Doug Zongker | 1749527 | 2012-07-25 13:10:58 -0700 | [diff] [blame] | 60 | 367251975, 810756730, -1941182952, 1175080310 }, |
| 61 | 3 |
| 62 | }; |
| 63 | |
| 64 | RSAPublicKey test_f4_key = |
| 65 | { 64, 0xc9bd1f21, |
| 66 | { 293133087u, 3210546773u, 865313125u, 250921607u, |
| 67 | 3158780490u, 943703457u, 1242806226u, 2986289859u, |
| 68 | 2942743769u, 2457906415u, 2719374299u, 1783459420u, |
| 69 | 149579627u, 3081531591u, 3440738617u, 2788543742u, |
| 70 | 2758457512u, 1146764939u, 3699497403u, 2446203424u, |
| 71 | 1744968926u, 1159130537u, 2370028300u, 3978231572u, |
| 72 | 3392699980u, 1487782451u, 1180150567u, 2841334302u, |
| 73 | 3753960204u, 961373345u, 3333628321u, 748825784u, |
| 74 | 2978557276u, 1566596926u, 1613056060u, 2600292737u, |
| 75 | 1847226629u, 50398611u, 1890374404u, 2878700735u, |
| 76 | 2286201787u, 1401186359u, 619285059u, 731930817u, |
| 77 | 2340993166u, 1156490245u, 2992241729u, 151498140u, |
| 78 | 318782170u, 3480838990u, 2100383433u, 4223552555u, |
| 79 | 3628927011u, 4247846280u, 1759029513u, 4215632601u, |
| 80 | 2719154626u, 3490334597u, 1751299340u, 3487864726u, |
| 81 | 3668753795u, 4217506054u, 3748782284u, 3150295088u }, |
| 82 | { 1772626313u, 445326068u, 3477676155u, 1758201194u, |
| 83 | 2986784722u, 491035581u, 3922936562u, 702212696u, |
| 84 | 2979856666u, 3324974564u, 2488428922u, 3056318590u, |
| 85 | 1626954946u, 664714029u, 398585816u, 3964097931u, |
| 86 | 3356701905u, 2298377729u, 2040082097u, 3025491477u, |
| 87 | 539143308u, 3348777868u, 2995302452u, 3602465520u, |
| 88 | 212480763u, 2691021393u, 1307177300u, 704008044u, |
| 89 | 2031136606u, 1054106474u, 3838318865u, 2441343869u, |
| 90 | 1477566916u, 700949900u, 2534790355u, 3353533667u, |
| 91 | 336163563u, 4106790558u, 2701448228u, 1571536379u, |
| 92 | 1103842411u, 3623110423u, 1635278839u, 1577828979u, |
| 93 | 910322800u, 715583630u, 138128831u, 1017877531u, |
| 94 | 2289162787u, 447994798u, 1897243165u, 4121561445u, |
| 95 | 4150719842u, 2131821093u, 2262395396u, 3305771534u, |
| 96 | 980753571u, 3256525190u, 3128121808u, 1072869975u, |
| 97 | 3507939515u, 4229109952u, 118381341u, 2209831334u }, |
| 98 | 65537 |
Doug Zongker | 73ae31c | 2009-12-09 17:01:45 -0800 | [diff] [blame] | 99 | }; |
| 100 | |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 101 | RecoveryUI* ui = NULL; |
Doug Zongker | 73ae31c | 2009-12-09 17:01:45 -0800 | [diff] [blame] | 102 | |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 103 | // verifier expects to find a UI object; we provide one that does |
| 104 | // nothing but print. |
| 105 | class FakeUI : public RecoveryUI { |
| 106 | void Init() { } |
| 107 | void SetBackground(Icon icon) { } |
Doug Zongker | 73ae31c | 2009-12-09 17:01:45 -0800 | [diff] [blame] | 108 | |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 109 | void SetProgressType(ProgressType determinate) { } |
| 110 | void ShowProgress(float portion, float seconds) { } |
| 111 | void SetProgress(float fraction) { } |
| 112 | |
| 113 | void ShowText(bool visible) { } |
| 114 | bool IsTextVisible() { return false; } |
| 115 | bool WasTextEverVisible() { return false; } |
| 116 | void Print(const char* fmt, ...) { |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 117 | va_list ap; |
| 118 | va_start(ap, fmt); |
Doug Zongker | 7c3ae45 | 2013-05-14 11:03:02 -0700 | [diff] [blame] | 119 | vfprintf(stderr, fmt, ap); |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 120 | va_end(ap); |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 123 | void StartMenu(const char* const * headers, const char* const * items, |
| 124 | int initial_selection) { } |
| 125 | int SelectMenu(int sel) { return 0; } |
| 126 | void EndMenu() { } |
| 127 | }; |
Doug Zongker | 73ae31c | 2009-12-09 17:01:45 -0800 | [diff] [blame] | 128 | |
Doug Zongker | 7c3ae45 | 2013-05-14 11:03:02 -0700 | [diff] [blame] | 129 | void |
| 130 | ui_print(const char* format, ...) { |
| 131 | va_list ap; |
| 132 | va_start(ap, format); |
| 133 | vfprintf(stdout, format, ap); |
| 134 | va_end(ap); |
| 135 | } |
| 136 | |
Doug Zongker | 73ae31c | 2009-12-09 17:01:45 -0800 | [diff] [blame] | 137 | int main(int argc, char **argv) { |
Doug Zongker | 6c249f7 | 2012-11-02 15:04:05 -0700 | [diff] [blame] | 138 | if (argc < 2 || argc > 4) { |
| 139 | fprintf(stderr, "Usage: %s [-f4 | -file <keys>] <package>\n", argv[0]); |
Doug Zongker | 73ae31c | 2009-12-09 17:01:45 -0800 | [diff] [blame] | 140 | return 2; |
| 141 | } |
| 142 | |
Doug Zongker | 1749527 | 2012-07-25 13:10:58 -0700 | [diff] [blame] | 143 | RSAPublicKey* key = &test_key; |
Doug Zongker | 6c249f7 | 2012-11-02 15:04:05 -0700 | [diff] [blame] | 144 | int num_keys = 1; |
Doug Zongker | 1749527 | 2012-07-25 13:10:58 -0700 | [diff] [blame] | 145 | ++argv; |
| 146 | if (strcmp(argv[0], "-f4") == 0) { |
| 147 | ++argv; |
| 148 | key = &test_f4_key; |
Doug Zongker | 6c249f7 | 2012-11-02 15:04:05 -0700 | [diff] [blame] | 149 | } else if (strcmp(argv[0], "-file") == 0) { |
| 150 | ++argv; |
| 151 | key = load_keys(argv[0], &num_keys); |
| 152 | ++argv; |
Doug Zongker | 1749527 | 2012-07-25 13:10:58 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Doug Zongker | daefc1d | 2011-10-31 09:34:15 -0700 | [diff] [blame] | 155 | ui = new FakeUI(); |
| 156 | |
Doug Zongker | 6c249f7 | 2012-11-02 15:04:05 -0700 | [diff] [blame] | 157 | int result = verify_file(*argv, key, num_keys); |
Doug Zongker | 73ae31c | 2009-12-09 17:01:45 -0800 | [diff] [blame] | 158 | if (result == VERIFY_SUCCESS) { |
| 159 | printf("SUCCESS\n"); |
| 160 | return 0; |
| 161 | } else if (result == VERIFY_FAILURE) { |
| 162 | printf("FAILURE\n"); |
| 163 | return 1; |
| 164 | } else { |
| 165 | printf("bad return value\n"); |
| 166 | return 3; |
| 167 | } |
| 168 | } |