Exemple #1
0
int main(int argc, char *argv[])
{
    auto desc = create_descriptions();
    auto vm = parse_options(argc, argv, desc);
    if(vm.count("help"))
    {
        std::cout << desc << std::endl;
        return 1;
    }

    Botan::LibraryInitializer init;

    QApplication a{argc, argv};

    fg::main_window_context c;
        
    c.home = vm["home"].as<std::string>();
    c.host = vm["host"].as<std::string>();
    c.port = vm["port"].as<std::string>();
    c.debug = vm.count("debug");

    CREATE_LOG(c.home);

    c.user = fg::setup_user(c.home);
    if(!c.user) return 0;

    fg::main_window w{c};

    w.show();

    return a.exec();
}
Exemple #2
0
int main(int argc, char *argv[])
try
{
    auto desc = create_descriptions();
    auto vm = parse_options(argc, argv, desc);
    if(vm.count("help"))
    {
        std::cout << desc << std::endl;
        return 1;
    }

    fu::setup_env();
    fu::set_assert_dialog_callback(assert_dialog);

    QApplication a{argc, argv};

    fg::main_window_context c;
    c.home = vm["home"].as<std::string>();
    c.host = vm["host"].as<std::string>();
    c.port = get_port(c.home, vm["port"].as<int>());
    c.debug = vm.count("debug");

    CREATE_LOG(c.home);

    fg::setup_gui();

    c.user = fg::setup_user(c.home);
    if(!c.user) return 0;

    fg::main_window w{c};
    w.show();

    auto rc = a.exec();
    LOG << "firestr shutting down..." << std::endl;
    return rc;
}
catch(std::exception& e)
{
    LOG << "program quit prematurely: " << e.what() << std::endl;
    return 1;
}
catch(...)
{
    LOG << "program quit prematurely: unknown reason" << std::endl;
    return 1;
}
Exemple #3
0
int main(int argc, char *argv[])
{
    CREATE_LOG("./");

    auto desc = create_descriptions();
    auto vm = parse_options(argc, argv, desc);
    if(vm.count("help"))
    {
        std::cout << desc << std::endl;
        return 1;
    }

    Botan::LibraryInitializer init;

    auto host = vm["host"].as<std::string>();
    auto port = vm["port"].as<int>();
    auto pass = vm.count("pass") ? vm["pass"].as<std::string>() : prompt_pass();
    auto key = vm["key"].as<std::string>();

    auto pkey = load_private_key(key, pass);
    CHECK(pkey);

    n::connection_manager con{POOL_SIZE, static_cast<n::port_type>(port)};
    sc::encrypted_channels sec{*pkey};
    user_info_map users;

    u::bytes data;
    while(true)
    try
    {
        n::endpoint ep;
        if(!con.receive(ep, data))
        {
            u::sleep_thread(THREAD_SLEEP);
            continue;
        }

        //decrypt message
        auto sid = n::make_address_str(ep);
        sc::encryption_type et;
        data = sec.decrypt(sid, data, et);
        data = u::uncompress(data);

        //parse message
        m::message m;
        u::decode(data, m);

        if(m.meta.type == ms::GREET_REGISTER)
        {
            if(et != sc::encryption_type::asymmetric) continue;

            ms::greet_register r{m};
            register_user(con, sec, ep, r, users);
        }
        else if(m.meta.type == ms::GREET_FIND_REQUEST)
        {
            if(et != sc::encryption_type::asymmetric) continue;

            ms::greet_find_request r{m};
            find_user(con, sec,  ep, r, users);
        }
        else if(m.meta.type == ms::GREET_KEY_REQUEST)
        {
            ms::greet_key_request r{m};
            send_pub_key(con, sec, ep, r, users, *pkey);
        }
    }
    catch(std::exception& e)
    {
        LOG << "error parsing message: " << e.what() << std::endl;
    }
    catch(...)
    {
        LOG << "unknown error parsing message: " << std::endl;
    }
}
Exemple #4
0
int main(int argc, char *argv[])
{
    CREATE_LOG("./");

    auto desc = create_descriptions();
    auto vm = parse_options(argc, argv, desc);
    if(vm.count("help"))
    {
        std::cout << desc << std::endl;
        return 1;
    }

    Botan::LibraryInitializer init;

    auto host = vm["host"].as<std::string>();
    auto port = vm["port"].as<std::string>();
    auto pass = vm.count("pass") ? vm["pass"].as<std::string>() : prompt_pass();

    auto key = vm["key"].as<std::string>();

    auto pkey = load_private_key(key, pass);
    CHECK(pkey);


    //it is important the tcp_connection manager is created before
    //the input tcp_connection is made. This is because tcp on
    //linux requires that binds to the same port are made before
    //a listen is made.
    n::connection_manager con{POOL_SIZE, port};
    sc::session_library sec{*pkey};
    user_info_map users;

    u::bytes data;
    while(true)
    try
    {
        n::endpoint ep;
        if(!con.receive(ep, data))
        {
            u::sleep_thread(THREAD_SLEEP);
            continue;
        }

        //decrypt message
        auto sid = n::make_address_str(ep);
        data = sec.decrypt(sid, data);

        //parse message
        m::message m;
        u::decode(data, m);

        if(m.meta.type == ms::GREET_REGISTER)
        {
            ms::greet_register r{m};
            register_user(con, sec, ep, r, users);
        }
        else if(m.meta.type == ms::GREET_FIND_REQUEST)
        {
            ms::greet_find_request r{m};
            find_user(con, sec,  ep, r, users);
        }
        else if(m.meta.type == ms::GREET_KEY_REQUEST)
        {
            ms::greet_key_request r{m};
            send_pub_key(con, sec, ep, r, users, *pkey);
        }
    }
    catch(std::exception& e)
    {
        LOG << "error parsing message: " << e.what() << std::endl;
        LOG << "message: " << u::to_str(data) << std::endl;
    }
    catch(...)
    {
        LOG << "unknown error parsing message: " << std::endl;
        LOG << "message: " << u::to_str(data) << std::endl;
    }
}