[13] [DFN[[[distinguished name]]]] ([DFN[[[DN]]]]) / [[X.501]] の[[型]] [DFN[[CODE[[[Name]]]]]] は、
「国名」「組織名」その他の[[属性]]によって表現される階層化された名前を表すものです。

* 仕様書

[REFS[
- [1] '''[CITE@en[RFC 5280 - Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile]] ([TIME[2015-02-22 15:44:10 +09:00]] 版) <http://tools.ietf.org/html/rfc5280#section-4.1.2.4>'''
- [20] [CITE@en[RFC 5280 - Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile]] ([TIME[2015-02-22 15:44:10 +09:00]] 版) <http://tools.ietf.org/html/rfc5280#section-4.1.2.6>
- [27] [CITE@en[RFC 5280 - Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile]] ([TIME[2015-02-22 15:44:10 +09:00]] 版) <http://tools.ietf.org/html/rfc5280#section-7.1>
- [11] [CITE@en[RFC 6125 - Representation and Verification of Domain-Based Application Service Identity within Internet Public Key Infrastructure Using X.509 (PKIX) Certificates in the Context of Transport Layer Security (TLS)]]
([TIME[2015-03-13 22:27:53 +09:00]] 版)
<https://tools.ietf.org/html/rfc6125#section-1.8>
- [14] [CITE@en[RFC 6125 - Representation and Verification of Domain-Based Application Service Identity within Internet Public Key Infrastructure Using X.509 (PKIX) Certificates in the Context of Transport Layer Security (TLS)]] ([TIME[2015-03-13 22:27:53 +09:00]] 版) <https://tools.ietf.org/html/rfc6125#section-2.3>
]REFS]

[3] [[RFC 5280]] は [[X.501]] の[[型]] [CODE[[[Name]]]] の[[インターネットPKI]]における[[プロファイル]]を規定しています。

* 意味

[15] [[X.509]] で規定される[[証明書]]は [[X.500]] や [[X.501]]
が規定する[[ディレクトリーサービスモデル]]を採用しており、 [[X.509]]
の[[プロファイル]]である [[PKIX]] も理論上はそれに従っています。 [SRC[>>14]]

[16] [[X.500]] ディレクトリーサービスモデルでは、情報は[[ディレクトリー情報ベース]] ([[DIB]])
に格納されるもので、 [[DIB]] 上のエントリーは[[ディレクトリー情報木]] ([[DIT]])
と呼ばれる構造になっています。 [SRC[>>14]]

[22] [[DIT]] 上のオブジェクトや別名エントリーは、[[属性]]の[[集合]]によって構成され、
[[Distinguished Name]] ([[DN]]) によって固有に識別されます。
[[DN]] は、 [[DIT]] 上でより上位 ([[根]]側) にあるエントリーの
[[Relative Distinguished Name]] ([[RDN]]) である[[属性]]を集めることで得られます。
[[RDN]] は [[attribute-type-and-value pair]] の[[集合]]です。 [SRC[>>14]]

;; [23] [[RDN]] は上位のエントリーの [[DN]] に相対的なものという意味で
relative と呼ばれています [SRC[>>14]]。

;; [24] [[根]]に近いエントリーを most significant である、[[葉]]を
least significant であるといいます。

;; [29] [[RDN]] は[[集合]]であり、本来順序を持たないはずですが、 [[証明書]]に用いる
[[DER]] で[[符号化]]したり、それを文字列表現で表示したりすると、
特定の順序で示されることになります (それが[[ビッグエンディアン]]だったり[[リトルエンディアン]]だったりしますが)。
しかもその順序を情報の階層と暗黙に関連付けて (実際にはそんな関係はあったりなかったりわからないですが)
left-most/right-most、first/last、most/least specific/signiicant といった言葉を使う仕様書もあったりして、混乱しています。 [SRC[>>14]]
[[CN-ID]] の規定では、この混乱を根拠に、同じ型の[[属性]]が複数指定された場合を定義から除外しています [SRC[>>14]]。しかし実際には複数含まれる[[証明書]]も発行されているようです
([[service identity]] 参照)。

;; [30] [CODE[[[Name]]]] 中の [[RDN]] の順序も理論上は意味があると考えることもありますが、
実際にはあまりそのように扱われていません [SRC[>>14]]。

[25] 実際には [[PKIX]] は [CODE[[[subject]]]] [[欄]]を [[X.501]] [CODE[[[Name]]]]
で指定せずに空欄にして、かわりに [[SAN]] で指定することも認めています。 [SRC[>>14]]

* 構文

[4] [CODE[[[Name]]]] の書式は [[ASN.1]] により定義されています。

[5] [DFN[[CODE[[[Name]]]]]] は、 [CODE[[[RDNSequence]]]] 型の値の[[欄]]
[DFN[[CODE[[[rdnSequence]]]]]] のみを持ちます [SRC[>>1]]。

[6] [DFN[[CODE[[[RDNSequence]]]]]] は、 [CODE[[[RelativeDistinguishedName]]]]
の[[列]] ([CODE[[[SEQUENCE]]]]) です [SRC[>>1]]。

[7] [DFN[[CODE[[[RelativeDistinguishedName]]]]]] は、1個[[以上]]の
[CODE[[[AttributeTypeAndValue]]]] の[[集合]]です [SRC[>>1]]。

[8] [DFN[[CODE[[[AttributeTypeAndValue]]]]]] は、
[CODE[[[AttributeType]]]] 型の[[欄]] [DFN[[CODE[[[type]]]]]] と
[CODE[[[AttributeValue]]]] 型の[[欄]] [DFN[[CODE[[[value]]]]]] で構成されます [SRC[>>1]]。
[DFN[[[attribute-type-and-value pair]]]] ともいいます [SRC[>>11]]。

[9] [DFN[[CODE[[[AttributeType]]]]]] は、[[オブジェクト識別子]]です [SRC[>>1]]。

[10] [DFN[[CODE[[[AttributeValue]]]]]] は、 [CODE[[[AttributeType]]]] によって決まる値です [SRC[>>1]]。通常は [CODE[[[DirectoryString]]]] となります [SRC[>>1]]。

;; [12] まとめると、1つ[[以上]]の[[属性]]の[[集合]]であり、[[属性]]は[[型]]と[[値]]により構成されます。

* 文脈

[2] [CODE[Name]] は [[証明書]]の [CODE[[[issuer]]]] [[欄]], [CODE[[[subject]]]]
[[欄]]の値として用いられます。
[[TLS]] の [CODE[CertificateRequest]] でも使われます。

[38] [CODE[RelativeDistinguishedName]] は [[CRLDistributionPoints]]
で用いられます。

* 属性

[17] [[RFC 5280]] は[[名前]]中で使用できる[[属性型]]を制限していません [SRC[>>1]]。

[18] 次の[[属性型]]を含む [CODE[[[issuer]]]] と [CODE[[[subject]]]]
の[[名前]]に対応しなければ[['''なりません''']]。 [SRC[>>1]]

[FIG(short list)[
- [[country]]
- [[organization]]
- [[organization unit]]
- [[distinguished name qualifier]]
- [[state or province name]]
- [[common name]]
- [[serial number]]
- [CODE[[[domainComponent]]]]
]FIG]

[19] 次の[[属性型]]を含む [CODE[[[issuer]]]] と [CODE[[[subject]]]]
の[[名前]]に対応する[['''べきです''']]。 [SRC[>>1]]

[FIG(short list)[
- [[locality]]
- [[title]]
- [[surname]]
- [[given name]]
- [[initials]]
- [[pseudonym]]
- [[generation qualifier]]
]FIG]

[26] その他:
[FIG(short list)[
- [CODE[[[emailAddress]]]]
- [CODE[1.3.6.1.4.1.311.60.2.1.3]]
- [CODE[1.3.6.1.4.1.311.60.2.1.2]]
]FIG]

* 比較

[FIG(quote)[
[FIGCAPTION[
[28] [CITE@en[RFC 5280 - Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile]]
([TIME[2015-02-22 15:44:10 +09:00]] 版)
<http://tools.ietf.org/html/rfc5280#section-7.1>
]FIGCAPTION]

> Two naming attributes match if the attribute types are the same and
the values of the attributes are an exact match after processing with
the string preparation algorithm.  Two relative distinguished names
RDN1 and RDN2 match if they have the same number of naming attributes
and for each naming attribute in RDN1 there is a matching naming
attribute in RDN2.  Two distinguished names DN1 and DN2 match if they
have the same number of RDNs, for each RDN in DN1 there is a matching
RDN in DN2, and the matching RDNs appear in the same order in both
DNs.  A distinguished name DN1 is within the subtree defined by the
distinguished name DN2 if DN1 contains at least as many RDNs as DN2,
and DN1 and DN2 are a match when trailing RDNs in DN1 are ignored.

]FIG]

[21] [CODE[[[subject]]]] [[欄]]の値の比較では、[[属性値]]が [CODE[[[DirectoryString]]]]
なら、その比較規則を使って構いません。それ以外の値なら、バイナリ比較を使うべきです。 [SRC[>>20]]

* メモ

[40] [CITE@en[RFC 1485 - A String Representation of Distinguished Names (OSI-DS 23 (v5))]], [TIME[2021-01-31T13:58:52.000Z]], [TIME[2021-03-16T09:04:52.699Z]] <https://tools.ietf.org/html/rfc1485>

[39] [CITE@en[RFC 1779 - A String Representation of Distinguished Names]], [TIME[2021-01-31T08:31:43.000Z]], [TIME[2021-03-16T09:04:26.357Z]] <https://tools.ietf.org/html/rfc1779>

[41] [CITE@en[RFC 2253 - Lightweight Directory Access Protocol (v3): UTF-8 String Representation of Distinguished Names]], [TIME[2021-03-14T08:13:53.000Z]], [TIME[2021-03-23T11:54:55.164Z]] <https://tools.ietf.org/html/rfc2253>


[37] 
[CODE[UniversalString]] は [[UCS-4]] を、
[CODE[BMPString]] は [[UCS-2]] を表しています。

[FIG(quote)[
[FIGCAPTION[
[31] [CITE@en[RFC 5246 - The Transport Layer Security (TLS) Protocol Version 1.2]]
([TIME[2015-03-25 03:49:56 +09:00]] 版)
<https://tools.ietf.org/html/rfc5246#section-7.4.4>
]FIGCAPTION]

>       opaque DistinguishedName<1..2^16-1>;

]FIG]


[32] [CITE@en[RFC 4514 - Lightweight Directory Access Protocol (LDAP): String Representation of Distinguished Names]]
([TIME[2015-02-08 17:24:27 +09:00]] 版)
<http://tools.ietf.org/html/rfc4514>

[33] [CITE[https - 東京都内のいくつかの団体のSSL証明書情報ピックアップ - Qiita]]
([TIME[2015-11-16 00:14:56 +09:00]] 版)
<http://qiita.com/kobake@github/items/bc05d3790bde10869ad6>

[34] [CITE[Re: '''['''certid''']''' Need to define "most specific RDN"]]
( ([TIME[2012-05-08 02:58:04 +09:00]]))
<https://www.ietf.org/mail-archive/web/certid/current/msg00231.html>

[35] [CITE@en[469533 – FireFox 3.0.6 only processes 'Last' CN in x509 certificate when multiple CNs are present - ssl_error_bad_cert_domain]]
( ([TIME[2016-05-08 22:03:43 +09:00]]))
<https://bugzilla.mozilla.org/show_bug.cgi?id=469533>

[36] [CITE@ja[自堕落な技術者の日記 : X.509証明書の識別名などで使われるMulti-valued RDNとjsrsasignのサポートについて - livedoor Blog(ブログ)]]
([TIME[2018-05-20 23:14:27 +09:00]])
<http://blog.livedoor.jp/k_urushima/archives/1808377.html>