Пример #1
0
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
Пример #2
0
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
Пример #3
0
    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)
Пример #4
0
    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)
Пример #5
0
    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)
Пример #6
0
    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)
Пример #7
0
    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
Пример #8
0
    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
Пример #9
0
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
Пример #10
0
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
Пример #11
0
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...'
Пример #12
0
    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()

# 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)
Пример #13
0
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()
Пример #14
0
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()
Пример #15
0
           hs = hiddenService()
           print 'Waiting for ' + USER2 + ' to connect...'

        elif mode == '--client':
    	   print "client"

        #mode == --auth
        else:
            newaxo = Axolotl(USER1, dbname=USER2+'.db')
            newaxo.printKeys()
            ans = raw_input('Do you want to create a new Axolotl database? Y/N ')

            if ans.lower() == 'y':
                identity = raw_input('What is the identity key for the other party? ')
                ratchet = raw_input('What is the ratchet key for the other party? ')
                handshake = raw_input('What is the handshake key for the other party? ')

                newaxo.initState(OTHER_NICK, binascii.a2b_base64(identity),
                              binascii.a2b_base64(handshake),
                         binascii.a2b_base64(ratchet))
                newaxo.saveState()

                print 'The database for ' + USER1 + ' -> ' + USER2 + ' has been saved.'
            else:
                print 'OK, nothing has been saved...' 

    else:
        arg_info()	


Пример #16
0
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...'

Пример #17
0
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()