0
0
Fork 0
mirror of https://github.com/boltgolt/howdy.git synced 2024-09-12 09:41:18 +02:00

Added config file and session auth

This commit is contained in:
boltgolt 2018-01-05 02:41:56 +01:00
parent 4b3f3064ce
commit 4d3d0d4701
5 changed files with 51 additions and 17 deletions

5
.gitignore vendored
View file

@ -100,5 +100,8 @@ ENV/
# mypy
.mypy_cache/
# Ignore generated models
# generated models
/models
# config file
config.py

10
README.md Normal file
View file

@ -0,0 +1,10 @@
# Ubuntu Howdy
Windows Hello™ style authentication for Ubuntu
Notes:
tail /var/log/auth.log
/etc/pam.d/sudo
auth sufficient pam_python.so /path/to/pam.py

View file

@ -3,13 +3,12 @@ import cv2
import sys
import os
import config
def stop(status):
video_capture.release()
sys.exit(status)
path = ""
distance = 3
try:
if not isinstance(sys.argv[1], str):
sys.exit(1)
@ -17,19 +16,18 @@ except IndexError:
sys.exit(1)
user = sys.argv[1]
# Get a reference to webcam #0 (the default one)
video_capture = cv2.VideoCapture(1)
video_capture = cv2.VideoCapture(config.device_id)
encodings = []
try:
for exposure in ["L", "M", "S"]:
ref = face_recognition.load_image_file(path + "/" + user + "/" + exposure + ".jpg")
ref = face_recognition.load_image_file(os.path.dirname(__file__) + "/models/" + user + "/" + exposure + ".jpg")
enc = face_recognition.face_encodings(ref)[0]
encodings.append(enc)
except FileNotFoundError:
stop(802)
stop(10)
tries = 0
@ -44,10 +42,10 @@ while True:
matches = face_recognition.face_distance(encodings, face_encoding)
for match in matches:
if match < distance:
if match < config.certainty:
stop(0)
if tries => 100:
stop(801)
if tries > config.frame_count:
stop(11)
tries += 1

10
config_template.py Normal file
View file

@ -0,0 +1,10 @@
# The certainty of the detected face belonging to the user of the account
# On a scale from 1 to 10, values above 5 are not recomended
certainty = 3
# The number of frames to capture and to process before timing out
frame_count = 120
# The /dev/videoX id to capture frames from
# On my laptop, video0 is the normal camera and video1 is the IR version
device_id = 1

25
pam.py
View file

@ -2,17 +2,30 @@ import subprocess
import sys
import os
def pam_sm_authenticate(pamh, flags, args):
status = subprocess.call(["python3", "compair.py", pamh.get_user()])
def doAuth(pamh):
status = subprocess.call(["python3", "/compair.py", pamh.get_user()])
if status == 801:
print("Timeout reached, ould not find a known face")
if status == 10:
print("No face model is known for this user, aborting")
return pamh.PAM_SYSTEM_ERR
if status == 34:
print("No face model is known for this user")
if status == 11:
print("Timeout reached, ould not find a known face")
return pamh.PAM_SYSTEM_ERR
if status == 0:
print("Identified face as " + os.environ.get("USER"))
return pamh.PAM_SUCCESS
print(status)
return pamh.PAM_SYSTEM_ERR
def pam_sm_authenticate(pamh, flags, args):
return doAuth(pamh)
def pam_sm_open_session(pamh, flags, args):
return doAuth(pamh)
def pam_sm_close_session(pamh, flags, argv):
return pamh.PAM_SUCCESS
def pam_sm_setcred(pamh, flags, argv):
return pamh.PAM_SUCCESS