@@ -840,7 +840,7 @@ protected void process13HelloRetryRequest(ServerHello helloRetryRequest)
840840 final Hashtable extensions = helloRetryRequest .getExtensions ();
841841 if (null == extensions )
842842 {
843- throw new TlsFatalAlert (AlertDescription .illegal_parameter );
843+ throw new TlsFatalAlert (AlertDescription .illegal_parameter , "no extensions found" );
844844 }
845845 TlsUtils .checkExtensionData13 (extensions , HandshakeType .hello_retry_request , AlertDescription .illegal_parameter );
846846
@@ -855,30 +855,37 @@ protected void process13HelloRetryRequest(ServerHello helloRetryRequest)
855855 while (e .hasMoreElements ())
856856 {
857857 Integer extType = (Integer )e .nextElement ();
858+ int extensionType = extType .intValue ();
858859
859- if (ExtensionType .cookie == extType . intValue () )
860+ if (ExtensionType .cookie == extensionType )
860861 {
861862 continue ;
862863 }
863864
864865 if (null == TlsUtils .getExtensionData (clientExtensions , extType ))
865866 {
866- throw new TlsFatalAlert (AlertDescription .unsupported_extension );
867+ throw new TlsFatalAlert (AlertDescription .unsupported_extension ,
868+ "received unrequested extension response: " + ExtensionType .getText (extensionType ));
867869 }
868870 }
869871 }
870872
871873 final ProtocolVersion server_version = TlsExtensionsUtils .getSupportedVersionsExtensionServer (extensions );
872874 if (null == server_version )
873875 {
874- throw new TlsFatalAlert (AlertDescription .missing_extension );
876+ throw new TlsFatalAlert (AlertDescription .missing_extension ,
877+ "missing extension response: " + ExtensionType .getText (ExtensionType .supported_versions ));
875878 }
876879
877880 if (!ProtocolVersion .TLSv13 .isEqualOrEarlierVersionOf (server_version ) ||
878- !ProtocolVersion .contains (tlsClientContext .getClientSupportedVersions (), server_version ) ||
879- !TlsUtils .isValidVersionForCipherSuite (cipherSuite , server_version ))
881+ !ProtocolVersion .contains (tlsClientContext .getClientSupportedVersions (), server_version ))
880882 {
881- throw new TlsFatalAlert (AlertDescription .illegal_parameter );
883+ throw new TlsFatalAlert (AlertDescription .illegal_parameter , "invalid version selected: " + server_version );
884+ }
885+
886+ if (!TlsUtils .isValidVersionForCipherSuite (cipherSuite , server_version ))
887+ {
888+ throw new TlsFatalAlert (AlertDescription .illegal_parameter , "invalid cipher suite for selected version" );
882889 }
883890
884891 if (null != clientBinders )
@@ -891,6 +898,20 @@ protected void process13HelloRetryRequest(ServerHello helloRetryRequest)
891898 }
892899 }
893900
901+ final int selected_group = TlsExtensionsUtils .getKeyShareHelloRetryRequest (extensions );
902+
903+ /*
904+ * TODO[tls:psk_ke]
905+ *
906+ * RFC 8446 4.2.8. Servers [..] MUST NOT send a KeyShareEntry when using the "psk_ke"
907+ * PskKeyExchangeMode.
908+ */
909+ if (selected_group < 0 )
910+ {
911+ throw new TlsFatalAlert (AlertDescription .missing_extension ,
912+ "missing extension response: " + ExtensionType .getText (ExtensionType .key_share ));
913+ }
914+
894915 /*
895916 * RFC 8446 4.2.8. Upon receipt of this [Key Share] extension in a HelloRetryRequest, the
896917 * client MUST verify that (1) the selected_group field corresponds to a group which was
@@ -899,12 +920,10 @@ protected void process13HelloRetryRequest(ServerHello helloRetryRequest)
899920 * extension in the original ClientHello. If either of these checks fails, then the client
900921 * MUST abort the handshake with an "illegal_parameter" alert.
901922 */
902- final int selected_group = TlsExtensionsUtils .getKeyShareHelloRetryRequest (extensions );
903-
904923 if (!TlsUtils .isValidKeyShareSelection (server_version , securityParameters .getClientSupportedGroups (),
905924 clientAgreements , selected_group ))
906925 {
907- throw new TlsFatalAlert (AlertDescription .illegal_parameter );
926+ throw new TlsFatalAlert (AlertDescription .illegal_parameter , "invalid key_share selected" );
908927 }
909928
910929 final byte [] cookie = TlsExtensionsUtils .getCookieExtension (extensions );
0 commit comments