Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bump challenge-response #215

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ cipher = { version = "0.4", features = ["std"] }
twofish = "0.7"
cbc = "0.1"

challenge_response = { version = "0.3", optional = true }
challenge_response = { version = "0.4", optional = true }

uuid = { version = "1.2", features = ["v4", "serde"] }
hex = { version = "0.4", optional = true }
Expand Down
27 changes: 14 additions & 13 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use zeroize::{Zeroize, ZeroizeOnDrop};
#[cfg(feature = "challenge_response")]
use challenge_response::{
config::{Config, Mode, Slot},
Yubico,
ChallengeResponse,
};

use crate::{crypt::calculate_sha256, error::DatabaseKeyError};
Expand Down Expand Up @@ -100,29 +100,30 @@ impl ChallengeResponseKey {
Ok(response)
}
ChallengeResponseKey::YubikeyChallenge(yubikey, slot_number) => {
let mut yubikey_client = Yubico::new().map_err(|e| {
let mut challenge_response_client = ChallengeResponse::new().map_err(|e| {
DatabaseKeyError::ChallengeResponseKeyError(format!(
"Could not search for yubikey: {}",
e.to_string()
))
})?;
let slot = parse_yubikey_slot(slot_number)?;

let yubikey_device = match yubikey_client.find_yubikey_from_serial(yubikey.serial_number) {
Ok(d) => d,
Err(_e) => {
return Err(DatabaseKeyError::ChallengeResponseKeyError(
"Yubikey not found".to_string(),
))
}
};
let yubikey_device =
match challenge_response_client.find_device_from_serial(yubikey.serial_number) {
Ok(d) => d,
Err(_e) => {
return Err(DatabaseKeyError::ChallengeResponseKeyError(
"Yubikey not found".to_string(),
))
}
};

let mut config = Config::new_from(yubikey_device);
config = config.set_variable_size(true);
config = config.set_mode(Mode::Sha1);
config = config.set_slot(slot);

match yubikey_client.challenge_response_hmac(challenge, config) {
match challenge_response_client.challenge_response_hmac(challenge, config) {
Ok(hmac_result) => Ok(hmac_result.to_vec()),
Err(e) => Err(DatabaseKeyError::ChallengeResponseKeyError(format!(
"Could not perform challenge response: {}",
Expand All @@ -134,14 +135,14 @@ impl ChallengeResponseKey {
}

pub fn get_available_yubikeys() -> Result<Vec<Yubikey>, DatabaseKeyError> {
let mut yubikey_client = Yubico::new().map_err(|e| {
let mut challenge_response_client = ChallengeResponse::new().map_err(|e| {
DatabaseKeyError::ChallengeResponseKeyError(format!(
"Could not search for yubikey: {}",
e.to_string()
))
})?;
let mut response: Vec<Yubikey> = vec![];
let yubikeys = match yubikey_client.find_all_yubikeys() {
let yubikeys = match challenge_response_client.find_all_devices() {
Ok(y) => y,
Err(e) => {
return Err(DatabaseKeyError::ChallengeResponseKeyError(format!(
Expand Down