libDwmAuth-0.3.6
DwmAuthPeerAuthenticator.hh
Go to the documentation of this file.
1 //===========================================================================
2 // @(#) $Name:$
3 // @(#) $Id: DwmAuthPeerAuthenticator.hh 10963 2020-08-23 07:51:58Z dwm $
4 //===========================================================================
5 // Copyright (c) Daniel W. McRobb 2017, 2018, 2020
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // 1. Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 // 2. Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 // 3. The names of the authors and copyright holders may not be used to
18 // endorse or promote products derived from this software without
19 // specific prior written permission.
20 //
21 // IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
22 // DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
23 // INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
24 // EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
25 // DAMAGE.
26 //
27 // THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
28 // DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
29 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
30 // REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
31 // IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
32 // WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
33 // OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
34 // TRADEMARK OR OTHER RIGHTS.
35 //===========================================================================
36 
37 //---------------------------------------------------------------------------
40 //---------------------------------------------------------------------------
41 
42 #ifndef _DWMAUTHPEERAUTHENTICATOR_HH_
43 #define _DWMAUTHPEERAUTHENTICATOR_HH_
44 
45 #include <chrono>
46 #include <string>
47 
48 #include <boost/asio.hpp>
49 
50 #include "DwmAuthPublicKeysFile.hh"
51 #include "DwmAuthECDHAgreement.hh"
52 #include "DwmAuthEd25519Keys.hh"
53 
54 namespace Dwm {
55 
56  namespace Auth {
57 
58  //------------------------------------------------------------------------
70  //------------------------------------------------------------------------
72  {
73  public:
74  //----------------------------------------------------------------------
86  //----------------------------------------------------------------------
87  PeerAuthenticator(const std::string & myPrivKeyPath,
88  const std::string & pubKeysPath);
89 
90  //----------------------------------------------------------------------
94  //----------------------------------------------------------------------
95  PeerAuthenticator(const std::string & myId,
96  const Ed25519::KeyPair & keyPair,
97  const std::string & pubKeysPath);
98 
99  //----------------------------------------------------------------------
105  //----------------------------------------------------------------------
106  bool Authenticate(int fd, std::string & theirId,
107  std::string & agreedKey);
108 
109  //----------------------------------------------------------------------
111  //----------------------------------------------------------------------
112  bool Authenticate(boost::asio::ip::tcp::socket & s,
113  std::string & theirId,
114  std::string & agreedKey);
115 
116  private:
117  std::string _myId;
118  Ed25519::KeyPair _myKeys;
119  std::string _pubKeysPath;
120 
121  bool ECExchange(int fd, Auth::ECDHAgreement & agreement);
122  bool ECExchange(boost::asio::ip::tcp::socket & s,
123  Auth::ECDHAgreement & agreement);
124  std::string BuildIDAndSignature(const ECDHAgreement & agreement);
125  bool IDAndSigExchange(int fd, const ECDHAgreement & agreement,
126  std::string & theirId,
127  std::string & theirIdCrypted,
128  std::string & theirSig);
129  bool IDAndSigExchange(boost::asio::ip::tcp::socket & s,
130  const ECDHAgreement & agreement,
131  std::string & theirId,
132  std::string & theirIdCrypted,
133  std::string & theirSig);
134  int BytesReady(int fd) const;
135  bool WaitForBytesReady(int fd, uint32_t numBytes,
136  std::chrono::milliseconds timeout) const;
137  };
138 
139  } // namespace Auth
140 
141 } // namespace Dwm
142 
143 #endif // _DWMAUTHPEERAUTHENTICATOR_HH_
bool Authenticate(int fd, std::string &theirId, std::string &agreedKey)
Authenticate the peer connected to the socket fd.
Encapsulates a private/public key pair.
Definition: DwmAuthEd25519Keys.hh:147
A simplified peer authenticator.
Definition: DwmAuthPeerAuthenticator.hh:71
Dwm::Auth::ECDHAgreement class definition.
NOT YET DOCUMENTED.
Encapsulates information used in an ECDH key agreement.
Definition: DwmAuthECDHAgreement.hh:57
PeerAuthenticator(const std::string &myPrivKeyPath, const std::string &pubKeysPath)
Construct from a path to our ed25519 private key and a path to a file containing public keys.
Dwm::Auth::PublicKeysFile class definition.