GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — OCSP: Correctly handle that `nextUpdate` is optional · netty/netty@e3ebf70

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • handler-ssl-ocsp/src
    • main/java/io/netty/handler/ssl/ocsp
      • OcspResponse.java
      • OcspServerCertificateValidator.java
    • test/java/io/netty/handler/ssl/ocsp
      • AbstractOcspTest.java
      • OcspServerCertificateValidatorTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎handler-ssl-ocsp/src/main/java/io/netty/handler/ssl/ocsp/OcspResponse.java‎

Copy file name to clipboardExpand all lines: handler-ssl-ocsp/src/main/java/io/netty/handler/ssl/ocsp/OcspResponse.java
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,27 @@ public class OcspResponse {
2727
public OcspResponse(Status status, Date thisUpdate, Date nextUpdate) {
2828
this.status = checkNotNull(status, "Status");
2929
this.thisUpdate = checkNotNull(thisUpdate, "ThisUpdate");
30-
this.nextUpdate = checkNotNull(nextUpdate, "NextUpdate");
30+
this.nextUpdate = nextUpdate; // The 'nextUpdate' field is optional.
3131
}
3232

33+
/**
34+
* The OCSP response status, saying if the certificate is valid or not.
35+
*/
3336
public Status status() {
3437
return status;
3538
}
3639

40+
/**
41+
* The date of the given OCSP update, never {@code null}.
42+
*/
3743
public Date thisUpdate() {
3844
return thisUpdate;
3945
}
4046

47+
/**
48+
* The future date of the next OCSP update, if any.
49+
* This field is optional, and if {@code null}, indicates that an update is available at any time.
50+
*/
4151
public Date nextUpdate() {
4252
return nextUpdate;
4353
}
Collapse file

‎handler-ssl-ocsp/src/main/java/io/netty/handler/ssl/ocsp/OcspServerCertificateValidator.java‎

Copy file name to clipboardExpand all lines: handler-ssl-ocsp/src/main/java/io/netty/handler/ssl/ocsp/OcspServerCertificateValidator.java
+17-12Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import java.net.SocketAddress;
3838
import java.security.cert.Certificate;
3939
import java.security.cert.X509Certificate;
40-
import java.time.Instant;
4140
import java.util.Date;
4241
import java.util.List;
4342
import java.util.concurrent.TimeUnit;
@@ -186,16 +185,17 @@ public void userEventTriggered(final ChannelHandlerContext ctx, final Object evt
186185
if (future.isSuccess()) {
187186
SingleResp response = future.getNow().getResponses()[0];
188187

189-
Date thisUpdateDate = response.getThisUpdate();
190-
Date nextUpdateDate = response.getNextUpdate();
191-
Instant thisUpdate = thisUpdateDate == null ? null :
192-
thisUpdateDate.toInstant().minusMillis(CLOCK_SKEW_TOLERANCE_MILLIS);
193-
Instant nextUpdate = nextUpdateDate == null ? null :
194-
nextUpdateDate.toInstant().plusMillis(CLOCK_SKEW_TOLERANCE_MILLIS);
195-
Instant now = Instant.now();
196-
if (thisUpdate == null || !now.isAfter(thisUpdate) ||
197-
(nextUpdate != null && !now.isBefore(nextUpdate))) {
188+
Date thisUpdate = response.getThisUpdate();
189+
Date nextUpdate = response.getNextUpdate();
190+
long now = System.currentTimeMillis();
191+
Date nowLower = new Date(now - CLOCK_SKEW_TOLERANCE_MILLIS);
192+
Date nowUpper = new Date(now + CLOCK_SKEW_TOLERANCE_MILLIS);
193+
if (thisUpdate == null || nowUpper.before(thisUpdate) ||
194+
nowLower.after(nextUpdate == null ? thisUpdate : nextUpdate)) {
198195
ctx.fireExceptionCaught(new IllegalStateException("OCSP Response is out-of-date"));
196+
if (closeAndThrowIfNotValid) {
197+
ctx.close();
198+
}
199199
return;
200200
}
201201

@@ -210,14 +210,14 @@ public void userEventTriggered(final ChannelHandlerContext ctx, final Object evt
210210
}
211211

212212
ctx.fireUserEventTriggered(new OcspValidationEvent(
213-
new OcspResponse(status, thisUpdateDate, nextUpdateDate)));
213+
new OcspResponse(status, thisUpdate, nextUpdate)));
214214

215215
// If Certificate is not VALID and 'closeAndThrowIfNotValid' is set
216216
// to 'true' then close the channel and throw an exception.
217217
if (status != OcspResponse.Status.VALID && closeAndThrowIfNotValid) {
218218
// Certificate is not valid. Throw
219219
ctx.fireExceptionCaught(new OCSPException(
220-
"Certificate not valid. Status: " + status));
220+
"Certificate not valid. Status: " + status));
221221
ctx.close();
222222
}
223223
} else {
@@ -226,6 +226,11 @@ public void userEventTriggered(final ChannelHandlerContext ctx, final Object evt
226226
ctx.close();
227227
}
228228
}
229+
} catch (Throwable th) {
230+
ctx.fireExceptionCaught(th);
231+
if (closeAndThrowIfNotValid) {
232+
ctx.close();
233+
}
229234
} finally {
230235
ctx.fireUserEventTriggered(evt);
231236
// Lets remove ourselves from the pipeline because we are done processing validation.
Collapse file

‎handler-ssl-ocsp/src/test/java/io/netty/handler/ssl/ocsp/AbstractOcspTest.java‎

Copy file name to clipboardExpand all lines: handler-ssl-ocsp/src/test/java/io/netty/handler/ssl/ocsp/AbstractOcspTest.java
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import org.junit.jupiter.api.AfterEach;
2424
import org.junit.jupiter.api.BeforeEach;
2525

26+
import java.util.concurrent.TimeUnit;
27+
2628
/**
2729
* We can't use {@link IoTransport#DEFAULT} because that breaks leak detection. This base class creates a per-test
2830
* transport as a substitute.
@@ -37,7 +39,7 @@ void start() {
3739

3840
@AfterEach
3941
void stop() {
40-
group.shutdownGracefully().syncUninterruptibly();
42+
group.shutdownGracefully(100, 1000, TimeUnit.MILLISECONDS).syncUninterruptibly();
4143
}
4244

4345
IoTransport createDefaultTransport() {

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.