diff options
Diffstat (limited to 'openvpn_otp.py')
| -rwxr-xr-x | openvpn_otp.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/openvpn_otp.py b/openvpn_otp.py new file mode 100755 index 0000000..321e69e --- /dev/null +++ b/openvpn_otp.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 + +"""OpenVPN wrapper with OTP authentication.""" + +import os +import sys +from pathlib import Path + +import mintotp +import pexpect + + +def main(): + """Entrypoint.""" + child = pexpect.spawn(f"openvpn --config {os.environ['OPENVPN_CONFIG_FILE']}") + child.logfile = sys.stdout.buffer + child.expect("CHALLENGE: Verification code:") + child.sendline( + mintotp.totp(Path(os.environ["OPENVPN_OTP_SECRET_FILE"]).read_text()) + ) + # macos - python script: pexpect hangs on child.wait()? - Stack Overflow + # https://stackoverflow.com/questions/58751357/python-script-pexpect-hangs-on-child-wait + while True: + try: + child.read_nonblocking() + except Exception: + break + if child.isalive(): + child.wait() + + +if __name__ == "__main__": + main() |
