From dd0cdcd2130699be8dde5dbadcf18cd9c00ef78f Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Mon, 6 Jan 2020 00:47:13 +0100 Subject: Also execute GET_DEVICE_STATUS in get_status for Storage As described in this issue [0], the GET_STATUS command does not work for the Nitrokey Storage. Therefore, NitrokeyManager::get_status does not work either. To fix this, we additionally execute the GET_DEVICE_STATUS command if a Nitrokey Storage is detected to determine the serial number and the firmware version. This also fixes the failing test test_get_status that we introduced in the last patch. Fixes #166. [0] https://github.com/Nitrokey/nitrokey-storage-firmware/issues/96 --- NitrokeyManager.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index 6c26a43..f345692 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -401,7 +401,19 @@ using nitrokey::misc::strcpyT; stick10::GetStatus::ResponsePayload NitrokeyManager::get_status(){ try{ auto response = GetStatus::CommandTransaction::run(device); - return response.data(); + auto data = response.data(); + if (device != nullptr && device->get_device_model() == DeviceModel::STORAGE) { + // The GET_STATUS command does not work for the Nitrokey Storage, + // see https://github.com/Nitrokey/nitrokey-storage-firmware/issues/96 + // Therefore, we have to use the GET_DEVICE_STATUS command to query + // the correct serial number and firmware version. + auto response2 = stick20::GetDeviceStatus::CommandTransaction::run(device); + auto data2 = response2.data(); + data.firmware_version_st.major = data2.versionInfo.major; + data.firmware_version_st.minor = data2.versionInfo.minor; + data.card_serial_u32 = data2.ActiveSmartCardID_u32; + } + return data; } catch (DeviceSendingFailure &e){ // disconnect(); -- cgit v1.2.3