2022-12-28

在Rocky9使用openssl_sign及openssl_verify失敗的原因

 

在Rocky 9 (RHEL 9),一些已被認為不安全的cipher suites 及 protocols預設是停用的,

因此像在php8使用openssl_sign或openssl_verify,若不加第四個參數,預設都是用不安全的OPENSSL_ALGO_SHA1,因此會簽章或驗證失敗,但從錯誤訊息(-1)是看不出原因的(openssl_verify 來說,1=驗證成功,0=驗證失敗,-1/false=發生錯誤)。

還有使用ssh連線到別台主機時,可能別台主機還是用舊的sha1簽章,因此連線交握過程會失敗。

若在Rocky 9(RHEL 9)要啟用不安全的湊雜及加密演算法,必須下指令:
update-crypto-policies --set LEGACY

update-crypto-policies --set DEFAULT:SHA1 #只增加SHA1

以上指令會修改以下檔案(其實還會修改其它backend設定檔,如java/openssh/nss/gnutls等,以下單指openssl):
/etc/pki/tls/openssl.cnf:
[ crypto_policy ]
.include = /etc/crypto-policies/back-ends/opensslcnf.config

/etc/crypto-policies/back-ends/opensslcnf.config
[evp_properties]
rh-allow-sha1-signatures = yes

openssl-libs所包含的設定檔:
dnf repoquery -l openssl-libs | grep etc

ref:
https://bugs.launchpad.net/ubuntu/+source/crypto-policies/+bug/1926664/comments/6
https://gitlab.com/redhat-crypto/fedora-crypto-policies
https://forums.rockylinux.org/t/php-8-0-13-openssl-verify-fails-on-rocky-9/7478
https://github.com/php/php-src/issues/9686
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/security_hardening/using-the-system-wide-cryptographic-policies_security-hardening
https://www.redhat.com/en/blog/rhel-security-sha-1-package-signatures-distrusted-rhel-9