| 1 | *** ./engine_pkcs11.c.orig 2008-07-31 10:49:08.000000000 -0400 |
|---|
| 2 | --- ./engine_pkcs11.c 2008-09-09 16:44:15.000000000 -0400 |
|---|
| 3 | *************** |
|---|
| 4 | *** 391,397 **** |
|---|
| 5 | PKCS11_TOKEN *tok; |
|---|
| 6 | PKCS11_CERT *certs, *selected_cert = NULL; |
|---|
| 7 | X509 *x509; |
|---|
| 8 | ! unsigned int count, n, m; |
|---|
| 9 | unsigned char cert_id[MAX_VALUE_LEN / 2]; |
|---|
| 10 | size_t cert_id_len = sizeof(cert_id); |
|---|
| 11 | char *cert_label = NULL; |
|---|
| 12 | --- 391,397 ---- |
|---|
| 13 | PKCS11_TOKEN *tok; |
|---|
| 14 | PKCS11_CERT *certs, *selected_cert = NULL; |
|---|
| 15 | X509 *x509; |
|---|
| 16 | ! unsigned int slot_count, cert_count, n, m; |
|---|
| 17 | unsigned char cert_id[MAX_VALUE_LEN / 2]; |
|---|
| 18 | size_t cert_id_len = sizeof(cert_id); |
|---|
| 19 | char *cert_label = NULL; |
|---|
| 20 | *************** |
|---|
| 21 | *** 425,438 **** |
|---|
| 22 | } |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | ! if (PKCS11_enumerate_slots(ctx, &slot_list, &count) < 0) |
|---|
| 26 | fail("failed to enumerate slots\n"); |
|---|
| 27 | |
|---|
| 28 | if (verbose) { |
|---|
| 29 | ! fprintf(stderr, "Found %u slot%s\n", count, |
|---|
| 30 | ! (count <= 1) ? "" : "s"); |
|---|
| 31 | } |
|---|
| 32 | ! for (n = 0; n < count; n++) { |
|---|
| 33 | slot = slot_list + n; |
|---|
| 34 | flags[0] = '\0'; |
|---|
| 35 | if (slot->token) { |
|---|
| 36 | --- 425,438 ---- |
|---|
| 37 | } |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | ! if (PKCS11_enumerate_slots(ctx, &slot_list, &slot_count) < 0) |
|---|
| 41 | fail("failed to enumerate slots\n"); |
|---|
| 42 | |
|---|
| 43 | if (verbose) { |
|---|
| 44 | ! fprintf(stderr, "Found %u slot%s\n", slot_count, |
|---|
| 45 | ! (slot_count <= 1) ? "" : "s"); |
|---|
| 46 | } |
|---|
| 47 | ! for (n = 0; n < slot_count; n++) { |
|---|
| 48 | slot = slot_list + n; |
|---|
| 49 | flags[0] = '\0'; |
|---|
| 50 | if (slot->token) { |
|---|
| 51 | *************** |
|---|
| 52 | *** 464,483 **** |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | if (slot_nr == -1) { |
|---|
| 56 | ! if (!(slot = PKCS11_find_token(ctx, slot_list, count))) |
|---|
| 57 | fail("didn't find any tokens\n"); |
|---|
| 58 | ! } else if (slot_nr >= 0 && slot_nr < count) |
|---|
| 59 | slot = slot_list + slot_nr; |
|---|
| 60 | else { |
|---|
| 61 | fprintf(stderr, "Invalid slot number: %d\n", slot_nr); |
|---|
| 62 | ! PKCS11_release_all_slots(ctx, slot_list, count); |
|---|
| 63 | return NULL; |
|---|
| 64 | } |
|---|
| 65 | tok = slot->token; |
|---|
| 66 | |
|---|
| 67 | if (tok == NULL) { |
|---|
| 68 | fprintf(stderr, "Found empty token; \n"); |
|---|
| 69 | ! PKCS11_release_all_slots(ctx, slot_list, count); |
|---|
| 70 | return NULL; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | --- 464,483 ---- |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | if (slot_nr == -1) { |
|---|
| 77 | ! if (!(slot = PKCS11_find_token(ctx, slot_list, slot_count))) |
|---|
| 78 | fail("didn't find any tokens\n"); |
|---|
| 79 | ! } else if (slot_nr >= 0 && slot_nr < slot_count) |
|---|
| 80 | slot = slot_list + slot_nr; |
|---|
| 81 | else { |
|---|
| 82 | fprintf(stderr, "Invalid slot number: %d\n", slot_nr); |
|---|
| 83 | ! PKCS11_release_all_slots(ctx, slot_list, slot_count); |
|---|
| 84 | return NULL; |
|---|
| 85 | } |
|---|
| 86 | tok = slot->token; |
|---|
| 87 | |
|---|
| 88 | if (tok == NULL) { |
|---|
| 89 | fprintf(stderr, "Found empty token; \n"); |
|---|
| 90 | ! PKCS11_release_all_slots(ctx, slot_list, slot_count); |
|---|
| 91 | return NULL; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | *************** |
|---|
| 95 | *** 486,503 **** |
|---|
| 96 | fprintf(stderr, "Found token: %s\n", slot->token->label); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | ! if (PKCS11_enumerate_certs(tok, &certs, &count)) { |
|---|
| 100 | fprintf(stderr, "unable to enumerate certificates\n"); |
|---|
| 101 | ! PKCS11_release_all_slots(ctx, slot_list, count); |
|---|
| 102 | return NULL; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | if (verbose) { |
|---|
| 106 | ! fprintf(stderr, "Found %u cert%s:\n", count, |
|---|
| 107 | ! (count <= 1) ? "" : "s"); |
|---|
| 108 | } |
|---|
| 109 | if ((s_slot_cert_id && *s_slot_cert_id) || (cert_id_len == 0)) { |
|---|
| 110 | ! for (n = 0; n < count; n++) { |
|---|
| 111 | PKCS11_CERT *k = certs + n; |
|---|
| 112 | |
|---|
| 113 | if (cert_id_len != 0 && k->id_len == cert_id_len && |
|---|
| 114 | --- 486,503 ---- |
|---|
| 115 | fprintf(stderr, "Found token: %s\n", slot->token->label); |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | ! if (PKCS11_enumerate_certs(tok, &certs, &cert_count)) { |
|---|
| 119 | fprintf(stderr, "unable to enumerate certificates\n"); |
|---|
| 120 | ! PKCS11_release_all_slots(ctx, slot_list, slot_count); |
|---|
| 121 | return NULL; |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | if (verbose) { |
|---|
| 125 | ! fprintf(stderr, "Found %u cert%s:\n", cert_count, |
|---|
| 126 | ! (cert_count <= 1) ? "" : "s"); |
|---|
| 127 | } |
|---|
| 128 | if ((s_slot_cert_id && *s_slot_cert_id) || (cert_id_len == 0)) { |
|---|
| 129 | ! for (n = 0; n < cert_count; n++) { |
|---|
| 130 | PKCS11_CERT *k = certs + n; |
|---|
| 131 | |
|---|
| 132 | if (cert_id_len != 0 && k->id_len == cert_id_len && |
|---|
| 133 | *************** |
|---|
| 134 | *** 511,517 **** |
|---|
| 135 | |
|---|
| 136 | if (selected_cert == NULL) { |
|---|
| 137 | fprintf(stderr, "certificate not found.\n"); |
|---|
| 138 | ! PKCS11_release_all_slots(ctx, slot_list, count); |
|---|
| 139 | return NULL; |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | --- 511,517 ---- |
|---|
| 143 | |
|---|
| 144 | if (selected_cert == NULL) { |
|---|
| 145 | fprintf(stderr, "certificate not found.\n"); |
|---|
| 146 | ! PKCS11_release_all_slots(ctx, slot_list, slot_count); |
|---|
| 147 | return NULL; |
|---|
| 148 | } |
|---|
| 149 | |
|---|