From f344dbaad407d3d3b2255628a09fc28a947a34c1 Mon Sep 17 00:00:00 2001 From: Stepan Fedorko-Bartos Date: Sat, 17 Nov 2018 01:25:07 -0700 Subject: [PATCH] Fixes NFC Response for Mobile Login --- src/api/core/two_factor.rs | 4 ++-- src/api/identity.rs | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/api/core/two_factor.rs b/src/api/core/two_factor.rs index d4be29be..5583f675 100644 --- a/src/api/core/two_factor.rs +++ b/src/api/core/two_factor.rs @@ -507,9 +507,9 @@ struct EnableYubikeyData { #[derive(Deserialize, Serialize, Debug)] #[allow(non_snake_case)] -struct YubikeyMetadata { +pub struct YubikeyMetadata { Keys: Vec, - Nfc: bool, + pub Nfc: bool, } use yubico::Yubico; diff --git a/src/api/identity.rs b/src/api/identity.rs index 752bcd2e..04a04a24 100644 --- a/src/api/identity.rs +++ b/src/api/identity.rs @@ -269,6 +269,19 @@ fn _json_err_twofactor(providers: &[i32], user_uuid: &str, conn: &DbConn) -> Api result["TwoFactorProviders2"][provider.to_string()] = Value::Object(map); } + Some(TwoFactorType::YubiKey) => { + let twofactor = match TwoFactor::find_by_user_and_type(user_uuid, TwoFactorType::YubiKey as i32, &conn) { + Some(tf) => tf, + None => err!("No YubiKey devices registered"), + }; + + let yubikey_metadata: two_factor::YubikeyMetadata = serde_json::from_str(&twofactor.data).expect("Can't parse Yubikey Metadata"); + + let mut map = JsonMap::new(); + map.insert("Nfc".into(), Value::Bool(yubikey_metadata.Nfc)); + result["TwoFactorProviders2"][provider.to_string()] = Value::Object(map); + } + _ => {} } }