Skip to content

Add XDG standard path auto-discovery for PVA TLS keychains#3782

Merged
kasemir merged 2 commits intoControlSystemStudio:masterfrom
george-mcintyre:feat/pva-xdg-keychain-discovery
Apr 15, 2026
Merged

Add XDG standard path auto-discovery for PVA TLS keychains#3782
kasemir merged 2 commits intoControlSystemStudio:masterfrom
george-mcintyre:feat/pva-xdg-keychain-discovery

Conversation

@george-mcintyre
Copy link
Copy Markdown
Contributor

Motivation

PVXS (the reference C++ PVA implementation) stores its keystores at the XDG standard location:

$XDG_CONFIG_HOME/pva/1.5/client.p12   (client keychain)
$XDG_CONFIG_HOME/pva/1.5/server.p12   (server keychain)

where $XDG_CONFIG_HOME defaults to ~/.config on Linux and the platform-appropriate equivalent on macOS/Windows.

The Java client had no equivalent discovery logic: EPICS_PVA_TLS_KEYCHAIN had to be set explicitly, making interoperability with a PVXS-configured system painful in development environments and CI.

Change

PVASettings now probes the XDG path for client.p12 / server.p12 at startup when EPICS_PVA_TLS_KEYCHAIN / EPICS_PVAS_TLS_KEYCHAIN are not explicitly set. If a keychain is found at the XDG location it is used automatically, matching PVXS behaviour and requiring zero configuration when the user has already set up PVXS.

Explicit env-var settings always take precedence; the XDG probe is only a fallback.

Files Changed

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

Copy link
Copy Markdown
Collaborator

@kasemir kasemir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, that might now work.
if (EPICS_PVAS_TLS_KEYCHAIN.isEmpty()), it auto-discovers. How do I disable TLS? With the C++ implementation, I understand you can

export  EPICS_PVAS_TLS_KEYCHAIN=""

so now it's defined but empty, and that disables TLS.

Right now it's a little hard to distinguish between not-defined and defined-as-empty....

When EPICS_PVA_TLS_KEYCHAIN or EPICS_PVAS_TLS_KEYCHAIN is explicitly set
to an empty string, TLS should be disabled -- matching PVXS behaviour where
'export EPICS_PVA_TLS_KEYCHAIN=""' is the documented way to force plain TCP.

Previously isEmpty() was the only guard, which conflated two distinct cases:
  1. Variable not defined at all  -> auto-discover from XDG path
  2. Variable explicitly set to "" -> user wants TLS disabled

Add isDefined() helper that checks both System.getProperty() and
System.getenv(). XDG discovery now only runs when the variable is
absent (case 1); an explicitly-blank value suppresses discovery (case 2).
Copy link
Copy Markdown
Contributor Author

@george-mcintyre george-mcintyre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks Kay. Fixed in a9d5e46 — added isDefined() which checks System.getProperty() and System.getenv() directly to distinguish "variable absent" from "variable explicitly set to empty".

The XDG auto-discovery now only runs when the variable is absent (not defined in env or as a Java property). Setting export EPICS_PVA_TLS_KEYCHAIN="" (or export EPICS_PVAS_TLS_KEYCHAIN="") explicitly to blank will suppress discovery and keep TLS disabled, matching the C++ behaviour you described.

@sonarqubecloud
Copy link
Copy Markdown

@kasemir kasemir merged commit 4e2897b into ControlSystemStudio:master Apr 15, 2026
4 checks passed
@george-mcintyre george-mcintyre deleted the feat/pva-xdg-keychain-discovery branch April 16, 2026 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants