From ccef1b59bc6cca89474eaddf7144972926281e29 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Wed, 10 May 2017 19:56:44 -0400 Subject: Clean up default location of PKCS #11 library. --- Makefile | 2 +- cryptech/py11/__init__.py | 11 ++++++++++- scripts/time-signature.py | 7 +------ unit_tests.py | 8 +------- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 954380e..ccee996 100644 --- a/Makefile +++ b/Makefile @@ -193,7 +193,7 @@ TAGS: *.[ch] # Basic testing, via the Python unittest library and our cryptech.py11 interface code test: all - python unit_tests.py + python unit_tests.py --libpkcs11 ./${SONAME} # Further testing using hsmbully, if we can find a copy of it. diff --git a/cryptech/py11/__init__.py b/cryptech/py11/__init__.py index fb9af7e..1618a76 100644 --- a/cryptech/py11/__init__.py +++ b/cryptech/py11/__init__.py @@ -12,6 +12,15 @@ from .types import * from .constants import * from .attributes import * +import platform + +if platform.system() == "Darwin": + default_so_name = "/usr/local/lib/libcryptech-pkcs11.dylib" +elif platform.system() == "Linux": + default_so_name = "/usr/lib/libcryptech-pkcs11.so" +else: + default_so_name = "/usr/local/lib/libcryptech-pkcs11.so" + class PKCS11 (object): """ @@ -46,7 +55,7 @@ class PKCS11 (object): # Whether to use C_GetFunctionList() instead of dynamic link symbols. use_C_GetFunctionList = False - def __init__(self, so_name = "libpkcs11.so"): + def __init__(self, so_name = default_so_name): self.so_name = so_name self.so = CDLL(so_name) self.d = type("Dispatch", (object,), {})() diff --git a/scripts/time-signature.py b/scripts/time-signature.py index 99ec718..732eaa4 100755 --- a/scripts/time-signature.py +++ b/scripts/time-signature.py @@ -7,7 +7,6 @@ Time PKCS #11 signatures. import collections import argparse import datetime -import platform import sys from Crypto.Hash.SHA256 import SHA256Hash as SHA256 @@ -22,11 +21,7 @@ except ImportError: sys.path.append(dirname(dirname(abspath(sys.argv[0])))) from cryptech.py11 import * - -if platform.system() == "Darwin": - libpkcs11_default = "./libcryptech-pkcs11.dylib" -else: - libpkcs11_default = "./libcryptech-pkcs11.so" +from cryptech.py11 import default_so_name as libpkcs11_default class RSAKey(object): diff --git a/unit_tests.py b/unit_tests.py index fe96207..e4c4a97 100644 --- a/unit_tests.py +++ b/unit_tests.py @@ -6,10 +6,10 @@ PKCS #11 unit tests, using cryptech.py11 and the Python unit_test framework. import unittest import datetime -import platform import sys from cryptech.py11 import * +from cryptech.py11 import default_so_name as libpkcs11_default from cryptech.py11.mutex import MutexDB try: @@ -22,12 +22,6 @@ except ImportError: pycrypto_loaded = False -if platform.system() == "Darwin": - libpkcs11_default = "./libcryptech-pkcs11.dylib" -else: - libpkcs11_default = "./libcryptech-pkcs11.so" - - def log(msg): if not args.quiet: sys.stderr.write(msg) -- cgit v1.2.3