Last active
November 19, 2015 07:01
-
-
Save Quentin-M/272d64faf0bc8533e131 to your computer and use it in GitHub Desktop.
Unlock 1Password with Yukikey in Challenge-Response mode
This file contains 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
-# Have 1Password Mini enabled | |
-# Configure Ubikey with the Challenge-Response mode (Slot 2 per defaut, change -2 by -1 to use Slot 1) | |
-# Get the response of /usr/bin/sudo /usr/local/bin/ykchalresp -2 *PIN_CODE* and set it as your 1Password master password | |
-# Modify the pin in the code below | |
-# Create a service in Automator, paste the script, set the script input as none, save it | |
-# Open MacOS Shortcut preferences, create a service with the exact same name, define a shortcut | |
-# The app that has the focus when you press the shortcut has to have assistive access | |
on toggle_mini() | |
tell application "System Events" to tell process "1Password mini" | |
click menu bar item 1 of menu bar 1 | |
end tell | |
end toggle_mini | |
on is_closed() | |
tell application "System Events" to tell process "1Password mini" | |
if (window 1) exists then | |
return false | |
else | |
return true | |
end if | |
end tell | |
end is_closed | |
on is_locked() | |
tell application "System Events" to tell process "1Password mini" | |
set unlock_button to a reference to button "Unlock" of window 1 | |
if unlock_button exists then | |
return true | |
else | |
return false | |
end if | |
end tell | |
end is_locked | |
on unlock_vault(pin) | |
set masterpass to my challenge(pin) | |
if my is_closed() then my toggle_mini() | |
tell application "System Events" to tell process "1Password mini" | |
keystroke masterpass | |
keystroke return | |
end tell | |
end unlock_vault | |
on challenge(chal) | |
set ykcmd to "/usr/bin/sudo /usr/local/bin/ykchalresp -2 " & chal | |
set master to (do shell script ykcmd with administrator privileges) | |
return master | |
end challenge | |
on run {} | |
set pin to "0000" | |
try | |
if my is_closed() then my toggle_mini() | |
if my is_locked() then | |
my unlock_vault(pin) | |
end if | |
on error error_string number error_number | |
set msg to "Error " & error_number & ": " & error_string | |
display alert msg as critical | |
return false | |
end try | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment