Ity
Ity copied to clipboard
`public/cert` 存储商户私钥及证书,可能存在泄漏风险
https://github.com/pleaseyang/Ity/blob/b626989e45a02f5cb220514702d57564a076d249/app/Models/Config.php#L190-L202
web
的根目录是在public
,如果没做安全防范,恶意请求可以通过web方式直接下载到商户私钥文件cert/apiclient_key.pem
,存在安全隐患。
项目用到了Redis
,建议抛弃文件存储,商户私钥、商户证书、平台证书均可以以base64-string
形式存储在库中,\WeChatPay\Rsa::from
支持无感加载,详情可参考:
- https://github.com/wechatpay-apiv3/wechatpay-php/blob/main/tests/Crypto/RsaTest.php#L45-L53
- https://github.com/wechatpay-apiv3/wechatpay-php/blob/main/tests/Crypto/RsaTest.php#L148-L149
从证书中提取公钥
详见 PHP openssl_x509_parse 返回值。
加载时仅需增加协议即形如 Rsa::from('public.spki://' . $i_am_a_base64_string_without_envelope, Rsa::KEY_TYPE_PUBLIC)
。
当然Rsa::from
也支持原样以文件内容为字符串形式加载私钥及证书,详细用法可参考上述 RsaTest
测试用例覆盖方法。