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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
//! Where algorithm support is enforced, and where it deliberately is not.
//!
//! [`TrustAnchor::from_cert`] applies the CA profile: what the certificate
//! asserts about what it may be used for. It does not ask whether this
//! build can verify a signature made with the key, and it could not — it
//! takes no [`pkix_path::SignatureVerifier`], and the supported set is a
//! property of the verifier rather than of the certificate. So a
//! certificate whose key this build cannot use still becomes an anchor, and
//! the limit is reported at validation.
//!
//! That split is deliberate, and it is the opposite of the choice made for
//! a BER-encoded `cA` boolean (see `ber_boolean.rs`), so the distinction is
//! worth stating:
//!
//! * A BER boolean means **the certificate's own claim cannot be read**.
//! The profile check needs `cA` and cannot get it, so refusing is the
//! only way to avoid guessing a security-relevant value.
//! * An unsupported key algorithm means **everything the certificate says
//! is legible and satisfied** — `cA=TRUE`, critical, `keyCertSign`
//! permitted. What is missing is a capability of this build, not a fact
//! about the certificate. `SignatureVerifier` is public, so a caller may
//! well supply one that handles the algorithm; refusing at construction
//! would make that caller's valid configuration impossible to express.
//!
//! Refuse when the certificate is unreadable; do not refuse when the
//! limitation is ours.
//!
//! # What this costs, and what makes it tolerable
//!
//! A caller loading `third_party/trust-stores/ru-national/` gets eight
//! anchors, six of which cannot verify anything in this build, with an
//! empty `rejected` list. The cost is discoverability, and what keeps it
//! bounded is that the eventual error is specific:
//! [`Error::SignatureNotVerified`] carrying
//! [`VerificationErrorKind::UnsupportedAlgorithm`], naming the chain index.
//! Not `NoTrustedPath`, not `SignatureInvalid`, not a panic. A caller told
//! "unsupported algorithm at index 0" can act; one told "no path" cannot.
//!
//! That is the contract these tests exist to defend. It was untested, which
//! for a behaviour justified by the quality of its error message is the
//! wrong way round.
//!
//! # The fixtures
//!
//! Two Головной удостоверяющий центр roots — Russia's Head Certification
//! Authority, the apex of its accredited-CA system — from the vendored
//! `ru-national` store, on the two different GOST arcs:
//!
//! * `fixtures/ru-root-gost2012.der`, SHA-256 prefix `4bb37cc7c0ff4bf2`.
//! `CN=Минцифры России`, key GOST R 34.10-2012 (1.2.643.7.1.1.1.1),
//! signature 1.2.643.7.1.1.3.2, valid 2022-01-08 to 2040-01-08.
//! * `fixtures/ru-root-gost2001.der`, SHA-256 prefix `4e450e4971f2d77d`.
//! `CN=Головной удостоверяющий центр`, key GOST R 34.10-2001
//! (1.2.643.2.2.19) on the older CryptoPro arc, signature 1.2.643.2.2.3,
//! valid 2012-07-20 to 2027-07-17.
//!
//! Both are real, in-window national roots. OpenSSL without a GOST
//! provider cannot even load their public keys.
use Decode as _;
use ;
// Only the `cfg(not(feature = "gost"))` arm of
// `a_path_through_a_gost_anchor_validates` names this: with the feature
// on the path validates, so there is no error kind left to match.
use VerificationErrorKind;
use Certificate;
const GOST_2012: & = include_bytes!;
const GOST_2001: & = include_bytes!;
/// GOST R 34.10-2012 public key.
const OID_GOST_2012_KEY: &str = "1.2.643.7.1.1.1.1";
/// GOST R 34.10-2001 public key, CryptoPro arc.
const OID_GOST_2001_KEY: &str = "1.2.643.2.2.19";
/// `(fixture, key OID, notBefore, notAfter)`.
///
/// Validity oracles, computed outside this workspace with
/// `date -u -d '<the date openssl x509 -dates prints>' +%s`:
/// 2022-01-08T13:32:39Z, 2040-01-08T13:32:39Z, 2012-07-20T12:31:14Z,
/// 2027-07-17T12:31:14Z.
const ROOTS: & = &;
/// The fixtures really carry GOST keys on the two arcs, and really are
/// certificates this build cannot verify.
///
/// The premise guard. If a refresh replaced either with an RSA root, every
/// test below would pass while testing nothing: the anchor would build and
/// the path would validate, and "builds an anchor" would no longer be the
/// interesting half.
/// A certificate whose key algorithm this build cannot use still becomes a
/// trust anchor.
///
/// The deliberate half. Would catch a well-meaning change that screened
/// anchors against the verifier's supported set at construction — which
/// `from_cert` cannot do correctly anyway, since it is given no verifier
/// and a caller may supply one that handles GOST.
/// A path through a GOST anchor now VALIDATES.
///
/// This test asserted the opposite until `pkix_path::gost_r3410` landed:
/// that a GOST path failed with `SignatureNotVerified { reason:
/// UnsupportedAlgorithm }`, naming the algorithm so a caller learned
/// precisely why rather than being told their trust store held no path.
/// That was the right behaviour for a build with no GOST, and the
/// argument it justified -- accept the anchor, explain at the point it
/// matters -- is unchanged.
///
/// What changed is that there is no longer anything to explain. These
/// are the Russian national roots, and a one-certificate path through
/// each of them verifies end to end: both GOST generations, the
/// CryptoPro-A curve, and RFC 4491's two disagreeing byte orders.
///
/// Kept pointed at `validate_path` rather than at the verifier directly,
/// because that is the layer the old assertion was about and the layer a
/// caller uses.
/// It is specifically not reported as an invalid signature.
///
/// Pinned apart from the test above because the difference is what a
/// caller acts on. `SignatureInvalid` says the issuer did not sign this
/// certificate — a statement about the certificates, and grounds for
/// suspicion. `SignatureNotVerified` with an unsupported algorithm says
/// this build cannot tell. Conflating them would turn a missing feature
/// into an accusation.
/// Loading such a root through a bundle reports nothing as rejected.
///
/// The cost of the design, pinned so it is a stated consequence rather
/// than a surprise: `is_clean` is true and `rejected` is empty, because
/// nothing about these certificates is wrong. A caller counting usable
/// anchors from `anchors.len()` will over-count by six on Russia's store,
/// and the only way to find out is to validate.