GeezerVison is showing github.com — OpenSSL: Allow to obtain used named group via OpenSslSession · netty/netty@58d266f
File treeExpand file treeCollapse file tree Open diff view settings main/java/io/netty/handler/ssl test/java/io/netty/handler/ssl
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: handler/src/main/java/io/netty/handler/ssl/ExtendedOpenSslSession.java +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -251,6 +251,11 @@ public void handshakeFinished(byte[] id, String cipher, String protocol, byte[] | 251 | 251 | wrapped.handshakeFinished(id, cipher, protocol, peerCertificate, peerCertificateChain, creationTime, timeout); | 252 | 252 | } | 253 | 253 |
| | 254 | + @Override | | 255 | + public String getNamedGroup() { | | 256 | + return wrapped.getNamedGroup(); | | 257 | + } | | 258 | + | 254 | 259 | @Override | 255 | 260 | public boolean equals(Object o) { | 256 | 261 | return wrapped.equals(o); | |
Collapse file Copy file name to clipboardExpand all lines: handler/src/main/java/io/netty/handler/ssl/OpenSslSession.java +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -34,6 +34,15 @@ public interface OpenSslSession extends SSLSession { | 34 | 34 | */ | 35 | 35 | boolean hasPeerCertificates(); | 36 | 36 |
| | 37 | + /** | | 38 | + * Returns the used named group or {@code null} if none was used or if it can't be determined. | | 39 | + * | | 40 | + * @return the named group | | 41 | + */ | | 42 | + default String getNamedGroup() { | | 43 | + return null; | | 44 | + } | | 45 | + | 37 | 46 | @Override | 38 | 47 | OpenSslSessionContext getSessionContext(); | 39 | 48 | } |
Collapse file Copy file name to clipboardExpand all lines: handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslEngine.java +11-1Lines changed: 11 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -2489,6 +2489,7 @@ private final class DefaultOpenSslSession implements OpenSslInternalSession { | 2489 | 2489 | // Updated once a new handshake is started and so the SSLSession reused. | 2490 | 2490 | private long lastAccessed = -1; | 2491 | 2491 |
| | 2492 | + private volatile String namedGroup; | 2492 | 2493 | private volatile int applicationBufferSize = MAX_PLAINTEXT_LENGTH; | 2493 | 2494 | private volatile Certificate[] localCertificateChain; | 2494 | 2495 | private volatile Map<String, Object> keyValueStorage = new ConcurrentHashMap<String, Object>(); | @@ -2653,7 +2654,11 @@ public void handshakeFinished(byte[] id, String cipher, String protocol, byte[] | 2653 | 2654 | } | 2654 | 2655 | this.cipher = toJavaCipherSuite(cipher, protocol); | 2655 | 2656 | this.protocol = protocol; | 2656 | | - | | 2657 | + try { | | 2658 | + this.namedGroup = SSL.getGroupName(ssl); | | 2659 | + } catch (Exception e) { | | 2660 | + throw new SSLException(e); | | 2661 | + } | 2657 | 2662 | if (clientMode) { | 2658 | 2663 | if (isEmpty(peerCertificateChain)) { | 2659 | 2664 | peerCerts = EmptyArrays.EMPTY_CERTIFICATES; | @@ -2725,6 +2730,11 @@ private void initCerts(byte[][] chain, int startPos) { | 2725 | 2730 | } | 2726 | 2731 | } | 2727 | 2732 |
| | 2733 | + @Override | | 2734 | + public String getNamedGroup() { | | 2735 | + return namedGroup; | | 2736 | + } | | 2737 | + | 2728 | 2738 | @Override | 2729 | 2739 | public Certificate[] getPeerCertificates() throws SSLPeerUnverifiedException { | 2730 | 2740 | synchronized (ReferenceCountedOpenSslEngine.this) { | |
Collapse file Copy file name to clipboardExpand all lines: handler/src/test/java/io/netty/handler/ssl/PkiTestingTlsTest.java +17Lines changed: 17 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 40 | 40 | import org.junit.jupiter.params.provider.ValueSource; | 41 | 41 |
| 42 | 42 | import java.util.ArrayList; | | 43 | +import java.util.Arrays; | 43 | 44 | import java.util.List; | 44 | 45 | import java.util.concurrent.TimeUnit; | 45 | 46 | import java.util.stream.Stream; | 46 | 47 | import javax.net.ssl.SNIHostName; | 47 | 48 | import javax.net.ssl.SSLParameters; | | 49 | +import javax.net.ssl.SSLSession; | | 50 | + | | 51 | +import static org.junit.jupiter.api.Assertions.assertTrue; | 48 | 52 |
| 49 | 53 | public class PkiTestingTlsTest { | 50 | 54 |
| @@ -282,6 +286,19 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) | 282 | 286 | if (evt instanceof SslHandshakeCompletionEvent) { | 283 | 287 | SslHandshakeCompletionEvent shce = (SslHandshakeCompletionEvent) evt; | 284 | 288 | if (shce.isSuccess()) { | | 289 | + SSLSession session = handler.engine().getSession(); | | 290 | + if (session instanceof OpenSslSession) { | | 291 | + String namedGroup = ((OpenSslSession) handler.engine() | | 292 | + .getSession()).getNamedGroup(); | | 293 | + if (groups != null) { | | 294 | + assertTrue(Arrays.asList(groups).contains(namedGroup)); | | 295 | + } else { | | 296 | + // If not specified explicit we will still use | | 297 | + // what we can support. | | 298 | + assertTrue(Arrays.asList(OpenSsl.NAMED_GROUPS) | | 299 | + .contains(namedGroup)); | | 300 | + } | | 301 | + } | 285 | 302 | promise.setSuccess(shce); | 286 | 303 | } else { | 287 | 304 | promise.setFailure(shce.cause()); | |
|