equal
deleted
inserted
replaced
191 protected NamedGroupFunctions(NamedGroup ng) { |
191 protected NamedGroupFunctions(NamedGroup ng) { |
192 this.ng = ng; |
192 this.ng = ng; |
193 } |
193 } |
194 |
194 |
195 public AlgorithmParameters getParameters() { |
195 public AlgorithmParameters getParameters() { |
|
196 |
196 AlgorithmParameters result = namedGroupParams.get(ng); |
197 AlgorithmParameters result = namedGroupParams.get(ng); |
197 if (result == null) { |
198 if (result == null) { |
198 Optional<AlgorithmParameters> paramsOpt = getParametersImpl(); |
199 Optional<AlgorithmParameters> paramsOpt = getParametersImpl(); |
199 if (paramsOpt.isPresent()) { |
200 if (paramsOpt.isPresent()) { |
200 result = paramsOpt.get(); |
201 result = paramsOpt.get(); |
201 namedGroupParams.put(ng, result); |
202 namedGroupParams.put(ng, result); |
202 } |
203 } |
203 } |
204 } |
|
205 |
204 return result; |
206 return result; |
205 } |
207 } |
206 |
208 |
207 public NamedGroup getNamedGroup() { |
209 public NamedGroup getNamedGroup() { |
208 return ng; |
210 return ng; |
311 } |
313 } |
312 |
314 |
313 @Override |
315 @Override |
314 public boolean isAvailable() { |
316 public boolean isAvailable() { |
315 |
317 |
|
318 AlgorithmParameters params = getParameters(); |
|
319 return params != null; |
|
320 } |
|
321 |
|
322 @Override |
|
323 protected Optional<AlgorithmParameters> getParametersImpl() { |
316 try { |
324 try { |
317 AlgorithmParameters params = getParameters(); |
325 AlgorithmParameters params = JsseJce.getAlgorithmParameters("DiffieHellman"); |
318 AlgorithmParameterSpec spec = getFFDHEDHParameterSpec(getNamedGroup()); |
326 AlgorithmParameterSpec spec = getFFDHEDHParameterSpec(getNamedGroup()); |
319 params.init(spec); |
327 params.init(spec); |
320 return true; |
328 return Optional.of(params); |
321 } catch (InvalidParameterSpecException e) { |
329 } catch(InvalidParameterSpecException | NoSuchAlgorithmException ex) { |
322 return false; |
|
323 } |
|
324 } |
|
325 |
|
326 @Override |
|
327 protected Optional<AlgorithmParameters> getParametersImpl() { |
|
328 try { |
|
329 return Optional.of( |
|
330 JsseJce.getAlgorithmParameters("DiffieHellman")); |
|
331 } catch(NoSuchAlgorithmException ex) { |
|
332 return Optional.empty(); |
330 return Optional.empty(); |
333 } |
331 } |
334 } |
332 } |
335 |
333 |
336 } |
334 } |
364 } |
362 } |
365 |
363 |
366 @Override |
364 @Override |
367 public boolean isAvailable() { |
365 public boolean isAvailable() { |
368 |
366 |
|
367 AlgorithmParameters params = getParameters(); |
|
368 return params != null; |
|
369 } |
|
370 |
|
371 @Override |
|
372 protected Optional<AlgorithmParameters> getParametersImpl() { |
369 try { |
373 try { |
370 AlgorithmParameters params = getParameters(); |
374 AlgorithmParameters params = JsseJce.getAlgorithmParameters("EC"); |
371 AlgorithmParameterSpec spec = new ECGenParameterSpec(getNamedGroup().oid); |
375 AlgorithmParameterSpec spec = new ECGenParameterSpec(getNamedGroup().oid); |
372 params.init(spec); |
376 params.init(spec); |
373 return true; |
377 return Optional.of(params); |
374 } catch (InvalidParameterSpecException e) { |
378 } catch(InvalidParameterSpecException | NoSuchAlgorithmException ex) { |
375 return false; |
|
376 } |
|
377 } |
|
378 |
|
379 @Override |
|
380 protected Optional<AlgorithmParameters> getParametersImpl() { |
|
381 try { |
|
382 return Optional.of( |
|
383 JsseJce.getAlgorithmParameters("EC")); |
|
384 } catch(NoSuchAlgorithmException ex) { |
|
385 return Optional.empty(); |
379 return Optional.empty(); |
386 } |
380 } |
387 } |
381 } |
388 } |
382 } |
389 |
383 |
847 } |
841 } |
848 |
842 |
849 // check whether the group is supported by the underlying providers |
843 // check whether the group is supported by the underlying providers |
850 public static boolean isAvailableGroup(NamedGroup namedGroup) { |
844 public static boolean isAvailableGroup(NamedGroup namedGroup) { |
851 |
845 |
852 Optional<NamedGroupFunctions> ngf = namedGroup.getFunctions(); |
846 Optional<NamedGroupFunctions> ngfOpt = namedGroup.getFunctions(); |
853 if (ngf.isEmpty()) { |
847 if (ngfOpt.isEmpty()) { |
854 return false; |
848 return false; |
855 } |
849 } |
856 return ngf.get().isAvailable(); |
850 NamedGroupFunctions ngf = ngfOpt.get(); |
|
851 return ngf.isAvailable(); |
857 |
852 |
858 } |
853 } |
859 |
854 |
860 static ECGenParameterSpec getECGenParamSpec(NamedGroup namedGroup) { |
855 static ECGenParameterSpec getECGenParamSpec(NamedGroup namedGroup) { |
861 if (namedGroup.type != NamedGroupType.NAMED_GROUP_ECDHE) { |
856 if (namedGroup.type != NamedGroupType.NAMED_GROUP_ECDHE) { |