fix: Catch DNS from wireformat error
All checks were successful
Build Docker / Build Docker (push) Successful in 1m39s
All checks were successful
Build Docker / Build Docker (push) Successful in 1m39s
This commit is contained in:
1
.python-version
Normal file
1
.python-version
Normal file
@@ -0,0 +1 @@
|
||||
3.13
|
||||
6
main.py
Normal file
6
main.py
Normal file
@@ -0,0 +1,6 @@
|
||||
def main():
|
||||
print("Hello from hns-login!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
22
pyproject.toml
Normal file
22
pyproject.toml
Normal file
@@ -0,0 +1,22 @@
|
||||
[project]
|
||||
name = "hns-login"
|
||||
version = "0.1.0"
|
||||
description = "Add your description here"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.13"
|
||||
dependencies = [
|
||||
"authlib>=1.6.5",
|
||||
"dnspython>=2.6.1",
|
||||
"eth-account>=0.13.7",
|
||||
"flask>=3.1.2",
|
||||
"flask-sqlalchemy>=3.1.1",
|
||||
"python-dotenv>=1.2.1",
|
||||
"requests>=2.32.3",
|
||||
"requests-doh>=1.0.0",
|
||||
"web3>=7.14.0",
|
||||
]
|
||||
|
||||
[dependency-groups]
|
||||
dev = [
|
||||
"ruff>=0.14.5",
|
||||
]
|
||||
@@ -1,7 +1,7 @@
|
||||
import time
|
||||
import datetime as dt
|
||||
from .varo_auth import flask_login as varo_auth_flask_login
|
||||
from flask import Blueprint, request, session, url_for, make_response
|
||||
from flask import Blueprint, request, session, url_for
|
||||
from flask import render_template, redirect, jsonify, send_from_directory
|
||||
from werkzeug.security import gen_salt
|
||||
from authlib.integrations.flask_oauth2 import current_token
|
||||
@@ -18,7 +18,6 @@ from datetime import timedelta
|
||||
from eth_account.messages import encode_defunct
|
||||
from eth_account import Account
|
||||
import json
|
||||
import urllib.parse
|
||||
|
||||
|
||||
|
||||
@@ -60,7 +59,7 @@ def get_idns_records(domain:str) -> list:
|
||||
query = dns.message.make_query(domain, dns.rdatatype.TXT)
|
||||
dns_request = query.to_wire()
|
||||
# Send the DNS query over HTTPS
|
||||
response = requests.post('https://hnsdoh.com/dns-query', data=dns_request, headers={'Content-Type': 'application/dns-message'})
|
||||
response = requests.post('https://au.hnsdoh.com/dns-query', data=dns_request, headers={'Content-Type': 'application/dns-message'})
|
||||
# Parse the DNS response
|
||||
dns_response = dns.message.from_wire(response.content)
|
||||
# Loop over TXT records and look for profile
|
||||
@@ -145,7 +144,7 @@ def home():
|
||||
|
||||
if request.method == "POST":
|
||||
auth = varo_auth_flask_login(request)
|
||||
if auth == False:
|
||||
if not auth:
|
||||
return redirect("/?error=login_failed")
|
||||
print(auth)
|
||||
user = User.query.filter_by(username=auth).first()
|
||||
@@ -267,20 +266,23 @@ def hnsid_domain(domain):
|
||||
|
||||
@bp.route("/txt", methods=["POST"])
|
||||
def txtLogin():
|
||||
# Get domain from form
|
||||
domain = request.form.get("domain").lower().strip().replace("/", "").removesuffix(".")
|
||||
# Get uuid
|
||||
uuid = session["uuid"]
|
||||
|
||||
query = dns.message.make_query(domain, dns.rdatatype.TXT)
|
||||
dns_request = query.to_wire()
|
||||
|
||||
# Send the DNS query over HTTPS
|
||||
response = requests.post('https://hnsdoh.com/dns-query', data=dns_request, headers={'Content-Type': 'application/dns-message'})
|
||||
|
||||
# Parse the DNS response
|
||||
dns_response = dns.message.from_wire(response.content)
|
||||
|
||||
try:
|
||||
# Get domain from form
|
||||
domain = request.form.get("domain").lower().strip().replace("/", "").removesuffix(".")
|
||||
# Get uuid
|
||||
uuid = session["uuid"]
|
||||
query = dns.message.make_query(domain, dns.rdatatype.TXT)
|
||||
dns_request = query.to_wire()
|
||||
# Send the DNS query over HTTPS
|
||||
response = requests.post('https://au.hnsdoh.com/dns-query', data=dns_request, headers={'Content-Type': 'application/dns-message'})
|
||||
# Parse the DNS response
|
||||
dns_response = dns.message.from_wire(response.content)
|
||||
except Exception as e:
|
||||
print(f"Error fetching DNS records: {e}")
|
||||
return render_template("error.html",error="The domain wasn't able to be authenticated.",
|
||||
message="<br>Double check the TXT record and try again.",
|
||||
custom="<button onclick='window.location.reload();'>Try again</button>"), 200
|
||||
# Loop over TXT records and look for profile avatar
|
||||
idns_records = []
|
||||
for record in dns_response.answer:
|
||||
@@ -623,7 +625,7 @@ def avatar(username):
|
||||
dns_request = query.to_wire()
|
||||
|
||||
# Send the DNS query over HTTPS
|
||||
response = requests.post('https://hnsdoh.com/dns-query', data=dns_request, headers={'Content-Type': 'application/dns-message'})
|
||||
response = requests.post('https://au.hnsdoh.com/dns-query', data=dns_request, headers={'Content-Type': 'application/dns-message'})
|
||||
|
||||
# Parse the DNS response
|
||||
dns_response = dns.message.from_wire(response.content)
|
||||
@@ -640,7 +642,7 @@ def avatar(username):
|
||||
|
||||
if avatar_url != "":
|
||||
# Download the avatar using DNS-over-HTTPS
|
||||
add_dns_provider("hns", "https://hnsdoh.com/dns-query")
|
||||
add_dns_provider("hns", "https://au.hnsdoh.com/dns-query")
|
||||
session = DNSOverHTTPSSession(provider="hns")
|
||||
response = session.get(avatar_url)
|
||||
with open(f"website/avatars/{username}.png", "wb") as f:
|
||||
|
||||
@@ -12,7 +12,7 @@ def flask_login(request):
|
||||
def login(request):
|
||||
r = requests.get(f'https://auth.shakestation.io/verify/{request}')
|
||||
r = r.json()
|
||||
if r['success'] == False:
|
||||
if not r['success']:
|
||||
return False
|
||||
|
||||
if 'data' in r:
|
||||
|
||||
Reference in New Issue
Block a user