Skip to content

Commit

Permalink
Merge branch 'macos-installer'
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-modelist-dev committed Nov 21, 2018
2 parents 6439672 + 1dcc8ed commit d81469a
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@
*.orig
*cpk
.idea/*
.DS_Store

18 changes: 18 additions & 0 deletions keychain_cmd_app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ if (NOT MSVC)
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++" )
endif()
endif()
if(APPLE)
SET(CMAKE_EXE_LINKER_FLAGS "-framework Cocoa")
endif()

SET(BOOST_COMPONENTS)
LIST(APPEND BOOST_COMPONENTS log date_time system filesystem program_options signals serialization chrono unit_test_framework locale thread exception iostreams)
Expand Down Expand Up @@ -82,10 +85,25 @@ else()

file(GLOB KEYCHAIN_SOURCES "./*.cpp" )
file(GLOB KEYCHAIN_INCLUDE "./*.hpp" )
if(APPLE)
file(GLOB KEYCHAIN_INCLUDE "./*.h*" "../keychain_mac/*.h*" )
file(GLOB KEYCHAIN_SOURCES ("./*.m*" "./*.cpp" "../keychain_mac/*.m*" "../keychain_mac/*.cpp" ) )
endif()
add_executable(keychain ${KEYCHAIN_SOURCES} ${KEYCHAIN_INCLUDE} )

if (MSVC)
target_link_libraries(keychain keychain_common fc_light eth-crypto ${LIB_OPENSSL} ${Boost_LIBRARIES} Userenv.lib)
else()
target_link_libraries(keychain keychain_common fc_light eth-crypto ${LIB_OPENSSL} ${Boost_LIBRARIES})
if(APPLE)
set_property (TARGET keychain APPEND_STRING PROPERTY
COMPILE_FLAGS "-fobjc-arc")
set_target_properties(
${APP_NAME}
PROPERTIES
MACOSX_BUNDLE YES
XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES
)
endif()
endif()
endif()
8 changes: 6 additions & 2 deletions keychain_cmd_app/cmd_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include "sec_mod_linux.hpp"
#endif

#ifdef APPLE
#include "../keychain_mac/sec_mod_mac.hpp"
#endif
using namespace keychain_app;


Expand All @@ -47,6 +50,7 @@ int cmd_parser::run(int argc, const char* const argv [])
try
{
po::parsed_options parsed = po::command_line_parser(argc, argv).options(desc).allow_unregistered().run();

po::store(parsed, options);
po::notify(options);

Expand All @@ -67,8 +71,8 @@ int cmd_parser::run(int argc, const char* const argv [])
BOOST_LOG_SEV(log.lg, info) << "secure_module: <sec_mod_linux>";
sec_mod = secure_module<sec_mod_linux>::instance();
#else
BOOST_LOG_SEV(log.lg, info) << "secure_module: <sec_mod_dummy>";
sec_mod = secure_module<sec_mod_dummy>::instance();
BOOST_LOG_SEV(log.lg, info) << "secure_module: <sec_mod_mac>";
sec_mod = secure_module<sec_mod_mac>::instance();
#endif
}
else
Expand Down
9 changes: 8 additions & 1 deletion keychain_lib/include/keychain_lib/keychain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@
#define KEY_DEFAULT_PATH "/var/keychain/key_data"
#define LOG_DEFAULT_PATH "/var/keychain/logs"
#else
#error "Need to define path to KEYCHAIN_DATA"

#if defined(macintosh) || defined(__APPLE__) || defined(__APPLE_CC__)
//#error "Need to define path to KEYCHAIN_DATA"
#define KEY_DEFAULT_PATH "data/keychain/key_data"
#define LOG_DEFAULT_PATH "data/keychain/logs"
#else
#error "Need to define path to KEYCHAIN_DATA"
#endif
#endif


Expand Down
17 changes: 17 additions & 0 deletions keychain_mac/MyDialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// MyDialog.h
// keychain
//
// Created by Mikhail Lutskiy on 29/10/2018.
//

#import <Cocoa/Cocoa.h>

NS_ASSUME_NONNULL_BEGIN

@interface MyDialog : NSWindowController
- (instancetype)initWithFrame:(NSRect)frame;
- (void)runModal;
@end

NS_ASSUME_NONNULL_END
63 changes: 63 additions & 0 deletions keychain_mac/MyDialog.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// MyDialog.m
// keychain
//
// Created by Mikhail Lutskiy on 29/10/2018.
//

#import "MyDialog.h"
#import "PassSyncStore.h"

@interface MyDialog () {
NSSecureTextField *pass;
}

@end

@implementation MyDialog

- (instancetype)initWithFrame:(NSRect)frame {
NSWindowStyleMask windowMask = NSWindowStyleMaskTitled
| NSWindowStyleMaskClosable;
NSWindow *window = [[NSWindow alloc] initWithContentRect:frame
styleMask:windowMask
backing:NSBackingStoreBuffered
defer:NO];
[window setTitle:@"Keychain"];
[window makeKeyAndOrderFront:self];
[window orderFront:self];

[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(windowWillClose:)
name:NSWindowWillCloseNotification
object:nil];

return [super initWithWindow:window];
}

- (void) clickButton {
[[PassSyncStore sharedInstance] setPass:pass.stringValue];
[self.window close];
}

- (void)dealloc {
[NSNotificationCenter.defaultCenter removeObserver:self];
}

- (void)runModal {
pass = [[NSSecureTextField alloc] initWithFrame:CGRectMake(50, 100, 100, 25)];
pass.placeholderString = @"Password";
[self.window.contentView addSubview:pass];
NSButton *button = [NSButton buttonWithTitle:@"Sign" target:self action:@selector(clickButton)];
[self.window.contentView addSubview:button];
[[NSApplication sharedApplication] runModalForWindow:self.window];
}

- (void)windowWillClose:(NSNotification *)notification {
[NSApp setActivationPolicy:NSApplicationActivationPolicyProhibited];
dispatch_async(dispatch_get_main_queue(), ^{
[NSApp stopModal];
});
}

@end
19 changes: 19 additions & 0 deletions keychain_mac/PassSyncStore.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// PassSyncStore.h
// keychain
//
// Created by Mikhail Lutskiy on 31/10/2018.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface PassSyncStore : NSObject

@property (atomic, strong) NSString *pass;

+ (instancetype)sharedInstance;
@end

NS_ASSUME_NONNULL_END
22 changes: 22 additions & 0 deletions keychain_mac/PassSyncStore.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// PassSyncStore.m
// keychain
//
// Created by Mikhail Lutskiy on 31/10/2018.
//

#import "PassSyncStore.h"

@implementation PassSyncStore

+ (instancetype)sharedInstance
{
static PassSyncStore *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[PassSyncStore alloc] init];
});
return sharedInstance;
}

@end
31 changes: 31 additions & 0 deletions keychain_mac/sec_mod_mac.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// sec_mod_mac.hpp
// keychain
//
// Created by Mikhail Lutskiy on 29/10/2018.
//
//#ifdef __OBJC__
//#ifndef sec_mod_mac_hpp
//#define sec_mod_mac_hpp

#include <keychain_lib/keychain_wrapper.hpp>

namespace keychain_app
{

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

}

//#endif //KEYCHAINAPP_SEC_MOD_LINUX_HPP
//#endif
54 changes: 54 additions & 0 deletions keychain_mac/sec_mod_mac.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// sec_mod_mac.cpp
// keychain
//
// Created by Mikhail Lutskiy on 29/10/2018.
//

#include "sec_mod_mac.hpp"
#import <Foundation/Foundation.h>
#import "MyDialog.h"
#import "PassSyncStore.h"

using namespace keychain_app;

sec_mod_mac::sec_mod_mac()
{}

sec_mod_mac::~sec_mod_mac()
{}


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

byte_seq_t sec_mod_mac::get_passwd_trx_raw(const std::string& raw_trx, std::string binary_dir) const
{
[NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
[NSApp activateIgnoringOtherApps:YES];

NSRect frame = NSMakeRect(0, 0, 200, 200);
MyDialog *dialog = [[MyDialog alloc] initWithFrame:frame];
[dialog runModal];
std::string str = std::string([[[PassSyncStore sharedInstance] pass] UTF8String]);
[[PassSyncStore sharedInstance] setPass:@""];
keychain_app::byte_seq_t pass(str.begin(), str.end());
return pass;
}

byte_seq_t sec_mod_mac::get_passwd_on_create(std::string binary_dir) const
{
[NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
[NSApp activateIgnoringOtherApps:YES];

NSRect frame = NSMakeRect(0, 0, 200, 200);
MyDialog *dialog = [[MyDialog alloc] initWithFrame:frame];
[dialog runModal];
std::string str = std::string([[[PassSyncStore sharedInstance] pass] UTF8String]);
[[PassSyncStore sharedInstance] setPass:@""];
keychain_app::byte_seq_t pass(str.begin(), str.end());
return pass;
}

0 comments on commit d81469a

Please sign in to comment.