hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
field_validator.hpp
Go to the documentation of this file.
1 
6 #ifndef IROHA_SHARED_MODEL_FIELD_VALIDATOR_HPP
7 #define IROHA_SHARED_MODEL_FIELD_VALIDATOR_HPP
8 
9 #include <regex>
10 
11 #include "datetime/time.hpp"
15 #include "validators/answer.hpp"
17 
18 namespace shared_model {
19 
20  namespace interface {
21  class Amount;
22  class BatchMeta;
23  class Peer;
24  class TxPaginationMeta;
25  } // namespace interface
26 
27  namespace validation {
28 
34  private:
35  using TimeFunction = std::function<iroha::ts64_t()>;
36 
37  public:
38  // todo igor-egorov 05.04.2018 IR-439 Remove ValidatorsConfig from
39  // FieldValidator
40  FieldValidator(std::shared_ptr<ValidatorsConfig> config,
41  time_t future_gap = kDefaultFutureGap,
42  TimeFunction time_provider = [] {
43  return iroha::time::now();
44  });
45 
46  void validateAccountId(
47  ReasonsGroupType &reason,
48  const interface::types::AccountIdType &account_id) const;
49 
50  void validateAssetId(ReasonsGroupType &reason,
51  const interface::types::AssetIdType &asset_id) const;
52 
53  void validatePeer(ReasonsGroupType &reason,
54  const interface::Peer &peer) const;
55 
56  void validateAmount(ReasonsGroupType &reason,
57  const interface::Amount &amount) const;
58 
59  void validatePubkey(ReasonsGroupType &reason,
60  const interface::types::PubkeyType &pubkey) const;
61 
62  void validatePeerAddress(
63  ReasonsGroupType &reason,
64  const interface::types::AddressType &address) const;
65 
66  void validateRoleId(ReasonsGroupType &reason,
67  const interface::types::RoleIdType &role_id) const;
68 
69  void validateAccountName(
70  ReasonsGroupType &reason,
71  const interface::types::AccountNameType &account_name) const;
72 
73  // clang-format off
94  // clang-format on
95  void validateDomainId(
96  ReasonsGroupType &reason,
97  const interface::types::DomainIdType &domain_id) const;
98 
99  void validateAssetName(
100  ReasonsGroupType &reason,
101  const interface::types::AssetNameType &asset_name) const;
102 
103  void validateAccountDetailKey(
104  ReasonsGroupType &reason,
105  const interface::types::AccountDetailKeyType &key) const;
106 
107  void validateAccountDetailValue(
108  ReasonsGroupType &reason,
109  const interface::types::AccountDetailValueType &value) const;
110 
111  void validatePrecision(
112  ReasonsGroupType &reason,
113  const interface::types::PrecisionType &precision) const;
114 
115  void validateRolePermission(
116  ReasonsGroupType &reason,
117  const interface::permissions::Role &permission) const;
118 
119  void validateGrantablePermission(
120  ReasonsGroupType &reason,
121  const interface::permissions::Grantable &permission) const;
122 
123  void validateQuorum(ReasonsGroupType &reason,
124  const interface::types::QuorumType &quorum) const;
125 
126  void validateCreatorAccountId(
127  ReasonsGroupType &reason,
128  const interface::types::AccountIdType &account_id) const;
129 
133  void validateCreatedTime(ReasonsGroupType &reason,
136 
140  void validateCreatedTime(ReasonsGroupType &reason,
141  interface::types::TimestampType timestamp) const;
142 
143  void validateCounter(ReasonsGroupType &reason,
144  const interface::types::CounterType &counter) const;
145 
146  void validateSignatures(
147  ReasonsGroupType &reason,
148  const interface::types::SignatureRangeType &signatures,
149  const crypto::Blob &source) const;
150 
151  void validateQueryPayloadMeta(
152  ReasonsGroupType &reason,
153  const interface::QueryPayloadMeta &meta) const;
154 
155  void validateDescription(
156  ReasonsGroupType &reason,
157  const interface::types::DescriptionType &description) const;
158 
159  void validateBatchMeta(ReasonsGroupType &reason,
160  const interface::BatchMeta &description) const;
161 
162  void validateHeight(ReasonsGroupType &reason,
163  const interface::types::HeightType &height) const;
164 
165  void validateHash(ReasonsGroupType &reason,
166  const crypto::Hash &hash) const;
167 
168  void validateTxPaginationMeta(
169  ReasonsGroupType &reason,
170  const interface::TxPaginationMeta &tx_pagination_meta) const;
171 
172  private:
173  const static std::string account_name_pattern_;
174  const static std::string asset_name_pattern_;
175  const static std::string domain_pattern_;
176  const static std::string ip_v4_pattern_;
177  const static std::string peer_address_pattern_;
178  const static std::string account_id_pattern_;
179  const static std::string asset_id_pattern_;
180  const static std::string detail_key_pattern_;
181  const static std::string role_id_pattern_;
182 
183  const static std::regex account_name_regex_;
184  const static std::regex asset_name_regex_;
185  const static std::regex domain_regex_;
186  const static std::regex ip_v4_regex_;
187  const static std::regex peer_address_regex_;
188  const static std::regex account_id_regex_;
189  const static std::regex asset_id_regex_;
190  const static std::regex detail_key_regex_;
191  const static std::regex role_id_regex_;
192 
193  // gap for future transactions
194  time_t future_gap_;
195  // time provider callback
196  TimeFunction time_provider_;
197 
198  public:
199  // max-delay between tx creation and validation
200  static constexpr auto kMaxDelay =
201  std::chrono::hours(24) / std::chrono::milliseconds(1);
202  // default value for future_gap field of FieldValidator
203  static constexpr auto kDefaultFutureGap =
204  std::chrono::minutes(5) / std::chrono::milliseconds(1);
205 
206  // size of key
207  static const size_t public_key_size;
208  static const size_t signature_size;
209  static const size_t hash_size;
210  static const size_t value_size;
211  static const size_t description_size;
212  };
213 
214  boost::optional<ConcreteReasonType> validatePubkey(
215  const interface::types::PubkeyType &pubkey);
216 
217  } // namespace validation
218 } // namespace shared_model
219 
220 #endif // IROHA_SHARED_MODEL_FIELD_VALIDATOR_HPP
static const size_t signature_size
Definition: field_validator.hpp:208
uint64_t HeightType
Type of height (for Block, Proposal etc)
Definition: types.hpp:39
Definition: hash.hpp:18
Definition: blob.hpp:24
Grantable
Definition: permissions.hpp:66
std::string AddressType
Type of peer address.
Definition: types.hpp:41
Definition: peer.hpp:18
decltype(iroha::time::now()) time_t
Definition: time.hpp:38
std::string DomainIdType
Iroha domain id type.
Definition: types.hpp:49
Definition: amount.hpp:20
static const size_t public_key_size
Definition: field_validator.hpp:207
auto now()
Definition: time.hpp:23
boost::any_range< interface::Signature, boost::forward_traversal_tag, const Signature & > SignatureRangeType
Type of signature range, which returns when signatures are invoked.
Definition: range_types.hpp:24
std::string DescriptionType
Type of the transfer message.
Definition: types.hpp:79
Definition: query_payload_meta.hpp:19
std::string AccountDetailKeyType
Type of account detail key.
Definition: types.hpp:73
Role
Definition: permissions.hpp:17
std::string AccountIdType
Type of account id.
Definition: types.hpp:35
hash256_t hash(const T &pb)
Definition: pb_common.hpp:43
Provides query metadata for any transaction list pagination.
Definition: tx_pagination_meta.hpp:17
Definition: field_validator.hpp:33
uint8_t PrecisionType
Type of precision.
Definition: types.hpp:37
boost::optional< ConcreteReasonType > validatePubkey(const interface::types::PubkeyType &pubkey)
Definition: field_validator.cpp:377
std::string AccountNameType
Type of account name.
Definition: types.hpp:65
static const size_t value_size
limit for the set account detail size in bytes
Definition: field_validator.hpp:210
uint64_t CounterType
Type of counter.
Definition: types.hpp:63
Definition: public_key.hpp:16
static const size_t description_size
Definition: field_validator.hpp:211
Definition: batch_meta.hpp:18
static const size_t hash_size
Definition: field_validator.hpp:209
std::pair< ReasonsGroupName, GroupedReasons > ReasonsGroupType
Definition: answer.hpp:22
std::string AccountDetailValueType
Type of account detail value.
Definition: types.hpp:75
Definition: command_executor.hpp:12
uint16_t QuorumType
Type of Quorum used in transaction and set quorum.
Definition: types.hpp:57
std::string AssetNameType
Type of asset name.
Definition: types.hpp:67
std::string RoleIdType
Type of role (i.e admin, user)
Definition: types.hpp:47
uint64_t TimestampType
Type of timestamp.
Definition: types.hpp:59
std::string AssetIdType
Type of asset id.
Definition: types.hpp:51