blob: da3fa1cec670b26e8370ed07c58de17c68ddf48e [file] [log] [blame]
David Drysdalefe418252023-11-07 09:27:56 +00001/*
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//! VTS test library for AuthGraph functionality.
18//!
19//! This test code is bundled as a library, not as `[cfg(test)]`, to allow it to be
20//! re-used inside the (Rust) VTS tests of components that use AuthGraph.
21
22use android_hardware_security_authgraph::aidl::android::hardware::security::authgraph::{
23 Error::Error, IAuthGraphKeyExchange::IAuthGraphKeyExchange, Identity::Identity,
24 PlainPubKey::PlainPubKey, PubKey::PubKey, SessionIdSignature::SessionIdSignature,
25};
26use authgraph_boringssl as boring;
Hasini Gunasinghe5df6ed52023-11-13 09:18:25 +000027use authgraph_core::{error::Error as AgError, keyexchange as ke};
David Drysdalefe418252023-11-07 09:27:56 +000028use coset::CborSerializable;
29
30pub mod sink;
31pub mod source;
32
Hasini Gunasinghe5df6ed52023-11-13 09:18:25 +000033/// Return an AuthGraphParticipant suitable for testing.
34pub fn test_ag_participant() -> Result<ke::AuthGraphParticipant, AgError> {
35 Ok(ke::AuthGraphParticipant::new(
36 boring::crypto_trait_impls(),
David Drysdalefe418252023-11-07 09:27:56 +000037 Box::<boring::test_device::AgDevice>::default(),
Hasini Gunasinghe5df6ed52023-11-13 09:18:25 +000038 ke::MAX_OPENED_SESSIONS,
39 )?)
David Drysdalefe418252023-11-07 09:27:56 +000040}
41
42fn build_plain_pub_key(pub_key: &Option<Vec<u8>>) -> PubKey {
43 PubKey::PlainKey(PlainPubKey {
44 plainPubKey: pub_key.clone().unwrap(),
45 })
46}
47
48fn extract_plain_pub_key(pub_key: &Option<PubKey>) -> &PlainPubKey {
49 match pub_key {
50 Some(PubKey::PlainKey(pub_key)) => pub_key,
51 Some(PubKey::SignedKey(_)) => panic!("expect unsigned public key"),
52 None => panic!("expect pubKey to be populated"),
53 }
54}
55
David Drysdalefe418252023-11-07 09:27:56 +000056fn vec_to_identity(data: &[u8]) -> Identity {
57 Identity {
58 identity: data.to_vec(),
59 }
60}
61
62fn vec_to_signature(data: &[u8]) -> SessionIdSignature {
63 SessionIdSignature {
64 signature: data.to_vec(),
65 }
66}