#include <gnutls/x509.h>
#include "../utils.h"
+#include "softhsm.h"
#include "../test-chains.h"
#define URL "pkcs11:model=SoftHSM;manufacturer=SoftHSM;serial=1;token=test"
return -1;
}
-#define LIB1 "/usr/lib64/softhsm/libsofthsm.so"
-#define LIB2 "/usr/lib/softhsm/libsofthsm.so"
-
void doit(void)
{
int exit_val = 0;
size_t i;
int ret;
FILE *fp;
- const char *lib;
+ const char *lib, *bin;
gnutls_typed_vdata_st vdata[2];
+ char buf[128];
unsetenv("SOFTHSM_CONF");
/* The overloading of time() seems to work in linux (ELF?)
exit(77);
#endif
- if (access("/usr/bin/softhsm", X_OK) < 0) {
- fprintf(stderr, "cannot find softhsm binary\n");
- exit(77);
- }
-
- if (access(LIB1, R_OK) == 0) {
- lib = LIB1;
- } else if (access(LIB2, R_OK) == 0) {
- lib = LIB2;
- } else {
- fprintf(stderr, "cannot find softhsm module\n");
- exit(77);
- }
+ bin = softhsm_bin();
+ lib = softhsm_lib();
ret = global_init();
if (ret != 0) {
setenv("SOFTHSM_CONF", CONFIG, 0);
- system("softhsm --init-token --slot 0 --label test --so-pin 1234 --pin 1234");
+ snprintf(buf, sizeof(buf), "%s --init-token --slot 0 --label test --so-pin 1234 --pin 1234", bin);
+ system(buf);
ret = gnutls_pkcs11_add_provider(lib, "trusted");
if (ret < 0) {
#include "../utils.h"
#include "../test-chains.h"
+#include "softhsm.h"
#define URL "pkcs11:model=SoftHSM;manufacturer=SoftHSM;serial=1;token=test"
#define NAME "softhsm-combo"
return -1;
}
-#define LIB1 "/usr/lib64/softhsm/libsofthsm.so"
-#define LIB2 "/usr/lib/softhsm/libsofthsm.so"
-
void doit(void)
{
+ char buf[128];
int exit_val = 0;
int ret;
unsigned j;
FILE *fp;
- const char *lib;
+ const char *lib, *bin;
gnutls_x509_crt_t issuer = NULL;
gnutls_x509_trust_list_t tl;
gnutls_x509_crt_t certs[MAX_CHAIN];
#ifdef _WIN32
exit(77);
#endif
- if (access("/usr/bin/softhsm", X_OK) < 0) {
- fprintf(stderr, "cannot find softhsm binary\n");
- exit(77);
- }
-
- if (access(LIB1, R_OK) == 0) {
- lib = LIB1;
- } else if (access(LIB2, R_OK) == 0) {
- lib = LIB2;
- } else {
- fprintf(stderr, "cannot find softhsm module\n");
- exit(77);
- }
+ bin = softhsm_bin();
+ lib = softhsm_lib();
ret = global_init();
if (ret != 0) {
setenv("SOFTHSM_CONF", CONFIG, 0);
- system("/usr/bin/softhsm --init-token --slot 0 --label test --so-pin "PIN" --pin "PIN);
+ snprintf(buf, sizeof(buf), "%s --init-token --slot 0 --label test --so-pin "PIN" --pin "PIN, bin);
+ system(buf);
ret = gnutls_pkcs11_add_provider(lib, "trusted");
if (ret < 0) {
#include "../utils.h"
#include "../test-chains.h"
+#include "softhsm.h"
#define URL "pkcs11:model=SoftHSM;manufacturer=SoftHSM;serial=1;token=test"
#define CONFIG "softhsm-issuer.config"
return -1;
}
-#define LIB1 "/usr/lib64/softhsm/libsofthsm.so"
-#define LIB2 "/usr/lib/softhsm/libsofthsm.so"
-
void doit(void)
{
+ char buf[128];
int exit_val = 0;
int ret;
unsigned j;
FILE *fp;
- const char *lib;
+ const char *lib, *bin;
gnutls_x509_crt_t issuer = NULL;
gnutls_x509_trust_list_t tl;
gnutls_x509_crt_t certs[MAX_CHAIN];
exit(1);
}
- if (access("/usr/bin/softhsm", X_OK) < 0) {
- fprintf(stderr, "cannot find softhsm binary\n");
- exit(77);
- }
-
- if (access(LIB1, R_OK) == 0) {
- lib = LIB1;
- } else if (access(LIB2, R_OK) == 0) {
- lib = LIB2;
- } else {
- fprintf(stderr, "cannot find softhsm module\n");
- exit(77);
- }
+ bin = softhsm_bin();
+ lib = softhsm_lib();
ret = global_init();
if (ret != 0) {
setenv("SOFTHSM_CONF", CONFIG, 0);
- system("/usr/bin/softhsm --init-token --slot 0 --label test --so-pin "PIN" --pin "PIN);
+ snprintf(buf, sizeof(buf), "%s --init-token --slot 0 --label test --so-pin "PIN" --pin "PIN, bin);
+ system(buf);
ret = gnutls_pkcs11_add_provider(lib, "trusted");
if (ret < 0) {
#include <gnutls/x509-ext.h>
#include "../utils.h"
+#include "softhsm.h"
#define MAX_CHAIN 16
return -1;
}
-#define LIB1 "/usr/lib64/softhsm/libsofthsm.so"
-#define LIB2 "/usr/lib/softhsm/libsofthsm.so"
-
void doit(void)
{
+ char buf[128];
int exit_val = 0;
int ret;
unsigned j;
FILE *fp;
- const char *lib;
+ const char *lib, *bin;
gnutls_x509_crt_t issuer = NULL;
gnutls_x509_trust_list_t tl;
gnutls_x509_crt_t certs[MAX_CHAIN];
#ifdef _WIN32
exit(77);
#endif
- if (access("/usr/bin/softhsm", X_OK) < 0) {
- fprintf(stderr, "cannot find softhsm binary\n");
- exit(77);
- }
-
- if (access(LIB1, R_OK) == 0) {
- lib = LIB1;
- } else if (access(LIB2, R_OK) == 0) {
- lib = LIB2;
- } else {
- fprintf(stderr, "cannot find softhsm module\n");
- exit(77);
- }
+ bin = softhsm_bin();
+ lib = softhsm_lib();
ret = global_init();
if (ret != 0) {
setenv("SOFTHSM_CONF", CONFIG, 0);
- system("/usr/bin/softhsm --init-token --slot 0 --label test --so-pin "PIN" --pin "PIN);
+ snprintf(buf, sizeof(buf), "%s --init-token --slot 0 --label test --so-pin "PIN" --pin "PIN, bin);
+ system(buf);
ret = gnutls_pkcs11_add_provider(lib, "trusted");
if (ret < 0) {
#include <gnutls/x509-ext.h>
#include "../utils.h"
+#include "softhsm.h"
/* Tests whether gnutls_certificate_set_x509_key_file2() will utilize
* the provided password as PIN when PKCS #11 keys are imported */
return -1;
}
-#define LIB1 "/usr/lib64/softhsm/libsofthsm.so"
-#define LIB2 "/usr/lib/softhsm/libsofthsm.so"
-
void doit(void)
{
+ char buf[128];
int exit_val = 0;
int ret;
FILE *fp;
- const char *lib;
+ const char *lib, *bin;
gnutls_x509_crt_t crt;
gnutls_x509_privkey_t key;
gnutls_certificate_credentials_t cred;
#ifdef _WIN32
exit(77);
#endif
- if (access("/usr/bin/softhsm", X_OK) < 0) {
- fprintf(stderr, "cannot find softhsm binary\n");
- exit(77);
- }
-
- if (access(LIB1, R_OK) == 0) {
- lib = LIB1;
- } else if (access(LIB2, R_OK) == 0) {
- lib = LIB2;
- } else {
- fprintf(stderr, "cannot find softhsm module\n");
- exit(77);
- }
+ bin = softhsm_bin();
+ lib = softhsm_lib();
ret = global_init();
if (ret != 0) {
setenv("SOFTHSM_CONF", CONFIG, 0);
- system("/usr/bin/softhsm --init-token --slot 0 --label test --so-pin "PIN" --pin "PIN);
+ snprintf(buf, sizeof(buf), "%s --init-token --slot 0 --label test --so-pin "PIN" --pin "PIN, bin);
+ system(buf);
ret = gnutls_pkcs11_add_provider(lib, "trusted");
if (ret < 0) {
--- /dev/null
+/*
+ * Copyright (C) 2014 Nikos Mavrogiannopoulos
+ *
+ * This file is part of GnuTLS.
+ *
+ * GnuTLS is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuTLS is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GnuTLS; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef SOFTHSM_H
+# define SOFTHSM_H
+
+#define LIB1 "/usr/lib64/softhsm/libsofthsm.so"
+#define LIB2 "/usr/lib/softhsm/libsofthsm.so"
+#define LIB3 "/usr/local/lib/softhsm/libsofthsm.so"
+
+inline static const char *softhsm_lib(void)
+{
+ const char *lib;
+
+ if (access(LIB1, R_OK) == 0) {
+ lib = LIB1;
+ } else if (access(LIB2, R_OK) == 0) {
+ lib = LIB2;
+ } else if (access(LIB3, R_OK) == 0) {
+ lib = LIB3;
+ } else {
+ fprintf(stderr, "cannot find softhsm module\n");
+ exit(77);
+ }
+
+ return lib;
+}
+
+inline static const char *softhsm_bin(void)
+{
+ const char *bin;
+
+ if (access("/usr/bin/softhsm", X_OK) == 0) {
+ bin = "/usr/bin/softhsm";
+ } else if (access("/usr/local/bin/softhsm", X_OK) == 0) {
+ bin = "/usr/local/bin/softhsm";
+ } else {
+ fprintf(stderr, "cannot find softhsm module\n");
+ exit(77);
+ }
+
+ return bin;
+}
+
+#endif
export SOFTHSM_CONF="softhsm-testpkcs11.config"
-if test -f /usr/lib/softhsm/libsofthsm.so;then
- ADDITIONAL_PARAM="--provider /usr/lib/softhsm/libsofthsm.so"
+if test -f /usr/local/lib/softhsm/libsofthsm.so;then
+ ADDITIONAL_PARAM="--provider /usr/local/lib/softhsm/libsofthsm.so"
else
- ADDITIONAL_PARAM="--provider /usr/lib64/softhsm/libsofthsm.so"
+ if test -f /usr/lib/softhsm/libsofthsm.so;then
+ ADDITIONAL_PARAM="--provider /usr/lib/softhsm/libsofthsm.so"
+ else
+ ADDITIONAL_PARAM="--provider /usr/lib64/softhsm/libsofthsm.so"
+ fi
fi
init_card () {