def test_individual_dbs(self, exchange): # create two instance classes with encrypted databases a = Axolotl('angie', dbname=self.dbs[0], dbpassphrase=self.dbs[0]) b = Axolotl('barb', dbname=self.dbs[1], dbpassphrase=self.dbs[1]) # initialize the states a.initState(other_name=b.name, other_identityKey=b.state['DHIs'], other_handshakeKey=b.handshakePKey, other_ratchetKey=b.state['DHRs'], verify=False) b.initState(other_name=a.name, other_identityKey=a.state['DHIs'], other_handshakeKey=a.handshakePKey, other_ratchetKey=a.state['DHRs'], verify=False) # save the states a.saveState() b.saveState() # reload the databases a = Axolotl('angie', dbname=self.dbs[0], dbpassphrase=self.dbs[0]) b = Axolotl('barb', dbname=self.dbs[1], dbpassphrase=self.dbs[1]) # load their states a.loadState(a.name, b.name) b.loadState(b.name, a.name) # send some messages back and forth exchange(a, b)
def test_passphrase(self, passphrase_0, passphrase_1): a = Axolotl('Angie', dbpassphrase=passphrase_0) b = Axolotl('Barb', dbpassphrase=None) a.initState(other_name=b.name, other_identityKey=b.state['DHIs'], other_handshakeKey=b.handshakePKey, other_ratchetKey=b.state['DHRs'], verify=False) a.saveState() if passphrase_0 == passphrase_1: a = Axolotl('Angie', dbpassphrase=passphrase_1) assert isinstance(a.db, sqlite3.Connection) else: with pytest.raises(SystemExit): a = Axolotl('Angie', dbpassphrase=passphrase_1)
def test_shared_db(self): # create two instance classes - one which will share its database # (note that Dick and Harry's passphrases must match or Harry won't # be able to load Dick's saved database) shared_pass = '******' tom = Axolotl('Tom', dbpassphrase="tom's passphrase") dick = Axolotl('Dick', dbpassphrase=shared_pass) # initialize Tom and Dick's states tom.initState(other_name=dick.name, other_identityKey=dick.state['DHIs'], other_handshakeKey=dick.handshakePKey, other_ratchetKey=dick.state['DHRs'], verify=False) dick.initState(other_name=tom.name, other_identityKey=tom.state['DHIs'], other_handshakeKey=tom.handshakePKey, other_ratchetKey=tom.state['DHRs'], verify=False) # get the plaintext msg = 'plaintext' # Tom encrypts it to Dick ciphertext = tom.encrypt(msg) # save Dick's state prior to decrypting the message dick.saveState() # Dick decrypts the ciphertext assert dick.decrypt(ciphertext) == msg # now load Dick's state to Harry harry = Axolotl('Harry', dbpassphrase=shared_pass) harry.loadState(dick.name, tom.name) # Harry decrypts the ciphertext assert harry.decrypt(ciphertext) == msg
#!/usr/bin/env python """ A three-toed Axolotl track ;-) """ from pyaxo import Axolotl # create two instance classes a = Axolotl("Angie") b = Axolotl("Barb") # initialize their states a.initState("Barb", b.state["DHIs"], b.handshakePKey, b.state["DHRs"], verify=False) b.initState("Angie", a.state["DHIs"], a.handshakePKey, a.state["DHRs"], verify=False) # tell who is who if a.mode: print "Angie is Alice-like" print "Barb is Bob-like" else: print "Angie is Bob-like" print "Barb is Alice-like" # Walk the three-toed Axolotl walk.. msg0 = a.encrypt("Step 1, Toe 1") msg1 = a.encrypt("Step 1, Toe 2") msg2 = a.encrypt("Step 1, Toe 3") print "b decrypt: ", b.decrypt(msg0) print "b decrypt: ", b.decrypt(msg1) print "b decrypt: ", b.decrypt(msg2)
#!/usr/bin/env python import os from pyaxo import Axolotl # start with a fresh database try: os.remove('./alice.db') os.remove('./bob.db') except OSError: pass # unencrypted databases a = Axolotl('alice', dbname='alice.db', dbpassphrase=None) b = Axolotl('bob', dbname='bob.db', dbpassphrase=None) a.initState('bob', b.state['DHIs'], b.handshakePKey, b.state['DHRs'], verify=False) b.initState('alice', a.state['DHIs'], a.handshakePKey, a.state['DHRs'], verify=False) a.saveState() b.saveState()
If you decide not to complete the initialization process, just answer no to the question about creating a new conversation. Nothing will be saved. If you want to reinitialize a conversation, just run the script again. The old conversation key data will be overwritten in the databases. """ import sys import binascii from pyaxo import Axolotl your_name = raw_input('Your name for this conversation? ').strip() other_name = raw_input('What is the name of the other party? ').strip() a = Axolotl(your_name, dbname=your_name + '.db') b = Axolotl(other_name, dbname=other_name + '.db') a.initState(other_name, b.state['DHIs'], b.handshakePKey, b.state['DHRs'], verify=False) b.initState(your_name, a.state['DHIs'], a.handshakePKey, a.state['DHRs'], verify=False) a.saveState() b.saveState() print 'The conversation ' + your_name + ' -> ' + other_name + ' has been saved in: ' + your_name + '.db' print 'The conversation ' + other_name + ' -> ' + your_name + ' has been saved in: ' + other_name + '.db'
#!/usr/bin/env python from pyaxo import Axolotl import sys import os # start with a fresh database try: os.remove('./name1.db') os.remove('./name2.db') except OSError: pass # unencrypted databases a = Axolotl('name1', dbname='name1.db', dbpassphrase=None) b = Axolotl('name2', dbname='name2.db', dbpassphrase=None) a.initState('name2', b.state['DHIs'], b.handshakePKey, b.state['DHRs'], verify=False) b.initState('name1', a.state['DHIs'], a.handshakePKey, a.state['DHRs'], verify=False) a.saveState() b.saveState()
If you decide not to complete the initialization process, just answer no to the question about creating a new conversation. Nothing will be saved. If you want to reinitialize a conversation, just run the script again. The old conversation key data will be overwritten in the database. """ import sys import binascii from pyaxo import Axolotl your_name = raw_input('Your name for this conversation? ').strip() a = Axolotl(your_name) a.printKeys() ans = raw_input('Do you want to create a new conversation? y/N ').strip() if ans == 'y': other_name = raw_input('What is the name of the other party? ').strip() identity = raw_input( 'What is the identity key for the other party? ').strip() handshake = raw_input( 'What is the handshake key for the other party? ').strip() ratchet = raw_input( 'What is the ratchet key for the other party? ').strip() a.initState(other_name, binascii.a2b_base64(identity), binascii.a2b_base64(handshake), binascii.a2b_base64(ratchet)) a.saveState() print 'The conversation ' + your_name + ' -> ' + other_name + ' has been saved.' else: print 'OK, nothing has been saved...'
elif step == 6: step6 = sm_py.step_6(payload, smKeys) if step6["success"] != 1: # print('Socialist millionaire protocol failed') # print('after 6') sys.exit() smWait = False except: print("Socialist millionaire protocol failed") # print('on receive') sys.exit() sleep(0.01) a.initState( OTHER_NICK, binascii.a2b_base64(obj["identity"].strip()), binascii.a2b_base64(obj["handshakekey"].strip()), binascii.a2b_base64(obj["ratchet"].strip()), False, ) a.saveState() chatThread() elif mode == "-c": a = Axolotl(NICK, dbname=OTHER_NICK + ".db") a.postKeys() smUrl = "https://lab3key.herokuapp.com/messages" smPayload = {"message": {"source": NICK, "destination": OTHER_NICK, "isSMP": True, "typeSMP": 1, "payload": ""}} smParams = json.dumps(smPayload) smReq = urllib2.Request(smUrl, data=smParams, headers={"content-type": "application/json"}) try: response = urllib2.urlopen(smReq)
in their weechat configuration directory. You should only need to generate and distribute the databases once per nick pair. If each party wishes to generate their own database, you can use the init_conversations.py script in the utilities directory of the Axolotl distribution. """ import sys import binascii from pyaxo import Axolotl # modify this as appropriate (also modify axolotl.worker.py to match) def getPasswd(username): return username + "123" your_nick = raw_input("Your nick for this conversation? ").strip() other_nick = raw_input("What is the nick of the other party? ").strip() a = Axolotl(your_nick, dbname=other_nick + ".db", dbpassphrase=getPasswd(other_nick)) b = Axolotl(other_nick, dbname=your_nick + ".db", dbpassphrase=getPasswd(your_nick)) a.initState(other_nick, b.state["DHIs"], b.handshakePKey, b.state["DHRs"], verify=False) b.initState(your_nick, a.state["DHIs"], a.handshakePKey, a.state["DHRs"], verify=False) a.saveState() b.saveState() print "The keys for " + your_nick + " -> " + other_nick + " have been saved in: " + other_nick + ".db" print "The keys for " + other_nick + " -> " + your_nick + " have been saved in: " + your_nick + ".db"
""" This script will generate a pair of databases named after two conversants. The databases can then be securely distributed to initialize axolotl. You will need to provide your name and the other party's name. Conversations are identified by your name and the other person's name. The conversation should have a unique other person's name. If you decide not to complete the initialization process, just answer no to the question about creating a new conversation. Nothing will be saved. If you want to reinitialize a conversation, just run the script again. The old conversation key data will be overwritten in the databases. """ import sys import binascii from pyaxo import Axolotl your_name = raw_input('Your name for this conversation? ').strip() other_name = raw_input('What is the name of the other party? ').strip() a = Axolotl(your_name,dbname=your_name+'.db') b = Axolotl(other_name,dbname=other_name+'.db') a.initState(other_name, b.state['DHIs'], b.handshakePKey, b.state['DHRs'], verify=False) b.initState(your_name, a.state['DHIs'], a.handshakePKey, a.state['DHRs'], verify=False) a.saveState() b.saveState() print 'The conversation ' + your_name + ' -> ' + other_name + ' has been saved in: ' + your_name + '.db' print 'The conversation ' + other_name + ' -> ' + your_name + ' has been saved in: ' + other_name + '.db'
from pyaxo import Axolotl # need clean database for this example to work try: os.remove('./axolotl.db') except OSError: pass # create two instance classes with unencrypted database a = Axolotl('Angie', dbpassphrase=None) b = Axolotl('Barb', dbpassphrase=None) # initialize their states a.initState('Barb', b.state['DHIs'], b.handshakePKey, b.state['DHRs'], verify=False) b.initState('Angie', a.state['DHIs'], a.handshakePKey, a.state['DHRs'], verify=False) # tell who is who if a.mode: print 'Angie is Alice-like' print 'Barb is Bob-like' else: print 'Angie is Bob-like' print 'Barb is Alice-like' # send some messages back and forth msg0 = a.encrypt('message 0') print 'b decrypt: ', b.decrypt(msg0) msg1 = b.encrypt('message 1')
s.bind((HOST, PORT)) s.listen(1) conn, addr = s.accept() chatThread(conn) elif mode == '-c': HOST = raw_input('Enter the server: ') print 'Connecting to ' + HOST + '...' with socketcontext(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect((HOST, PORT)) chatThread(s) elif mode == '-g': a = Axolotl(NICK, dbname=OTHER_NICK+'.db') a.printKeys() ans = raw_input('Do you want to create a new Axolotl database? y/N ').strip() if ans == 'y': identity = raw_input('What is the identity key for the other party? ').strip() ratchet = raw_input('What is the ratchet key for the other party? ').strip() handshake = raw_input('What is the handshake key for the other party? ').strip() a.initState(OTHER_NICK, binascii.a2b_base64(identity), binascii.a2b_base64(handshake), binascii.a2b_base64(ratchet)) a.saveState() print 'The database for ' + NICK + ' -> ' + OTHER_NICK + ' has been saved.' else: print 'OK, nothing has been saved...' else: usage()
# need clean database for this example to work try: os.remove('./axolotl.db') except OSError: pass # create three instance classes - axolotl will prompt for database passphrases # Note that dick and harry's passphrases must match or harry won't be able to # load dick's saved database tom = Axolotl('Tom') dick = Axolotl('Dick') harry = Axolotl('Harry') # initialize Tom and Dick's states tom.initState('Dick', dick.state['DHIs'], dick.handshakePKey, dick.state['DHRs'], verify=False) dick.initState('Tom', tom.state['DHIs'], tom.handshakePKey, tom.state['DHRs'], verify=False) # tell who is who if tom.mode: print 'Tom is Alice-like' print 'Dick is Bob-like' else: print 'Tom is Bob-like' print 'Dick is Alice-like' print # get the plaintext with open('file.txt', 'r') as f: msg = f.read()
the same for each conversation or different for each one or any combination. If you decide not to complete the initialization process, just answer no to the question about creating a new conversation. Nothing will be saved. If you want to reinitialize a conversation, just run the script again. The old conversation key data will be overwritten in the database. """ import sys import binascii from pyaxo import Axolotl your_name = raw_input('Your name for this conversation? ').strip() a = Axolotl(your_name) a.printKeys() ans = raw_input('Do you want to create a new conversation? y/N ').strip() if ans == 'y': other_name = raw_input('What is the name of the other party? ').strip() identity = raw_input('What is the identity key for the other party? ').strip() handshake = raw_input('What is the handshake key for the other party? ').strip() ratchet = raw_input('What is the ratchet key for the other party? ').strip() a.initState(other_name, binascii.a2b_base64(identity), binascii.a2b_base64(handshake), binascii.a2b_base64(ratchet)) a.saveState() print 'The conversation ' + your_name + ' -> ' + other_name + ' has been saved.' else: print 'OK, nothing has been saved...'
def main(): global lock, screen_needs_update, NICK, OTHER_NICK mode = None try: mode = sys.argv[1] except: usage() NICK = raw_input("Enter your nick: ") OTHER_NICK = raw_input("Enter the nick of the other party: ") lock = threading.Lock() screen_needs_update = False host = "" port = 50000 while True: try: if mode == "-g": port = 50000 # dummy assignment break port = raw_input("TCP port (1 for random choice, 50000 is default): ") port = int(port) break except ValueError: break if 1025 <= port <= 65535: pass elif port == 1: port = 1025 + randint(0, 64510) print("PORT is " + str(port)) if mode == "-s": print("Waiting for " + OTHER_NICK + " to connect...") with socketcontext(socket.AF_INET, socket.SOCK_STREAM) as s: s.bind((host, port)) s.listen(1) conn, addr = s.accept() chat_thread(conn) elif mode == "-c": host = raw_input("Enter the server: ") print("Connecting to " + host + "...") with socketcontext(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect((host, port)) chat_thread(s) elif mode == "-g": a = Axolotl(NICK, dbname=OTHER_NICK + ".db") a.printKeys() ans = raw_input("Do you want to create a new Axolotl database? y/N ").strip() if ans == "y": identity = raw_input("What is the identity key for the other party? ").strip() ratchet = raw_input("What is the ratchet key for the other party? ").strip() handshake = raw_input("What is the handshake key for the other party? ").strip() a.initState( OTHER_NICK, binascii.a2b_base64(identity), binascii.a2b_base64(handshake), binascii.a2b_base64(ratchet) ) a.saveState() print("The database for " + NICK + " -> " + OTHER_NICK + " has been saved.") else: print("OK, nothing has been saved...") else: usage()