1*d289c2baSAndroid Build Coastguard Worker /* 2*d289c2baSAndroid Build Coastguard Worker * Copyright (C) 2016 The Android Open Source Project 3*d289c2baSAndroid Build Coastguard Worker * 4*d289c2baSAndroid Build Coastguard Worker * Permission is hereby granted, free of charge, to any person 5*d289c2baSAndroid Build Coastguard Worker * obtaining a copy of this software and associated documentation 6*d289c2baSAndroid Build Coastguard Worker * files (the "Software"), to deal in the Software without 7*d289c2baSAndroid Build Coastguard Worker * restriction, including without limitation the rights to use, copy, 8*d289c2baSAndroid Build Coastguard Worker * modify, merge, publish, distribute, sublicense, and/or sell copies 9*d289c2baSAndroid Build Coastguard Worker * of the Software, and to permit persons to whom the Software is 10*d289c2baSAndroid Build Coastguard Worker * furnished to do so, subject to the following conditions: 11*d289c2baSAndroid Build Coastguard Worker * 12*d289c2baSAndroid Build Coastguard Worker * The above copyright notice and this permission notice shall be 13*d289c2baSAndroid Build Coastguard Worker * included in all copies or substantial portions of the Software. 14*d289c2baSAndroid Build Coastguard Worker * 15*d289c2baSAndroid Build Coastguard Worker * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16*d289c2baSAndroid Build Coastguard Worker * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17*d289c2baSAndroid Build Coastguard Worker * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18*d289c2baSAndroid Build Coastguard Worker * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19*d289c2baSAndroid Build Coastguard Worker * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20*d289c2baSAndroid Build Coastguard Worker * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21*d289c2baSAndroid Build Coastguard Worker * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22*d289c2baSAndroid Build Coastguard Worker * SOFTWARE. 23*d289c2baSAndroid Build Coastguard Worker */ 24*d289c2baSAndroid Build Coastguard Worker 25*d289c2baSAndroid Build Coastguard Worker #if !defined(AVB_INSIDE_LIBAVB_CERT_H) && !defined(AVB_COMPILATION) 26*d289c2baSAndroid Build Coastguard Worker #error \ 27*d289c2baSAndroid Build Coastguard Worker "Never include this file directly, include libavb_cert/libavb_cert.h instead." 28*d289c2baSAndroid Build Coastguard Worker #endif 29*d289c2baSAndroid Build Coastguard Worker 30*d289c2baSAndroid Build Coastguard Worker #ifndef AVB_CERT_VALIDATE_H_ 31*d289c2baSAndroid Build Coastguard Worker #define AVB_CERT_VALIDATE_H_ 32*d289c2baSAndroid Build Coastguard Worker 33*d289c2baSAndroid Build Coastguard Worker #include "avb_cert_ops.h" 34*d289c2baSAndroid Build Coastguard Worker #include "avb_cert_types.h" 35*d289c2baSAndroid Build Coastguard Worker 36*d289c2baSAndroid Build Coastguard Worker #ifdef __cplusplus 37*d289c2baSAndroid Build Coastguard Worker extern "C" { 38*d289c2baSAndroid Build Coastguard Worker #endif 39*d289c2baSAndroid Build Coastguard Worker 40*d289c2baSAndroid Build Coastguard Worker /* Rollback index locations for libavb_cert key versions. */ 41*d289c2baSAndroid Build Coastguard Worker #define AVB_CERT_PIK_VERSION_LOCATION 0x1000 42*d289c2baSAndroid Build Coastguard Worker #define AVB_CERT_PSK_VERSION_LOCATION 0x1001 43*d289c2baSAndroid Build Coastguard Worker 44*d289c2baSAndroid Build Coastguard Worker /* An implementation of `validate_vbmeta_public_key()` for libavb_cert. See 45*d289c2baSAndroid Build Coastguard Worker * libavb/avb_ops.h for details on validate_vbmeta_public_key in general. This 46*d289c2baSAndroid Build Coastguard Worker * implementation uses the metadata expected with libavb_cert vbmeta images 47*d289c2baSAndroid Build Coastguard Worker * to perform validation on the public key. The cert ops must be implemented. 48*d289c2baSAndroid Build Coastguard Worker * That is, |ops->cert_ops| must be valid. 49*d289c2baSAndroid Build Coastguard Worker * 50*d289c2baSAndroid Build Coastguard Worker * There are a multiple values that need verification: 51*d289c2baSAndroid Build Coastguard Worker * - Permanent Product Attributes: A hash of these attributes is fused into 52*d289c2baSAndroid Build Coastguard Worker * hardware. Consistency is checked. 53*d289c2baSAndroid Build Coastguard Worker * - Product Root Key (PRK): This key is provided in permanent attributes and 54*d289c2baSAndroid Build Coastguard Worker * is the root authority. 55*d289c2baSAndroid Build Coastguard Worker * - Product Intermediate Key (PIK): This key is a rotated intermediary. It is 56*d289c2baSAndroid Build Coastguard Worker * certified by the PRK. 57*d289c2baSAndroid Build Coastguard Worker * - Product Signing Key (PSK): This key is a rotated authority for a specific 58*d289c2baSAndroid Build Coastguard Worker * product. It is certified by a PIK and must 59*d289c2baSAndroid Build Coastguard Worker * match |public_key_data|. 60*d289c2baSAndroid Build Coastguard Worker * - Product ID: This value is provided in permanent attributes and is unique 61*d289c2baSAndroid Build Coastguard Worker * to a specific product. This value must match the subject of 62*d289c2baSAndroid Build Coastguard Worker * the PSK certificate. 63*d289c2baSAndroid Build Coastguard Worker */ 64*d289c2baSAndroid Build Coastguard Worker AvbIOResult avb_cert_validate_vbmeta_public_key( 65*d289c2baSAndroid Build Coastguard Worker AvbOps* ops, 66*d289c2baSAndroid Build Coastguard Worker const uint8_t* public_key_data, 67*d289c2baSAndroid Build Coastguard Worker size_t public_key_length, 68*d289c2baSAndroid Build Coastguard Worker const uint8_t* public_key_metadata, 69*d289c2baSAndroid Build Coastguard Worker size_t public_key_metadata_length, 70*d289c2baSAndroid Build Coastguard Worker bool* out_is_trusted); 71*d289c2baSAndroid Build Coastguard Worker 72*d289c2baSAndroid Build Coastguard Worker /* Generates a challenge which can be used to create an unlock credential. */ 73*d289c2baSAndroid Build Coastguard Worker AvbIOResult avb_cert_generate_unlock_challenge( 74*d289c2baSAndroid Build Coastguard Worker AvbCertOps* cert_ops, AvbCertUnlockChallenge* out_unlock_challenge); 75*d289c2baSAndroid Build Coastguard Worker 76*d289c2baSAndroid Build Coastguard Worker /* Validates an unlock credential. The certificate validation is very similar to 77*d289c2baSAndroid Build Coastguard Worker * the validation of public key metadata except in place of the PSK is a Product 78*d289c2baSAndroid Build Coastguard Worker * Unlock Key (PUK) and the certificate usage field identifies it as such. The 79*d289c2baSAndroid Build Coastguard Worker * challenge signature field is verified against this PUK. 80*d289c2baSAndroid Build Coastguard Worker */ 81*d289c2baSAndroid Build Coastguard Worker AvbIOResult avb_cert_validate_unlock_credential( 82*d289c2baSAndroid Build Coastguard Worker AvbCertOps* cert_ops, 83*d289c2baSAndroid Build Coastguard Worker const AvbCertUnlockCredential* unlock_credential, 84*d289c2baSAndroid Build Coastguard Worker bool* out_is_trusted); 85*d289c2baSAndroid Build Coastguard Worker 86*d289c2baSAndroid Build Coastguard Worker #ifdef __cplusplus 87*d289c2baSAndroid Build Coastguard Worker } 88*d289c2baSAndroid Build Coastguard Worker #endif 89*d289c2baSAndroid Build Coastguard Worker 90*d289c2baSAndroid Build Coastguard Worker #endif /* AVB_CERT_VALIDATE_H_ */ 91