-
Notifications
You must be signed in to change notification settings - Fork 83
fix(cert): NotBefore=0 collides with CHIP no-expiry sentinel #454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -123,9 +123,22 @@ impl NocGenerator { | |||||||||||||||||||||||||||||||||||||||||
| ca_id: Some(rcac_id), | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| // NotBefore MUST NOT be 0 (Matter epoch start, 2000-01-01). | ||||||||||||||||||||||||||||||||||||||||||
| // CHIP's ChipEpochToASN1Time treats epoch=0 as the "no | ||||||||||||||||||||||||||||||||||||||||||
| // well-defined expiration date" sentinel and re-emits it as | ||||||||||||||||||||||||||||||||||||||||||
| // GeneralizedTime "99991231235959Z" regardless of which field | ||||||||||||||||||||||||||||||||||||||||||
| // it appears in (see CHIPCert.cpp:1076-1106 and the | ||||||||||||||||||||||||||||||||||||||||||
| // explanatory comment about CHIP epoch 0 NotBefore producing | ||||||||||||||||||||||||||||||||||||||||||
| // an invalid TBS signature on round-trip). | ||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||
| // We sign over UTCTime "000101000000Z" (Matter epoch); CHIP | ||||||||||||||||||||||||||||||||||||||||||
| // would reconstruct GeneralizedTime "99991231235959Z" and the | ||||||||||||||||||||||||||||||||||||||||||
| // hash would mismatch. Using 1 second past the Matter epoch | ||||||||||||||||||||||||||||||||||||||||||
| // avoids the sentinel collision while keeping the cert | ||||||||||||||||||||||||||||||||||||||||||
| // effectively unbounded on the lower end. | ||||||||||||||||||||||||||||||||||||||||||
| let validity = crate::cert::builder::Validity { | ||||||||||||||||||||||||||||||||||||||||||
| not_before: 0, // epoch start | ||||||||||||||||||||||||||||||||||||||||||
| not_after: 0, // no expiry | ||||||||||||||||||||||||||||||||||||||||||
| not_before: 1, // 2000-01-01 00:00:01 — past CHIP's epoch=0 sentinel | ||||||||||||||||||||||||||||||||||||||||||
| not_after: 0, // no expiry (NotAfter sentinel is legitimate) | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+126
to
142
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block of code (comment and For example, you could add this before // NotBefore MUST NOT be 0 (Matter epoch start, 2000-01-01).
// CHIP's ChipEpochToASN1Time treats epoch=0 as the "no
// well-defined expiration date" sentinel and re-emits it as
// GeneralizedTime "99991231235959Z" regardless of which field
// it appears in (see CHIPCert.cpp:1076-1106 and the
// explanatory comment about CHIP epoch 0 NotBefore producing
// an invalid TBS signature on round-trip).
//
// We sign over UTCTime "000101000000Z" (Matter epoch); CHIP
// would reconstruct GeneralizedTime "99991231235959Z" and the
// hash would mismatch. Using 1 second past the Matter epoch
// avoids the sentinel collision while keeping the cert
// effectively unbounded on the lower end.
const DEFAULT_VALIDITY: crate::cert::builder::Validity = crate::cert::builder::Validity {
not_before: 1, // 2000-01-01 00:00:01 — past CHIP's epoch=0 sentinel
not_after: 0, // no expiry (NotAfter sentinel is legitimate)
};Then, you can replace this block and the other two occurrences with a single line.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| let cert_len = RcacBuilder::new(&mut cert_buf).build( | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -234,9 +247,22 @@ impl NocGenerator { | |||||||||||||||||||||||||||||||||||||||||
| ca_id: Some(icac_id), | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| // NotBefore MUST NOT be 0 (Matter epoch start, 2000-01-01). | ||||||||||||||||||||||||||||||||||||||||||
| // CHIP's ChipEpochToASN1Time treats epoch=0 as the "no | ||||||||||||||||||||||||||||||||||||||||||
| // well-defined expiration date" sentinel and re-emits it as | ||||||||||||||||||||||||||||||||||||||||||
| // GeneralizedTime "99991231235959Z" regardless of which field | ||||||||||||||||||||||||||||||||||||||||||
| // it appears in (see CHIPCert.cpp:1076-1106 and the | ||||||||||||||||||||||||||||||||||||||||||
| // explanatory comment about CHIP epoch 0 NotBefore producing | ||||||||||||||||||||||||||||||||||||||||||
| // an invalid TBS signature on round-trip). | ||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||
| // We sign over UTCTime "000101000000Z" (Matter epoch); CHIP | ||||||||||||||||||||||||||||||||||||||||||
| // would reconstruct GeneralizedTime "99991231235959Z" and the | ||||||||||||||||||||||||||||||||||||||||||
| // hash would mismatch. Using 1 second past the Matter epoch | ||||||||||||||||||||||||||||||||||||||||||
| // avoids the sentinel collision while keeping the cert | ||||||||||||||||||||||||||||||||||||||||||
| // effectively unbounded on the lower end. | ||||||||||||||||||||||||||||||||||||||||||
| let validity = crate::cert::builder::Validity { | ||||||||||||||||||||||||||||||||||||||||||
| not_before: 0, // epoch start | ||||||||||||||||||||||||||||||||||||||||||
| not_after: 0, // no expiry | ||||||||||||||||||||||||||||||||||||||||||
| not_before: 1, // 2000-01-01 00:00:01 — past CHIP's epoch=0 sentinel | ||||||||||||||||||||||||||||||||||||||||||
| not_after: 0, // no expiry (NotAfter sentinel is legitimate) | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| let issuer = crate::cert::builder::IssuerDN { | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -330,9 +356,22 @@ impl NocGenerator { | |||||||||||||||||||||||||||||||||||||||||
| ca_id: None, | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| // NotBefore MUST NOT be 0 (Matter epoch start, 2000-01-01). | ||||||||||||||||||||||||||||||||||||||||||
| // CHIP's ChipEpochToASN1Time treats epoch=0 as the "no | ||||||||||||||||||||||||||||||||||||||||||
| // well-defined expiration date" sentinel and re-emits it as | ||||||||||||||||||||||||||||||||||||||||||
| // GeneralizedTime "99991231235959Z" regardless of which field | ||||||||||||||||||||||||||||||||||||||||||
| // it appears in (see CHIPCert.cpp:1076-1106 and the | ||||||||||||||||||||||||||||||||||||||||||
| // explanatory comment about CHIP epoch 0 NotBefore producing | ||||||||||||||||||||||||||||||||||||||||||
| // an invalid TBS signature on round-trip). | ||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||
| // We sign over UTCTime "000101000000Z" (Matter epoch); CHIP | ||||||||||||||||||||||||||||||||||||||||||
| // would reconstruct GeneralizedTime "99991231235959Z" and the | ||||||||||||||||||||||||||||||||||||||||||
| // hash would mismatch. Using 1 second past the Matter epoch | ||||||||||||||||||||||||||||||||||||||||||
| // avoids the sentinel collision while keeping the cert | ||||||||||||||||||||||||||||||||||||||||||
| // effectively unbounded on the lower end. | ||||||||||||||||||||||||||||||||||||||||||
| let validity = crate::cert::builder::Validity { | ||||||||||||||||||||||||||||||||||||||||||
| not_before: 0, // epoch start | ||||||||||||||||||||||||||||||||||||||||||
| not_after: 0, // no expiry | ||||||||||||||||||||||||||||||||||||||||||
| not_before: 1, // 2000-01-01 00:00:01 — past CHIP's epoch=0 sentinel | ||||||||||||||||||||||||||||||||||||||||||
| not_after: 0, // no expiry (NotAfter sentinel is legitimate) | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| let cert_len = NocBuilder::new(&mut cert_buf).build( | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To align with the main fix in this PR and avoid using a value known to cause interoperability issues, it's better to use
1fornot_beforehere instead of0. This ensures the test validates the corrected behavior and serves as a better example for future use.