1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//! `NumericString` attribute values in RFC 5280 §7.1 name comparison.
//!
//! `DirectoryString` (§4.1.2.4) admits `PrintableString`, `UTF8String`,
//! `TeletexString`, `UniversalString` and `BMPString` — not
//! `NumericString`. But a `Name` is an `RDNSequence` of `AttributeTypeAndValue`
//! whose `value` is `ANY`, and an attribute type outside the standard set
//! defines its own syntax. Russia's registry identifiers do exactly that:
//! `OGRN` (1.2.643.100.1) and the legal-entity `INN` (1.2.643.100.4) are
//! `NumericString`, legitimately, and six of the eight roots in
//! `third_party/trust-stores/ru-national/` carry them.
//!
//! X.680 restricts `NumericString` to the digits `0`–`9` and SPACE, so its
//! content is ASCII and the same normalization the other ASCII string types
//! get applies without transcoding. LDAP agrees: the `Numeric String`
//! syntax has its own equality rule, `numericStringMatch`, which RFC 4517
//! §4.2.22 defines over the RFC 4518 preparation that §7.1 points at —
//! including insignificant-space handling.
//!
//! # The fixtures
//!
//! Both are the subject `Name` of the Russian Ministry of Digital
//! Development's root, lifted from `ru-national` and 319 bytes each:
//!
//! * `fixtures/ru-dn-numericstring.der` — as published. SHA-256 prefix
//! `0786ebfbeee61151`.
//! * `fixtures/ru-dn-printablestring.der` — byte-identical except that the
//! two `NumericString` tags are `PrintableString`. SHA-256 prefix
//! `8368e7c9b40d60c3`.
//!
//! The re-tagging is legitimate: digits are in the `PrintableString`
//! character set, so the variant is a well-formed encoding of the same
//! name, and it is the encoding a different CA in the same hierarchy could
//! reasonably emit. That is the case §7.1 exists for — China's ePassport
//! CSCA is already in the corpus encoding one name as `UTF8String` in its
//! issuer field and `PrintableString` in its subject field (see
//! `names_match_mixed_string_types.rs`).
//!
//! The DN is a good specimen beyond the point at issue: Cyrillic
//! `UTF8String` values, an `IA5String` `emailAddress`, a `PrintableString`
//! country, and the two `NumericString` identifiers.
use ;
use Name;
const NUMERIC_DER: & = include_bytes!;
const PRINTABLE_DER: & = include_bytes!;
/// `NumericString`, tag 0x12.
const TAG_NUMERIC_STRING: u8 = 0x12;
/// `PrintableString`, tag 0x13.
const TAG_PRINTABLE_STRING: u8 = 0x13;
/// The OGRN value, used to build a genuinely-different name.
const OGRN: & = b"1047702026701";
/// The two fixtures differ in exactly two bytes, and both are the string
/// tag of an attribute value.
///
/// The premise guard. If they differed in content as well as encoding, the
/// equality test below would be asserting something much weaker, and if
/// they did not differ at all it would be comparing a name to itself.
/// A `NumericString` name is equal to itself.
///
/// Trivial, and worth pinning: before `NumericString` reached the string
/// path it was compared by tag and raw bytes, which also gets this right.
/// So this test passing says nothing about the fix — it is here so that a
/// change which broke the easy case could not hide behind the interesting
/// one below.
/// The same name is equal whether its registry identifiers are
/// `NumericString` or `PrintableString`.
///
/// This is the claim. Before the fix `NumericString` fell outside the
/// string dispatch and was compared by tag plus raw bytes, so these two
/// names — the same name, differing in two tag bytes — compared as
/// different. The failure mode was a false negative: a path that should
/// chain would not, and the symptom would be `NoTrustedPath` with nothing
/// to indicate that an encoding was the reason.
///
/// Would catch a dispatch that handles `NumericString` in only one
/// direction, since the comparison would then depend on argument order —
/// which [`the_comparison_is_symmetric`] pins separately.
/// The comparison does not depend on argument order.
/// A different registry number is a different name.
///
/// The negative half, and the one that stops the test above from being
/// satisfied by a comparison that ignores `NumericString` content
/// altogether — which is exactly the shape a careless dispatch addition
/// could take. One digit of the OGRN is changed, so the two names differ
/// in content while agreeing in every encoding.
/// Re-encoding a parsed `Name` is byte-identical, so the fixtures really do
/// round-trip and the comparison is being handed what is on disk.
///
/// Guards against a fixture that only appears to differ because the parser
/// normalised something on the way in.