예제 #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_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
예제 #4
0
파일: test_db.py 프로젝트: felipedau/pyaxo
    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
예제 #5
0
파일: test4.py 프로젝트: ghtdak/pyaxo
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')
print 'a decrypt: ', a.decrypt(msg1)
msg2 = a.encrypt('message 2')
msg3 = a.encrypt('message 3')
print 'b decrypt: ', b.decrypt(msg2)
msg4 = b.encrypt('message 4')
print 'a decrypt: ', a.decrypt(msg4)
msg5 = a.encrypt('message 5')
print 'b decrypt: ', b.decrypt(msg5)
print 'b decrypt: ', b.decrypt(msg3)

# save the state
a.saveState()
b.saveState()
예제 #6
0
파일: threetoe.py 프로젝트: ghtdak/pyaxo
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)
msg0 = b.encrypt("Step 2, Toe 1")
msg1 = b.encrypt("Step 2, Toe 2")
msg2 = b.encrypt("Step 2, Toe 3")
print "a decrypt: ", a.decrypt(msg0)
print "a decrypt: ", a.decrypt(msg1)
print "a decrypt: ", a.decrypt(msg2)
msg0 = a.encrypt("Step 3, Toe 1")
msg1 = a.encrypt("Step 3, Toe 2")
msg2 = a.encrypt("Step 3, Toe 3")
print "b decrypt: ", b.decrypt(msg0)
print "b decrypt: ", b.decrypt(msg1)
print "b decrypt: ", b.decrypt(msg2)
msg0 = b.encrypt("Step 4, Toe 1")
예제 #7
0
파일: test3.py 프로젝트: eglanz/pyaxo
    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!!!
예제 #8
0
파일: test2.py 프로젝트: ghtdak/pyaxo
    print 'Barb is Alice-like'

# send some messages back and forth
msg0 = a.encrypt('message 0')
msg1 = a.encrypt('message 1')
msg2 = a.encrypt('message 2')
msg3 = a.encrypt('message 3')
msg4 = a.encrypt('message 4')
msg5 = a.encrypt('message 5')
msg6 = a.encrypt('message 6')
msg7 = a.encrypt('message 7')
msg8 = a.encrypt('message 8')
msg9 = a.encrypt('message 9')
msg10 = a.encrypt('message 10')
msg11 = a.encrypt('message 11')
print 'b decrypt: ', b.decrypt(msg11)
print 'b decrypt: ', b.decrypt(msg10)
print 'b decrypt: ', b.decrypt(msg9)
print 'b decrypt: ', b.decrypt(msg8)
print 'b decrypt: ', b.decrypt(msg7)
print 'b decrypt: ', b.decrypt(msg6)
print 'b decrypt: ', b.decrypt(msg5)
print 'b decrypt: ', b.decrypt(msg4)
print 'b decrypt: ', b.decrypt(msg3)
print 'b decrypt: ', b.decrypt(msg2)
print 'b decrypt: ', b.decrypt(msg1)
print 'b decrypt: ', b.decrypt(msg0)

msg0 = b.encrypt('message 0')
msg1 = b.encrypt('message 1')
msg2 = b.encrypt('message 2')
예제 #9
0
파일: test.py 프로젝트: eglanz/pyaxo
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')
msg1 = a.encrypt('message 1')
msg2 = b.encrypt('message 2')
print 'b decrypt: ', b.decrypt(msg0)
print 'b decrypt: ', b.decrypt(msg1)
print 'a decrypt: ', a.decrypt(msg2)
msg3 = a.encrypt('message 3')
msg4 = a.encrypt('message 4')
msg5 = b.encrypt('message 5')
msg6 = a.encrypt('message 6')
msg7 = b.encrypt('message 7')
msg8 = a.encrypt('message 8')
msg9 = a.encrypt('message 9')
msg10 = a.encrypt('message 10')
msg11 = a.encrypt('message 11')
print 'b decrypt: ', b.decrypt(msg11)
print 'b decrypt: ', b.decrypt(msg3)
print 'b decrypt: ', b.decrypt(msg9)
print 'a decrypt: ', a.decrypt(msg5)