cli/command/
reset_lock.rs

1// SPDX-License-Identifier: GPL-3-0-or-later
2// Copyright (c) 2024-2025 Jarkko Sakkinen
3// Copyright (c) 2025 Opinsys Oy
4
5use crate::{cli::SubCommand, command::CommandError, device::with_device, job::Job};
6use clap::Args;
7use tpm2_protocol::{
8    data::{TpmCc, TpmRh},
9    message::TpmDictionaryAttackLockResetCommand,
10};
11
12/// Resets the dictionary attack lockout counter.
13#[derive(Args, Debug)]
14pub struct ResetLock {}
15
16impl SubCommand for ResetLock {
17    fn run(&self, job: &mut Job) -> Result<(), CommandError> {
18        with_device(job.device.clone(), |device| {
19            let lock_handle = (TpmRh::Lockout as u32).into();
20            let command = TpmDictionaryAttackLockResetCommand { lock_handle };
21            let handles = [TpmRh::Lockout as u32];
22            let auths = vec![job.auth_list.first().cloned().unwrap_or_default()];
23
24            let (resp, _) = job.execute(device, &command, &handles, &auths)?;
25
26            resp.DictionaryAttackLockReset()
27                .map_err(|_| CommandError::ResponseMismatch(TpmCc::DictionaryAttackLockReset))?;
28            Ok(())
29        })
30    }
31}