@@ -311,22 +311,6 @@ protected ServerHello generate13ServerHello(ClientHello clientHello, HandshakeMe
311311
312312 return generate13HelloRetryRequest (clientHello );
313313 }
314-
315- if (clientShare .getNamedGroup () != serverSupportedGroups [0 ])
316- {
317- /*
318- * TODO[tls13] RFC 8446 4.2.7. As of TLS 1.3, servers are permitted to send the
319- * "supported_groups" extension to the client. Clients MUST NOT act upon any
320- * information found in "supported_groups" prior to successful completion of the
321- * handshake but MAY use the information learned from a successfully completed
322- * handshake to change what groups they use in their "key_share" extension in
323- * subsequent connections. If the server has a group it prefers to the ones in the
324- * "key_share" extension but is still willing to accept the ClientHello, it SHOULD
325- * send "supported_groups" to update the client's view of its preferences; this
326- * extension SHOULD contain all groups the server supports, regardless of whether
327- * they are currently supported by the client.
328- */
329- }
330314 }
331315
332316
@@ -408,6 +392,28 @@ protected ServerHello generate13ServerHello(ClientHello clientHello, HandshakeMe
408392 TlsExtensionsUtils .addKeyShareServerHello (serverHelloExtensions , serverShare );
409393
410394 sharedSecret = agreement .calculateSecret ();
395+
396+ /*
397+ * RFC 8446 4.2.7. As of TLS 1.3, servers are permitted to send the "supported_groups" extension to
398+ * the client. Clients MUST NOT act upon any information found in "supported_groups" prior to
399+ * successful completion of the handshake but MAY use the information learned from a successfully
400+ * completed handshake to change what groups they use in their "key_share" extension in subsequent
401+ * connections. If the server has a group it prefers to the ones in the "key_share" extension but is
402+ * still willing to accept the ClientHello, it SHOULD send "supported_groups" to update the client's
403+ * view of its preferences; this extension SHOULD contain all groups the server supports, regardless
404+ * of whether they are currently supported by the client.
405+ */
406+ if (!afterHelloRetryRequest )
407+ {
408+ int [] serverSupportedGroups = securityParameters .getServerSupportedGroups ();
409+
410+ if (!TlsUtils .isNullOrEmpty (serverSupportedGroups ) &&
411+ namedGroup != serverSupportedGroups [0 ] &&
412+ !serverEncryptedExtensions .containsKey (TlsExtensionsUtils .EXT_supported_groups ))
413+ {
414+ TlsExtensionsUtils .addSupportedGroupsExtension (serverEncryptedExtensions , serverSupportedGroups );
415+ }
416+ }
411417 }
412418
413419 TlsUtils .establish13PhaseSecrets (tlsServerContext , pskEarlySecret , sharedSecret );
0 commit comments