feat(auth): Implement Go HTTP auth server for max performance

This commit is contained in:
Whispering Wind
2025-08-24 20:34:33 +03:30
committed by GitHub
parent 3ca2e6649e
commit dbff546523
4 changed files with 72 additions and 10 deletions

View File

@ -5,6 +5,30 @@ source /etc/hysteria/core/scripts/utils.sh
source /etc/hysteria/core/scripts/scheduler.sh
define_colors
compile_auth_binary() {
echo "Compiling authentication binary..."
local auth_dir="/etc/hysteria/core/scripts/auth"
if [ -f "$auth_dir/user_auth.go" ]; then
(
cd "$auth_dir" || exit 1
go mod init hysteria-auth >/dev/null 2>&1
go mod tidy >/dev/null 2>&1
if go build -o user_auth .; then
chown hysteria:hysteria user_auth
chmod +x user_auth
echo "Authentication binary compiled successfully."
else
echo -e "${red}Error:${NC} Failed to compile the authentication binary."
exit 1
fi
)
else
echo -e "${red}Error:${NC} Go source file not found at $auth_dir/user_auth.go"
exit 1
fi
}
install_hysteria() {
local port=$1
@ -12,7 +36,9 @@ install_hysteria() {
bash <(curl -fsSL https://get.hy2.sh/) >/dev/null 2>&1
mkdir -p /etc/hysteria && cd /etc/hysteria/
compile_auth_binary
echo "Generating CA key and certificate..."
openssl ecparam -genkey -name prime256v1 -out ca.key >/dev/null 2>&1
openssl req -new -x509 -days 36500 -key ca.key -out ca.crt -subj "/CN=$sni" >/dev/null 2>&1
@ -114,4 +140,4 @@ else
else
echo -e "${red}Error:${NC} Hysteria2 service is not active. Please check the logs for more details."
fi
fi
fi

View File

@ -39,20 +39,20 @@ check_scheduler_service() {
}
setup_hysteria_auth_server() {
chmod +x /etc/hysteria/core/scripts/hysteria2/auth_server.py
chmod +x /etc/hysteria/core/scripts/auth/user_auth
cat > /etc/systemd/system/hysteria-auth.service << 'EOF'
[Unit]
Description=Hysteria aiohttp Auth Server
Description=Hysteria Auth Server
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/etc/hysteria
ExecStart=/etc/hysteria/hysteria2_venv/bin/python3 /etc/hysteria/core/scripts/hysteria2/auth_server.py
User=hysteria
Group=hysteria
ExecStart=/etc/hysteria/core/auth-server/auth_server
Restart=always
RestartSec=10
RestartSec=5
StandardOutput=journal
StandardError=journal
SyslogIdentifier=hysteria-Auth