summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2017-03-11 12:08:21 +0100
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2017-03-12 08:37:53 +0100
commitf472b1656d4c06c35bdef2d231496e8af0ffe699 (patch)
tree05a003ef8078c1ce2b13a4fc62f041c7c23294ee
parent591451930472aa1081a0d264300f72cc98a2c541 (diff)
downloadgnutls-f472b1656d4c06c35bdef2d231496e8af0ffe699.tar.gz
pkcs11: during scan, leave the provider loop asap
This optimizes access when multiple provider modules are available, by avoiding scanning irrelevant ones. Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
-rw-r--r--lib/pkcs11.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/lib/pkcs11.c b/lib/pkcs11.c
index 4bd2f3f232..a7b2c2b2f6 100644
--- a/lib/pkcs11.c
+++ b/lib/pkcs11.c
@@ -1202,6 +1202,11 @@ pkcs11_find_slot(struct ck_function_list **module, ck_slot_id_t * slot,
if (providers[x].active == 0)
continue;
+ if (!p11_kit_uri_match_module_info(info,
+ &providers[x].info)) {
+ continue;
+ }
+
nslots = sizeof(slots) / sizeof(slots[0]);
ret = scan_slots(&providers[x], slots, &nslots);
if (ret < 0) {
@@ -1219,17 +1224,12 @@ pkcs11_find_slot(struct ck_function_list **module, ck_slot_id_t * slot,
continue;
}
- if (pkcs11_get_slot_info
- (providers[x].module, slots[z],
- &sinfo) != CKR_OK) {
+ if (!p11_kit_uri_match_token_info(info, &tinfo)) {
continue;
}
- if (!p11_kit_uri_match_token_info
- (info, &tinfo)
- || !p11_kit_uri_match_module_info(info,
- &providers
- [x].info)) {
+ if (pkcs11_get_slot_info
+ (providers[x].module, slots[z], &sinfo) != CKR_OK) {
continue;
}
@@ -1327,6 +1327,10 @@ _pkcs11_traverse_tokens(find_func_t find_func, void *input,
if (flags & SESSION_TRUSTED && providers[x].trusted == 0)
continue;
+ if (info && !p11_kit_uri_match_module_info(info, &providers[x].info)) {
+ continue;
+ }
+
nslots = sizeof(slots) / sizeof(slots[0]);
ret = scan_slots(&providers[x], slots, &nslots);
if (ret < 0) {
@@ -1344,17 +1348,13 @@ _pkcs11_traverse_tokens(find_func_t find_func, void *input,
continue;
}
- if (pkcs11_get_slot_info(module, slots[z],
- &l_sinfo) != CKR_OK) {
+ if (info && !p11_kit_uri_match_token_info(info, &l_tinfo)) {
continue;
}
- if (info != NULL) {
- if (!p11_kit_uri_match_token_info(info, &l_tinfo) ||
- !p11_kit_uri_match_module_info(info, &providers
- [x].info)) {
+ if (pkcs11_get_slot_info(module, slots[z],
+ &l_sinfo) != CKR_OK) {
continue;
- }
}
rv = (module)->C_OpenSession(slots[z],