Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python-module-privacyidea-pam
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Eugene Omelyanovich
python-module-privacyidea-pam
Commits
3cfa8da6
Commit
3cfa8da6
authored
Mar 02, 2016
by
Brandon Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor expecting to allow other commands to work
parent
df572d31
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
17 deletions
+38
-17
ssh-u2f.py
ssh-u2f.py
+38
-17
No files found.
ssh-u2f.py
View file @
3cfa8da6
...
...
@@ -32,31 +32,52 @@ except:
ssh
=
pexpect
.
spawn
(
command
or
"ssh"
,
sys
.
argv
[
1
:])
winch_handler
(
None
,
None
)
index
=
-
1
pattern_list
=
ssh
.
compile_pattern_list
([
"Enter additional factors:.*"
,
"----- BEGIN U2F CHALLENGE -----
\r
?
\n
([^
\r\n
]*)
\r
?
\n
(.*)
\r
?
\n
----- END U2F CHALLENGE -----"
,
"Welcome.*"
,
pexpect
.
EOF
])
def
passthrough
():
print
()
sys
.
stdout
.
write
(
ssh
.
match
.
group
())
try
:
ssh
.
interact
()
except
UnboundLocalError
:
# Work around bug in pexpect 3.1
pass
sys
.
exit
(
0
)
index
=
ssh
.
expect
([
"Authenticated with partial success."
,
"[^
\r\n
]+"
,
pexpect
.
EOF
])
if
index
==
0
:
print
(
ssh
.
match
.
group
())
elif
index
==
1
:
passthrough
()
elif
index
==
2
:
sys
.
exit
(
0
)
while
True
:
index
=
ssh
.
expect_list
(
pattern_list
)
index
=
ssh
.
expect
([
"Enter additional factors: "
,
"----- BEGIN U2F CHALLENGE -----
\r\n
"
,
"[^
\r\n
]+"
,
pexpect
.
EOF
])
if
index
==
0
:
try
:
pin
=
getpass
.
getpass
(
ssh
.
match
.
group
())
except
EOFError
:
pin
=
""
ssh
.
sendline
(
pin
.
strip
())
elif
index
==
1
:
p
=
subprocess
.
Popen
([
"u2f-host"
,
"-aauthenticate"
,
"-o"
,
ssh
.
match
.
group
(
1
)],
u2f_origin
=
ssh
.
readline
()
.
strip
()
u2f_challenge
=
ssh
.
readline
()
.
strip
()
ssh
.
expect
(
"----- END U2F CHALLENGE -----"
)
p
=
subprocess
.
Popen
([
"u2f-host"
,
"-aauthenticate"
,
"-o"
,
u2f_origin
],
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
)
out
,
err
=
p
.
communicate
(
ssh
.
match
.
group
(
2
)
)
out
,
err
=
p
.
communicate
(
u2f_challenge
)
p
.
wait
()
ssh
.
sendline
(
out
.
strip
())
else
:
break
if
index
==
3
:
sys
.
exit
(
0
)
sys
.
stdout
.
write
(
ssh
.
match
.
group
())
ssh
.
interact
(
)
elif
index
==
2
:
passthrough
()
elif
index
==
3
:
sys
.
exit
(
0
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment