-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlight_client.py
executable file
·58 lines (46 loc) · 1.45 KB
/
light_client.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
#Import needed libs
import socket
from keyczar import keyczar
from keyczar import keyczart
from keyczar.errors import KeyczarError
def main():
PUB_KEY = "/home/pi/.keys/public"
PVT_KEY = "/home/pi/.keys/private"
#Test environment
#PUB_KEY = "/Users/wmm125/.ssh/raspberry/keys/public"
#PVT_KEY = "/Users/wmm125/.ssh/raspberry/keys/private"
#MSGLEN = 690
MSGLEN = 178
print "Loading Private/Public keys.."
crypter = keyczar.Encrypter.Read(PUB_KEY)
decrypter = keyczar.Crypter.Read(PVT_KEY)
print "starting client..."
#Create a socket object
s = socket.socket()
#Get local machine name
host = socket.gethostbyname("mmmarq.dnsdynamic.net")
print host
#Reserve a port for your service.
port = 50004
s.connect((host, port))
while True:
command = raw_input('Enter command: ')
if ( command == 'gate.open' ):
PASS_PHRASE = raw_input('Enter pass code: ')
command = command + '|' + PASS_PHRASE
data = crypter.Encrypt(command)
print "Sending: " + decrypter.Decrypt(data) + " [" + str(len(data)) + "]"
s.send(data)
print "Waiting response..."
msg = ''
while len(msg) < MSGLEN:
chunk = s.recv(MSGLEN-len(msg))
if chunk == '':
raise RuntimeError("socket connection broken")
msg = msg + chunk
print decrypter.Decrypt(msg)
break
if __name__ == '__main__':
main()