enceeper / enceeper-phpconf
这是一个用于从用户Enceeper账户中获取密钥的PHP包。主要目标是能够在密钥中存储配置信息,并将这些信息传递给PHP应用程序(欢迎其他用途 😄)。
v1.1
2018-12-17 12:01 UTC
Requires
- php: ^7.0
- ext-openssl: *
Suggests
- php-64bit: PHP 64-bit is required if you plan on testing/using the PHP scrypt implementation.
- ext-intl: For utilizing the Normalizer::normalize on passwords and using their NFKD form.
- ext-redis: You will need to install Redis server and the PHP Redis package in order to utilize the RedisCache implementation.
- enceeper/scrypt: Binary scrypt implementation (in C) to run 20 times faster and consume less memory (you will need to compile the software and provide the path to the executable).
This package is auto-updated.
Last update: 2024-09-18 23:50:01 UTC
README
这是一个用于从用户Enceeper账户中获取密钥的PHP包。主要目标是存储配置信息在密钥中,并将这些信息传递给PHP应用程序(欢迎其他用途 😄)。
介绍
Enceeper应用程序(https://github.com/enceeper/enceeper)和Enceeper服务(https://www.enceeper.com/)可以用于安全地存储和检索凭证(用户名、密码、API密钥等)。我们希望将这种想法扩展到配置文件:为PHP项目(以及未来的其他编程语言)安全地存储和传递配置信息。场景是Enceeper应用程序用户可以在其账户中存储带有配置信息的密钥(以JSON格式)。此包将检索加密的JSON并返回解密后的信息作为配置。我们还添加了文件系统和Redis缓存机制,以更好地利用资源并优雅地处理错误。
我们认为这种方法有以下优点
- 您的项目配置在Enceeper中安全存储(加密)
- 您可以在Enceeper中更新此信息,并将其部署到您的项目,而无需在服务器或应用程序上更新任何内容
- 信息是加密提供的,并且只能用正确的密码解密
- 此解决方案没有额外的访问您的Enceeper账户权限
Enceeper应用程序在将信息传递给Enceeper服务之前对信息进行加密。此包接收条目的加密信息并使用条目特定的解密密钥进行本地解密。这是在TLS(HTTPS)网络流量之上的额外安全层。
使用Composer安装
{
"require": {
"enceeper/enceeper-phpconf": "^1.0"
}
}
重要提示
在生产环境中使用此包时,您需要考虑以下事项
- 为了简单起见,我们提供了一种PHP实现(使用SHA512的scrypt)。此实现有以下限制
- 它需要PHP 64位,因为PHP不支持无符号整数
- 它运行非常慢(与N=32768的C实现相比慢约20倍)
- 它需要内存,因此您需要编辑php.ini并设置memory_limit指令(N=32768时约为400MB)
- 我们强烈建议您使用以下:https://github.com/enceeper/scrypt并提供可执行文件的路径。
- 我们提供了一种使用文件系统或Redis的缓存机制。您需要考虑以下事项
- 对于Redis缓存,您需要安装Redis(Redis服务器:https://redis.ac.cn 和PHP Redis包:https://github.com/phpredis/phpredis)
- 对于文件系统缓存,您必须确保脚本具有写入目标目录的权限
- 对于生产系统,建议使用批处理模式策略:
STRATEGY_BATCH_MODE
。您还必须设置一个作业(例如,crontab)以定期更新缓存内容
- 我们还推荐您安装国际化扩展(intl),它提供了
Normalizer::normalize
方法,以便检索密码的NFKD形式,并确保在各个平台和编码中结果一致(https://php.ac.cn/manual/en/normalizer.normalize.php)
使用方法
<?php require __DIR__ .'/vendor/autoload.php'; // The key identifier and the password $pw = 'ThisLittlePiggyWasHappyWithEncryption'; $id = 'fd925fdd94706d418cc3ddbe8bf46ce9'; // Connect to Redis $redis = new Redis(); $redis->connect('127.0.0.1', 6379, 2.0); // Instanciate Enceeper and the cache $enc = new Enceeper\Enceeper($pw, $id); $cch = new Enceeper\RedisCache($redis, 'enceeper-conf', 5, $enc, Enceeper\AbstractCache::STRATEGY_BATCH_MODE); // Get the configuration array $conf = $cch->get(); // // The code bellow will be called asynchronously by another script // // //$cch->update(); // // // You can continue with your application logic //
版权和许可证
版权所有 © 2018 Vassilis Poursalidis。在GNU GPL3或更高版本下发布 - 详细信息请参阅LICENSE
文件。