1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Permission is hereby granted, free of charge, to any person 5 * obtaining a copy of this software and associated documentation 6 * files (the "Software"), to deal in the Software without 7 * restriction, including without limitation the rights to use, copy, 8 * modify, merge, publish, distribute, sublicense, and/or sell copies 9 * of the Software, and to permit persons to whom the Software is 10 * furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be 13 * included in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 * SOFTWARE. 23 */ 24 25 /* 26 #if !defined(AVB_INSIDE_LIBAVB_ATX_H) && !defined(AVB_COMPILATION) 27 #error \ 28 "Never include this file directly, include libavb_atx/libavb_atx.h instead." 29 #endif 30 */ 31 32 #ifndef AVB_ATX_VALIDATE_H_ 33 #define AVB_ATX_VALIDATE_H_ 34 35 #include <android_avb/avb_atx_ops.h> 36 #include <android_avb/avb_atx_types.h> 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 /* Rollback index locations for Android Things key versions. */ 43 #define AVB_ATX_PIK_VERSION_LOCATION 0x1000 44 #define AVB_ATX_PSK_VERSION_LOCATION 0x1001 45 46 /** 47 * read permanent attributes from rpmb 48 * 49 * @param atx_ops 50 * 51 * @param attributes The attributes inclue psk_public product id, 52 * ref:AvbAtxPermanentAttributes. 53 * 54 * @return AvbIOResult 55 */ 56 AvbIOResult avb_read_perm_attr(AvbAtxOps* atx_ops, 57 AvbAtxPermanentAttributes* attributes); 58 59 /** 60 * read permanent attributes hash from efuse 61 * 62 * @param atx_ops 63 * 64 * @param attributes The attributes inclue psk_public product id, 65 * ref:AvbAtxPermanentAttributes. 66 * 67 * @return AvbIOResult 68 */ 69 AvbIOResult avb_read_perm_attr_hash(AvbAtxOps* atx_ops, 70 uint8_t hash[AVB_SHA256_DIGEST_SIZE]); 71 /* An implementation of validate_vbmeta_public_key for Android Things. See 72 * libavb/avb_ops.h for details on validate_vbmeta_public_key in general. This 73 * implementation uses the metadata expected with Android Things vbmeta images 74 * to perform validation on the public key. The ATX ops must be implemented. 75 * That is, |ops->atx_ops| must be valid. 76 * 77 * There are a multiple values that need verification: 78 * - Permanent Product Attributes: A hash of these attributes is fused into 79 * hardware. Consistency is checked. 80 * - Product Root Key (PRK): This key is provided in permanent attributes and 81 * is the root authority for all Android Things 82 * products. 83 * - Product Intermediate Key (PIK): This key is a rotated intermediary. It is 84 * certified by the PRK. 85 * - Product Signing Key (PSK): This key is a rotated authority for a specific 86 * Android Things product. It is certified by a 87 * PIK and must match |public_key_data|. 88 * - Product ID: This value is provided in permanent attributes and is unique 89 * to a specific Android Things product. This value must match 90 * the subject of the PSK certificate. 91 */ 92 AvbIOResult avb_atx_validate_vbmeta_public_key( 93 AvbOps* ops, 94 const uint8_t* public_key_data, 95 size_t public_key_length, 96 const uint8_t* public_key_metadata, 97 size_t public_key_metadata_length, 98 bool* out_is_trusted); 99 100 #ifdef __cplusplus 101 } 102 #endif 103 104 #endif /* AVB_ATX_VALIDATE_H_ */ 105