Skip to content

Commit 8ca6235

Browse files
authored
Merge pull request #3618 from ControlSystemStudio/pva_srv_check_client_cert
PVS Server: Check CERT:STATUS:... of client
2 parents 2d1b91b + 7118866 commit 8ca6235

35 files changed

+930
-268
lines changed

core/pva/.classpath

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
<classpathentry kind="src" path="src/test/java"/>
77
<classpathentry kind="src" path="src/test/resources"/>
88
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
9+
<classpathentry combineaccessrules="false" kind="src" path="/phoebus-target"/>
910
<classpathentry kind="output" path="target/classes"/>
1011
</classpath>

core/pva/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@
2020
<version>1.3</version>
2121
<scope>test</scope>
2222
</dependency>
23+
24+
<!-- bouncycastle library used in PVA to decode and check OCSP confirmation of certificates
25+
bcpkix depends on bcutil, which depends on bcprov
26+
-->
27+
<dependency>
28+
<groupId>org.bouncycastle</groupId>
29+
<artifactId>bcpkix-jdk18on</artifactId>
30+
<version>1.82</version>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.bouncycastle</groupId>
34+
<artifactId>bcutil-jdk18on</artifactId>
35+
<version>1.82</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.bouncycastle</groupId>
39+
<artifactId>bcprov-jdk18on</artifactId>
40+
<version>1.82</version>
41+
</dependency>
42+
2343
</dependencies>
2444

2545
<build>

core/pva/serverdemo

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
#!/bin/sh
1+
#!/bin/bash
2+
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`
27

38
JAR=`echo target/core-pva*.jar`
49
if [ -r "$JAR" ]
510
then
6-
# Echo use jar file
7-
java -cp $JAR org.epics.pva.server.ServerDemo
11+
# Use jar
12+
java -cp $LIB:$JAR org.epics.pva.server.ServerDemo "$@"
813
else
9-
# Use build output
10-
java -cp target/classes org.epics.pva.server.ServerDemo
14+
# Use IDE build output
15+
java -cp $LIB:target/classes org.epics.pva.server.ServerDemo "$@"
1116
fi
17+

core/pva/src/main/java/org/epics/pva/PVASettings.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019-2023 Oak Ridge National Laboratory.
2+
* Copyright (c) 2019-2025 Oak Ridge National Laboratory.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -18,10 +18,19 @@
1818
*
1919
* @author Kay Kasemir
2020
*/
21-
@SuppressWarnings("nls")
2221
public class PVASettings
2322
{
24-
/** Common logger */
23+
/** Common logger
24+
*
25+
* Usage of levels:
26+
* <ul>
27+
* <li>INFO - Not used?
28+
* <li>CONFIG - Log value of configuration settings
29+
* <li>FINE - Log Search, reply, connection, auth, put/get/monitor
30+
* <li>FINER - Log detail of sockets, messages
31+
* <li>FINEST - Hexdump of each packet
32+
* </ul>
33+
*/
2534
public static final Logger logger = Logger.getLogger(PVASettings.class.getPackage().getName());
2635

2736
/** Address list.

core/pva/src/main/java/org/epics/pva/client/ChannelSearch.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.epics.pva.common.AddressInfo;
3030
import org.epics.pva.common.RequestEncoder;
3131
import org.epics.pva.common.SearchRequest;
32-
import org.epics.pva.data.Hexdump;
3332
import org.epics.pva.data.PVAString;
3433

3534
/** Handler for search requests
@@ -65,7 +64,6 @@
6564
*
6665
* @author Kay Kasemir
6766
*/
68-
@SuppressWarnings("nls")
6967
class ChannelSearch
7068
{
7169
/** Basic search period is one second */
@@ -352,6 +350,8 @@ private void runSearches()
352350
synchronized (this)
353351
{
354352
final Set<SearchedChannel> bucket = search_buckets.get(current);
353+
if (bucket.isEmpty())
354+
return;
355355
logger.log(Level.FINEST, () -> "Search bucket " + current);
356356

357357
// Remove searched channels from the current bucket
@@ -518,7 +518,7 @@ private void sendSearch(final int seq, final Collection<SearchRequest.Channel> c
518518
try
519519
{
520520
logger.log(Level.FINER, () -> "Sending search to UDP " + addr + " (unicast), " +
521-
"response addr " + response + "\n" + Hexdump.toHexdump(send_buffer));
521+
"response addr " + response);
522522
udp.send(send_buffer, addr);
523523
}
524524
catch (Exception ex)
@@ -536,7 +536,7 @@ private void sendSearch(final int seq, final Collection<SearchRequest.Channel> c
536536
try
537537
{
538538
logger.log(Level.FINER, () -> "Sending search to UDP " + addr + " (broadcast/multicast), " +
539-
"response addr " + response + "\n" + Hexdump.toHexdump(send_buffer));
539+
"response addr " + response);
540540
udp.send(send_buffer, addr);
541541
}
542542
catch (Exception ex)

core/pva/src/main/java/org/epics/pva/client/ClientAuthentication.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019-2023 Oak Ridge National Laboratory.
2+
* Copyright (c) 2019-2025 Oak Ridge National Laboratory.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -23,7 +23,6 @@
2323
/** PVA Client authentication modes
2424
* @author Kay Kasemir
2525
*/
26-
@SuppressWarnings("nls")
2726
abstract class ClientAuthentication
2827
{
2928
/** @param buffer Buffer to which client's authentication info is added
@@ -41,15 +40,15 @@ abstract class ClientAuthentication
4140
@Override
4241
public void encode(final ByteBuffer buffer) throws Exception
4342
{
44-
PVAString.encodeString(PVAAuth.X509, buffer);
43+
PVAString.encodeString(PVAAuth.x509.name(), buffer);
4544
// No detail because server already has name
4645
buffer.put(PVAFieldDesc.NULL_TYPE_CODE);
4746
}
4847

4948
@Override
5049
public String toString()
5150
{
52-
return PVAAuth.X509;
51+
return PVAAuth.x509.name();
5352
}
5453
};
5554

@@ -60,15 +59,15 @@ public String toString()
6059
@Override
6160
public void encode(final ByteBuffer buffer) throws Exception
6261
{
63-
PVAString.encodeString(PVAAuth.ANONYMOUS, buffer);
62+
PVAString.encodeString(PVAAuth.anonymous.name(), buffer);
6463
// No detail because we're anonymous
6564
buffer.put(PVAFieldDesc.NULL_TYPE_CODE);
6665
}
6766

6867
@Override
6968
public String toString()
7069
{
71-
return PVAAuth.ANONYMOUS;
70+
return PVAAuth.anonymous.name();
7271
}
7372
};
7473

@@ -102,7 +101,7 @@ private static class CAAuthentication extends ClientAuthentication
102101
@Override
103102
public void encode(final ByteBuffer buffer) throws Exception
104103
{
105-
PVAString.encodeString(PVAAuth.CA, buffer);
104+
PVAString.encodeString(PVAAuth.ca.name(), buffer);
106105
// Send identity detail
107106
identity.encodeType(buffer, new BitSet());
108107
identity.encode(buffer);
@@ -111,7 +110,7 @@ public void encode(final ByteBuffer buffer) throws Exception
111110
@Override
112111
public String toString()
113112
{
114-
return "ca(" + user + "@" + host + ")";
113+
return PVAAuth.ca.name() + "(" + user + "@" + host + ")";
115114
}
116115
}
117116
}

core/pva/src/main/java/org/epics/pva/client/ClientTCPHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
*
4040
* @author Kay Kasemir
4141
*/
42-
@SuppressWarnings("nls")
4342
class ClientTCPHandler extends TCPHandler
4443
{
4544
private static final CommandHandlers<ClientTCPHandler> handlers =
@@ -112,7 +111,7 @@ class ClientTCPHandler extends TCPHandler
112111
public ClientTCPHandler(final PVAClient client, final InetSocketAddress address, final Guid guid, final boolean tls) throws Exception
113112
{
114113
super(true);
115-
logger.log(Level.FINE, () -> "TCPHandler " + (tls ? "(TLS) " : "") + guid + " for " + address + " created ============================");
114+
logger.log(Level.FINER, () -> "TCPHandler " + (tls ? "(TLS) " : "") + guid + " for " + address + " created ============================");
116115
this.server_address = address;
117116
this.tls = tls;
118117
this.client = client;

core/pva/src/main/java/org/epics/pva/client/ClientUDPHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
/** Sends and receives search replies, monitors beacons
3838
* @author Kay Kasemir
3939
*/
40-
@SuppressWarnings("nls")
4140
class ClientUDPHandler extends UDPHandler
4241
{
4342
@FunctionalInterface
@@ -122,7 +121,7 @@ public ClientUDPHandler(final BeaconHandler beacon_handler,
122121
ipV6Msg = "";
123122
}
124123
String logMsg = String.format("Awaiting search replies on UDP %s%s and beacons on %s", udp_localaddr4, ipV6Msg, Network.getLocalAddress(udp_beacon));
125-
logger.log(Level.FINE, logMsg);
124+
logger.log(Level.CONFIG, logMsg);
126125
}
127126

128127
/** @param target Address to which message will be sent
@@ -135,6 +134,7 @@ InetSocketAddress getResponseAddress(final AddressInfo target)
135134

136135
public void send(final ByteBuffer buffer, final AddressInfo info) throws Exception
137136
{
137+
logger.log(Level.FINEST, () -> "Sending UDP to " + info.getAddress() + "\n" + Hexdump.toHexdump(buffer));
138138
// synchronized (udp_search)?
139139
// Not necessary based on Javadoc for send(),
140140
// but in case we set the multicast IF & TTL

core/pva/src/main/java/org/epics/pva/client/EchoHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
/** Handle a server's ECHO reply
2121
* @author Kay Kasemir
2222
*/
23-
@SuppressWarnings("nls")
2423
class EchoHandler implements CommandHandler<ClientTCPHandler>
2524
{
2625
@Override
@@ -39,10 +38,10 @@ public void handleCommand(final ClientTCPHandler tcp, final ByteBuffer buffer) t
3938
buffer.get(payload);
4039
final String expected = tcp.getActiveEchoRequest();
4140
if (Arrays.equals(payload, expected.getBytes()))
42-
logger.log(Level.FINE, () -> "Received ECHO:\n" + Hexdump.toHexdump(payload));
41+
logger.log(Level.FINE, () -> "Received ECHO '" + expected + "'");
4342
else
4443
{
45-
logger.log(Level.WARNING, this + " received invalid echo reply, expected " + expected + ":\n" +
44+
logger.log(Level.WARNING, this + " received invalid echo reply, expected '" + expected + "':\n" +
4645
Hexdump.toHexdump(payload));
4746
return;
4847
}

core/pva/src/main/java/org/epics/pva/client/EchoRequest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
/** Send a 'ECHO' request to server
2020
* @author Kay Kasemir
2121
*/
22-
@SuppressWarnings("nls")
2322
class EchoRequest implements RequestEncoder
2423
{
2524
// Random number so replies don't all start with 'echo00'
@@ -40,7 +39,7 @@ public void encodeRequest(final byte version, final ByteBuffer buffer) throws Ex
4039
final int count = counter.incrementAndGet();
4140
active_check = String.format("echo%02d", count % 100);
4241
final byte[] check = active_check.getBytes();
43-
logger.log(Level.FINE, () -> "Sending ECHO request (Version " + version + ")");
42+
logger.log(Level.FINE, () -> "Sending ECHO request (Version " + version + " '" + active_check + "')");
4443
PVAHeader.encodeMessageHeader(buffer, PVAHeader.FLAG_NONE, PVAHeader.CMD_ECHO, check.length);
4544
buffer.put(check);
4645
}

0 commit comments

Comments
 (0)