To complement @SteffenUllrich's answer, it seems indeed to be a bit of a mess and dependent on the versions of the related perl modules. Here on Debian with these package versions:
| package |
version |
| libio-socket-ssl-perl |
2.095-1 |
| liblwp-protocol-https-perl |
6.14-1 |
| libnet-ssleay-perl |
1.94-3 |
| libwww-perl |
6.81-1 |
I find that to disable SSL certificate verification altogether, you need to:
- set the
SSL_verify_mode UserAgent ssl_opts to 0 (aka IO::Socket::SSL::SSL_VERIFY_NONE), either as ssl_opts parameter to UserAgent->new() or via UserAgent->ssl_opts().
- And set
verify_hostname to 0 (for instance via the PERL_LWP_SSL_VERIFY_HOSTNAME env var or including verify_hostname => 0 in the ssl_opts) as otherwise, if it's set to 1 as it is by default, SSL_verify_mode is reset to 1 further down the line.
Not that I would recommend doing any such thing, but that means you could do what you want with:
perl <(sed '
s/RequestAgent->new/&(ssl_opts=>{SSL_verify_mode=>0,verify_hostname=>0})/
' /usr/bin/lwp-request
) -m HEAD -SU 'https://law.sme.gov.tw/ailt/modules/forum/details/?topic_id=22489'
Where we edit lwp-request (to which HEAD is linked to) on the fly to append (ssl_opts=>{SSL_verify_mode=>0,verify_hostname=>0}) to the RequestAgent->new invocation (RequestAgent being lwp-request's wrapper package around LWP::UserAgent).
Here, it may be not as much that the root CA is not trusted on your system but that that server seems to intermittently return a bogus certificate chain.
Sometimes, I see it returning:
$ openssl s_client -connect law.sme.gov.tw:443
Connecting to 210.69.123.131
CONNECTED(00000003)
depth=2 C=TW, O=Chunghwa Telecom Co., Ltd., CN=HiPKI Root CA - G1
verify return:1
depth=1 C=TW, O=Chunghwa Telecom Co., Ltd., CN=HiPKI OV TLS CA - G1
verify return:1
depth=0 C=TW, L=臺北市, O=政府機關-經濟部中小及新創企業署, CN=startup.sme.gov.tw
verify return:1
---
Certificate chain
0 s:C=TW, L=臺北市, O=政府機關-經濟部中小及新創企業署, CN=startup.sme.gov.tw
i:C=TW, O=Chunghwa Telecom Co., Ltd., CN=HiPKI OV TLS CA - G1
a:PKEY: RSA, 2048 (bit); sigalg: sha256WithRSAEncryption
v:NotBefore: Apr 1 01:16:51 2025 GMT; NotAfter: Feb 4 16:00:00 2026 GMT
1 s:C=TW, O=Chunghwa Telecom Co., Ltd., CN=HiPKI OV TLS CA - G1
i:C=TW, O=Chunghwa Telecom Co., Ltd., CN=HiPKI Root CA - G1
a:PKEY: RSA, 4096 (bit); sigalg: sha256WithRSAEncryption
v:NotBefore: May 18 02:51:28 2023 GMT; NotAfter: Dec 31 15:59:59 2037 GMT
2 s:C=TW, O=Chunghwa Telecom Co., Ltd., CN=HiPKI Root CA - G1
i:C=TW, O=Chunghwa Telecom Co., Ltd., CN=HiPKI Root CA - G1
a:PKEY: RSA, 4096 (bit); sigalg: sha256WithRSAEncryption
v:NotBefore: Feb 22 09:46:04 2019 GMT; NotAfter: Dec 31 15:59:59 2037 GMT
3 s:C=TW, O=行政院, CN=政府伺服器數位憑證管理中心 - G1
i:C=TW, O=Chunghwa Telecom Co., Ltd., CN=ePKI Root Certification Authority - G2
a:PKEY: RSA, 4096 (bit); sigalg: sha256WithRSAEncryption
v:NotBefore: Jul 19 06:46:45 2019 GMT; NotAfter: Aug 19 06:46:45 2031 GMT
4 s:C=TW, O=Chunghwa Telecom Co., Ltd., CN=ePKI Root Certification Authority - G2
i:C=TW, O=Chunghwa Telecom Co., Ltd., OU=ePKI Root Certification Authority
a:PKEY: RSA, 4096 (bit); sigalg: sha256WithRSAEncryption
v:NotBefore: Nov 17 08:51:35 2015 GMT; NotAfter: Dec 20 02:31:27 2034 GMT
5 s:C=TW, O=Chunghwa Telecom Co., Ltd., OU=ePKI Root Certification Authority
i:C=TW, O=Chunghwa Telecom Co., Ltd., OU=ePKI Root Certification Authority
a:PKEY: RSA, 4096 (bit); sigalg: sha1WithRSAEncryption
v:NotBefore: Dec 20 02:31:27 2004 GMT; NotAfter: Dec 20 02:31:27 2034 GMT
Where 2 is redundant as it's the root, 3, 4, 5 seem to have nothing to do with the website cert, but at least cert 1 allows openssl to identify the root CA at the top of the issuance chain (HiPKI Root CA - G1 which my system trusts).
While some other times (most times), it returns:
$ openssl s_client -connect law.sme.gov.tw:443
Connecting to 210.69.123.131
CONNECTED(00000003)
depth=0 C=TW, L=臺北市, O=政府機關-經濟部中小及新創企業署, CN=startup.sme.gov.tw
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 C=TW, L=臺北市, O=政府機關-經濟部中小及新創企業署, CN=startup.sme.gov.tw
verify error:num=21:unable to verify the first certificate
verify return:1
depth=0 C=TW, L=臺北市, O=政府機關-經濟部中小及新創企業署, CN=startup.sme.gov.tw
verify return:1
---
Certificate chain
0 s:C=TW, L=臺北市, O=政府機關-經濟部中小及新創企業署, CN=startup.sme.gov.tw
i:C=TW, O=Chunghwa Telecom Co., Ltd., CN=HiPKI OV TLS CA - G1
a:PKEY: RSA, 2048 (bit); sigalg: sha256WithRSAEncryption
v:NotBefore: Apr 1 01:16:51 2025 GMT; NotAfter: Feb 4 16:00:00 2026 GMT
1 s:C=TW, O=行政院, CN=政府伺服器數位憑證管理中心 - G1
i:C=TW, O=Chunghwa Telecom Co., Ltd., CN=ePKI Root Certification Authority - G2
a:PKEY: RSA, 4096 (bit); sigalg: sha256WithRSAEncryption
v:NotBefore: Jul 19 06:46:45 2019 GMT; NotAfter: Aug 19 06:46:45 2031 GMT
2 s:C=TW, O=Chunghwa Telecom Co., Ltd., CN=ePKI Root Certification Authority - G2
i:C=TW, O=Chunghwa Telecom Co., Ltd., OU=ePKI Root Certification Authority
a:PKEY: RSA, 4096 (bit); sigalg: sha256WithRSAEncryption
v:NotBefore: Nov 17 08:51:35 2015 GMT; NotAfter: Dec 20 02:31:27 2034 GMT
3 s:C=TW, O=Chunghwa Telecom Co., Ltd., OU=ePKI Root Certification Authority
i:C=TW, O=Chunghwa Telecom Co., Ltd., OU=ePKI Root Certification Authority
a:PKEY: RSA, 4096 (bit); sigalg: sha1WithRSAEncryption
v:NotBefore: Dec 20 02:31:27 2004 GMT; NotAfter: Dec 20 02:31:27 2034 GMT
Same irrelevant last 3 certs but missing the cert for the intermediate CA that issued its certificate.
curl -k -Iworks. Unfortunately, the output is not quite as detailed asHEAD -S -U. e.g. trycurl -k -I https://law.sme.gov.tw/ailt/modules/forum/details/?topic_id=22489curl -k -I --verboseshows the full request chain, but it also shows a lot more. it's very verbose, too verbose compared toHEAD -SU