Skip to content

Commit c407804

Browse files
committed
Improve chain build result checking and further document flags and the
changed error handling. This also restores CERT_CHAIN_CACHE_END_CERT since caching is never harmful for the majority of users.
1 parent 0c997c0 commit c407804

File tree

1 file changed

+12
-9
lines changed
  • rustls-platform-verifier/src/verification

1 file changed

+12
-9
lines changed

rustls-platform-verifier/src/verification/windows.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use winapi::{
3636
CertAddEncodedCertificateToStore, CertCloseStore, CertFreeCertificateChain,
3737
CertFreeCertificateChainEngine, CertFreeCertificateContext, CertGetCertificateChain,
3838
CertOpenStore, CertSetCertificateContextProperty, CertVerifyCertificateChainPolicy,
39-
AUTHTYPE_SERVER, CERT_CHAIN_CONTEXT, CERT_CHAIN_PARA,
39+
AUTHTYPE_SERVER, CERT_CHAIN_CACHE_END_CERT, CERT_CHAIN_CONTEXT, CERT_CHAIN_PARA,
4040
CERT_CHAIN_POLICY_IGNORE_ALL_REV_UNKNOWN_FLAGS, CERT_CHAIN_POLICY_PARA,
4141
CERT_CHAIN_POLICY_SSL, CERT_CHAIN_POLICY_STATUS,
4242
CERT_CHAIN_REVOCATION_ACCUMULATIVE_TIMEOUT, CERT_CHAIN_REVOCATION_CHECK_END_CERT,
@@ -367,11 +367,14 @@ impl CertificateStore {
367367
}
368368
};
369369

370-
// `CERT_CHAIN_REVOCATION_CHECK_END_CERT` only checks revocation for end cert.
370+
// `CERT_CHAIN_REVOCATION_CHECK_END_CERT` only checks revocation for end cert. See the crate's revocation documentation
371+
// for more details.
371372
// `CERT_CHAIN_REVOCATION_ACCUMULATIVE_TIMEOUT` accumulates network retrievals timeouts
372373
// to limit network time and improve performance.
373-
const FLAGS: u32 =
374-
CERT_CHAIN_REVOCATION_CHECK_END_CERT | CERT_CHAIN_REVOCATION_ACCUMULATIVE_TIMEOUT;
374+
// `CERT_CHAIN_CACHE_END_CERT` speeds up the common case of multiple connections to same server.
375+
const FLAGS: u32 = CERT_CHAIN_REVOCATION_CHECK_END_CERT
376+
| CERT_CHAIN_REVOCATION_ACCUMULATIVE_TIMEOUT
377+
| CERT_CHAIN_CACHE_END_CERT;
375378

376379
// Lowering URL retrieval timeout from default 15s to 10s to account for higher internet speeds
377380
parameters.dwUrlRetrievalTimeout = 10 * 1000; // milliseconds
@@ -391,12 +394,12 @@ impl CertificateStore {
391394
)
392395
};
393396

394-
let cert_chain = call_with_last_error(|| match nonnull_from_const_ptr(cert_chain) {
395-
Some(c) if res == TRUE => Some(c),
397+
// XXX: Windows will internally map the chain's `TrustStatus.dwErrorStatus` to a `dwError` when
398+
// a chain policy is verified, so we only check for errors there.
399+
call_with_last_error(|| match nonnull_from_const_ptr(cert_chain) {
400+
Some(c) if res == TRUE => Some(CertChain { inner: c }),
396401
_ => None,
397-
})?;
398-
399-
Ok(CertChain { inner: cert_chain })
402+
})
400403
}
401404
}
402405

0 commit comments

Comments
 (0)