Open jkroepke opened 4 years ago
I believe this is related to the other issue you opened about client notifications. After server-initiated event support lands you should be able to register a callback for the >PASSWORD
event which will do what you need. Currently not yet supported on the current code.
Thanks! I take a look at #14 (https://github.com/Jamie-/openvpn-api/pull/14/files#diff-4f82b16515cab347ce3c2b39f140bac4R85) and it wont be resolved, since there is a check for a >INFO
immediately. If a password is required, OpenVPN will ask for a password first and the script will throw an assert error.
See: https://github.com/jkroepke/openvpn_aad_authenticator/blob/380cf4d93d78533393b9e76ac55d6c0f99520d82/openvpn/__init__.py#L64-L72 for a better understanding.
Oh nice spot. Thanks for that info! In that case I shall re-open this to track and that needs fixing.
Can you please add password support?
Thanks!
def connect(self) -> Optional[bool]:
"""Connect to management interface socket.
"""
try:
if self.type == VPNType.IP:
assert self._mgmt_host is not None and self._mgmt_port is not None
self._socket = socket.create_connection((self._mgmt_host, self._mgmt_port), timeout=3)
elif self.type == VPNType.UNIX_SOCKET:
assert self._mgmt_socket is not None
self._socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self._socket.connect(self._mgmt_socket)
else:
raise ValueError("Invalid connection type")
resp = self._socket_recv()
print(resp)
if self._password != None:
if resp.startswith("ENTER PASSWORD:"):
self._socket_send(self._password+'\n')
resp = self._socket_recv()
print(resp)
if resp.startswith("ENTER PASSWORD:"):
raise errors.ConnectError('Incorrect Password')
if resp.startswith("SUCCESS:"):
return True
else:
raise errors.ConnectError('Login did not return success', resp)
assert resp.startswith(">INFO"), "Did not get expected response from interface when opening socket."
return True
except (socket.timeout, socket.error) as e:
raise errors.ConnectError(str(e)) from None
Made a small change to allow for passwords, it could be improved.
Hi
how I could enter a password if the management interface require a password?