mirror of
https://github.com/NLnetLabs/krill.git
synced 2026-09-30 13:24:52 +02:00
88 lines
2.1 KiB
Rust
88 lines
2.1 KiB
Rust
extern crate krill_daemon;
|
|
extern crate krill_client;
|
|
extern crate krill_commons;
|
|
extern crate krill_pubc;
|
|
extern crate krill_ca;
|
|
|
|
use krill_ca::trustanchor::ta_handle;
|
|
use krill_client::options::{
|
|
CaCommand,
|
|
Command,
|
|
TrustAnchorCommand,
|
|
};
|
|
use krill_client::report::ApiResponse;
|
|
use krill_commons::api::ca::ResourceSet;
|
|
use krill_commons::api::admin::{
|
|
AddChildRequest,
|
|
CertAuthInit,
|
|
CertAuthPubMode,
|
|
Handle,
|
|
ParentCaContact,
|
|
ParentCaInfo,
|
|
Token,
|
|
};
|
|
use krill_daemon::test::{ test_with_krill_server, execute_krillc_command };
|
|
|
|
|
|
fn init_ta() {
|
|
execute_krillc_command(Command::TrustAnchor(TrustAnchorCommand::Init));
|
|
}
|
|
|
|
fn init_child(handle: &Handle, token: &Token) {
|
|
let init = CertAuthInit::new(
|
|
handle.clone(), token.clone(), CertAuthPubMode::Embedded
|
|
);
|
|
execute_krillc_command(Command::CertAuth(CaCommand::Init(init)));
|
|
}
|
|
|
|
fn add_child_to_ta(
|
|
handle: &Handle,
|
|
token: &Token,
|
|
resources: ResourceSet
|
|
) -> ParentCaContact {
|
|
let req = AddChildRequest::new(handle.clone(), token.clone(), resources);
|
|
let res = execute_krillc_command(
|
|
Command::TrustAnchor(TrustAnchorCommand::AddChild(req))
|
|
);
|
|
|
|
match res {
|
|
ApiResponse::ParentCaInfo(info) => info,
|
|
_ => panic!("Expected ParentCaInfo response")
|
|
}
|
|
}
|
|
|
|
fn add_parent_to_ca(handle: &Handle, parent: ParentCaInfo) {
|
|
execute_krillc_command(
|
|
Command::CertAuth(CaCommand::AddParent(handle.clone(), parent))
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn ca_under_ta() {
|
|
test_with_krill_server(|_d|{
|
|
|
|
let ta_handle = ta_handle();
|
|
|
|
let child_handle = Handle::from("child");
|
|
let child_token = Token::from("child");
|
|
let child_resources = ResourceSet::from_strs(
|
|
"",
|
|
"192.168.0.0/16",
|
|
""
|
|
).unwrap();
|
|
|
|
init_ta();
|
|
|
|
init_child(&child_handle, &child_token);
|
|
|
|
|
|
let parent = {
|
|
let parent_contact = add_child_to_ta(
|
|
&child_handle, &child_token, child_resources
|
|
);
|
|
ParentCaInfo::new(ta_handle.clone(), parent_contact)
|
|
};
|
|
|
|
add_parent_to_ca(&child_handle, parent);
|
|
});
|
|
} |