From 6517d097a3059c25e40bb20124ba56107e5f893a Mon Sep 17 00:00:00 2001 From: nginsburg Date: Sun, 5 Apr 2020 12:57:37 -0400 Subject: [PATCH] parallelize the loading of iddb --- libpkpass/commands/command.py | 4 ++-- libpkpass/identities.py | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/libpkpass/commands/command.py b/libpkpass/commands/command.py index 15e7402..2748349 100644 --- a/libpkpass/commands/command.py +++ b/libpkpass/commands/command.py @@ -372,14 +372,14 @@ def _validate_identities(self, swap_list=None): if not swap_list: swap_list = self.escrow_and_recipient_list for recipient in swap_list: - self.identities.verify_identity(recipient) + self.identities.verify_identity(recipient, []) if recipient not in self.identities.iddb.keys(): raise CliArgumentError( "Error: Recipient '%s' is not in the recipient database" % recipient) if self.args['identity'] in self.identities.iddb.keys(): - self.identities.verify_identity(self.args['identity']) + self.identities.verify_identity(self.args['identity'], []) else: raise CliArgumentError( "Error: Your user '%s' is not in the recipient database" % diff --git a/libpkpass/identities.py b/libpkpass/identities.py index bd2d927..5cc2fa1 100644 --- a/libpkpass/identities.py +++ b/libpkpass/identities.py @@ -1,6 +1,7 @@ """This Module handles the identitydb object""" import os import tempfile +import threading import libpkpass.crypto as crypto from libpkpass.errors import FileOpenError, CliArgumentError @@ -77,12 +78,22 @@ def load_certs_from_directory(self, if certpath: self._load_from_directory(certpath, 'certificate') if verify_on_load: - for key, _ in self.iddb.items(): - self.verify_identity(key) + x_ls = self.iddb.keys() + thread_list = [] + results = [] + for username in x_ls: + thread = threading.Thread(target=self.verify_identity, args=(username, results)) + thread_list.append(thread) + for thread in thread_list: + thread.start() + for thread in thread_list: + thread.join() ####################################################################### - def verify_identity(self, identity): - """ Read in all rsa keys from directory and name them as found """ + def verify_identity(self, identity, results): + """ Read in all rsa keys from directory and name them as found + results is a meaningless parameter, but is required to make threading work + """ ####################################################################### try: self.iddb[identity]['cabundle'] = self.cabundle