diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2017-02-21 14:56:07 +0100 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2017-03-11 15:41:49 +0100 |
commit | 29fc4839b7aaf76c3587cf0d268546fd1d1390c4 (patch) | |
tree | e66eec3090ae3235e740a6fc9690fe913d8a49e8 /include | |
parent | c13c7fda5b9f69cd46ba40ac5e6cf1cc4bc7e71d (diff) | |
download | libnitrokey-29fc4839b7aaf76c3587cf0d268546fd1d1390c4.tar.gz libnitrokey-29fc4839b7aaf76c3587cf0d268546fd1d1390c4.tar.bz2 |
Build debug-log-free library for increased security
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/CommandFailedException.h | 2 | ||||
-rw-r--r-- | include/LibraryException.h | 2 | ||||
-rw-r--r-- | include/LongOperationInProgressException.h | 2 | ||||
-rw-r--r-- | include/device_proto.h | 34 | ||||
-rw-r--r-- | include/log.h | 7 | ||||
-rw-r--r-- | include/misc.h | 2 |
6 files changed, 28 insertions, 21 deletions
diff --git a/include/CommandFailedException.h b/include/CommandFailedException.h index 6ff9a2d..417e850 100644 --- a/include/CommandFailedException.h +++ b/include/CommandFailedException.h @@ -20,7 +20,7 @@ public: CommandFailedException(uint8_t last_command_id, uint8_t last_command_status) : last_command_id(last_command_id), last_command_status(last_command_status){ - nitrokey::log::Log::instance()(std::string("CommandFailedException, status: ")+ std::to_string(last_command_status), nitrokey::log::Loglevel::DEBUG); + LOG(std::string("CommandFailedException, status: ")+ std::to_string(last_command_status), nitrokey::log::Loglevel::DEBUG); } virtual const char *what() const throw() { diff --git a/include/LibraryException.h b/include/LibraryException.h index daf0155..b9303ad 100644 --- a/include/LibraryException.h +++ b/include/LibraryException.h @@ -83,7 +83,7 @@ public: TooLongStringException(size_t size_source, size_t size_destination, const std::string &message = "") : size_source( size_source), size_destination(size_destination), message(message) { - nitrokey::log::Log::instance()(std::string("TooLongStringException, size diff: ")+ std::to_string(size_source-size_destination), nitrokey::log::Loglevel::DEBUG); + LOG(std::string("TooLongStringException, size diff: ")+ std::to_string(size_source-size_destination), nitrokey::log::Loglevel::DEBUG); } diff --git a/include/LongOperationInProgressException.h b/include/LongOperationInProgressException.h index 7f182b0..5b441c0 100644 --- a/include/LongOperationInProgressException.h +++ b/include/LongOperationInProgressException.h @@ -15,7 +15,7 @@ public: LongOperationInProgressException( unsigned char _command_id, uint8_t last_command_status, unsigned char _progress_bar_value) : CommandFailedException(_command_id, last_command_status), progress_bar_value(_progress_bar_value){ - nitrokey::log::Log::instance()( + LOG( std::string("LongOperationInProgressException, progress bar status: ")+ std::to_string(progress_bar_value), nitrokey::log::Loglevel::DEBUG); } diff --git a/include/device_proto.h b/include/device_proto.h index 3519123..ea8f136 100644 --- a/include/device_proto.h +++ b/include/device_proto.h @@ -218,7 +218,7 @@ namespace nitrokey { static std::mutex send_receive_mtx; std::lock_guard<std::mutex> guard(send_receive_mtx); - Log::instance()(__FUNCTION__, Loglevel::DEBUG_L2); + LOG(__FUNCTION__, Loglevel::DEBUG_L2); if (dev == nullptr){ throw DeviceNotConnected("Device not initialized"); @@ -236,8 +236,8 @@ namespace nitrokey { outp.payload = payload; outp.update_CRC(); - Log::instance()("Outgoing HID packet:", Loglevel::DEBUG); - Log::instance()(static_cast<std::string>(outp), Loglevel::DEBUG); + LOG("Outgoing HID packet:", Loglevel::DEBUG); + LOG(static_cast<std::string>(outp), Loglevel::DEBUG); if (!outp.isValid()) throw std::runtime_error("Invalid outgoing packet"); @@ -249,7 +249,7 @@ namespace nitrokey { status = dev->send(&outp); if (status <= 0){ //FIXME early disconnection not yet working properly -// Log::instance()("Encountered communication error, disconnecting device", Loglevel::DEBUG_L2); +// LOG("Encountered communication error, disconnecting device", Loglevel::DEBUG_L2); // dev->disconnect(); dev->m_counters.sending_error++; throw DeviceSendingFailure( @@ -268,7 +268,7 @@ namespace nitrokey { if (dev->get_device_model() == DeviceModel::STORAGE && resp.command_id >= stick20::CMD_START_VALUE && resp.command_id < stick20::CMD_END_VALUE ) { - Log::instance()(std::string("Detected storage device cmd, status: ") + + LOG(std::string("Detected storage device cmd, status: ") + std::to_string(resp.storage_status.device_status), Loglevel::DEBUG_L2); resp.last_command_status = static_cast<uint8_t>(stick10::command_status::ok); @@ -286,7 +286,7 @@ namespace nitrokey { resp.device_status = static_cast<uint8_t>(stick10::device_status::ok); break; default: - Log::instance()(std::string("Unknown storage device status, cannot translate: ") + + LOG(std::string("Unknown storage device status, cannot translate: ") + std::to_string(resp.storage_status.device_status), Loglevel::DEBUG); resp.device_status = resp.storage_status.device_status; break; @@ -306,11 +306,11 @@ namespace nitrokey { dev->m_counters.busy++; if (busy_counter++<10) { receiving_retry_counter++; - Log::instance()("Status busy, not decreasing receiving_retry_counter counter: " + + LOG("Status busy, not decreasing receiving_retry_counter counter: " + std::to_string(receiving_retry_counter), Loglevel::DEBUG_L2); } else { busy_counter = 0; - Log::instance()("Status busy, decreasing receiving_retry_counter counter: " + + LOG("Status busy, decreasing receiving_retry_counter counter: " + std::to_string(receiving_retry_counter), Loglevel::DEBUG); } } @@ -320,7 +320,7 @@ namespace nitrokey { successful_communication = true; break; } - Log::instance()(std::string("Retry status - dev status, awaited cmd crc, correct packet CRC: ") + LOG(std::string("Retry status - dev status, awaited cmd crc, correct packet CRC: ") + std::to_string(resp.device_status) + " " + std::to_string(CRC_equal_awaited) + " " + std::to_string(resp.isCRCcorrect()), Loglevel::DEBUG_L2); @@ -329,18 +329,18 @@ namespace nitrokey { if (!CRC_equal_awaited) dev->m_counters.CRC_other_than_awaited++; - Log::instance()( + LOG( "Device is not ready or received packet's last CRC is not equal to sent CRC packet, retrying...", Loglevel::DEBUG); - Log::instance()("Invalid incoming HID packet:", Loglevel::DEBUG_L2); - Log::instance()(static_cast<std::string>(resp), Loglevel::DEBUG_L2); + LOG("Invalid incoming HID packet:", Loglevel::DEBUG_L2); + LOG(static_cast<std::string>(resp), Loglevel::DEBUG_L2); dev->m_counters.total_retries++; std::this_thread::sleep_for(dev->get_retry_timeout()); continue; } if (successful_communication) break; - Log::instance()(std::string("Resending (outer loop) "), Loglevel::DEBUG_L2); - Log::instance()(std::string("sending_retry_counter count: ") + std::to_string(sending_retry_counter), + LOG(std::string("Resending (outer loop) "), Loglevel::DEBUG_L2); + LOG(std::string("sending_retry_counter count: ") + std::to_string(sending_retry_counter), Loglevel::DEBUG); } @@ -355,9 +355,9 @@ namespace nitrokey { std::to_string(status)); } - Log::instance()("Incoming HID packet:", Loglevel::DEBUG); - Log::instance()(static_cast<std::string>(resp), Loglevel::DEBUG); - Log::instance()(std::string("receiving_retry_counter count: ") + std::to_string(receiving_retry_counter), + LOG("Incoming HID packet:", Loglevel::DEBUG); + LOG(static_cast<std::string>(resp), Loglevel::DEBUG); + LOG(std::string("receiving_retry_counter count: ") + std::to_string(receiving_retry_counter), Loglevel::DEBUG); if (resp.device_status == static_cast<uint8_t>(stick10::device_status::busy) && diff --git a/include/log.h b/include/log.h index 695884b..a3e8281 100644 --- a/include/log.h +++ b/include/log.h @@ -53,4 +53,11 @@ class Log { } } + +#ifdef NO_LOG +#define LOG(string, level) while(false){} +#else +#define LOG(string, level) nitrokey::log::Log::instance()((string), (level)) +#endif + #endif diff --git a/include/misc.h b/include/misc.h index c39c741..111d772 100644 --- a/include/misc.h +++ b/include/misc.h @@ -28,7 +28,7 @@ namespace misc { // throw EmptySourceStringException(slot_number); return; const size_t s_dest = sizeof dest; - nitrokey::log::Log::instance()(std::string("strcpyT sizes dest src ") + LOG(std::string("strcpyT sizes dest src ") +std::to_string(s_dest)+ " " +std::to_string(strlen(src))+ " " ,nitrokey::log::Loglevel::DEBUG); |