def decrypt(data, msgtype, servername, args): global decrypted hostmask, chanmsg = string.split(args, "PRIVMSG ", 1) channelname, message = string.split(chanmsg, " :", 1) if re.match(r'^\[\d{2}:\d{2}:\d{2}]\s', message): timestamp = message[:11] message = message[11:] else: timestamp = '' if channelname[0] == "#": username=channelname else: username, rest = string.split(hostmask, "!", 1) username = username[1:] nick = channelname.strip() if os.path.exists(weechat_dir + '/' + username + '.db'): a = Axolotl(nick, dbname=weechat_dir+'/'+username+'.db', dbpassphrase=getPasswd(username)) a.loadState(nick, username) decrypted = a.decrypt(a2b_base64(message)) a.saveState() del a if decrypted == "": return args decrypted = ''.join(c for c in decrypted if ord(c) > 31 or ord(c) == 9 or ord(c) == 2 or ord(c) == 3 or ord(c) == 15) return hostmask + "PRIVMSG " + channelname + " :" + chr(3) + "04" + weechat.config_get_plugin("message_indicator") + chr(15) + timestamp + decrypted else: return args
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_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 decrypt(data, msgtype, servername, args): global decrypted hostmask, chanmsg = string.split(args, "PRIVMSG ", 1) channelname, message = string.split(chanmsg, " :", 1) if re.match(r'^\[\d{2}:\d{2}:\d{2}]\s', message): timestamp = message[:11] message = message[11:] else: timestamp = '' if channelname[0] == "#": username = channelname else: username, rest = string.split(hostmask, "!", 1) username = username[1:] buf = weechat.current_buffer() nick = weechat.buffer_get_string(buf, 'localvar_nick') if os.path.exists(weechat_dir + '/' + username + '.db'): a = Axolotl(nick, dbname=weechat_dir + '/' + username + '.db', dbpassphrase=getPasswd(username)) a.loadState(nick, username) decrypted = a.decrypt(a2b_base64(message)) a.saveState() del a if decrypted == "": return args decrypted = ''.join(c for c in decrypted if ord(c) > 31 or ord(c) == 9 or ord(c) == 2 or ord(c) == 3 or ord(c) == 15) return hostmask + "PRIVMSG " + channelname + " :" + chr( 3) + "04" + weechat.config_get_plugin("message_indicator") + chr( 15) + timestamp + decrypted else: return args
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
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
def encrypt(data, msgtype, servername, args): global encrypted pre, message = string.split(args, ":", 1) prestr=pre.split(" ") username=prestr[-2] buf = weechat.current_buffer() nick = weechat.buffer_get_string(buf, 'localvar_nick') if os.path.exists(weechat_dir + '/' + username + '.db'): a = Axolotl(nick, dbname=weechat_dir+'/'+username+'.db', dbpassphrase=getPasswd(username)) a.loadState(nick, username) encrypted = a.encrypt(message) if encrypted == '': return args encrypted = b2a_base64(encrypted) a.saveState() del a encrypted = encrypted.replace("\n","") final_msg = pre + ":" +encrypted if len(encrypted) > 400: # I arrived at this next equation heuristically. If it doesn't work, let me know # and I will work on it some more. -DRA numsplits = 2*int(len(encrypted)/400) + 1 splitmsg=string.split(message," ") cutpoint=int(len(splitmsg)/numsplits) encrypted_list = [] for i in range(numsplits+1): if min((i+1)*cutpoint, len(splitmsg)) == (i+1)*cutpoint: segment = string.join(splitmsg[i*cutpoint:(i+1)*cutpoint]," ") + "\n" a = Axolotl(nick, dbname=weechat_dir+'/'+username+'.db', dbpassphrase=getPasswd(username)) a.loadState(nick, username) encrypted = b2a_base64(a.encrypt(segment)) a.saveState() del a valid_segment = True else: segment = string.join(splitmsg[i*cutpoint:]," ") if segment.strip() is None or len(segment) == 0: valid_segment = False else: a = Axolotl(nick, dbname=weechat_dir+'/'+username+'.db', dbpassphrase=getPasswd(username)) a.loadState(nick, username) encrypted = b2a_base64(a.encrypt(segment)) a.saveState() del a valid_segment = True encrypted = encrypted.replace("\n","") if valid_segment: encrypted_list += [encrypted] final_msg = '' for item in encrypted_list: final_msg = final_msg + pre + ":" + item + '\n' return final_msg return encrypted else: return args
def encrypt(data, msgtype, servername, args): global encrypted pre, message = string.split(args, ":", 1) prestr=pre.split(" ") username=prestr[-2] buf = weechat.current_buffer() nick = weechat.buffer_get_string(buf, 'localvar_nick') if os.path.exists(weechat_dir + '/' + username + '.db'): a = Axolotl(nick, dbname=weechat_dir+'/'+username+'.db', dbpassphrase=getPasswd(username)) a.loadState(nick, username) encrypted = a.encrypt(message) if encrypted == '': return args encrypted = b2a_base64(encrypted) a.saveState() del a encrypted = encrypted.replace("\n","") final_msg = pre + ":" +encrypted if len(encrypted) > 400: # I arrived at this next equation heuristically. If it doesn't work, let me know # and I will work on it some more. -DRA numsplits = 2*int(len(encrypted)/400) + 1 splitmsg=string.split(message," ") cutpoint=int(len(splitmsg)/numsplits) encrypted_list = [] for i in range(numsplits+1): if min((i+1)*cutpoint, len(splitmsg)) == (i+1)*cutpoint: segment = string.join(splitmsg[i*cutpoint:(i+1)*cutpoint]," ") + "\n" a = Axolotl(nick, dbname=weechat_dir+'/'+username+'.db', dbpassphrase=getPasswd(username)) a.loadState(nick, username) encrypted = b2a_base64(a.encrypt(segment)) a.saveState() del a valid_segment = True else: segment = string.join(splitmsg[i*cutpoint:]," ") if segment.strip() is None or len(segment) == 0: valid_segment = False else: a = Axolotl(nick, dbname=weechat_dir+'/'+username+'.db', dbpassphrase=getPasswd(username)) a.loadState(nick, username) encrypted = b2a_base64(a.encrypt(segment)) a.saveState() del a valid_segment = True encrypted = encrypted.replace("\n","") if valid_segment: encrypted_list += [encrypted] final_msg = '' for item in encrypted_list: final_msg = final_msg + pre + ":" + item + '\n' return final_msg return encrypted else: return args
#!/usr/bin/env python from pyaxo import Axolotl argv = ['progname', '-e', 'testfile.md'] a = Axolotl('name1', dbname='name1.db', dbpassphrase=None) a.loadState('name1', 'name2') if argv[1] == '-e': a.encrypt_file(argv[2]) print 'Encrypted file is ' + argv[2] + '.asc' else: a.decrypt_file(argv[2]) a.saveState()
your_name = raw_input("What is your name? ").strip() # specify dbname with kwarg - default dbname is axolotl.db db passphrase # will be prompted for - it can be specified here with dbpassprase kwarg a = Axolotl(your_name, dbname=your_name + ".db") other_name = None try: if sys.argv[1] == "-e": other_name = raw_input( "What is the name of the party \ that you want to encrypt the file to? " ).strip() a.loadState(your_name, other_name) a.encrypt_file(sys.argv[2]) print "The encrypted file is: " + sys.argv[2] + ".asc" else: other_name = raw_input( "What is the name of the party that \ you want to decrypt the file from? " ).strip() a.loadState(your_name, other_name) a.decrypt_file(sys.argv[2]) except IndexError: print "Usage: " + sys.argv[0] + " -(e,d) <filename>" exit() except KeyError: print "The conversation " + your_name + " -> " + other_name + " is not in the database"
print 'Tom is Bob-like' print 'Dick is Alice-like' print # get the plaintext with open('file.txt', 'r') as f: msg = f.read() # Tom encrypts it to Dick ciphertext = tom.encrypt(msg) # save Dick's state prior to decrypting the message dick.saveState() # Dick decrypts the ciphertext print "Dick's decryption..." print dick.decrypt(ciphertext) # now load Dick's state to Harry print print "Harry is loading Dick's state..." harry.loadState('Dick', 'Tom') # Harry decrypts the ciphertext print print "Harry's decryption..." print harry.decrypt(ciphertext) # they match, so the two states are the same!!!
def axo(my_name, other_name, dbname, dbpassphrase): a = Axolotl(my_name, dbname=dbname, dbpassphrase=dbpassphrase) a.loadState(my_name, other_name) yield a a.saveState()
def axo(my_name, other_name, dbname, dbpassphrase): a = Axolotl(my_name, dbname=dbname, dbpassphrase=dbpassphrase) a.loadState(my_name, other_name) yield a a.saveState()
#!/usr/bin/env python import os from pyaxo import Axolotl name1 = 'Angie' name2 = 'Barb' a = Axolotl(name1, dbname='name1.db', dbpassphrase=None) b = Axolotl(name2, dbname='name2.db', dbpassphrase=None) a.loadState(name1, name2) b.loadState(name2, name1) topic = [' My Name', 'Other Name', ' RK', ' HKs', ' HKr', ' NHKs', ' NHKr', ' CKs', ' CKr', ' DHIs_priv', ' DHIs', ' DHIr', ' DHRs_priv', ' DHRs', ' DHRr', ' CONVid',
#!/usr/bin/env python from pyaxo import Axolotl import sys a = Axolotl('name1', dbname='name1.db', dbpassphrase=None) a.loadState('name1', 'name2') if sys.argv[1] == '-e': a.encrypt_file(sys.argv[2]) print 'Encrypted file is ' + sys.argv[2] + '.asc' else: a.decrypt_file(sys.argv[2]) a.saveState()
def axo(my_name, other_name, dbname, dbpassphrase): global a a = Axolotl(my_name, dbname=dbname, dbpassphrase=dbpassphrase, nonthreaded_sql=False) a.loadState(my_name, other_name)
#!/usr/bin/env python import copy import os from pyaxo import Axolotl name1 = 'Angie' name2 = 'Barb' a = Axolotl(name1, dbname='name1.db', dbpassphrase=None) b = Axolotl(name2, dbname='name2.db', dbpassphrase=None) a.loadState(name1, name2) b.loadState(name2, name1) topic = [ ' My Name', 'Other Name', ' RK', ' HKs', ' HKr', ' NHKs', ' NHKr', ' CKs', ' CKr', ' DHIs_priv', ' DHIs', ' DHIr', ' DHRs_priv', ' DHRs', ' DHRr', ' CONVid', ' Ns', ' Nr', ' PNs', ' ratchet', ' mode' ] def hilite(text, c=False): attr = [] if c: attr.append('41') return '\x1b[%sm%s\x1b[0m' % (';'.join(attr), text)
""" from pyaxo import Axolotl import sys your_name = raw_input('What is your name? ').strip() # specify dbname with kwarg - default dbname is axolotl.db # db passphrase will be prompted for - it can be specified here with dbpassprase kwarg a = Axolotl(your_name, dbname=your_name + '.db') try: if sys.argv[1] == '-e': other_name = \ raw_input("What is the name of the party that you want to encrypt the file to? " ).strip() a.loadState(your_name, other_name) a.encrypt_file(sys.argv[2]) print 'The encrypted file is: ' + sys.argv[2] + '.asc' else: other_name = \ raw_input("What is the name of the party that you want to decrypt the file from? " ).strip() a.loadState(your_name, other_name) a.decrypt_file(sys.argv[2]) except IndexError: print 'Usage: ' + sys.argv[0] + ' -(e,d) <filename>' exit() except KeyError: print 'The conversation ' + your_name + ' -> ' + other_name + \ ' is not in the database' exit()