From: Nikos Mavrogiannopoulos Date: Fri, 12 Sep 2014 09:31:28 +0000 (+0200) Subject: pkcs11-get-issuer: do not hardcode the chain number, use its name X-Git-Tag: gnutls_3_4_0~949 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=76a00c50a4735d799dc1ad492fe5db049e3bc4e6;p=thirdparty%2Fgnutls.git pkcs11-get-issuer: do not hardcode the chain number, use its name --- diff --git a/tests/suite/pkcs11-get-issuer.c b/tests/suite/pkcs11-get-issuer.c index d1e25803ca..121f208fca 100644 --- a/tests/suite/pkcs11-get-issuer.c +++ b/tests/suite/pkcs11-get-issuer.c @@ -31,6 +31,7 @@ #include #include +#include #include "../utils.h" #include "../test-chains.h" @@ -85,6 +86,7 @@ void doit(void) gnutls_x509_crt_t certs[MAX_CHAIN]; gnutls_x509_crt_t ca; gnutls_datum_t tmp; + int idx = -1; unsetenv("SOFTHSM_CONF"); /* The overloading of time() seems to work in linux (ELF?) @@ -93,6 +95,19 @@ void doit(void) #ifdef _WIN32 exit(77); #endif + for (j=0;;j++) { + if (chains[j].name == NULL) + break; + if (strcmp(chains[j].name, "verisign.com v1 ok") == 0) { + idx = j; + break; + } + } + + if (idx == -1) { + fail("could not find proper chain\n"); + exit(1); + } if (access("/usr/bin/softhsm", X_OK) < 0) { fprintf(stderr, "cannot find softhsm binary\n"); @@ -142,7 +157,7 @@ void doit(void) exit(1); } - for (j = 0; chains[3].chain[j]; j++) { + for (j = 0; chains[idx].chain[j]; j++) { if (debug > 2) printf("\tAdding certificate %d...", (int) j); @@ -156,8 +171,8 @@ void doit(void) exit(1); } - tmp.data = (unsigned char *) chains[3].chain[j]; - tmp.size = strlen(chains[3].chain[j]); + tmp.data = (unsigned char *) chains[idx].chain[j]; + tmp.size = strlen(chains[idx].chain[j]); ret = gnutls_x509_crt_import(certs[j], &tmp, @@ -167,7 +182,7 @@ void doit(void) if (ret < 0) { fprintf(stderr, "gnutls_x509_crt_import[%s,%d]: %s\n", - chains[3].name, (int) j, + chains[idx].name, (int) j, gnutls_strerror(ret)); exit(1); } @@ -191,8 +206,8 @@ void doit(void) exit(1); } - tmp.data = (unsigned char *) *chains[3].ca; - tmp.size = strlen(*chains[3].ca); + tmp.data = (unsigned char *) *chains[idx].ca; + tmp.size = strlen(*chains[idx].ca); ret = gnutls_x509_crt_import(ca, &tmp, GNUTLS_X509_FMT_PEM); @@ -255,7 +270,7 @@ void doit(void) gnutls_x509_trust_list_deinit(tl, 0); gnutls_x509_crt_deinit(ca); - for (j = 0; chains[3].chain[j]; j++) + for (j = 0; chains[idx].chain[j]; j++) gnutls_x509_crt_deinit(certs[j]); if (debug) printf("done\n\n\n");