xrpld
Loading...
Searching...
No Matches
libxrpl/protocol/Sign.cpp
1#include <xrpl/protocol/Sign.h>
2
3#include <xrpl/protocol/AccountID.h>
4#include <xrpl/protocol/HashPrefix.h>
5#include <xrpl/protocol/KeyType.h>
6#include <xrpl/protocol/PublicKey.h>
7#include <xrpl/protocol/SField.h>
8#include <xrpl/protocol/STExchange.h>
9#include <xrpl/protocol/STObject.h>
10#include <xrpl/protocol/SecretKey.h>
11#include <xrpl/protocol/Serializer.h>
12
13namespace xrpl {
14
15void
17 STObject& st,
18 HashPrefix const& prefix,
19 KeyType type,
20 SecretKey const& sk,
21 SF_VL const& sigField)
22{
23 Serializer ss;
24 ss.add32(prefix);
26 set(st, sigField, sign(type, sk, ss.slice()));
27}
28
29bool
30verify(STObject const& st, HashPrefix const& prefix, PublicKey const& pk, SF_VL const& sigField)
31{
32 auto const sig = get(st, sigField);
33 if (!sig)
34 return false;
35 Serializer ss;
36 ss.add32(prefix);
38 return verify(pk, Slice(ss.data(), ss.size()), Slice(sig->data(), sig->size()));
39}
40
41// Questions regarding buildMultiSigningData:
42//
43// Why do we include the Signer.Account in the blob to be signed?
44//
45// Unless you include the Account which is signing in the signing blob,
46// you could swap out any Signer.Account for any other, which may also
47// be on the SignerList and have a RegularKey matching the
48// Signer.SigningPubKey.
49//
50// That RegularKey may be set to allow some 3rd party to sign transactions
51// on the account's behalf, and that RegularKey could be common amongst all
52// users of the 3rd party. That's just one example of sharing the same
53// RegularKey amongst various accounts and just one vulnerability.
54//
55// "When you have something that's easy to do that makes entire classes of
56// attacks clearly and obviously impossible, you need a damn good reason
57// not to do it." -- David Schwartz
58//
59// Why would we include the signingFor account in the blob to be signed?
60//
61// In the current signing scheme, the account that a signer is `signing
62// for/on behalf of` is the tx_json.Account.
63//
64// Later we might support more levels of signing. Suppose Bob is a signer
65// for Alice, and Carol is a signer for Bob, so Carol can sign for Bob who
66// signs for Alice. But suppose Alice has two signers: Bob and Dave. If
67// Carol is a signer for both Bob and Dave, then the signature needs to
68// distinguish between Carol signing for Bob and Carol signing for Dave.
69//
70// So, if we support multiple levels of signing, then we'll need to
71// incorporate the "signing for" accounts into the signing data as well.
72Serializer
73buildMultiSigningData(STObject const& obj, AccountID const& signingID)
74{
76 finishMultiSigningData(signingID, s);
77 return s;
78}
79
80Serializer
82{
83 Serializer s;
86 return s;
87}
88
89} // namespace xrpl
A public key.
Definition PublicKey.h:42
void addWithoutSigningFields(Serializer &s) const
Definition STObject.h:985
A secret key.
Definition SecretKey.h:18
Slice slice() const noexcept
Definition Serializer.h:44
std::size_t size() const noexcept
Definition Serializer.h:50
void const * data() const noexcept
Definition Serializer.h:56
An immutable linear range of bytes.
Definition Slice.h:26
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
Serializer startMultiSigningData(STObject const &obj)
Break the multi-signing hash computation into 2 parts for optimization.
bool set(T &target, std::string const &name, Section const &section)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
KeyType
Definition KeyType.h:8
T get(Section const &section, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
bool verify(PublicKey const &publicKey, Slice const &m, Slice const &sig) noexcept
Verify a signature on a message.
void finishMultiSigningData(AccountID const &signingID, Serializer &s)
Definition Sign.h:64
TypedField< STBlob > SF_VL
Definition SField.h:353
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28
HashPrefix
Prefix for hashing functions.
Definition HashPrefix.h:34
@ TxMultiSign
inner transaction to multi-sign
Definition HashPrefix.h:54
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &message)
Generate a signature for a message.
Serializer buildMultiSigningData(STObject const &obj, AccountID const &signingID)
Return a Serializer suitable for computing a multisigning TxnSignature.