Skip to content

Commit

Permalink
Improve libcrypto detection
Browse files Browse the repository at this point in the history
Closes #23.
  • Loading branch information
jborg committed Jan 9, 2014
1 parent 3a064ab commit c973040
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Version 0.9
- Improved error handling / reporting. (#12)
- Use fcntl() instead of flock() when locking repository/cache. (#15)
- Let ssh figure out port/user if not specified so we don't override .ssh/config (#9)
- Improved libcrypto path detection (#23).

Version 0.8.1
-------------
Expand Down
28 changes: 20 additions & 8 deletions attic/crypto.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
"""A thin ctypes based wrapper for OpenSSL 1.0
"""
import sys
import os
from ctypes import cdll, c_char_p, c_int, c_uint, c_void_p, POINTER, create_string_buffer
from ctypes.util import find_library
import struct

libcrypto = cdll.LoadLibrary(find_library('crypto'))
# Default libcrypto on OS X is too old, try the brew version
if not hasattr(libcrypto, 'PKCS5_PBKDF2_HMAC') and sys.platform == 'darwin':
libcrypto = cdll.LoadLibrary('/usr/local/opt/openssl/lib/libcrypto.dylib')
# Default libcrypto on FreeBSD is too old, try the ports version
if not hasattr(libcrypto, 'PKCS5_PBKDF2_HMAC') and sys.platform.startswith('freebsd'):
libcrypto = cdll.LoadLibrary('/usr/local/lib/libcrypto.so')

def _find_libcrypto():
_possible_paths = [
find_library('crypto'),
os.environ.get('ATTIC_LIBCRYPTO_PATH'),
'/usr/local/opt/openssl/lib/libcrypto.dylib', # OS X Brew
'/usr/local/lib/libcrypto.so', # FreeBSD Ports
'/usr/local/ssl/lib/libcrypto.so'
]
for path in _possible_paths:
try:
lib = cdll.LoadLibrary(path)
if hasattr(lib, 'PKCS5_PBKDF2_HMAC'):
return lib
except OSError:
pass
raise Exception('Failed to find libcrypto version >= 1.0')

libcrypto = _find_libcrypto()

libcrypto.PKCS5_PBKDF2_HMAC.argtypes = (c_char_p, c_int, c_char_p, c_int, c_int, c_void_p, c_int, c_char_p)
libcrypto.EVP_sha256.restype = c_void_p
Expand Down

0 comments on commit c973040

Please sign in to comment.