示例#1
0
    def store_keys(self):
        if self.key_presses:
            self.maybe_end_specials()

            keys = [press.key for press in self.key_presses]
            timings = [press.time for press in self.key_presses]

            nrkeys = reduce(
                lambda count, press: count + (not press.is_repeat and 1 or 0),
                self.key_presses, 0)

            if not self.store_text:
                keys = []
                self.curtext = u""

            self.session.add(
                Keys(self.curtext.encode('utf8'), keys, timings, nrkeys,
                     self.started, self.cur_win_proc, self.cur_win_id,
                     self.cur_geo_id))

            self.trycommit()

            self.started = NOW()
            self.curtext = u""
            self.key_presses = []
            self.last_key_time = time.time()
示例#2
0
    def store_keys(self):
        """ Stores the current queued key-presses """
        self.filter_many()

        if self.key_presses:
            keys = [press.key for press in self.key_presses]
            timings = [press.time for press in self.key_presses]
            add = lambda count, press: count + (1 if press.is_repeat else 0)
            nrkeys = reduce(add, self.key_presses, 0)

            curtext = u""
            if not self.store_text:
                keys = []
            else:
                curtext = ''.join(keys)

            self.session.add(
                Keys(curtext.encode('utf8'), keys, timings, nrkeys,
                     self.started, self.current_window.proc_id,
                     self.current_window.win_id, self.current_window.geo_id))

            self.trycommit()

            self.started = NOW()
            self.key_presses = []
            self.last_key_time = time.time()
示例#3
0
    def generate_client_keys(self, client: Client) -> (Keys, UUID):
        client_keys = Keys()
        
        if client.id in self._client_keys:
            raise ValueError("Cannot generate a new keypair for an already existing client!")

        self._client_keys[client.id] = client_keys

        return client_keys
示例#4
0
文件: client.py 项目: roemba/sdm
    def exchange_keys(self, A1: EcPt, A2: EcPt) -> Tuple[EcPt, EcPt]:
        curve = EcGroup(713)
        g = curve.generator()

        b1 = curve.order().random()
        B1 = g.pt_mul(b1)

        b2 = curve.order().random()
        B2 = g.pt_mul(b2)

        self._keys = Keys()
        self._keys.encryption_key = sha256(A1.pt_mul(b1).export()).digest()
        self._keys.hashing_key = sha256(A2.pt_mul(b2).export()).digest()

        return B1, B2
示例#5
0
    def exchange_client_keys(self, client: Client):
        curve = EcGroup(713)
        g = curve.generator()

        a1 = curve.order().random()
        A1 = g.pt_mul(a1)

        a2 = curve.order().random()
        A2 = g.pt_mul(a2)

        B1, B2 = client.exchange_keys(A1, A2)

        self._client_keys[client.id] = Keys()
        self._client_keys[client.id].encryption_key = sha256(B1.pt_mul(a1).export()).digest()
        self._client_keys[client.id].hashing_key = sha256(B2.pt_mul(a2).export()).digest()
示例#6
0
def parse_keys(session):
    # get names of files to read and mongodb collection to write
    keyfile = os.path.join(os.path.expanduser(cfg.CURRENT_DIR), cfg.KEYLOG)

    # read the file, write lines to database, and save lines that were not
    # written to the database
    # TODO may need to check if file is already open using a file lock
    if os.path.isfile(keyfile):
        f = open(keyfile, 'r+')
        lines_to_save = []
        for line in f:
            try:
                text = ast.literal_eval(line.rstrip())

                # get active app and window at time of event
                app = session.query(AppEvent).filter(
                    AppEvent.event == "Active",
                    AppEvent.time <= text['time']).order_by(
                        AppEvent.time.desc()).first()
                window = session.query(WindowEvent).filter(
                    WindowEvent.event == "Active",
                    WindowEvent.time <= text['time']).order_by(
                        WindowEvent.time.desc()).first()
                pid = app.app_id if app else 0
                wid = window.window_id if window else 0

                key = Keys(text['time'], text['key'],
                           json.dumps(text['modifiers']), pid, wid)
                session.add(key)
            except:
                print "Could not save " + str(
                    line
                ) + " to the database. Saving for the next round of parsing."
                lines_to_save.append(line)
        # write lines that did not make it into the database to the start of the
        # file and delete the rest of the file
        f.seek(0)
        for line in lines_to_save:
            f.write(line)
        f.truncate()
        f.close()
示例#7
0
def key():
    user = current_user._get_current_object()
    keys = Keys.query.all()
    error = ''
    generated = 'false'
    if request.method == 'GET':
        keyform = keyForm()
        return render_template('key.html',
                               user=user,
                               keys=keys,
                               keyform=keyform,
                               generated=generated)
    else:
        keyform = keyForm(request.form)
        if keyform.date.data > date.today():
            error = ""
            key = Keys()
            key.expiration = keyform.date.data
            key.token = token_hex(16)
            key.description = keyform.description.data
            response = urlopen("http://tinyurl.com/api-create.php?url=" +
                               urlsurvey + key.token)
            key.urlsurvey = response.read().decode('utf-8')
            response2 = urlopen("http://tinyurl.com/api-create.php?url=" +
                                urledu + key.token)
            key.urledu = response2.read().decode('utf-8')

            user_datastore.put(key)
            db_session.commit()
            generated = key.token
            keyform = keyForm()
        else:
            error = "Data inserita non valida, validità minima: 1 giorno"
        keys = Keys.query.all()
        return render_template('key.html',
                               user=user,
                               keys=keys,
                               keyform=keyform,
                               error=error,
                               generated=generated)