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