Skip to content

Commit 918132c

Browse files
author
kasemir
committed
OCSP check
Use "REVOKED" from OCSP response Tweak log messages Add bouncycastle to serverdemo
1 parent 523c3af commit 918132c

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

core/pva/serverdemo

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

3-
LIB=../../dependencies/phoebus-target/target/lib/bcpkix-jdk18on-1.82.jar:../../dependencies/phoebus-target/target/lib/bcprov-jdk18on-1.82.jar
3+
# External dependencies
4+
LIB=`echo ../../dependencies/phoebus-target/target/lib/bcpkix-*.jar`
5+
LIB+=':'`echo ../../dependencies/phoebus-target/target/lib/bcprov-*.jar`
6+
LIB+=':'`echo ../../dependencies/phoebus-target/target/lib/bcutil-*.jar`
47

58
JAR=`echo target/core-pva*.jar`
69
if [ -r "$JAR" ]
710
then
8-
# Echo use jar file
11+
# Use jar
912
java -cp $LIB:$JAR org.epics.pva.server.ServerDemo "$@"
1013
else
11-
# Use build output
14+
# Use IDE build output
1215
java -cp $LIB:target/classes org.epics.pva.server.ServerDemo "$@"
1316
fi
1417

core/pva/src/main/java/org/epics/pva/common/CertificateStatus.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class CertificateStatus
5050
private final X509Certificate certificate;
5151
private final String peer_name;
5252
private final PVAChannel pv;
53-
private String status = null;
53+
private volatile String status = null;
5454

5555
/** Called by {@link CertificateStatusMonitor}
5656
*
@@ -158,6 +158,7 @@ private void handleMonitor(final PVAChannel channel, final BitSet changes, final
158158

159159
// OCSP can include one or more responses. Find one that confirms the certificate
160160
boolean ocsp_confirmation = false;
161+
final Date now = new Date();
161162
for (SingleResp response : basic.getResponses())
162163
{
163164
// Is response for the certificate we want to check?
@@ -175,7 +176,7 @@ private void handleMonitor(final PVAChannel channel, final BitSet changes, final
175176
"\ndiffers from expected\n" + Hexdump.toHexdump(cert_issuer_name_hash));
176177
continue;
177178
}
178-
logger.log(Level.FINER, () -> "OCSP authority hash for name " + certificate.getIssuerX500Principal() +
179+
logger.log(Level.FINER, () -> "OCSP matches authority hash for name " + certificate.getIssuerX500Principal() +
179180
"\n" + Hexdump.toHexdump(id.getIssuerNameHash()));
180181

181182
// 2) Same authority key?
@@ -185,7 +186,7 @@ private void handleMonitor(final PVAChannel channel, final BitSet changes, final
185186
"\ndiffers from expected\n" + Hexdump.toHexdump(authority_key_id));
186187
continue;
187188
}
188-
logger.log(Level.FINER, () -> "OCSP authority key\n" + Hexdump.toHexdump(id.getIssuerKeyHash()));
189+
logger.log(Level.FINER, () -> "OCSP matches authority key\n" + Hexdump.toHexdump(id.getIssuerKeyHash()));
189190

190191
// 3) Same serial number?
191192
if (! id.getSerialNumber().equals(certificate.getSerialNumber()))
@@ -194,18 +195,19 @@ private void handleMonitor(final PVAChannel channel, final BitSet changes, final
194195
" differs from expected 0x" + certificate.getSerialNumber().toString(16));
195196
continue;
196197
}
197-
logger.log(Level.FINER, () -> "OCSP Serial: 0x" + id.getSerialNumber().toString(16));
198+
logger.log(Level.FINER, () -> "OCSP matches serial 0x" + id.getSerialNumber().toString(16));
198199

199200
// Response seems applicable to the certificate we want to check!
200201

201202
// Is covered time range from <= now <= until? 'until' may be null...
202-
final Date now = new Date(), from = response.getThisUpdate(), until = response.getNextUpdate();
203+
final Date from = response.getThisUpdate(), until = response.getNextUpdate();
203204
if (from.after(now) || (until != null && now.after(until)))
204205
{
205206
logger.log(Level.FINER, () -> "Applicable time range " + from + " to " + until +
206207
" does not include now, " + now);
207208
continue;
208209
}
210+
logger.log(Level.FINER, () -> "OCSP applicable from " + from + " to " + until);
209211

210212
// What is the status? OCSP only indicates null for valid, RevokedStatus with revocation date, or UnknownStatus.
211213
// Use that to potentially correct the more detailed status from the enum
@@ -222,12 +224,12 @@ else if (response_status instanceof RevokedStatus revoked)
222224
logger.log(Level.FINER, "OCSP status is REVOKED as of " + revoked.getRevocationTime());
223225
status = "REVOKED";
224226
ocsp_confirmation = true;
227+
break;
225228
}
226229
else
227230
{ // Allow PENDING etc. but correct VALID
228231
logger.log(Level.FINER, "OCSP status is UNKNOWN");
229-
if ("VALID".equals(status))
230-
status = "UNKNOWN";
232+
// No ocsp_confirmation, look for better response or fall through to UNKNOWN
231233
}
232234
}
233235

@@ -252,7 +254,7 @@ else if (response_status instanceof RevokedStatus revoked)
252254
void close()
253255
{
254256
if (! listeners.isEmpty())
255-
throw new IllegalStateException(getPVName() + " is still in use");
257+
throw new IllegalStateException("CertificateStatus(" + getPVName() + ") is still in use");
256258
pv.close();
257259
}
258260

0 commit comments

Comments
 (0)