plebble
peer_t.h
Go to the documentation of this file.
1 /*
2 -------------------------------------------------------------------------------
3  PLEBBLE
4 -------------------------------------------------------------------------------
5  Copyright (C) 2019-2020 KATLAS Technology. (http://katlastechnology.com)
6  Copyright (C) 2017-2020 Marcos Mayorga. (mm@mm-studios.com)
7 
8  This file is part of our Plebble(R) Platform.
9 
10  The code below cannot be copied, used for any purpose other than the one
11  agreed and/or distributed without the express permission of
12  KATLAS Technology.
13 -------------------------------------------------------------------------------
14 
15 
16 */
17 #ifndef USGOV_adb8d14e20731e001ab4e0eb7742ff5881fc9a7fabb4666497868c91f9a18570
18 #define USGOV_adb8d14e20731e001ab4e0eb7742ff5881fc9a7fabb4666497868c91f9a18570
19 
20 #include <us/gov/socket/peer_t.h>
21 #include <mutex>
22 #include <condition_variable>
23 #include <us/gov/crypto/crypto.h>
24 #include <us/gov/crypto/hash.h>
26 #include <us/gov/config.h>
27 
28 namespace us { namespace gov {
29 namespace id {
30  using namespace std;
31  using us::ko;
32 
33  struct daemon;
34 
36  typedef socket::peer_t b;
38  typedef keys::pub_t pub_t;
41 
42  static const char* KO_6017;
43 
44  enum stage_t { //coupled with sdk/java/src/Wallet.java
45  anonymous=0,
48  num_stages
49  };
50  constexpr static array<const char*,num_stages> stagestr={"anonymous","verified","verified_fail"};
51 
52  enum role_t {
53  role_peer=0,
54  role_sysop=1,
55  role_device=2,
56  num_roles
57  };
58  constexpr static array<const char*,num_roles> rolestr={"peer","sysop","device"};
59 
60  peer_t(int sock);
61  virtual ~peer_t();
62 
63  ko connect(const string& host, uint16_t port, uint16_t pport, role_t, bool block);
64  virtual ko connect(uint32_t host, uint16_t port, uint16_t pport, role_t, bool block);
65  virtual void verification_completed(uint16_t rpport) {}
66  virtual const keys& get_keys() const;
67  virtual void dump_all(const string& prefix, ostream& os) const override;
68  void dump(const string& prefix, ostream& os) const;
70  void process_request(datagram* d, const keys&);
73  ko initiate_dialogue(role_t role, uint16_t pport_pin);
74  static string to_string(const vector<unsigned char>& data);
75  bool verification_is_fine() const { return get_stage_peer()==verified; }
76  string short_version() const;
78  ko wait_auth() const;
81  //datagram* encrypt0(const datagram&) const override;
82  void disconnect(uint16_t seq, const string&reason) override;
85 
87  const daemon* get_parent() const;
88 
89  inline bool is_role_peer() const { return role==role_peer; }
90  inline bool is_role_sysop() const { return role==role_sysop; }
91  inline bool is_role_device() const { return role==role_device; }
92 
93  struct handshake_t {
96  handshake_t(role_t role, uint16_t pport);
97  handshake_t();
98  role_t parse_role() const;
99  uint16_t parse_version_fingerprint() const;
100  uint16_t parse_pport() const;
101  uint16_t parse_pin() const;
102  void dump(const string& pfx, ostream&os) const;
103 
105  };
106  struct handshakes_t {
107  handshakes_t(role_t role, uint16_t pport);
108  handshakes_t();
109  ~handshakes_t();
110  handshake_t* me{nullptr};
111  handshake_t* peer{nullptr};
112  };
113 
114  stage_t stage_peer{anonymous};
115  handshakes_t* handshakes{nullptr};
116  role_t role{role_peer};
117  pub_t pubkey; //peer's public key
118  uint16_t version_fingerprint{0};
119  mutable mutex mx_auth;
120  mutable condition_variable cv_auth;
121  mutable crypto::symmetric_encryption* se{nullptr};
122  };
123 
124 }
125 }}
126 
127 #endif
128 
us::gov::id::peer_t::get_parent
const daemon * get_parent() const
us::gov::id::peer_t::~peer_t
virtual ~peer_t()
us::gov::id::peer_t::connect
ko connect(const string &host, uint16_t port, uint16_t pport, role_t, bool block)
us::gov::id::peer_t::initiate_dialogue
ko initiate_dialogue(role_t role, uint16_t pport_pin)
us::gov::id::peer_t::get_stage_peer
stage_t get_stage_peer() const
us::gov::id::peer_t::connect
virtual ko connect(uint32_t host, uint16_t port, uint16_t pport, role_t, bool block)
us::gov::id::peer_t::peer_t
peer_t(int sock)
us::gov::id::peer_t::process_peer_challenge
void process_peer_challenge(datagram *d, const keys &)
us::gov::socket::client.pair
Definition: client.cs:143
us::gov::id::peer_t::is_role_sysop
bool is_role_sysop() const
Definition: peer_t.h:90
us::gov::id::peer_t::get_keys
virtual const keys & get_keys() const
us.ko
Definition: ko.java:20
us::gov::id::peer_t::get_parent
daemon * get_parent()
us
Definition: daemon.h:22
us::gov::crypto::ripemd160::value_type
Definition: ripemd160.h:38
us::gov::crypto::sha256::value_type
Definition: sha256.h:38
us::gov::id::peer_t::is_role_peer
bool is_role_peer() const
Definition: peer_t.h:89
us::gov::id::peer_t::to_string
static string to_string(const vector< unsigned char > &data)
us::gov::id::peer_t.stage_t
Definition: peer_t.java:54
us::gov::id::peer_t::turn_on_encryption
ko turn_on_encryption()
us::gov::crypto::ec::keys::pub_t
Definition: ec.h:44
us::gov::id::peer_t::handshakes_t
Definition: peer_t.h:106
us::gov::id::peer_t::decrypt0
pair< ko, datagram * > decrypt0(datagram *) const override
us::gov::id::peer_t::handshake_t
Definition: peer_t.h:93
us::gov::id::peer_t::disconnect
void disconnect(uint16_t seq, const string &reason) override
us::gov::socket::datagram
Definition: datagram.h:44
us::gov::crypto::sha256
Definition: sha256.h:33
us::gov::id::peer_t::handshake_t::sigmsg_hash_t
sigmsg_hasher_t::value_type sigmsg_hash_t
Definition: peer_t.h:95
us::gov::auth::daemon
id::daemon daemon
Definition: daemon.h:25
us::gov::id::peer_t::pubkey
pub_t pubkey
Definition: peer_t.h:117
us::gov::id::peer_t.stage_t::verified
@ verified
Definition: peer_t.h:46
us::gov::id::peer_t::set_stage_peer
void set_stage_peer(stage_t)
us::gov::engine::auth::pub_t
peer::daemon::pub_t pub_t
Definition: auth_app.h:53
us::gov::id::peer_t.role_t
Definition: peer_t.java:71
us::gov::id::peer_t::keys
crypto::ec::keys keys
Definition: peer_t.h:37
us::gov::id::peer_t::hash_t
pub_t::hash_t hash_t
Definition: peer_t.h:39
us::gov::id::peer_t::wait_auth
ko wait_auth() const
us::gov::id::daemon
Definition: daemon.h:28
us::gov::crypto::symmetric_encryption
Definition: symmetric_encryption.h:37
peer_t.h
us::ko
const ko_t * ko
Definition: ko.h:27
us::gov::id::peer_t::b
socket::peer_t b
Definition: peer_t.h:36
us::gov::id::peer_t::verification_is_fine
bool verification_is_fine() const
Definition: peer_t.h:75
us::gov::id::peer_t.stage_t::verified_fail
@ verified_fail
Definition: peer_t.h:47
us::gov::id::peer_t::handshake_t::msg
sigmsg_hash_t msg
Definition: peer_t.h:104
us::gov::socket::peer_t
Definition: peer_t.h:28
symmetric_encryption.h
us::gov::id::peer_t::process_work
bool process_work(datagram *d)
std
Definition: app.h:380
us::gov::id::peer_t::process_challenge_response
void process_challenge_response(datagram *d)
us::gov::id::peer_t::verification_completed
virtual void verification_completed(uint16_t rpport)
Definition: peer_t.h:65
us::gov::id::peer_t::encrypt0
pair< ko, datagram * > encrypt0(datagram *) const override
hash.h
us::gov::id::peer_t::cv_auth
condition_variable cv_auth
Definition: peer_t.h:120
us::gov::crypto::ec::keys
Definition: ec.h:43
config.h
us::gov::id::peer_t::mx_auth
mutex mx_auth
Definition: peer_t.h:119
us::gov::id::peer_t::dump
void dump(const string &prefix, ostream &os) const
us::gov::id::peer_t::short_version
string short_version() const
crypto.h
us::gov::id::peer_t
Definition: peer_t.h:35
us::gov::id::peer_t::KO_6017
static const char * KO_6017
Definition: peer_t.h:42
us::gov::id::peer_t::dump_all
virtual void dump_all(const string &prefix, ostream &os) const override
us::gov::id::peer_t::handshake_t::sigmsg_hasher_t
crypto::ec::sigmsg_hasher_t sigmsg_hasher_t
Definition: peer_t.h:94
us::gov::id::peer_t::is_role_device
bool is_role_device() const
Definition: peer_t.h:91
us::gov::id::peer_t::process_request
void process_request(datagram *d, const keys &)