Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python-module-privacyidea-pam
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Eugene Omelyanovich
python-module-privacyidea-pam
Commits
8f0fe412
Commit
8f0fe412
authored
Apr 05, 2015
by
Cornelius Kölbel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add pam module tests
Closes #116
parent
cb910475
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
13 deletions
+26
-13
privacyidea_pam.py
privacyidea_pam.py
+26
-13
No files found.
privacyidea_pam.py
View file @
8f0fe412
...
...
@@ -75,7 +75,7 @@ def pam_sm_authenticate(pamh, flags, argv):
"
%
s: user
%
s in realm
%
s"
%
(
__name__
,
user
,
realm
))
# First we try to authenticate against the sqlitedb
if
check_otp
(
user
,
pamh
.
authtok
,
sqlfile
,
window
=
10
):
if
check_o
ffline_o
tp
(
user
,
pamh
.
authtok
,
sqlfile
,
window
=
10
):
syslog
.
syslog
(
syslog
.
LOG_DEBUG
,
"
%
s: successfully authenticated against offline "
"database
%
s"
%
(
__name__
,
sqlfile
))
...
...
@@ -111,8 +111,9 @@ def pam_sm_authenticate(pamh, flags, argv):
result
.
get
(
"error"
)
.
get
(
"message"
)))
rval
=
pamh
.
PAM_SYSTEM_ERR
except
pamh
.
exception
as
exx
:
rval
=
exx
.
pam_result
except
Exception
as
exx
:
syslog
.
syslog
(
syslog
.
LOG_ERR
,
"
%
s:
%
s"
%
(
__name__
,
exx
))
rval
=
pamh
.
PAM_AUTH_ERR
except
requests
.
exceptions
.
SSLError
:
syslog
.
syslog
(
syslog
.
LOG_CRIT
,
"
%
s: SSL Validation error. Get a valid "
"SSL "
...
...
@@ -141,7 +142,7 @@ def pam_sm_chauthtok(pamh, flags, argv):
return
pamh
.
PAM_SUCCESS
def
check_otp
(
user
,
otp
,
sqlfile
,
window
=
10
):
def
check_o
ffline_o
tp
(
user
,
otp
,
sqlfile
,
window
=
10
):
"""
compare the given otp values with the next hashes of the user.
...
...
@@ -156,14 +157,18 @@ def check_otp(user, otp, sqlfile, window=10):
res
=
False
conn
=
sqlite3
.
connect
(
sqlfile
)
c
=
conn
.
cursor
()
_create_table
(
c
)
c
.
execute
(
"SELECT counter, user, otp FROM authitems WHERE user='
%
s' "
"ORDER by counter"
%
user
)
for
x
in
range
(
0
,
window
):
r
=
c
.
fetchone
()
hash_value
=
r
[
2
]
if
passlib
.
hash
.
pbkdf2_sha512
.
verify
(
otp
,
hash_value
):
res
=
True
counter
=
r
[
0
]
if
r
:
hash_value
=
r
[
2
]
if
passlib
.
hash
.
pbkdf2_sha512
.
verify
(
otp
,
hash_value
):
res
=
True
counter
=
r
[
0
]
break
else
:
break
# We found a matching password, so we remove the old entries
if
res
:
...
...
@@ -194,11 +199,7 @@ def save_auth_item(sqlfile, user, authitem):
conn
=
sqlite3
.
connect
(
sqlfile
)
c
=
conn
.
cursor
()
# Create the table if necessary
try
:
c
.
execute
(
"CREATE TABLE authitems "
"(counter int, user text, tokenowner text, otp text)"
)
except
:
pass
_create_table
(
c
)
syslog
.
syslog
(
syslog
.
LOG_DEBUG
,
"
%
s: offline save authitem:
%
s"
%
(
__name__
,
authitem
))
...
...
@@ -217,3 +218,15 @@ def save_auth_item(sqlfile, user, authitem):
# We can also close the connection if we are done with it.
# Just be sure any changes have been committed or they will be lost.
conn
.
close
()
def
_create_table
(
c
):
"""
Create table if necessary
:param c: The connection cursor
"""
try
:
c
.
execute
(
"CREATE TABLE authitems "
"(counter int, user text, tokenowner text, otp text)"
)
except
:
pass
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment