マイクロソフト系技術情報 Wiki」は、「Open棟梁Project」,「OSSコンソーシアム .NET開発基盤部会」によって運営されています。

目次

概要

  • SSL/TLSプロトコルのOSS。
  • C言語で開発されているため、クロスプラットフォーム。

インストール

証明書操作

証明書生成から、色々な証明書操作が可能。

各種証明書操作

  • 秘密鍵の生成(*.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化

バイナリ形式ファイルをpem化できる。

デバッグ

  • 中身をダンプできるので、これを使ってデバッグできる。
  • これにより、X509Certificate、X509Certificate2等の問題を切り分けられる。

暗号化ライブラリ

ユーティリティに暗号化ライブラリを含む。

C言語

#include        <openssl/evp.h>
#include        <openssl/aes.h>

各言語

  • .NET Core on Linux
    下位が、CAPI(CSP)、CNGなどではなく、
    OpenSSLプロバイダとなっている。
  • Java
    javax.crypto.*など。
  • Ruby
    OpenSSL::Cipherクラスなど。
  • PHP
    Crypt::CBCモジュールなど。

詳細

証明書操作(RSA)

基本

in, outを拡張子付きで明示することで制御した方がイイ。

  • 入出力フォーマット
    • -inform DER|PEM|NET
      入力ファイルの書式(拡張子から自動判別する)
    • -outform DER|PEM|NET
      出力ファイルの書式(拡張子から自動判別する)
  • 入出力ファイル デフォルトは、標準出力
    • -in filename
      入力する証明書のファイル名を指定。
    • -out filename
      出力する証明書のファイル名を指定。
  • 出力方式
    • -text
      テキスト形式で出力
    • -noout
      出力しない

*.pfxの生成

  • 秘密鍵の単品生成
    (最後の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 > cer.cer
  • 秘密鍵と証明書から*.pfxを生成する。
    >openssl pkcs12 -export -out pfx.pfx -inkey private-key.pem -in cer.cer
    Enter Export Password:
    Verifying - Enter Export Password:

*.cer に変換

'*.pfxから、公開鍵 or 証明書を出力

  • 秘密鍵&公開鍵の取り出し
    >openssl pkcs12 -in ca.pfx -nocerts -nodes -out ca.key
    Enter Import Password:
    MAC verified OK
  • 証明書の取り出し
    >openssl pkcs12 -in ca.pfx -clcerts -nokeys -out ca.cer
    Enter Import Password:
    MAC verified OK

*.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:
  • *.cer を pemに変換
    >openssl x509 -in XXX.cer -pubkey -out XXX.pem

暗号化ライブラリ (.NET)

.NET Standardでは、OpenSSLベースのプロバイダも提供され始めている
(.NET Platform Extensions?の 2.1以上で使用できる模様)。

プロバイダ

以下のプロバイダがOpenSsl?ベースのプロバイダとして提供されいている。
https://github.com/dotnet/corefx/tree/master/src/System.Security.Cryptography.OpenSsl/src/System/Security/Cryptography

  • RSAOpenSsl?
  • DSAOpenSsl?
  • ECDiffieHellmanOpenSsl?
  • ECDsaOpenSsl?

ネイティブ実装

NuGetで検索すると以下のようなLinuxディストリビューション毎のネイティブ実装がある事を確認できる。
https://www.nuget.org/packages?q=runtime.native.System.Security.Cryptography.OpenSsl

#名前空間
プラットフォーム・・・
1runtime.debian.8-x64.runtime.native.System.Security.Cryptography.OpenSsl?
2runtime.opensuse.42.1-x64.runtime.native.System.Security.Cryptography.OpenSsl?
3runtime.rhel.7-x64.runtime.native.System.Security.Cryptography.OpenSsl?
4runtime.fedora.24-x64.runtime.native.System.Security.Cryptography.OpenSsl?
5runtime.opensuse.13.2-x64.runtime.native.System.Security.Cryptography.OpenSsl?
6runtime.ubuntu.14.04-x64.runtime.native.System.Security.Cryptography.OpenSsl?
7runtime.fedora.23-x64.runtime.native.System.Security.Cryptography.OpenSsl?
8runtime.osx.10.10-x64.runtime.native.System.Security.Cryptography.OpenSsl?
9runtime.ubuntu.16.04-x64.runtime.native.System.Security.Cryptography.OpenSsl?
10runtime.ubuntu.16.10-x64.runtime.native.System.Security.Cryptography.OpenSsl?
11runtime.opensuse.42.3-x64.runtime.native.System.Security.Cryptography.OpenSsl?
12runtime.fedora.28-x64.runtime.native.System.Security.Cryptography.OpenSsl?
13runtime.ubuntu.18.04-x64.runtime.native.System.Security.Cryptography.OpenSsl?
14runtime.debian.9-x64.runtime.native.System.Security.Cryptography.OpenSsl?
15runtime.fedora.27-x64.runtime.native.System.Security.Cryptography.OpenSsl?

その他の証明書

DSA証明書

手順

  • DSAパラメタを生成
    >openssl dsaparam -out dsa.param 2048
  • 以下のコマンドで秘密鍵を生成
    >openssl gendsa -out private-key.pem dsa.param
  • 以降、コチラ以降の手順と同じ。
  • 通しで
    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

参考

ECDSA証明書

prime256v1 でCSR を作成する。
(現時点では、prime256v1, secp384r1, secp521r1が各環境で使い物になるレベルらしい)

手順

  • インストールされているopensslで使える楕円曲線暗号の種類を確認
    prime256v1, secp384r1, secp521r1等が含まれていることを確認する。
    >openssl ecparam -list_curves
  • 以下のコマンドで秘密鍵を生成
    >openssl ecparam -out private-key.pem -name prime256v1 -genkey
  • 以降、コチラ以降の手順と同じ。
  • 通しで
    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

参考

SSLサーバ証明書

証明書発行要求を作成する例

証明書発行要求に応答する例

SSLクライアント証明書

証明書発行要求を作成する例

証明書発行要求に応答する例

参考

証明書操作

基本操作

DSA証明書生成

ECDSA証明書生成

@IT

Qiita

Stack Overflow

その他

galife


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


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2021-08-22 (日) 12:51:00 (971d)