How to modify code for s_client?

2020-04-21 00:01发布

问题:

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 after I save the file and do a make all, or a make.

For example, I changed the sc_usage function to this:

BIO_printf(bio_err,"This is how you use s_client\n");
BIO_printf(bio_err,"usage: s_client args\n");
BIO_printf(bio_err,"\n");
BIO_printf(bio_err," -host host     - use -connect instead\n");
BIO_printf(bio_err," -port port     - use -connect instead\n");

I then save and do a make all in the apps folder, but when I run the program by doing this: openssl s_client abc, I don't see the line I introduced, this is how you use s_client, in the output.

Where am I going wrong?

回答1:

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.



回答2:

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 ....