Adding to user3258557 's answer, let's say that you need to test some fake server of your own with your own root CA etc. And you just don't want to use curl's -k
option.
First, let's create a RSA key for your Root CA:
openssl genrsa -des3 -out rootCA.key 4096
Then, using that key, let's sign a certificate for our own CA:
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.crt
Now, you have a Root CA with private Key and Certificate.
Let's now generate keys and certificates for our own websites:
openssl genrsa -out mainsite.net.key 2048
Now, before creating the certificate, we will need a Certificate Signing Request (CSR) first. Then our Root CA will "sign" the CSR and generate the certificate for our website.
openssl req -new -key mainsite.net.key -out mainsite.net.csr
Let's finally create the certificate for our website:
openssl x509 -req -in mainsite.net.csr -CA rootCA.crt -CAkey rootCA.key -CAcreateserial -out mainsite.net.crt -days 500 -sha256
For ease of use, let's generate a .pem
file using our .crt
and .key
files as:
cat mainsite.net.key mainsite.net.crt > mainsite.net.pem
Now, you can run a simple server with this .pem
file. Say this server is running at 127.0.0.1:12345
For curl request, you can just do this:
curl --cacert "rootCA.crt" https://127.0.0.1:12345/
Going a step further, if you want to host multiple sites on a port using SNI, you can generate the key for each site, sign the CSR's and use a curl request like below:
curl --resolve subsite1.mainsite.net:12345:127.0.0.1 -X GET --cacert "rootCA.crt" --cert "subsite1.mainsite.net.crt" --key "subsite1.mainsite.net.key" https://subsite1.mainsite.net:12345/
– Alex Huszagh Dec 05 '16 at 15:12alias insecure-curl="curl -k"
curl
against other examples of common SSL mistakes and problems.curl -k
would also letcurl
tolerate a site with a self-signed certificate like https://self-signed.badssl.com/, it is not just a cert+hostname check. – Freiheit Apr 05 '19 at 18:56-k
were shown against EVERY case at BadSSL.com? I think that is scriptable.curl
without-k
should just work against the "good" cases and should fail against the "bad" cases. Thencurl -k
should work against all cases, good and bad. – Freiheit Apr 08 '19 at 13:35-k
as in inseKure? Nice.. :) – Kristof Jozsa Jul 06 '21 at 11:54