Attention is currently required from: Arne Schwabe, Name of user not set 
#1000061.

Ralf Lici has posted comments on this change by Arne Schwabe. ( 
https://gerrit.openvpn.net/c/openvpn/+/2037?usp=email )

Change subject: Add python scripts that demonstrate the ACC protocol
......................................................................


Patch Set 4:

(1 comment)

Patchset:

PS4:
Pasting here Sashiko's findings (the AI bot accidentally picked this patch for 
review):

```
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) 
to consider:
- [High] sample/management: undefined DpcConnectedClient in 
client_event_REAUTH()
- [Medium] sample/management: unhandled OSError from os.getlogin() in 
send_info_response()
- [Medium] sample/management: leaked child process on timeout in get_routes()
- [Low] sample/management: unused socket import and truncated comment in client 
demo
--

commit 59f0e39cb91ec113a14b2f7981e12a71495246d9
Author: Arne Schwabe (Code Review) via Openvpn-devel 
<[email protected]>

Change in openvpn[master]: Add python scripts that demonstrate the ACC protocol

This commit adds client and server Python demonstration scripts for the
OpenVPN management interface that implement the sys_info app custom control
(ACC) protocol to query client system details from the server.

> diff --git a/sample/management/acc_sysinfo_client_demo.py 
> b/sample/management/acc_sysinfo_client_demo.py
> new file mode 100755
> index 0000000000000..99e994e6fd3f1
> --- /dev/null
> +++ b/sample/management/acc_sysinfo_client_demo.py
> @@ -0,0 +1,150 @@

[ ... ]

> +import os
> +import platform
> +import socket
> +import subprocess
> +from asyncio import CancelledError

[ ... ]

> +class OmiSysInfoClientProtocol(OMIClientProtocol):
> +    def __init__(self, finish_future, connect_data: ConnectData):
> +        super().__init__(finish_future, connect_data)
> +
> +
> +    def receive_acc_sys_info(self, acc_message):
> +        print(f"Received sys_info message: {acc_message!r}")
> +
> +        logger.debug(f"Received sys_info message: {acc_message!r}")
> +        msg = json.loads(acc_message)
> +
> +        asyncio.create_task(self.send_info_response(msg))
> +
> +    async def send_info_response(self, msg):
> +        response = {}
> +        if msg.get("uname", False):
> +            response['uname'] = platform.uname()._asdict()
> +
> +        if msg.get("username", False):
> +            response['username'] = os.getlogin()

[Severity: Medium]
When OpenVPN spawns acc_sysinfo_client_demo.py via --management ...
unix-script or runs in a daemon, service, or container environment without a
controlling terminal, won't os.getlogin() in
OmiSysInfoClientProtocol.send_info_response() raise an unhandled OSError?

Because OmiSysInfoClientProtocol.receive_acc_sys_info() schedules
send_info_response() as a background task via asyncio.create_task(), an
uncaught OSError aborts the coroutine before self.send_acc_msg() is reached,
preventing the client from sending any sys_info response back to the server
whenever username is requested.

Would catching OSError or falling back to getpass.getuser() avoid aborting
the response task?

> +
> +        if msg.get("hostname", False):
> +            response['hostname'] = platform.node()
> +
> +        if msg.get("dns-google.com", False):
> +            try:
> +                loop = asyncio.get_running_loop()
> +                # getaddrinfo is a blocking call. This is okay for the demo
> +                # here but
> +                addrs = [x[4][0] for x in await 
> loop.getaddrinfo('google.com', 443)]

[Severity: Low]
This isn't a bug, but the comment in
OmiSysInfoClientProtocol.send_info_response() is cut off mid-sentence and
describes a blocking getaddrinfo call right above await loop.getaddrinfo(),
while the socket module imported at the top of the file is unused. Should the
unused import be removed and the comment completed or updated?

> +                response["dns-google.com"] = addrs
> +
> +            except Exception as e:
> +                logger.error(f"Error resolving DNS for google.com: {e}", 
> exc_info=True)
> +                response["dns-google.com"] = None
> +
> +        if msg.get("route", False):
> +            response['route'] = await self.get_routes(False)
> +
> +        if msg.get("route6", False):
> +            response['route6'] = await self.get_routes(True)
> +
> +        msg = json.dumps(response).encode()
> +
> +        await self.send_acc_msg("sys_info", msg)
> +
> +    async def get_routes(self, v6):

[ ... ]

> +        proc = await asyncio.subprocess.create_subprocess_exec(cmd, *args, 
> stdout=subprocess.PIPE)
> +        try:
> +            output, _ = await asyncio.wait_for(proc.communicate(), 
> timeout=15)
> +        except asyncio.TimeoutError:
> +            return "Timeout while waiting for command output"
> +        return output.decode()

[Severity: Medium]
If the route command in OmiSysInfoClientProtocol.get_routes() exceeds the
15-second timeout, asyncio.wait_for() cancels proc.communicate(), but does
returning immediately from the asyncio.TimeoutError handler leak the running
child process proc and its stdout pipe without calling proc.kill() and
awaiting proc.wait()?

Also, if the hardcoded binary path (/usr/sbin/ip or netstat) does not exist
on the client host, create_subprocess_exec() will raise an uncaught
FileNotFoundError that aborts OmiSysInfoClientProtocol.send_info_response().

> diff --git a/sample/management/acc_sysinfo_server_demo.py 
> b/sample/management/acc_sysinfo_server_demo.py
> new file mode 100755
> index 0000000000000..a2ab0c1b05a92
> --- /dev/null
> +++ b/sample/management/acc_sysinfo_server_demo.py
> @@ -0,0 +1,122 @@

[ ... ]

> +class SysInfoConnectedClient(ConnectedClient):
> +    # Remember the key-id that we authenticated
> +    authenticated_kid = None
> +
> +class OMISysInfoServerProtocol(OMIServerProtocol):
> +    def __init__(self, finish_future, connect_data: ConnectData = None):
> +        super().__init__(finish_future, connect_data)
> +        self._connected_client_class = SysInfoConnectedClient
> +
> +    def client_event_ESTABLISHED(self, client, kid, env, extra):
> +        print(f"CLient connected: {client}")
> +
> +        kid = client.authenticated_kid
> +        asyncio.create_task(self._send_sys_info_command(client, kid))
> +
> +    def client_event_CONNECT(self, client, kid, env, extra):
> +        print(f"Authenticating client {client.cid}, {kid}")
> +        self.queue_command(f"client-auth-nt {client.cid} {kid}")
> +        client.authenticated_kid = kid
> +
> +    def client_event_REAUTH(self, client: DpcConnectedClient, kid: int, env: 
> dict, extra: str):
> +        print(f"Re-authenticating client {client} on re-negotiation")
> +        _ = self.queue_command(f"client-auth-nt {client.cid} {kid}")

[Severity: High]
When acc_sysinfo_server_demo.py is executed, Python evaluates the parameter
annotations of OMISysInfoServerProtocol.client_event_REAUTH() at class
definition time. Because the script defines SysInfoConnectedClient rather
than DpcConnectedClient, doesn't this immediately crash on startup with
NameError: name 'DpcConnectedClient' is not defined?

In addition, when a client renegotiates its key in client_event_REAUTH(),
should client.authenticated_kid also be updated to kid, matching
OMISysInfoServerProtocol.client_event_CONNECT()?

--
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/0e153ba9c81e52ff9debee73e09f2dd317817c81-emailreplacepatchset-h...@gerrit.openvpn.net?part=1
```



--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2037?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I695967524bb9e83887b8c07d0d09baff6e41acf4
Gerrit-Change-Number: 2037
Gerrit-PatchSet: 4
Gerrit-Owner: Arne Schwabe <[email protected]>
Gerrit-CC: Name of user not set #1000061
Gerrit-CC: Ralf Lici <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Name of user not set #1000061
Gerrit-Attention: Arne Schwabe <[email protected]>
Gerrit-Comment-Date: Tue, 03 Nov 2026 15:47:56 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to