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 //! Utility to emit the CDDL for messages passed between HAL and TA.
16
17 use kmr_common::crypto;
18 use kmr_wire::*;
19 use kmr_wire::{keymint::*, secureclock::*, sharedsecret::*};
20
show_schema<T: kmr_wire::AsCborValue>()21 fn show_schema<T: kmr_wire::AsCborValue>() {
22 if let (Some(n), Some(s)) = (<T>::cddl_typename(), <T>::cddl_schema()) {
23 println!("{} = {}", n, s);
24 }
25 }
26
main()27 fn main() {
28 // CDDL corresponding to types defined by the AIDL spec.
29
30 // newtype wrappers
31 show_schema::<DateTime>();
32 show_schema::<kmr_wire::KeySizeInBits>();
33 show_schema::<kmr_wire::RsaExponent>();
34
35 // enums
36 show_schema::<Algorithm>();
37 show_schema::<BlockMode>();
38 show_schema::<Digest>();
39 show_schema::<EcCurve>();
40 show_schema::<crypto::CurveType>();
41 show_schema::<ErrorCode>();
42 show_schema::<HardwareAuthenticatorType>();
43 show_schema::<KeyFormat>();
44 show_schema::<KeyOrigin>();
45 show_schema::<KeyPurpose>();
46 show_schema::<PaddingMode>();
47 show_schema::<SecurityLevel>();
48 show_schema::<Tag>();
49 show_schema::<TagType>();
50
51 // structs
52 show_schema::<AttestationKey>();
53 // BeginResult omitted as it holds a Binder reference
54 show_schema::<Certificate>();
55 show_schema::<rpc::DeviceInfo>();
56 show_schema::<HardwareAuthToken>();
57 show_schema::<KeyCharacteristics>();
58 show_schema::<KeyCreationResult>();
59 show_schema::<KeyMintHardwareInfo>();
60 show_schema::<rpc::EekCurve>();
61 show_schema::<rpc::MacedPublicKey>();
62 show_schema::<rpc::ProtectedData>();
63 show_schema::<rpc::HardwareInfo>();
64 show_schema::<TimeStampToken>();
65 show_schema::<Timestamp>();
66 show_schema::<SharedSecretParameters>();
67
68 // Internal exhaustive enum (instead of `KeyParameter` and `KeyParameterValue` from the HAL).
69 show_schema::<KeyParam>();
70
71 // CDDL corresponding to types defined in this crate.
72
73 // enums
74 show_schema::<KeyMintOperation>();
75
76 // structs
77
78 show_schema::<GetHardwareInfoRequest>();
79 show_schema::<GetHardwareInfoResponse>();
80 show_schema::<AddRngEntropyRequest>();
81 show_schema::<AddRngEntropyResponse>();
82 show_schema::<GenerateKeyRequest>();
83 show_schema::<GenerateKeyResponse>();
84 show_schema::<ImportKeyRequest>();
85 show_schema::<ImportKeyResponse>();
86 show_schema::<ImportWrappedKeyRequest>();
87 show_schema::<ImportWrappedKeyResponse>();
88 show_schema::<UpgradeKeyRequest>();
89 show_schema::<UpgradeKeyResponse>();
90 show_schema::<DeleteKeyRequest>();
91 show_schema::<DeleteKeyResponse>();
92 show_schema::<DeleteAllKeysRequest>();
93 show_schema::<DeleteAllKeysResponse>();
94 show_schema::<DestroyAttestationIdsRequest>();
95 show_schema::<DestroyAttestationIdsResponse>();
96 show_schema::<BeginRequest>();
97 show_schema::<InternalBeginResult>(); // Special case
98 show_schema::<EarlyBootEndedRequest>();
99 show_schema::<EarlyBootEndedResponse>();
100 show_schema::<ConvertStorageKeyToEphemeralRequest>();
101 show_schema::<ConvertStorageKeyToEphemeralResponse>();
102 show_schema::<GetKeyCharacteristicsRequest>();
103 show_schema::<GetKeyCharacteristicsResponse>();
104 show_schema::<UpdateAadRequest>();
105 show_schema::<UpdateAadResponse>();
106 show_schema::<UpdateRequest>();
107 show_schema::<UpdateResponse>();
108 show_schema::<FinishRequest>();
109 show_schema::<FinishResponse>();
110 show_schema::<AbortRequest>();
111 show_schema::<AbortResponse>();
112
113 show_schema::<GetRpcHardwareInfoRequest>();
114 show_schema::<GetRpcHardwareInfoResponse>();
115 show_schema::<GenerateEcdsaP256KeyPairRequest>();
116 show_schema::<GenerateEcdsaP256KeyPairResponse>();
117 show_schema::<GenerateCertificateRequestRequest>();
118 show_schema::<GenerateCertificateRequestResponse>();
119 show_schema::<GenerateCertificateRequestV2Request>();
120 show_schema::<GenerateCertificateRequestV2Response>();
121
122 show_schema::<GetSharedSecretParametersRequest>();
123 show_schema::<GetSharedSecretParametersResponse>();
124 show_schema::<ComputeSharedSecretRequest>();
125 show_schema::<ComputeSharedSecretResponse>();
126
127 show_schema::<GenerateTimeStampRequest>();
128 show_schema::<GenerateTimeStampResponse>();
129
130 // Autogenerated enums
131 show_schema::<PerformOpReq>();
132 show_schema::<PerformOpRsp>();
133
134 // Overall response structure
135 show_schema::<PerformOpResponse>();
136 }
137