示例#1
0
文件: distribute.py 项目: olcf/pkpass
 def _confirm_pdb(self):
     self.filtered_pdb = dictionary_filter(
         path.join(self.args["pwstore"], self.args["pwname"]),
         self.passworddb.pwdb,
         [self.args["identity"], "recipients"],
     )
     yield "The following password files have matched:"
     yield "\n".join(self.filtered_pdb.keys())
     correct = input("Are these correct? (y/N) ")
     if not correct or correct.lower()[0] == "n":
         self.args["pwname"] = input("Please try a new filter: ")
         yield from self._confirm_pdb()
示例#2
0
    def _run_command_execution(self):
        """ Run function for class.                                      """
        ####################################################################
        passworddb = PasswordDB()
        passworddb.load_from_directory(self.args['pwstore'])
        filtered_pdb = util.dictionary_filter(
            path.join(self.args['pwstore'], self.args['pwname']),
            passworddb.pwdb,
            [self.args['identity'], 'recipients']
        )
        self.recipient_list.append(str(self.args['identity']))
        self.recipient_list = list(set(self.recipient_list))
        print("The following users will receive the password:"******", ".join(self.recipient_list))
        print("The following password files have matched:")
        print(*filtered_pdb.keys(), sep="\n")
        correct_distribution = input("Are these lists correct? (y/N) ")
        if correct_distribution and correct_distribution.lower()[0] == 'y':
            passworddb.pwdb = filtered_pdb
            db_len = len(passworddb.pwdb.keys())
            i = 0
            self.progress_bar(i, db_len)
            for dist_pass, _ in passworddb.pwdb.items():
                password = PasswordEntry()
                password.read_password_data(dist_pass)
                if self.args['identity'] in password.recipients.keys():
                    # we shouldn't modify escrow on distribute
                    self.args['min_escrow'] = None
                    self.args['escrow_users'] = None
                    plaintext_pw = password.decrypt_entry(
                        self.identities.iddb[self.args['identity']],
                        passphrase=self.passphrase,
                        card_slot=self.args['card_slot'])

                    password.read_password_data(dist_pass)
                    password.add_recipients(secret=plaintext_pw,
                                            distributor=self.args['identity'],
                                            recipients=self.recipient_list,
                                            identitydb=self.identities,
                                            passphrase=self.passphrase,
                                            card_slot=self.args['card_slot'],
                                            pwstore=self.args['pwstore']
                                           )

                    password.write_password_data(dist_pass)
                    i += 1
                    self.progress_bar(i, db_len)
            # format the progress bar appropriately after the loop
            print("")
        else:
            print("Exiting due to wrong password list")
示例#3
0
文件: list.py 项目: Tubbz-alt/pkpass
    def _run_command_execution(self):
        """ Run function for class.                                      """
        ####################################################################

        passworddb = PasswordDB()
        passworddb.load_from_directory(self.args['pwstore'])

        result = {}
        for pwname, passwordentry in passworddb.pwdb.items():
            if self.args['recovery'] and passwordentry.escrow:
                for rec_list in passwordentry.escrow.keys():
                    recipients = passwordentry.escrow[rec_list]['recipients']
                    for key, value in recipients.items():
                        if key == self.args['identity']:
                            result[pwname] = {
                                'name': passwordentry.metadata['name'],
                                'group': rec_list,
                                'stake_holders': list(recipients.keys()),
                                'distributor': value['distributor'],
                                'minimum_shares': passwordentry.escrow[rec_list]['metadata']['minimum_escrow']
                            }
            elif not self.args['recovery'] and self.args['identity'] in passwordentry.recipients.keys():
                result[pwname] = {
                    'name': passwordentry.metadata['name'],
                    'distributor': passwordentry.recipients[self.args['identity']]['distributor']
                }

        if 'filter' in self.args and self.args['filter']:
            result = dictionary_filter(self.args['filter'], result)

        print("Passwords for '%s':" % self.args['identity'])
        for key, value in result.items():
            print("%s\n  %s\n  %s" %
                  (
                      self.color_print(key + ":",
                                       "first_level"),
                      self.color_print("Distributor: ",
                                       "second_level") + value['distributor'],
                      self.color_print("Name: ",
                                       "second_level") + value['name']
                  ))
示例#4
0
文件: list.py 项目: olcf/pkpass
    def _run_command_execution(self):
        ####################################################################
        """Run function for class."""
        ####################################################################
        result = {}
        for pwname, passwordentry in self.passworddb.pwdb.items():
            if self.args["recovery"] and passwordentry.escrow:
                for rec_list in passwordentry.escrow.keys():
                    recipients = passwordentry.escrow[rec_list]["recipients"]
                    for key, value in recipients.items():
                        if key == self.args["identity"]:
                            result[pwname] = {
                                "name":
                                passwordentry.metadata["name"],
                                "group":
                                rec_list,
                                "stake_holders":
                                list(recipients.keys()),
                                "distributor":
                                value["distributor"],
                                "minimum_shares":
                                passwordentry.escrow[rec_list]["metadata"]
                                ["minimum_escrow"],
                            }
            elif (not self.args["recovery"] and self.args["identity"]
                  in passwordentry.recipients.keys()):
                result[pwname] = {
                    "name":
                    passwordentry.metadata["name"],
                    "distributor":
                    passwordentry.recipients[self.args["identity"]]
                    ["distributor"],
                }

        if "filter" in self.args and self.args["filter"]:
            result = dictionary_filter(self.args["filter"], result)

        yield f"Passwords for '{self.args['identity']}':"
        for key, value in sorted(result.items()):
            yield f"{self.color_print(key + ':', 'first_level')}\n  {self.color_print('Distributor: ', 'second_level') + value['distributor']}\n  {self.color_print('Name: ', 'second_level') + value['name']}"
示例#5
0
    def _run_command_execution(self):
        """ Run function for class.                                  """
        ####################################################################

        if self.args['verbosity'] != -1:
            print('Certificate store: "%s"' % self.args['certpath'])
            print('Key store: "%s"' % self.args['keypath'])
            print('CA Bundle file: "%s"' % self.args['cabundle'])
            print('Looking for Key Extension: "%s"' %
                  self.identities.extensions['key'])
            print('Looking for Certificate Extension: "%s"' %
                  self.identities.extensions['certificate'])

            print("Loaded %s identities:\n" % len(self.identities.iddb.keys()))

        # we don't want to overwrite iddb because of the interpreter
        if 'filter' in self.args and self.args['filter']:
            tempiddb = util.dictionary_filter(self.args['filter'],
                                              self.identities.iddb)
        else:
            tempiddb = self.identities.iddb
        for key, _ in tempiddb.items():
            self._print_identity(key)