SkillPilotAI

openssl (s_client, s_server, x509, req, verify, ciphers, ocsp, s_time, genpkey, pkcs12) (3/5)

openssl s_server is a small TLS server that lets you test clients and TLS settings (versions, ciphers, sessions, SNI, ALPN, OCSP, PSK) without nginx, and openssl ciphers tells you exactly which suites a cipher string expands to.

172.1 Why is it used?

  • Build a replica TLS server with the planned settings and try every client combination before touching production.
  • See the handshake step by step (-state, -msg, -trace) to debug alerts.
  • Check what a cipher string really means before putting it in nginx/Apache config.
  • Install: Linux openssl package; macOS has LibreSSL, so brew install openssl@3; Windows via Git for Windows or winget ShiningLight.OpenSSL.Light.
One TLS handshake in the lab
  1. 1.n172-client 192.168.192.20 sends ClientHello: SNI shop.lab, ALPN http/1.1, TLS 1.3 + 1.2 ciphers

  2. 2.n172-srv 192.168.192.10:4491 picks the cert by SNI (CN=shop.lab)

  3. 3.ServerHello: TLSv1.3, TLS_AES_256_GCM_SHA384

  4. 4.Certificate + stapled OCSP: Cert Status good

  5. 5.Client verifies the cert: Verification: OK

172.2 Web server and echo modes

ModeBehaviour
-wwwHTML status page: command line, ciphers, session
-WWWServes files from the folder, builds headers itself
-HTTPSends files as-is (headers live inside the file)
-revEcho server: sends text back reversed
-sendfilekTLS sendfile for -WWW/-HTTP (not run in lab)
Terminal
# n172-srv (o = openssl s_server + cert, key)o -accept 4434 -WWWo -accept 4435 -HTTPo -accept 4436 -rev# n172-clientcurl -si --cacert ca.crt https://shop.lab:4435/raw.txt(echo "hello lab"; sleep 1) | openssl \  s_client -brief -CAfile ca.crt \  -connect shop.lab:4436
Output
HTTP/1.0 200 OKContent-Type: text/plainX-Lab: N172 raw file from -HTTPCONNECTION ESTABLISHEDProtocol version: TLSv1.3Ciphersuite: TLS_AES_256_GCM_SHA384Verification: OKbal ollehDONE

172.3 Output and debugging

OptionLog lines in labShows
-quiet1Only the data (lab ping 4442)
-brief7Short summary: protocol, ciphersuite
-state46Every handshake state (read client hello, write server hello...)
-msg194Every message + hex dump
-trace312Full decoded trace, e.g. all ClientHello cipher suites by name
Output
$ wc -l < /tmp/state.log46SSL_accept:SSLv3/TLS read client helloSSL_accept:SSLv3/TLS write server helloSSL_accept:TLSv1.3 write encrypted extensionsSSL_accept:SSLv3/TLS write certificateSSL_accept:SSLv3/TLS write finishedSSL_accept:SSLv3/TLS read finishedSSL_accept:SSLv3/TLS write session ticketCIPHER is TLS_AES_256_GCM_SHA384
  • -keylogfile F writes TLS secrets that let Wireshark decrypt traffic: lab only.
  • Also: -debug (full hex), -tlsextdebug (extensions), -msgfile, -security_debug, -keymatexport.

172.4 Protocol versions and DTLS

Terminal
# n172-srvo -accept 4451 -tls1_3o -accept 4452 -no_tls1_3o -accept 4453 -dtls1_2    # UDP# n172-clients() { echo | openssl s_client -brief \  -CAfile ca.crt "$@" 2>&1 \  | grep -E '^Protocol|error'; }s -connect shop.lab:4451s -connect shop.lab:4451 -tls1_2s -connect shop.lab:4452s -connect shop.lab:4453 -dtls
Output
Protocol version: TLSv1.3...:error:0A00042E:SSL routines:ssl3_read_bytes:  tlsv1 alert protocol version:...:SSL alert number 70Protocol version: TLSv1.2Protocol version: DTLSv1.2
  • A version mismatch gives alert 70 (protocol version); the server logs unsupported protocol.
  • -dtls1_2 listens on UDP: netstat shows udp :::4453.
  • In production prefer -min_protocol / -max_protocol (a range); DTLS -listen does a HelloVerifyRequest cookie exchange, -mtu sets the link MTU.

172.5 Ciphers, groups and signature algorithms

Terminal
o -accept 4471 -tls1_2 \  -cipher ECDHE-ECDSA-AES128-GCM-SHA256o -accept 4472 \  -ciphersuites TLS_CHACHA20_POLY1305_SHA256o -accept 4473 -groups X25519o -accept 4474 -sigalgs ECDSA+SHA384
Server settingClientResult
4471 -cipher ...AES128-GCMdefaultTLSv1.2, ECDHE-ECDSA-AES128-GCM-SHA256
4471-cipher ...AES256-GCMalert 40; server: no shared cipher
4472 -ciphersuites CHACHA20defaultTLSv1.3 TLS_CHACHA20_POLY1305_SHA256
4473 -groups X25519-groups P-384alert 40; server: no suitable key share
4473-groups P-384:X25519TLSv1.3, Server Temp Key: X25519
4474 -sigalgs ECDSA+SHA384defaultFalls back to TLSv1.2 (P-256 key cannot sign SHA384 in TLS 1.3)
  • -cipher is for TLS 1.2 and below; -ciphersuites is for TLS 1.3 only.
  • -serverpref makes the server's cipher order win; -record_padding pads TLS 1.3 records.

172.6 Sessions, tickets, renegotiation

Terminal
# n172-srv (all -tls1_2)o -accept 4481o -accept 4482 -no_ticketo -accept 4483 -no_ticket -no_cache# n172-clientfor p in 4481 4482 4483; do  echo "## port $p"; rm -f s.pem  echo | openssl s_client -CAfile ca.crt -connect \    shop.lab:$p -sess_out s.pem 2>&1 | grep -E '^New|lifetime'  echo | openssl s_client -CAfile ca.crt -connect \    shop.lab:$p -sess_in s.pem 2>&1 | grep -E '^(New|Reus)|rror'done
Output
## port 4481New, TLSv1.2, Cipher is ECDHE-ECDSA-AES256-GCM-SHA384    TLS session ticket lifetime hint: 7200 (seconds)Reused, TLSv1.2, Cipher is ECDHE-ECDSA-AES256-GCM-SHA384## port 4482New, TLSv1.2, Cipher is ECDHE-ECDSA-AES256-GCM-SHA384Reused, TLSv1.2, Cipher is ECDHE-ECDSA-AES256-GCM-SHA384## port 4483New, TLSv1.2, Cipher is ECDHE-ECDSA-AES256-GCM-SHA384...:error:80000002:system library:BIO_new_file:  No such file or directory:...:calling fopen(s.pem, r)
  • -no_ticket alone still resumes via the session cache (Session ID): server log showed 1 session cache hits.
  • TLS 1.3: -num_tickets N (default 2), -early_data accepts 0-RTT, -anti_replay protects it.
  • -comp turns compression on: not recommended (CRIME attack).

172.7 SNI, ALPN and OCSP stapling

SNI: one IP, two certificates
  1. 1.ClientHello server_name: shop.lab -> server sends -cert CN=shop.lab

  2. 2.ClientHello server_name: api.lab -> server sends -cert2 CN=api.lab

  3. 3.ClientHello server_name: other.lab (unknown)

  4. 4.With -servername_fatal: alert 112 unrecognized name, connection closed

Terminal
o -accept 4491 -servername api.lab \  -cert2 api.lab.crt -key2 api.lab.key \  -alpn h2,http/1.1 -status_file ocsp.dero -accept 4492 -servername api.lab \  -servername_fatal -cert2 api.lab.crt \  -key2 api.lab.key# n172-client: s PORT SNI [options]s 4491 api.lab | grep ^subjects 4491 shop.lab -alpn http/1.1 -status \  | grep -E 'ALPN|Resp.*Status|Cert St|Next's 4492 other.lab | grep alert
Output
subject=CN=api.lab    OCSP Response Status: successful (0x0)    Cert Status: good    Next Update: Nov 11 09:45:39 2026 GMTALPN protocol: http/1.1...:tlsv1 unrecognized name:...:SSL alert number 112
  • -status_file staples a ready DER OCSP response (the lab has no internet); -status / -status_url make the server fetch it from a responder.
  • -nextprotoneg is NPN, the older ALPN predecessor (not in TLS 1.3).

172.8 PSK, performance and providers

Terminal
# n172-srv: no certificate, only a PSKopenssl s_server -accept 4501 -nocert \  -psk 1a2b3c4d -psk_identity client1# n172-clientp() { echo | openssl s_client -brief \  -connect shop.lab:4501 -psk_identity \  client1 "$@" 2>&1 \  | grep -E '^(Prot|Ciph)|alert'; }p -psk 1a2b3c4dp -psk 1a2b3c4d -tls1_2p -psk 99999999
Output
Protocol version: TLSv1.3Ciphersuite: TLS_CHACHA20_POLY1305_SHA256Protocol version: TLSv1.2Ciphersuite: DHE-PSK-AES256-GCM-SHA384...:ssl/tls alert illegal parameter:...:SSL alert number 47[srv] ...:tls_psk_do_binder:binder does not verify:...
  • -psk is hex without 0x; -psk_hint sends a hint; SRP options (-srpvfile, -srpuserseed) are deprecated.
  • Performance: -max_send_frag (most practical), -split_send_frag, -max_pipelines (needs a pipelining engine), -read_buf.
  • Providers: -provider default|legacy|fips, -propquery, -rand/-writerand; -engine is deprecated in OpenSSL 3.

172.9 Connected commands (typed at the start of a line)

KeyEffectSeen in lab
qClose connection, keep acceptingDONE / CONNECTION CLOSED
QClose and exit the servershutdown accept socket
r / RRenegotiate (TLS 1.2); R also requests client certClient: read hello request (x2)
PPlain text on TCP (protocol violation)fatal record_overflow
SPrint session cache status0 items in the session cache
k / KTLS 1.3 key update (K also requests one)<<< KeyUpdate
cRequest client cert (TLS 1.3), useful for mTLS tests-

172.10 openssl ciphers: options and syntax

Terminal
openssl ciphers -v 'ECDHE+AESGCM'openssl ciphers -V ECDHE-ECDSA-AES128-GCM-SHA256openssl ciphers -convert \  TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256openssl ciphers -s -tls1_2 | tr : '\n' | wc -l
Output
TLS_AES_256_GCM_SHA384  TLSv1.3 Kx=any  Au=any   Enc=AESGCM(256) Mac=AEAD...ECDHE-ECDSA-AES128-GCM-SHA256 TLSv1.2 Kx=ECDH Au=ECDSA Enc=AESGCM(128) Mac=AEAD  0xC0,0x2B - ECDHE-ECDSA-AES128-GCM-SHA256 TLSv1.2 Kx=ECDH Au=ECDSA Enc=AESGCM(128) Mac=AEADOpenSSL cipher name: ECDHE-RSA-AES128-GCM-SHA25627
OperatorMeaning
a:bList (comma/space also work)
A+BAND: suites matching both
!XDelete permanently (cannot be added back)
-XDelete, can be added back later
+XMove matching suites to the end
@STRENGTHSort by key length
@SECLEVEL=nSecurity level 0-5
  • 'ALL:!kRSA:kRSA+AES256' gave 0 RSA suites; 'ALL:-kRSA:kRSA+AES256' gave 5.
  • A typo (HIHG) or a removed cipher (3DES) gives Error in cipher list: no cipher match.

172.11 Cipher strings and TLS 1.3 names

Output
ALL                    140HIGH                   130HIGH:!aNULL:!MD5       118ECDHE+AESGCM           7DEFAULT                60aNULL                  16eNULL                  21-s DEFAULT             30-s DEFAULT@SECLEVEL=3  24-s DEFAULT@SECLEVEL=4  11
  • ALL excludes the 21 eNULL suites (they are in COMPLEMENTOFALL); aNULL = no authentication, open to man-in-the-middle.
  • Keyword groups: key exchange (kRSA, kECDHE, kDHE), auth (aRSA, aECDSA), encryption (AES128, AESGCM, CHACHA20), MAC (SHA256, SHA384), PSK, SUITEB, CBC.
  • TLS 1.3 has only five suites: three by default (AES_256_GCM, CHACHA20_POLY1305, AES_128_GCM) plus AES_128_CCM and AES_128_CCM_8 via -ciphersuites.
  • With -s, CCM_8 disappears: its 8-byte tag is too weak for the default security level.

172.12 Common mistakes

  • Believing ALL means every cipher: it has weak suites and no eNULL; use DEFAULT or HIGH:!aNULL:!MD5.
  • Setting TLS 1.3 suites with -cipher (needs -ciphersuites).
  • Expecting -no_ticket to stop resumption: add -no_cache too.
  • Leaving -keylogfile or -comp on outside a lab.

172.13 Interview tips

  • Testing TLS safely: s_server replica with the same cert, versions and ciphers; try combinations with s_client -trace; expand strings with openssl ciphers -s -v.
  • Know the alerts: 40 handshake failure, 47 illegal parameter (bad PSK), 70 protocol version, 112 unrecognized name.
  • Resumption: tickets (stateless) vs session cache (Session ID, server-side state).
  • ! vs - in cipher strings: ! is permanent, - can be re-added.