Alice Wang | 15f6d08 | 2023-08-25 09:11:07 +0000 | [diff] [blame] | 1 | // 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 | |
| 17 | use 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 | }; |
| 26 | use avflog::LogResult; |
| 27 | use binder::{BinderFeatures, ExceptionCode, Interface, Result as BinderResult, Status, Strong}; |
| 28 | |
| 29 | /// Constructs a binder object that implements `IRemotelyProvisionedComponent`. |
| 30 | pub(crate) fn new_binder() -> Strong<dyn IRemotelyProvisionedComponent> { |
| 31 | BnRemotelyProvisionedComponent::new_binder( |
| 32 | AvfRemotelyProvisionedComponent {}, |
| 33 | BinderFeatures::default(), |
| 34 | ) |
| 35 | } |
| 36 | |
| 37 | struct AvfRemotelyProvisionedComponent {} |
| 38 | |
| 39 | impl Interface for AvfRemotelyProvisionedComponent {} |
| 40 | |
| 41 | #[allow(non_snake_case)] |
| 42 | impl 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, |
| 55 | _testMode: bool, |
| 56 | _macedPublicKey: &mut MacedPublicKey, |
| 57 | ) -> BinderResult<Vec<u8>> { |
| 58 | // TODO(b/274881098): Implement this. |
| 59 | Err(Status::new_exception(ExceptionCode::UNSUPPORTED_OPERATION, None)).with_log() |
| 60 | } |
| 61 | |
| 62 | fn generateCertificateRequest( |
| 63 | &self, |
| 64 | _testMode: bool, |
| 65 | _keysToSign: &[MacedPublicKey], |
| 66 | _endpointEncryptionCertChain: &[u8], |
| 67 | _challenge: &[u8], |
| 68 | _deviceInfo: &mut DeviceInfo, |
| 69 | _protectedData: &mut ProtectedData, |
| 70 | ) -> BinderResult<Vec<u8>> { |
| 71 | Err(Status::new_service_specific_error_str( |
| 72 | STATUS_REMOVED, |
| 73 | Some("This method was deprecated in v3 of the interface."), |
| 74 | )) |
| 75 | .with_log() |
| 76 | } |
| 77 | |
| 78 | fn generateCertificateRequestV2( |
| 79 | &self, |
| 80 | _keysToSign: &[MacedPublicKey], |
| 81 | _challenge: &[u8], |
| 82 | ) -> BinderResult<Vec<u8>> { |
| 83 | // TODO(b/274881098): Implement this. |
| 84 | Err(Status::new_exception(ExceptionCode::UNSUPPORTED_OPERATION, None)).with_log() |
| 85 | } |
| 86 | } |