xref: /aosp_15_r20/system/keymint/common/src/bin/cddl-dump.rs (revision 9860b7637a5f185913c70aa0caabe3ecb78441e4)
1*9860b763SAndroid Build Coastguard Worker // Copyright 2022, The Android Open Source Project
2*9860b763SAndroid Build Coastguard Worker //
3*9860b763SAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License");
4*9860b763SAndroid Build Coastguard Worker // you may not use this file except in compliance with the License.
5*9860b763SAndroid Build Coastguard Worker // You may obtain a copy of the License at
6*9860b763SAndroid Build Coastguard Worker //
7*9860b763SAndroid Build Coastguard Worker //     http://www.apache.org/licenses/LICENSE-2.0
8*9860b763SAndroid Build Coastguard Worker //
9*9860b763SAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software
10*9860b763SAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS,
11*9860b763SAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*9860b763SAndroid Build Coastguard Worker // See the License for the specific language governing permissions and
13*9860b763SAndroid Build Coastguard Worker // limitations under the License.
14*9860b763SAndroid Build Coastguard Worker 
15*9860b763SAndroid Build Coastguard Worker //! Utility to emit the CDDL for messages passed between HAL and TA.
16*9860b763SAndroid Build Coastguard Worker 
17*9860b763SAndroid Build Coastguard Worker use kmr_common::crypto;
18*9860b763SAndroid Build Coastguard Worker use kmr_wire::*;
19*9860b763SAndroid Build Coastguard Worker use kmr_wire::{keymint::*, secureclock::*, sharedsecret::*};
20*9860b763SAndroid Build Coastguard Worker 
show_schema<T: kmr_wire::AsCborValue>()21*9860b763SAndroid Build Coastguard Worker fn show_schema<T: kmr_wire::AsCborValue>() {
22*9860b763SAndroid Build Coastguard Worker     if let (Some(n), Some(s)) = (<T>::cddl_typename(), <T>::cddl_schema()) {
23*9860b763SAndroid Build Coastguard Worker         println!("{} = {}", n, s);
24*9860b763SAndroid Build Coastguard Worker     }
25*9860b763SAndroid Build Coastguard Worker }
26*9860b763SAndroid Build Coastguard Worker 
main()27*9860b763SAndroid Build Coastguard Worker fn main() {
28*9860b763SAndroid Build Coastguard Worker     // CDDL corresponding to types defined by the AIDL spec.
29*9860b763SAndroid Build Coastguard Worker 
30*9860b763SAndroid Build Coastguard Worker     // newtype wrappers
31*9860b763SAndroid Build Coastguard Worker     show_schema::<DateTime>();
32*9860b763SAndroid Build Coastguard Worker     show_schema::<kmr_wire::KeySizeInBits>();
33*9860b763SAndroid Build Coastguard Worker     show_schema::<kmr_wire::RsaExponent>();
34*9860b763SAndroid Build Coastguard Worker 
35*9860b763SAndroid Build Coastguard Worker     // enums
36*9860b763SAndroid Build Coastguard Worker     show_schema::<Algorithm>();
37*9860b763SAndroid Build Coastguard Worker     show_schema::<BlockMode>();
38*9860b763SAndroid Build Coastguard Worker     show_schema::<Digest>();
39*9860b763SAndroid Build Coastguard Worker     show_schema::<EcCurve>();
40*9860b763SAndroid Build Coastguard Worker     show_schema::<crypto::CurveType>();
41*9860b763SAndroid Build Coastguard Worker     show_schema::<ErrorCode>();
42*9860b763SAndroid Build Coastguard Worker     show_schema::<HardwareAuthenticatorType>();
43*9860b763SAndroid Build Coastguard Worker     show_schema::<KeyFormat>();
44*9860b763SAndroid Build Coastguard Worker     show_schema::<KeyOrigin>();
45*9860b763SAndroid Build Coastguard Worker     show_schema::<KeyPurpose>();
46*9860b763SAndroid Build Coastguard Worker     show_schema::<PaddingMode>();
47*9860b763SAndroid Build Coastguard Worker     show_schema::<SecurityLevel>();
48*9860b763SAndroid Build Coastguard Worker     show_schema::<Tag>();
49*9860b763SAndroid Build Coastguard Worker     show_schema::<TagType>();
50*9860b763SAndroid Build Coastguard Worker 
51*9860b763SAndroid Build Coastguard Worker     // structs
52*9860b763SAndroid Build Coastguard Worker     show_schema::<AttestationKey>();
53*9860b763SAndroid Build Coastguard Worker     // BeginResult omitted as it holds a Binder reference
54*9860b763SAndroid Build Coastguard Worker     show_schema::<Certificate>();
55*9860b763SAndroid Build Coastguard Worker     show_schema::<rpc::DeviceInfo>();
56*9860b763SAndroid Build Coastguard Worker     show_schema::<HardwareAuthToken>();
57*9860b763SAndroid Build Coastguard Worker     show_schema::<KeyCharacteristics>();
58*9860b763SAndroid Build Coastguard Worker     show_schema::<KeyCreationResult>();
59*9860b763SAndroid Build Coastguard Worker     show_schema::<KeyMintHardwareInfo>();
60*9860b763SAndroid Build Coastguard Worker     show_schema::<rpc::EekCurve>();
61*9860b763SAndroid Build Coastguard Worker     show_schema::<rpc::MacedPublicKey>();
62*9860b763SAndroid Build Coastguard Worker     show_schema::<rpc::ProtectedData>();
63*9860b763SAndroid Build Coastguard Worker     show_schema::<rpc::HardwareInfo>();
64*9860b763SAndroid Build Coastguard Worker     show_schema::<TimeStampToken>();
65*9860b763SAndroid Build Coastguard Worker     show_schema::<Timestamp>();
66*9860b763SAndroid Build Coastguard Worker     show_schema::<SharedSecretParameters>();
67*9860b763SAndroid Build Coastguard Worker 
68*9860b763SAndroid Build Coastguard Worker     // Internal exhaustive enum (instead of `KeyParameter` and `KeyParameterValue` from the HAL).
69*9860b763SAndroid Build Coastguard Worker     show_schema::<KeyParam>();
70*9860b763SAndroid Build Coastguard Worker 
71*9860b763SAndroid Build Coastguard Worker     // CDDL corresponding to types defined in this crate.
72*9860b763SAndroid Build Coastguard Worker 
73*9860b763SAndroid Build Coastguard Worker     // enums
74*9860b763SAndroid Build Coastguard Worker     show_schema::<KeyMintOperation>();
75*9860b763SAndroid Build Coastguard Worker 
76*9860b763SAndroid Build Coastguard Worker     // structs
77*9860b763SAndroid Build Coastguard Worker 
78*9860b763SAndroid Build Coastguard Worker     show_schema::<GetHardwareInfoRequest>();
79*9860b763SAndroid Build Coastguard Worker     show_schema::<GetHardwareInfoResponse>();
80*9860b763SAndroid Build Coastguard Worker     show_schema::<AddRngEntropyRequest>();
81*9860b763SAndroid Build Coastguard Worker     show_schema::<AddRngEntropyResponse>();
82*9860b763SAndroid Build Coastguard Worker     show_schema::<GenerateKeyRequest>();
83*9860b763SAndroid Build Coastguard Worker     show_schema::<GenerateKeyResponse>();
84*9860b763SAndroid Build Coastguard Worker     show_schema::<ImportKeyRequest>();
85*9860b763SAndroid Build Coastguard Worker     show_schema::<ImportKeyResponse>();
86*9860b763SAndroid Build Coastguard Worker     show_schema::<ImportWrappedKeyRequest>();
87*9860b763SAndroid Build Coastguard Worker     show_schema::<ImportWrappedKeyResponse>();
88*9860b763SAndroid Build Coastguard Worker     show_schema::<UpgradeKeyRequest>();
89*9860b763SAndroid Build Coastguard Worker     show_schema::<UpgradeKeyResponse>();
90*9860b763SAndroid Build Coastguard Worker     show_schema::<DeleteKeyRequest>();
91*9860b763SAndroid Build Coastguard Worker     show_schema::<DeleteKeyResponse>();
92*9860b763SAndroid Build Coastguard Worker     show_schema::<DeleteAllKeysRequest>();
93*9860b763SAndroid Build Coastguard Worker     show_schema::<DeleteAllKeysResponse>();
94*9860b763SAndroid Build Coastguard Worker     show_schema::<DestroyAttestationIdsRequest>();
95*9860b763SAndroid Build Coastguard Worker     show_schema::<DestroyAttestationIdsResponse>();
96*9860b763SAndroid Build Coastguard Worker     show_schema::<BeginRequest>();
97*9860b763SAndroid Build Coastguard Worker     show_schema::<InternalBeginResult>(); // Special case
98*9860b763SAndroid Build Coastguard Worker     show_schema::<EarlyBootEndedRequest>();
99*9860b763SAndroid Build Coastguard Worker     show_schema::<EarlyBootEndedResponse>();
100*9860b763SAndroid Build Coastguard Worker     show_schema::<ConvertStorageKeyToEphemeralRequest>();
101*9860b763SAndroid Build Coastguard Worker     show_schema::<ConvertStorageKeyToEphemeralResponse>();
102*9860b763SAndroid Build Coastguard Worker     show_schema::<GetKeyCharacteristicsRequest>();
103*9860b763SAndroid Build Coastguard Worker     show_schema::<GetKeyCharacteristicsResponse>();
104*9860b763SAndroid Build Coastguard Worker     show_schema::<UpdateAadRequest>();
105*9860b763SAndroid Build Coastguard Worker     show_schema::<UpdateAadResponse>();
106*9860b763SAndroid Build Coastguard Worker     show_schema::<UpdateRequest>();
107*9860b763SAndroid Build Coastguard Worker     show_schema::<UpdateResponse>();
108*9860b763SAndroid Build Coastguard Worker     show_schema::<FinishRequest>();
109*9860b763SAndroid Build Coastguard Worker     show_schema::<FinishResponse>();
110*9860b763SAndroid Build Coastguard Worker     show_schema::<AbortRequest>();
111*9860b763SAndroid Build Coastguard Worker     show_schema::<AbortResponse>();
112*9860b763SAndroid Build Coastguard Worker 
113*9860b763SAndroid Build Coastguard Worker     show_schema::<GetRpcHardwareInfoRequest>();
114*9860b763SAndroid Build Coastguard Worker     show_schema::<GetRpcHardwareInfoResponse>();
115*9860b763SAndroid Build Coastguard Worker     show_schema::<GenerateEcdsaP256KeyPairRequest>();
116*9860b763SAndroid Build Coastguard Worker     show_schema::<GenerateEcdsaP256KeyPairResponse>();
117*9860b763SAndroid Build Coastguard Worker     show_schema::<GenerateCertificateRequestRequest>();
118*9860b763SAndroid Build Coastguard Worker     show_schema::<GenerateCertificateRequestResponse>();
119*9860b763SAndroid Build Coastguard Worker     show_schema::<GenerateCertificateRequestV2Request>();
120*9860b763SAndroid Build Coastguard Worker     show_schema::<GenerateCertificateRequestV2Response>();
121*9860b763SAndroid Build Coastguard Worker 
122*9860b763SAndroid Build Coastguard Worker     show_schema::<GetSharedSecretParametersRequest>();
123*9860b763SAndroid Build Coastguard Worker     show_schema::<GetSharedSecretParametersResponse>();
124*9860b763SAndroid Build Coastguard Worker     show_schema::<ComputeSharedSecretRequest>();
125*9860b763SAndroid Build Coastguard Worker     show_schema::<ComputeSharedSecretResponse>();
126*9860b763SAndroid Build Coastguard Worker 
127*9860b763SAndroid Build Coastguard Worker     show_schema::<GenerateTimeStampRequest>();
128*9860b763SAndroid Build Coastguard Worker     show_schema::<GenerateTimeStampResponse>();
129*9860b763SAndroid Build Coastguard Worker 
130*9860b763SAndroid Build Coastguard Worker     // Autogenerated enums
131*9860b763SAndroid Build Coastguard Worker     show_schema::<PerformOpReq>();
132*9860b763SAndroid Build Coastguard Worker     show_schema::<PerformOpRsp>();
133*9860b763SAndroid Build Coastguard Worker 
134*9860b763SAndroid Build Coastguard Worker     // Overall response structure
135*9860b763SAndroid Build Coastguard Worker     show_schema::<PerformOpResponse>();
136*9860b763SAndroid Build Coastguard Worker }
137