shadowsocks / shadowsocks-libev

Bug-fix-only libev port of shadowsocks. Future development moved to shadowsocks-rust
https://github.com/shadowsocks/shadowsocks-rust
GNU General Public License v3.0
15.83k stars 5.69k forks source link

configure --enable-static --with-openssl= arguments are not respected #821

Closed superkuh closed 8 years ago

superkuh commented 8 years ago

What version of shadowsocks-libev are you using?

shadowsocks-libev 2.5.1

What operating system are you using?

Ubuntu 10.04 and Ubuntu 14.04

What I'm trying to do and how it's failing.

I'm trying to use shadowsocks-libev on my Ubuntu 10.04 machine with openssl 0.9.8 but instead of linking to system openssl I'd like to link to a compiled version of openssl 1.0.2g which I built with shared enabled.

cd /home/superkuh/app_installs/openssl/
make clean
./config shared
make depend
make test
make

I've used this copy of openssl for static linking with Tor before so I know it works. I copied this folder openssl/ (containing openssl1.0.2g) to my shadowsocks-libev directory to use for compilation and set up the configure like so,

cd /home/superkuh/app_installs/shadowsocks-libev/
./configure --enable-static --with-openssl=/home/superkuh/app_installs/shadowsocks-libev/openssl
make

But after I compiled it this way with static linked openssl libs of a newer vintage it still would not work. It runs, it binds to the port locally, but it doesn't act as a socks5 proxy connecting to the remote ss-server,

 ./ss-local -c test.conf 
2016-09-10 09:34:49 INFO: onetime authentication enabled
2016-09-10 09:34:49 INFO: initializing ciphers... aes-256-cfb
2016-09-10 09:34:49 INFO: listening at 127.0.0.1:3141

test.conf

    {
        "server":"remote.server.ip.here",
        "server_port":3141,
        "local_port":3141,
        "password":"password",
        "timeout":600,
        "method":"aes-256-cfb",
        "auth": true,
        "verbose":2
    }

With this exact same configuration file using ss-local compiled on Ubuntu 14.04 using /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 it works fine. It should work with static linked openssl 1.0.2g on Ubuntu 10.04 but the configure options don't seem to have an effect. It still links to the system 0.9.8,

$ lsof -p 14347
COMMAND    PID     USER   FD   TYPE  DEVICE SIZE/OFF     NODE NAME
ss-local 14347 superkuh  cwd    DIR     8,1     4096 17662203 /home/superkuh/app_installs/shadowsocks-libev/src
ss-local 14347 superkuh  rtd    DIR    8,17     4096        2 /
ss-local 14347 superkuh  txt    REG     8,1  1017976 17600785 /home/superkuh/app_installs/shadowsocks-libev/src/ss-local
ss-local 14347 superkuh  mem    REG    8,17  1596808  2124928 /lib/libc-2.11.1.so
ss-local 14347 superkuh  mem    REG    8,17   135745  2124922 /lib/libpthread-2.11.1.so
ss-local 14347 superkuh  mem    REG    8,17    14696  2124926 /lib/libdl-2.11.1.so
ss-local 14347 superkuh  mem    REG    8,17    92752  2097346 /lib/libz.so.1.2.3.3
ss-local 14347 superkuh  mem    REG    8,17   186440  2097289 /lib/libpcre.so.3.12.1
ss-local 14347 superkuh  mem    REG    8,17   534832  2124911 /lib/libm-2.11.1.so
ss-local 14347 superkuh  mem    REG    8,17  1626432  2120663 /lib/libcrypto.so.0.9.8
ss-local 14347 superkuh  mem    REG    8,17   136936  2124919 /lib/ld-2.11.1.so
ss-local 14347 superkuh    0u   CHR  136,16      0t0       19 /dev/pts/16
ss-local 14347 superkuh    1u   CHR  136,16      0t0       19 /dev/pts/16
ss-local 14347 superkuh    2u   CHR  136,16      0t0       19 /dev/pts/16
ss-local 14347 superkuh    3u  0000     0,9        0     5165 anon_inode
ss-local 14347 superkuh    4u  0000     0,9        0     5165 anon_inode
ss-local 14347 superkuh    5u  IPv4 3993154      0t0      TCP localhost:3141 (LISTEN)

libcrypto.so.0.9.8! So my question is, how to I configure and compile shadowsocks-libev to use static provided openssl libs. Or even better, how can I get shadowsocks to be more verbose about it's errors or actually log to disk somewhere?

skyroveRR on freenode ##networking suggested manually editing the Makefile to force static libs and paths,

CC="gcc -static -I/(your_new_openssl_headers) -L(your_new_openssl_lib)" LDFLAGS=-static

So I edited my autogenerated makefile like so,

Makefile

...
#CC = gcc
CC = "gcc -static -I/home/superkuh/app_installs/shadowsocks-libev/openssl/include -L/home/superkuh/app_installs/shadowsocks-libev/openssl"
...
#LDFLAGS =  -L/home/superkuh/app_installs/shadowsocks-libev/openssl/lib
#LDFLAGS =  -L/home/superkuh/app_installs/shadowsocks-libev/openssl
LDFLAGS =  -L/home/superkuh/app_installs/shadowsocks-libev/openssl -static
...

But even doing this lsof still reports ss-local is using /lib/libcrypto.so.0.9.8 and it still doesn't actually work.

I am a bit confused a the LDFLAGS path that --with-openssl=/home/superkuh/app_installs/shadowsocks-libev/openssl generated,

    LDFLAGS =  -L/home/superkuh/app_installs/shadowsocks-libev/openssl/lib

My openssl path/directory doesn't actually have a openssl/lib, it just has the library .so files in the main dir like,

$ ls /home/superkuh/app_installs/shadowsocks-libev/openssl
ACKNOWLEDGMENTS  CONTRIBUTING  GitMake        INSTALL.W32         libssl.so        ms            README.ASN1
apps             crypto        include        INSTALL.W64         libssl.so.1.0.0  Netware       README.ENGINE
appveyor.yml     demos         INSTALL        INSTALL.WCE         LICENSE          NEWS          rehash.time
bugs             doc           install.com    libcrypto.a         MacOS            openssl.doxy  shlib
certs            engines       INSTALL.DJGPP  libcrypto.pc        Makefile         openssl.pc    ssl
CHANGES          e_os2.h       INSTALL.MacOS  libcrypto.so        Makefile.bak     openssl.spec  test
CHANGES.SSLeay   e_os.h        INSTALL.NW     libcrypto.so.1.0.0  Makefile.org     os2           tools
config           FAQ           INSTALL.OS2    libssl.a            Makefile.shared  PROBLEMS      util
Configure        GitConfigure  INSTALL.VMS    libssl.pc           makevms.com      README        VMS

So I figure the correct LDFLAGS -L path is the above stated but with -static to force static linking,

    LDFLAGS =  -L/home/superkuh/app_installs/shadowsocks-libev/openssl -static

But even when I compile it like this is still only links dynamically to the system openssl 0.9.8

What is the proper what to configure shadowsocks-libev to compile and link with static openssl? How do I get ./configure to actually implement the openssl selection and static linking?

madeye commented 8 years ago
  1. --enable-static means to build static library of libshadowsocks, not link statically with other libraries.
  2. Although it's not recommended to link statically against OpenSSL (potential license issue), you can try the following steps:
    • Copy your libcrypto.a to a folder, e.g. /path/to/openssl-static/lib
    • Copy all the headers to the above folder, e.g. /path/to/openssl-static/include
    • Run the configure like this: ./configure --with-openssl=/path/to/openssl-static

BTW, here is an example of openssl-static:

├── include
│   └── openssl
│       ├── aes.h
│       ├── asn1.h
│       ├── asn1_mac.h
│       ├── asn1t.h
│       ├── bio.h
│       ├── blowfish.h
│       ├── bn.h
│       ├── buffer.h
│       ├── camellia.h
│       ├── cast.h
│       ├── cmac.h
│       ├── cms.h
│       ├── comp.h
│       ├── conf.h
│       ├── conf_api.h
│       ├── crypto.h
│       ├── des.h
│       ├── des_old.h
│       ├── dh.h
│       ├── dsa.h
│       ├── dso.h
│       ├── dtls1.h
│       ├── e_os2.h
│       ├── ebcdic.h
│       ├── ec.h
│       ├── ecdh.h
│       ├── ecdsa.h
│       ├── engine.h
│       ├── err.h
│       ├── evp.h
│       ├── hmac.h
│       ├── idea.h
│       ├── krb5_asn.h
│       ├── kssl.h
│       ├── lhash.h
│       ├── md4.h
│       ├── md5.h
│       ├── mdc2.h
│       ├── modes.h
│       ├── obj_mac.h
│       ├── objects.h
│       ├── ocsp.h
│       ├── opensslconf.h
│       ├── opensslv.h
│       ├── ossl_typ.h
│       ├── pem.h
│       ├── pem2.h
│       ├── pkcs12.h
│       ├── pkcs7.h
│       ├── pqueue.h
│       ├── rand.h
│       ├── rc2.h
│       ├── rc4.h
│       ├── ripemd.h
│       ├── rsa.h
│       ├── safestack.h
│       ├── seed.h
│       ├── sha.h
│       ├── srp.h
│       ├── srtp.h
│       ├── ssl.h
│       ├── ssl2.h
│       ├── ssl23.h
│       ├── ssl3.h
│       ├── stack.h
│       ├── symhacks.h
│       ├── tls1.h
│       ├── ts.h
│       ├── txt_db.h
│       ├── ui.h
│       ├── ui_compat.h
│       ├── whrlpool.h
│       ├── x509.h
│       ├── x509_vfy.h
│       └── x509v3.h
└── lib
    └── libcrypto.a
wongsyrone commented 8 years ago

You can also try ./configure <blahblah> LIBS="<full-path-to-dot-a-file>"

phoenixxie0 commented 8 years ago

You may use the openssl static library please try ./config no-share

superkuh commented 8 years ago

Thanks for the quick responses, madeye in particular. My problem was that I had libcrypto.a in ./openssl instead of in ./openssl/lib . When I created a ./openssl/lib folded and copied it there everything compiled and shadowsocks linked statically with openssl 1.0.2g.

This didn't fix the problem and socks5 proxying still won't work but at least I know it's not an openssl problem. Issue closed.