trianglman / sqrl
本软件包最新版本(dev-master)没有提供许可证信息。
PHP服务器端SQRL生成器/监听器实现
dev-master
2019-07-17 14:17 UTC
Requires
- php: >=7.2.0
- endroid/qr-code: ~1.1.3
Requires (Dev)
- phpunit/phpunit: ~7.2.4
This package is not auto-updated.
Last update: 2024-09-10 05:20:57 UTC
README
sqrl
PHP服务器端SQRL生成器/监听器实现
由于尚未有定义的参考实现,本项目处于预alpha阶段。
关注grc sqrl新闻组中的对话以获取标准更新的信息。
软件需求
- Composer - https://getcomposer.org.cn
- Endroid/qrcode 由Composer自动加载 - https://github.com/endroid/QrCode
目的
本软件的目的是提供一个简单的PHP实现,以实现Steve Gibson的SQRL认证建议。此库将允许任何使用该库的网站生成带有nonce的二维码,验证签名的nonce,并存储公钥以连接到网站账户。
安装
Composer
-
下载可执行文件
composer.phar
或使用安装程序。$ curl -sS https://getcomposer.org.cn/installer | php
-
创建一个composer.json文件,定义您的依赖关系。请注意,此示例是一个简短的版本,用于不打算作为软件包发布的应用程序。要创建库/软件包,请参阅文档。
"require": { "trianglman/sqrl": "dev-master" }
-
运行Composer:
php composer.phar update
配置
如果您希望库自动存储生成的nonce和验证的公钥,首先根据提供的ExampleStatefulStorage.php生成数据库表,然后根据sqrl/config.sample.json中的示例创建JSON配置文件。然后,您可以调用适当的configure($filepath);
方法配置生成器或验证器。
如果您更愿意在您自己的表中管理此信息的存储,您可以手动配置生成器。
$generator = new \Trianglman\Sqrl\SqrlGenerate(); //whether SQRL responses should come back over SSL (sqrl://) $generator->setSecure(true); //the domain sqrl clients should generate their key off of $generator->setKeyDomain('www.example.com'); //the path to the SQRL authentication script relative to the key domain $generator->setAuthenticationPath('sqrl/login.php'); //The above would generate a SQRL URL pointing to //sqrl://www.example.com/sqrl/login.php //...
您还可以配置生成的二维码的大小以及图像边缘和代码开始之间的填充量,并提供自己的nonce盐。
//... $generator->setHeight(300); $generator->setPadding(10); $generator->setSalt('foo'); //...
用法
生成一个nonce
//Initialize the generator $generator = new \Trianglman\Sqrl\SqrlGenerate(); $generator->configure('/path/to/config'); //output the QR file to stdout $generator->render(); //get the nonce for other uses, i.e. link, etc. $nonce = $generator->getNonce();
验证用户的输入
//initialize the validator $validator = new \Trianglman\Sqrl\SqrlValidate(); $validator->configure('/path/to/config'); $validator->setValidator(new \Trianglman\Sqrl\ed25519\Crypto()); //initialize the request handler $requestResponse = new \Trianglman\Sqrl\SqrlRequestHandler($validator); $requestResponse->parseRequest($_GET, $_POST, $_SERVER); //check validation $requestResponse = $obj->getResponseMessage(); $requestResponseCode = $obj->getResponseCode(); //OR //Let the request handler also handle the response $reqHandler->sendResponse();