「[[マイクロソフト系技術情報 Wiki>http://techinfoofmicrosofttech.osscons.jp/]]」は、「[[Open棟梁Project>https://github.com/OpenTouryoProject/]]」,「[[OSSコンソーシアム .NET開発基盤部会>https://www.osscons.jp/dotNetDevelopmentInfrastructure/]]」によって運営されています。

-戻る
--[[証明書]]
--[[.NETの署名・暗号化アルゴリズム]]

* 目次 [#aa46b0c8]
#contents

*概要 [#v2890f24]
-SSL・TLSプロトコルのOSS。
-C言語で開発されているため、クロスプラットフォーム。

**証明書操作 [#a9e66640]
証明書生成から、色々な証明書操作が可能。

***各種証明書操作 [#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等の問題を切り分けられる。

**暗号化ライブラリ [#dbb192d0]
ユーティリティに暗号化ライブラリを含む。

*詳細 [#ef153ac4]

**証明書操作(RSA) [#r4f83894]

***基本 [#k18a6fe8]
in, outを拡張子付きで明示することで制御した方がイイ。

-入出力フォーマット
-- -inform DER|PEM|NET~
入力ファイルの書式(拡張子から自動判別する)
-- -outform DER|PEM|NET~
出力ファイルの書式(拡張子から自動判別する)

-入出力ファイル
デフォルトは、標準出力
-- -in filename~
入力する証明書のファイル名を指定。
-- -out filename~
出力する証明書のファイル名を指定。

-出力方式
-- -text~
テキスト形式で出力
-- -noout~
出力しない

*** *.pfxの生成 [#wd296f49]

-秘密鍵の単品生成~
(最後の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

-秘密鍵と証明書から*.pfxを生成する。
 >openssl pkcs12 -export -out pfx.pfx -inkey private-key.pem -in crt.crt
 Enter Export Password:
 Verifying - Enter Export Password:

*** *.cer に変換 [#vb447469]
'*.pfxから、公開鍵 or 証明書を出力

-PUBLIC KEY, CERTIFICATEセクションを出力
 >openssl pkcs12 -in XXX.pfx -out XXX.cer -nokeys -clcerts
 Enter Import Password:

-PUBLIC KEYセクションのみ出力
 ・・・
 Enter Import Password:

-CERTIFICATEセクションのみ出力
 ・・・
 Enter Import Password:

※ 署名検証は、PUBLIC KEY, CERTIFICATEの何れか1つがあれば可能。

*** *.pem に変換 [#me647f08]
-*.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:

-*.cer を pemに変換
 >openssl x509 -in XXX.cer -pubkey -out XXX.pem

**暗号化ライブラリ [#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]

***[[参考>#q5a319e3]] [#v9e0b878]

**ECDSA証明書 [#w0f78b28]
prime256v1 でCSR を作成する。~
(現時点では、prime256v1, secp384r1, secp521r1が各環境で使い物になるレベルらしい)

***手順 [#l15b864d]
-以下のコマンドで秘密鍵を生成
 openssl ecparam -out private-key.pem -name prime256v1 -genkey

-以降、[[コチラ>#wd296f49]]以降の手順と同じ。

***[[参考>#h729c131]] [#y249eeb8]

*参考 [#q3fcc1da]
-OpenSSL - Wikipedia~
https://ja.wikipedia.org/wiki/OpenSSL

-OpenSSLについて~
http://ash.jp/sec/openssl.htm

-opensslコマンドの使い方 - Qiita~
https://qiita.com/hana_shin/items/6d9de0847a06d8ee95cc

**暗号化ライブラリ [#t6f513aa]

**証明書操作 [#fe7a7c51]

***基本操作 [#t5c3930c]
-OpenSSLでpfx形式、PKCS#12形式をPEM形式に変換する:新米システム管理者の覚書~
http://system-admin.seesaa.net/article/94984370.html

***DSA証明書生成 [#q5a319e3]

***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]
-kunichiko
--RSA鍵、証明書のファイルフォーマットについて~
https://qiita.com/kunichiko/items/12cbccaadcbf41c72735
--OpenSSLコマンドによる公開鍵暗号、電子署名の方法~
http://qiita.com/kunichiko/items/3c0b1a2915e9dacbd4c1

-SSLを利用するための自己証明書(オレオレ証明書)の設定メモ~
https://qiita.com/clown0082/items/551d7c081ff6b41b1717

***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/

----
Tags: [[:セキュリティ]], [[:暗号化]], [[:証明書]], [[:.NET Core]], [[:.NET Standard]]

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS