Skip to content

Commit

Permalink
feat(rendezvous-server): verify the device certificate chain
Browse files Browse the repository at this point in the history
use trusted CAs specified by the optional `trusted_device_keys_path`
configuration variable to verify the device certificate chain.

if the configuration variable is not specified we still validate
that the chain is correct but all the certificates will be trusted.

Signed-off-by: Miguel Martín <[email protected]>
  • Loading branch information
mmartinv committed Apr 4, 2024
1 parent dbfac37 commit fc253f4
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 4 deletions.
5 changes: 4 additions & 1 deletion HOWTO.md
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ session_store_driver:
Directory:
path: /path/to/stores/rendezvous_sessions
trusted_manufacturer_keys_path: /path/to/keys/manufacturer_cert.pem
trusted_device_keys_path: /path/to/keys/device_ca_cert.pem
max_wait_seconds: ~
bind: "0.0.0.0:8082"
```
Expand Down Expand Up @@ -568,7 +569,9 @@ Where:
Please refer to the [Database management section](#database-management) on how to initialize databases.
- `session_store_driver`: path to a directory that will hold session
information.
- `trusted_manufacturer_keys_path`: path to the Manufacturer Certificate.
- `trusted_manufacturer_keys_path` [OPTIONAL]: path to the Manufacturer Certificate.
- `trusted_device_keys_path` [OPTIONAL]: path to the CA certificates used for
device certificate chain verification.
- `max_wait_seconds`: [OPTIONAL] maximum wait time in seconds for the TO0 and
TO1 protocols (default 2592000).
- `bind`: IP address and port that the Rendezvous Server will take.
Expand Down
5 changes: 5 additions & 0 deletions admin-tool/src/aio/configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ fn generate_configs(aio_dir: &Path, config_args: &Configuration) -> Result<(), E
.expect("Failed to build absolute path"),
),

trusted_device_keys_path: Some(
AbsolutePathBuf::new(aio_dir.join("keys").join("device_ca_cert.pem"))
.expect("Failed to build absolute path"),
),

max_wait_seconds: None,

bind: get_bind(config_args.listen_port_rendezvous_server)?,
Expand Down
1 change: 1 addition & 0 deletions examples/config/rendezvous-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ session_store_driver:
Directory:
path: /path/to/stores/rendezvous_sessions
trusted_manufacturer_keys_path: /path/to/keys/manufacturer_cert.pem
trusted_device_keys_path: /path/to/keys/device_ca_cert.pem
max_wait_seconds: ~
bind: "0.0.0.0:8082"
10 changes: 8 additions & 2 deletions rendezvous-server/src/handlers_to0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,14 @@ pub(super) async fn ownersign(
}
Some(v) => v,
};
//let device_pubkey = match device_cert_chain.verify_from_x5bag(&user_data.trusted_device_keys) {
let device_pubkey = match device_cert_chain.insecure_verify_without_root_verification() {

let verify_device_pubkey = if let Some(trusted_device_keys) = &user_data.trusted_device_keys {
device_cert_chain.verify_from_x5bag(trusted_device_keys)
} else {
device_cert_chain.insecure_verify_without_root_verification()
};

let device_pubkey = match verify_device_pubkey {
Err(cert_chain_err) => {
log::debug!("Error verifying device certificate: {:?}", cert_chain_err);
return Err(Error::new(
Expand Down
19 changes: 19 additions & 0 deletions rendezvous-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ impl fdo_store::MetadataLocalKey for RendezvousStoreMetadataKey {
struct RendezvousUD {
max_wait_seconds: u32,
trusted_manufacturer_keys: Option<X5Bag>,
trusted_device_keys: Option<X5Bag>,

store: Box<dyn Store<fdo_store::ReadWriteOpen, Guid, StoredItem, RendezvousStoreMetadataKey>>,

session_store: Arc<fdo_http_wrapper::server::SessionStore>,
Expand Down Expand Up @@ -102,11 +104,28 @@ async fn main() -> Result<()> {
.transpose()
.context("Error loading trusted manufacturer keys")?;

// Load trusted CA certs for device certificate chain verification
let trusted_device_keys = settings
.trusted_device_keys_path
.as_ref()
.map(|path| -> Result<X5Bag, anyhow::Error> {
let trusted_device_keys = {
let contents = std::fs::read(path)
.with_context(|| format!("Error reading trusted device keys at {}", &path))?;
X509::stack_from_pem(&contents).context("Error parsing trusted device keys")?
};
X5Bag::with_certs(trusted_device_keys)
.context("Error building trusted device keys X5Bag")
})
.transpose()
.context("Error loading trusted device keys")?;

// Initialize handler stores
let user_data = Arc::new(RendezvousUD {
max_wait_seconds,
store,
trusted_manufacturer_keys,
trusted_device_keys,

session_store: session_store.clone(),
});
Expand Down
1 change: 1 addition & 0 deletions test/fdo/rendezvous-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ session_store_driver:
Directory:
path: /etc/fdo/stores/rendezvous_sessions
trusted_manufacturer_keys_path: /etc/fdo/keys/manufacturer_cert.pem
trusted_device_keys_path: /etc/fdo/keys/device_ca_cert.pem
max_wait_seconds: ~
bind: "0.0.0.0:8082"
1 change: 1 addition & 0 deletions test/fmf/tests/onboarding/run-onboarding.sh
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ session_store_driver:
Directory:
path: ${STORES_DIR}/rendezvous_sessions
trusted_manufacturer_keys_path: ${KEYS_DIR}/manufacturer_cert.pem
trusted_device_keys_path: ${KEYS_DIR}/device_ca_cert.pem
max_wait_seconds: ~
bind: "0.0.0.0:8082"
EOF
Expand Down
5 changes: 4 additions & 1 deletion util/src/servers/configuration/rendezvous_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ pub struct RendezvousServerSettings {
#[serde(with = "serde_yaml::with::singleton_map")]
pub session_store_driver: StoreConfig,

// Trusted keys
// Trusted manufacturer public keys
pub trusted_manufacturer_keys_path: Option<AbsolutePathBuf>,

// Trusted CA certs for device cert chain verification
pub trusted_device_keys_path: Option<AbsolutePathBuf>,

// Other info
pub max_wait_seconds: Option<u32>,

Expand Down

0 comments on commit fc253f4

Please sign in to comment.