complete-computing-environment/using_yubikey_as_an_otp_key...

2.0 KiB

Using Yubikey as an OTP Key

(provide 'cce/yubikey-otp)

Yubikeys can also store time-based one-time passwords. It drifts in and out of the Fedora packaging standards, and so I chose to install it from PIP. I use this as a backup in case my Pass configuration is broken or degraded.

(setq ykman-path "/usr/bin/ykman")

(evil-leader/set-key "y" #'yubikey-get-oath)
(defun yubikey-get-oath ()
  "Copy a OATH token to yourkill-ring"
  (interactive)
  (let ((ivy-hash (make-hash-table :test 'equal))
        (cb (lambda (choice)
              (with-temp-buffer
                (call-process-region (point-min) (point-max) ykman-path t t nil "oath" "code" (gethash choice ivy-hash))
                (let* ((output (buffer-string))
                       (cells (split-string output))
                       (code (last cells))
                       )
                  (kill-new (car code)))))))
    (with-temp-buffer
      (call-process-region (point-min) (point-max) ykman-path t t nil "oath" "list")
      (let ((output (buffer-string)))
        (dolist (line (split-string output "\n"))
          (puthash line line ivy-hash)
          )))
    (ivy-read "Copy token:" ivy-hash :action cb)))
- name: python-devel installed
  dnf:
    name:
    - python-devel
    - pcsc-lite-devel
    - swig
    state: present
  when: ansible_pkg_mgr=="dnf"
  tags:
  - yubikey-otp

- fail: msg=dnf
  when: ansible_pkg_mgr!="dnf"

- name: ykman is installed
  pip:
    name: yubikey-manager
    state: present
  tags:
  - yubikey-otp