自己証明書テスト

■1.ルート証明書
$rootca = New-SelfSignedCertificate `
  -Subject NCSI_rootca `
  -NotAfter $(Get-Date).AddDays(1825) `
  -CertStoreLocation cert:\CurrentUser\My `
  -KeyUsage CertSign,CRLSign
  
certmgr
    個人 > 証明書 に作成
    ※信頼されていない

■2.ルート証明書エクスポート
Export-Certificate -Cert $rootca -FilePath NCSI_rootca.cer

実行ユーザーのカレントディレクトリに証明書をエクスポート

■3.信頼されたルート証明機関にインポート
Import-Certificate -Cert cert:\CurrentUser\Root -FilePath NCSI_rootca.cer

certmgr
    個人 > 証明書
    ※信頼されていないが解消

    信頼されたルート証明機関 > 証明書 に登録される
    中間証明書機関 > 証明書 に登録される

■4.サーバ証明書作成
$rootca = Get-ChildItem `
  -Path cert:\CurrentUser\My | where { $_.Subject -eq "CN=NCSI_rootca" }
 
$server = New-SelfSignedCertificate `
  -DnsName "www.vdimsconnecttest.com" `
  -NotAfter $(Get-Date).AddDays(1825) `
  -CertStoreLocation cert:\CurrentUser\My `
  -Signer $rootca `
  -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.1")
  
certmgr
    個人 > 証明書
    ⇒証明書が作成される
     発行先:localhost
     発行者:testrootca

■5.クライアント証明書作成

$rootca = Get-ChildItem `
  -Path cert:\CurrentUser\My | where { $_.Subject -eq "CN=NCSI_rootca" }
 
$client= New-SelfSignedCertificate `
  -Subject "CN=Chibatest, O=Kaisha, OU=Busho, L=Shinjuku, S=Tokyo, C=Japan" `
  -NotAfter $(Get-Date).AddDays(1865) `
  -CertStoreLocation cert:\CurrentUser\My `
  -Signer $rootca `
  -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.2")
 
$password = ConvertTo-SecureString -String "password" -Force -AsPlainText
Export-PfxCertificate -Cert $client -FilePath NCSIrootca.pfx -Password $password

certmgr
    個人 > 証明書
    ⇒証明書が作成される(クライアント認証)