forked from SeattleTestbed/seattlelib_v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecureclient.r2py
99 lines (73 loc) · 2.83 KB
/
secureclient.r2py
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
"""
<Program Name>
advertise_client.r2py
<Started>
August 3, 2011
<Author>
Sebastian Morgan sebass63@uw.edu
<Purpose>
Provides a command-line interface for sending advertisement queries
to a central-style secured advertise server.
"""
dy_import_module_symbols("secureadvertise_client.r2py")
dy_import_module_symbols("serialize.r2py")
dy_import_module_symbols("rsa.r2py")
dy_import_module_symbols("session.r2py")
# Default location of public and private keys.
mycontext['default_keyfiles'] = ('advertise.publickey', 'advertise.privatekey')
# Default size of public and private keys.
mycontext['default_keysize'] = 1024
# Default advertise server address.
mycontext['advertise_address'] = "128.208.4.96"
# Default advertise server port.
mycontext['advertise_port'] = 49010
# Default outsocket port for sending.
mycontext['out_port'] = 49000
# Default maximum number of return values.
mycontext['default_maxvals'] = 20
def blocking_recv(socketobj):
success = False
raw_response = ""
while not success:
try:
raw_response = session_recvmessage(socketobj)
success = True
except SocketWouldBlockError:
sleep(0.005)
return raw_response
if callfunc == 'initialize':
# Right now this whole method is a little sloppy, with uncaught input
# errors and that sort of thing. I will have this resolved soon.
# -Sebastian
if len(callargs) < 1:
log("ERROR: No arguments provided!\n")
# Currently, this will overwrite any existing keys that you have.
# I can't really think of a better way to do this.
elif callargs[0].lower() == 'createkeys':
log(" > Creating keys . . . ")
public_key, private_key = rsa_gen_pubpriv_keys(1024)
log("Done.\n")
log(" > Writing keys to file . . . ")
rsa_publickey_to_file(public_key, mycontext['default_keyfiles'][0])
rsa_privatekey_to_file(private_key, mycontext['default_keyfiles'][1])
log("Done.\n")
elif callargs[0].lower() == 'put':
if len(callargs) < 3:
log(" > Not enough arguments provided. PUT usage:\n")
log(" > advertise_client.r2py put <value> <time to live>\n")
else:
advertise_val = callargs[1]
advertise_ttl = int(callargs[2])
log(" > Loading keys . . . ")
public_key = rsa_file_to_publickey(mycontext['default_keyfiles'][0])
private_key = rsa_file_to_privatekey(mycontext['default_keyfiles'][1])
log("Done.\n")
log(" > Attempting announce . . . ")
result = secureadvertise_announce(public_key, private_key, advertise_val, advertise_ttl)
log("Done.\n")
log(" > Advertise Result: " + str(result) + "\n")
elif callargs[0].lower() == 'get':
get_key = rsa_file_to_publickey(mycontext['default_keyfiles'][0])
data = secureadvertise_lookup(get_key)
log(" > GET data received. Server returned the following answers:\n")
log(" > " + str(data[1]) + "\n")