Skip to content

Commit

Permalink
Merge pull request #1089 from loki-project/dev
Browse files Browse the repository at this point in the history
Merge Valiant Vidar 7.1.1 to master
  • Loading branch information
Doy-lee authored Mar 18, 2020
2 parents 77ae6e9 + adc647e commit 242ea17
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 27 deletions.
4 changes: 2 additions & 2 deletions contrib/depends/packages/sqlite3.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ $(package)_file_name=sqlite-autoconf-$($(package)_version).tar.gz
$(package)_sha256_hash=62284efebc05a76f909c580ffa5c008a7d22a1287285d68b7825a2b6b51949ae

define $(package)_set_vars
$(package)_cflags=-Wformat -Wformat-security -fstack-protector -fstack-protector-strong
$(package)_cxxflags=-std=C++11 -Wformat -Wformat-security -fstack-protector -fstack-protector-strong
$(package)_cflags=-Wformat -Wformat-security -fstack-protector -fstack-protector-strong -fPIC
$(package)_cxxflags=-std=C++11 -Wformat -Wformat-security -fstack-protector -fstack-protector-strong -fPIC
$(package)_config_opts=--prefix=$(host_prefix) --disable-shared
$(package)_ldflags=-pie
endef
Expand Down
13 changes: 1 addition & 12 deletions src/rpc/core_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3390,18 +3390,7 @@ namespace cryptonote
if (exceeds_quantity_limit(ctx, error_resp, m_restricted, request.types.size(), COMMAND_RPC_LNS_NAMES_TO_OWNERS::MAX_TYPE_REQUEST_ENTRIES, "types"))
return false;

std::string name = tools::lowercase_ascii_string(request.name);
for (uint16_t type16 : request.types)
{
if (!lns::validate_lns_name(static_cast<lns::mapping_type>(type16), name, &error_resp.message))
{
error_resp.code = CORE_RPC_ERROR_CODE_WRONG_PARAM;
return false;
}
}

std::string name_hash = lns::name_to_base64_hash(name);
std::vector<lns::mapping_record> records = db.get_mappings(request.types, name_hash);
std::vector<lns::mapping_record> records = db.get_mappings(request.types, request.name_hash);
for (auto const &record : records)
{
res.entries.emplace_back();
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/core_rpc_server_commands_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -3471,10 +3471,10 @@ constexpr char const CORE_RPC_STATUS_TX_LONG_POLL_MAX_CONNECTIONS[] = "Daemon ma
static size_t const MAX_TYPE_REQUEST_ENTRIES = 8;
struct request_entry
{
std::string name; // The name to resolve to a public key via Loki Name Service
std::string name_hash; // The name hashed using libsodium's crypto_generichash_blake2b in base64 to resolve to a public key via Loki Name Service
std::vector<uint16_t> types; // If empty, query all types. Currently only Session(0). In future updates more mapping types will be available.
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(name)
KV_SERIALIZE(name_hash)
KV_SERIALIZE(types)
END_KV_SERIALIZE_MAP()
};
Expand Down
23 changes: 19 additions & 4 deletions src/simplewallet/simplewallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
#include "int-util.h"
#include "wallet/message_store.h"
#include "wallet/wallet_rpc_server_commands_defs.h"
#include "string_coding.h"

#ifdef WIN32
#include <boost/locale.hpp>
Expand Down Expand Up @@ -6570,8 +6571,9 @@ bool simple_wallet::lns_print_name_to_owners(const std::vector<std::string>& arg
return true;
}

std::string const &name = tools::lowercase_ascii_string(args[name_index]);
cryptonote::COMMAND_RPC_LNS_NAMES_TO_OWNERS::request request = {};
request.entries.push_back({args[name_index], std::move(requested_types)});
request.entries.push_back({lns::name_to_base64_hash(name), std::move(requested_types)});

cryptonote::COMMAND_RPC_LNS_NAMES_TO_OWNERS::request_entry &entry = request.entries.back();
if (entry.types.empty()) entry.types.push_back(static_cast<uint16_t>(lns::mapping_type::session));
Expand All @@ -6586,12 +6588,24 @@ bool simple_wallet::lns_print_name_to_owners(const std::vector<std::string>& arg

for (auto const &mapping : response)
{
tools::msg_writer() << "name_hash=" << mapping.name_hash
lns::mapping_value encrypted_value = {};
encrypted_value.len = mapping.encrypted_value.size() / 2;
lokimq::from_hex(mapping.encrypted_value.begin(), mapping.encrypted_value.end(), encrypted_value.buffer.begin());

lns::mapping_value value = {};
if (!lns::decrypt_mapping_value(name, encrypted_value, value))
{
fail_msg_writer() << "Failed to decrypt the mapping value=" << mapping.encrypted_value;
return false;
}

tools::msg_writer() << "name_hash=" << request.entries[0].name_hash // NOTE: We only query one name at a time
<< ", type=" << static_cast<lns::mapping_type>(mapping.type)
<< ", owner=" << mapping.owner
<< ", backup_owner=" << (mapping.backup_owner.empty() ? NULL_STR : mapping.backup_owner)
<< ", height=" << mapping.register_height
<< ", encrypted_value=" << mapping.encrypted_value
<< ", value=" << epee::to_hex::string(value.to_span())
<< ", prev_txid=" << (mapping.prev_txid.empty() ? NULL_STR : mapping.prev_txid);
}

Expand All @@ -6616,9 +6630,10 @@ bool simple_wallet::lns_print_owners_to_names(const std::vector<std::string>& ar
{
for (std::string const &arg : args)
{
if (arg.size() != sizeof(crypto::ed25519_public_key) * 2)
size_t constexpr MAX_LEN = 128;
if (arg.size() >= MAX_LEN)
{
fail_msg_writer() << "arg is not a 64 character ed25519 public key, arg = " << arg;
fail_msg_writer() << "arg too long, fails basic size sanity check max length = " << MAX_LEN << ", arg = " << arg;
return false;
}
if (!lokimq::is_hex(arg))
Expand Down
2 changes: 1 addition & 1 deletion src/version.cpp.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#define DEF_LOKI_VERSION_MAJOR 7
#define DEF_LOKI_VERSION_MINOR 1
#define DEF_LOKI_VERSION_PATCH 0
#define DEF_LOKI_VERSION_PATCH 1

#define LOKI_STRINGIFY2(val) #val
#define LOKI_STRINGIFY(val) LOKI_STRINGIFY2(val)
Expand Down
13 changes: 7 additions & 6 deletions src/wallet/wallet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ using namespace epee;
#include "common/loki.h"
#include "common/loki_integration_test_hooks.h"
#include "loki_economy.h"
#include "string_coding.h"

extern "C"
{
Expand Down Expand Up @@ -8430,12 +8431,12 @@ struct lns_prepared_args
{
bool prepared;
operator bool() const { return prepared; }
lns::mapping_value encrypted_value;
crypto::hash name_hash;
lns::generic_owner owner;
lns::generic_owner backup_owner;
lns::mapping_value encrypted_value;
crypto::hash name_hash;
lns::generic_owner owner;
lns::generic_owner backup_owner;
lns::generic_signature signature;
crypto::hash prev_txid;
crypto::hash prev_txid;
};

static lns_prepared_args prepare_tx_extra_loki_name_system_values(wallet2 const &wallet,
Expand Down Expand Up @@ -8485,7 +8486,7 @@ static lns_prepared_args prepare_tx_extra_loki_name_system_values(wallet2 const
{
request.entries.emplace_back();
auto &request_entry = request.entries.back();
request_entry.name = name;
request_entry.name_hash = epee::string_encoding::base64_encode(reinterpret_cast<unsigned char const *>(result.name_hash.data), sizeof(result.name_hash));
request_entry.types.push_back(static_cast<uint16_t>(type));
}

Expand Down

0 comments on commit 242ea17

Please sign in to comment.