libtins  4.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
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>
51 class EAPOLHandshake {
52 public:
53  typedef std::vector<T> container_type;
54  typedef HWAddress<6> address_type;
55 
59  EAPOLHandshake() { }
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 
104 typedef EAPOLHandshake<RSNEAPOL> RSNHandshake;
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 
153  void clear_handshakes() {
154  completed_handshakes_.clear();
155  }
156 private:
157  typedef handshake_type::address_type address_type;
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