Adds partially support to t:sha1 transformation

This commit is contained in:
Felipe Zimmerle 2015-10-23 10:53:54 -03:00
parent 91d29d2849
commit 743fb651da
3 changed files with 29 additions and 10 deletions

View File

@ -24,6 +24,8 @@
#include "modsecurity/assay.h" #include "modsecurity/assay.h"
#include "actions/transformations/transformation.h" #include "actions/transformations/transformation.h"
#include "utils/sha1.h"
#include "src/utils.h"
namespace ModSecurity { namespace ModSecurity {
@ -37,15 +39,12 @@ Sha1::Sha1(std::string action)
std::string Sha1::evaluate(std::string value, std::string Sha1::evaluate(std::string value,
Assay *assay) { Assay *assay) {
/**
* @todo Implement the transformation Sha1 Utils::SHA1 sha1;
*/ sha1.update(&value);
if (assay) { std::string sha1_bin = sha1.final_bin();
#ifndef NO_LOGS
assay->debug(4, "Transformation Sha1 is not implemented yet."); return sha1_bin;
#endif
}
return value;
} }
} // namespace transformations } // namespace transformations

View File

@ -65,7 +65,7 @@ void SHA1::update(std::istream *is) {
} }
std::string SHA1::final() { std::string SHA1::final_bin(bool toReset = true) {
/* Total number of hashed bits */ /* Total number of hashed bits */
uint64_t total_bits = (transforms*BLOCK_BYTES + buffer.size()) * 8; uint64_t total_bits = (transforms*BLOCK_BYTES + buffer.size()) * 8;
@ -91,6 +91,22 @@ std::string SHA1::final() {
block[BLOCK_INTS - 2] = (total_bits >> 32); block[BLOCK_INTS - 2] = (total_bits >> 32);
transform(block); transform(block);
if (toReset) {
/* Reset for next run */
reset();
}
std::string bin;
bin.append((const char*) digest, BLOCK_INTS);
return bin;
}
std::string SHA1::final() {
final_bin(false);
/* Hex std::string */ /* Hex std::string */
std::ostringstream result; std::ostringstream result;
for (unsigned int i = 0; i < DIGEST_INTS; i++) { for (unsigned int i = 0; i < DIGEST_INTS; i++) {

View File

@ -47,6 +47,10 @@ class SHA1 {
void update(std::string *s); void update(std::string *s);
void update(std::istream *is); void update(std::istream *is);
std::string final(); std::string final();
std::string final_bin() {
return final_bin(true);
}
std::string final_bin(bool reset);
private: private:
/* number of 32bit integers per SHA1 digest */ /* number of 32bit integers per SHA1 digest */