From 2ba87abdb5c69e3d72b88164030ed5633986a63d Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Wed, 9 Nov 2016 19:22:46 +0100 Subject: Convinient function for checking if authorization command is supported Signed-off-by: Szczepan Zalega --- NitrokeyManager.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'NitrokeyManager.cc') diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index 20f4f14..b254071 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -3,6 +3,7 @@ #include "include/NitrokeyManager.h" #include "include/LibraryException.h" #include +#include #include "include/misc.h" namespace nitrokey{ @@ -35,7 +36,11 @@ namespace nitrokey{ // package type to auth, auth type [Authorize,UserAuthorize] template - void authorize_packet(T &package, const char *admin_temporary_password, shared_ptr device){ + void NitrokeyManager::authorize_packet(T &package, const char *admin_temporary_password, shared_ptr device){ + if (!is_authorization_command_supported()){ + Log::instance()("Authorization command not supported, skipping", Loglevel::WARNING); + return; + } auto auth = get_payload(); strcpyT(auth.temporary_password, admin_temporary_password); auth.crc_to_authorize = S::CommandTransaction::getCRC(package); @@ -480,6 +485,15 @@ namespace nitrokey{ return v; } + bool NitrokeyManager::is_authorization_command_supported(){ + auto m = std::unordered_map({ + {DeviceModel::PRO, 7}, + {DeviceModel::STORAGE, 43}, + }); + auto status_p = GetStatus::CommandTransaction::run(*device); + return status_p.data().firmware_version <= m[device->get_device_model()]; + } + bool NitrokeyManager::is_AES_supported(const char *user_password) { auto a = get_payload(); strcpyT(a.user_password, user_password); -- cgit v1.2.1