2024-10-31 12:14:45 +00:00
|
|
|
{ pkgs, config, ... }:
|
|
|
|
let
|
|
|
|
sshotp = pkgs.writeScriptBin "sshotp"
|
|
|
|
''
|
|
|
|
#!/usr/bin/env expect
|
|
|
|
set stty_init -echo
|
|
|
|
set timeout 300
|
|
|
|
set totp [lindex $argv 0];
|
|
|
|
puts "Our TOTP $totp"
|
|
|
|
spawn ssh -D 20000 dresden.uio.no
|
|
|
|
expect {
|
|
|
|
-re {.*(Verification_Code):} {
|
|
|
|
send -- "$totp\r"
|
|
|
|
exp_continue
|
|
|
|
}
|
|
|
|
-re {.*dresden.*} {
|
|
|
|
wait
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
ssh-dresden = pkgs.writeShellApplication {
|
|
|
|
name = "ssh-dresden";
|
|
|
|
runtimeInputs = [ pkgs.rbw pkgs.expect ];
|
|
|
|
text = ''
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
totp=$(rbw get -f "TOTP" rlogin)
|
|
|
|
expect -f ${sshotp}/bin/sshotp "$totp"
|
|
|
|
'';
|
2024-03-20 14:15:46 +00:00
|
|
|
|
2024-10-31 12:14:45 +00:00
|
|
|
};
|
2024-03-20 14:15:46 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
systemd.user.services.ssh-office = {
|
2024-10-31 12:14:45 +00:00
|
|
|
Unit = {
|
2024-03-20 14:15:46 +00:00
|
|
|
Description = "Office ssh session";
|
|
|
|
};
|
|
|
|
Service = {
|
|
|
|
Type = "simple";
|
|
|
|
ExecStart = "${ssh-dresden}/bin/ssh-dresden";
|
2024-10-31 12:14:45 +00:00
|
|
|
Restart = "never";
|
2024-03-20 14:15:46 +00:00
|
|
|
};
|
|
|
|
};
|
2024-10-31 12:14:45 +00:00
|
|
|
}
|
|
|
|
|