⇤ ← 2016-05-05 18:06:22時点のリビジョン1
サイズ: 6726
コメント:
|
サイズ: 16917
コメント:
|
削除された箇所はこのように表示されます。 | 追加された箇所はこのように表示されます。 |
行 9: | 行 9: |
= ディスティングイッシュ名を決める = * 自らが作りたい、俺々SSLサーバー証明書のコモンネーム(CN)以外は本質的に必要ない。 * 管理責任等の明確化のために、組織名(O)や部門名(OU)を加えるとなおよしで、その場合、国名(C)、都道府県(ST)、市区町村(L)を含めるのは当然かと。 * また、ワイルドカード証明書を作りたい場合も、同一手順で問題無いが、SAN(Subject Alternative Name)を行いたい場合は、もう少し手順が必要となる。 * ここでは自身のドメイン(例では ninth-nine.com のこと)をSANしてみる:-)。 ||<#FFFF00> 項目名 ||<#FFFF00> 略号 ||<#FFFF00> 設定例 ||<#FFFF00> 備考 || || 国名(Country name) || C || JP || || || 都道府県名(STate or province name) || ST || || || || 市区町村(Locality name) || L || || || || 組織名(Organization name) || O || || || || 部門名(Organization Unit name) || OU || || || || コモンネーム(Common Name) || CN || *.ninth-nine.com || || || メールアドレス(emailAddress) || emailAddress || || || 上記をまとめたのが下記の通りとなる。省略した項目は項目名から省略する(一切残さない)。 {{{ /C=JP/CN=*.ninth-nine.com }}} = openssl.cnfの準備 = == 関連セクション・項目一覧 == === req セクション(必須) === ||<#FFFF00> 項目名 ||<#FFFF00> 値 ||<#FFFF00> 意味 ||<FFFF00> オプション ||<#FFFF00> 必須 ||<#FFFF00> 備考 || || distinguished_name || セクション名 || ディスティングイッシュ名セクションの指定 || なし || 必須 || || || attributes || セクション名 || 属性セクションの指定 || なし || オプション || 通常不要 || || x509_extensions || セクション名 || 署名拡張セクションの指定 || -extensions セクション名 || オプション || || || req_extensions || セクション名 || 要求拡張セクションの指定 || -reqexts セクション名 || オプション || 本件では不要 || || default_md || sha1 / sha256 等 || 署名アルゴリズムの指定 || -sha / -sha256 等 || オプション || 指定が無い場合 -sha などに解釈 || || default_bits || 数字 || ビット数 || なし || 必須 || 何の?公開鍵暗号アルゴリズムによる || || default_keyfile || パス名 || 秘密鍵のファイル名 || -keyout パス名 || オプション || 指定が無い場合標準出力へ || || RANDFILE || パス名 || 乱数シードのファイル名 || -rand パス名 || オプション || 厳密には RANDFILE と -rand は違う || || input_password || パスワード || 指定された秘密鍵のパスワード || -passin パスワード || オプション || 事前に秘密鍵は作らないので不要 || || output_password || パスワード || 保存する秘密鍵のパスワード || -passout パスワード || オプション || パスワード保護しないので指定しない || || encrypt_rsa_key || no || 秘密鍵を 3DES 暗号化するかどうか || -nodes || オプション || encrypt_key と同義(compat) || || encrypt_key || no || 秘密鍵を 3DES 暗号化するかどうか || -nodes || オプション || 3DES 以外の選択肢無し || || prompt || no || プロンプトを表示するかどうか || なし || オプション || || || string_mask || default / utf8only / pkix / nombstr / WARNING / MASK:値 || 特定フィールドの文字列型で使用 || なし || 必須 || || || utf8 || yes || UTF8 文字列を解釈する || -utf8 || オプション || 未指定の場合 ASCII || === distinguished_name セクション(必須) === {{{-subj}}} オプションで必要な項目を指定するため、本セクションでの指定は無い。ただし、セクション名自体は存在する必要がある。 === x509_extensions(オプション) === ||<#FFFF00> 項目名 ||<#FFFF00> 値 ||<#FFFF00> 意味 ||<#FFFF00> 備考 || || subjectKeyIdentifier || hash || || || || authorityKeyIdentifier || keyid || || || || || keyid:always || || || || || issuer || || || || basicConstraints || CA:FALSE || CA機能無し || || || || CA:TRUE || CA機能有り || || || || pathlen:0~ || 認証チェインの深さ(0 は子供のみ、1 は孫まで、2 ...) || || || nsCertType || client || クライアント証明書 || || || || server || サーバー証明書 || || || || email || メール証明書(S/MIME) || || || || objsign || オブジェクト(コード)サイニング || || || || sslCA || 認証局 || || || || emailCA || メール認証局 || || || || objCA || オブジェクトサイニング認証局 || || || keyUsage || digitalSignature || デジタル署名 || || || || nonRepudiation || 否認不可 || || || || keyEncipherment || 鍵交換 || || || || dataEncipherment || データ交換 || || || || keyAgreement || || || || || keyCertSign || || || || || cRLSign || || || || || encipherOnly || 暗号化のみ || || || || decipherOnly || 複合化のみ || || || extendedKeyUsage || serverAuth || SSL/TLS Web Server Authentication. || || || || clientAuth || SSL/TLS Web Client Authentication. || || || || codeSigning || Code signing. || || || || emailProtection || E-mail Protection (S/MIME). || || || || timeStamping || Trusted Timestamping || || || || msCodeInd || Microsoft Individual Code Signing (authenticode) || || || || msCodeCom || Microsoft Commercial Code Signing (authenticode) || || || || msCTLSign || Microsoft Trust List Signing || || || || msSGC || Microsoft Server Gated Crypto || || || || msEFS || Microsoft Encrypted File System || || || || nsSGC || Netscape Server Gated Crypto || || || subjectAltName || DNS.n:ドメイン名 || || || == 設定ファイル == {{{ [req] distinguished_name = distinguished_name x509_extensions = x509_extensions string_mask = utf8only [distinguished_name] [x509_extensions] subjectKeyIdentifier = hash authorityKeyIdentifier = keyid,issuer basicConstraints = critical,CA:FALSE nsCertType = server keyUsage = digitalSignature, keyEncipherment extendedKeyUsage = serverAuth subjectAltName = DNS.1:*.ninth-nine.com, DNS.2:ninth-nine.com }}} = 自己署名証明書の作り方(RSA) = {{{ openssl req -newkey rsa:2048 -sha256 -nodes -subj '/C=JP/CN=*.ninth-nine.com' -out '/ssl/*.ninth-nine.com/*.ninth-nine.com,rsa2048-sha256,201601-201912,0.crt -keyout '/ssl/*.ninth-nine.com/*.ninth-nine.com,rsa2048-sha256,201601-201912,0.key -x509 -startdate '160101000000Z' -enddate '191231235959Z' -config 設定ファイル }}} = 自己署名証明書の作り方(ECDSA) = {{{ openssl req -newkey ec:<(openssl ecparam -name prime256v1) -sha256 -nodes -subj '/C=JP/CN=*.ninth-nine.com' -out '/ssl/*.ninth-nine.com/*.ninth-nine.com,prime256v1-sha256,201601-201912,0.crt -keyout '/ssl/*.ninth-nine.com/*.ninth-nine.com,prime256v1-sha256,201601-201912,0.key -x509 -startdate '160101000000Z' -enddate '191231235959Z' -config 設定ファイル }}} |
|
行 10: | 行 143: |
* FreeBSD 10.3-RELEASEのopensslコマンド(1.0.1s)にパッチを当てる。 | * FreeBSD 10.3-RELEASEのopensslコマンド(1.0.1s)に以下のパッチを当てる。 |
行 96: | 行 229: |
= ディスティングイッシュ名を決める = * 自らが作りたい、俺々SSLサーバー証明書のコモンネーム(CN)以外は本質的に必要ない。 * 管理責任等の明確化のために、組織名(O)や部門名(OU)を加えるとなおよしで、その場合、国名(C)、都道府県(ST)、市区町村(L)を含めるのは当然かと。 * また、ワイルドカード証明書を作りたい場合も、同一手順で問題無いが、SAN(Subject Alternative Name)を行いたい場合は、もう少し手順が必要となる。 * ここでは自身のドメイン(例では ninth-nine.com のこと)をSANしてみる:-)。 ||<#FFFF00> 項目名 ||<#FFFF00> 略号 ||<#FFFF00> 設定例 ||<#FFFF00> 備考 || || 国名(Country name) || C || JP || || || 都道府県名(STate or province name) || ST || || || || 市区町村(Locality name) || L || || || || 組織名(Organization name) || O || || || || 部門名(Organization Unit name) || OU || || || || コモンネーム(Common Name) || CN || *.ninth-nine.com || || || メールアドレス(emailAddress) || emailAddress || || || 上記をまとめたのが下記の通りとなる。省略した項目は項目名から省略する(一切残さない)。 {{{ /C=JP/CN=*.ninth-nine.com }}} = openssl.cnfの準備 = = 自己署名証明書の作り方 = {{{ openssl req -new -newkey ec:<(openssl ecparam -name prime256v1) -sha256 -nodes -subj '/C=JP/CN=*.ninth-nine.com' -out '/ssl/*.ninth-nine.com/*.ninth-nine.com,prime256v1-sha256,201601-201912,0.crt -keyout '/ssl/*.ninth-nine.com/*.ninth-nine.com,prime256v1-sha256,201601-201912,0.key -x509 -startdate '160101000000Z' -enddate '191231235959Z' -extensions exts }}} |
= 参考文献 = * [[https://www.openssl.org/docs/manmaster/apps/x509v3_config.html|x509v3_config(1)]] |
俺々SSLサーバー証明書の作り方
- 自己署名証明書の基本的な作り方について解説する。
- これは俺々認証局を作るのにも必要な基本的な技術であるためである。
- もちろん実運用的には、イントラネット内に閉じた環境のSSLサーバー証明書の運用など、実務でも使うことがある。
- 対インターネット向けなら、Let's Encryptはもちろんのこと、年額1000円~2000円程度の認証局があるので、そちらを利用されたし。
目次
ディスティングイッシュ名を決める
- 自らが作りたい、俺々SSLサーバー証明書のコモンネーム(CN)以外は本質的に必要ない。
- 管理責任等の明確化のために、組織名(O)や部門名(OU)を加えるとなおよしで、その場合、国名(C)、都道府県(ST)、市区町村(L)を含めるのは当然かと。
- また、ワイルドカード証明書を作りたい場合も、同一手順で問題無いが、SAN(Subject Alternative Name)を行いたい場合は、もう少し手順が必要となる。
- ここでは自身のドメイン(例では ninth-nine.com のこと)をSANしてみる:-)。
項目名 |
略号 |
設定例 |
備考 |
国名(Country name) |
C |
JP |
|
都道府県名(STate or province name) |
ST |
|
|
市区町村(Locality name) |
L |
|
|
組織名(Organization name) |
O |
|
|
部門名(Organization Unit name) |
OU |
|
|
コモンネーム(Common Name) |
CN |
*.ninth-nine.com |
|
メールアドレス(emailAddress) |
emailAddress |
|
|
上記をまとめたのが下記の通りとなる。省略した項目は項目名から省略する(一切残さない)。
/C=JP/CN=*.ninth-nine.com
openssl.cnfの準備
関連セクション・項目一覧
req セクション(必須)
項目名 |
値 |
意味 |
"FFFF00"の後に"="がありません。 オプション |
必須 |
備考 |
distinguished_name |
セクション名 |
ディスティングイッシュ名セクションの指定 |
なし |
必須 |
|
attributes |
セクション名 |
属性セクションの指定 |
なし |
オプション |
通常不要 |
x509_extensions |
セクション名 |
署名拡張セクションの指定 |
-extensions セクション名 |
オプション |
|
req_extensions |
セクション名 |
要求拡張セクションの指定 |
-reqexts セクション名 |
オプション |
本件では不要 |
default_md |
sha1 / sha256 等 |
署名アルゴリズムの指定 |
-sha / -sha256 等 |
オプション |
指定が無い場合 -sha などに解釈 |
default_bits |
数字 |
ビット数 |
なし |
必須 |
何の?公開鍵暗号アルゴリズムによる |
default_keyfile |
パス名 |
秘密鍵のファイル名 |
-keyout パス名 |
オプション |
指定が無い場合標準出力へ |
RANDFILE |
パス名 |
乱数シードのファイル名 |
-rand パス名 |
オプション |
厳密には RANDFILE と -rand は違う |
input_password |
パスワード |
指定された秘密鍵のパスワード |
-passin パスワード |
オプション |
事前に秘密鍵は作らないので不要 |
output_password |
パスワード |
保存する秘密鍵のパスワード |
-passout パスワード |
オプション |
パスワード保護しないので指定しない |
encrypt_rsa_key |
no |
秘密鍵を 3DES 暗号化するかどうか |
-nodes |
オプション |
encrypt_key と同義(compat) |
encrypt_key |
no |
秘密鍵を 3DES 暗号化するかどうか |
-nodes |
オプション |
3DES 以外の選択肢無し |
prompt |
no |
プロンプトを表示するかどうか |
なし |
オプション |
|
string_mask |
default / utf8only / pkix / nombstr / WARNING / MASK:値 |
特定フィールドの文字列型で使用 |
なし |
必須 |
|
utf8 |
yes |
UTF8 文字列を解釈する |
-utf8 |
オプション |
未指定の場合 ASCII |
distinguished_name セクション(必須)
-subj オプションで必要な項目を指定するため、本セクションでの指定は無い。ただし、セクション名自体は存在する必要がある。
x509_extensions(オプション)
項目名 |
値 |
意味 |
備考 |
subjectKeyIdentifier |
hash |
|
|
authorityKeyIdentifier |
keyid |
|
|
|
keyid:always |
|
|
|
issuer |
|
|
basicConstraints |
CA:FALSE |
CA機能無し |
|
|
CA:TRUE |
CA機能有り |
|
|
pathlen:0~ |
認証チェインの深さ(0 は子供のみ、1 は孫まで、2 ...) |
|
nsCertType |
client |
クライアント証明書 |
|
|
server |
サーバー証明書 |
|
|
メール証明書(S/MIME) |
|
|
|
objsign |
オブジェクト(コード)サイニング |
|
|
sslCA |
認証局 |
|
|
emailCA |
メール認証局 |
|
|
objCA |
オブジェクトサイニング認証局 |
|
keyUsage |
digitalSignature |
デジタル署名 |
|
|
nonRepudiation |
否認不可 |
|
|
keyEncipherment |
鍵交換 |
|
|
dataEncipherment |
データ交換 |
|
|
keyAgreement |
|
|
|
keyCertSign |
|
|
|
cRLSign |
|
|
|
encipherOnly |
暗号化のみ |
|
|
decipherOnly |
複合化のみ |
|
extendedKeyUsage |
serverAuth |
SSL/TLS Web Server Authentication. |
|
|
clientAuth |
SSL/TLS Web Client Authentication. |
|
|
codeSigning |
Code signing. |
|
|
emailProtection |
E-mail Protection (S/MIME). |
|
|
timeStamping |
Trusted Timestamping |
|
|
msCodeInd |
Microsoft Individual Code Signing (authenticode) |
|
|
msCodeCom |
Microsoft Commercial Code Signing (authenticode) |
|
|
msCTLSign |
Microsoft Trust List Signing |
|
|
msSGC |
Microsoft Server Gated Crypto |
|
|
msEFS |
Microsoft Encrypted File System |
|
|
nsSGC |
Netscape Server Gated Crypto |
|
subjectAltName |
DNS.n:ドメイン名 |
|
|
設定ファイル
[req] distinguished_name = distinguished_name x509_extensions = x509_extensions string_mask = utf8only [distinguished_name] [x509_extensions] subjectKeyIdentifier = hash authorityKeyIdentifier = keyid,issuer basicConstraints = critical,CA:FALSE nsCertType = server keyUsage = digitalSignature, keyEncipherment extendedKeyUsage = serverAuth subjectAltName = DNS.1:*.ninth-nine.com, DNS.2:ninth-nine.com
自己署名証明書の作り方(RSA)
openssl req -newkey rsa:2048 -sha256 -nodes -subj '/C=JP/CN=*.ninth-nine.com' -out '/ssl/*.ninth-nine.com/*.ninth-nine.com,rsa2048-sha256,201601-201912,0.crt -keyout '/ssl/*.ninth-nine.com/*.ninth-nine.com,rsa2048-sha256,201601-201912,0.key -x509 -startdate '160101000000Z' -enddate '191231235959Z' -config 設定ファイル
自己署名証明書の作り方(ECDSA)
openssl req -newkey ec:<(openssl ecparam -name prime256v1) -sha256 -nodes -subj '/C=JP/CN=*.ninth-nine.com' -out '/ssl/*.ninth-nine.com/*.ninth-nine.com,prime256v1-sha256,201601-201912,0.crt -keyout '/ssl/*.ninth-nine.com/*.ninth-nine.com,prime256v1-sha256,201601-201912,0.key -x509 -startdate '160101000000Z' -enddate '191231235959Z' -config 設定ファイル
パッチ
- FreeBSD 10.3-RELEASEのopensslコマンド(1.0.1s)に以下のパッチを当てる。
このパッチはreq(1)に-startdateと-enddateオプションを与えるパッチである。
パッチを当てられないほとんどの環境では-startdate ~ -enddate ~オプションの代わりに-days ~オプションを指定すること。
1 Index: crypto/openssl/apps/req.c
2 ===================================================================
3 --- crypto/openssl/apps/req.c (revision 298785)
4 +++ crypto/openssl/apps/req.c (working copy)
5 @@ -126,6 +126,8 @@
6 * -x509 - output a self signed X509 structure instead.
7 * -asn1-kludge - output new certificate request in a format that some CA's
8 * require. This format is wrong
9 + * -startdate - notBefore field
10 + * -enddate - notAfter field
11 */
12
13 static int make_REQ(X509_REQ *req, EVP_PKEY *pkey, char *dn, int mutlirdn,
14 @@ -179,6 +181,7 @@
15 int nodes = 0, kludge = 0, newhdr = 0, subject = 0, pubkey = 0;
16 char *infile, *outfile, *prog, *keyfile = NULL, *template =
17 NULL, *keyout = NULL;
18 + char *startdate=NULL,*enddate=NULL;
19 #ifndef OPENSSL_NO_ENGINE
20 char *engine = NULL;
21 #endif
22 @@ -364,6 +367,14 @@
23 if (--argc < 1)
24 goto bad;
25 req_exts = *(++argv);
26 + } else if (strcmp(*argv,"-startdate") == 0) {
27 + if (--argc < 1)
28 + goto bad;
29 + startdate= *(++argv);
30 + } else if (strcmp(*argv,"-enddate") == 0) {
31 + if (--argc < 1)
32 + goto bad;
33 + enddate= *(++argv);
34 } else if ((md_alg = EVP_get_digestbyname(&((*argv)[1]))) != NULL) {
35 /* ok */
36 digest = md_alg;
37 @@ -428,6 +439,10 @@
38 BIO_printf(bio_err,
39 " -days number of days a certificate generated by -x509 is valid for.\n");
40 BIO_printf(bio_err,
41 + " -startdate certificate validity notBefore - YYMMDDHHMMSSZ.\n");
42 + BIO_printf(bio_err,
43 + " -enddate certificate validity notAfter - YYMMDDHHMMSSZ.\n");
44 + BIO_printf(bio_err,
45 " -set_serial serial number to use for a certificate generated by -x509.\n");
46 BIO_printf(bio_err,
47 " -newhdr output \"NEW\" in the header lines\n");
48 @@ -796,13 +811,26 @@
49 if (!rand_serial(NULL, X509_get_serialNumber(x509ss)))
50 goto end;
51 }
52 -
53 + if (startdate == NULL) {
54 + if (!X509_gmtime_adj(X509_get_notBefore(x509ss), 0))
55 + goto end;
56 + } else {
57 + if (!ASN1_UTCTIME_set_string(X509_get_notBefore(x509ss), startdate)) {
58 + BIO_printf(bio_err, "start date is invalid, it should be YYMMDDHHMMSSZ\n");
59 + goto end;
60 + }
61 + }
62 + if (enddate == NULL) {
63 + if (!X509_time_adj_ex(X509_get_notAfter(x509ss), days, 0, NULL))
64 + goto end;
65 + } else {
66 + if (!ASN1_UTCTIME_set_string(X509_get_notAfter(x509ss), enddate)) {
67 + BIO_printf(bio_err, "end date is invalid, it should be YYMMDDHHMMSSZ\n");
68 + goto end;
69 + }
70 + }
71 if (!X509_set_issuer_name(x509ss, X509_REQ_get_subject_name(req)))
72 goto end;
73 - if (!X509_gmtime_adj(X509_get_notBefore(x509ss), 0))
74 - goto end;
75 - if (!X509_time_adj_ex(X509_get_notAfter(x509ss), days, 0, NULL))
76 - goto end;
77 if (!X509_set_subject_name
78 (x509ss, X509_REQ_get_subject_name(req)))
79 goto end;