예제 #1
0
파일: sshd.py 프로젝트: CyaLiven/totp
from os import environ, execl as exec
from sys import argv, exit
from getpass import getpass

import totp

try:
  if len(argv) > 1:
    myFile = argv[1]
  else:
    myFile = '~/.2fa'

  myTOTP = totp.Config(myFile)

  totp.setCatch(myTOTP.options['timer'])

  while True:
    myCode = getpass('Challenge: ')
    if len(myCode):
      break

  if myTOTP.authenticate(myCode):
    myShell = environ['SHELL']
    with open('/etc/shells') as handle:
      goodShell = False
      for line in handle:
        if line.rstrip() == myShell:
          goodShell = True
          break
      if not goodShell:
예제 #2
0
파일: pam.py 프로젝트: CyaLiven/totp
import totp

try:
  setresuid(getuid(environ['PAM_USER'])[2], getuid(environ['PAM_USER'])[2], 0)

  if len(argv) > 1:
    myFile = argv[1]
  else:
    myFile = '~/.2fa'

  myConf = totp.Config(myFile)
  myTTY = '/dev/' + environ['PAM_TTY']

  setresuid(0,0,0)

  totp.setCatch(myConf.options['timer'])

  with open(myTTY, 'w') as handle:
    handle.write('Challenge: ')
  with open(myTTY) as handle:
    old = tcgetattr(handle.fileno())
    new = tcgetattr(handle.fileno())
    new[3] = new[3] & ~ECHO
    try:
      tcsetattr(handle.fileno(), DRAIN, new)
      while True:
        myCode = handle.readline().rstrip()
        if len(myCode):
          break
    finally:
      tcsetattr(handle.fileno(), DRAIN, old)
예제 #3
0
try:
    setresuid(
        getuid(environ['PAM_USER'])[2],
        getuid(environ['PAM_USER'])[2], 0)

    if len(argv) > 1:
        myFile = argv[1]
    else:
        myFile = '~/.2fa'

    myConf = totp.Config(myFile)
    myTTY = '/dev/' + environ['PAM_TTY']

    setresuid(0, 0, 0)

    totp.setCatch(myConf.options['timer'])

    with open(myTTY, 'w') as handle:
        handle.write('Challenge: ')
    with open(myTTY) as handle:
        old = tcgetattr(handle.fileno())
        new = tcgetattr(handle.fileno())
        new[3] = new[3] & ~ECHO
        try:
            tcsetattr(handle.fileno(), DRAIN, new)
            while True:
                myCode = handle.readline().rstrip()
                if len(myCode):
                    break
        finally:
            tcsetattr(handle.fileno(), DRAIN, old)