rippled
Loading...
Searching...
No Matches
NodeIdentity.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/app/main/Application.h>
21#include <xrpld/app/main/NodeIdentity.h>
22#include <xrpld/app/rdb/Wallet.h>
23#include <xrpld/core/Config.h>
24#include <xrpld/core/ConfigSections.h>
25
26namespace ripple {
27
30 Application& app,
31 boost::program_options::variables_map const& cmdline)
32{
34
35 if (cmdline.count("nodeid"))
36 {
37 seed = parseGenericSeed(cmdline["nodeid"].as<std::string>(), false);
38
39 if (!seed)
40 Throw<std::runtime_error>("Invalid 'nodeid' in command line");
41 }
42 else if (app.config().exists(SECTION_NODE_SEED))
43 {
44 seed = parseBase58<Seed>(
45 app.config().section(SECTION_NODE_SEED).lines().front());
46
47 if (!seed)
48 Throw<std::runtime_error>("Invalid [" SECTION_NODE_SEED
49 "] in configuration file");
50 }
51
52 if (seed)
53 {
54 auto secretKey = generateSecretKey(KeyType::secp256k1, *seed);
55 auto publicKey = derivePublicKey(KeyType::secp256k1, secretKey);
56
57 return {publicKey, secretKey};
58 }
59
60 auto db = app.getWalletDB().checkoutDb();
61
62 if (cmdline.count("newnodeid") != 0)
64
65 return getNodeIdentity(*db);
66}
67
68} // namespace ripple
virtual Config & config()=0
virtual DatabaseCon & getWalletDB()=0
Retrieve the "wallet database".
bool exists(std::string const &name) const
Returns true if a section with the given name exists.
Section & section(std::string const &name)
Returns the section with the given name.
LockedSociSession checkoutDb()
std::vector< std::string > const & lines() const
Returns all the lines in the section.
Definition BasicConfig.h:70
T front(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
std::pair< PublicKey, SecretKey > getNodeIdentity(Application &app, boost::program_options::variables_map const &cmdline)
The cryptographic credentials identifying this server instance.
PublicKey derivePublicKey(KeyType type, SecretKey const &sk)
Derive the public key from a secret key.
SecretKey generateSecretKey(KeyType type, Seed const &seed)
Generate a new secret key deterministically.
void clearNodeIdentity(soci::session &session)
Delete any saved public/private key associated with this node.
Definition Wallet.cpp:127
std::optional< Seed > parseGenericSeed(std::string const &str, bool rfc1751=true)
Attempt to parse a string as a seed.
Definition Seed.cpp:97