Skip to content

use MacOS builtin security framework instead of homebrew - #126

Open
rob-miller wants to merge 1 commit into
Leseratte10:masterfrom
rob-miller:macos-homebrew-openssl-fix
Open

use MacOS builtin security framework instead of homebrew#126
rob-miller wants to merge 1 commit into
Leseratte10:masterfrom
rob-miller:macos-homebrew-openssl-fix

Conversation

@rob-miller

Copy link
Copy Markdown

Admittedly with help from Claude and many hours trying different things, this works on my MacOS system to install and use the acsm calibre plugin with homebrew installed openssl@3 without 'brew un/link openssl@3'. Basically this just uses the system crypto libraries if they are available.

With this change to init.py, I can successfully load the plugin on MacOS Sequoia 15.4 with homebrew installed (and linked) openssl@3 and then drag in .acsm files and get the epub loaded.

Closes #106 and better addresses #109, #65 and #63.

@Leseratte10

Copy link
Copy Markdown
Owner

Thanks for the MR. I do not have a Mac to test this, though, so I'd prefer to get some feedback from other MacOS users if this fixes some of the outstanding issues on MacOS.

Also, I noticed that you hard-coded "libcrypto.46.dylib" and "libssl.46.dylib" - is this a good idea / is this always the file name on all versions of MacOS and unlikely to change in the future? Or can this be made to dynamically find the proper file name?

@rob-miller
rob-miller force-pushed the macos-homebrew-openssl-fix branch from 0190906 to ce0ef87 Compare May 10, 2025 20:38
re-write with better understanding of Mac security framework and dyld shared cache
@rob-miller
rob-miller force-pushed the macos-homebrew-openssl-fix branch from 6a85ac4 to d145292 Compare May 10, 2025 21:04
@rob-miller

Copy link
Copy Markdown
Author

I thought the 'lib*.46.dylib' was just a last resort as a default to return, but it turns out that is what is needed for loading libadobe on MacOS with Homebrew openssl libs.

MacOS doesn't actually have the files in its directory, but they are in its 'dyld shared cache' to be loaded. If you try to load something more generic like /usr/lib/libcrypto.dylib the OS will crash your entire program with an error saying "don't do that, the API is not stable". Explicitly using the Apple Security Framework as I had before does not work because libadobe looks for 'OpenSSL version' which is not available.

So this code tries the .46 version (available since 2020) and then the .35 version (available since 2015) and tests loading libadobe for each; if neither works it gives up with a message seen if running in the terminal.

There's also:

  • code to get the environment variables on a Mac if running from a terminal instead of the GUI
  • avoids checking if the path exists when loading libraries specified in env variables on Mac, as the files are probably not there

How do we find someone else with a Mac to review this? Add to the Mobilread thread?

@mettavi

mettavi commented Jul 5, 2025

Copy link
Copy Markdown

Hi, I am running Calibre 8.5 on MacOS Sequoia 5.5 (x86_64) with homebrew installed. I am having the same problem, and I saw this PR, so thought I would test it on my own system.

Here is my process for reproduction:

  1. Download the repo code as a zip file as at commit d145292
  2. Unzip the zip file, cd into the top level folder, and run the bundle_calibre_plugin.sh script, which creates a calibre-plugin.zip file.
  3. Open calibre, and install the plugin from the zip file.

It installed cleanly!

Then I registered an anonymous adobe ID and tested the import of an epub and a pdf from the adobe test library. Success again!

Thanks for the plugin and the PR!

@prostolyubo

Copy link
Copy Markdown

Unfortunatelly the fix does not work for me. I still get:

calibre, version 6.29.0
ERROR: Unhandled exception: <b>InvalidPlugin</b>:Initialization of plugin Traceback (most recent call last):
  File "calibre_plugins.deacsm.__init__", line 184, in initialize
  File "&lt;frozen importlib._bootstrap&gt;", line 1027, in _find_and_load
  File "&lt;frozen importlib._bootstrap&gt;", line 1006, in _find_and_load_unlocked
  File "&lt;frozen importlib._bootstrap&gt;", line 688, in _load_unlocked
  File "calibre/customize/zipplugin.py", line 206, in exec_module
  File "calibre_plugins.deacsm.libadobe", line 59, in &lt;module&gt;
    # This is a list of versions that can be used for new authorizations:
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/keys.py", line 5, in &lt;module&gt;
    from ._asymmetric import parse_certificate, parse_private, parse_public
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_asymmetric.py", line 27, in &lt;module&gt;
    from .kdf import pbkdf1, pbkdf2, pkcs12_kdf
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/kdf.py", line 9, in &lt;module&gt;
    from .util import rand_bytes
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/util.py", line 10, in &lt;module&gt;
    from ._mac.util import rand_bytes
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_mac/util.py", line 208, in &lt;module&gt;
    from .._openssl._libcrypto import libcrypto
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_openssl/_libcrypto.py", line 24, in &lt;module&gt;
    from ._libcrypto_ctypes import (
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_openssl/_libcrypto_ctypes.py", line 30, in &lt;module&gt;
    libcrypto = CDLL(libcrypto_path, use_errno=True)
  File "ctypes/__init__.py", line 374, in __init__
OSError: dlopen(/usr/local/lib/libcrypto.dylib, 0x0006): tried: '/usr/local/lib/libcrypto.dylib' (code signature in &lt;0717C03A-6252-3ADC-96B9-47B651E22388&gt; '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.), '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' (code signature in &lt;0717C03A-6252-3ADC-96B9-47B651E22388&gt; '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "calibre/customize/ui.py", line 710, in initialize_plugin
  File "calibre_plugins.deacsm.__init__", line 187, in initialize
    # Also extract EXE files needed for WINE ADE key extraction
  File "/Users/heti/Downloads/DeACSM_0.0.16_bak/DeAscm_0016.zip/libadobe.py", line 59, in &lt;module&gt;
    from oscrypto import keys
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/keys.py", line 5, in &lt;module&gt;
    from ._asymmetric import parse_certificate, parse_private, parse_public
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_asymmetric.py", line 27, in &lt;module&gt;
    from .kdf import pbkdf1, pbkdf2, pkcs12_kdf
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/kdf.py", line 9, in &lt;module&gt;
    from .util import rand_bytes
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/util.py", line 10, in &lt;module&gt;
    from ._mac.util import rand_bytes
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_mac/util.py", line 208, in &lt;module&gt;
    from .._openssl._libcrypto import libcrypto
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_openssl/_libcrypto.py", line 24, in &lt;module&gt;
    from ._libcrypto_ctypes import (
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_openssl/_libcrypto_ctypes.py", line 30, in &lt;module&gt;
    libcrypto = CDLL(libcrypto_path, use_errno=True)
  File "ctypes/__init__.py", line 374, in __init__
OSError: dlopen(/usr/local/lib/libcrypto.dylib, 0x0006): tried: '/usr/local/lib/libcrypto.dylib' (code signature in &lt;0717C03A-6252-3ADC-96B9-47B651E22388&gt; '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.), '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' (code signature in &lt;0717C03A-6252-3ADC-96B9-47B651E22388&gt; '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.)
 failed with traceback:
Traceback (most recent call last):
  File "calibre_plugins.deacsm.__init__", line 184, in initialize
  File "&lt;frozen importlib._bootstrap&gt;", line 1027, in _find_and_load
  File "&lt;frozen importlib._bootstrap&gt;", line 1006, in _find_and_load_unlocked
  File "&lt;frozen importlib._bootstrap&gt;", line 688, in _load_unlocked
  File "calibre/customize/zipplugin.py", line 206, in exec_module
  File "calibre_plugins.deacsm.libadobe", line 59, in &lt;module&gt;
    # This is a list of versions that can be used for new authorizations:
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/keys.py", line 5, in &lt;module&gt;
    from ._asymmetric import parse_certificate, parse_private, parse_public
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_asymmetric.py", line 27, in &lt;module&gt;
    from .kdf import pbkdf1, pbkdf2, pkcs12_kdf
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/kdf.py", line 9, in &lt;module&gt;
    from .util import rand_bytes
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/util.py", line 10, in &lt;module&gt;
    from ._mac.util import rand_bytes
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_mac/util.py", line 208, in &lt;module&gt;
    from .._openssl._libcrypto import libcrypto
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_openssl/_libcrypto.py", line 24, in &lt;module&gt;
    from ._libcrypto_ctypes import (
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_openssl/_libcrypto_ctypes.py", line 30, in &lt;module&gt;
    libcrypto = CDLL(libcrypto_path, use_errno=True)
  File "ctypes/__init__.py", line 374, in __init__
OSError: dlopen(/usr/local/lib/libcrypto.dylib, 0x0006): tried: '/usr/local/lib/libcrypto.dylib' (code signature in &lt;0717C03A-6252-3ADC-96B9-47B651E22388&gt; '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.), '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' (code signature in &lt;0717C03A-6252-3ADC-96B9-47B651E22388&gt; '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "calibre/customize/ui.py", line 710, in initialize_plugin
  File "calibre_plugins.deacsm.__init__", line 187, in initialize
    # Also extract EXE files needed for WINE ADE key extraction
  File "/Users/heti/Downloads/DeACSM_0.0.16_bak/DeAscm_0016.zip/libadobe.py", line 59, in &lt;module&gt;
    from oscrypto import keys
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/keys.py", line 5, in &lt;module&gt;
    from ._asymmetric import parse_certificate, parse_private, parse_public
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_asymmetric.py", line 27, in &lt;module&gt;
    from .kdf import pbkdf1, pbkdf2, pkcs12_kdf
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/kdf.py", line 9, in &lt;module&gt;
    from .util import rand_bytes
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/util.py", line 10, in &lt;module&gt;
    from ._mac.util import rand_bytes
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_mac/util.py", line 208, in &lt;module&gt;
    from .._openssl._libcrypto import libcrypto
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_openssl/_libcrypto.py", line 24, in &lt;module&gt;
    from ._libcrypto_ctypes import (
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_openssl/_libcrypto_ctypes.py", line 30, in &lt;module&gt;
    libcrypto = CDLL(libcrypto_path, use_errno=True)
  File "ctypes/__init__.py", line 374, in __init__
OSError: dlopen(/usr/local/lib/libcrypto.dylib, 0x0006): tried: '/usr/local/lib/libcrypto.dylib' (code signature in &lt;0717C03A-6252-3ADC-96B9-47B651E22388&gt; '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.), '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' (code signature in &lt;0717C03A-6252-3ADC-96B9-47B651E22388&gt; '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.)


calibre 6.29  embedded-python: True
macOS-12.7.6-x86_64-i386-64bit Darwin ('64bit', '')
('Darwin', '21.6.0', 'Darwin Kernel Version 21.6.0: Mon Jun 24 00:56:10 PDT 2024; root:xnu-8020.240.18.709.2~1/RELEASE_X86_64')
Python 3.10.1
OSX: ('12.7.6', ('', '', ''), 'x86_64')
Interface language: None
Successfully initialized third party plugins: DeDRM (10, 0, 3)
Traceback (most recent call last):
  File "calibre_plugins.deacsm.__init__", line 184, in initialize
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "calibre/customize/zipplugin.py", line 206, in exec_module
  File "calibre_plugins.deacsm.libadobe", line 59, in <module>
    # This is a list of versions that can be used for new authorizations:
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/keys.py", line 5, in <module>
    from ._asymmetric import parse_certificate, parse_private, parse_public
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_asymmetric.py", line 27, in <module>
    from .kdf import pbkdf1, pbkdf2, pkcs12_kdf
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/kdf.py", line 9, in <module>
    from .util import rand_bytes
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/util.py", line 10, in <module>
    from ._mac.util import rand_bytes
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_mac/util.py", line 208, in <module>
    from .._openssl._libcrypto import libcrypto
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_openssl/_libcrypto.py", line 24, in <module>
    from ._libcrypto_ctypes import (
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_openssl/_libcrypto_ctypes.py", line 30, in <module>
    libcrypto = CDLL(libcrypto_path, use_errno=True)
  File "ctypes/__init__.py", line 374, in __init__
OSError: dlopen(/usr/local/lib/libcrypto.dylib, 0x0006): tried: '/usr/local/lib/libcrypto.dylib' (code signature in <0717C03A-6252-3ADC-96B9-47B651E22388> '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.), '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' (code signature in <0717C03A-6252-3ADC-96B9-47B651E22388> '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "calibre/customize/ui.py", line 710, in initialize_plugin
  File "calibre_plugins.deacsm.__init__", line 187, in initialize
    # Also extract EXE files needed for WINE ADE key extraction
  File "/Users/heti/Downloads/DeACSM_0.0.16_bak/DeAscm_0016.zip/libadobe.py", line 59, in <module>
    from oscrypto import keys
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/keys.py", line 5, in <module>
    from ._asymmetric import parse_certificate, parse_private, parse_public
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_asymmetric.py", line 27, in <module>
    from .kdf import pbkdf1, pbkdf2, pkcs12_kdf
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/kdf.py", line 9, in <module>
    from .util import rand_bytes
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/util.py", line 10, in <module>
    from ._mac.util import rand_bytes
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_mac/util.py", line 208, in <module>
    from .._openssl._libcrypto import libcrypto
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_openssl/_libcrypto.py", line 24, in <module>
    from ._libcrypto_ctypes import (
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_openssl/_libcrypto_ctypes.py", line 30, in <module>
    libcrypto = CDLL(libcrypto_path, use_errno=True)
  File "ctypes/__init__.py", line 374, in __init__
OSError: dlopen(/usr/local/lib/libcrypto.dylib, 0x0006): tried: '/usr/local/lib/libcrypto.dylib' (code signature in <0717C03A-6252-3ADC-96B9-47B651E22388> '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.), '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' (code signature in <0717C03A-6252-3ADC-96B9-47B651E22388> '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "calibre/gui2/preferences/plugins.py", line 325, in add_plugin
  File "calibre/customize/ui.py", line 520, in add_plugin
  File "calibre/customize/ui.py", line 715, in initialize_plugin
calibre.customize.InvalidPlugin: Initialization of plugin Traceback (most recent call last):
  File "calibre_plugins.deacsm.__init__", line 184, in initialize
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "calibre/customize/zipplugin.py", line 206, in exec_module
  File "calibre_plugins.deacsm.libadobe", line 59, in <module>
    # This is a list of versions that can be used for new authorizations:
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/keys.py", line 5, in <module>
    from ._asymmetric import parse_certificate, parse_private, parse_public
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_asymmetric.py", line 27, in <module>
    from .kdf import pbkdf1, pbkdf2, pkcs12_kdf
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/kdf.py", line 9, in <module>
    from .util import rand_bytes
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/util.py", line 10, in <module>
    from ._mac.util import rand_bytes
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_mac/util.py", line 208, in <module>
    from .._openssl._libcrypto import libcrypto
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_openssl/_libcrypto.py", line 24, in <module>
    from ._libcrypto_ctypes import (
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_openssl/_libcrypto_ctypes.py", line 30, in <module>
    libcrypto = CDLL(libcrypto_path, use_errno=True)
  File "ctypes/__init__.py", line 374, in __init__
OSError: dlopen(/usr/local/lib/libcrypto.dylib, 0x0006): tried: '/usr/local/lib/libcrypto.dylib' (code signature in <0717C03A-6252-3ADC-96B9-47B651E22388> '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.), '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' (code signature in <0717C03A-6252-3ADC-96B9-47B651E22388> '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "calibre/customize/ui.py", line 710, in initialize_plugin
  File "calibre_plugins.deacsm.__init__", line 187, in initialize
    # Also extract EXE files needed for WINE ADE key extraction
  File "/Users/heti/Downloads/DeACSM_0.0.16_bak/DeAscm_0016.zip/libadobe.py", line 59, in <module>
    from oscrypto import keys
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/keys.py", line 5, in <module>
    from ._asymmetric import parse_certificate, parse_private, parse_public
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_asymmetric.py", line 27, in <module>
    from .kdf import pbkdf1, pbkdf2, pkcs12_kdf
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/kdf.py", line 9, in <module>
    from .util import rand_bytes
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/util.py", line 10, in <module>
    from ._mac.util import rand_bytes
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_mac/util.py", line 208, in <module>
    from .._openssl._libcrypto import libcrypto
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_openssl/_libcrypto.py", line 24, in <module>
    from ._libcrypto_ctypes import (
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_openssl/_libcrypto_ctypes.py", line 30, in <module>
    libcrypto = CDLL(libcrypto_path, use_errno=True)
  File "ctypes/__init__.py", line 374, in __init__
OSError: dlopen(/usr/local/lib/libcrypto.dylib, 0x0006): tried: '/usr/local/lib/libcrypto.dylib' (code signature in <0717C03A-6252-3ADC-96B9-47B651E22388> '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.), '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' (code signature in <0717C03A-6252-3ADC-96B9-47B651E22388> '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.)
 failed with traceback:
Traceback (most recent call last):
  File "calibre_plugins.deacsm.__init__", line 184, in initialize
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "calibre/customize/zipplugin.py", line 206, in exec_module
  File "calibre_plugins.deacsm.libadobe", line 59, in <module>
    # This is a list of versions that can be used for new authorizations:
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/keys.py", line 5, in <module>
    from ._asymmetric import parse_certificate, parse_private, parse_public
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_asymmetric.py", line 27, in <module>
    from .kdf import pbkdf1, pbkdf2, pkcs12_kdf
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/kdf.py", line 9, in <module>
    from .util import rand_bytes
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/util.py", line 10, in <module>
    from ._mac.util import rand_bytes
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_mac/util.py", line 208, in <module>
    from .._openssl._libcrypto import libcrypto
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_openssl/_libcrypto.py", line 24, in <module>
    from ._libcrypto_ctypes import (
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_openssl/_libcrypto_ctypes.py", line 30, in <module>
    libcrypto = CDLL(libcrypto_path, use_errno=True)
  File "ctypes/__init__.py", line 374, in __init__
OSError: dlopen(/usr/local/lib/libcrypto.dylib, 0x0006): tried: '/usr/local/lib/libcrypto.dylib' (code signature in <0717C03A-6252-3ADC-96B9-47B651E22388> '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.), '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' (code signature in <0717C03A-6252-3ADC-96B9-47B651E22388> '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "calibre/customize/ui.py", line 710, in initialize_plugin
  File "calibre_plugins.deacsm.__init__", line 187, in initialize
    # Also extract EXE files needed for WINE ADE key extraction
  File "/Users/heti/Downloads/DeACSM_0.0.16_bak/DeAscm_0016.zip/libadobe.py", line 59, in <module>
    from oscrypto import keys
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/keys.py", line 5, in <module>
    from ._asymmetric import parse_certificate, parse_private, parse_public
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_asymmetric.py", line 27, in <module>
    from .kdf import pbkdf1, pbkdf2, pkcs12_kdf
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/kdf.py", line 9, in <module>
    from .util import rand_bytes
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/util.py", line 10, in <module>
    from ._mac.util import rand_bytes
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_mac/util.py", line 208, in <module>
    from .._openssl._libcrypto import libcrypto
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_openssl/_libcrypto.py", line 24, in <module>
    from ._libcrypto_ctypes import (
  File "/Users/heti/Library/Preferences/calibre/plugins/DeACSM/modules/oscrypto/oscrypto/_openssl/_libcrypto_ctypes.py", line 30, in <module>
    libcrypto = CDLL(libcrypto_path, use_errno=True)
  File "ctypes/__init__.py", line 374, in __init__
OSError: dlopen(/usr/local/lib/libcrypto.dylib, 0x0006): tried: '/usr/local/lib/libcrypto.dylib' (code signature in <0717C03A-6252-3ADC-96B9-47B651E22388> '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.), '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' (code signature in <0717C03A-6252-3ADC-96B9-47B651E22388> '/usr/local/Cellar/openssl@3/3.5.0/lib/libcrypto.3.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.)

@mettavi

mettavi commented Jul 6, 2025

Copy link
Copy Markdown

Unfortunatelly the fix does not work for me.

I also got the same error at first, but a couple of things helped me.

Although it did not show up in the plugins list in the calibre settings, I found the old module in the ~/Library/Preferences/calibre/plugins directory. First I deleted all the old ACSM related files there. Then I quit and relaunched calibre. After that, installing the new version worked for me.

@roeme

roeme commented Oct 1, 2025

Copy link
Copy Markdown

I can confirm that this pull request works, on a x86 Mac running Sequoia 15.6.1.

But as mentioned by others, the plugins folder must be properly cleaned, otherwise the old code and the new incoming plugin will step on each others toes.

The old plugin cannot be cleanly removed through calibre's GUI; some GUI plugin stays, and can neither be removed nor disabled since its specially marked (In gaming terms, one could view this as a "softlock"...).

Having the old plugin code still present results in all kinds of weird errors, such as the mentioned libcrypto-thingie.

@Leseratte10

Copy link
Copy Markdown
Owner

Thanks for confirming that this MR works, I guess then there's nothing that blocks it from getting merged anymore.

The weird issue with plugin updates is unrelated to this MR. It always happens when updating from 0.0.16 to 0.1.0, I have not yet found a clean solution for that, and this is the main reason why version 0.1.0 still isn't released yet and has been stuck in beta for over a year. I will have to take another look at that eventually, but that's unrelated to the MacOS changes.

@roeme

roeme commented Dec 29, 2025

Copy link
Copy Markdown

Perhaps a small error message (with a link to a manual update instruction guide) when a previous install is detected might suffice. Might generate less work than trying to account for, and handle every corner case.

@bookchiq

bookchiq commented Apr 3, 2026

Copy link
Copy Markdown

I followed @mettavi's process (download zip at commit d145292, run bundle_calibre_plugin.sh, install in Calibre) on macOS 26.3.1 (Apple Silicon) with Calibre 9.6, no previous version of this plugin, and hit a build script issue worth noting.

Here's a summary compiled by Claude based on what I had to fix to get it installed:

The problem: bundle_calibre_plugin.sh uses shopt -s globstar and **/*.py.tmp glob patterns, which require bash 4.0+. macOS ships bash 3.2 (due to GPLv3 licensing), so the "Injecting Python2 compat code" step silently fails — the glob doesn't expand, the sed/mv operations no-op, and the resulting zip contains unpatched .py files.

On modern Calibre (9.x, Python 3.14), this means the plugin's bare from libadobe import ... statements aren't rewritten to relative imports (from .libadobe import ...), causing a ModuleNotFoundError: No module named 'libadobe' at plugin initialization.

The fix: Run the build script with bash 4+ instead of the system bash. If you have Homebrew:

brew install bash  # if not already installed
/opt/homebrew/bin/bash bundle_calibre_plugin.sh   # Apple Silicon
# or /usr/local/bin/bash bundle_calibre_plugin.sh  # Intel Mac

After rebuilding with a modern bash, the plugin installed and loaded cleanly on Calibre 9.6.0.

Suggestion for the script itself: It might be worth either adding a bash version check at the top of the script (with a clear error message), or replacing the globstar/** patterns with find-based equivalents so the script works with macOS's default bash.

@fkick

fkick commented Jun 15, 2026

Copy link
Copy Markdown

Hi All,

I've been unable to get this to install on Calibre 9.8.0 on macOS 26.5.1. It was a fresh install attempt and confirmed no references to ACSMInput and DeACSM in ~/Library/Preferences/calibre/plugins

Used Homebrew Bash to run bundle_calibre_plugin and build the calibre-plugin.zip and get the "No module named 'oscrypto'" error on install to calibre. Exception log below

calibre, version 9.8.0
ERROR: Unhandled exception: <b>InvalidPlugin</b>:Initialization of plugin Traceback (most recent call last):
  File "calibre/customize/ui.py", line 778, in initialize_plugin
  File "calibre_plugins.deacsm.__init__", line 360, in initialize
    from libadobe import createDeviceKeyFile, update_account_path, sendHTTPRequest
  File "/Users/USERNAME/Downloads/acsm-calibre-plugin-d1452926e458fec8af4d8c801c18e66d9b76666e/calibre-plugin.zip/libadobe.py", line 70, in &lt;module&gt;
    from oscrypto import keys
ModuleNotFoundError: No module named 'oscrypto'
 failed with traceback:
Traceback (most recent call last):
  File "calibre/customize/ui.py", line 778, in initialize_plugin
  File "calibre_plugins.deacsm.__init__", line 360, in initialize
    from libadobe import createDeviceKeyFile, update_account_path, sendHTTPRequest
  File "/Users/USERNAME/Downloads/acsm-calibre-plugin-d1452926e458fec8af4d8c801c18e66d9b76666e/calibre-plugin.zip/libadobe.py", line 70, in &lt;module&gt;
    from oscrypto import keys
ModuleNotFoundError: No module named 'oscrypto'


calibre 9.8  embedded-python: True
macOS-26.5.1-arm64-arm-64bit-Mach-O Darwin ('64bit', 'Mach-O')
('Darwin', '25.5.0', 'Darwin Kernel Version 25.5.0: Mon Apr 27 20:41:12 PDT 2026; root:xnu-12377.121.6~2/RELEASE_ARM64_T6050')
Python 3.14.4
OSX: ('26.5.1', ('', '', ''), 'arm64')
Interface language: None
EXE path: /Applications/calibre.app/Contents/MacOS/calibre
Successfully initialized third party plugins: Gather KFX-ZIP (from KFX Input) (2, 32, 0) && DeDRM (10, 0, 9) && Package KFX (from KFX Input) (2, 32, 0) && Count Pages (1, 15, 2) && Embed Comic Metadata (1, 6, 7) && Goodreads (1, 8, 5) && KFX metadata reader (from KFX Input) (2, 32, 0) && From KFX (2, 32, 0) && KFX Input (2, 32, 0) && Kindle hi-res covers (0, 5, 1) && KindleUnpack - The Plugin (0, 83, 8) && Obok DeDRM (10, 0, 3) && ACSM Input Plugin GUI Extension (0, 1, 0)
Traceback (most recent call last):
  File "calibre/customize/ui.py", line 778, in initialize_plugin
  File "calibre_plugins.deacsm.__init__", line 360, in initialize
    from libadobe import createDeviceKeyFile, update_account_path, sendHTTPRequest
  File "/Users/USERNAME/Downloads/acsm-calibre-plugin-d1452926e458fec8af4d8c801c18e66d9b76666e/calibre-plugin.zip/libadobe.py", line 70, in <module>
    from oscrypto import keys
ModuleNotFoundError: No module named 'oscrypto'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "calibre/gui2/preferences/plugins.py", line 331, in add_plugin
  File "calibre/customize/ui.py", line 581, in add_plugin
  File "calibre/customize/ui.py", line 783, in initialize_plugin
calibre.customize.InvalidPlugin: Initialization of plugin Traceback (most recent call last):
  File "calibre/customize/ui.py", line 778, in initialize_plugin
  File "calibre_plugins.deacsm.__init__", line 360, in initialize
    from libadobe import createDeviceKeyFile, update_account_path, sendHTTPRequest
  File "/Users/USERNAME/Downloads/acsm-calibre-plugin-d1452926e458fec8af4d8c801c18e66d9b76666e/calibre-plugin.zip/libadobe.py", line 70, in <module>
    from oscrypto import keys
ModuleNotFoundError: No module named 'oscrypto'
 failed with traceback:
Traceback (most recent call last):
  File "calibre/customize/ui.py", line 778, in initialize_plugin
  File "calibre_plugins.deacsm.__init__", line 360, in initialize
    from libadobe import createDeviceKeyFile, update_account_path, sendHTTPRequest
  File "/Users/USERNAME/Downloads/acsm-calibre-plugin-d1452926e458fec8af4d8c801c18e66d9b76666e/calibre-plugin.zip/libadobe.py", line 70, in <module>
    from oscrypto import keys
ModuleNotFoundError: No module named 'oscrypto'


Any thoughts?

Thanks

@Leseratte10
Leseratte10 force-pushed the master branch 2 times, most recently from 1e94d92 to 64df5ab Compare June 27, 2026 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to install Plugin on Mac

7 participants