Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
61 lines (44 sloc) 1.51 KB
Secnode server.
This server accepts TCP connections from a remote device and decrypts them.
by Travis Howse <>
2012. License, GPL v2 or later
from Crypto.Cipher import AES
import SocketServer
import sys
def toHex(s):
lst = []
for ch in s:
hv = hex(ord(ch)).replace('0x', '')
if len(hv) == 1:
hv = '0'+hv
return reduce(lambda x,y:x+y, lst)
class MyTCPHandler(SocketServer.BaseRequestHandler):
The RequestHandler class for our server.
It is instantiated once per connection to the server, and must
override the handle() method to implement communication to the
def handle(self):
# self.request is the TCP socket connected to the client = self.request.recv(16)
#print "{} wrote:".format(self.client_address[0])
#print sys.getsizeof(
if (sys.getsizeof( == 37):
obj2 ='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', AES.MODE_ECB)
print toHex(obj2.decrypt(
#TODO Calculate the checksum, check it, if it passes, send back an ack.
print "Lost a message! Very bad!"
# just send back the same data, but upper-cased
if __name__ == "__main__":
HOST, PORT = "", 5555
# Create the server, binding to localhost on port 9999
server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)
# Activate the server; this will keep running until you
# interrupt the program with Ctrl-C
Something went wrong with that request. Please try again.