libDwmCredence-0.1.32
DwmCredenceAuthenticator.hh
Go to the documentation of this file.
1//===========================================================================
2// @(#) $DwmPath$
3//===========================================================================
4// Copyright (c) Daniel W. McRobb 2022, 2023
5// All rights reserved.
6//
7// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions
9// are met:
10//
11// 1. Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13// 2. Redistributions in binary form must reproduce the above copyright
14// notice, this list of conditions and the following disclaimer in the
15// documentation and/or other materials provided with the distribution.
16// 3. The names of the authors and copyright holders may not be used to
17// endorse or promote products derived from this software without
18// specific prior written permission.
19//
20// IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
21// DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
22// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
23// EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
24// DAMAGE.
25//
26// THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
27// DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
28// UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
29// REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
30// IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31// WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
32// OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
33// TRADEMARK OR OTHER RIGHTS.
34//===========================================================================
35
36//---------------------------------------------------------------------------
40//---------------------------------------------------------------------------
41
42#ifndef _DWMCREDENCEAUTHENTICATOR_HH_
43#define _DWMCREDENCEAUTHENTICATOR_HH_
44
45#include <chrono>
46#include <boost/asio.hpp>
47
48#include "DwmStreamIOCapable.hh"
53
54namespace Dwm {
55
56 namespace Credence {
57
58 //------------------------------------------------------------------------
60 //------------------------------------------------------------------------
62 {
63 public:
64 //----------------------------------------------------------------------
66 //----------------------------------------------------------------------
67 Authenticator(const KeyStash & keyStash, const KnownKeys & knownKeys);
68
69 //----------------------------------------------------------------------
71 //----------------------------------------------------------------------
72 void SetIdExchangeTimeout(std::chrono::milliseconds ms);
73
74 //----------------------------------------------------------------------
83 //----------------------------------------------------------------------
84 bool Authenticate(boost::asio::ip::tcp::iostream & s,
85 const std::string & agreedKey,
86 std::string & theirId);
87
88 //----------------------------------------------------------------------
97 //----------------------------------------------------------------------
98 bool Authenticate(boost::asio::local::stream_protocol::iostream & s,
99 const std::string & agreedKey,
100 std::string & theirId);
101
102 private:
103 KeyStash _keyStash;
104 KnownKeys _knownKeys;
105 std::chrono::milliseconds _timeout;
106 boost::asio::ip::tcp::endpoint _endPoint;
107 boost::asio::local::stream_protocol::endpoint _lendPoint;
108 std::unique_ptr<XChaCha20Poly1305::Ostream> _xos;
109 std::unique_ptr<XChaCha20Poly1305::Istream> _xis;
110
111 bool ExchangeIds(boost::asio::ip::tcp::iostream & s,
112 Ed25519KeyPair & myKeys,
113 ShortString & theirId,
114 std::string & theirPubKey);
115 bool ExchangeIds(boost::asio::local::stream_protocol::iostream & s,
116 Ed25519KeyPair & myKeys, ShortString & theirId,
117 std::string & theirPubKey);
118 bool ExchangeChallenges(const std::string & ourSecretKey,
119 const std::string & theirId,
120 const std::string & theirPubKey);
121 bool Send(const std::string & msg);
122 bool Send(const HasStreamWrite auto & msg);
123 bool Receive(std::string & msg);
124 bool Receive(HasStreamRead auto & msg);
125 std::string EndPointString() const;
126 };
127
128 } // namespace Credence
129
130} // namespace Dwm
131
132#endif // _DWMCREDENCEAUTHENTICATOR_HH_
Dwm::Credence::KeyStash class declaration.
Dwm::Credence::KnownKeys class declaration.
Dwm::Credence::XChaCha20Poly1305::Istream class declaration.
Dwm::Credence::XChaCha20Poly1305::Ostream class declaration.
Used by Dwm::Credence::Peer for authentication.
Definition DwmCredenceAuthenticator.hh:62
void SetIdExchangeTimeout(std::chrono::milliseconds ms)
Sets the timeout for ID exchange to occur, in milliseconds.
bool Authenticate(boost::asio::local::stream_protocol::iostream &s, const std::string &agreedKey, std::string &theirId)
Authenticate the peer connected to s using the previously negotiated encryption key agreedKey to encr...
bool Authenticate(boost::asio::ip::tcp::iostream &s, const std::string &agreedKey, std::string &theirId)
Authenticate the peer connected to s using the previously negotiated encryption key agreedKey to encr...
Authenticator(const KeyStash &keyStash, const KnownKeys &knownKeys)
Construct from the given keyStash and knownKeys.
Encapsulates an Ed25519 key pair.
Definition DwmCredenceEd25519KeyPair.hh:64
Encapsulates storage of an Ed25519KeyPair in a filesystem.
Definition DwmCredenceKeyStash.hh:56
Encapsulates the storage of a set of known public keys.
Definition DwmCredenceKnownKeys.hh:60
Encapsulates a string that is restricted to 255 bytes or less.
Definition DwmCredenceShortString.hh:57