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