pam_script method works, but requests password once before working.
My context is slightly different: no security key, but separate passwords for login and lockscreen. Relevant excerpt from my gdm-password file is:
auth [success=2 default=ignore] pam_script.so dir=/etc/pam.d/is-locked
auth [success=1 default=ignore] pam_unix.so nullok_secure nodelay
auth requisite pam_deny.so
auth [success=2 default=ignore] pam_script.so dir=/etc/pam.d/is-unlocked
auth [success=1 default=ignore] pam_userdb.so nodelay crypt=crypt db=/var/local/passwd
auth requisite pam_deny.so
Again, works fine, but first attempt to type password is ignored, no matter what it is. I'm a PAM newbie, so either there's a bug in my code, or pam_script.so is somehow triggering an extra password prompt.
(With apologies; don't have enough points to post as comment.)
[Note added: Yup; newbie error: try_first_pass is needed as argument to both pam_userdb.so and pam_unix.so so that originally-submitted password can be used. And the above code can be simplified so that only one script is needed.
Bottom line: pam_script does the job. Improved version below.]
auth [success=ignore default=1] pam_script.so dir=/etc/pam.d/is-locked
auth [success=2 default=ignore] pam_userdb.so nodelay try_first_pass crypt=crypt db=/var/local/sudopass
auth [success=1 default=ignore] pam_unix.so nullok_secure nodelay try_first_pass
auth requisite pam_deny.so