Arne Schwabe has uploaded a new patch set (#2). ( https://gerrit.openvpn.net/c/openvpn/+/1860?usp=email )
Change subject: Add python scripts that demonstrate using the dpc1 ACC protocol ...................................................................... Add python scripts that demonstrate using the dpc1 ACC protocol The dpc1 protocol is used by the OpenVPN Connect clients and OpenVPN Connexa. Change-Id: Ie20289737d502a25eedc60677d3c350ddc3b3c22 Signed-off-by: Arne Schwabe <[email protected]> --- A sample/management/acc_dpc1_client_demo.py A sample/management/acc_dpc1_server_demo.py 2 files changed, 248 insertions(+), 0 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/60/1860/2 diff --git a/sample/management/acc_dpc1_client_demo.py b/sample/management/acc_dpc1_client_demo.py new file mode 100755 index 0000000..abe1617 --- /dev/null +++ b/sample/management/acc_dpc1_client_demo.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python3 +# Copyright (c) 2026 OpenVPN Inc <[email protected]> +# Copyright (c) 2026 Arne Schwabe <[email protected]> +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, see <https://www.gnu.org/licenses/>. +import asyncio +import base64 +import json +import logging +import platform + +from omi import OmiProtocol +from omi_tools import run_main, start_management_protocol, ConnectData + +logger = logging.getLogger(__name__) + +class OmiAccProtocol(OmiProtocol): + def __init__(self, finish_future, connect_data:ConnectData): + super().__init__(finish_future, connect_data) + self.accmsg = "" + + def recv_notify_ACC(self, args): + # dpc1,0,eyJkcGNfcmVx[...] + protocol, fragment, b64msg = args.split(",", 2) + if protocol != "dpc1": + logger.info(f"Received unknown ACC protocol: {protocol}") + return + + msg = base64.decodebytes(b64msg.encode()) + self.accmsg += msg.decode() + + # Message is not yet complete. Wait for more fragments. + if fragment != "0": + return + + self.parseDpc1(self.accmsg) + self.accmsg = "" + + def parseDpc1(self, accmsg): + msg = json.loads(accmsg) + + logger.error(f"Received sys_info message: {accmsg}") + + dpc_request = msg["dpc_request"] + ver = dpc_request["ver"] + if ver != "1.0": + logger.error(f"Received unknown ACC protocol version: {ver}") + return + + client_info = dpc_request.get("client_info", False) + antivirus = "antivirus" in dpc_request + disk_encryption = "disk_encryption" in dpc_request + + logger.info(f"Received DPC1 request: antivirus={antivirus}, disk_encryption={disk_encryption}, client_info={client_info}") + + if client_info: + self._sendDPC1ClientInfo() + + def _sendDPC1ClientInfo(self): + system = platform.system() + if system == "Darwin": + system = "MacOS" + + response = { + "dpc_response": { + "ver": "1.0", + "client_info": { + "os": { + "type": system, + "version": platform.release(), + "extra": + { + "arch": platform.machine(), + } + } + } + } + } + + b64msg = base64.b64encode(json.dumps(response).encode()).decode() + + command = f"acc-msg\ndpc1\n6\n{b64msg}\nEND" + self.queue_command(command) + +async def main(connect_data:ConnectData): + transport, protocol, finish_future = await start_management_protocol(connect_data, OmiAccProtocol) + + management_version = await protocol.management_ready() + print(f"Management interface version: {management_version}") + + await protocol.set_bytecount_interval(5) + + await finish_future + + +if __name__ == '__main__': + run_main(main) \ No newline at end of file diff --git a/sample/management/acc_dpc1_server_demo.py b/sample/management/acc_dpc1_server_demo.py new file mode 100644 index 0000000..69b199e --- /dev/null +++ b/sample/management/acc_dpc1_server_demo.py @@ -0,0 +1,131 @@ +#!/usr/bin/env python3 +# Copyright (c) 2026 OpenVPN Inc <[email protected]> +# Copyright (c) 2026 Arne Schwabe <[email protected]> +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, see <https://www.gnu.org/licenses/>. +import asyncio +import json +import logging +from pprint import pprint + +logging.basicConfig() + +from omi_server_protocol import OMIServerProtocol, ConnectedClient +from omi_tools import start_management_protocol, ConnectData + +logger = logging.getLogger(__name__) + + +class DpcConnectedClient(ConnectedClient): + # Remember the key-id that we authenticated + dpc_completed = False + + +class OmiDPCServerProtocol(OMIServerProtocol): + def __init__(self, finish_future, connect_data: ConnectData = None): + super().__init__(finish_future, connect_data) + self._connected_client_class = DpcConnectedClient + + def receive_acc_client_dpc1(self, client: DpcConnectedClient, kid, accmsg): + print(f"Received DPC1 message: {accmsg!r}") + msg = json.loads(accmsg) + pprint(msg) + + dpc_response = msg["dpc_response"] + ver = dpc_response["ver"] + if ver != "1.0": + logger.error(f"Received unknown ACC protocol version: {ver}") + return + + client_info = dpc_response.get("client_info", {}) + antivirus = "antivirus" in dpc_response + disk_encryption = "disk_encryption" in dpc_response + + logger.info( + f"Received DPC1 response: antivirus={antivirus}, disk_encryption={disk_encryption}, client_info={client_info}") + + # Normally here would be a check that the response matches the policy + # this demo script just allows everyone with a response to pass + client.dpc_completed = True + + self.queue_command(f"client-auth-nt {client.cid} {kid}") + + async def dpc_request_timeout(self, client, kid, timeout): + await asyncio.sleep(timeout) + if client.dpc_completed: + return + + client_deny = f'client-deny {client.cid} {kid} "dpc1 timeout" "Timeout on device posture"' + await self.queue_command(client_deny) + + + def client_event_ESTABLISHED(self, client, kid, env, extra): + print(f"CLient connected: {client}") + pprint(env) + + async def send_client_deny_no_dpc1(self, client: DpcConnectedClient, kid: int): + client_reason = "ACC[protocol dpc1]: To connect to this server you " \ + "need to upgrade to a client that supports the " \ + "OpenVPN Inc device posture protocol and has it " \ + "enabled, e.g. OpenVPN for Android, openvpn3-linux, " \ + "or OpenVPN Connect" + client_deny = f'client-deny {client.cid} {kid} "no dpc1 support" "{client_reason}"' + await self.queue_command(client_deny) + + def client_event_CONNECT(self, client, kid, env, extra): + print(f"Authenticating client {client}, {kid}, protos: {client.acc_negotiated_protocols}") + asyncio.create_task(self.check_client_posture(client, kid)) + + async def check_client_posture(self, client, kid): + await self.queue_command(f"client-pending-auth {client.cid} {kid} ACC 180") + + await asyncio.sleep(2) + if "dpc1" not in client.acc_negotiated_protocols: + await self.send_client_deny_no_dpc1(client, kid) + return + + dpc_cmd = {"dpc_request": {"ver": "1.0", "correlation_id": "n/a", "timestamp": "yesterday", "client_info": True, + "disk_encryption": {"full": True}, "antivirus": {}}} + + dpc_cmd_str = json.dumps(dpc_cmd) + acc_protocol = "dpc1" + + await self.send_acc_msg(client, kid, acc_protocol, dpc_cmd_str.encode()) + asyncio.create_task(self.dpc_request_timeout(client, kid, 60)) + + +async def main(connect_data: ConnectData): + transport, protocol, finish_future = await start_management_protocol(connect_data, OmiDPCServerProtocol) + + management_version = await protocol.management_ready() + print(f"Management interface version: {management_version}") + + await protocol.enable_log() + + await protocol.set_bytecount_interval(5) + + await finish_future + + +if __name__ == '__main__': + asyncio.run(main()) -- To view, visit https://gerrit.openvpn.net/c/openvpn/+/1860?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.openvpn.net/settings?usp=email Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ie20289737d502a25eedc60677d3c350ddc3b3c22 Gerrit-Change-Number: 1860 Gerrit-PatchSet: 2 Gerrit-Owner: Arne Schwabe <[email protected]> Gerrit-CC: openvpn-devel <[email protected]>
_______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
