Esempio n. 1
0
 def print_keys(self):
     print 'Your Identity key is:\n' + b2a(self.keys['DHIs'])
     fingerprint = hash_(self.keys['DHIs']).encode('hex').upper()
     fprint = ''
     for i in range(0, len(fingerprint), 4):
         fprint += fingerprint[i:i + 2] + ':'
     print 'Your identity key fingerprint is: '
     print fprint[:-1] + '\n'
     print 'Your Ratchet key is:\n' + b2a(self.keys['DHRs'])
     if self.handshake_key:
         print 'Your Handshake key is:\n' + b2a(self.handshake_pkey)
     else:
         print 'Your Handshake key is not available'
Esempio n. 2
0
 def print_state(self):
     print
     print 'Warning: saving this data to disk is insecure!'
     print
     for key in sorted(self.keys):
         if 'priv' in key:
             pass
         else:
             if self.keys[key] is None:
                 print key + ': None'
             elif type(self.keys[key]) is bool:
                 if self.keys[key]:
                     print key + ': True'
                 else:
                     print key + ': False'
             elif type(self.keys[key]) is str:
                 try:
                     self.keys[key].decode('ascii')
                     print key + ': ' + self.keys[key]
                 except UnicodeDecodeError:
                     print key + ': ' + b2a(self.keys[key]).strip()
             else:
                 print key + ': ' + str(self.keys[key])
     if self.mode is ALICE_MODE:
         print 'Mode: Alice'
     else:
         print 'Mode: Bob'
Esempio n. 3
0
 def encrypt_file(self, filename):
     with open(filename, 'r') as f:
         plaintext = f.read()
     ciphertext = b2a(self.encrypt(plaintext))
     with open(filename + '.asc', 'w') as f:
         lines = [
             ciphertext[i:i + 64] for i in xrange(0, len(ciphertext), 64)
         ]
         for line in lines:
             f.write(line + '\n')
Esempio n. 4
0
 def _commit_skipped_mk(self, conversation):
     with self.db as db:
         db.execute(
             '''
             DELETE FROM
                 skipped_mk
             WHERE
                 my_identity = ? AND
                 to_identity = ?''',
             (conversation.name, conversation.other_name))
         for skipped_mk in conversation.staged_hk_mk.values():
             db.execute(
                 '''
                 INSERT INTO
                     skipped_mk (
                         my_identity,
                         to_identity,
                         HKr,
                         mk,
                         timestamp)
                 VALUES (?, ?, ?, ?, ?)''',
                 (conversation.name, conversation.other_name,
                  b2a(skipped_mk.hk).strip(), b2a(
                      skipped_mk.mk).strip(), skipped_mk.timestamp))
Esempio n. 5
0
        axolotl = Axolotl(NICK,
                    dbname=OTHER_NICK+'.db',
                    dbpassphrase=None,
                    nonthreaded_sql=False)
        axolotl.createState(other_name=OTHER_NICK,
                           mkey=hash_(mkey),
                           mode=False)
        tor_process = tor(TOR_SERVER_PORT,
                          TOR_SERVER_CONTROL_PORT,
                          '/tmp/tor.server',
                          '')
        hs, cookie, onion = ephemeralHiddenService()
        print 'Exchanging credentials via tor...'
        if credentialsSend(mkey,
                           cookie,
                           b2a(axolotl.state['DHRs']).strip(),
                           onion):
            pass
        else:
            sys.exit(1)
        print 'Credentials sent, waiting for the other party to connect...'
        with socketcontext(socket.AF_INET, socket.SOCK_STREAM) as s:
            s.bind((HOST, PORT))
            s.listen(1)
            conn, addr = s.accept()
            print 'Connected...'
            smp_match = doSMP(conn, True)
            chatThread(conn, smp_match, None)

    elif mode == '-c':
        axolotl = Axolotl(NICK,
Esempio n. 6
0
import binascii

hexstring = hex("44656c6f6e")
print binascii.b2a(hexstring)
Esempio n. 7
0
from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
from funx import *
import sys
from binascii import b2a_base64 as b2a
from binascii import a2b_base64 as a2b

in_filepath = 'p-text-data/16-block/p_txt_str.txt'

key_sizes = [128, 192, 256]
numb_keys = 5

key_vals = { i :\
 [ get_random_bytes(int( i/8 )) \
 for j in range(0,numb_keys - 1)] for i in key_sizes }

for key_size in key_vals:
    key_idx = 0
    for key in key_vals[key_size]:
        key_idx += 1
        filepath = 'c-text-data/aes/aes' + str(key_size) + '_key_' + str(
            key_idx) + '_ciphertext_'
        keywrite(filepath, [
            b2a(key).decode('ascii'),
            to_byte_fromint(key), key_idx, key_size
        ])
        for p_txt in open(in_filepath, 'r').readlines():
            cipher = AES.new(key, AES.MODE_ECB)
            c_txt = cipher.encrypt(p_txt.rstrip('\n '))
            filewrite(filepath, c_txt)
Esempio n. 8
0
import binascii
binascii.b2a(1)
Esempio n. 9
0
if 61 - 61: o00ooo0
if 79 - 79: Oo0Ooo + I1IiiI - ii1II11I1ii1I
oO00O00o0OOO0 = "[{}]{}" . format ( o00 , iIi )
Ii1iIIIi1ii = O0o0o00o0Oo0 . sign ( oO00O00o0OOO0 , hashfunc = hashlib . sha256 )
if 80 - 80: oO0ooO * i11iIiiIii / iiIIIII1i1iI
if 9 - 9: iI1Ii11111iIi + OOooOOo % iI1Ii11111iIi + i1IIi . ii11ii1ii
if 31 - 31: o0oOOo0O0Ooo + oO0ooO + oO0ooO / II111iiii
if 26 - 26: OoooooooOO
print ( "----------------------------------------------------------------------" )
print ( "" )
print ( "Crypto-hashed EID: {}" . format ( oO00O00o0OOO0 ) )
print ( "" )
print ( "Private-key for lisp-sig.pem/lisp-lig.pem file:\n{}" . format ( O0o0o00o0Oo0 . to_pem ( ) ) )
if 12 - 12: OoooooooOO % OoOoOO00 / o00ooo0 % o0oOOo0O0Ooo
if 29 - 29: OoooooooOO
ii11 = b2a ( O0o0o00o0Oo0 . get_verifying_key ( ) . to_pem ( ) )
print ( "Public-key for lisp.config file:\n{}" . format ( ii11 ) )
Ii1iIIIi1ii = b2a ( Ii1iIIIi1ii )
print ( "EID signature for lisp.config file:\n{}" . format ( Ii1iIIIi1ii ) )
if 23 - 23: o0oOOo0O0Ooo . II111iiii
print ( "----------------------------------------------------------------------" )
print ( "" )
if 98 - 98: iIii1I11I1II1 % OoOoOO00 * I1ii11iIi11i * OoOoOO00
print ( "Add the following commands to the lisp.config file:" )
if 45 - 45: iiIIIII1i1iI . OoOoOO00
oO = OoO000
if ( ( len ( oO ) % 4 ) == 0 ) :
 OoO000 = [ ]
else :
 OoO000 = [ oO [ 0 : 2 ] ]
 oO = oO [ 2 : : ]
Esempio n. 10
0
        a = Axolotl(NICK,
                    dbname=OTHER_NICK+'.db',
                    dbpassphrase=None,
                    nonthreaded_sql=False)
        a.createState(other_name=OTHER_NICK,
                           mkey=hashlib.sha256(mkey).digest(),
                           mode=False)
        tor_process = tor(TOR_SERVER_PORT,
                          TOR_SERVER_CONTROL_PORT,
                          '/tmp/tor.server',
                          '')
        hs, cookie, onion = ephemeralHiddenService()
        print 'Exhanging credentials via tor...'
        if credentialsSend(mkey,
                           cookie,
                           b2a(a.state['DHRs']).strip(),
                           onion):
            pass
        else:
            sys.exit(1)
        print 'Credentials sent, 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()
            print 'Connected...'
            smp_match = doSMP(conn, True)
            chatThread(conn, smp_match)

    elif mode == '-c':
        a = Axolotl(NICK,
Esempio n. 11
0
    mkey = getpass('What is the masterkey (format: NNN-xxxx)? ')

    if mode == '-s':
        axolotl = Axolotl(NICK,
                          dbname=OTHER_NICK + '.db',
                          dbpassphrase=None,
                          nonthreaded_sql=False)
        axolotl.createState(other_name=OTHER_NICK,
                            mkey=hash_(mkey),
                            mode=False)
        tor_process = tor(TOR_SERVER_PORT, TOR_SERVER_CONTROL_PORT,
                          '/tmp/tor.server', '')
        hs, cookie, onion = ephemeralHiddenService()
        print 'Exchanging credentials via tor...'
        if credentialsSend(mkey, cookie,
                           b2a(axolotl.state['DHRs']).strip(), onion):
            pass
        else:
            sys.exit(1)
        print 'Credentials sent, waiting for the other party to connect...'
        with socketcontext(socket.AF_INET, socket.SOCK_STREAM) as s:
            s.bind((HOST, PORT))
            s.listen(1)
            conn, addr = s.accept()
            print 'Connected...'
            smp_match = doSMP(conn, True)
            chatThread(conn, smp_match, None)

    elif mode == '-c':
        axolotl = Axolotl(NICK,
                          dbname=OTHER_NICK + '.db',
Esempio n. 12
0
 def encrypt_pipe(self):
     plaintext = sys.stdin.read()
     ciphertext = b2a(self.encrypt(plaintext))
     sys.stdout.write(ciphertext)
     sys.stdout.flush()
Esempio n. 13
0
for mode in [AES.MODE_CBC, AES.MODE_CFB, AES.MODE_OFB]:
    for key_bytes in [16, 24, 32]:
        test_num = 0
        for pt_len in [5, 16, 21, 32]:
            # CBC mode requires block sized inputs.
            if mode == AES.MODE_CBC and pt_len % 16:
                continue
            test_num += 1

            actual_pt_len = pt_len
            if pt_len % 16:
                pt_len = 16 * ((pt_len / 16) + 1)

            key = os.urandom(key_bytes)
            iv = os.urandom(16)
            pt = os.urandom(pt_len)

            obj = AES.new(key, mode=mode, IV=iv, segment_size=128)
            ct = obj.encrypt(pt)
            obj = AES.new(key, mode=mode, IV=iv, segment_size=128)

            assert obj.decrypt(ct)[:pt_len] == pt

            print template.format(mode=modes[mode],
                                  key_bits=str(key_bytes * 8),
                                  test_num=str(test_num),
                                  pt=b2a(h2be(pt[:actual_pt_len])),
                                  key=b2a(h2be(key)),
                                  ct=b2a(h2be(ct[:actual_pt_len])),
                                  iv=b2a(h2be(iv))),
Esempio n. 14
0
if 32 - 32: Oo0Ooo * O0 % oO0o % Ii1I.O00oOoOoO0o0O
o0OOOOO00o0O0 = "[{}]{}".format(Oo0oO0ooo, OOoO000O0OO)
o0o0OOO0o0 = I11iii11IIi.sign(o0OOOOO00o0O0, hashfunc=hashlib.sha256)
if 84 - 84: O00oOoOoO0o0O
if 25 - 25: Oo0Ooo - O00oOoOoO0o0O.OoooooooOO
if 22 - 22: O00oOoOoO0o0O + II111iiii % O0oo0OO0.I11i.OoOoOO00
if 76 - 76: OoOoOO00 - O0 % OOooOOo / I1ii11iIi11i / OoOoOO00
print "----------------------------------------------------------------------"
print ""
print "Crypto-hashed EID: {}".format(o0OOOOO00o0O0)
print ""
print "Private-key for lisp-sig.pem/lisp-lig.pem file:\n{}".format(
    I11iii11IIi.to_pem())
if 54 - 54: I1IiiI % II111iiii % II111iiii
if 13 - 13: o0oOOo0O0Ooo.Ii1I
O00o0o0000o0o = b2a(I11iii11IIi.get_verifying_key().to_pem())
print "Public-key for lisp.config file:\n{}".format(O00o0o0000o0o)
o0o0OOO0o0 = b2a(o0o0OOO0o0)
print "EID signature for lisp.config file:\n{}".format(o0o0OOO0o0)
if 19 - 19: I11i + Oo0ooO0oo0oO
print "----------------------------------------------------------------------"
print ""
if 53 - 53: OoooooooOO.i1IIi
print "Add the following commands to the lisp.config file:"
if 18 - 18: o0oOOo0O0Ooo
I1i1I1II = iiiIi
if ((len(I1i1I1II) % 4) == 0):
    iiiIi = []
else:
    iiiIi = [I1i1I1II[0:2]]
    I1i1I1II = I1i1I1II[2::]
Esempio n. 15
0
Ii1iIIIi1ii = Ii1iIIIi1ii.replace(":0", ":")
if 9 - 9: o0000oOoOoO0o + iiiiIi11i % o0000oOoOoO0o + i1IIi.II11iiII
if 31 - 31: Ooo00oOo00o + OoOO0ooOOoo0O + OoOO0ooOOoo0O / II111iiii
if 26 - 26: OoooooooOO
if 12 - 12: OoooooooOO % oOo0O0Ooo / Oo % Ooo00oOo00o
if 29 - 29: OoooooooOO
if 23 - 23: Ooo00oOo00o.II111iiii
Oo0O0OOOoo = "[{}]{}".format(Ooo00O0, Ii1iIIIi1ii)
oOoOooOo0o0 = IIIiI11ii.sign(Oo0O0OOOoo, hashfunc=hashlib.sha256)
if 61 - 61: Ooo00oOo00o / ooOO00oOo + Oo * iiiiIi11i / iiiiIi11i
if 75 - 75: i1IIi / OoooooooOO - O0 / oOo0O0Ooo.II111iiii - i1IIi
if 71 - 71: II11iiII + o0000oOoOoO0o * II11iiII - ooOO00oOo * Ooo00oOo00o
if 65 - 65: O0 % oo.oOoO0oo0OOOo % iIii1I11I1II1 / II11iiII % o0oo0o
print("Generated crypto-EID {}\n".format(IiII1IiiIiI1(Oo0O0OOOoo)))
if 51 - 51: i11iIiiIii.oo + II111iiii
O000oo = b2a(IIIiI11ii.get_verifying_key().to_pem())
print("Public-key {}".format(O000oo))
oOoOooOo0o0 = b2a(oOoOooOo0o0)
if 10 - 10: oOoO0oo0OOOo * Oo * II111iiii % o0000oOoOoO0o.II11iiII + o0oo0o
IIiIi11i1 = O0O
if ((len(IIiIi11i1) % 4) == 0):
    O0O = []
else:
    O0O = [IIiIi11i1[0:2]]
    IIiIi11i1 = IIiIi11i1[2::]
    if 29 - 29: oOoO0oo0OOOo % oo + Oo / Ooo00oOo00o + II11iiII * Ooo00oOo00o
for i1I1iI in range(0, len(IIiIi11i1), 4):
    O0O.append(IIiIi11i1[i1I1iI:i1I1iI + 4])
    if 93 - 93: iIii1I11I1II1 % iiiiIi11i * i1IIi
    if 16 - 16: O0 - o0oo0o * iIii1I11I1II1 + i1I1ii1II1iII
O0O = ":".join(O0O)
Esempio n. 16
0
eid = eid.replace(":0", ":")

#
# Now do signature. Make sure sig_data is hashed with sha256. This is required
# for Go to Python interoperability. The lispers.net verifier needs to assume
# this for both signers. Note to use sha256, you need curve NIST256p.
#
sig_data = "[{}]{}".format(iid, eid)
sig = key.sign(sig_data, hashfunc=hashlib.sha256)

#
# Return values in base64 format
#
print "Generated crypto-EID {}\n".format(bold(sig_data))

pubkey = b2a(key.get_verifying_key().to_pem())
print "Public-key {}".format(pubkey)
sig = b2a(sig)

hvv = hv
if ((len(hvv) % 4) == 0):
    hv = []
else:
    hv = [hvv[0:2]]
    hvv = hvv[2::]
#endif
for i in range(0, len(hvv), 4):
    hv.append(hvv[i:i + 4])
#endfor

hv = ":".join(hv)
Esempio n. 17
0
            break
        except ValueError:
            PORT = 50000
            break
    if PORT >= 1025 and PORT <= 65535:
        pass
    elif PORT == 1:
        PORT = 1025 + randint(0, 64510)
        print('PORT is ' + str(PORT))

    if mode == '-s':
        a = Axolotl(NICK, dbname=OTHER_NICK + '.db', dbpassphrase=None)
        a.createState(other_name=OTHER_NICK,
                      mkey=hashlib.sha256(mkey.encode()).digest(),
                      mode=False)
        print('Your ratchet key is: %s' % b2a(a.state['DHRs']).strip())
        print('Send this to %s...' % OTHER_NICK)

        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()
            chatThread(conn)

    elif mode == '-c':
        rkey = input('Enter %s\'s ratchet key: ' % OTHER_NICK)
        a = Axolotl(NICK, dbname=OTHER_NICK + '.db', dbpassphrase=None)
        a.createState(other_name=OTHER_NICK,
                      mkey=hashlib.sha256(mkey.encode()).digest(),
                      mode=True,
Esempio n. 18
0
 def save_conversation(self, conversation):
     HKs = 0 if conversation.keys['HKs'] is None else b2a(
         conversation.keys['HKs']).strip()
     HKr = 0 if conversation.keys['HKr'] is None else b2a(
         conversation.keys['HKr']).strip()
     CKs = 0 if conversation.keys['CKs'] is None else b2a(
         conversation.keys['CKs']).strip()
     CKr = 0 if conversation.keys['CKr'] is None else b2a(
         conversation.keys['CKr']).strip()
     DHIr = 0 if conversation.keys['DHIr'] is None else b2a(
         conversation.keys['DHIr']).strip()
     DHRs_priv = 0 if conversation.keys['DHRs_priv'] is None else b2a(
         conversation.keys['DHRs_priv']).strip()
     DHRs = 0 if conversation.keys['DHRs'] is None else b2a(
         conversation.keys['DHRs']).strip()
     DHRr = 0 if conversation.keys['DHRr'] is None else b2a(
         conversation.keys['DHRr']).strip()
     ratchet_flag = 1 if conversation.ratchet_flag else 0
     mode = 1 if conversation.mode else 0
     with self.db as db:
         db.execute(
             '''
             REPLACE INTO
                 conversations (
                     my_identity,
                     other_identity,
                     RK,
                     HKS,
                     HKr,
                     NHKs,
                     NHKr,
                     CKs,
                     CKr,
                     DHIs_priv,
                     DHIs,
                     DHIr,
                     DHRs_priv,
                     DHRs,
                     DHRr,
                     CONVid,
                     Ns,
                     Nr,
                     PNs,
                     ratchet_flag,
                     mode)
             VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
                     ?, ?, ?)''',
             (conversation.name, conversation.other_name,
              b2a(conversation.keys['RK']).strip(), HKs, HKr,
              b2a(conversation.keys['NHKs']).strip(),
              b2a(conversation.keys['NHKr']).strip(), CKs, CKr,
              b2a(conversation.keys['DHIs_priv']).strip(),
              b2a(conversation.keys['DHIs']).strip(), DHIr, DHRs_priv, DHRs,
              DHRr, b2a(
                  conversation.keys['CONVid']).strip(), conversation.ns,
              conversation.nr, conversation.pns, ratchet_flag, mode))
     self._commit_skipped_mk(conversation)
     self.write_db()
Esempio n. 19
0
def main():
    global a

    class Chat_Server(threading.Thread):
        def __init__(self):
            print "Chat_Server init"
            threading.Thread.__init__(self)
            self.running = 1
            self.conn = None
            self.addr = None
            self.host = '127.0.0.1'
            self.port = None

        def run(self):
            print "running chat server"
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.bind((self.host, self.port))
            s.listen(1)
            print("waiting for connection from client")
            self.conn, addr = s.accept()
            while self.running == True:
                data = self.conn.recv(1024)

                if data:
                    data = a.decrypt(data)
                    if data == 'exit':
                        self.running = 0
                    else:
                        print "Client Says >> " + data
                else:
                    break
            time.sleep(0)

        def kill(self):
            self.running = 0

    class Chat_Client(threading.Thread):
        def __init__(self):
            print "Chat Client init"
            threading.Thread.__init__(self)
            self.host = None
            self.sock = None
            self.running = 1
            self.port = None

        def run(self):
            print "Chat Client Run"
            self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.sock.connect((self.host, self.port))
            while self.running == True:

                rcv = self.sock.recv(1024)

                data = '' + rcv
                if data:
                    data = a.decrypt(data)
                    if data == 'exit':
                        self.running = 0
                    else:
                        print "Server Says >> " + data
                else:
                    break
            time.sleep(0)

        def kill(self):
            self.running = 0

    class Text_Input(threading.Thread):
        def __init__(self):
            print "text input init"
            threading.Thread.__init__(self)
            self.running = 1

        def run(self):
            print "text input run "
            while self.running == True:
                text = raw_input('')
                try:
                    text = text.replace('\n', '') + '\n'
                    text = a.encrypt(text)
                    chat_client.sock.sendall(text)
                except:
                    Exception
                try:
                    text = text.replace('\n', '') + '\n'
                    text = a.encrypt(text)
                    chat_server.conn.sendall(text)
                except:
                    Exception
                time.sleep(0.1)

        def kill(self):
            self.running = 0

    try:
        mode = sys.argv[1]
    except:
        exit(1)

    if mode == '-s':
        s = socket.socket()
        s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,
                     1)  # Socket object
        host = '127.0.0.1'  # Get host name
        port = 8000
        myName = raw_input("What is your name: ")
        otherName = raw_input("What is the other name: ")
        masterkey = raw_input("what is your previously decided on master key"
                              )  # Reserve best port.
        a = Axolotl(myName,
                    dbname=otherName + '.db',
                    dbpassphrase=None,
                    nonthreaded_sql=False)
        a.createState(other_name=otherName,
                      mkey=hashlib.sha256(masterkey).digest(),
                      mode=False)
        rkey = b2a(a.state['DHRs']).strip()
        print "Send this ratchet key to your client: ", rkey
        print 'Server started'
        print 'Waiting for cients to connect...'

        s.bind((host, port))  # Bind to the port
        s.listen(3)  # Now wait for client connection.
        c, addr = s.accept()  # Establish connection with client.
        print 'Got connection from', addr
        secret = raw_input("Enter shared secret: ")
        smpr = smp.SMP(secret)
        buffer = c.recv(4096)[4:]

        buffer = smpr.step2(buffer)
        tempBuffer = padBytes(longToBytes(len(buffer) + 4), 4) + buffer
        c.send(tempBuffer)

        buffer = c.recv(4096)[4:]

        buffer = smpr.step4(buffer)
        tempBuffer = padBytes(longToBytes(len(buffer) + 4), 4) + buffer
        c.send(tempBuffer)

        if smpr.match:
            print "match"
        else:
            print "no match"
            s.close()
            sys.exit()

        chat_server = Chat_Server()
        chat_server.port = int(raw_input("Enter port to listen on: "))
        chat_server.start()
        text_input = Text_Input()
        text_input.start()

    elif mode == '-c':
        s = socket.socket()
        s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,
                     1)  # Socket object
        host = '127.0.0.1'  # Get host name
        port = 8000
        # Reserve best port.
        myName = raw_input("What is your name: ")
        otherName = raw_input("What is the other name: ")
        masterkey = raw_input("what is your previously decided on master key"
                              )  # Reserve best port.
        rkey = raw_input(
            "what is the ratchet key you received from your partner:")
        print 'Connect to ', host, port
        s.connect((host, port))
        secret = raw_input("Enter shared secret: ")
        smpr = smp.SMP(secret)

        buffer = smpr.step1()
        #print "buffer = {}\n".format(  buffer )
        tempBuffer = padBytes(longToBytes(len(buffer) + 4), 4) + buffer

        s.send(tempBuffer)

        buffer = s.recv(4096)[4:]
        buffer = smpr.step3(buffer)
        tempBuffer = padBytes(longToBytes(len(buffer) + 4), 4) + buffer
        s.send(tempBuffer)

        buffer = s.recv(4096)[4:]
        smpr.step5(buffer)
        if smpr.match:
            print "match"
        else:
            print "no match"
            s.close()
            sys.exit()
        a = Axolotl(myName,
                    dbname=otherName + '.db',
                    dbpassphrase=None,
                    nonthreaded_sql=False)
        a.createState(other_name=otherName,
                      mkey=hashlib.sha256(masterkey).digest(),
                      mode=True,
                      other_ratchetKey=a2b(rkey))
        chat_client = Chat_Client()
        chat_client.host = raw_input("Enter host to connect to: ")
        chat_client.port = int(raw_input("Enter port to connect to: "))
        chat_client.start()
        text_input = Text_Input()
        text_input.start()
Esempio n. 20
0
            PORT = raw_input("TCP port (1 for random choice, 50000 is default): ")
            PORT = int(PORT)
            break
        except ValueError:
            PORT = 50000
            break
    if PORT >= 1025 and PORT <= 65535:
        pass
    elif PORT == 1:
        PORT = 1025 + randint(0, 64510)
        print "PORT is " + str(PORT)

    if mode == "-s":
        a = Axolotl(NICK, dbname=OTHER_NICK + ".db", dbpassphrase=None, nonthreaded_sql=False)
        a.createState(other_name=OTHER_NICK, mkey=hashlib.sha256(mkey).digest(), mode=False)
        print "Your ratchet key is: %s" % b2a(a.state["DHRs"]).strip()
        print "Send this to %s..." % OTHER_NICK

        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()
            chatThread(conn)

    elif mode == "-c":
        rkey = raw_input("Enter %s's ratchet key: " % OTHER_NICK)
        a = Axolotl(NICK, dbname=OTHER_NICK + ".db", dbpassphrase=None, nonthreaded_sql=False)
        a.createState(other_name=OTHER_NICK, mkey=hashlib.sha256(mkey).digest(), mode=True, other_ratchetKey=a2b(rkey))

        HOST = raw_input("Enter the server: ")