Skip to content

Commit

Permalink
Merge pull request #26 from muflihun/develop
Browse files Browse the repository at this point in the history
4.0.0
  • Loading branch information
abumq authored Aug 17, 2017
2 parents 10be7b2 + 1d514b5 commit af638f7
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 71 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change Log

## [4.0.0] - 17-08-2017
### Changes
- All errors are throwing runtime exceptions instead of logging

### Updated
- All the compiler warnings are report as error

## [3.3.0] - 27-07-2017
### Added
- Ability to encrypt using specified IV
Expand Down
25 changes: 11 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ option(test "Build all tests" OFF)
option(travis "Build all tests for travis" OFF)
option(dll "DLL imports (Use on windows only)" OFF)
option(dll_export "DLL exports (Use on windows only)" OFF)
option(build_static_lib "Build ripe as a static library (as opposed to default, i.e, shared)" OFF)
option (BUILD_SHARED_LIBS "build shared libraries" ON)

set (RIPE_VERSION "3.3.0")
set (RIPE_SOVERSION "3.3.0")
set (RIPE_VERSION "4.0.0")
set (RIPE_SOVERSION "4.0.0")

add_definitions (-DRIPE_VERSION="${RIPE_VERSION}")
add_definitions (-DELPP_NO_LOG_TO_FILE)
Expand Down Expand Up @@ -57,9 +57,7 @@ if (APPLE)
endif()
endif()

if (!travis)
list(APPEND CMAKE_CXX_FLAGS "-Wno-deprecated-declarations")
endif()
list (APPEND CMAKE_CXX_FLAGS " -Wall -Werror -fPIC -g2 -O2 ")

if (dll)
add_definitions (-DRIPE_DLL)
Expand All @@ -77,10 +75,6 @@ find_package(CryptoPP REQUIRED)
message ("-- Crypto++ binary: " ${CRYPTOPP_LIBRARY})
include_directories (${CRYPTOPP_INCLUDE_DIRS})

# Check for Easylogging++
find_package(EASYLOGGINGPP REQUIRED)
include_directories (${EASYLOGGINGPP_INCLUDE_DIR})

find_package(ZLIB REQUIRED)
if (ZLIB_FOUND)
include_directories(${ZLIB_INCLUDE_DIRS})
Expand All @@ -107,13 +101,12 @@ set (CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE})
# Ripe lib
set(LIB_RIPE_SOURCE_FILES
lib/Ripe.cc
${EASYLOGGINGPP_INCLUDE_DIR}/easylogging++.cc
)

if (build_static_lib)
add_library(ripe STATIC ${LIB_RIPE_SOURCE_FILES})
else()
if (BUILD_SHARED_LIBS)
add_library(ripe SHARED ${LIB_RIPE_SOURCE_FILES})
else()
add_library(ripe STATIC ${LIB_RIPE_SOURCE_FILES})
endif()

set_target_properties(ripe PROPERTIES
Expand Down Expand Up @@ -155,6 +148,10 @@ add_custom_target (all_placeholder SOURCES ${all_headers})
########################################## Unit Testing ###################################
if (test)

# Check for Easylogging++
find_package(EASYLOGGINGPP REQUIRED)
include_directories (${EASYLOGGINGPP_INCLUDE_DIR})

find_package (gtest REQUIRED)

include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ These are the requirements to build Ripe binaries.
* gcc
* gcc-c++
* [Easylogging++](https://github.com/muflihun/easyloggingpp) v9.94.1+
* [Crypto++](https://www.cryptopp.com/) v5.6.5+ [with Pem Pack](https://raw.githubusercontent.com/muflihun/muflihun.github.io/master/downloads/Pem-pack.zip)
* [Crypto++](https://www.cryptopp.com/) v5.6.5+ [with Pem Pack](https://raw.githubusercontent.com/muflihun/muflihun.github.io/master/downloads/pem_pack.zip)
* [cmake](https://cmake.org/) v2.8.12+
* [zlib-devel](https://zlib.net/)

Expand Down
10 changes: 5 additions & 5 deletions cmake/FindRipe.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# CMake module for Ripe cryptography library
# CMake module for Ripe cryptography wrapper
#
# Creates ${RIPE_INCLUDE_DIR} and ${RIPE_LIBRARY}
#
Expand All @@ -21,15 +21,15 @@ find_path(RIPE_INCLUDE_DIR
)

if (Ripe_USE_STATIC_LIBS)
message ("-- Ripe: Static linking is preferred")
message ("-- Ripe: Static linking")
find_library(RIPE_LIBRARY
NAMES libripe.a libripe.dylib libripe ripe
NAMES libripe.dylib libripe ripe
HINTS "${CMAKE_PREFIX_PATH}/lib"
)
else()
message ("-- Ripe: Dynamic linking is preferred")
message ("-- Ripe: Dynamic linking")
find_library(RIPE_LIBRARY
NAMES ripe libripe libripe.dylib libripe.a
NAMES ripe libripe libripe.dylib
HINTS "${CMAKE_PREFIX_PATH}/lib"
)
endif()
Expand Down
8 changes: 7 additions & 1 deletion include/Ripe.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ RIPE_API class Ripe {
* @param inputFile Input file path
* @return True if successful, otherwise false
*/
static bool compressFile(const std::string& gzFilename, const std::string& inputFile) noexcept;
static bool compressFile(const std::string& gzFilename, const std::string& inputFile);

/**
* @brief Compresses string using zlib (inflate)
Expand Down Expand Up @@ -433,5 +433,11 @@ RIPE_API class Ripe {
/// \brief version Version of Ripe library
///
static std::string version() noexcept;

private:

Ripe() = delete;
Ripe(const Ripe&) = delete;
Ripe& operator=(const Ripe&) = delete;
};
#endif /* Ripe_h */
17 changes: 0 additions & 17 deletions include/log.h

This file was deleted.

32 changes: 17 additions & 15 deletions lib/Ripe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <sstream>
#include <fstream>
#include <vector>
#include <iostream>

#include <cryptopp/osrng.h>
#include <cryptopp/base64.h>
Expand All @@ -20,12 +21,9 @@
#include <zlib.h>

#include "include/Ripe.h"
#include "include/log.h"

#define RIPE_UNUSED(x) (void)x

INITIALIZE_EASYLOGGINGPP

using namespace CryptoPP;

const std::string Ripe::PACKET_DELIMITER = "\r\n\r\n";
Expand Down Expand Up @@ -170,7 +168,6 @@ std::string Ripe::signRSA(const std::string& data, const std::string& privateKey

bool Ripe::writeRSAKeyPair(const std::string& publicFile, const std::string& privateFile, int length, const std::string& secret)
{
RLOG(INFO) << "Generating key pair that can encrypt " << Ripe::maxRSABlockSize(length) << " bytes";
bool result = true;
KeyPair keypair = Ripe::generateRSAKeyPair(length, secret);
if (keypair.privateKey.size() > 0 && keypair.publicKey.size() > 0) {
Expand All @@ -179,7 +176,9 @@ bool Ripe::writeRSAKeyPair(const std::string& publicFile, const std::string& pri
fs.write(keypair.privateKey.c_str(), keypair.privateKey.size());
fs.close();
} else {
RLOG(ERROR) << "Unable to open [" << privateFile << "]";
throw std::runtime_error(
std::string("Unable to open private file for writing [" + privateFile + "] " + std::strerror(errno)).data()
);
result = false;
}
fs.open(publicFile.c_str(), std::ios::out);
Expand All @@ -188,24 +187,23 @@ bool Ripe::writeRSAKeyPair(const std::string& publicFile, const std::string& pri
fs.close();
result = result && true;
} else {
RLOG(ERROR) << "Unable to open [" << publicFile << "]";
throw std::runtime_error(
std::string("Unable to open public file for writing [" + publicFile + "] " + std::strerror(errno)).data()
);
result = false;
}
}
if (!result) {
RLOG(ERROR) << "Failed to generate key pair! Please check logs for details" << std::endl;
throw std::logic_error("Failed to generate key pair!");
throw std::runtime_error("Failed to generate key pair.");
}
RLOG(INFO) << "Successfully saved!";
return result;
}

std::string Ripe::generateRSAKeyPairBase64(int length, const std::string& secret)
{
Ripe::KeyPair pair = Ripe::generateRSAKeyPair(length, secret);
if (pair.privateKey.empty() || pair.publicKey.empty()) {
RLOG(ERROR) << "Failed to generate key pair! Please check logs for details" << std::endl;
throw std::logic_error("Failed to generate key pair!");
throw std::runtime_error("Failed to generate key pair.");
}
return Ripe::base64Encode(pair.privateKey) + ":" + Ripe::base64Encode(pair.publicKey);
}
Expand Down Expand Up @@ -313,7 +311,7 @@ std::string Ripe::encryptAES(std::string& data, const std::string& hexKey, const
std::vector<byte> iv;
if (!ivec.empty()) {
byte* ivBytes = reinterpret_cast<byte*>(const_cast<char*>(ivec.data()));
iv = std::move(Ripe::byteToVec(ivBytes));
iv = Ripe::byteToVec(ivBytes);
}
std::string encrypted = Ripe::encryptAES(data, hexKey, iv);

Expand Down Expand Up @@ -382,11 +380,13 @@ std::string Ripe::decryptAES(std::string& data, const std::string& hexKey, std::
return Ripe::decryptAES(data, reinterpret_cast<const byte*>(Ripe::hexToString(hexKey).c_str()), hexKey.size() / 2, ivHex);
}

bool Ripe::compressFile(const std::string& gzFilename, const std::string& inputFile) noexcept
bool Ripe::compressFile(const std::string& gzFilename, const std::string& inputFile)
{
gzFile out = gzopen(gzFilename.c_str(), "wb");
if (!out) {
RLOG(ERROR) << "Unable to open file [" << gzFilename << "] for writing." << std::strerror(errno);
throw std::runtime_error(
std::string("Unable to open file for writing [" + gzFilename + "] " + std::strerror(errno)).data()
);
return false;
}
char buff[BUFSIZ];
Expand All @@ -396,7 +396,9 @@ bool Ripe::compressFile(const std::string& gzFilename, const std::string& inputF
int bytes_written = gzwrite(out, buff, nRead);
if (bytes_written == 0) {
int err_no = 0;
RLOG(ERROR) << "Error during compression: " << gzerror(out, &err_no);
throw std::runtime_error(
std::string("Error during compression " + std::string(gzerror(out, &err_no))).data()
);
gzclose(out);
return false;
}
Expand Down
4 changes: 3 additions & 1 deletion openssl-compatibility.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
RIPE=./ripe
if [ "$RIPE" = "" ];then
RIPE=./ripe
fi

#################################################=- KEY USING RIPE -=###################################################

Expand Down
Loading

0 comments on commit af638f7

Please sign in to comment.