GNOME Bugzilla – Bug 680652
gcr_pkcs11_get_modules() returns NULL when not initialized
Last modified: 2019-02-22 11:59:37 UTC
gcr_pkcs11_get_modules() should return an empty list if no gcr_pkcs11_initialize() yet. It shouldn't need to warn about this. We use gcr_pkcs11_get_modules() in various code that doesn't expect to do a long running operation like gcr_pkcs11_initialize(). So gcr_pkcs11_initialize() needs to be called separately before use of the pkcs11 stuff.
Created attachment 219693 [details] [review] gcr: Don't fail preconditions when pkcs11 isn't initialized * Callers should initialize pkcs11 early, because initialize can be a long running call, and should be handled appropriately in the user interface.
Comment on attachment 219693 [details] [review] gcr: Don't fail preconditions when pkcs11 isn't initialized >+ * An empty list of modules will be returnef if gcr_pkcs11_set_modules(), ^ typo but isn't return-if-fail correct? You shouldn't be calling gcr_pkcs11_get_modules() if you haven't initialized gcr-pkcs11...
(In reply to comment #2) > (From update of attachment 219693 [details] [review]) > >+ * An empty list of modules will be returnef if gcr_pkcs11_set_modules(), > ^ typo > > but isn't return-if-fail correct? You shouldn't be calling > gcr_pkcs11_get_modules() if you haven't initialized gcr-pkcs11... Yeah, that's what I thought at first too but: We call gcr_pkcs11_get_modules() from the GcrPkcs11Importer. gcr_importer_create_for_parsed() calls for all registered importers, of which GcrPkcs11Importer is one. Not all importers use PKCS#11 modules. So we want the GcrPkcs11Importer to be a noop if PKCS#11 hasn't been initialized. Another way to do that is to only register the GcrPkcs11Importer once pkcs11 modules have been initialized. Does that seem better?
Created attachment 219705 [details] [review] gcr: Don't fail preconditions when pkcs11 isn't initialized * Callers should initialize pkcs11 early, because initialize can be a long running call, and should be handled appropriately in the user interface.
Attachment 219705 [details] pushed as a6fe45c - gcr: Don't fail preconditions when pkcs11 isn't initialized