create new token if none exists
This commit is contained in:
parent
e3bd32c985
commit
eed2dad08f
18
src/cli.rs
18
src/cli.rs
@ -12,7 +12,7 @@ use std::io::Write;
|
|||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
use crate::luks::LuksDevice;
|
use crate::luks::{Fido2LuksToken, LuksDevice};
|
||||||
use crate::util::sha256;
|
use crate::util::sha256;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
@ -27,6 +27,12 @@ impl Display for HexEncoded {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AsRef<[u8]> for HexEncoded {
|
||||||
|
fn as_ref(&self) -> &[u8] {
|
||||||
|
&self.0[..]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl FromStr for HexEncoded {
|
impl FromStr for HexEncoded {
|
||||||
type Err = hex::FromHexError;
|
type Err = hex::FromHexError;
|
||||||
|
|
||||||
@ -628,10 +634,12 @@ pub fn run_cli() -> Fido2LuksResult<()> {
|
|||||||
tokens.push((id, token));
|
tokens.push((id, token));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if tokens.is_empty() {
|
let count = if tokens.is_empty() {
|
||||||
unimplemented!("// TODO: create new token")
|
dev.add_token(&Fido2LuksToken::with_credentials(&credentials.ids.0, *slot))?;
|
||||||
}
|
1
|
||||||
let count = tokens.len();
|
} else {
|
||||||
|
tokens.len()
|
||||||
|
};
|
||||||
for (id, mut token) in tokens {
|
for (id, mut token) in tokens {
|
||||||
token
|
token
|
||||||
.credential
|
.credential
|
||||||
|
23
src/luks.rs
23
src/luks.rs
@ -87,6 +87,13 @@ impl LuksDevice {
|
|||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_token(&mut self, data: &Fido2LuksToken) -> Fido2LuksResult<()> {
|
||||||
|
self.device
|
||||||
|
.token_handle()
|
||||||
|
.json_set(TokenInput::AddToken(&serde_json::to_value(&data).unwrap()))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn remove_token(&mut self, token: u32) -> Fido2LuksResult<()> {
|
pub fn remove_token(&mut self, token: u32) -> Fido2LuksResult<()> {
|
||||||
self.device
|
self.device
|
||||||
.token_handle()
|
.token_handle()
|
||||||
@ -274,14 +281,24 @@ pub struct Fido2LuksToken {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Fido2LuksToken {
|
impl Fido2LuksToken {
|
||||||
fn new(credential_id: impl AsRef<[u8]>, slot: u32) -> Self {
|
pub fn new(credential_id: impl AsRef<[u8]>, slot: u32) -> Self {
|
||||||
|
Self::with_credentials(std::iter::once(credential_id), slot)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn with_credentials<I: IntoIterator<Item = B>, B: AsRef<[u8]>>(
|
||||||
|
credentials: I,
|
||||||
|
slot: u32,
|
||||||
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
credential: vec![hex::encode(credential_id)].into_iter().collect(),
|
credential: credentials
|
||||||
|
.into_iter()
|
||||||
|
.map(|cred| hex::encode(cred.as_ref()))
|
||||||
|
.collect(),
|
||||||
keyslots: vec![slot.to_string()].into_iter().collect(),
|
keyslots: vec![slot.to_string()].into_iter().collect(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn default_type() -> &'static str {
|
pub fn default_type() -> &'static str {
|
||||||
"fido2luks"
|
"fido2luks"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user