rippled
Loading...
Searching...
No Matches
Sign.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 <xrpl/protocol/Sign.h>
21
22namespace ripple {
23
24void
26 STObject& st,
27 HashPrefix const& prefix,
28 KeyType type,
29 SecretKey const& sk,
30 SF_VL const& sigField)
31{
32 Serializer ss;
33 ss.add32(prefix);
35 set(st, sigField, sign(type, sk, ss.slice()));
36}
37
38bool
40 STObject const& st,
41 HashPrefix const& prefix,
42 PublicKey const& pk,
43 SF_VL const& sigField)
44{
45 auto const sig = get(st, sigField);
46 if (!sig)
47 return false;
48 Serializer ss;
49 ss.add32(prefix);
51 return verify(
52 pk, Slice(ss.data(), ss.size()), Slice(sig->data(), sig->size()));
53}
54
55// Questions regarding buildMultiSigningData:
56//
57// Why do we include the Signer.Account in the blob to be signed?
58//
59// Unless you include the Account which is signing in the signing blob,
60// you could swap out any Signer.Account for any other, which may also
61// be on the SignerList and have a RegularKey matching the
62// Signer.SigningPubKey.
63//
64// That RegularKey may be set to allow some 3rd party to sign transactions
65// on the account's behalf, and that RegularKey could be common amongst all
66// users of the 3rd party. That's just one example of sharing the same
67// RegularKey amongst various accounts and just one vulnerability.
68//
69// "When you have something that's easy to do that makes entire classes of
70// attacks clearly and obviously impossible, you need a damn good reason
71// not to do it." -- David Schwartz
72//
73// Why would we include the signingFor account in the blob to be signed?
74//
75// In the current signing scheme, the account that a signer is `signing
76// for/on behalf of` is the tx_json.Account.
77//
78// Later we might support more levels of signing. Suppose Bob is a signer
79// for Alice, and Carol is a signer for Bob, so Carol can sign for Bob who
80// signs for Alice. But suppose Alice has two signers: Bob and Dave. If
81// Carol is a signer for both Bob and Dave, then the signature needs to
82// distinguish between Carol signing for Bob and Carol signing for Dave.
83//
84// So, if we support multiple levels of signing, then we'll need to
85// incorporate the "signing for" accounts into the signing data as well.
86Serializer
87buildMultiSigningData(STObject const& obj, AccountID const& signingID)
88{
90 finishMultiSigningData(signingID, s);
91 return s;
92}
93
94Serializer
96{
97 Serializer s;
100 return s;
101}
102
103} // namespace ripple
A public key.
Definition: PublicKey.h:62
void addWithoutSigningFields(Serializer &s) const
Definition: STObject.h:941
A secret key.
Definition: SecretKey.h:37
std::size_t size() const noexcept
Definition: Serializer.h:72
void const * data() const noexcept
Definition: Serializer.h:78
Slice slice() const noexcept
Definition: Serializer.h:66
An immutable linear range of bytes.
Definition: Slice.h:45
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
void finishMultiSigningData(AccountID const &signingID, Serializer &s)
Definition: Sign.h:85
Serializer startMultiSigningData(STObject const &obj)
Break the multi-signing hash computation into 2 parts for optimization.
Definition: Sign.cpp:95
bool verify(PublicKey const &publicKey, Slice const &m, Slice const &sig, bool mustBeFullyCanonical=true) noexcept
Verify a signature on a message.
Definition: PublicKey.cpp:272
Serializer buildMultiSigningData(STObject const &obj, AccountID const &signingID)
Return a Serializer suitable for computing a multisigning TxnSignature.
Definition: Sign.cpp:87
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,...
Definition: BasicConfig.h:316
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &message)
Generate a signature for a message.
Definition: SecretKey.cpp:238
KeyType
Definition: KeyType.h:28
T get(Section const &section, std::string const &name, T const &defaultValue=T{})
Retrieve a key/value pair from a section.
Definition: BasicConfig.h:356
HashPrefix
Prefix for hashing functions.
Definition: HashPrefix.h:54
@ txMultiSign
inner transaction to multi-sign
A field with a type known at compile time.
Definition: SField.h:315