How to modify code for s_client?

后端 未结 2 1332
小蘑菇
小蘑菇 2021-01-23 19:38

I\'m playing around with apps/s_client.c in the openssl source code. I want to make a few changes and run it, but my changes are not getting reflected

相关标签:
2条回答
  • 2021-01-23 20:07

    Are you sure you run the correct app? Try ./openssl.

    In Linux, current directory is not searched for executable files by default, so you are probably running system's openssl.

    0 讨论(0)
  • 2021-01-23 20:13

    I want to make a few changes and run it, but my changes are not getting reflected after I save the file and do a make all, or a make.

    Its even easier than that once you know the tricks.

    1. Configure the OpenSSL library as normal (configure)
    2. Build the OpenSSL library as normal (make depend && make)
    3. Install the OpenSSL library as normal (sudo make install)
    4. Make your changes to s_client.c
    5. Compile s_client.c in place (the apps/ directory):

    Here's the grease. You have to build some additional object files, like apps.o and apps_rand.o, to support s_client.o.

    export OPENSSLDIR=/usr/local/ssl/darwin    
    gcc -DOPENSSL_NO_PSK -DMONOLITH -I$OPENSSLDIR/include -I../ -c apps.c    
    gcc -DOPENSSL_NO_PSK -DMONOLITH -I$OPENSSLDIR/include -I../ -c app_rand.c    
    gcc -DOPENSSL_NO_PSK -DMONOLITH -I$OPENSSLDIR/include -I../ -c s_cb.c
    gcc -DOPENSSL_NO_PSK -DMONOLITH -I$OPENSSLDIR/include -I../ -c s_socket.c
    
    gcc -DOPENSSL_NO_PSK -I$OPENSSLDIR/include -I../ \
      app_rand.o apps.o s_cb.o s_socket.o \
      $OPENSSLDIR/lib/libssl.a $OPENSSLDIR/lib/libcrypto.a \
      s_client.c -o my_s_client.exe
    

    The OPENSSL_NO_PSK is needed because a declaration (psk_key) was commented out. The -I../ is needed because e_os.h is not installed after a make install. It sure would be nice if OpenSSL actually tested their stuff before releasing it...

    Then:

    $ ./my_s_client.exe -connect www.google.com:443
    CONNECTED(00000003)
    depth=2 C = US, O = GeoTrust Inc., CN = GeoTrust Global CA
    verify error:num=20:unable to get local issuer certificate
    verify return:0
    ---
    Certificate chain
     0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=www.google.com
       i:/C=US/O=Google Inc/CN=Google Internet Authority G2
     ...
    

    No need to rebuild the whole library or all the apps. No need for openssl s_client ....

    0 讨论(0)
提交回复
热议问题