1
0
Fork 0
forked from lthn/blockchain

auth basic r and d

This commit is contained in:
cryptozoidberg 2024-03-13 13:16:36 +01:00
parent 4ea976b887
commit 21c1631825
No known key found for this signature in database
GPG key ID: 2E10CC61CAC8F36D
8 changed files with 78 additions and 10 deletions

View file

@ -1,4 +1,4 @@
// Copyright (c) 2019, anonimal, <anonimal@zano.org>
// Copyright (c) 2019, anonimal, <anonimal@zano.org>
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
// All rights reserved.
//

View file

@ -171,6 +171,11 @@ namespace currency
return true;
}
if(hshd.top_id == currency::null_hash)
{
LOG_PRINT_L0("wtf");
}
int64_t diff = static_cast<int64_t>(hshd.current_height) - static_cast<int64_t>(m_core.get_current_blockchain_size());
LOG_PRINT_COLOR2(LOG_DEFAULT_TARGET, (is_inital ? "Inital ":"Idle ") << "sync data returned unknown top block (" << hshd.top_id << "): " << m_core.get_top_block_height() << " -> " << hshd.current_height - 1
<< " [" << std::abs(diff) << " blocks (" << diff / (24 * 60 * 60 / DIFFICULTY_TOTAL_TARGET ) << " days) "

@ -1 +1 @@
Subproject commit e4a76ad1329244ec4fb9ec7825361518e95d1933
Subproject commit f8e9556fbaccd49841ce91afc3c90c8e3142ac95

View file

@ -17,6 +17,7 @@ using namespace epee;
#include "wallet_rpc_server_error_codes.h"
#include "wallet_helpers.h"
#include "wrap_service.h"
#include <jwt-cpp/jwt.h>
#define GET_WALLET() wallet_rpc_locker w(m_pwallet_provider);
@ -184,11 +185,43 @@ namespace tools
m_net_server.set_threads_prefix("RPC");
bool r = handle_command_line(vm);
CHECK_AND_ASSERT_MES(r, false, "Failed to process command line in core_rpc_server");
m_jwt_secrete = "secretesecrete";
return epee::http_server_impl_base<wallet_rpc_server, connection_context>::init(m_port, m_bind_ip);
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::auth_http_request(const epee::net_utils::http::http_request_info& query_info, epee::net_utils::http::http_response_info& response, connection_context& m_conn_context)
{
auto it = std::find_if(query_info.m_header_info.m_etc_fields.begin(), query_info.m_header_info.m_etc_fields.end(), [](const auto& element)
{ return element.first == ZANO_ACCESS_TOKEN; });
if(it == query_info.m_header_info.m_etc_fields.end())
return false;
std::string token = it->second; //"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCIsInNhbXBsZSI6InRlc3QifQ.lQm3N2bVlqt2-1L-FsOjtR6uE-L4E9zJutMWKIe1v1M";
auto decoded_token = jwt::decode(token);
auto verifier = jwt::verify()
.with_issuer("auth0")
.with_claim("sample", jwt::claim(std::string("test")))
.allow_algorithm(jwt::algorithm::hs256 { m_jwt_secrete });
verifier.verify(decoded_token);
return false;
}
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::handle_http_request(const epee::net_utils::http::http_request_info& query_info, epee::net_utils::http::http_response_info& response, connection_context& m_conn_context)
{
if (m_jwt_secrete.size())
{
if (!auth_http_request(query_info, response, m_conn_context))
{
response.m_response_code = 401;
response.m_response_comment = "Unauthorized";
return true;
}
}
response.m_response_code = 200;
response.m_response_comment = "Ok";
std::string reference_stub;

View file

@ -12,11 +12,11 @@
#include "wallet_public_structs_defs.h"
#include "wallet2.h"
#include "common/command_line.h"
#define ZANO_ACCESS_TOKEN "Zano-Access-Token"
namespace tools
{
struct i_wallet_provider
{
virtual void lock() {};
@ -143,8 +143,9 @@ namespace tools
MAP_JON_RPC_WE("encrypt_data", on_encrypt_data, wallet_public::COMMAND_ENCRYPT_DATA)
MAP_JON_RPC_WE("decrypt_data", on_decrypt_data, wallet_public::COMMAND_DECRYPT_DATA)
END_JSON_RPC_MAP()
END_URI_MAP2()
END_URI_MAP2()
bool auth_http_request(const epee::net_utils::http::http_request_info& query_info, epee::net_utils::http::http_response_info& response, connection_context& m_conn_context);
//json_rpc
bool on_getbalance(const wallet_public::COMMAND_RPC_GET_BALANCE::request& req, wallet_public::COMMAND_RPC_GET_BALANCE::response& res, epee::json_rpc::error& er, connection_context& cntx);
bool on_getaddress(const wallet_public::COMMAND_RPC_GET_ADDRESS::request& req, wallet_public::COMMAND_RPC_GET_ADDRESS::response& res, epee::json_rpc::error& er, connection_context& cntx);
@ -212,6 +213,8 @@ namespace tools
bool m_do_mint;
bool m_deaf;
uint64_t m_last_wallet_store_height;
std::string m_jwt_secrete;
};
} // namespace tools

View file

@ -29,11 +29,11 @@ add_executable(net_load_tests_srv net_load_tests/srv.cpp)
add_dependencies(coretests version)
target_link_libraries(coretests rpc wallet currency_core common crypto zlibstatic ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} OpenSSL::SSL OpenSSL::Crypto)
target_link_libraries(functional_tests rpc wallet currency_core crypto common zlibstatic ethash libminiupnpc-static ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
target_link_libraries(functional_tests rpc wallet currency_core crypto common zlibstatic ethash libminiupnpc-static ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} OpenSSL::SSL OpenSSL::Crypto)
target_link_libraries(hash-tests crypto ethash)
target_link_libraries(hash-target-tests crypto currency_core ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
target_link_libraries(performance_tests rpc wallet currency_core common crypto zlibstatic ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
target_link_libraries(unit_tests wallet currency_core common crypto gtest_main zlibstatic ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
target_link_libraries(performance_tests rpc wallet currency_core common crypto zlibstatic ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} OpenSSL::SSL OpenSSL::Crypto)
target_link_libraries(unit_tests wallet currency_core common crypto gtest_main zlibstatic ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} OpenSSL::SSL OpenSSL::Crypto)
target_link_libraries(net_load_tests_clt currency_core common crypto gtest_main ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
target_link_libraries(net_load_tests_srv currency_core common crypto gtest_main ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})

View file

@ -26,9 +26,35 @@
#include "threads_pool_tests.h"
#include "wallet/plain_wallet_api.h"
#include "wallet/view_iface.h"
#include <jwt-cpp/jwt.h>
void test_plain_wallet()
{
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCIsInNhbXBsZSI6InRlc3QifQ.lQm3N2bVlqt2-1L-FsOjtR6uE-L4E9zJutMWKIe1v1M";
auto decoded_token = jwt::decode(token);
auto verifier = jwt::verify()
.with_issuer("auth0")
.with_claim("sample", jwt::claim(std::string("test")))
.allow_algorithm(jwt::algorithm::hs256 { "secret" });
verifier.verify(decoded_token);
auto token = jwt::create()
.set_type("JWS")
.set_issuer("auth0")
.set_payload_claim("sample", jwt::claim(std::string("test")))
.sign(jwt::algorithm::hs256 { "secret" });
return;
std::string res = plain_wallet::init("195.201.107.230", "33336", "E:\\tmp\\", 0);
uint64_t instance_id = 0;

View file

@ -18,7 +18,8 @@ public:
m_bob.generate();
uint64_t block_reward_without_fee = 0;
if (!construct_miner_tx(0, 0, 0, 2, 0, m_bob.get_keys().account_address, m_bob.get_keys().account_address, m_tx, block_reward_without_fee, TRANSACTION_VERSION_PRE_HF4, blobdata(), CURRENCY_MINER_TX_MAX_OUTS))
uint64_t block_reward = 0;
if(!construct_miner_tx(0, 0, 0, 2, 0, m_bob.get_keys().account_address, m_bob.get_keys().account_address, m_tx, block_reward_without_fee, block_reward, TRANSACTION_VERSION_PRE_HF4, blobdata(), CURRENCY_MINER_TX_MAX_OUTS))
return false;
m_tx_pub_key = get_tx_pub_key_from_extra(m_tx);