我使用这个Makefile为foo.localhost创建了一个使用让我们加密推荐的自签名证书:
include ../.env
configuration = csr.cnf
certificate = self-signed.crt
key = self-signed.key
.PHONY: all
all: $(certificate)
$(certificate): $(configuration)
openssl req -x509 -out $@ -keyout $(key) -newkey rsa:2048 -nodes -sha256 -subj '/CN=$(HOSTNAME)' -extensions EXT -config $(configuration)
$(configuration):
printf "[dn]\nCN=$(HOSTNAME)\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:$(HOSTNAME)\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth" > $@
.PHONY: clean
clean:
$(RM) $(configuration)
然后,我将其分配给一个web服务器。我已经验证服务器返回相关证书:
$ openssl s_client -showcerts -connect foo.localhost:8443 < /dev/null
CONNECTED(00000003)
depth=0 CN = foo.localhost
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 CN = foo.localhost
verify error:num=21:unable to verify the first certificate
verify return:1
---
Certificate chain
0 s:/CN=foo.localhost
i:/CN=foo.localhost
-----BEGIN CERTIFICATE-----
[…]
-----END CERTIFICATE-----
---
Server certificate
subject=/CN=foo.localhost
issuer=/CN=foo.localhost
---
No client certificate CA names sent
Peer signing digest: SHA512
Server Temp Key: X25519, 253 bits
---
SSL handshake has read 1330 bytes and written 269 bytes
Verification error: unable to verify the first certificate
---
New, TLSv1.2, Cipher is ECDHE-RSA-AES128-GCM-SHA256
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1.2
Cipher : ECDHE-RSA-AES128-GCM-SHA256
Session-ID: […]
Session-ID-ctx:
Master-Key: […]
PSK identity: None
PSK identity hint: None
SRP username: None
TLS session ticket:
[…]
Start Time: 1529622990
Timeout : 7200 (sec)
Verify return code: 21 (unable to verify the first certificate)
Extended master secret: no
---
DONE
如何使cURL信任它而不修改/etc中的任何内容?--cacert
不工作,大概是因为没有CA:
$ curl --cacert tls/foo.localhost.crt 'https://foo.localhost:8443/'
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.haxx.se/docs/sslcerts.html
curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
目标是在开发过程中启用HTTPS:
curl -k
就像catch (Exception e) {}
一样--一点也不像浏览器与web服务器对话。换句话说,在运行curl [something] https://project.local/api/foo
时,我希望确信
使用HTTP或--insecure
不能满足第二个条件。
发布于 2020-04-24 20:12:26
我有这个问题,完全相同的问题和错误消息,但是我使用GNUTLS的certtool来生成我的cert,而不是openssl。
我的问题是,我没有使我自己签署证书为CA。它只被配置为充当web服务器证书。这就是我想要做的,我不打算用它作为一个CA来签署其他证书。
但是,当您想要将证书作为其他证书的颁发者添加到信任链中时,该证书必须是CA,否则将被openssl拒绝!
在certtool -i < mycert.crt
中,人们需要看到以下内容:
Extensions:
Basic Constraints (critical):
Certificate Authority (CA): TRUE
尝试将-addext basicConstraints=critical,CA:TRUE,pathlen:1
添加到openssl命令中,或以同样的效果修改cnf文件。
或者,使用certtool,这对于一次性证书生成来说要容易得多:
certtool -p --outfile localhost.key
certtool -s --load-privkey localhost.key --outfile localhost.crt
然后回答提供证书的CN等提示。当被问到是否为证书颁发机构时,请说是!
发布于 2018-10-16 23:55:31
试试-k
:
curl -k https://yourhost/
它应该“接受”自签署的证书。
发布于 2018-09-11 19:19:32
遵循以下步骤可以解决您的问题:
echo quit | openssl s_client -showcerts -servername "${API_HOST}" -connect "${API_HOST}":443 > cacert.pem
curl
客户端:curl --cacert cacert.pem --location --silent https://${API_HOST}
此外,还可以使用wget和忽略使用:wget --no-check-certificate https://${API_HOST}
的证书。
https://unix.stackexchange.com/questions/451207
复制相似问题