在Mac OS X上生成Openssl密钥失败

18

我正在尝试在一个新的干净的Mac上为一个Spring项目运行我们的单元测试。其中一个测试需要生成ssl密钥。

我已经通过Homebrew安装了openssl,但错误仍然存在。

请参见下面的错误:

Using configuration from /Users/myuser/workspace/project/webapp/target/test-data/clientvpn/acc1/openssl.conf
default is an unsupported message digest type
13499:error:02001002:system library:fopen:No such file or directory:/BuildRoot/Library/Caches/com.apple.xbs/Sources/OpenSSL098/OpenSSL098-59/src/crypto/bio/bss_file.c:126:fopen('./index.txt.attr','rb')
13499:error:2006D080:BIO routines:BIO_new_file:no such file:/BuildRoot/Library/Caches/com.apple.xbs/Sources/OpenSSL098/OpenSSL098-59/src/crypto/bio/bss_file.c:129:
13499:error:0E078072:configuration file routines:DEF_LOAD:no such file:/BuildRoot/Library/Caches/com.apple.xbs/Sources/OpenSSL098/OpenSSL098-59/src/crypto/conf/conf_def.c:197:

3
输入 which openssl 并回报结果。 - jww
2
感谢回复。which openssl 打印出 /usr/bin/openssl,这是非 Homebrew 版本的 OpenSSL。强制让 brew 链接新的 OpenSSL 解决了问题。请参见下面的答案,其中包含稍微详细的描述。 - robinjohnobrien
4个回答

21

通过多次谷歌搜索并与最近也转向 Mac 的同事咨询,我已解决了这个问题。

当 Homebrew 安装新的 OpenSSL 时,符号链接未被创建。如果你运行 brew link openssl,你将看到以下消息:Warning: openssl is keg-only and must be linked with --force

这就是解决方案。需要明确告诉 Homebrew 创建正确的链接。

brew link --force openssl

如果你现在检查which openssl,你会发现它指向brew安装的版本/usr/local/bin/openssl


13
不幸的是,即使使用 --force,这似乎也不再起作用了。我得到了这个警告:Warning: Refusing to link macOS-provided software: openssl。它建议先将其添加到 PATH 中。 - Matthew Read
1
运行brew link命令给出的add to path命令并重新启动终端对我有用:echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc - Steven P
1
我收到了这个警告:警告:拒绝链接 macOS 提供/遮蔽的软件:openssl@1.1 - IgorGanapolsky
无法在macOS Mojave 10.14.6上工作。与上述相同的警告:“警告:拒绝链接macOS提供/遮蔽的软件:openssl@1.1”。 - Ruben Murray

8

这个对我在 Monterey(12.2)上起了作用。

brew install openssl
brew link openssl # outputs :

Warning: Refusing to link macOS provided/shadowed software: openssl@3
If you need to have openssl@3 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/openssl@3/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@3 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@3/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@3/include"

For pkg-config to find openssl@3 you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openssl@3/lib/pkgconfig"

我只是使用了该命令,所以我:

echo 'export PATH="/usr/local/opt/openssl@3/bin:$PATH"' >> ~/.zshrc

那个有效,旧输出:
➜  ca git:(master) openssl version
LibreSSL 2.8.3

之后:

➜  ca git:(master) source ~/.zshrc
➜  ca git:(master) openssl version
OpenSSL 3.0.1 14 Dec 2021 (Library: OpenSSL 3.0.1 14 Dec 2021)

注意:根据您的需求可能需要其他选项。 注意2:我的默认shell是zsh,如果您使用bash,请将其添加到您的bashrc中,或者添加到您选择的shell和其PATH中。


1
也适用于 Monterey 12.4,谢谢。 - Mücahit Yılmaz

-1

通过允许我的操作系统访问该文件来解决了问题。 例如,macOS 允许终端访问此文件。


-1

openssl:错误:'-CAcreateserial' 是无效命令。 - IgorGanapolsky

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接