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 /* An implementation of validate_vbmeta_public_key for Android Things. See 47 * libavb/avb_ops.h for details on validate_vbmeta_public_key in general. This 48 * implementation uses the metadata expected with Android Things vbmeta images 49 * to perform validation on the public key. The ATX ops must be implemented. 50 * That is, |ops->atx_ops| must be valid. 51 * 52 * There are a multiple values that need verification: 53 * - Permanent Product Attributes: A hash of these attributes is fused into 54 * hardware. Consistency is checked. 55 * - Product Root Key (PRK): This key is provided in permanent attributes and 56 * is the root authority for all Android Things 57 * products. 58 * - Product Intermediate Key (PIK): This key is a rotated intermediary. It is 59 * certified by the PRK. 60 * - Product Signing Key (PSK): This key is a rotated authority for a specific 61 * Android Things product. It is certified by a 62 * PIK and must match |public_key_data|. 63 * - Product ID: This value is provided in permanent attributes and is unique 64 * to a specific Android Things product. This value must match 65 * the subject of the PSK certificate. 66 */ 67 AvbIOResult avb_atx_validate_vbmeta_public_key( 68 AvbOps* ops, 69 const uint8_t* public_key_data, 70 size_t public_key_length, 71 const uint8_t* public_key_metadata, 72 size_t public_key_metadata_length, 73 bool* out_is_trusted); 74 75 /* Generates a challenge which can be used to create an unlock credential. */ 76 AvbIOResult avb_atx_generate_unlock_challenge( 77 AvbAtxOps* atx_ops, AvbAtxUnlockChallenge* out_unlock_challenge); 78 79 /* Validates an unlock credential. The certificate validation is very similar to 80 * the validation of public key metadata except in place of the PSK is a Product 81 * Unlock Key (PUK) and the certificate usage field identifies it as such. The 82 * challenge signature field is verified against this PUK. 83 */ 84 AvbIOResult avb_atx_validate_unlock_credential( 85 AvbAtxOps* atx_ops, 86 const AvbAtxUnlockCredential* unlock_credential, 87 bool* out_is_trusted); 88 89 #ifdef __cplusplus 90 } 91 #endif 92 93 #endif /* AVB_ATX_VALIDATE_H_ */ 94