- 追加された行はこの色です。
- 削除された行はこの色です。
「[[マイクロソフト系技術情報 Wiki>http://techinfoofmicrosofttech.osscons.jp/]]」は、「[[Open棟梁Project>https://github.com/OpenTouryoProject/]]」,「[[OSSコンソーシアム .NET開発基盤部会>https://www.osscons.jp/dotNetDevelopmentInfrastructure/]]」によって運営されています。
-戻る
--[[証明書]]
--[[SSL/TLS]]
--[[.NETの署名・暗号化アルゴリズム]]
* 目次 [#aa46b0c8]
#contents
*概要 [#v2890f24]
-SSL・TLSプロトコルのOSS。
-[[SSL/TLS]]プロトコルのOSS。
-C言語で開発されているため、クロスプラットフォーム。
**暗号化ライブラリ [#dbb192d0]
ユーティリティに暗号化ライブラリを含む。
**[[インストール>#p1808afd]] [#cdf95605]
**証明書操作 [#a9e66640]
証明書生成から、色々な証明書操作が可能。
***[[pem関連>証明書#mde70013]] [#h9add398]
***各種証明書操作 [#c4bcd4ea]
-秘密鍵の生成(*.key or *.pem)
-証明書署名要求(*.csr)の生成~
証明書署名要求(CSR: Certificate Signing Request)
-証明書の生成(*.crt, *.cer)の生成~
--証明書(CRT: CERTIFICATE)
--*.crt: Unix or Linux
--*.cer: Windows
-*.pfxの生成(*.pfx or *.pem)
-*.pfxから単離
--証明書(*.cer or *.pem)
--公開鍵(*.key or *.pem)
***[[pem化>証明書#mde70013]] [#h9add398]
バイナリ形式ファイルを[[pem化>証明書#mde70013]]できる。
***デバッグ [#vd935428]
-中身をダンプできるので、これを使ってデバッグできる。
-これにより、X509Certificate、X509Certificate2等の問題を切り分けられる。
*詳細 [#ef153ac4]
**暗号化ライブラリ [#dbb192d0]
ユーティリティに暗号化ライブラリを含む。
**暗号化ライブラリ [#w3b59557]
[[.NET Standard]]では、OpenSSLベースのプロバイダも提供され始めている(.NET Platform Extensions ?の 2.1以上で使用できる模様)。
***C言語 [#s2816266]
***プロバイダ [#va0adf42]
以下のプロバイダがOpenSslベースのプロバイダとして提供されいている。~
https://github.com/dotnet/corefx/tree/master/src/System.Security.Cryptography.OpenSsl/src/System/Security/Cryptography
-RSAOpenSsl
-DSAOpenSsl
-ECDiffieHellmanOpenSsl
-ECDsaOpenSsl
#include <openssl/evp.h>
#include <openssl/aes.h>
***ネイティブ実装 [#s6dfd72f]
NuGetで検索すると以下のようなLinuxディストリビューション毎のネイティブ実装がある事を確認できる。~
https://www.nuget.org/packages?q=runtime.native.System.Security.Cryptography.OpenSsl
|#|>|名前空間|h
|~|プラットフォーム|・・・|h
|1|runtime.debian.8-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|2|runtime.opensuse.42.1-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|3|runtime.rhel.7-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|4|runtime.fedora.24-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|5|runtime.opensuse.13.2-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|6|runtime.ubuntu.14.04-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|7|runtime.fedora.23-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|8|runtime.osx.10.10-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|9|runtime.ubuntu.16.04-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|10|runtime.ubuntu.16.10-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|11|runtime.opensuse.42.3-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|12|runtime.fedora.28-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|13|runtime.ubuntu.18.04-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|14|runtime.debian.9-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|15|runtime.fedora.27-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
-参考
--OpenSSL ライブラリを使ったハッシュ生成、~
暗号化(RSA, AES)、復号処理(RSA, AES)、~
署名生成(RSA)、署名検証(RSA) - Qiita~
https://qiita.com/dwarfJP/items/f849dd904d4c85eec38d
**証明書操作 [#r4f83894]
***各言語 [#a61200b8]
-[[.NET Core on Linux>#w3b59557]]~
下位が、CAPI(CSP)、CNGなどではなく、~
OpenSSLプロバイダとなっている。
-'*.pfx を ...
-Java~
javax.crypto.*など。
-Ruby~
OpenSSL::Cipherクラスなど。
-PHP~
Crypt::CBCモジュールなど。
*詳細 [#ef153ac4]
**証明書操作(RSA) [#r4f83894]
***基本 [#k18a6fe8]
in, outを拡張子付きで明示することで制御した方がイイ。
-入出力フォーマット
-- -inform DER|PEM|NET~
入力ファイルの書式(拡張子から自動判別する)
-- -outform DER|PEM|NET~
出力ファイルの書式(拡張子から自動判別する)
-入出力ファイル
デフォルトは、標準出力
-- -in filename~
入力する証明書のファイル名を指定。
-- -out filename~
出力する証明書のファイル名を指定。
-出力方式
-- -text~
テキスト形式で出力
-- -noout~
出力しない
*** *.pfxの生成 [#wd296f49]
キーペアを生成
-秘密鍵の単品生成
>openssl genrsa -rand rand.dat -out private-key.pem 2048
-- -randは無くてもOK
-- 最後の2048は鍵長
-秘密鍵の単品生成~
(最後の2048は鍵長)
>openssl genrsa -out private-key.pem 2048
-証明書の単品生成~
以下の2フェーズから成る。
--証明書署名要求(CSR: Certificate Signing Request)の生成~
最低限、「Common Name(CN)」さえ入力されていれば、通る。
>openssl req -new -key private-key.pem > csr.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:.
State or Province Name (full name) [Some-State]:.
Locality Name (eg, city) []:.
Organization Name (eg, company) [Internet Widgits Pty Ltd]:.
Organizational Unit Name (eg, section) []:.
Common Name (e.g. server FQDN or YOUR name) []:x
Email Address []:.
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:.
An optional company name []:.
--証明書の生成
>openssl x509 -in csr.csr -days 365000 -req -signkey private-key.pem > crt.crt
>openssl x509 -in csr.csr -days 365000 -req -signkey private-key.pem > cer.cer
-秘密鍵と証明書から*.pfxを生成する。
>openssl pkcs12 -export -out pfx.pfx -inkey private-key.pem -in crt.crt
>openssl pkcs12 -export -out pfx.pfx -inkey private-key.pem -in cer.cer
Enter Export Password:
Verifying - Enter Export Password:
*** *.cer に変換 [#vb447469]
キーペアから公開鍵(証明書)を分離
'*.pfxから、公開鍵 or 証明書を出力
-PUBLIC KEY, CERTIFICATEを出力
>openssl pkcs12 -in XXX.pfx -out XXX.cer -nokeys -clcerts
-秘密鍵&公開鍵の取り出し
>openssl pkcs12 -in ca.pfx -nocerts -nodes -out ca.key
Enter Import Password:
MAC verified OK
-PUBLIC KEYのみ出力
・・・
-証明書の取り出し
>openssl pkcs12 -in ca.pfx -clcerts -nokeys -out ca.cer
Enter Import Password:
MAC verified OK
-CERTIFICATEのみ出力
・・・
Enter Import Password:
※ 署名検証は、PUBLIC KEY, CERTIFICATEの何れか1つがあれば可能。
*** *.pem に変換 [#me647f08]
-キーペアをpemに変換
-*.pfxをpemに変換
--pemの秘密鍵を暗号化する場合
>openssl pkcs12 -in XXX.pfx -out XXX.pem
Enter Import Password:
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
--pemの秘密鍵を暗号化しない場合
>openssl pkcs12 -in pfx.pfx -out XXX.pem -nodes
Enter Import Password:
-公開鍵(証明書)をpemに変換
-*.cer を pemに変換
>openssl x509 -in XXX.cer -pubkey -out XXX.pem
**暗号化ライブラリ (.NET) [#w3b59557]
[[.NET Standard]]では、OpenSSLベースのプロバイダも提供され始めている~
(.NET Platform Extensions?の 2.1以上で使用できる模様)。
***プロバイダ [#va0adf42]
以下のプロバイダがOpenSslベースのプロバイダとして提供されいている。~
https://github.com/dotnet/corefx/tree/master/src/System.Security.Cryptography.OpenSsl/src/System/Security/Cryptography
-RSAOpenSsl
-DSAOpenSsl
-ECDiffieHellmanOpenSsl
-ECDsaOpenSsl
***ネイティブ実装 [#s6dfd72f]
NuGetで検索すると以下のようなLinuxディストリビューション毎のネイティブ実装がある事を確認できる。~
https://www.nuget.org/packages?q=runtime.native.System.Security.Cryptography.OpenSsl
|#|>|名前空間|h
|~|プラットフォーム|・・・|h
|1|runtime.debian.8-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|2|runtime.opensuse.42.1-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|3|runtime.rhel.7-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|4|runtime.fedora.24-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|5|runtime.opensuse.13.2-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|6|runtime.ubuntu.14.04-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|7|runtime.fedora.23-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|8|runtime.osx.10.10-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|9|runtime.ubuntu.16.04-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|10|runtime.ubuntu.16.10-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|11|runtime.opensuse.42.3-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|12|runtime.fedora.28-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|13|runtime.ubuntu.18.04-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|14|runtime.debian.9-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
|15|runtime.fedora.27-x64.runtime.native|.System.Security.Cryptography.OpenSsl|
*その他の証明書 [#d000b904]
**DSA証明書 [#odf24106]
***手順 [#l80a48a4]
-DSAパラメタを生成
>openssl dsaparam -out dsa.param 2048
-以下のコマンドで秘密鍵を生成
>openssl gendsa -out private-key.pem dsa.param
-以降、[[コチラ>#wd296f49]]以降の手順と同じ。
-通しで
openssl dsaparam -out dsa.param 2048
openssl gendsa -out private-key.pem dsa.param
openssl req -new -key private-key.pem > csr.csr
openssl x509 -in csr.csr -days 365000 -req -signkey private-key.pem > cer.cer
openssl pkcs12 -export -out pfx.pfx -inkey private-key.pem -in cer.cer
:openssl pkcs12 -in pfx.pfx -out cer.cer -nokeys -clcerts
***[[参考>#q5a319e3]] [#v9e0b878]
**ECDSA証明書 [#w0f78b28]
prime256v1 でCSR を作成する。~
(現時点では、prime256v1, secp384r1, secp521r1が各環境で使い物になるレベルらしい)
***手順 [#l15b864d]
-インストールされているopensslで使える楕円曲線暗号の種類を確認~
prime256v1, secp384r1, secp521r1等が含まれていることを確認する。
>openssl ecparam -list_curves
-以下のコマンドで秘密鍵を生成
>openssl ecparam -out private-key.pem -name prime256v1 -genkey
-以降、[[コチラ>#wd296f49]]以降の手順と同じ。
-通しで
openssl ecparam -list_curves
openssl ecparam -out private-key.pem -name prime256v1 -genkey
openssl req -new -key private-key.pem > csr.csr
openssl x509 -in csr.csr -days 365000 -req -signkey private-key.pem > cer.cer
openssl pkcs12 -export -out pfx.pfx -inkey private-key.pem -in cer.cer
:openssl pkcs12 -in pfx.pfx -out cer.cer -nokeys -clcerts
***[[参考>#h729c131]] [#y249eeb8]
**SSLサーバ証明書 [#q1310f25]
***[[証明書発行要求を作成する例>IISのSSL設定#wc42b90a]] [#v0c76843]
***[[証明書発行要求に応答する例>IISのSSL設定#b1ec45f2]] [#t4949870]
**SSLクライアント証明書 [#q1310f25]
***[[証明書発行要求を作成する例>Mosquitto#k649a644]] [#g20300c7]
***[[証明書発行要求に応答する例>Mosquitto#k649a644]] [#c4c708c4]
*参考 [#q3fcc1da]
-OpenSSL - Wikipedia~
https://ja.wikipedia.org/wiki/OpenSSL
-OpenSSLについて~
http://ash.jp/sec/openssl.htm
**暗号化ライブラリ [#t6f513aa]
**証明書操作 [#fe7a7c51]
**証明書操作 [#fe7a7c51]
***基本操作 [#t5c3930c]
-OpenSSLでpfx形式、PKCS#12形式をPEM形式に変換する:新米システム管理者の覚書~
http://system-admin.seesaa.net/article/94984370.html
-opensslコマンド使い方まとめ | KentaKomai Blog~
http://komaken.me/blog/2015/12/26/openssl%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E4%BD%BF%E3%81%84%E6%96%B9%E3%81%BE%E3%81%A8%E3%82%81/
***DSA証明書生成 [#q5a319e3]
-OpenSSL(1) コマンドライン - s-kitaの日記~
http://d.hatena.ne.jp/s-kita/20090130/1233325598
-お勉強 - なんかてきとうに~
Linuxのお勉強(OpenSSLを使ってみる)~
https://calkinos.hatenablog.com/entry/2014/10/23/120613
***ECDSA証明書生成 [#h729c131]
-ECCのCSR生成方法~
https://knowledge.digicert.com/ja/jp/solution/SO23005.html
-ECDSAなSSL証明書を作ってみる – がとらぼ~
https://gato.intaa.net/net/ecdsa_ssl_cert
-Let's Encrypt の証明書をECDSA(ECC: 楕円曲線暗号)で作成する - Qiita~
https://qiita.com/TsutomuNakamura/items/e2e7be7c1f4d1638454d
***@IT [#p1808afd]
-Tech TIPS - @IT
--WindowsにOpenSSLをインストールして証明書を取り扱う(基本編)~
http://www.atmarkit.co.jp/ait/articles/1601/29/news043.html
--Windows上で、証明書や秘密鍵をPEM形式に変換してエクスポートする~
http://www.atmarkit.co.jp/ait/articles/1602/05/news039.html
***Qiita [#habd5321]
-opensslコマンドの使い方~
https://qiita.com/hana_shin/items/6d9de0847a06d8ee95cc
-kunichiko
--RSA鍵、証明書のファイルフォーマットについて~
https://qiita.com/kunichiko/items/12cbccaadcbf41c72735
--OpenSSLコマンドによる公開鍵暗号、電子署名の方法~
http://qiita.com/kunichiko/items/3c0b1a2915e9dacbd4c1
-SSLを利用するための自己証明書(オレオレ証明書)の設定メモ~
https://qiita.com/clown0082/items/551d7c081ff6b41b1717
-おれおれ認証局になっておれおれSSL証明書を発行してやる方法~
https://qiita.com/suin/items/37313aee4543c5d01285
***Stack Overflow [#n709fb95]
-security - Convert .pfx to .cer - Stack Overflow~
http://stackoverflow.com/questions/403174/convert-pfx-to-cer
-openssl - Extract public key from certificate in DER format~
http://stackoverflow.com/questions/13539535/extract-public-key-from-certificate-in-der-format
-, etc.
***その他 [#z8d3b676]
-SSL サーバ証明書:DigiCert(デジサート)
--証明書ファイルの種類とopensslでの変換方法~
https://rms-digicert.ne.jp/howto/basis/file_types.html
--openssl コマンドとは~
https://rms-digicert.ne.jp/howto/basis/openssl_command.html#read_cert
-OpenSSL 入門 | WEB ARCH LABO~
http://weblabo.oscasierra.net/openssl/
--OpenSSL で SSL 自己証明書を発行する手順~
http://weblabo.oscasierra.net/openssl-gencert-1/
--OpenSSL で RSA の秘密鍵を作成する方法~
http://weblabo.oscasierra.net/openssl-genrsa-secret-1/
--OpenSSL で RSA の公開鍵を作成する方法~
http://weblabo.oscasierra.net/openssl-genrsa-public-1/
--OpenSSL で RSA 公開鍵暗号を試してみよう~
http://weblabo.oscasierra.net/openssl-public-key-crypto/
--OpenSSL で SSL 自己証明書を発行する手順~
http://weblabo.oscasierra.net/openssl-gencert-1/
**galife [#o9cf4b14]
-OpenSSL を Windows にインストールする方法~
https://garafu.blogspot.com/2018/07/openssl-install-windows.html
-OpenSSL で Windows に プライベート認証局 を 構築する方法~
https://garafu.blogspot.com/2018/07/openssl-setup-ca-on-windows.html
-OpenSSL で 証明書要求を作成、署名する方法~
https://garafu.blogspot.com/2018/07/openssl-create-sever-cert.html
----
Tags: [[:セキュリティ]], [[:暗号化]], [[:証明書]], [[:.NET Core]], [[:.NET Standard]]