[1] [DFN[[[Certificate Download Specification]]]] は、[[証明書]]の[[ダウンロード]]に関する仕様書です。

* 仕様書

[REFS[
- [2] [CITE@en-US[NSS Certificate Download Specification - Mozilla | MDN]] ([TIME[2014-05-07 16:41:21 +09:00]] 版) <https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/Certificate_Download_Specification>
]REFS]

* ファイル形式

[13] 次のファイル形式が規定されています。
[FIG(middle list)[
- [[PKCS#7 certificate chain]]
- [[Netscape Certificate Sequence]]
- [CODE[[[.pem]]]]
]FIG]

[14] また [[DER]] 符号化された[[証明書]]も採用しています。

* MIME 型

[9] 次の [[MIME型]]が規定されています。
[FIG(middle list)[
- [CODE(MIME)@en[[[application/x-x509-user-cert]]]]
- [CODE(MIME)@en[[[application/x-x509-ca-cert]]]]
- [CODE(MIME)@en[[[application/x-x509-email-cert]]]]
]FIG]

;; [10] >>3 の時点では [CODE(MIME)@en[[[application/x-x509-email-cert]]]] はまだ無かったようです。
>>18 や >>4 には含まれており、 [[Netscape4]] 時代に追加されたものと思われます。

;; [11] [CODE(MIME)@en[[[application/x-x509-server-cert]]]]
も使われることがあるようですが、当仕様書には含まれていません。

;; [33] 少なくても [[Chrome]] は、その他に [CODE(MIME)@en[[[application/x-pkcs12]]]]
にも対応しているように見えます。 ([[Chrome]] は 
[CODE(MIME)@en[[[application/x-x509-email-cert]]]] に対応していないように見えます。)
[TIME[2015-05-07T13:13:25.100Z]]

[15] これらの [[MIME型]]はファイル形式を示すものではなく (>>13 のいずれでも良いようです)、
[[ダウンロード]]した[[証明書]]をどう処理するべきかを指定するもののようです。

;; [16] 用途によって少しずつ[[証明書]]に記述するべき内容も違っているので、
広義のファイル形式ではあるのですが...

[23] [CODE(MIME)@en[[[application/x-x509-user-cert]]]] は、
[[Webブラウザー]]の[[利用者]]の[[証明書]]を表しています。
最初の[[証明書]]は[[利用者]]の[[証明書]]でなければなりません。 [SRC[>>2]]

;; [12] [CODE(HTMLe)@en[[[keygen]]]] [[要素]]を含む[[フォームの提出]]で[[公開鍵]]を受け取った[[サーバー]]が[[証明書]]を生成し、
[[Webブラウザー]]に[[ダウンロード]]させるために使うことができます。

[25] [CODE(MIME)@en[[[application/x-x509-ca-cert]]]] は、
[[CA証明書]]を表しています。
最初の[[証明書]]は[[CA証明書]]でなければなりません。 [SRC[>>2]]

[27] [CODE(MIME)@en[[[application/x-x509-email-cert]]]] は、
他の[[利用者]]の [[S/MIME]] 用[[証明書]]を表しています。
最初の[[証明書]]は[[利用者]]の[[証明書]]でなければなりません。 [SRC[>>2]]

;; [29] 人や [[CA]] が [[Webサイト]]に[[証明書]]を用意して、
その人宛に[[電子メール]]を送りたい人がこれを[[ダウンロード]]して使うことが想定されています
[SRC[>>2]]。

* 処理

[20] 与えられた[[ファイル]]に[[証明書]]が複数含まれる場合、
最初の[[証明書]]が文脈依存の方法で処理されます [SRC[>>2]]。

[21] ここでいう文脈依存の方法は、[[ダウンロード]]の際の [[MIME型]]により決まります。
[[NSS]] を使った[[サーバー]]では、管理画面オプションの選択肢により決まります。 [SRC[>>2]]

[FIG(switch)[
:[24] [CODE(MIME)@en[[[application/x-x509-user-cert]]]]:
[[証明書]]に対応する[[秘密鍵]]が[[利用者]]の[[ローカル鍵データベース]]に存在しなければ、
エラーを表示して停止します [SRC[>>2]]。そうでなければ、[[利用者]]の[[証明書]]として[[ローカル証明書データベース]]に追加します。
:[26] [CODE(MIME)@en[[[application/x-x509-ca-cert]]]]:
[[CA]] を信頼するかどうかを決めるダイアログを表示します [SRC[>>2]]。
:[28] [CODE(MIME)@en[[[application/x-x509-email-cert]]]]:
他の[[利用者]]の[[証明書]]として[[ローカル証明書データベース]]に追加します。
]FIG]

[22] 最初以外の[[証明書]]は、 [CODE[[[BasicConstraints]]]] により
[[CA証明書]]であるとされており、既に[[ローカル証明書データベース]]に含まれていないなら、
信頼されていない [[CA]] として[[ローカル証明書データベース]]に追加されます。 [SRC[>>2]]

[34] [[Chrome]] は [CODE(MIME)@en[[[application/x-x509-user-cert]]]]
には対応していますが、 [CODE(MIME)@en[[[application/x-x509-ca-cert]]]]
には対応していないようです。 [TIME[2015-08-13T07:38:14.700Z]]

[40] 
[[Chrome]] で
[CODE[application/x-x509-ca-cert]]
の [[.pemファイル]]を開くと、危険なファイルの警告が表示されます。
[TIME[2018-12-28T06:17:15.000Z]]

[35] [[Firefox]] は [CODE(MIME)@en[[[application/x-x509-ca-cert]]]]
だと [[trust bits]] を選択する[[ダイアログ]]が表示されます。 [TIME[2015-08-13T07:39:08.200Z]]

* 歴史

[REFS[
- [3] [CITE[Netscape Certificate Download Specification]] ([TIME[2015-04-11 23:26:48 +09:00]] 版) <http://web.archive.org/web/19970709163955/http://home.netscape.com/eng/security/downloadcert.html>
- [18] [CITE[Netscape Certificate Download Specification]] ([TIME[2015-04-12 13:21:05 +09:00]] 版) <http://web.archive.org/web/20000511091621/http://www.netscape.com/eng/security/comm4-cert-download.html>
- [4] [CITE[Netscape Certificate Management System Installation and Deployment Guide:]] ([TIME[2011-02-10 11:26:52 +09:00]] 版) <http://docs.oracle.com/cd/E19957-01/816-5533-10/dwnld.htm>
- [5] [CITE@en[CA:Certificate Download Specification - MozillaWiki]] ([TIME[2015-04-11 18:26:28 +09:00]] 版) <https://wiki.mozilla.org/CA:Certificate_Download_Specification>
]REFS]

[6] >>3 は1996年6月28日付けの [[Netscape3]] 版、 >>18 が [[Netscape4]] 版です。

[7] >>4 は [[NES]]、 >>5 と >>2 は [[Firefox]] へと受け継がれた版です。

[8] >>2 が2014年5月7日更新で、現時点で最新となっています。

[17] [CITE@en[249004 – Importing false CA certificate leading to error -8182 (perm DoS), especially exploitable by email]]
([TIME[2015-04-12 13:19:44 +09:00]] 版)
<https://bugzilla.mozilla.org/show_bug.cgi?id=249004>

[FIG(quote)[
[FIGCAPTION[
[19] ([TIME[2015-04-12 13:24:24 +09:00]] 版)
<http://web.archive.org/web/20060929031003/http://www.alw.nih.gov/pki/docs/ns-ca.txt>
]FIGCAPTION]

> The browser uses the public key encoded in the certificate to
> 	associate the certificate with the appropriate private key in
> 	its local key database.  Now, the certificate is "installed".

]FIG]

[31] [CITE[Issue 37142 - chromium - Intermediate certs received along with generated client cert will not be saved - An open-source project to help move the web forward. - Google Project Hosting]]
([TIME[2015-04-12 15:36:22 +09:00]] 版)
<https://code.google.com/p/chromium/issues/detail?id=37142>

[30] [CITE[Issue 136534 - chromium - Offer the ability to download application/x-x509-user-cert responses - An open-source project to help move the web forward. - Google Project Hosting]]
([TIME[2015-04-12 15:38:51 +09:00]] 版)
<https://code.google.com/p/chromium/issues/detail?id=136534>


[FIG(quote)[
[FIGCAPTION[
[32] [CITE@en[draft-gutmann-scep-00 - Simple Certificate Enrolment Protocol]]
([TIME[2015-04-03 02:25:17 +09:00]] 版)
<https://tools.ietf.org/html/draft-gutmann-scep-00#section-5.2.1.1.1>
]FIGCAPTION]

> The response will have a Content-Type of "application/x-x509-ca-cert".

]FIG]

[36] [CITE[Issue 37142 - chromium - Intermediate certs received along with generated client cert will not be saved - An open-source project to help move the web forward. - Google Project Hosting]]
([TIME[2015-03-22 00:58:11 +09:00]] 版)
<https://code.google.com/p/chromium/issues/detail?id=37142>

[FIG(quote)[
[FIGCAPTION[
[37] [CITE[(Pre-)Intent to Deprecate: <keygen> element and application/x-x509-*-cert MIME handling - Google グループ]]
([TIME[2015-09-02 11:09:53 +09:00]] 版)
<https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/pX5NbX0Xack/discussion>
]FIGCAPTION]

> On the application/x-x509-*-cert support, there is a wide gap of interoperability. Chrome does not support multiple certificates, but Firefox does. Firefox will further reorder certificates that are inconsistent with what was specified, offering a non-standard behaviour. Chrome does not support application/x-x509-ca-cert on Desktop, and on Android, defers to the platform capabilities, which further diverge from Firefox. Both browsers have the underspecified behaviour of requiring the user having a matching key a-priori, except that's not detailed as to how it works. Firefox also handles various mis-encodings (improper DER, DER when it should be base64), which Chrome later implemented, but is not well specified.

]FIG]


[38] [CITE@en[1024871 – stop offering to import CA certificates when browsed to]]
([TIME[2015-09-02 11:10:17 +09:00]] 版)
<https://bugzilla.mozilla.org/show_bug.cgi?id=1024871>

[39] [CITE@en[Expand on the <keygen> removal and deprecation]]
([[domenic]]著, [TIME[2016-11-24 09:31:45 +09:00]])
<https://github.com/whatwg/html/commit/8a85d1742d9ac9be17f79f8087898147209d354c>