00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FILTER_ANON_POLICIES_HH_
00023 # define FILTER_ANON_POLICIES_HH_
00024
00025 # include <map>
00026 # include <set>
00027
00028 # ifdef HAVE_OPENSSL
00029 # include <openssl/evp.h>
00030 # endif // HAVE_OPENSSL
00031
00032 # include <boost/array.hpp>
00033 # include <boost/scoped_ptr.hpp>
00034
00035 # include <wipal/tool/mapping.hh>
00036 # include <wipal/wifi/addr.hh>
00037 # include <wipal/wifi/essid.hh>
00038
00039 namespace wpl
00040 {
00041
00042 namespace wifi
00043 {
00044
00045 namespace anon
00046 {
00047
00048
00049
00050
00051
00052 namespace internals
00053 {
00054
00055 struct ppmp_mapping_factory
00056 {
00057 typedef std::map<addr, addr> mac_map;
00058
00059 addr new_value(const addr& a,
00060 const mac_map& );
00061 void value_loaded(const addr& ,
00062 const addr& a,
00063 const mac_map& );
00064
00065 private:
00066 std::set<addr> values_;
00067 };
00068
00069 }
00070
00071
00072 struct prefix_preserving_mac_policy:
00073 public tool::mapping<addr, addr, internals::ppmp_mapping_factory>
00074 {
00075 typedef tool::mapping<addr, addr, internals::ppmp_mapping_factory>
00076 super_type;
00077
00078 prefix_preserving_mac_policy(const std::string& mapname = "MAC.map");
00079 };
00080
00081
00082
00083
00084
00085 namespace internals
00086 {
00087
00088 struct ppep_mapping_factory
00089 {
00090 typedef std::map<essid, essid> essid_map;
00091
00092 ppep_mapping_factory();
00093
00094 essid new_value(const essid& e,
00095 const essid_map& m);
00096 void value_loaded(const essid& from,
00097 const essid& to,
00098 const essid_map& );
00099 private:
00100
00101 struct node;
00102
00103 std::pair<std::string, node*>
00104 longest_anonymized_prefix(const essid& orig_essid);
00105
00106
00107
00108
00109
00110
00111 struct node
00112 {
00113 node* child(unsigned char c);
00114 std::pair<char, node*> add_valued_child(unsigned char c);
00115 node* add_valued_child(unsigned char c,
00116 unsigned char value);
00117
00118 virtual ~node();
00119
00120 private:
00121 static unsigned char rand_extended();
00122 static unsigned char rand_alnum();
00123 static unsigned char rand_print();
00124 static unsigned char rand_other();
00125 static unsigned char rand_same_class(unsigned char c);
00126
00127 private:
00128 boost::array<boost::scoped_ptr<node>, 256> children_;
00129 std::set<char> children_values_;
00130 };
00131
00132 struct valued_node: public node
00133 {
00134 valued_node(char value);
00135
00136 char value;
00137 };
00138
00139
00140
00141
00142
00143 boost::shared_ptr<node> root_;
00144 };
00145
00146 }
00147
00148 struct prefix_preserving_essid_policy:
00149 public tool::mapping<essid, essid, internals::ppep_mapping_factory>
00150 {
00151 typedef tool::mapping<essid, essid, internals::ppep_mapping_factory>
00152 super_type;
00153
00154 prefix_preserving_essid_policy(const std::string&
00155 mapname = "ESSID.map");
00156 };
00157
00158 # ifdef HAVE_OPENSSL
00159
00160
00161
00162
00163
00164 namespace internals
00165 {
00166
00167 template <class Type, size_t Len>
00168 struct xor_policy
00169 {
00170 xor_policy(const uint8_t* mask, const std::string& seed);
00171 xor_policy(const xor_policy&);
00172 ~xor_policy();
00173
00174 xor_policy& operator = (const xor_policy&);
00175 const Type& operator [] (const Type& x);
00176
00177 private:
00178 typedef std::map<Type, Type> cache_type;
00179
00180 const uint8_t* mask_;
00181 EVP_MD_CTX seed_ctx_;
00182 cache_type cache_;
00183 };
00184
00185 }
00186
00187
00188
00189
00190
00191 struct xor_mac_policy: public internals::xor_policy<addr, sizeof (addr)>
00192 {
00193 typedef internals::xor_policy<addr, sizeof (addr)> super_type;
00194
00195 xor_mac_policy(const std::string& seed);
00196
00197 const addr& operator [] (const addr& x);
00198
00199 private:
00200 static const uint8_t mask_[];
00201 };
00202
00203
00204
00205
00206
00207 struct xor_essid_policy: public internals::xor_policy<essid, 32>
00208 {
00209 typedef internals::xor_policy<essid, 32> super_type;
00210
00211 xor_essid_policy(const std::string& seed);
00212
00213 private:
00214 static const uint8_t mask_[];
00215 };
00216
00217 # endif // HAVE_OPENSSL
00218
00219 }
00220
00221 }
00222
00223 }
00224
00225 # include "anon_policies.hxx"
00226
00227 #endif // ! FILTER_ANON_POLICIES_HH_