Skip to content

Commit

Permalink
#89=merge cracklib
Browse files Browse the repository at this point in the history
  • Loading branch information
sinev-valentine committed Feb 7, 2019
2 parents bb1b5b6 + 5054a6b commit becec60
Show file tree
Hide file tree
Showing 19 changed files with 2,719 additions and 132 deletions.
14 changes: 8 additions & 6 deletions keychain_cmd_app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ if( NOT MSVC )
else()
find_library(LIB_OPENSSL NAME libcrypto.lib HINTS "${OPENSSL_ROOT_DIR}/lib")
endif( NOT MSVC )


if ( ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
include_directories(
find_library(LIB_CR NAMES crack HINTS "../keychain_linux")

include_directories(
"../keychain_lib/include"
"../keychain_linux/passentry_cmd"
"../libraries/fc_light/include"
Expand All @@ -52,7 +52,9 @@ if ( ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
"${CMAKE_SOURCE_DIR}/libraries/kaitai_struct_cpp_stl_runtime"
"${OPENSSL_ROOT_DIR}/include"
"/usr/include/libcxxabi"
${Boost_INCLUDE_DIR})
${Boost_INCLUDE_DIR}
"../libraries/cracklib")


file(GLOB KEYCHAIN_SOURCES "./*.cpp" "../keychain_linux/passentry_cmd/*.cpp" )
file(GLOB KEYCHAIN_INCLUDE "./*.hpp" "../keychain_linux/passentry_cmd/*.hpp" )
Expand All @@ -66,8 +68,8 @@ if ( ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
endif()
find_library(LIB_XI NAME Xi HINTS "/usr/lib/x86_64-linux-gnu/")
add_executable(keychain ${KEYCHAIN_SOURCES} ${KEYCHAIN_INCLUDE} )
add_dependencies(keychain passentry_gui)
target_link_libraries(keychain keychain_common ${LIB_PTHREAD} fc_light eth-crypto ${LIB_OPENSSL} ${Boost_LIBRARIES} ${X11_LIBRARIES} ${LIB_XI})
add_dependencies(keychain passentry_gui)
target_link_libraries(keychain keychain_common ${LIB_PTHREAD} fc_light eth-crypto ${LIB_OPENSSL} ${Boost_LIBRARIES} ${X11_LIBRARIES} ${LIB_XI} ${LIB_CR})

set(GUI_BINARY ${CMAKE_BINARY_DIR}/keychain_linux/passentry_gui/passentry_gui)
set(KEYCHAIN_BINARY_DIR ${CMAKE_BINARY_DIR}/keychain_cmd_app/passentry_gui)
Expand Down
2 changes: 1 addition & 1 deletion keychain_lib/src/keychain_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace keychain_app {

using swap_trx_t = secmod_commands::transaction_view<secmod_commands::blockchain_secmod_te::ethereum_swap>::type;

bool swap_action(std::string data, swap_trx_t::swap_t &swap_info) {
bool swap_action(std::string data, swap_trx_t::swap_t &swap_info) {
if (data.size() < 8)
return false;

Expand Down
Binary file added keychain_linux/libcrack.a
Binary file not shown.
20 changes: 18 additions & 2 deletions keychain_linux/passentry_cmd/cmd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <boost/hana/for_each.hpp>
#include <boost/hana/size.hpp>
#include "polling.hpp"
#include "../passentry_gui/include/password_strength.h"

namespace slave {
enum struct cmds {unknown = 0, ok, cancel, focus, expert_mode, last}; //from gui
Expand Down Expand Up @@ -112,7 +113,7 @@ namespace slave {
}

namespace master {
enum struct cmds {unknown = 0, rawtrx, close, modify, length, create, unlock, check, focus, close_expert_mode, last};
enum struct cmds {unknown = 0, rawtrx, close, modify, length, create, unlock, check, focus, close_expert_mode, strength, last};

struct cmd_base {
cmd_base(): cmd(cmds::unknown){};
Expand Down Expand Up @@ -215,9 +216,21 @@ namespace master {
cmd():base(){}
struct params_t {params_t():cmd(cmds::close_expert_mode){} cmds cmd;} base;
};

template<>
struct cmd<cmds::strength> : cmd_base{
cmd(strength_te res): cmd_base(), strength_param(res){
cmd_base::cmd = cmds::strength;
params = fc_light::variant(strength_param);
};
struct params_t {
params_t(strength_te res_):res(res_) {}
strength_te res;
} strength_param;
};
}

FC_LIGHT_REFLECT_ENUM(master::cmds, (unknown)(rawtrx)(close)(modify)(length)(unlock)(check)(focus)(close_expert_mode)(last))
FC_LIGHT_REFLECT_ENUM(master::cmds, (unknown)(rawtrx)(close)(modify)(length)(unlock)(check)(focus)(close_expert_mode)(strength)(last))
FC_LIGHT_REFLECT(master::cmd_base, (cmd)(params))
FC_LIGHT_REFLECT(master::cmd<master::cmds::rawtrx>::params_t, (rawtrx))
FC_LIGHT_REFLECT(master::cmd<master::cmds::close>::params_t, (cmd))
Expand All @@ -227,11 +240,14 @@ FC_LIGHT_REFLECT(master::cmd<master::cmds::create>::params_t, (keyname))
FC_LIGHT_REFLECT(master::cmd<master::cmds::unlock>::params_t, (keyname)(unlock_time))
FC_LIGHT_REFLECT(master::cmd<master::cmds::check>::params_t, (res))
FC_LIGHT_REFLECT(master::cmd<master::cmds::focus>::params_t, (line))
FC_LIGHT_REFLECT(master::cmd<master::cmds::strength>::params_t, (res))
FC_LIGHT_REFLECT(master::cmd<master::cmds::close_expert_mode>::params_t, (cmd))

FC_LIGHT_REFLECT_ENUM(slave::cmds, (unknown)(ok)(cancel)(focus)(expert_mode)(last))
FC_LIGHT_REFLECT(slave::cmd_common, (cmd)(params))
FC_LIGHT_REFLECT(slave::cmd<slave::cmds::focus>::params_t, (line_edit))
FC_LIGHT_REFLECT(slave::cmd<slave::cmds::expert_mode>::params_t, (enable))

FC_LIGHT_REFLECT_ENUM(strength_te, (unknown)(weak)(middle)(strong)(last))

#endif //KEYCHAINAPP_CMD_H
123 changes: 74 additions & 49 deletions keychain_linux/passentry_cmd/pass_entry_term.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
#include <sys/types.h>
#include "pass_entry_term.hpp"
#include "cmd.hpp"
#include <crack.h>

#define path_ "./passentry_gui"
#define small "/usr/local/share/cracklib/pw_small"
#define large "/usr/local/share/cracklib/pw_dict"

pass_entry_term::pass_entry_term(bool confirm_) : confirm(confirm_)
{
Expand Down Expand Up @@ -64,7 +67,7 @@ void pass_entry_term::ChangeKbProperty(
}


bool pass_entry_term::OnKey (unsigned short scancode, int shft, int cpslock, int nmlock, std::wstring& pass, const KeySym * map)
bool pass_entry_term::OnKey (unsigned short scancode, int shft, int cpslock, int nmlock, std::string& pass, const KeySym * map)
{
// HACK: manual NumPad processing (It is right only for English keyboard layout)
switch (scancode)
Expand Down Expand Up @@ -96,7 +99,7 @@ bool pass_entry_term::OnKey (unsigned short scancode, int shft, int cpslock, int
case KEY_ENTER: return true;
case KEY_ESC: pass.clear(); return true;;
case KEY_BACKSPACE: if (!pass.empty()) pass.pop_back(); break;
case KEY_DELETE: if (!pass.empty()) pass.pop_back(); break;
case KEY_DELETE: break;
default:{
int code = (scancode)*2 +(cpslock xor shft);
if (code < MAP_SIZE)
Expand Down Expand Up @@ -188,20 +191,19 @@ keychain_app::byte_seq_t pass_entry_term::fork_gui(const KeySym * map, const std
close(sockets[0]);
send_gui(mes , sockets[1]);

std::wstring pass = input_password(map, sockets[1]);
std::string pass = input_password(map, sockets[1]);
close(sockets[1]);
if (wait(NULL) == -1) throw std::runtime_error("waiting gui");

keychain_app::byte_seq_t vec(std::distance(pass.begin(), pass.end()));
std::transform(pass.begin(), pass.end(), vec.begin(), [](auto a){ return ((char) a);});
keychain_app::byte_seq_t vec(pass.begin(), pass.end());

return vec;
};


std::wstring pass_entry_term::input_password(const KeySym * map, int socket)
std::string pass_entry_term::input_password(const KeySym * map, int socket)
{
std::vector<std::wstring> password(2);
std::vector<std::string> password(2);
int line_edit = 0;

std::list<std::string> devices;
Expand All @@ -215,6 +217,7 @@ std::wstring pass_entry_term::input_password(const KeySym * map, int socket)
char name[256] = "Unknown";
bool first_key = true;
auto gui = polling(socket);
std::vector<int> pass_len(2, 0);
ChangeKbProperty(dev_info, kbd_atom, device_enabled_prop, dev_cnt, 0);

capslock = keyState(XK_Caps_Lock);
Expand All @@ -224,21 +227,23 @@ std::wstring pass_entry_term::input_password(const KeySym * map, int socket)
auto mes = fc_light::json::to_string(fc_light::variant(static_cast<const master::cmd_base&>(a)));
send_gui( mes, socket );

FD_ZERO(&readfds);
devices = parse_device_file();
for (auto &sdev : devices)
try
{
id = open(sdev.c_str(), O_RDONLY);
if (id > FD_SETSIZE || id == -1 ) continue;
if (id > nfds) nfds = id + 1;
FD_ZERO(&readfds);
devices = parse_device_file();
for (auto &sdev : devices)
{
id = open(sdev.c_str(), O_RDONLY);
if (id > FD_SETSIZE || id == -1 ) continue;
if (id > nfds) nfds = id + 1;

fd_list.push_back(id);
FD_SET(id, &readfds);
}
fd_list.push_back(id);
FD_SET(id, &readfds);
}

if (!fd_list.size())
throw std::runtime_error("access denied to " PROC_BUS_INPUT_DEVICES);

std::vector<int> pass_len(2, 0);
try
{
while (1)
{
res = select(nfds, &readfds, NULL, NULL, &to); // polling keyboard
Expand Down Expand Up @@ -273,9 +278,13 @@ std::wstring pass_entry_term::input_password(const KeySym * map, int socket)
if ((res = read(kbd_id, ev, size * 64)) < size)
break;
}
if (size % sizeof(input_event) !=0 ) break;
if (size / sizeof(input_event) !=1 ) break;


first_key = false;

if (ev[0].value != ' ' && ev[1].type == EV_KEY )
if (/*ev[0].value != ' ' &&*/ ev[1].type == EV_KEY )
{
if (ev[1].value == 1)
{
Expand All @@ -302,33 +311,23 @@ std::wstring pass_entry_term::input_password(const KeySym * map, int socket)
{
password[0].clear();
password[1].clear();
auto v = master::cmd<master::cmds::close>();
mes = fc_light::json::to_string(fc_light::variant(v.base));
send_gui( mes, socket );
break;
}
else if (confirm && ev[1].code == KEY_ENTER) // create key
{
if (password[0] == password[1])
{
auto v = master::cmd<master::cmds::close>();
mes = fc_light::json::to_string(fc_light::variant(v.base));
send_gui( mes, socket );
break;
}
}
else if (OnKey (ev[1].code, shift, capslock, numlock, password[line_edit], map))
{
auto v = master::cmd<master::cmds::close>();
mes = fc_light::json::to_string(fc_light::variant(v.base));
send_gui( mes, socket );
break;
if (password[0] == password[1]) break;
}
else if (OnKey (ev[1].code, shift, capslock, numlock, password[line_edit], map)) break;
}
else if (ev[1].value == 0)
{
if ( (ev[1].code == KEY_LEFTSHIFT) || (ev[1].code == KEY_RIGHTSHIFT)) shift=0;
}
else if (ev[1].value == 2)
{
if (ev[1].code == KEY_BACKSPACE) OnKey (ev[1].code, shift, capslock, numlock, password[line_edit], map);
}

if ( (capslock | (numlock<<1) | (shift<<2)) != modify )
{
auto a = master::cmd<master::cmds::modify>(capslock, numlock, shift);
Expand All @@ -352,34 +351,52 @@ std::wstring pass_entry_term::input_password(const KeySym * map, int socket)
auto t = master::cmd<master::cmds::check>(password[0] == password[1]);
auto mes = fc_light::json::to_string(fc_light::variant(static_cast<const master::cmd_base&>(t)));
send_gui( mes, socket );

keychain_app::byte_seq_t vec(password[0].begin(), password[0].end());

if (password[0].size())
{
const char * found = nullptr;
found = FascistCheck(password[0].c_str(), large);
if (found )
{
found = FascistCheck(password[0].c_str(), small);
if (found)
{
auto t = master::cmd<master::cmds::strength>(strength_te::weak);
auto mes = fc_light::json::to_string(fc_light::variant(static_cast<const master::cmd_base&>(t)));
send_gui( mes, socket );
}
else
{
auto t = master::cmd<master::cmds::strength>(strength_te::middle);
auto mes = fc_light::json::to_string(fc_light::variant(static_cast<const master::cmd_base&>(t)));
send_gui( mes, socket );
}
}
else{ //strong
auto t = master::cmd<master::cmds::strength>(strength_te::strong);
auto mes = fc_light::json::to_string(fc_light::variant(static_cast<const master::cmd_base&>(t)));
send_gui( mes, socket );
}
}
}
}


gui.Select(); // polling gui

if (gui.CancelButtonPressEvent)
{
gui.CancelButtonPressEvent = false;
password[0].clear();
password[1].clear();

auto v = master::cmd<master::cmds::close>();
mes = fc_light::json::to_string(fc_light::variant(v.base));
send_gui( mes, socket );
break;
}

if (gui.OkButtonPressEvent)
{
gui.OkButtonPressEvent = false;
if (!confirm || (password[0] == password[1]))
{
auto v = master::cmd<master::cmds::close>();
mes = fc_light::json::to_string(fc_light::variant(v.base));
send_gui( mes, socket );
break;
}
if (!confirm || (password[0] == password[1])) break;
}

if (gui.focusEvent)
Expand All @@ -388,11 +405,19 @@ std::wstring pass_entry_term::input_password(const KeySym * map, int socket)
line_edit = gui.line_edit;
}
}
auto v = master::cmd<master::cmds::close>();
mes = fc_light::json::to_string(fc_light::variant(v.base));
send_gui( mes, socket );

if (kbd_id != -1) ioctl(kbd_id, EVIOCGRAB, 0);
for (auto dev : fd_list) close(dev);
}
catch (const std::exception& e)
{
auto v = master::cmd<master::cmds::close>();
mes = fc_light::json::to_string(fc_light::variant(v.base));
send_gui( mes, socket );

if (kbd_id != -1) ioctl(kbd_id, EVIOCGRAB, 0);
for (auto dev : fd_list) close(dev);
password[0].clear();
Expand Down
4 changes: 2 additions & 2 deletions keychain_linux/passentry_cmd/pass_entry_term.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class pass_entry_term
keychain_app::byte_seq_t fork_gui(const KeySym*, const std::string&);
Display* _display = NULL;
private:
std::wstring input_password(const KeySym *, int);
std::string input_password(const KeySym *, int);
void ChangeKbProperty(XDeviceInfo *, Atom, Atom, int, unsigned char);
bool OnKey (unsigned short, int, int, int, std::wstring&, const KeySym *);
bool OnKey (unsigned short, int, int, int, std::string&, const KeySym *);
unsigned int keyState(unsigned int);
std::list<std::string> parse_device_file();
void send_gui (std::string, int);
Expand Down
20 changes: 0 additions & 20 deletions keychain_linux/passentry_gui/include/CheckPasswordStrength.h

This file was deleted.

0 comments on commit becec60

Please sign in to comment.