1 //! Defines the context type for a session handling hwtrust data structures. 2 3 /// The context for a session handling hwtrust data structures. 4 pub struct Session { 5 /// Options that control the behaviour during this session. 6 pub options: Options, 7 } 8 9 /// Options that control the behaviour of a session. 10 #[derive(Default)] 11 pub struct Options { 12 /// The expected format for the configuration descriptor in the first certificate of the DICE 13 /// chain. When the chain is ROM-rooted, the first certificate is generated by ROM so this 14 /// option can be used for compatibility with ROMs. 15 pub first_dice_chain_cert_config_format: ConfigFormat, 16 17 /// The types that are permitted for the key_ops field of COSE_Key objects in the DICE chain. 18 /// This option can be used for compatibility with the RKP HAL before v3 which diverged from 19 /// the COSE spec and allowed a single int instead of always requiring an array. 20 pub dice_chain_key_ops_type: KeyOpsType, 21 22 /// The types that are permitted for the mode field of the DICE certificates. This option can 23 /// be used for compatibility with the RKP HAL v3 which allowed some deviations from the Open 24 /// Profile for DICE specification. 25 pub dice_chain_mode_type: ModeType, 26 27 /// Whether to allow the key_usage field of the DICE certificates to be encoded in big-endian 28 /// byte order. This introduces ambiguity of the exact key usage being expressed but the keys 29 /// in the DICE chain are only used for verification so it may be preferable to allow for 30 /// compatibility with implementations that use the wrong endianness. 31 pub dice_chain_allow_big_endian_key_usage: bool, 32 33 /// The types that are permitted for the component version field in the configuration 34 /// descriptor. The specification has changed the allowed types over time and this option 35 /// can be used to select which rules to apply. 36 pub dice_chain_component_version_type: ComponentVersionType, 37 } 38 39 /// Format of the DICE configuration descriptor. 40 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] 41 pub enum ConfigFormat { 42 /// The configuration descriptor format specified by Android. 43 #[default] 44 Android, 45 /// Any configuration descriptor format is allowed. 46 Permissive, 47 } 48 49 /// Type allowed for the COSE_Key object key_ops field in the DICE chain. 50 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] 51 pub enum KeyOpsType { 52 /// The key_ops field must be an array as specified in the COSE RFC. 53 #[default] 54 Array, 55 /// The key_ops field can be either a single int or an array as specified in the COSE RFC. 56 IntOrArray, 57 } 58 59 /// Type allowed for the DICE certificate mode field. 60 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] 61 pub enum ModeType { 62 /// The mode field must be a byte string holding a single byte as specified by the Open Profile 63 /// for DICE. 64 #[default] 65 Bytes, 66 /// The mode field can be either an int or a byte string holding a single byte. 67 IntOrBytes, 68 } 69 70 /// Type allowed for the DICE certificate configuration descriptor's component version field. 71 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] 72 pub enum ComponentVersionType { 73 /// The component version can be either an int or a free-form string. 74 #[default] 75 IntOrString, 76 /// The component version must be an int. 77 Int, 78 } 79 80 impl Options { 81 /// The options use by VSR 13. vsr13() -> Self82 pub fn vsr13() -> Self { 83 Self { 84 // Context: b/262599829#comment65 85 dice_chain_key_ops_type: KeyOpsType::IntOrArray, 86 // Context: b/273552826 87 dice_chain_component_version_type: ComponentVersionType::Int, 88 ..Options::default() 89 } 90 } 91 92 /// The options use by VSR 14. vsr14() -> Self93 pub fn vsr14() -> Self { 94 Self { 95 // Context: b/261647022 96 first_dice_chain_cert_config_format: ConfigFormat::Permissive, 97 // Context: b/273552826 98 dice_chain_mode_type: ModeType::IntOrBytes, 99 dice_chain_allow_big_endian_key_usage: true, 100 ..Options::default() 101 } 102 } 103 } 104