Ejemplo n.º 1
0
    def on_update_mobile_clicked(self, widget, tree_selection):
        (model, pathlist) = tree_selection.get_selected_rows()
        tree_iter = model.get_iter(pathlist)

# tu trzeba znalesc telefon o okreslonym UUID
        uuid = model[tree_iter][2]
        mobile = model[tree_iter][1]

        try:
            (btaddr, port) = BTfunctions.findPhone(CONS_UUID + uuid)
        except ValueError as err:
            print(err.args)
            dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.ERROR,
                                       Gtk.ButtonsType.CANCEL,
                                       "Unable to find phone")
            dialog.format_secondary_text("Unable to find phone with service UUID : " + str(uuid) + " Please chceck if its properly set.")
            dialog.run()
            dialog.destroy()
            return None;
# i zapisac te dane to listy
        model[tree_iter][3] = btaddr
        model[tree_iter][4] = str(port)
        print "update Mobile returned Adrr: " + str(btaddr) + " Port:"+str(port)
Ejemplo n.º 2
0
    def on_Add_mobile_clicked(self, widget, liststore):
        # Popros uzywkonika o nazwe telefonu
        new_mobile_id = windows.entryWindow(self, "Enter your mobile name: ",
                                    "Add mobile")
        # Popros uzytwkonika o fragment UUID z telefonu
        uuid_suffix = windows.entryWindow(self, "Enter id presented by mobile",
                                    "Add mobile")

        # Znajdz telefon
        if DBG_FIXED_ADDR_PORT is True:
            addr = FIXED_ADDR
            port = FIXED_PORT
        else:
            (addr, port) = BTfunctions.findPhone(CONS_UUID + uuid_suffix)

        priv_file_dir = PRIV_PATH + new_mobile_id + PRIV_KEY_FILE_EXT

        # Generowanie kluczy
        if DBG_FIXED_RSA_KEYS is True:
            pub_file = open(DBG_FIXED_PUBKEY_DIR, 'r')
            pubkey = pub_file.read()
            pub_file.close()
            priv_file_dir = DBG_FIXED_PRIV_DIR
        else:
            # Wygeneruj pare kluczy
            pubkey = CryptoEngine.genKeys(DBG_FIXED_PUBKEY_DIR, priv_file_dir)

        # Usun z klucza poczatek i koniec
        pubkey_to_send = configuration.preparePublicKey(pubkey)
        # Wyslij do telfonu klucz publiczny
        BTfunctions.sendPubKey(addr, port, pubkey_to_send)

        # Identyfiatkator sessjii
        if DBG_FIXED_SESSIONID is True:
            sessionID = FIXED_SESSIONID
        else:
            sessionID = base64.b64encode(os.urandom(SESSION_ID_LEN_BYTES))

        # Okno z posba o ustawnowienie hasla na telefonie
        dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO,
            Gtk.ButtonsType.OK, "Add mobile")
        dialog.format_secondary_text(
            "Please set password in mobile device")

        while(True):
            # Wyswietl okno
            dialog.run()
            # Proba odebrabnia ct
            ct = BTfunctions.receiveCipherText(addr, port, sessionID)
            if ct is not None:
                break
        # Szyfrogram pobrany usun okno
        dialog.destroy()

        # Obrob odebrany szyfrogram
        idkey_hash = configuration.processCipherText(ct, sessionID,
                                                     priv_file_dir)
        # Zapisz otrzymany skrot do pliku
        hash_file = open(HASH_PATH + new_mobile_id, 'w')
        hash_file.write(idkey_hash)
        hash_file.close()

# dopoki nie polaczenie z telefonem nie zostanie zrealizowane i
# nie zosanie pobrany btaddr i port sa puste i telefon jest domyslni
# wylaczony
        liststore.append((new_mobile_id, False, uuid_suffix, addr, str(port)))