Re: Is there a way to tell s_client to just "send a command" and quit?

Jochen Bern <[email protected]> Fri, 26 Sep 2025 09:36:24 +0200
Newsgroups gmane.comp.encryption.openssl.user
Organization Binect GmbH
Message-ID <[email protected]>
On 25.09.25 23:25, Dan Mahoney wrote:
> I'm writing some certificate checks that call s_client to fetch my
> cert, but openssl s_client is blocking.  Is there an easy way to
> tell it "hang up as soon as negotiation settles?"
> 
> Perhaps with a "clean" command like "QUIT" or something (depending
> on the protocol being used).
> 
> This complicates scripting it with a simple shell script or something
> like that, and would be super useful.

Since you're specifically asking for a "clean" exit, I shall assume that 
you need to avoid the server seeing a "dirty" connection/request, as in, 
writing a warning thereto to the logs. (Otherwise, see the previous 
replies about making /dev/null the stdin.)

Needless to say, such a method depends on the protocol for the service 
you're connecting to, so support by s_client will necessarily be 
limited. "Natively", you (only) need to make sure that there's enough 
time for the server to process the request before s_client sees the EOF 
and closes the connection.

For example, most *HTTPS* servers I need to "ping" like that are OK with 
HTTP 1.0 and Unix EOLs, so I'm essentially doing

(echo "HEAD / HTTP/1.0";echo "";sleep 5)|openssl s_client -connect ...

A truly picky one with name-based virtual hosts, on the other hand, 
needs something like

( echo -e 'GET / HTTP/1.1\r' ; echo -e 'Host: foo.bar\r' ; echo -e 
'Connection: close\r' ; echo -e '\r' ; sleep 5 ) | openssl s_client 
-connect foo.bar:443 -servername foo.bar ...

(Again, assuming that the client's "echo" command is appending the 
unixoid \n EOL on its own, and that 5s are enough time for the server to 
reply.)

Kind regards,
-- 
Jochen Bern
Systemingenieur

Binect GmbH

-- 
You received this message because you are subscribed to the Google Groups "openssl-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openssl-users+unsubscribe-MCmKBN63+Bmbup2nOX2J7Q@public.gmane.org
To view this discussion visit https://groups.google.com/a/openssl.org/d/msgid/openssl-users/5e2c33e9-1918-456f-9f1b-80deb1f10436%40binect.de.
smime.p7s (application/pkcs7-signature, 4.2 KB) - not displayed