GeezerVison is showing github.com — Fix OCSP Tests (#17114) · netty/netty@7aa3f1f
File treeExpand file treeCollapse file tree Open diff view settings main/java/io/netty/handler/ssl/ocsp test/java/io/netty/handler/ssl/ocsp
testsuite-jpms/src/test/java/io/netty/testsuite_jpms/test
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +31Lines changed: 31 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +/* | | 2 | + * Copyright 2026 The Netty Project | | 3 | + * | | 4 | + * The Netty Project licenses this file to you under the Apache License, | | 5 | + * version 2.0 (the "License"); you may not use this file except in compliance | | 6 | + * with the License. You may obtain a copy of the License at: | | 7 | + * | | 8 | + * https://www.apache.org/licenses/LICENSE-2.0 | | 9 | + * | | 10 | + * Unless required by applicable law or agreed to in writing, software | | 11 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | | 12 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | | 13 | + * License for the specific language governing permissions and limitations | | 14 | + * under the License. | | 15 | + */ | | 16 | +package io.netty.handler.ssl.ocsp; | | 17 | + | | 18 | +/** | | 19 | + * Thrown internally by {@link OcspClient} if the certificate being checked does not specify any OCSP Responder. | | 20 | + * <p> | | 21 | + * This exception extends {@link NullPointerException} for backwards compatibility reasons. | | 22 | + */ | | 23 | +public final class NoOcspResponderException extends NullPointerException { | | 24 | + /** | | 25 | + * Create a new instance with the given message. | | 26 | + * @param message The error message. | | 27 | + */ | | 28 | + public NoOcspResponderException(String message) { | | 29 | + super(message); | | 30 | + } | | 31 | +} |
Collapse file Copy file name to clipboardExpand all lines: handler-ssl-ocsp/src/main/java/io/netty/handler/ssl/ocsp/OcspClient.java +7-5Lines changed: 7 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -104,7 +104,7 @@ final class OcspClient { | 104 | 104 | * @param issuer {@link X509Certificate} issuer of client certificate | 105 | 105 | * @param validateResponseNonce Set to {@code true} to enable OCSP response validation | 106 | 106 | * @param ioTransport {@link IoTransport} to use | 107 | | - * @return {@link Promise} of {@link BasicOCSPResp} | | 107 | + * @param responsePromise {@link Promise} of {@link BasicOCSPResp} | 108 | 108 | */ | 109 | 109 | static void query(final X509Certificate x509Certificate, | 110 | 110 | final X509Certificate issuer, final boolean validateResponseNonce, | @@ -401,13 +401,15 @@ private static String parseOcspUrlFromCertificate(X509Certificate cert) { | 401 | 401 | AuthorityInformationAccess aiaExtension = AuthorityInformationAccess.fromExtensions(holder.getExtensions()); | 402 | 402 |
| 403 | 403 | // Lookup for OCSP responder url | 404 | | - for (AccessDescription accessDescription : aiaExtension.getAccessDescriptions()) { | 405 | | - if (accessDescription.getAccessMethod().equals(id_ad_ocsp)) { | 406 | | - return accessDescription.getAccessLocation().getName().toASN1Primitive().toString(); | | 404 | + if (aiaExtension != null) { | | 405 | + for (AccessDescription accessDescription : aiaExtension.getAccessDescriptions()) { | | 406 | + if (accessDescription.getAccessMethod().equals(id_ad_ocsp)) { | | 407 | + return accessDescription.getAccessLocation().getName().toASN1Primitive().toString(); | | 408 | + } | 407 | 409 | } | 408 | 410 | } | 409 | 411 |
| 410 | | - throw new NullPointerException("Unable to find OCSP responder URL in Certificate"); | | 412 | + throw new NoOcspResponderException("Unable to find OCSP responder URL in Certificate"); | 411 | 413 | } | 412 | 414 |
| 413 | 415 | static final class Initializer extends ChannelInitializer<SocketChannel> { | |
Collapse file Copy file name to clipboardExpand all lines: handler-ssl-ocsp/src/main/java/io/netty/handler/ssl/ocsp/OcspServerCertificateValidator.java +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -168,8 +168,8 @@ public void userEventTriggered(final ChannelHandlerContext ctx, final Object evt | 168 | 168 |
| 169 | 169 | Date current = new Date(); | 170 | 170 | Date thisUpdate = response.getThisUpdate(); | 171 | | - Date nextUpdate = response.getNextUpdate(); | 172 | | - if (thisUpdate == null || !current.after(thisUpdate) || | | 171 | + Date nextUpdate = response.getNextUpdate(); | | 172 | + if (thisUpdate == null || !current.after(thisUpdate) || | 173 | 173 | (nextUpdate != null && !current.before(nextUpdate))) { | 174 | 174 | ctx.fireExceptionCaught(new IllegalStateException("OCSP Response is out-of-date")); | 175 | 175 | return; | |
Collapse file Copy file name to clipboardExpand all lines: handler-ssl-ocsp/src/test/java/io/netty/handler/ssl/ocsp/OcspClientTest.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 73 | 73 | class OcspClientTest extends AbstractOcspTest { | 74 | 74 |
| 75 | 75 | @ParameterizedTest | 76 | | - @ValueSource(strings = {"https://netty.io", "https://apple.com"}) | | 76 | + @ValueSource(strings = {"https://apple.com"}) | 77 | 77 | void simpleOcspQueryTest(String urlString) throws IOException, ExecutionException, InterruptedException { | 78 | 78 | HttpsURLConnection httpsConnection = null; | 79 | 79 | try { | |
Collapse file Copy file name to clipboardExpand all lines: handler-ssl-ocsp/src/test/java/io/netty/handler/ssl/ocsp/OcspServerCertificateValidatorTest.java +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -59,7 +59,7 @@ void connectUsingHttpAndValidateCertificateUsingOcspTest() throws Exception { | 59 | 59 | @Override | 60 | 60 | protected void initChannel(SocketChannel ch) { | 61 | 61 | ChannelPipeline pipeline = ch.pipeline(); | 62 | | - pipeline.addLast(sslContext.newHandler(ch.alloc(), "netty.io", 443)); | | 62 | + pipeline.addLast(sslContext.newHandler(ch.alloc(), "apple.com", 443)); | 63 | 63 | pipeline.addLast(new OcspServerCertificateValidator(false, createDefaultTransport())); | 64 | 64 | pipeline.addLast(new SimpleChannelInboundHandler<Object>() { | 65 | 65 | @Override | @@ -81,7 +81,7 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { | 81 | 81 | } | 82 | 82 | }); | 83 | 83 |
| 84 | | - ChannelFuture channelFuture = bootstrap.connect("netty.io", 443); | | 84 | + ChannelFuture channelFuture = bootstrap.connect("apple.com", 443); | 85 | 85 | channelFuture.sync(); | 86 | 86 |
| 87 | 87 | // Wait for maximum of 1 minute for Ocsp validation to happen | |
Collapse file Copy file name to clipboardExpand all lines: testsuite-jpms/src/test/java/io/netty/testsuite_jpms/test/OCSPTest.java +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -62,7 +62,7 @@ public void testSimpleQueryTest() throws Exception { | 62 | 62 | @Override | 63 | 63 | protected void initChannel(SocketChannel ch) { | 64 | 64 | ChannelPipeline pipeline = ch.pipeline(); | 65 | | - pipeline.addLast(sslContext.newHandler(ch.alloc(), "netty.io", 443)); | | 65 | + pipeline.addLast(sslContext.newHandler(ch.alloc(), "apple.com", 443)); | 66 | 66 | pipeline.addLast(new OcspServerCertificateValidator(false)); | 67 | 67 | pipeline.addLast(new SimpleChannelInboundHandler<>() { | 68 | 68 | @Override | @@ -84,7 +84,7 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { | 84 | 84 | } | 85 | 85 | }); | 86 | 86 |
| 87 | | - ChannelFuture channelFuture = bootstrap.connect("netty.io", 443); | | 87 | + ChannelFuture channelFuture = bootstrap.connect("apple.com", 443); | 88 | 88 | channelFuture.sync(); | 89 | 89 |
| 90 | 90 | // Wait for maximum of 1 minute for Ocsp validation to happen | |
|