AC注册(含Sha1-Registration)不起作用
也许我站在林中,看不清眼前的树,但我已经不知道还能尝试什么了。
如下情况:
在运行中的AzerothCore私有局域网服务器(PHP 8.4),上面有一个用于GameAccs的 registrationscript 正在运行(感谢 Ferreira9006)。这切都没问题(因此GMP扩展似乎在工作),但现在注册已经实现了使用salt和 verifier等等,我正试图把它和一个使用sha1和 md5的注册方式整合在一起(是的,是旧项目,但这是必要的)……
当然,我希望两者共用一个注册逻辑,并且我正在试图把这些输入发送到我服务器上的一个文件中,让它把它们“呈现”为Game-Acc所需的输入(身份验证数据库、账户、'$username'、'$email'、'$salt'、'$verifier'),以在打开URL时进行测试,稍后在旧的注册脚本中用curl测试……
现在如果我在文件中用PHP类 SRP6(就像它在游戏注册脚本中那样工作),它什么也不输出,而写入数据库的只有盐和verifier,值为 0x0000000000...
如果我把类的语句注释掉,它确实会输出一个verifier,但有你能想到的所有迹象都在,但没有用于数据库的可工作的输入值,因此用于数据库的输入语句不起作用……
这是那个把盐和verifier写进去的脚本 0x0000000000...,我该如何把正确渲染出的数值放进这些变量,或者我到底做错了什么?
<?php
//URL:
//http://IP.IP.IP.IP/reg/forum-register.php?name=test&[email protected]&pass=1234567&pass-rep=1234567
//Datenbank connection
$host = "127.0.0.1"; // Database Host
$user = "user"; // Database Username
$pass = "pwd"; // Database Password
$db = "acore_auth"; // Database Name
$db = mysqli_connect($host, $user, $pass, $db);
if(!$db)
{
exit("Verbindungsfehler: ".mysqli_connect_error());
}else{
echo "DB-Connection war erfolgreich<br><br>";
}
//Values URL
//$username:
$username = isset($_GET['name']) ? $_GET['name'] : 'anonymous';
//$email:
$email = isset($_GET['mail']) ? $_GET['mail'] : '[email protected]';
//$password:
$password = isset($_GET['pass']) ? $_GET['pass'] : 'pwd';
//$passwordRepeat:
$passwordRepeat = isset($_GET['pass-rep']) ? $_GET['pass-rep'] : 'pwd-rep';
echo "User: ".$username."<br>";
echo "Mail: ".$email."<br>";
echo "PWD: ".$password."<br>";
echo "PWDrep: ".$passwordRepeat."<br>";
//}
class SRP6
{
// Its from TrinityCore/account-creator
public static function calculateSRP6Verifier($username, $password, $salt)
{
// algorithm constants
$g = gmp_init(7);
$N = gmp_init('894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7', 16);
// calculate first hash
$h1 = sha1(strtoupper($username . ':' . $password), TRUE);
// calculate second hash
$h2 = sha1($salt . $h1, TRUE);
// convert to integer (little-endian)
$h2 = gmp_import($h2, 1, GMP_LSW_FIRST);
// g^h2 mod N
$verifier = gmp_powm($g, $h2, $N);
// convert back to a byte array (little-endian)
$verifier = gmp_export($verifier, 1, GMP_LSW_FIRST);
// pad to 32 bytes, remember that zeros go on the end in little-endian!
$verifier = str_pad($verifier, 32, chr(0), STR_PAD_RIGHT);
return $verifier;
}
public static function getRegistrationData($username, $password)
{
// generates a random salt
$salt = random_bytes(32);
// calculate the verifier using the created salt
$verifier = self::calculateSRP6Verifier($username, $password, $salt);
return array($salt, $verifier);
}
}
//DB-Input
$neuacc = "INSERT INTO `account` (username, email, salt, verifier) VALUES ('$username', '$email', '$salt', '$verifier')";
$auswahl = mysqli_query($db, $neuacc);
?>
解决方案
你的代码有两处需要修改(如其他志愿者所述):
- 你已经有了实现Secure Remote Password (SRP) 协议的SRP6类,但你尚未创建该类的实例(以便调用其中的方法),例如
$srp = new SRP6();
$result=$srp->getRegistrationData($username, $password);
$salt=$result[0];
$verifier=$result[1];
- 在你的数据库插入查询中,应该使用参数化的预处理语句以抵御SQL注入。
因此你的代码可以按如下方式修改:
<?php
$host = "127.0.0.1"; // Database Host
$user = "user"; // Database Username
$pass = "pwd"; // Database Password
$db = "acore_auth"; // Database Name
$conn = new mysqli($host, $user, $pass, $db);
$username = isset($_GET['name']) ? $_GET['name'] : 'anonymous';
$email = isset($_GET['mail']) ? $_GET['mail'] : '[email protected]';
$password = isset($_GET['pass']) ? $_GET['pass'] : 'pwd';
$passwordRepeat = isset($_GET['pass-rep']) ? $_GET['pass-rep'] : 'pwd-rep';
class SRP6
{
// Its from TrinityCore/account-creator
public static function calculateSRP6Verifier($username, $password, $salt)
{
// algorithm constants
$g = gmp_init(7);
$N = gmp_init('894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7', 16);
// calculate first hash
$h1 = sha1(strtoupper($username . ':' . $password), TRUE);
// calculate second hash
$h2 = sha1($salt . $h1, TRUE);
// convert to integer (little-endian)
$h2 = gmp_import($h2, 1, GMP_LSW_FIRST);
// g^h2 mod N
$verifier = gmp_powm($g, $h2, $N);
// convert back to a byte array (little-endian)
$verifier = gmp_export($verifier, 1, GMP_LSW_FIRST);
// pad to 32 bytes, remember that zeros go on the end in little-endian!
$verifier = str_pad($verifier, 32, chr(0), STR_PAD_RIGHT);
return $verifier;
}
public static function getRegistrationData($username, $password)
{
// generates a random salt
$salt = random_bytes(32);
// calculate the verifier using the created salt
$verifier = self::calculateSRP6Verifier($username, $password, $salt);
return array($salt, $verifier);
}
}
$srp = new SRP6();
$result=$srp->getRegistrationData($username, $password);
$salt=$result[0];
$verifier=$result[1];
$sql = "INSERT INTO `account` (username, email, salt, verifier) VALUES (?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ssss",
$username,
$email,
$salt,
$verifier);
$stmt->execute();
// echo $stmt->insert_id;
?>
最后但同样重要的是,请确保已经安装/启用GNU多精度运算(GMP)扩展,因为你的SRP6类使用了这个PHP模块。
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。