-
Notifications
You must be signed in to change notification settings - Fork 56
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
feat: Integration with Cumulocity CA #3259
base: main
Are you sure you want to change the base?
feat: Integration with Cumulocity CA #3259
Conversation
Codecov ReportAttention: Patch coverage is Additional details and impacted files📢 Thoughts on this report? Let us know! |
) | ||
} | ||
} | ||
warning!("Will retry in 5 seconds"); |
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.
One needs to loop only when it makes senses to retry: i.e. the c8y endpoint has been reached but the device has not been registered yet.
Question: does Cumulocity return a specific HTTP status when the device is not registered?
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.
No I don't think any other response is returned as it would give away information.
Sorry I didn't see that this comment was from last year!
844dc34
to
284c8ee
Compare
284c8ee
to
fba8ed6
Compare
5f284b5
to
5335af8
Compare
Robot Results
|
8ee9b20
to
abfa57e
Compare
46d8bd5
to
4911dbf
Compare
4911dbf
to
d8ad1bd
Compare
d8ad1bd
to
cdc553c
Compare
Signed-off-by: Didier Wenzek <[email protected]>
Signed-off-by: Didier Wenzek <[email protected]>
Signed-off-by: Didier Wenzek <[email protected]>
Signed-off-by: Didier Wenzek <[email protected]>
Signed-off-by: Didier Wenzek <[email protected]>
Signed-off-by: Didier Wenzek <[email protected]>
84e5202
to
bc3ec20
Compare
// For unknown reasons, the base64 encoding differs | ||
// when compared with the value computed using `openssl pkcs7 -print_certs` | ||
let openssl_x509 = r#" | ||
-----BEGIN CERTIFICATE----- | ||
MIIBeTCCASCgAwIBAgIGAZU9kiLNMAoGCCqGSM49BAMCMEIxFjAUBgNVBAYTDVVu | ||
aXRlZCBTdGF0ZXMxEzARBgNVBAoTCkN1bXVsb2NpdHkxEzARBgNVBAMTCm1hbmFn | ||
ZW1lbnQwHhcNMjUwMjI1MTQ0NTQyWhcNMjYwMjI0MDk0MTQ0WjBGMRowGAYDVQQD | ||
DBFkaWRpZXItZGV2aWNlLTAwMTESMBAGA1UECgwJVGhpbiBFZGdlMRQwEgYDVQQL | ||
DAtUZXN0IERldmljZTBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABPBKM0T/sAlk | ||
S2tdbYI/YtIuVyXAPKHhjAeanAOGdMKb5nF55cFRxQBFwVc612bEyx630KAxCXUW | ||
PDbnl0hKmqIwCgYIKoZIzj0EAwIDRwAwRAIgJqlgFbLOsNTfohUS3I592UMDRtb0 | ||
cTenAfPZf0sCCXUCIAPSdprLGJ4fRFUTW8m10PeIIkevMs0zcR9/aA06G7Mk | ||
-----END CERTIFICATE----- | ||
"# | ||
.to_string(); | ||
|
||
// However, the certificate contents match | ||
let openssl_cert = PemCertificate::from_pem_string(&openssl_x509).unwrap(); | ||
assert_eq!(cert.subject().unwrap(), openssl_cert.subject().unwrap()); | ||
assert_eq!(cert.issuer().unwrap(), openssl_cert.issuer().unwrap()); | ||
assert_eq!( | ||
cert.not_before().unwrap(), | ||
openssl_cert.not_before().unwrap() | ||
); | ||
assert_eq!(cert.not_after().unwrap(), openssl_cert.not_after().unwrap()); | ||
|
||
// With an exception on the thumbprint | ||
// assert_eq!(cert.thumbprint().unwrap(), openssl_cert.thumbprint().unwrap()); | ||
assert_eq!( | ||
cert.thumbprint().unwrap(), | ||
"A392A53D3D4263A32C779D06CDDE13A847F272B6".to_string() | ||
); | ||
assert_eq!( | ||
openssl_cert.thumbprint().unwrap(), | ||
"9C68C7EC9A860366FB8D2697C53B2543D9EA525C".to_string() | ||
); |
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.
Can this be the root cause preventing c8y to accept the extracted certificate?
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.
After doing a deep dive into the differences in the certificates I've found exactly where the difference is coming from:
I have a working example with refactored code (using rasn/rasm-csm over the higher level cryptographic-message-syntax crate) where the thumbprint is the same as the one computed by openssl. The code can be found on my temp branch which uses a fork of the x509-certificate crate to avoid the "problem".
The problem originates from this part in the x509-certificate where it does the PEM encoding of the Der formatted value when handing the AlgorithmIdentifier and its handling of the optional parameters. The cryptographic-message-syntax crate suffers from the same problem as it uses the same x509-certificate crate.
The x509-certificate crate purposefully uses the ASN.1 NULL value when an AlgorithmIdentifier object does not have any parameters associated with it.
There is a comment in the code of x509-certificate explaining the motivation of using a ASN.1 NULL tag for (despite the ASN.1 spec clearly stating that the AlgorithmIdentifier parameter object is OPTIONAL).
fn encoded_values(&self, mode: Mode) -> impl Values + '_ {
// parameters is strictly OPTIONAL, which means we can omit it completely.
// However, it is common to see this field encoded as NULL and some
// parsers seem to insist the NULL be there or else they refuse to
// parse the ASN.1. So we ensure this field is always set.
let captured = if let Some(params) = self.parameters.as_ref() {
params.clone()
} else {
AlgorithmParameter(Captured::from_values(mode, ().encode_as(Tag::NULL)))
};
encode::sequence((self.algorithm.clone().encode(), captured))
}
Other libraries like openssl, and golang x509 libraries do not use ASN.1 NULL values if the AlgorithmIdentifier Parameters are empty, so this results in the PEM encoded x509 certificates having a different thumbprint when compared to the any Rust code which uses the 509-certificate crate.
Whilst this may not be a bug as the certificate should still be functionally equal, the difference in
thumbprints can give the impression that the cert is functionality different, and maybe this is causing the connection problem to Cumulocity (like you said), but I haven't verified this just yet.
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.
And I've found an easier solution for encoding the x509 cert from DER into the PEM format by using the existing dependency to the pem crate. Now no custom forks are needed and it adds very little crate dependencies (in comparison with the x509-certificate and cryptographic-message-syntax crates.
Proposed changes
Types of changes
Paste Link to the issue
#3248
Checklist
cargo fmt
as mentioned in CODING_GUIDELINEScargo clippy
as mentioned in CODING_GUIDELINESFurther comments