13ccd4bb0SJason Zhu /* 23ccd4bb0SJason Zhu * Copyright (C) 2016 The Android Open Source Project 33ccd4bb0SJason Zhu * 43ccd4bb0SJason Zhu * Permission is hereby granted, free of charge, to any person 53ccd4bb0SJason Zhu * obtaining a copy of this software and associated documentation 63ccd4bb0SJason Zhu * files (the "Software"), to deal in the Software without 73ccd4bb0SJason Zhu * restriction, including without limitation the rights to use, copy, 83ccd4bb0SJason Zhu * modify, merge, publish, distribute, sublicense, and/or sell copies 93ccd4bb0SJason Zhu * of the Software, and to permit persons to whom the Software is 103ccd4bb0SJason Zhu * furnished to do so, subject to the following conditions: 113ccd4bb0SJason Zhu * 123ccd4bb0SJason Zhu * The above copyright notice and this permission notice shall be 133ccd4bb0SJason Zhu * included in all copies or substantial portions of the Software. 143ccd4bb0SJason Zhu * 153ccd4bb0SJason Zhu * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 163ccd4bb0SJason Zhu * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 173ccd4bb0SJason Zhu * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 183ccd4bb0SJason Zhu * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 193ccd4bb0SJason Zhu * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 203ccd4bb0SJason Zhu * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 213ccd4bb0SJason Zhu * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 223ccd4bb0SJason Zhu * SOFTWARE. 233ccd4bb0SJason Zhu */ 243ccd4bb0SJason Zhu 253ccd4bb0SJason Zhu /* 263ccd4bb0SJason Zhu #if !defined(AVB_INSIDE_LIBAVB_ATX_H) && !defined(AVB_COMPILATION) 273ccd4bb0SJason Zhu #error \ 283ccd4bb0SJason Zhu "Never include this file directly, include libavb_atx/libavb_atx.h instead." 293ccd4bb0SJason Zhu #endif 303ccd4bb0SJason Zhu */ 313ccd4bb0SJason Zhu 323ccd4bb0SJason Zhu #ifndef AVB_ATX_VALIDATE_H_ 333ccd4bb0SJason Zhu #define AVB_ATX_VALIDATE_H_ 343ccd4bb0SJason Zhu 353ccd4bb0SJason Zhu #include <android_avb/avb_atx_ops.h> 363ccd4bb0SJason Zhu #include <android_avb/avb_atx_types.h> 373ccd4bb0SJason Zhu 383ccd4bb0SJason Zhu #ifdef __cplusplus 393ccd4bb0SJason Zhu extern "C" { 403ccd4bb0SJason Zhu #endif 413ccd4bb0SJason Zhu 423ccd4bb0SJason Zhu /* Rollback index locations for Android Things key versions. */ 433ccd4bb0SJason Zhu #define AVB_ATX_PIK_VERSION_LOCATION 0x1000 443ccd4bb0SJason Zhu #define AVB_ATX_PSK_VERSION_LOCATION 0x1001 453ccd4bb0SJason Zhu 463ccd4bb0SJason Zhu /* An implementation of validate_vbmeta_public_key for Android Things. See 473ccd4bb0SJason Zhu * libavb/avb_ops.h for details on validate_vbmeta_public_key in general. This 483ccd4bb0SJason Zhu * implementation uses the metadata expected with Android Things vbmeta images 493ccd4bb0SJason Zhu * to perform validation on the public key. The ATX ops must be implemented. 503ccd4bb0SJason Zhu * That is, |ops->atx_ops| must be valid. 513ccd4bb0SJason Zhu * 523ccd4bb0SJason Zhu * There are a multiple values that need verification: 533ccd4bb0SJason Zhu * - Permanent Product Attributes: A hash of these attributes is fused into 543ccd4bb0SJason Zhu * hardware. Consistency is checked. 553ccd4bb0SJason Zhu * - Product Root Key (PRK): This key is provided in permanent attributes and 563ccd4bb0SJason Zhu * is the root authority for all Android Things 573ccd4bb0SJason Zhu * products. 583ccd4bb0SJason Zhu * - Product Intermediate Key (PIK): This key is a rotated intermediary. It is 593ccd4bb0SJason Zhu * certified by the PRK. 603ccd4bb0SJason Zhu * - Product Signing Key (PSK): This key is a rotated authority for a specific 613ccd4bb0SJason Zhu * Android Things product. It is certified by a 623ccd4bb0SJason Zhu * PIK and must match |public_key_data|. 633ccd4bb0SJason Zhu * - Product ID: This value is provided in permanent attributes and is unique 643ccd4bb0SJason Zhu * to a specific Android Things product. This value must match 653ccd4bb0SJason Zhu * the subject of the PSK certificate. 663ccd4bb0SJason Zhu */ 673ccd4bb0SJason Zhu AvbIOResult avb_atx_validate_vbmeta_public_key( 683ccd4bb0SJason Zhu AvbOps* ops, 693ccd4bb0SJason Zhu const uint8_t* public_key_data, 703ccd4bb0SJason Zhu size_t public_key_length, 713ccd4bb0SJason Zhu const uint8_t* public_key_metadata, 723ccd4bb0SJason Zhu size_t public_key_metadata_length, 733ccd4bb0SJason Zhu bool* out_is_trusted); 743ccd4bb0SJason Zhu 75*ab608f80SJason Zhu /* Generates a challenge which can be used to create an unlock credential. */ 76*ab608f80SJason Zhu AvbIOResult avb_atx_generate_unlock_challenge( 77*ab608f80SJason Zhu AvbAtxOps* atx_ops, AvbAtxUnlockChallenge* out_unlock_challenge); 78*ab608f80SJason Zhu 79*ab608f80SJason Zhu /* Validates an unlock credential. The certificate validation is very similar to 80*ab608f80SJason Zhu * the validation of public key metadata except in place of the PSK is a Product 81*ab608f80SJason Zhu * Unlock Key (PUK) and the certificate usage field identifies it as such. The 82*ab608f80SJason Zhu * challenge signature field is verified against this PUK. 83*ab608f80SJason Zhu */ 84*ab608f80SJason Zhu AvbIOResult avb_atx_validate_unlock_credential( 85*ab608f80SJason Zhu AvbAtxOps* atx_ops, 86*ab608f80SJason Zhu const AvbAtxUnlockCredential* unlock_credential, 87*ab608f80SJason Zhu bool* out_is_trusted); 88*ab608f80SJason Zhu 893ccd4bb0SJason Zhu #ifdef __cplusplus 903ccd4bb0SJason Zhu } 913ccd4bb0SJason Zhu #endif 923ccd4bb0SJason Zhu 933ccd4bb0SJason Zhu #endif /* AVB_ATX_VALIDATE_H_ */ 94