9个不稳定版本 (3个破坏性更新)

使用旧的Rust 2015

0.9.0 2021年8月29日
0.8.2 2021年7月30日
0.8.1 2021年1月2日
0.8.0 2020年12月8日
0.6.2 2019年10月2日

身份验证中排名551

Download history 33/week @ 2024-04-05 39/week @ 2024-04-12 33/week @ 2024-04-19 36/week @ 2024-04-26 35/week @ 2024-05-03 31/week @ 2024-05-10 24/week @ 2024-05-17 24/week @ 2024-05-24 26/week @ 2024-05-31 17/week @ 2024-06-07 28/week @ 2024-06-14 42/week @ 2024-06-21 21/week @ 2024-06-28 5/week @ 2024-07-05 22/week @ 2024-07-12 13/week @ 2024-07-19

每月下载68
用于 3 crate

MIT/Apache

33KB
748

Yubikey Manager − 构建状态 最新版本 MIT授权 Apache-2.0授权

Yubikey 挑战-响应 & 配置。


当前功能

  • 挑战-响应,YubiKey 2.2及以后版本支持HMAC-SHA1或Yubico挑战-响应操作。
  • 配置。

用法

将以下内容添加到您的Cargo.toml

[dependencies]
yubico_manager = "0.8"

配置Yubikey(HMAC-SHA1模式)

注意,请阅读有关初始配置的信息。或者您可以使用官方的Yubikey个性化GUI来配置Yubikey。

extern crate rand;
extern crate yubico_manager;

use yubico_manager::{Yubico};
use yubico_manager::config::{Config, Command};
use yubico_manager::configure::{ DeviceModeConfig };
use yubico_manager::hmacmode::{ HmacKey };
use rand::{thread_rng, Rng};
use rand::distributions::{Alphanumeric};

fn main() {
   let mut yubi = Yubico::new();

   if let Ok(device) = yubi.find_yubikey() {
       println!("Vendor ID: {:?} Product ID {:?}", device.vendor_id, device.product_id);

       let config = Config::default()
           .set_vendor_id(device.vendor_id)
           .set_product_id(device.product_id)
           .set_command(Command::Configuration2);

        let mut rng = thread_rng();

        // Secret must have 20 bytes
        // Used rand here, but you can set your own secret: let secret: &[u8; 20] = b"my_awesome_secret_20";
        let secret: String = rng.sample_iter(&Alphanumeric).take(20).collect();
        let hmac_key: HmacKey = HmacKey::from_slice(secret.as_bytes());

        let mut device_config = DeviceModeConfig::default();
        device_config.challenge_response_hmac(&hmac_key, false, false);

        if let Err(err) = yubi.write_config(config, &mut device_config) {
            println!("{:?}", err);
        } else {
            println!("Device configured");
        }

   } else {
       println!("Yubikey not found");
   }
}

示例挑战-响应(HMAC-SHA1模式)

使用Yubikey个性化GUI配置Yubikey

extern crate hex;
extern crate yubico_manager;

use std::ops::Deref;
use yubico_manager::{Yubico};
use yubico_manager::config::{Config, Slot, Mode};

fn main() {
   let mut yubi = Yubico::new();

   if let Ok(device) = yubi.find_yubikey() {
       println!("Vendor ID: {:?} Product ID {:?}", device.vendor_id, device.product_id);

       let config = Config::default()
           .set_vendor_id(device.vendor_id)
           .set_product_id(device.product_id)
           .set_variable_size(true)
           .set_mode(Mode::Sha1)
           .set_slot(Slot::Slot2);

       // Challenge can not be greater than 64 bytes
       let challenge = String::from("mychallenge");
       // In HMAC Mode, the result will always be the SAME for the SAME provided challenge
       let hmac_result= yubi.challenge_response_hmac(challenge.as_bytes(), config).unwrap();

       // Just for debug, lets check the hex
       let v: &[u8] = hmac_result.deref();
       let hex_string = hex::encode(v);

       println!("{}", hex_string);

   } else {
       println!("Yubikey not found");
   }
}

依赖关系

~3MB
~57K SLoC