Last active
August 31, 2022 22:14
-
-
Save marcellourbani/dd9f92fc5ec1e22ba24ac7d2585a3bed to your computer and use it in GitHub Desktop.
Automated OTP responder based on fish shell - maybe not a great idea but convenient :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/fish | |
while true | |
set resp (inotifywait /run/systemd/ask-password -e moved_to) | |
set file = (string split ' ' $resp) | |
set pfile "/run/systemd/ask-password/$file[4]" | |
if grep "$CHALLENGE_KEY" $pfile >/dev/null | |
set socket (grep -i socket $pfile | sed s/socket=//i) | |
set ticket (oathtool -b --totp "$OTP_KEY") | |
echo socket "$socket" | |
echo "$ticket" | /lib/systemd/systemd-reply-password 1 "$socket" | |
echo code sent | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=OTP responder | |
[Service] | |
Type=simple | |
Environment=CHALLENGE_KEY=mychallengekey | |
Environment=OTP_KEY=myotpkey | |
ExecStart=/usr/local/bin/otpresponder | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment