xref: /aosp_15_r20/system/keymint/wire/src/rpc.rs (revision 9860b7637a5f185913c70aa0caabe3ecb78441e4)
1 // Copyright 2022, The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 //! Local types that are equivalent to those generated for the IRemotelyProvisionedComponent HAL
16 //! interface
17 
18 use crate::{cbor_type_error, try_from_n, AsCborValue, CborError};
19 use alloc::{
20     format,
21     string::{String, ToString},
22     vec::Vec,
23 };
24 use enumn::N;
25 use kmr_derive::AsCborValue;
26 
27 /// IRPC HAL Versions
28 pub const IRPC_V2: i32 = 2;
29 pub const IRPC_V3: i32 = 3;
30 /// `AuthenticatedRequest` CDDL schema version
31 pub const AUTH_REQ_SCHEMA_V1: i32 = 1;
32 /// `CertificateType` for keymint
33 pub const CERT_TYPE_KEYMINT: &str = "keymint";
34 
35 /// Indication of whether RKP is operating in test mode. (Only relevant for RKP v1 and v2.)
36 #[derive(Clone, Copy, PartialEq, Eq, Debug)]
37 pub struct TestMode(pub bool);
38 
39 #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
40 #[repr(i32)]
41 pub enum ErrorCode {
42     Ok = 0, // not in HAL, assumed
43     Failed = 1,
44     InvalidMac = 2,
45     ProductionKeyInTestRequest = 3,
46     TestKeyInProductionRequest = 4,
47     InvalidEek = 5,
48     Removed = 6,
49 }
50 
51 /// The default value for the minimum number of keys supported in a CSR.
52 pub const MINIMUM_SUPPORTED_KEYS_IN_CSR: i32 = 20;
53 
54 #[derive(Clone, Debug, Eq, PartialEq, AsCborValue)]
55 pub struct HardwareInfo {
56     pub version_number: i32,
57     pub rpc_author_name: String,
58     pub supported_eek_curve: EekCurve,
59     pub unique_id: Option<String>,
60     pub supported_num_keys_in_csr: i32,
61 }
62 
63 #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, AsCborValue, N)]
64 #[repr(i32)]
65 pub enum EekCurve {
66     None = 0,
67     P256 = 1,
68     Curve25519 = 2,
69 }
70 try_from_n!(EekCurve);
71 
72 #[derive(Clone, Debug, Eq, PartialEq, AsCborValue)]
73 pub struct MacedPublicKey {
74     pub maced_key: Vec<u8>,
75 }
76 
77 #[derive(Clone, Debug, Eq, PartialEq, AsCborValue)]
78 pub struct ProtectedData {
79     pub protected_data: Vec<u8>,
80 }
81 
82 #[derive(Clone, Debug, Eq, PartialEq, AsCborValue)]
83 pub struct DeviceInfo {
84     pub device_info: Vec<u8>,
85 }
86