30 #include <tins/config.h> 32 #if !defined(TINS_CRYPTO_H) && defined(TINS_HAVE_DOT11) 38 #ifdef TINS_HAVE_WPA2_CALLBACKS 40 #endif // TINS_HAVE_WPA2_CALLBACKS 41 #include <tins/macros.h> 42 #include <tins/handshake_capturer.h> 54 #ifdef TINS_HAVE_WPA2_DECRYPTION 60 class TINS_API SessionKeys {
65 static const size_t PMK_SIZE;
70 static const size_t PTK_SIZE;
75 typedef std::vector<uint8_t> ptk_type;
80 typedef std::vector<uint8_t> pmk_type;
94 SessionKeys(
const ptk_type& ptk,
bool is_ccmp);
104 SessionKeys(
const RSNHandshake& hs,
const pmk_type& pmk);
114 SNAP* decrypt_unicast(
const Dot11Data& dot11, RawPDU& raw)
const;
120 const ptk_type& get_ptk()
const;
126 bool uses_ccmp()
const;
128 SNAP* ccmp_decrypt_unicast(
const Dot11Data& dot11, RawPDU& raw)
const;
129 SNAP* tkip_decrypt_unicast(
const Dot11Data& dot11, RawPDU& raw)
const;
142 class TINS_API SupplicantData {
147 typedef SessionKeys::pmk_type pmk_type;
154 SupplicantData(
const std::string& psk,
const std::string& ssid);
160 const pmk_type& pmk()
const;
166 const std::string& ssid()
const;
173 #endif // TINS_HAVE_WPA2_DECRYPTION 194 void add_password(
const address_type& addr,
const std::string& password);
201 void remove_password(
const address_type& addr);
217 bool decrypt(
PDU& pdu);
219 typedef std::map<address_type, std::string> passwords_type;
221 PDU* decrypt(
RawPDU& raw,
const std::string& password);
223 passwords_type passwords_;
224 std::vector<uint8_t> key_buffer_;
227 #ifdef TINS_HAVE_WPA2_DECRYPTION 234 class TINS_API WPA2Decrypter {
250 typedef std::pair<address_type, address_type> addr_pair;
260 typedef std::map<addr_pair, WPA2::SessionKeys> keys_map;
262 #ifdef TINS_HAVE_WPA2_CALLBACKS 271 typedef std::function<void(
const std::string&,
272 const address_type&)> ap_found_callback_type;
282 typedef std::function<void(
const std::string&,
284 const address_type&)> handshake_captured_callback_type;
286 #endif // TINS_HAVE_WPA2_CALLBACKS 306 void add_ap_data(
const std::string& psk,
const std::string& ssid);
322 void add_ap_data(
const std::string& psk,
323 const std::string& ssid,
324 const address_type& addr);
346 void add_decryption_keys(
const addr_pair& addresses,
347 const WPA2::SessionKeys& session_keys);
364 bool decrypt(
PDU& pdu);
366 #ifdef TINS_HAVE_WPA2_CALLBACKS 375 void handshake_captured_callback(
const handshake_captured_callback_type& callback);
386 void ap_found_callback(
const ap_found_callback_type& callback);
388 #endif // TINS_HAVE_WPA2_CALLBACKS 398 const keys_map& get_keys()
const;
400 typedef std::map<std::string, WPA2::SupplicantData> pmks_map;
401 typedef std::map<address_type, WPA2::SupplicantData> bssids_map;
404 addr_pair make_addr_pair(
const address_type& addr1,
const address_type& addr2) {
405 return (addr1 < addr2) ?
406 std::make_pair(addr1, addr2) :
407 std::make_pair(addr2, addr1);
409 addr_pair extract_addr_pair(
const Dot11Data& dot11);
410 addr_pair extract_addr_pair_dst(
const Dot11Data& dot11);
411 bssids_map::const_iterator find_ap(
const Dot11Data& dot11);
412 void add_access_point(
const std::string& ssid,
const address_type& addr);
418 #ifdef TINS_HAVE_WPA2_CALLBACKS 419 handshake_captured_callback_type handshake_captured_callback_;
420 ap_found_callback_type ap_found_callback_;
421 #endif // TINS_HAVE_WPA2_CALLBACKS 423 #endif // TINS_HAVE_WPA2_DECRYPTION 433 template<
typename Functor,
typename Decrypter>
454 const decrypter_type& decr = decrypter_type());
459 decrypter_type& decrypter();
464 const decrypter_type& decrypter()
const;
470 bool operator() (
PDU& pdu);
473 decrypter_type decrypter_;
483 template<
typename Functor>
486 #ifdef TINS_HAVE_WPA2_DECRYPTION 494 template<
typename Functor>
498 #endif // TINS_HAVE_WPA2_DECRYPTION 504 template<
typename Functor,
typename Decrypter>
506 const decrypter_type& decr)
507 : functor_(func), decrypter_(decr) {
511 template<
typename Functor,
typename Decrypter>
517 template<
typename Functor,
typename Decrypter>
523 template<
typename Functor,
typename Decrypter>
525 return decrypter_.decrypt(pdu) ? functor_(pdu) :
true;
528 template<
typename Functor>
536 #endif // TINS_CRYPTO_H decrypter_type & decrypter()
Retrieves a reference to the decrypter object.
Definition: crypto.h:513
Definition: handshake_capturer.h:109
DecrypterProxy(const functor_type &func, const decrypter_type &decr=decrypter_type())
Constructs an object from a functor and a decrypter.
Definition: crypto.h:505
EAPOLHandshake< RSNEAPOL > RSNHandshake
Definition: handshake_capturer.h:104
Generic EAPOL handshake.
Definition: handshake_capturer.h:51
Decrypter decrypter_type
Definition: crypto.h:444
Represents an IEEE 802.11 data frame.
Definition: dot11_data.h:43
bool operator()(PDU &pdu)
The operator() which decrypts packets and forwards them to the functor.
Definition: crypto.h:524
Decrypts WEP-encrypted traffic.
Definition: crypto.h:178
The Tins namespace.
Definition: address_range.h:38
Pluggable decrypter object which can be used to decrypt data on sniffing sessions.
Definition: crypto.h:434
Functor functor_type
Definition: crypto.h:439
Base class for protocol data units.
Definition: pdu.h:107