Skip to content

Commit

Permalink
authentication: add no pin for passkey and pin as Enter key
Browse files Browse the repository at this point in the history
Signed-off-by: Madhuri Upadhye <[email protected]>
  • Loading branch information
madhuriupadhye committed Sep 16, 2024
1 parent 0b213ff commit 5769377
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 16 deletions.
58 changes: 58 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 59 additions & 16 deletions sssd_test_framework/utils/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,8 @@ def password_expired(self, username: str, password: str, new_password: str) -> b
return result.rc == 0

def passkey_with_output(
self, username: str, *, pin: str | int, device: str, ioctl: str, script: str, command: str = "exit 0"
self, username: str, *, device: str, ioctl: str, script: str, pin: str | int | None = None,
interactive_prompt: str | None = None, touch_prompt: str | None = None, command: str = "exit 0"
) -> tuple[int, int, str, str]:
"""
Call ``su - $username`` and authenticate the user with passkey.
Expand Down Expand Up @@ -385,7 +386,6 @@ def passkey_with_output(
""",
mode="a=rx",
)

playback_umockdev = self.fs.mktmp(
rf"""
#!/bin/bash
Expand All @@ -398,7 +398,7 @@ def passkey_with_output(
""",
mode="a=rx",
)

import pdb; pdb.set_trace()
result = self.host.conn.expect(
rf"""
# Disable debug output
Expand All @@ -422,28 +422,73 @@ def passkey_with_output(
set timeout {DEFAULT_AUTHENTICATION_TIMEOUT}
set prompt "\n.*\[#\$>\] $"
set command "{command}"
if {{"{pin}" == "None"}} {{
$pin = ""
set pin "{pin}"
}}
if {{"{interactive_prompt}" != "None"}} {{
$interactive_prompt = "{interactive_prompt}"
}}
if {{"{touch_prompt}" != "None"}} {{
$touch_prompt = "{touch_prompt}"
}}
spawn "{playback_umockdev}"
expect {{
"Insert your passkey device, then press ENTER*" {{send -- "\n"}}
timeout {{exitmsg "Unexpected output" 201}}
eof {{exitmsg "Unexpected end of file" 202}}
if {{$interactive_prompt ne "None"}} {{
expect {{
"{interactive_prompt}*" {{ send -- "\n"}}
timeout {{exitmsg "Unexpected output" 201}}
eof {{exitmsg "Unexpected end of file" 202}}
}}
}} else {{
expect {{
"Insert your passkey device, then press ENTER*" {{send -- "\n"}}
timeout {{exitmsg "Unexpected output" 201}}
eof {{exitmsg "Unexpected end of file" 202}}
}}
}}
expect {{
"Enter PIN:*" {{send -- "{pin}\r"}}
timeout {{exitmsg "Unexpected output" 201}}
eof {{exitmsg "Unexpected end of file" 202}}
if {{$pin eq "\r"}} {{
expect {{
"Enter PIN:*" {{send -- "{pin}\r"}}
timeout {{exitmsg "Unexpected output" 201}}
eof {{exitmsg "Unexpected end of file" 202}}
}}
expect {{
"Password:*" {{send -- "Secret123\r"}}
timeout {{exitmsg "Unexpected output" 301}}
eof {{exitmsg "Unexpected end of file" 302}}
}}
}} elseif {{$pin ne ""}} {{
expect {{
"Enter PIN:*" {{send -- "{pin}\r"}}
timeout {{exitmsg "Unexpected output" 401}}
eof {{exitmsg "Unexpected end of file" 402}}
}}
}} elseif {{ $touch_prompt ne "None" }}
expect {{
"{touch_prompt}*" {{ send -- "\n"}}
eof {{exitmsg "Password authentication successful" 0}}
timeout {{exitmsg "Unexpected output" 501}}
}}
}} else {{
expect {{
"Authentication failure" {{exitmsg "Authentication failure" 1}}
eof {{exitmsg "Password authentication successful" 0}}
timeout {{exitmsg "Unexpected output" 601}}
}}
}}
expect {{
"Authentication failure" {{exitmsg "Authentication failure" 1}}
eof {{exitmsg "Password authentication successful" 0}}
timeout {{exitmsg "Unexpected output" 201}}
timeout {{exitmsg "Unexpected output" 701}}
}}
exitmsg "Unexpected code path" 203
exitmsg "Unexpected code path" 803
""",
verbose=False,
Expand All @@ -464,9 +509,7 @@ def passkey_with_output(

return result.rc, cmdrc, stdout, result.stderr

def passkey(
self, username: str, *, pin: str | int, device: str, ioctl: str, script: str, command: str = "exit 0"
) -> bool:
def passkey(self, username: str, *, device: str, ioctl: str, script: str, pin: str | int | None = None, command: str = "exit 0") -> bool:
"""
Call ``su - $username`` and authenticate the user with passkey.
Expand Down

0 comments on commit 5769377

Please sign in to comment.