From da16d91146ea8d7ef885fdbd85631459b3544ee5 Mon Sep 17 00:00:00 2001 From: Brian Cox Date: Sat, 9 Apr 2016 16:36:39 -0700 Subject: [PATCH] Add option to show hashes as hex instead of base64. Siggen already provided this. --- man/man8/tripwire.8 | 4 ++++ man/man8/twprint.8 | 8 ++++++++ src/fco/signature.cpp | 26 ++++++++++++++++++++++++++ src/fco/signature.h | 7 +++++++ src/tripwire/tripwirestrings.cpp | 1 + src/tripwire/twcmdline.cpp | 10 +++++++++- src/tripwire/twcmdline.h | 3 ++- src/twprint/twprintcmdline.cpp | 8 ++++++++ src/twprint/twprintcmdline.h | 1 + src/twprint/twprintstrings.cpp | 2 ++ 10 files changed, 68 insertions(+), 2 deletions(-) diff --git a/man/man8/tripwire.8 b/man/man8/tripwire.8 index fd539d3..5017f97 100644 --- a/man/man8/tripwire.8 +++ b/man/man8/tripwire.8 @@ -273,6 +273,7 @@ lbw(1.2i) lb. -x \fIsection\fP --section \fIsection\fP -M --email-report -t \fR{ 0|1|2|3|4 }\fP --email-report-level \fR{ 0|1|2|3|4 }\fP +-h --hexadecimal .TE .RI "[ " object1 " [ " object2... " ]]" .RE @@ -369,6 +370,9 @@ EMAILREPORTLEVEL variable in the configuration file. \fIlevel\fR must be a number from 0\ to\ 4. Valid only with (\fB\(hyM\fP). .TP +.BR \(hyh ", " --hexadecimal +Display hash values as hexadecimal in email reports +.TP .RI "[ " object1 " [ " object2... " ]]" List of files and directories that should be integrity checked. Default is all files. If files are specified for checking, the diff --git a/man/man8/twprint.8 b/man/man8/twprint.8 index 1dc449e..ad33f86 100644 --- a/man/man8/twprint.8 +++ b/man/man8/twprint.8 @@ -53,6 +53,7 @@ lbw(1.2i) lb. -m r --print-report -v --verbose -s --silent\fR,\fP --quiet +-h --hexadecimal -c \fIcfgfile\fP --cfgfile \fIcfgfile\fP -r \fIreport\fP --twrfile \fIreport\fP -L \fIlocalkey\fP --local-keyfile \fIlocalkey\fP @@ -69,6 +70,9 @@ Verbose output mode. Mutually exclusive with (\fB\(hys\fR). .BR \(hys ", " --silent ", " --quiet Silent output mode. Mutually exclusive with (\fB\(hyv\fR). .TP +.BR \(hyh ", " --hexadecimal +Display hash values as hexadecimal. +.TP .BI \(hyc " cfgfile\fR, " --cfgfile " cfgfile" Use the specified configuration file. .TP @@ -92,6 +96,7 @@ lbw(1.2i) lb. -m d --print-dbfile -v --verbose -s --silent\fR,\fP --quiet +-h --hexadecimal -c \fIcfgfile\fP --cfgfile \fIcfgfile\fP -d \fIdatabase\fP --dbfile \fIdatabase\fP -L \fIlocalkey\fP --local-keyfile \fIlocalkey\fP @@ -108,6 +113,9 @@ Verbose output mode. Mutually exclusive with (\fB\(hys\fR). .BR \(hys ", " --silent ", " --quiet Silent output mode. Mutually exclusive with (\fB\(hyv\fR). .TP +.BR \(hyh ", " --hexadecimal +Display hash values as hexadecimal. +.TP .BI \(hyc " cfgfile\fR, " --cfgfile " cfgfile" Use the specified configuration file. .TP diff --git a/src/fco/signature.cpp b/src/fco/signature.cpp index 66f1aba..9111212 100755 --- a/src/fco/signature.cpp +++ b/src/fco/signature.cpp @@ -97,6 +97,7 @@ iFCOProp::CmpResult iSignature::Compare(const iFCOProp* rhs, Op op) const return (op == iFCOProp::OP_NE) ? iFCOProp::CMP_TRUE : iFCOProp::CMP_FALSE; } +bool cArchiveSigGen::mHex = false; void cArchiveSigGen::AddSig( iSignature* pSig ) { @@ -129,6 +130,16 @@ void cArchiveSigGen::CalculateSignatures( cArchive& a ) mSigList[i]->Finit(); } +bool cArchiveSigGen::Hex() +{ + return mHex; +} + +void cArchiveSigGen::SetHex(bool hex) +{ + mHex = hex; +} + /////////////////////////////////////////////////////////////////////////////// // btob64 -- convert arbitrary bits to base 64 string // @@ -399,6 +410,9 @@ void cCRC32Signature::Finit() // mCRC TSTRING cCRC32Signature::AsString() const { + if (cArchiveSigGen::Hex()) + return AsStringHex(); + TSTRING ret; char *ps_signature; char buf[100]; @@ -505,6 +519,9 @@ void cMD5Signature::Finit() // AsString -- Converts to Base64 representation and returns a TSTRING TSTRING cMD5Signature::AsString() const { + if (cArchiveSigGen::Hex()) + return AsStringHex(); + TSTRING ret; char buf[24]; int length; @@ -626,6 +643,9 @@ void cSHASignature::Finit() #ifdef HAVE_OPENSSL_SHA_H TSTRING cSHASignature::AsString(void) const { + if (cArchiveSigGen::Hex()) + return AsStringHex(); + TSTRING ret; char* ps_signature; char buf[100]; @@ -704,6 +724,9 @@ bool cSHASignature::IsEqual(const iSignature& rhs) const TSTRING cSHASignature::AsString(void) const { + if (cArchiveSigGen::Hex()) + return AsStringHex(); + TSTRING ret; char* ps_signature; char buf[100]; @@ -812,6 +835,9 @@ void cHAVALSignature::Finit() // AsString -- Returns Base64 representation of mSignature in a TSTRING TSTRING cHAVALSignature::AsString() const { + if (cArchiveSigGen::Hex()) + return AsStringHex(); + TSTRING ret; char buf[24]; int length; diff --git a/src/fco/signature.h b/src/fco/signature.h index 22343f5..8a1aec2 100644 --- a/src/fco/signature.h +++ b/src/fco/signature.h @@ -75,6 +75,8 @@ // TODO: figure out a way to do this without including these headers. // pool of objects? + + /////////////////////////////////////////////////////////////////////////////// // class iSignatrue -- Interface all signatures will implement. /////////////////////////////////////////////////////////////////////////////// @@ -145,6 +147,9 @@ public: // produces signature of archive for all signatures in the list // remember to rewind archive! + static bool Hex(); + static void SetHex(bool); + private: // don't let C++ create these functions cArchiveSigGen( const cArchiveSigGen& ); @@ -152,6 +157,8 @@ private: typedef std::vector< iSignature* > container_type; container_type mSigList; + + static bool mHex; }; diff --git a/src/tripwire/tripwirestrings.cpp b/src/tripwire/tripwirestrings.cpp index 4bc4828..1a7061d 100644 --- a/src/tripwire/tripwirestrings.cpp +++ b/src/tripwire/tripwirestrings.cpp @@ -89,6 +89,7 @@ TSS_BeginStringtable( cTripwire ) _T(" -m c --check\n") _T(" -I --interactive\n") _T(" -v --verbose\n") + _T(" -h --hexadecimal\n") _T(" -s --silent, --quiet\n") _T(" -c cfgfile --cfgfile cfgfile\n") _T(" -p polfile --polfile polfile\n") diff --git a/src/tripwire/twcmdline.cpp b/src/tripwire/twcmdline.cpp index cfccb72..4d885a7 100644 --- a/src/tripwire/twcmdline.cpp +++ b/src/tripwire/twcmdline.cpp @@ -66,6 +66,7 @@ #include #include "fco/parsergenreutil.h" // this is needed to figure out if a path is fully qualified for the current genre. #include "tw/fcodatabasefile.h" +#include "fco/signature.h" #include "fco/genreswitcher.h" #include "generatedb.h" #include "integritycheck.h" @@ -826,7 +827,8 @@ void cTWModeIC::InitCmdLineParser(cCmdLineParser& cmdLine) cmdLine.AddArg(cTWCmdLine::RULE_NAME, TSTRING(_T("R")), TSTRING(_T("rule-name")), cCmdLineParser::PARAM_ONE); cmdLine.AddArg(cTWCmdLine::GENRE_NAME, TSTRING(_T("x")), TSTRING(_T("section")), cCmdLineParser::PARAM_ONE); cmdLine.AddArg(cTWCmdLine::PARAMS, TSTRING(_T("")), TSTRING(_T("")), cCmdLineParser::PARAM_MANY); - + cmdLine.AddArg(cTWCmdLine::HEXADECIMAL, TSTRING(_T("h")), TSTRING(_T("hexadecimal")), cCmdLineParser::PARAM_NONE); + // multiple levels of reporting cmdLine.AddArg(cTWCmdLine::REPORTLEVEL, TSTRING(_T("t")), TSTRING(_T("email-report-level")), cCmdLineParser::PARAM_ONE); @@ -835,6 +837,8 @@ void cTWModeIC::InitCmdLineParser(cCmdLineParser& cmdLine) cmdLine.AddArg(cTWCmdLine::USE_GMMS, TSTRING(_T("g")), TSTRING(_T("gmms")), cCmdLineParser::PARAM_NONE); cmdLine.AddArg(cTWCmdLine::GMMS_VERBOSITY, TSTRING(_T("b")), TSTRING(_T("gmms-verbosity")), cCmdLineParser::PARAM_ONE); #endif + + // mutual exclusion... // you can't specify any of these 3 things together... @@ -964,6 +968,10 @@ bool cTWModeIC::Init(const cConfigFile& cf, const cCmdLineParser& cmdLine) ASSERT(iter.NumParams() > 0); mpData->mGenreName = iter.ParamAt(0); break; + case cTWCmdLine::HEXADECIMAL: + cArchiveSigGen::SetHex(true); + break; + case cTWCmdLine::PARAMS: { // pack all of these onto the files to check list... diff --git a/src/tripwire/twcmdline.h b/src/tripwire/twcmdline.h index d571d3f..668acd0 100644 --- a/src/tripwire/twcmdline.h +++ b/src/tripwire/twcmdline.h @@ -137,7 +137,8 @@ public: SITE_PASSPHRASE, TEST_EMAIL, REPORTLEVEL, - + HEXADECIMAL, + #ifdef GMMS USE_GMMS, GMMS_VERBOSITY, diff --git a/src/twprint/twprintcmdline.cpp b/src/twprint/twprintcmdline.cpp index 459703e..ce098ed 100644 --- a/src/twprint/twprintcmdline.cpp +++ b/src/twprint/twprintcmdline.cpp @@ -66,6 +66,8 @@ #include "fco/twfactory.h" #include "fco/fcospeclist.h" // cFCOSpecList #include "fco/fcopropdisplayer.h" +#include "fco/signature.h" + #include /////////////////////////////////////////////////////////////////////////////// @@ -118,6 +120,9 @@ static void InitCmdLineCommon(cCmdLineParser& parser) // unattended operation parser.AddArg(cTWPrintCmdLine::PASSPHRASE, TSTRING(_T("P")), TSTRING(_T("passphrase")), cCmdLineParser::PARAM_ONE); + + + parser.AddArg(cTWPrintCmdLine::HEXADECIMAL, TSTRING(_T("h")), TSTRING(_T("hexadecimal")), cCmdLineParser::PARAM_NONE); // the paramters to the command line ... for now, this will take "many", even though in some // modes, this is not valid to do... @@ -276,6 +281,9 @@ static void FillOutCmdLineInfo(cTWPrintModeCommon* pModeInfo, const cCmdLinePars ASSERT(iter.NumParams() > 0); // should be caught by cmd line parser pModeInfo->mSiteKeyFile = iter.ParamAt(0); break; + case cTWPrintCmdLine::HEXADECIMAL: + cArchiveSigGen::SetHex(true); + break; case cTWPrintCmdLine::PASSPHRASE: { // this bites! I have to make sure it is a narrow char string diff --git a/src/twprint/twprintcmdline.h b/src/twprint/twprintcmdline.h index 89190c1..bbc46ba 100644 --- a/src/twprint/twprintcmdline.h +++ b/src/twprint/twprintcmdline.h @@ -89,6 +89,7 @@ public: PASSPHRASE, REPORTLEVEL, + HEXADECIMAL, PARAMS, // the final parameters diff --git a/src/twprint/twprintstrings.cpp b/src/twprint/twprintstrings.cpp index 740bb16..d55e29e 100644 --- a/src/twprint/twprintstrings.cpp +++ b/src/twprint/twprintstrings.cpp @@ -56,6 +56,7 @@ TSS_BeginStringtable( cTWPrint ) _T("Print Database mode:\n") _T(" -m d --print-dbfile\n") _T(" -v --verbose\n") + _T(" -h --hexadecimal\n") _T(" -s --silent, --quiet\n") _T(" -c cfgfile --cfgfile cfgfile\n") _T(" -d database --dbfile database\n") @@ -70,6 +71,7 @@ TSS_BeginStringtable( cTWPrint ) _T("Print Report mode:\n") _T(" -m r --print-report\n") _T(" -v --verbose\n") + _T(" -h --hexadecimal\n") _T(" -s --silent, --quiet\n") _T(" -c cfgfile --cfgfile cfgfile\n") _T(" -r report --twrfile report\n")