[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 9c510ad 16/22: Measure elapsed time for MD5 d
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 9c510ad 16/22: Measure elapsed time for MD5 data-file validation |
Date: |
Sat, 28 Mar 2020 18:23:38 -0400 (EDT) |
branch: master
commit 9c510ad08bb0ec0ee3e30fe28ec3ff085f0b90e5
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Measure elapsed time for MD5 data-file validation
It is anticipated that this commit will soon be reverted. This
instrumentation could have been placed on a throwaway branch, but it's
more convenient to keep it on the main trunk.
Measure how long it takes to validate MD5 files by two methods:
- an external md5sum program, as in the past; and
- internally, as now.
Print timings to std::cout, so that only developers see them.
When run with '--pyx=measure_md5' and without '--ash_nazg', ignore
caching and thus revalidate before each PDF illustration is printed.
Reason: now that validation is faster, it may be desirable to address
this marked defect:
// TODO ?? Known security hole: data files can be modified after they
// have been validated.
by inhibiting caching (at least when neither '--ash_nazg' nor '--mellon'
is given--i.e., for users who aren't allowed to use the product editor).
Here are timings on a machine that's probably faster than the average
corporate laptop, for a one-line 'validated.md5':
/opt/lmi/data[0]$cat validated.md5
5fc68a795c9c60da1b32be989efc299a *expiry
/opt/lmi/bin[0]$wine ./lmi_wx_shared --mellon \
--data_path=/opt/lmi/data --pyx=measure_md5
Assay: production 1 milliseconds
Assay: external program 96 milliseconds
...and for a maximal 'validated.md5' prepared with the full list of
files in 'fardel_checksummed_files', using every known product, and
generating PDF illustrations several times (hence the repeated timings):
/opt/lmi/bin[1]$wine ./lmi_wx_shared --mellon \
--data_path=/opt/lmi/data --pyx=measure_md5
Assay: production 87 milliseconds
Assay: external program 245 milliseconds
Assay: internal 97 milliseconds
Assay: production 114 milliseconds
Assay: external program 180 milliseconds
Assay: internal 115 milliseconds
Assay: production 114 milliseconds
Assay: external program 181 milliseconds
Assay: internal 115 milliseconds
Assay: production 115 milliseconds
Assay: external program 183 milliseconds
Assay: internal 119 milliseconds
Is the extra security worth the extra delay? Only measurements on a
typical end-user machine can guide that decision. If it's considered
worthwhile, then the speed can be improved by eliminating some files
from 'fardel_checksummed_files':
- 'lmi_md5sum.exe', which is no longer required in production
- '*.dat *.ndx *.xst', which are already not human readable
Effect of eliminating those files:
/opt/lmi/bin[0]$wine ./lmi_wx_shared --mellon \
--data_path=/opt/lmi/data --pyx=measure_md5
Assay: production 76 milliseconds
Assay: external program 201 milliseconds
Assay: internal 79 milliseconds
Assay: production 60 milliseconds
Assay: external program 129 milliseconds
Assay: internal 65 milliseconds
Assay: production 59 milliseconds
Assay: external program 176 milliseconds
Assay: internal 78 milliseconds
It would probably be helpful to cache 'validated.md5' as well.
---
authenticity.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
objects.make | 4 ++++
2 files changed, 71 insertions(+)
diff --git a/authenticity.cpp b/authenticity.cpp
index 06b540f..46e3c24 100644
--- a/authenticity.cpp
+++ b/authenticity.cpp
@@ -25,11 +25,15 @@
#include "alert.hpp"
#include "calendar_date.hpp"
+#include "contains.hpp"
#include "global_settings.hpp"
#include "handle_exceptions.hpp"
#include "md5.hpp"
#include "md5sum.hpp"
#include "path_utility.hpp" // fs::path inserter
+#include "platform_dependent.hpp" // chdir()
+#include "system_command.hpp"
+#include "timer.hpp"
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/operations.hpp>
@@ -37,6 +41,7 @@
#include <cstdio> // fclose(), fopen()
#include <cstdlib> // exit(), EXIT_FAILURE
#include <cstring> // memcpy()
+#include <iostream> // cout, endl
#include <sstream>
#include <stdexcept>
#include <vector>
@@ -69,11 +74,14 @@ std::string Authenticity::Assay
,fs::path const& data_path
)
{
+ Timer timer;
+
// The cached date is valid unless it's the peremptorily-invalid
// default value of JDN zero.
if
( calendar_date(jdn_t(0)) != Instance().CachedDate_
&& candidate == Instance().CachedDate_
+ && !contains(global_settings::instance().pyx(), "measure_md5")
)
{
return "cached";
@@ -240,6 +248,65 @@ std::string Authenticity::Assay
}
// Cache the validated date.
Instance().CachedDate_ = candidate;
+
+ std::cout << "Assay: production " << timer.stop().elapsed_msec_str() <<
std::endl;
+
+ // MD5 !! Revert "measure_md5" instrumentation soon.
+ if(contains(global_settings::instance().pyx(), "measure_md5"))
+ {
+ try
+ {
+ timer.restart();
+ fs::path original_path(fs::current_path());
+ if(0 != chdir(data_path.string().c_str()))
+ {
+ oss
+ << "Unable to change directory to '"
+ << data_path
+ << "'. Try reinstalling."
+ ;
+ return oss.str();
+ }
+ system_command("md5sum --check --status " + (data_path /
md5sum_file()).string());
+ if(0 != chdir(original_path.string().c_str()))
+ {
+ oss
+ << "Unable to restore directory to '"
+ << original_path
+ << "'. Try reinstalling."
+ ;
+ return oss.str();
+ }
+ std::cout << "Assay: external program " <<
timer.stop().elapsed_msec_str() << std::endl;
+
+ timer.restart();
+ auto const sums = md5_read_checksum_file(data_path / md5sum_file());
+ for(auto const& s : sums)
+ {
+ auto const file_path = data_path / s.filename;
+ auto const md5 = md5_calculate_file_checksum
+ (data_path / s.filename
+ ,s.file_mode
+ );
+ if(md5 != s.md5sum)
+ {
+ throw std::runtime_error
+ ( "Integrity check failed for '"
+ + s.filename.string()
+ + "'"
+ );
+ }
+ }
+ std::cout << "Assay: internal " << timer.stop().elapsed_msec_str() <<
std::endl;
+ }
+ catch(...)
+ {
+ report_exception();
+ oss << "Failure in time measurements.";
+ return oss.str();
+ }
+ }
+
return "validated";
}
diff --git a/objects.make b/objects.make
index 8e86a5e..d1231cc 100644
--- a/objects.make
+++ b/objects.make
@@ -530,6 +530,7 @@ assert_lmi_test$(EXEEXT): \
$(common_test_objects) \
assert_lmi_test.o \
+# MD5 !! Remove "timer.o" below.
authenticity_test$(EXEEXT): \
$(boost_filesystem_objects) \
$(common_test_objects) \
@@ -544,6 +545,7 @@ authenticity_test$(EXEEXT): \
path_utility.o \
system_command.o \
system_command_non_wx.o \
+ timer.o \
bourn_cast_test$(EXEEXT): \
$(common_test_objects) \
@@ -1100,6 +1102,7 @@ lmi_md5sum$(EXEEXT): \
md5sum.o \
md5sum_cli.o \
+# MD5 !! Remove "timer.o" below.
generate_passkey$(EXEEXT): \
$(boost_filesystem_objects) \
$(main_auxiliary_common_objects) \
@@ -1114,6 +1117,7 @@ generate_passkey$(EXEEXT): \
path_utility.o \
system_command.o \
system_command_non_wx.o \
+ timer.o \
ihs_crc_comp$(EXEEXT): \
$(main_auxiliary_common_objects) \
- [lmi-commits] [lmi] master 925f946 05/22: Include headers iff appropriate, (continued)
- [lmi-commits] [lmi] master 925f946 05/22: Include headers iff appropriate, Greg Chicares, 2020/03/28
- [lmi-commits] [lmi] master fc09a91 03/22: Add unit tests for MD5-related functionality, Greg Chicares, 2020/03/28
- [lmi-commits] [lmi] master 225cf10 09/22: Avoid a warning by a different means, Greg Chicares, 2020/03/28
- [lmi-commits] [lmi] master 2db19f5 11/22: Remove unnecessary shared-object attributes, Greg Chicares, 2020/03/28
- [lmi-commits] [lmi] master 28f8ffc 15/22: Explicitly qualify std::cout, Greg Chicares, 2020/03/28
- [lmi-commits] [lmi] master f14ad11 01/22: Implement MD5 checksum files reading in lmi code, Greg Chicares, 2020/03/28
- [lmi-commits] [lmi] master ec4fe67 18/22: Realphabetize a list, Greg Chicares, 2020/03/28
- [lmi-commits] [lmi] master 8d3e03a 20/22: Expunge a disused makefile variable, Greg Chicares, 2020/03/28
- [lmi-commits] [lmi] master 72ee60f 17/22: Improve instructions, Greg Chicares, 2020/03/28
- [lmi-commits] [lmi] master 9ae6e81 19/22: Reformat and lightly revise some documentation, Greg Chicares, 2020/03/28
- [lmi-commits] [lmi] master 9c510ad 16/22: Measure elapsed time for MD5 data-file validation,
Greg Chicares <=
- [lmi-commits] [lmi] master 6645aa7 21/22: Eradicate 'winebindir', Greg Chicares, 2020/03/28
- [lmi-commits] [lmi] master 6425b3b 22/22: Install 'lmi_md5sum$(EXEEXT)' elsewhere, Greg Chicares, 2020/03/28