mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Each node on the network is supposed to have a unique cryptographic identity. Typically, this identity is generated randomly at startup and stored for later reuse in the (poorly named) file `wallet.db`. If the file is copied, it is possible for two nodes to share the same node identity. This is generally not desirable and existing servers will detect and reject connections to other servers that have the same key. This commit achives three things: 1. It improves the detection code to pinpoint instances where two distinct servers with the same key connect with each other. In that case, servers will log an appropriate error and shut down pending intervention by the server's operator. 2. It makes it possible for server administrators to securely and easily generate new cryptographic identities for servers using the new `--newnodeid` command line arguments. When a server is started using this command, it will generate and save a random secure identity. 3. It makes it possible to configure the identity using a command line option, which makes it possible to derive it from data or parameters associated with the container or hardware where the instance is running by passing the `--nodeid` option, followed by a single argument identifying the infomation from which the node's identity is derived. For example, the following command will result in nodes with different hostnames having different node identities: `rippled --nodeid $HOSTNAME` The last option is particularly useful for automated cloud-based deployments that minimize the need for storing state and provide unique deployment identifiers. **Important note for server operators:** Depending on variables outside of the the control of this code, such as operating system version or configuration, permissions, and more, it may be possible for other users or programs to be able to access the command line arguments of other processes on the system. If you are operating in a shared environment, you should avoid using this option, preferring instead to use the `[node_seed]` option in the configuration file, and use permissions to limit exposure of the node seed. A user who gains access to the value used to derive the node's unique identity could impersonate that node. The commit also updates the minimum supported server protocol version to `XRPL/2.1`, which has been supported since version 1.5.0 and eliminates support for `XPRL/2.0`.
141 lines
3.4 KiB
C++
141 lines
3.4 KiB
C++
//------------------------------------------------------------------------------
|
|
/*
|
|
This file is part of rippled: https://github.com/ripple/rippled
|
|
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
//==============================================================================
|
|
|
|
#ifndef RIPPLE_PROTOCOL_SEED_H_INCLUDED
|
|
#define RIPPLE_PROTOCOL_SEED_H_INCLUDED
|
|
|
|
#include <ripple/basics/Slice.h>
|
|
#include <ripple/basics/base_uint.h>
|
|
#include <ripple/protocol/tokens.h>
|
|
#include <array>
|
|
#include <optional>
|
|
|
|
namespace ripple {
|
|
|
|
/** Seeds are used to generate deterministic secret keys. */
|
|
class Seed
|
|
{
|
|
private:
|
|
std::array<uint8_t, 16> buf_;
|
|
|
|
public:
|
|
using const_iterator = std::array<uint8_t, 16>::const_iterator;
|
|
|
|
Seed() = delete;
|
|
|
|
Seed(Seed const&) = default;
|
|
Seed&
|
|
operator=(Seed const&) = default;
|
|
|
|
/** Destroy the seed.
|
|
The buffer will first be securely erased.
|
|
*/
|
|
~Seed();
|
|
|
|
/** Construct a seed */
|
|
/** @{ */
|
|
explicit Seed(Slice const& slice);
|
|
explicit Seed(uint128 const& seed);
|
|
/** @} */
|
|
|
|
std::uint8_t const*
|
|
data() const
|
|
{
|
|
return buf_.data();
|
|
}
|
|
|
|
std::size_t
|
|
size() const
|
|
{
|
|
return buf_.size();
|
|
}
|
|
|
|
const_iterator
|
|
begin() const noexcept
|
|
{
|
|
return buf_.begin();
|
|
}
|
|
|
|
const_iterator
|
|
cbegin() const noexcept
|
|
{
|
|
return buf_.cbegin();
|
|
}
|
|
|
|
const_iterator
|
|
end() const noexcept
|
|
{
|
|
return buf_.end();
|
|
}
|
|
|
|
const_iterator
|
|
cend() const noexcept
|
|
{
|
|
return buf_.cend();
|
|
}
|
|
};
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
/** Create a seed using secure random numbers. */
|
|
Seed
|
|
randomSeed();
|
|
|
|
/** Generate a seed deterministically.
|
|
|
|
The algorithm is specific to Ripple:
|
|
|
|
The seed is calculated as the first 128 bits
|
|
of the SHA512-Half of the string text excluding
|
|
any terminating null.
|
|
|
|
@note This will not attempt to determine the format of
|
|
the string (e.g. hex or base58).
|
|
*/
|
|
Seed
|
|
generateSeed(std::string const& passPhrase);
|
|
|
|
/** Parse a Base58 encoded string into a seed */
|
|
template <>
|
|
std::optional<Seed>
|
|
parseBase58(std::string const& s);
|
|
|
|
/** Attempt to parse a string as a seed.
|
|
|
|
@param str the string to parse
|
|
@param rfc1751 true if we should attempt RFC1751 style parsing (deprecated)
|
|
* */
|
|
std::optional<Seed>
|
|
parseGenericSeed(std::string const& str, bool rfc1751 = true);
|
|
|
|
/** Encode a Seed in RFC1751 format */
|
|
std::string
|
|
seedAs1751(Seed const& seed);
|
|
|
|
/** Format a seed as a Base58 string */
|
|
inline std::string
|
|
toBase58(Seed const& seed)
|
|
{
|
|
return encodeBase58Token(TokenType::FamilySeed, seed.data(), seed.size());
|
|
}
|
|
|
|
} // namespace ripple
|
|
|
|
#endif
|