curlコマンドでのプロキシ認証に証明書利用

curl -o c:\temp\test.txt https://nets-tip.com/wp-content/uploads/2025/12/test.txt

curl ― 証明書認証プロキシ利用のサンプル
PEM形式(.crt + .key)の場合

curl ― 証明書認証プロキシ利用のサンプル
PEM形式(.crt + .key)の場合
curl -x https://proxy.example.com:443 \
--proxy-cert client.crt \
--proxy-key client.key \
https://target.example.com

PKCS#12(.p12 / .pfx)の場合(証明書と鍵が 1 ファイルにまとまっている場合)
curl -x https://proxy.example.com:443 \
--proxy-cert proxy_client.p12:パスワード \
--proxy-cert-type P12 \
https://target.example.com

プロキシ認証 + 証明書(ID/Pass も必要な場合)
curl -x https://proxy.example.com:443 \
--proxy-user user1:password123 \
--proxy-cert client.crt \
--proxy-key client.key \
https://target.example.com
RHEL9:curl 証明書認証プロキシ利用サンプル
RHEL9 の curl は OpenSSL3 を利用しており、以下の形式が標準で使用が可能

PEM形式(client.crt + client.key)の場合
curl -x https://proxy.example.com:443 \
--proxy-cert /etc/pki/tls/certs/client.crt \
--proxy-key /etc/pki/tls/private/client.key \
--proxy-cacert /etc/pki/tls/certs/proxy_ca.crt \
https://target.example.com

・ --proxy-cert :プロキシに送るクライアント証明書
・ --proxy-key :秘密鍵
・ --proxy-cacert:プロキシサーバの証明書を検証するための CA
・ プロキシが HTTPS でない場合(http://)は証明書認証は不可

PKCS#12(.p12 / .pfx)の場合
curl -x https://proxy.example.com:443 \
--proxy-cert /etc/pki/tls/certs/proxy_client.p12:mypass \
--proxy-cert-type P12 \
--proxy-cacert /etc/pki/tls/certs/proxy_ca.crt \
https://target.example.com

.p12 内にクライアント証明書と鍵が両方入っている
:mypass はパスワード(空の場合は省略可)

ID/Password + 証明書の両方が要求される場合
curl -x https://proxy.example.com:443 \
--proxy-user user1:password123 \
--proxy-cert /etc/pki/tls/certs/client.crt \
--proxy-key /etc/pki/tls/private/client.key \
--proxy-cacert /etc/pki/tls/certs/proxy_ca.crt \
https://target.example.com

CA証明書として使う場合(--proxy-cacert)
curl -x https://proxy.example.com:443 \
--proxy-cacert proxy_ca.der \
https://target.example.com

ご参考まで

関連記事

TOP