Skip to content

Commit

Permalink
program options impl
Browse files Browse the repository at this point in the history
  • Loading branch information
sinev-valentine committed Oct 18, 2018
1 parent 202ad79 commit 3ffc85e
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 50 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ add_subdirectory(./libraries/fc_light)

if( MSVC )
add_subdirectory(./keychain_service_win)
else ( MSVC )
add_subdirectory(./keychain_linux/passentry_gui)
endif ( MSVC )
add_subdirectory(./keychain_cmd_app)


if ( ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
add_subdirectory(./keychain_linux/passentry_gui)
endif()
57 changes: 28 additions & 29 deletions keychain_cmd_app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,59 +19,58 @@ FIND_PACKAGE(Boost 1.65 REQUIRED COMPONENTS coroutine)
LIST(APPEND BOOST_COMPONENTS coroutine)
SET(Boost_LIBRARIES ${BOOST_LIBRARIES_TEMP} ${Boost_LIBRARIES})

if( MSVC )
include_directories(
"../keychain_lib/include"
"../libraries/fc_light/include"
"../libraries/ethereum/include"
"../libraries/secp256k1/include"
"${OPENSSL_ROOT_DIR}/include"
${Boost_INCLUDE_DIR})
else ( MSVC )

find_library(LIB_OPENSSL NAME crypto HINTS "${OPENSSL_ROOT_DIR}/lib")
if( NOT MSVC )
find_library(LIB_PTHREAD NAME pthread HINTS "/usr/lib/x86_64-linux-gnu")
endif( NOT MSVC )


if ( ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
include_directories(
"../keychain_lib/include"
"../keychain_linux/passentry_cmd"
"../libraries/fc_light/include"
"../libraries/ethereum/include"
"../libraries/secp256k1/include"
"../libraries/secp256k1_ext/include"
"${OPENSSL_ROOT_DIR}/include"
"/usr/include/libcxxabi"
${Boost_INCLUDE_DIR})
endif( MSVC )

find_library(LIB_OPENSSL NAME crypto HINTS "${OPENSSL_ROOT_DIR}/lib")
if( NOT MSVC )
find_library(LIB_PTHREAD NAME pthread HINTS "/usr/lib/x86_64-linux-gnu")
endif( NOT MSVC )

file(GLOB KEYCHAIN_SOURCES "./*.cpp" "../keychain_linux/passentry_cmd/*.cpp" )
file(GLOB KEYCHAIN_INCLUDE "./*.hpp" "../keychain_linux/passentry_cmd/*.hpp" )
file(GLOB KEYCHAIN_SOURCES "./*.cpp" "../keychain_linux/passentry_cmd/*.cpp" )
file(GLOB KEYCHAIN_INCLUDE "./*.hpp" "../keychain_linux/passentry_cmd/*.hpp" )

add_executable(keychain ${KEYCHAIN_SOURCES} ${KEYCHAIN_INCLUDE} )

if( NOT MSVC )
find_package(X11 REQUIRED)
if(NOT X11_FOUND)
message(SEND_ERROR "Failed to find X11")
return()
else()
include_directories(${X11_INCLUDE_DIR})
endif()

find_library(LIB_XI NAME Xi HINTS "/usr/lib/x86_64-linux-gnu/")
endif()

if( MSVC )
target_link_libraries(keychain keychain_common fc_light ether ${LIB_OPENSSL} ${Boost_LIBRARIES})
else ( MSVC )
add_executable(keychain ${KEYCHAIN_SOURCES} ${KEYCHAIN_INCLUDE} )
target_link_libraries(keychain keychain_common ${LIB_PTHREAD} fc_light ether ${LIB_OPENSSL} ${Boost_LIBRARIES} ${X11_LIBRARIES} ${LIB_XI})
endif ( MSVC )

if( NOT MSVC )
set(GUI_BINARY ${CMAKE_BINARY_DIR}/keychain_linux/passentry_gui/passentry_gui)
set(KEYCHAIN_BINARY_DIR ${CMAKE_BINARY_DIR}/keychain_cmd_app)
ADD_CUSTOM_COMMAND(TARGET keychain
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${GUI_BINARY} ${KEYCHAIN_BINARY_DIR}
)
endif (NOT MSVC )
else()
include_directories(
"../keychain_lib/include"
"../libraries/fc_light/include"
"../libraries/ethereum/include"
"../libraries/secp256k1/include"
"../libraries/secp256k1_ext/include"
"${OPENSSL_ROOT_DIR}/include"
${Boost_INCLUDE_DIR})

file(GLOB KEYCHAIN_SOURCES "./*.cpp" )
file(GLOB KEYCHAIN_INCLUDE "./*.hpp" )
add_executable(keychain ${KEYCHAIN_SOURCES} ${KEYCHAIN_INCLUDE} )
target_link_libraries(keychain keychain_common fc_light ether ${LIB_OPENSSL} ${Boost_LIBRARIES})

endif()
48 changes: 45 additions & 3 deletions keychain_cmd_app/cmd_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Created by roman on 4/6/18.
//


#include <boost/config/detail/select_platform_config.hpp>
#include <iostream>

#include <keychain_lib/pipeline_parser.hpp>
Expand All @@ -11,18 +13,58 @@
#include "cmd_parser.hpp"
#include "sec_mod.hpp"

#include <boost/program_options.hpp>
//#include <boost/program_options/options_description.hpp>
//#include <boost/program_options/option.hpp>

#ifdef LINUX
#include "sec_mod_linux.hpp"
#endif

using namespace keychain_app;


cmd_parser::cmd_parser()
{
//TODO: define program options
}

int cmd_parser::run(int argc, const char* const argv [])
{
//TODO: add boost program options call that will parse command line arguments

const secure_dlg_mod_base* sec_mod = secure_module<sec_mod_dummy>::instance();

const secure_dlg_mod_base* sec_mod;

std::string task_type;
po::options_description desc("Options");
desc.add_options()
("help,h", "Show help")
("mode", po::value<std::string>(&task_type), "Select mode=test_run for test program with \"blank\" password");

po::variables_map vm;
try
{
po::parsed_options parsed = po::command_line_parser(argc, argv).options(desc).allow_unregistered().run();
po::store(parsed, vm);
po::notify(vm);

if (task_type == "test_run")
sec_mod = secure_module<sec_mod_dummy>::instance();
else if (task_type == "")
{
#ifdef LINUX
sec_mod = secure_module<sec_mod_linux>::instance();
#else
sec_mod = secure_module<sec_mod_dummy>::instance();
#endif
}
else
std::cout<< desc << std::endl;
}
catch (std::exception& ex)
{
std::cout<< desc << std::endl;
return 0;
}

keychain_invoke_f f = std::bind(&keychain_wrapper, sec_mod, std::placeholders::_1);
pipeline_parser pipe_line_parser_(std::move(f), fileno(stdin), fileno(stdout));
Expand Down
9 changes: 9 additions & 0 deletions keychain_cmd_app/cmd_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@

#include <boost/program_options.hpp>

#if (defined(linux) || defined(__linux) || defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)) && !defined(_CRAYC)
#define LINUX
#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
#define WIN
#elif defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
#define APPLE
#endif


namespace po = boost::program_options;

namespace keychain_app
Expand Down
15 changes: 6 additions & 9 deletions keychain_cmd_app/sec_mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,15 @@ void sec_mod_dummy::print_mnemonic(const string_list& mnemonic) const

byte_seq_t sec_mod_dummy::get_passwd_trx_raw(const std::string& raw_trx) const
{
auto pass_entry = pass_entry_term();
auto map_instance = map_translate_singletone::instance(pass_entry._display);
auto pass = pass_entry.fork_gui(map_instance.map, raw_trx);
//std::cout <<"password: "<< std::string(pass.data(), pass.size()) << std::endl;
std::string str = "blank";
keychain_app::byte_seq_t pass(str.begin(), str.end());
return pass;
}

byte_seq_t sec_mod_dummy::get_passwd_on_create() const
{
auto pass_entry = pass_entry_term();
auto map_instance = map_translate_singletone::instance(pass_entry._display);
auto pass = pass_entry.fork_gui(map_instance.map, "");
//std::cout <<"password: "<< std::string(pass.data(), pass.size()) << std::endl;
std::string str = "blank";
keychain_app::byte_seq_t pass(str.begin(), str.end());
return pass;
}
}

1 change: 0 additions & 1 deletion keychain_cmd_app/sec_mod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#define KEYCHAINAPP_SEC_MOD_HPP

#include <keychain_lib/keychain_wrapper.hpp>
#include <pass_entry_term.hpp>

namespace keychain_app
{
Expand Down
40 changes: 40 additions & 0 deletions keychain_cmd_app/sec_mod_linux.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Created by user on 18.10.18.
//

#include "sec_mod_linux.hpp"

using namespace keychain_app;

#include <pass_entry_term.hpp>

sec_mod_linux::sec_mod_linux()
{}

sec_mod_linux::~sec_mod_linux()
{}

std::string sec_mod_linux::get_uid() const
{
return std::string("uid");
}

void sec_mod_linux::print_mnemonic(const string_list& mnemonic) const
{
}

byte_seq_t sec_mod_linux::get_passwd_trx_raw(const std::string& raw_trx) const
{
auto pass_entry = pass_entry_term();
auto map_instance = map_translate_singletone::instance(pass_entry._display);
auto pass = pass_entry.fork_gui(map_instance.map, raw_trx);
return pass;
}

byte_seq_t sec_mod_linux::get_passwd_on_create() const
{
auto pass_entry = pass_entry_term();
auto map_instance = map_translate_singletone::instance(pass_entry._display);
auto pass = pass_entry.fork_gui(map_instance.map, "");
return pass;
}
25 changes: 25 additions & 0 deletions keychain_cmd_app/sec_mod_linux.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

#ifndef KEYCHAINAPP_SEC_MOD_LINUX_HPP
#define KEYCHAINAPP_SEC_MOD_LINUX_HPP

#include <keychain_lib/keychain_wrapper.hpp>

namespace keychain_app
{

class sec_mod_linux: public secure_dlg_mod_base
{
public:
sec_mod_linux();
virtual ~sec_mod_linux();
virtual keychain_app::byte_seq_t get_passwd_trx_raw(const std::string& raw_trx) const override;
virtual keychain_app::byte_seq_t get_passwd_on_create() const override;
virtual void print_mnemonic(const string_list& mnemonic) const override;
virtual std::string get_uid() const override;
private:
static constexpr const char* pass_str = "blank_password";
};

}

#endif //KEYCHAINAPP_SEC_MOD_LINUX_HPP
8 changes: 4 additions & 4 deletions keychain_linux/passentry_gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ add_executable(passentry_gui ${GUI_SOURCES} ${GUI_INCLUDE})
# Use the Widgets module from Qt 5
target_link_libraries(passentry_gui Qt5::Widgets fc_light ${LIB_PTHREAD} ${LIB_OPENSSL} ${Boost_LIBRARIES} )

if( NOT MSVC )
set(GUI_BINARY ${CMAKE_BINARY_DIR}/keychain_linux/passentry_gui/passentry_gui)
set(KEYCHAIN_BINARY_DIR ${CMAKE_BINARY_DIR}/keychain_cmd_app)

set(GUI_BINARY ${CMAKE_BINARY_DIR}/keychain_linux/passentry_gui/passentry_gui)
set(KEYCHAIN_BINARY_DIR ${CMAKE_BINARY_DIR}/keychain_cmd_app)
ADD_CUSTOM_COMMAND(TARGET passentry_gui
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${GUI_BINARY} ${KEYCHAIN_BINARY_DIR}
)
endif (NOT MSVC )

4 changes: 3 additions & 1 deletion libraries/ethereum/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ ENDIF()
find_package(OpenSSL REQUIRED)

FIND_PACKAGE(Boost 1.65 REQUIRED COMPONENTS ${BOOST_COMPONENTS})
include_directories (../secp256k1_ext/include)
include_directories(${Boost_INCLUDE_DIR})


add_library( ether ${ETHER_SOURCES} ${ETHER_HEADERS} )

target_link_libraries( ether fc_light secp256k1_btc ${OPENSSL_LIBRARIES} ${CMAKE_USE_PTHREADS_INIT} dl)

target_include_directories( ether
PUBLIC "${CMAKE_SOURCE_DIR}/libraries/ethereum/include"
PUBLIC "${CMAKE_SOURCE_DIR}/libraries/secp256k1/include"
PUBLIC "${CMAKE_SOURCE_DIR}/libraries/secp256k1_ext/include"
PUBLIC "${CMAKE_SOURCE_DIR}/libraries/fc_light/include"
PRIVATE "${OPENSSL_ROOT_DIR}/include"
)

0 comments on commit 3ffc85e

Please sign in to comment.