LoginSignup
7
6

More than 3 years have passed since last update.

curlコマンドでSSLクライアント認証を行うには

Posted at

概要

SSLクライアント証明書(p12ファイル)からPEMファイル(鍵付き証明書)を作成し、curlコマンドでSSLクライアント認証を行う。

実行環境

CentOS Linux release 7.5.1804 (Core)

手順

openssl インストール

opensslコマンドでPEMファイルを生成するので、opensslコマンドがない場合は下記手順を実行してください。

$ curl -O https://www.openssl.org/source/openssl-1.0.2n.tar.gz .
$ tar xvzf openssl-1.0.2n.tar.gz
$ cd openssl-1.0.2n
$ ./config -fPIC shared
$ make
$ make install
$ ln -sf /usr/local/ssl/bin/openssl /usr/local/bin/openssl

PEMファイル作成

opensslコマンドで鍵付き証明書を作成する。

$ openssl pkcs12 -in file.p12 -out cert.pem -nodes -clcerts

curlコマンドでSSLクライアント認証を行う

PEFファイルのパスは、その階層にいても相対パスまたは絶対パスで書く。

$ curl -E ./cert.pem URL

Authorization, Bearer トークンを使ったAPIがあった場合などは下記のようにヘッダにトークンを指定すれば認証できる。

$ curl -H "Authorization: xxxxxxxx" -E ./cert.pem URL

以上!

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6