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