libtins  4.0
handshake_capturer.h
1 /*
2  * Copyright (c) 2017, Matias Fontanini
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following disclaimer
13  * in the documentation and/or other materials provided with the
14  * distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 
30 #include <tins/config.h>
31 
32 #if !defined(TINS_HANDSHAKE_CAPTURER_H) && defined(TINS_HAVE_DOT11)
33 #define TINS_HANDSHAKE_CAPTURER_H
34 
35 #include <vector>
36 #include <map>
37 #include <utility>
38 #include <tins/hw_address.h>
39 #include <tins/macros.h>
40 #include <tins/eapol.h>
41 
42 namespace Tins {
43 
50 template<typename T>
52 public:
53  typedef std::vector<T> container_type;
54  typedef HWAddress<6> address_type;
55 
60 
69  EAPOLHandshake(const address_type& client_address,
70  const address_type& supplicant_address,
71  const container_type& cont)
72  : cl_address_(client_address), suppl_address_(supplicant_address),
73  handshake_(cont) {
74  }
75 
79  const address_type& client_address() const {
80  return cl_address_;
81  }
82 
86  const address_type& supplicant_address() const {
87  return suppl_address_;
88  }
89 
93  const container_type& handshake() const {
94  return handshake_;
95  }
96 private:
97  address_type cl_address_, suppl_address_;
98  container_type handshake_;
99 };
100 
105 
109 class TINS_API RSNHandshakeCapturer {
110 public:
114  typedef RSNHandshake handshake_type;
115 
120  typedef std::vector<handshake_type> handshakes_type;
121 
131  bool process_packet(const PDU& pdu);
132 
142  const handshakes_type& handshakes() const {
143  return completed_handshakes_;
144  }
145 
154  completed_handshakes_.clear();
155  }
156 private:
158  typedef handshake_type::container_type eapol_list;
159  typedef std::map<std::pair<address_type, address_type>, eapol_list> handshake_map;
160 
161  bool do_insert(const handshake_map::key_type& key, const RSNEAPOL* eapol,
162  size_t expected);
163 
164  handshake_map handshakes_;
165  handshakes_type completed_handshakes_;
166 };
167 
168 } // Tins
169 
170 #endif // TINS_HANDSHAKE_CAPTURER_H
Definition: handshake_capturer.h:109
const address_type & supplicant_address() const
Definition: handshake_capturer.h:86
RSNHandshake handshake_type
Definition: handshake_capturer.h:114
void clear_handshakes()
Clears the completed handshakes.
Definition: handshake_capturer.h:153
EAPOLHandshake< RSNEAPOL > RSNHandshake
Definition: handshake_capturer.h:104
Generic EAPOL handshake.
Definition: handshake_capturer.h:51
const handshakes_type & handshakes() const
Retrieves the completed handshakes.
Definition: handshake_capturer.h:142
EAPOLHandshake(const address_type &client_address, const address_type &supplicant_address, const container_type &cont)
Definition: handshake_capturer.h:69
const container_type & handshake() const
Definition: handshake_capturer.h:93
std::vector< handshake_type > handshakes_type
Definition: handshake_capturer.h:120
The Tins namespace.
Definition: address_range.h:38
EAPOLHandshake()
Default constructor.
Definition: handshake_capturer.h:59
Class that represents the RSN EAPOL PDU.
Definition: eapol.h:397
const address_type & client_address() const
Definition: handshake_capturer.h:79
Base class for protocol data units.
Definition: pdu.h:107