Skip to content

Commit ee17534

Browse files
author
root
committed
Non-working HTTP basic authentication was fixed
1 parent 1d1036c commit ee17534

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

root/app/nginx-ldap-auth-daemon.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import sys, os, signal, base64, ldap, Cookie, argparse
1010
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
1111
from cryptography.fernet import Fernet
12+
from cryptography.fernet import InvalidToken
1213

1314
#Listen = ('localhost', 8888)
1415
#Listen = "/tmp/auth.sock" # Also uncomment lines in 'Requests are
@@ -74,11 +75,16 @@ def do_GET(self):
7475

7576
try:
7677
cipher_suite = Fernet('REPLACEWITHFERNETKEY')
78+
self.log_message('Trying to dechipher credentials...')
7779
auth_decoded = cipher_suite.decrypt(auth_header[6:])
7880
user, passwd = auth_decoded.split(':', 1)
79-
80-
except:
81+
except InvalidToken:
82+
self.log_message('Incorrect token. Trying to decode credentials from BASE64...')
83+
auth_decoded = base64.b64decode(auth_header[6:])
84+
user, passwd = auth_decoded.split(':', 1)
85+
except Exception as e:
8186
self.auth_failed(ctx)
87+
self.log_error(e)
8288
return True
8389

8490
ctx['user'] = user
@@ -245,8 +251,10 @@ def do_GET(self):
245251
self.send_response(200)
246252
self.end_headers()
247253

248-
except:
254+
except Exception as e:
249255
self.auth_failed(ctx)
256+
self.log_error(str(e))
257+
raise
250258

251259
def exit_handler(signal, frame):
252260
global Listen

0 commit comments

Comments
 (0)