Browse Source

tls: print the server's plaintext alert on handshake refusal

A server that does not support TLS 1.3 (e.g. cloudron.io, which is
TLS 1.2 only) answers the ClientHello with a plaintext fatal alert
(protocol_version).  pump_record() treated any non-handshake outer
record as a protocol error, so this surfaced only as a generic
"tls: handshake failed".

Decode outer-type-21 alerts before the handshake branch and map the
common descriptions, so the board now prints:

  tls: server alert: protocol version (the server may not support TLS 1.3) (level 2)
  tls: handshake failed (server does not support TLS 1.3)

Verified against `openssl s_server -tls1_2` in QEMU.  The change is in
the command pack, so `make net-cmds` delivers it without a kernel
reload.
Johannes Zellner 1 month ago
parent
commit
fca0087b5b
1 changed files with 30 additions and 0 deletions
  1. 30 0
      tls.c

+ 30 - 0
tls.c

@@ -594,6 +594,36 @@ static int pump_record(unsigned int deadline)
 		}
 		return 0;
 	}
+	if (hdr[0] == 21) {                     /* plaintext alert */
+		if (len != 2 || raw_read(rec_pt, 2, deadline) != 0) {
+			err = 3;
+			return -1;
+		}
+		u_puts("tls: server alert: ");
+		switch (rec_pt[1]) {
+		case 40:
+			u_puts("handshake failure");
+			break;
+		case 47:
+			u_puts("illegal parameter");
+			break;
+		case 70:
+			u_puts("protocol version (the server may not support TLS 1.3)");
+			break;
+		case 80:
+			u_puts("internal error");
+			break;
+		default:
+			u_puts("description ");
+			u_putdec(rec_pt[1]);
+			break;
+		}
+		u_puts(" (level ");
+		u_putdec(rec_pt[0]);
+		u_puts(")\n");
+		err = 4;
+		return -1;
+	}
 	if (phase == 0) {
 		if (hdr[0] != 22 || len > TLS_SH_MAX) {
 			err = 3;