7
7
import java .util .ArrayList ;
8
8
import java .util .Collection ;
9
9
import java .util .Collections ;
10
+ import java .util .Comparator ;
10
11
import java .util .HashSet ;
11
12
import java .util .Hashtable ;
12
13
import java .util .LinkedHashMap ;
45
46
import org .bouncycastle .tls .TlsUtils ;
46
47
import org .bouncycastle .tls .TrustedAuthority ;
47
48
import org .bouncycastle .tls .crypto .DHGroup ;
49
+ import org .bouncycastle .tls .crypto .TlsDHConfig ;
48
50
import org .bouncycastle .tls .crypto .impl .jcajce .JcaTlsCrypto ;
49
51
import org .bouncycastle .util .Arrays ;
50
52
import org .bouncycastle .util .encoders .Hex ;
@@ -64,7 +66,6 @@ class ProvTlsServer
64
66
* TODO[jsse] Does this selection override the restriction from 'jdk.tls.ephemeralDHKeySize'?
65
67
* TODO[fips] Probably should be ignored in fips mode?
66
68
*/
67
- @ SuppressWarnings ("unused" )
68
69
private static final DHGroup [] provServerDefaultDHEParameters = getDefaultDHEParameters ();
69
70
70
71
private static final boolean provServerEnableCA = PropertyUtils
@@ -153,6 +154,14 @@ else if (!p.isProbablePrime(120))
153
154
outerComma = closeBrace + 1 ;
154
155
if (outerComma >= limit )
155
156
{
157
+ result .sort (new Comparator <DHGroup >()
158
+ {
159
+ @ Override
160
+ public int compare (DHGroup a , DHGroup b )
161
+ {
162
+ return a .getP ().bitLength () - b .getP ().bitLength ();
163
+ }
164
+ });
156
165
return result .toArray (new DHGroup [result .size ()]);
157
166
}
158
167
}
@@ -324,6 +333,25 @@ protected boolean selectCipherSuite(int cipherSuite) throws IOException
324
333
return result ;
325
334
}
326
335
336
+ @ Override
337
+ public TlsDHConfig getDHConfig () throws IOException
338
+ {
339
+ if (provServerDefaultDHEParameters != null )
340
+ {
341
+ int minimumFiniteFieldBits = Math .max (
342
+ TlsDHUtils .getMinimumFiniteFieldBits (selectedCipherSuite ), provEphemeralDHKeySize );
343
+
344
+ for (DHGroup group : provServerDefaultDHEParameters )
345
+ {
346
+ if (group .getP ().bitLength () >= minimumFiniteFieldBits )
347
+ {
348
+ return new TlsDHConfig (group );
349
+ }
350
+ }
351
+ }
352
+ return super .getDHConfig ();
353
+ }
354
+
327
355
@ Override
328
356
protected int selectDH (int minimumFiniteFieldBits )
329
357
{
0 commit comments