-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathauditor_proximity_oracle.py
108 lines (90 loc) · 3.95 KB
/
auditor_proximity_oracle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"""Proximity Oracle
"""
from __future__ import absolute_import
import auditor_constants as const
from libs import verbose as vb
from time import time
class ProximityOracle(object):
"""Generic proximity oracle class
Allows a user to define their own oracle depending on the service
"""
def set_radius(self, radius):
"""Set the radius for a DUDP-behavior-like oracle
"""
raise AttributeError('set_radius undefined in child class')
def in_proximity(self, _auditor_user_a, _auditor_user_b):
"""
- To be defined by inherited classes.
This function should be inherited by the specific service auditing class
and should True or False depeding on the oracle outcome
"""
raise AttributeError('in_proximity undefined in child class')
class DiskProximityOracle(ProximityOracle):
"""Defines a disk proximity oracle
"""
def __init__(self, auditor, radius, verbose=True):
"""Initiate radius in km for disk oracle
"""
self.auditor = auditor
self.radius = radius
self.verbose = verbose
def set_radius(self, radius):
"""Set the radius for a DUDP-behavior-like oracle
"""
self.radius = radius
def in_proximity(self, auditor_user_a, auditor_user_b, test_id):
"""auditor_user_a examines if auditor_user_b is in proximity radius
(in km) using a disk proximity oracle
Args:
auditor_user_a: auditor user instance for attacker
auditor_user_b: auditor user instance for target
radius: radius of disk in km
Returns:
(answer, queries) where @answer is True if user_b is in proximity
to user_a with respect to the oracle else False.
"""
vb.vb_print(self.verbose, "Examining oracle:", "DUDP", True)
query_id = int(time())
(dist, q) = self.auditor.auditor_handled_distance(auditor_user_a,
auditor_user_b,
test_id,
auditor_user_a.loc,
query_id)
if dist is None:
vb.vb_print(self.verbose, " |-- None", "DUDP", True)
return (None, 1)
if dist < self.radius:
vb.vb_print(self.verbose, " |-- True", "DUDP", True)
return (True, q)
else:
vb.vb_print(self.verbose, " |-- False", "DUDP", True)
return (False, q)
class RoundingProximityOracle(ProximityOracle):
"""Defines a rounding proximity oracle
"""
def __init__(self, auditor, rounding_classes, verbose=True):
"""Initiate the class of intervals for this proximity oracle
Args:
@rounding_classes is a list of rounding classes in the form
[range (in km), rounding (in km), rounding_type], ex.
the class [[0.1, 0.2], 0.005, const.ROUNDING.UP] denotes that
from 100m to 200m, the services rounds up the returned distance
by 5m
"""
self.auditor = auditor
self.round_cl = rounding_classes
self.verbose = verbose
def in_proximity(self, auditor_user_a, auditor_user_b, test_id):
"""auditor_user_a gets the distance from auditor_user_b
using the disk proximity oracle
Args:
auditor_user_a: auditor user instance for attacker
auditor_user_b: auditor user instance for target
"""
vb.vb_print(self.verbose, "Examining oracle:", "RUDP", True)
query_id = int(time())
return self.auditor.auditor_handled_distance(auditor_user_a,
auditor_user_b,
test_id,
auditor_user_a.loc,
query_id)