David Drysdale | 6c09af2 | 2023-11-06 09:57:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2023 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | //! Common functionality for non-secure/testing instance of AuthGraph. |
| 18 | |
| 19 | use authgraph_boringssl as boring; |
| 20 | use authgraph_core::{ |
David Drysdale | 20c6549 | 2023-11-23 15:49:54 +0000 | [diff] [blame^] | 21 | error, keyexchange, |
David Drysdale | 6c09af2 | 2023-11-06 09:57:10 +0000 | [diff] [blame] | 22 | ta::{AuthGraphTa, Role}, |
David Drysdale | 6c09af2 | 2023-11-06 09:57:10 +0000 | [diff] [blame] | 23 | }; |
| 24 | use authgraph_hal::channel::SerializedChannel; |
| 25 | use std::sync::{Arc, Mutex}; |
David Drysdale | 6c09af2 | 2023-11-06 09:57:10 +0000 | [diff] [blame] | 26 | |
| 27 | /// Implementation of the AuthGraph TA that runs locally in-process (and which is therefore |
| 28 | /// insecure). |
| 29 | pub struct LocalTa { |
| 30 | ta: Arc<Mutex<AuthGraphTa>>, |
| 31 | } |
| 32 | |
| 33 | impl LocalTa { |
| 34 | /// Create a new instance. |
Hasini Gunasinghe | 5df6ed5 | 2023-11-13 09:18:25 +0000 | [diff] [blame] | 35 | pub fn new() -> Result<Self, error::Error> { |
| 36 | Ok(Self { |
David Drysdale | 6c09af2 | 2023-11-06 09:57:10 +0000 | [diff] [blame] | 37 | ta: Arc::new(Mutex::new(AuthGraphTa::new( |
Hasini Gunasinghe | 5df6ed5 | 2023-11-13 09:18:25 +0000 | [diff] [blame] | 38 | keyexchange::AuthGraphParticipant::new( |
| 39 | boring::crypto_trait_impls(), |
David Drysdale | 6c09af2 | 2023-11-06 09:57:10 +0000 | [diff] [blame] | 40 | Box::<boring::test_device::AgDevice>::default(), |
Hasini Gunasinghe | 5df6ed5 | 2023-11-13 09:18:25 +0000 | [diff] [blame] | 41 | keyexchange::MAX_OPENED_SESSIONS, |
| 42 | )?, |
David Drysdale | 6c09af2 | 2023-11-06 09:57:10 +0000 | [diff] [blame] | 43 | Role::Both, |
| 44 | ))), |
Hasini Gunasinghe | 5df6ed5 | 2023-11-13 09:18:25 +0000 | [diff] [blame] | 45 | }) |
David Drysdale | 6c09af2 | 2023-11-06 09:57:10 +0000 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | |
| 49 | /// Pretend to be a serialized channel to the TA, but actually just directly invoke the TA with |
| 50 | /// incoming requests. |
| 51 | impl SerializedChannel for LocalTa { |
| 52 | const MAX_SIZE: usize = usize::MAX; |
| 53 | |
| 54 | fn execute(&mut self, req_data: &[u8]) -> binder::Result<Vec<u8>> { |
| 55 | Ok(self.ta.lock().unwrap().process(req_data)) |
| 56 | } |
| 57 | } |