servicecore / shield
此包的最新版本(2.0.1)没有可用的许可信息。
恒定响应时间库
2.0.1
2022-09-28 17:50 UTC
Requires
- php: ^7.4 || ^8.0.0
- servicecore/timer: ^1.0.0
Requires (Dev)
- phpunit/phpunit: ^9.5.7
- roave/security-advisories: dev-latest
This package is not auto-updated.
Last update: 2024-10-02 08:00:49 UTC
README
恒定响应时间库。
时间攻击 是在线服务的常见威胁向量。使用恒定的代码执行时间可以大大降低风险。
Shield 库将使应用程序休眠,休眠时间为实际执行时间与期望执行时间之差
use ServiceCore\Shield\Ready as Shield;
// ... in a controller or resource somewhere
// instantiate a new shield
$shield = new Shield();
// start the shield with a 500 millisecond *desired* execution time
$shield = $shield->start(500);
// ... do something sensitive like authenticate a password
// stop the shield...
// this will sleep the application for the difference between the *actual* execution
// time and the *desired* execution time
//
$shield = $shield->stop();
使用方法
Shield 有三种状态:就绪、开始 和 停止。
您可以实例化一个 Ready Shield
use ServiceCore\Shield\Ready as Shield;
$shield = new Shield();
您可以使用期望的执行时间(以毫秒为单位)来启动一个 Ready Shield
// ... continued from the example above
$shield = $shield->start(500);
start() 方法将返回一个 Started Shield。
您可以停止一个 Started Shield
// ... continued from the example above
$shield = $shield->stop();
stop() 方法将休眠实际执行时间与期望执行时间之差。实际执行时间被认为是调用 Shield 的 start() 方法与 stop() 方法之间的时间。
stop() 方法将返回一个 Stopped Shield。
最后,您可以重置一个 Stopped Shield
// ... continued from the example above
$shield = $shield->reset();
reset() 方法将返回一个 Ready Shield。
版本
0.1.1,2016年3月7日
- 修复对
obg/timer的依赖,从dev-master更改为~0.1。
0.1.0,2016年3月7日
- 初始发布