Always add key_share extension to TLS 1.3 ClientHello
even when empty
@@ -4134,21 +4134,30 @@ static Hashtable addEarlyKeySharesToClientHello(TlsContext context, TlsClient cl
return null;
}
- int[] offeredGroups = TlsExtensionsUtils.getSupportedGroupsExtension(clientExtensions);
- if (null == offeredGroups || offeredGroups.length < 1)
- {
- return null;
+ Hashtable clientAgreements = new Hashtable();
+ Vector clientShares = new Vector();
+
+ collectEarlyKeyShares(context.getCrypto(), client, clientExtensions, clientAgreements, clientShares);
+
+ TlsExtensionsUtils.addKeyShareClientHello(clientExtensions, clientShares);
+
+ return clientAgreements;
}
+ private static void collectEarlyKeyShares(TlsCrypto crypto, TlsClient client, Hashtable clientExtensions,
+ Hashtable clientAgreements, Vector clientShares) throws IOException
+ {
Vector earlyGroups = client.getEarlyKeyShareGroups();
if (null == earlyGroups || earlyGroups.isEmpty())
{
- return null;
+ return;
}
- TlsCrypto crypto = context.getCrypto();
- Vector clientShares = new Vector();
- Hashtable clientAgreements = new Hashtable();
+ int[] offeredGroups = TlsExtensionsUtils.getSupportedGroupsExtension(clientExtensions);
+ if (null == offeredGroups || offeredGroups.length < 1)
+ {
+ return;
+ }
for (int i = 0; i < offeredGroups.length; ++i)
{
@@ -4187,15 +4196,6 @@ else if (NamedGroup.refersToASpecificFiniteField(offeredGroup))
clientAgreements.put(offeredGroupElement, agreement);
}
}
-
- if (clientAgreements.isEmpty())
- {
- return null;
- }
-
- TlsExtensionsUtils.addKeyShareClientHello(clientExtensions, clientShares);
-
- return clientAgreements;
}
static byte[] readEncryptedPMS(TlsContext context, InputStream input) throws IOException
