blob: bc615249a6cc41678820400f831d3401d63bd056 [file] [log] [blame]
Shashank Mittal64d04852014-08-28 15:02:46 -07001/*
Sridhar Parasuram8b792422015-07-05 11:38:13 -07002 * Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
Shashank Mittal64d04852014-08-28 15:02:46 -07003 *
4 * Redistribution and use in source and binary forms, with or without
Sridhar Parasuram8b792422015-07-05 11:38:13 -07005 * modification, are permitted provided that the following conditions are
6 * met:
Shashank Mittal64d04852014-08-28 15:02:46 -07007 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
Sridhar Parasuram8b792422015-07-05 11:38:13 -07009 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Shashank Mittal64d04852014-08-28 15:02:46 -070028 */
Sridhar Parasuram8b792422015-07-05 11:38:13 -070029
Shashank Mittal64d04852014-08-28 15:02:46 -070030#ifndef __BOOT_VERIFIER_H
31#define __BOOT_VERIFIER_H
32
33#include <asn1.h>
34#include <rsa.h>
35
36/**
37 * AndroidVerifiedBootSignature DEFINITIONS ::=
38 * BEGIN
39 * FormatVersion ::= INTEGER
Sridhar Parasuram8b792422015-07-05 11:38:13 -070040 * Certificate ::= Certificate
Shashank Mittal64d04852014-08-28 15:02:46 -070041 * AlgorithmIdentifier ::= SEQUENCE {
42 * algorithm OBJECT IDENTIFIER,
43 * parameters ANY DEFINED BY algorithm OPTIONAL
44 * }
45 * AuthenticatedAttributes ::= SEQUENCE {
46 * target CHARACTER STRING,
47 * length INTEGER
48 * }
49 * Signature ::= OCTET STRING
50 * END
51 */
52
53typedef struct auth_attr_st
54{
55 ASN1_PRINTABLESTRING *target;
56 ASN1_INTEGER *len;
57}AUTH_ATTR;
58
59DECLARE_STACK_OF(AUTH_ATTR)
60DECLARE_ASN1_SET_OF(AUTH_ATTR)
61DECLARE_ASN1_FUNCTIONS(AUTH_ATTR)
62
63typedef struct verif_boot_sig_st
64{
65 ASN1_INTEGER *version;
Unnati Gandhi93334992015-02-25 19:38:38 +053066 X509 *certificate;
Shashank Mittal64d04852014-08-28 15:02:46 -070067 X509_ALGOR *algor;
68 AUTH_ATTR *auth_attr;
69 ASN1_OCTET_STRING *sig;
70}VERIFIED_BOOT_SIG;
71
72DECLARE_STACK_OF(VERIFIED_BOOT_SIG)
73DECLARE_ASN1_SET_OF(VERIFIED_BOOT_SIG)
74DECLARE_ASN1_FUNCTIONS(VERIFIED_BOOT_SIG)
75
76/**
77 * AndroidVerifiedBootKeystore DEFINITIONS ::=
78 * BEGIN
79 * FormatVersion ::= INTEGER
80 * KeyBag ::= SEQUENCE {
81 * Key ::= SEQUENCE {
82 * AlgorithmIdentifier ::= SEQUENCE {
83 * algorithm OBJECT IDENTIFIER,
84 * parameters ANY DEFINED BY algorithm OPTIONAL
85 * }
86 * KeyMaterial ::= RSAPublicKey
87 * }
88 * }
89 * Signature ::= AndroidVerifiedBootSignature
90 * END
91 */
92
93typedef struct key_st
94{
95 X509_ALGOR *algorithm_id;
96 RSA *key_material;
97}KEY;
98
99DECLARE_STACK_OF(KEY)
100DECLARE_ASN1_SET_OF(KEY)
101DECLARE_ASN1_FUNCTIONS(KEY)
102
103typedef struct keybag_st
104{
105 KEY *mykey;
106}KEYBAG;
107
108DECLARE_STACK_OF(KEYBAG)
109DECLARE_ASN1_SET_OF(KEYBAG)
110DECLARE_ASN1_FUNCTIONS(KEYBAG)
111
112typedef struct keystore_inner_st
113{
114 ASN1_INTEGER *version;
115 KEYBAG *mykeybag;
116}KEYSTORE_INNER;
117
118DECLARE_STACK_OF(KEYSTORE_INNER)
119DECLARE_ASN1_SET_OF(KEYSTORE_INNER)
120DECLARE_ASN1_FUNCTIONS(KEYSTORE_INNER)
121
122typedef struct keystore_st
123{
124 ASN1_INTEGER *version;
125 KEYBAG *mykeybag;
126 VERIFIED_BOOT_SIG *sig;
127}KEYSTORE;
128
129DECLARE_STACK_OF(KEYSTORE)
130DECLARE_ASN1_SET_OF(KEYSTORE)
131DECLARE_ASN1_FUNCTIONS(KEYSTORE)
132
133enum boot_state
134{
135 GREEN,
136 ORANGE,
137 YELLOW,
138 RED,
139};
140
141enum boot_verfiy_event
142{
143 BOOT_INIT,
144 DEV_UNLOCK,
Sridhar Parasuram8b792422015-07-05 11:38:13 -0700145 BOOTIMG_EMBEDDED_CERT_VERIFICATION_PASS,
146 BOOTIMG_KEYSTORE_VERIFICATION_PASS,
147 BOOTIMG_VERIFICATION_FAIL,
Shashank Mittal64d04852014-08-28 15:02:46 -0700148 USER_DENIES,
149};
150
151extern char KEYSTORE_PTN_NAME[];
152/* Function to initialize keystore */
153uint32_t boot_verify_keystore_init();
154/* Function to verify boot/recovery image */
155bool boot_verify_image(unsigned char* img_addr, uint32_t img_size, char *pname);
156/* Function to send event to boot state machine */
157void boot_verify_send_event(uint32_t event);
158/* Read current boot state */
159uint32_t boot_verify_get_state();
160/* Print current boot state */
161void boot_verify_print_state();
162/* Function to validate keystore */
163bool boot_verify_validate_keystore(unsigned char * user_addr);
164/* Function to check if partition is allowed to flash in verified mode */
Channagoud Kadabi1420b002015-01-13 14:48:12 -0800165bool boot_verify_flash_allowed(const char * entry);
Sridhar Parasuram00bfedb2015-05-26 14:21:27 -0700166/* Function to send root of trust to trust zone */
167bool send_rot_command();
Shashank Mittal64d04852014-08-28 15:02:46 -0700168#endif