TyrantLucifer / ssr-command-client

:airplane:The commend client of ssr based Python3
Apache License 2.0
978 stars 240 forks source link

load liblibcrypto.a error #52

Open fengidri opened 2 years ago

fengidri commented 2 years ago

Linux version 5.10.63-v7+ (dom@buildbot) (arm-linux-gnueabihf-gcc-8 (Ubuntu/Linaro 8.4.0-3ubuntu1) 8.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #1459 SMP Wed Oct 6 16:41:10 BST 2021

raspberrypi. 2W

bug: tcprelay.py[line:1096] - [_log_error] - ERROR: [Errno 2] No such file or directory: b'liblibcrypto.a' when handling connection from 127.0.0.1:43384
TyrantLucifer commented 2 years ago

chacha20-ietf加密方式需要自己在本机安装加密库才能使用 linux详见https://0b2bd010.wiz06.com/wapp/pages/view/share/s/0baZ0g2Y0h7E2nCs-V3z8FhA0uorhp19pAP92-63v23qMflo windows版本需要下载libsodium dll文件,详见https://download.libsodium.org/libsodium/releases/ 然后将文件放置到C:/windows/system32中

fengidri commented 2 years ago

libsodium 已经加载了, 并不是这个问题。

TyrantLucifer commented 2 years ago

找到对应的libcrypto.a文件,加一个软连接liblibcrypto.a

fengidri commented 2 years ago

找到对应的libcrypto.a文件,加一个软连接liblibcrypto.a

我已经解决了, 我只是报告这是一个 bug 吗? 正常有 liblibcrypto.a 吗?

TyrantLucifer commented 2 years ago

ssr-command-client不会自带这种本地加密库过来,需要用户自行根据ssr的加密方式去安装到本机

fengidri commented 2 years ago

我的意思是, 真的有一个库的名字叫这个吗?liblibcrypto.a

libcrypto.a 我理解, 但是 liblibcrypto.a 是真有这个库吗? 不是代码的问题吗?

TyrantLucifer commented 2 years ago

加载库的代码在shadowsocksr的源码中,具体里面怎么加载的这加密库我也没研究过,我是做大数据开发的,不是搞网络的,也没仔细研究过这个shadowsocksr中间的加密过程,所以没办法给你一个明确的回复,感兴趣的话可以自行阅读一下哈,这个issue我就不关了,等研究过的大佬给个明确的回复

TJhaitang commented 2 years ago

我也遇到了这个问题,我注意到问题出现在shadowsocksr源码中的util.py文件中第68行,这里作者同时搜索了<library名>与"lib"+<library名>两个文件,然而ctypes.util.find_library方法对不存在的library抛出错误,为这里套上try-except后程序运行正常。 然而我查看了python3.10的文档,对于该方法其中提到当没有找到对应动态链接库时将返回None,似乎不应该抛出错误。但程序已经正常运行了我就没有继续找资料,看有没有其他感兴趣的大佬给出明确解答吧

npbcts commented 1 year ago

升级22.04后,默认python版本为3.10,会产生找不到liblibcrypto.a加密库的错误,三种解决方法:

  1. 将 /user/lib/x86_64-linux-gnu/libcrypto.a 软链接到/user/lib/liblibcrypto.a ->没测试能否成功

  2. crypto/util.py源码修改 -> 使用此方法成功 /shadowsocks/shadowsocks/crpyto/util.py, 56-62查找lib+,liblib+文件块放入try…except中

  3. python版本降为3.8,/usr/bin/python指向python3.8 -> 使用此方法成功

snailcoder commented 1 year ago

我也遇到了这个问题,我注意到问题出现在shadowsocksr源码中的util.py文件中第68行,这里作者同时搜索了<library名>与"lib"+<library名>两个文件,然而ctypes.util.find_library方法对不存在的library抛出错误,为这里套上try-except后程序运行正常。 然而我查看了python3.10的文档,对于该方法其中提到当没有找到对应动态链接库时将返回None,似乎不应该抛出错误。但程序已经正常运行了我就没有继续找资料,看有没有其他感兴趣的大佬给出明确解答吧

ctypes.util.find_library不能查找前缀为lib的库,参考这里:https://docs.python.org/release/3.10.6/library/ctypes.html#ctypes.util.find_library .如果用find_library查找"libcrypto",会抛出异常,可用以下代码测试: from ctypes.util import find_library
print(find_library("crypto")) # 输出'libcrypto.so.3' print(find_library("liblibcrypto")) # 输出None print(find_library("libcrypto")) # 抛出异常  

异常如下: Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.10/ctypes/util.py", line 341, in find_library _get_soname(_findLib_gcc(name)) or _get_soname(_findLib_ld(name)) File "/usr/lib/python3.10/ctypes/util.py", line 147, in _findLib_gcc if not _is_elf(file): File "/usr/lib/python3.10/ctypes/util.py", line 99, in _is_elf with open(filename, 'br') as thefile: FileNotFoundError: [Errno 2] No such file or directory: b'liblibcrypto.a

原因:根据find_library的调用栈,找到_findLib_gcc函数,该函数会通过subprocess调用gcc,并在gcc命令后面加上参数"-l",然后用正则去匹配gcc的输出.对比如下两个命令的输出: gcc -Wl,-t -o tmp.o -llibcrypto 以及 gcc -Wl,-t -o tmp.o -lliblibcrypto

前者输出如下: /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x8664-linux-gnu/11/crtbeginS.o /usr/bin/ld: cannot find -llibcrypto: No such file or directory **/usr/bin/ld: note to link with /usr/lib/gcc/x86_64-linux-gnu/11/../../../x8664-linux-gnu/libcrypto.a use -l:libcrypto.a or rename it to liblibcrypto.a** /usr/lib/gcc/x86_64-linux-gnu/11/libgcc.a /usr/lib/gcc/x86_64-linux-gnu/11/libgcc_s.so /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libgcc_s.so.1 /usr/lib/gcc/x86_64-linux-gnu/11/libgcc.a collect2: error: ld returned 1 exit status

后者输出如下: /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/Scrt1.o /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/11/crtbeginS.o /usr/bin/ld: cannot find -lliblibcrypto: No such file or directory /usr/lib/gcc/x86_64-linux-gnu/11/libgcc.a /usr/lib/gcc/x86_64-linux-gnu/11/libgcc_s.so /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libgcc_s.so.1 /usr/lib/gcc/x86_64-linux-gnu/11/libgcc.a collect2: error: ld returned 1 exit status

_findLib_gcc函数会用正则表达式,在gcc的输出中查找文件名,如果找到,则调用函数_is_elf打开匹配到的文件名.于是,对于前者的输出,正则查找liblibcrypto,在/usr/bin/ld: note to link with /usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/libcrypto.a use -l:libcrypto.a or rename it to liblibcrypto.a这句话中找到,并尝试打开文件liblibcrypto.a,该文件并不存在,所以报错;对于后者的输出,正则查找libliblibcrypto,在输出中未匹配到,不会调用_is_elf,并直接返回None,所以不会报错.

liudongyang1 commented 1 year ago

升级22.04后,默认python版本为3.10,会产生找不到liblibcrypto.a加密库的错误,三种解决方法:

  1. 将 /user/lib/x86_64-linux-gnu/libcrypto.a 软链接到/user/lib/liblibcrypto.a ->没测试能否成功
  2. crypto/util.py源码修改 -> 使用此方法成功 /shadowsocks/shadowsocks/crpyto/util.py, 56-62查找lib+,liblib+文件块放入try…except中
  3. python版本降为3.8,/usr/bin/python指向python3.8 -> 使用此方法成功

方法 1,再追加一次 sudo ln -s /usr/lib/x86_64-linux-gnu/libcrypto.a /usr/lib/liblibcrypto.a 也可以成功