blob: 599a614e3bf827ccfbac217a1f0faaa28e7916d2 [file] [log] [blame]
Alice Wang15f6d082023-08-25 09:11:07 +00001// Copyright 2023, 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//! IRemotelyProvisionedComponent HAL implementation.
16
17use android_hardware_security_rkp::aidl::android::hardware::security::keymint::{
18 DeviceInfo::DeviceInfo,
19 IRemotelyProvisionedComponent::{
20 BnRemotelyProvisionedComponent, IRemotelyProvisionedComponent, STATUS_REMOVED,
21 },
22 MacedPublicKey::MacedPublicKey,
23 ProtectedData::ProtectedData,
24 RpcHardwareInfo::{RpcHardwareInfo, CURVE_NONE, MIN_SUPPORTED_NUM_KEYS_IN_CSR},
25};
26use avflog::LogResult;
27use binder::{BinderFeatures, ExceptionCode, Interface, Result as BinderResult, Status, Strong};
28
29/// Constructs a binder object that implements `IRemotelyProvisionedComponent`.
30pub(crate) fn new_binder() -> Strong<dyn IRemotelyProvisionedComponent> {
31 BnRemotelyProvisionedComponent::new_binder(
32 AvfRemotelyProvisionedComponent {},
33 BinderFeatures::default(),
34 )
35}
36
37struct AvfRemotelyProvisionedComponent {}
38
39impl Interface for AvfRemotelyProvisionedComponent {}
40
41#[allow(non_snake_case)]
42impl IRemotelyProvisionedComponent for AvfRemotelyProvisionedComponent {
43 fn getHardwareInfo(&self) -> BinderResult<RpcHardwareInfo> {
44 Ok(RpcHardwareInfo {
45 versionNumber: 3,
46 rpcAuthorName: String::from("Android Virtualization Framework"),
47 supportedEekCurve: CURVE_NONE,
48 uniqueId: Some(String::from("Android Virtualization Framework 1")),
49 supportedNumKeysInCsr: MIN_SUPPORTED_NUM_KEYS_IN_CSR,
50 })
51 }
52
53 fn generateEcdsaP256KeyPair(
54 &self,
Alice Wanga723fe62023-09-06 12:38:59 +000055 testMode: bool,
Alice Wang15f6d082023-08-25 09:11:07 +000056 _macedPublicKey: &mut MacedPublicKey,
57 ) -> BinderResult<Vec<u8>> {
Alice Wanga723fe62023-09-06 12:38:59 +000058 if testMode {
59 return Err(Status::new_service_specific_error_str(
60 STATUS_REMOVED,
61 Some("generateEcdsaP256KeyPair does not support test mode in IRPC v3+ HAL."),
62 ))
63 .with_log();
64 }
Alice Wang15f6d082023-08-25 09:11:07 +000065 // TODO(b/274881098): Implement this.
66 Err(Status::new_exception(ExceptionCode::UNSUPPORTED_OPERATION, None)).with_log()
67 }
68
69 fn generateCertificateRequest(
70 &self,
71 _testMode: bool,
72 _keysToSign: &[MacedPublicKey],
73 _endpointEncryptionCertChain: &[u8],
74 _challenge: &[u8],
75 _deviceInfo: &mut DeviceInfo,
76 _protectedData: &mut ProtectedData,
77 ) -> BinderResult<Vec<u8>> {
78 Err(Status::new_service_specific_error_str(
79 STATUS_REMOVED,
80 Some("This method was deprecated in v3 of the interface."),
81 ))
82 .with_log()
83 }
84
85 fn generateCertificateRequestV2(
86 &self,
87 _keysToSign: &[MacedPublicKey],
88 _challenge: &[u8],
89 ) -> BinderResult<Vec<u8>> {
90 // TODO(b/274881098): Implement this.
91 Err(Status::new_exception(ExceptionCode::UNSUPPORTED_OPERATION, None)).with_log()
92 }
93}