Python3, MariaDB, OpenVPN Password Check fails

Viewed 51

os.eviron['username'] is sent from OpenVPN, but for debugging I changed it to "test" as user in the Database. os.eviron['password'] is sent from OpenVPN, but for debugging I changed it to the working password "password", and everything worked as designed.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import mysql.connector as database
import sys
import hashlib
from config import DB_NAME, DB_ADMIN, DB_PASSWORD, DB_HOST, HASH_ALGORITHM, HASH_SALTY

connection = database.connect(
    user=DB_ADMIN,
    password=DB_PASSWORD,
    host=DB_HOST,
    database=DB_NAME
)
cursor = connection.cursor()


hash_func = getattr(hashlib, HASH_ALGORITHM)
salty = hash_func(HASH_SALTY.encode("utf-8")).hexdigest()

ovpnuser = (os.environ['username'])
ovpnuser = "SELECT * FROM users WHERE usernames = '" + ovpnuser + "';"

cursor.execute(ovpnuser)
result = cursor.fetchone()

if result is None:
    sys.exit(1)

id, usernames, passwords = result
passw = (os.environ['password'] + salty) #Salt this mofo
if hash_func(passw.encode("utf-8")).hexdigest() != passwords:
    sys.exit(1)
sys.exit(0)

Now that I use OpenVPN to call this plugin as you see it now, it returns sys.exit(1) Failed to authenticate. I've tried to debug it, but I can't get ovpn to print and errors from connections or calls to this plugin. I even added echo to write to a log file in the python code, and it didn't work.

Any thoughts?

0 Answers
Related