Speed

No Common Cipher, No Common Group

The two ends must share a key-exchange group and a cipher suite. With no common group the server answers the hello with alert 40, handshake_failure, and a server that wants another group than the client sent is not a failure at all.

The question

Besides the version, the two ends must agree on a group for the key exchange and on a cipher for the records. What happens when the client offers one group and the server accepts only another, and does every mismatch end the handshake?

Both ends are test endpoints in this tab's memory, made with ssl.tls_pair. The client offers the group P-256 only and the server accepts X25519 only. The certificates and the key are public test material. In the exercise you set TLS 1.2 cipher lists and read which cipher was chosen.

Work it by hand

The client's hello carries the groups it supports and a key share for one of them (RFC 9846 sections 4.3.7 and 4.3.8). The server needs a group that is in the client's list and in its own. Here the lists are P-256 and X25519: nothing in common.

RFC 9846 section 2.1 says that if the client's key share is unsuitable the server corrects it with a HelloRetryRequest, and "If no common cryptographic parameters can be negotiated, the server MUST abort the handshake with an appropriate alert." The alert here should be handshake_failure, number 40, hex 28, described in section 6.2 as the sender being "unable to negotiate an acceptable set of security parameters". So two flights: the hello and a 7-byte alert, 15 03 03 00 02 02 28.

Run it

Line 3 sets the server's group and suite, and line 5 sets the client's. The loop of lines 8 to 12 takes turns, counts the flights that carry bytes and keeps the last one as hex. Lines 13 and 14 return that flight if it is a 7-byte alert, and no plaintext alert otherwise. Lines 15 and 16 return the number of flights and error().

Four rows: the client groups P-256, the server group X25519, 2 flights and the alert bytes 15 03 03 00 02 02 28.

Public test material, generated for this lesson. Never use it for anything real.

let server = ssl.server_ctx(ssl.parse_cert(leaf_pem), ssl.parse_key(leaf_key));
server.chain(ssl.parse_cert(int_pem));
server.groups(server_group); server.suites(server_suite);
let client = ssl.client_ctx(); client.add_ca(ssl.parse_cert(root_pem));
client.groups(client_groups); client.suites(client_suite);
let pair = ssl.tls_pair(client, server, "www.example.test");
let turns = 0; let flights = 0; let last = "";
while (!pair.done() && pair.error() == "" && turns < 10) {
  let flight = pair.step(); turns = turns + 1;
  if (str_len(flight) > 0) { flights = flights + 1; }
  if (str_len(flight) > 0) { last = str_hex_encode(flight); }
}
let answer = "no plaintext alert";
if (hex_len(last) == 7 && hex_u8(last, 0) == 21) { answer = last; }
lmcode_return_put("flights", flights);
lmcode_return_put("error", pair.error());
{
  "answer": "15030300020228",
  "flights": 2,
  "error": "server handshake: error:0A000065:SSL routines::no suitable key share"
}

With the client's group P-256 and the server's X25519 the answer is 15030300020228 in 2 flights. What this OpenSSL build says: server handshake: error:0A000065:SSL routines::no suitable key share. These come from this run.

You can change the four texts. With client_groups X25519:P-256 and server_group P-256 the handshake is not a failure: the server asks the client for another key share and the handshake finishes in 6 flights, with no alert. With client_groups X25519 and client_suite TLS_CHACHA20_POLY1305_SHA256 against the server's default suite it fails again with the same alert bytes and server handshake: error:0A0000C1:SSL routines::no shared cipher; that text is what this build says.

An empty client_groups runs: the client has nothing to offer and gives up alone, in one flight, with client handshake: error:0A000127:SSL routines::no suitable groups. A group that is not known, such as P-256x, stops line 3 for the server or line 5 for the client with "Line 5: TlsCtx.groups: no usable group in 'P-256x'". A suite that is not known stops with "Line 5: TlsCtx.suites: no usable TLS 1.3 suite in 'TLS_NOPE': error:0A0000B9:SSL routines::no cipher match".

Your turn

The program below sets TLS 1.2 as the highest version of both ends, gives the client the cipher list client_ciphers and the server server_ciphers, runs the handshake, and should return the name of the cipher that was chosen, or none if the handshake did not finish. Every case has either no cipher in common or exactly one. Decide whether it does, and find the candidates that do. Check runs each candidate on the data shown and on five others.

The client list ECDHE-RSA-AES256-GCM-SHA384 and the server list ECDHE-RSA-AES128-GCM-SHA256 of the case shown.

Public test material, generated for this lesson. Never use it for anything real.

let server = ssl.server_ctx(ssl.parse_cert(leaf_pem), ssl.parse_key(leaf_key));
server.chain(ssl.parse_cert(int_pem)); server.ciphers(server_ciphers);
let client = ssl.client_ctx(); client.add_ca(ssl.parse_cert(root_pem));
client.ciphers(client_ciphers);
server.max_version("TLSv1.2"); client.max_version("TLSv1.2");
let pair = ssl.tls_pair(client, server, "www.example.test");
let turns = 0;
while (!pair.done() && pair.error() == "" && turns < 10) {
  let flight = pair.step(); turns = turns + 1;
}
let answer = "none";
answer = pair.cipher();
lmcode_return_put("version", pair.version());
{
  "answer": "(NONE)",
  "version": "TLSv1.2"
}

A client asks for www.example.test and trusts root_pem; the server holds leaf_pem, int_pem and leaf_key. Both ends are test endpoints in this tab's memory. Set the highest version of both ends to TLSv1.2, the client's TLS 1.2 cipher list to client_ciphers and the server's to server_ciphers. Take turns while the pair is not done and has no error, at most ten times. Return the name of the cipher the pair reports if the handshake finished, and none if it did not. Check runs each candidate on the data shown and on five others.

Read the result carefully

A TLS 1.2 cipher name such as ECDHE-RSA-AES128-GCM-SHA256 names the key exchange and the signature as well as the cipher; a TLS 1.3 suite does not, because the group is negotiated separately. Alert 40 does not say which of the two was missing: the sentence in error() does, and only the server has it. With two ciphers in common the two ends of a real pair may prefer differently, so no case here has two.

The texts and numbers are what this OpenSSL build says and sends, and a real server may answer differently or not at all. The suite mismatch above is this build's text; Check does not cover it, only the TLS 1.2 cipher lists. The certificates are valid from 2026-01-01 to 2036-01-01, and the results hold only between those years. They are test material.

Compare the group negotiation in the live handshake.

Recap

  • The ends need a common group and a common cipher; with none in common the server aborts with alert 40, handshake_failure (RFC 9846 sections 2.1 and 6.2).
  • A server that asks for another group than the client sent is corrected by a retry, not a failure.
  • A TLS 1.2 cipher name includes the key exchange; a TLS 1.3 suite does not.
  • The alert does not say which of group or cipher was missing; error() does.