Skip to content
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

Enable OCSP revocation check for trusted CA #3593

Conversation

kyberpunk
Copy link
Contributor

@kyberpunk kyberpunk commented Dec 9, 2023

Hello, based on issue #3588 I implemented OCSP revocation check support when using trusted CAs for device authentication in tenant.

PR contains following functionality:

  • Enabling OCSP revocation check on configured trusted CA in tenant
  • Configuring useful OCSP settings per CA - OCSP URI, OCSP CA, nonce, check end entities only
  • Tried to keep and public methods and network methods stable where possible.

To reconsider:

  • Implemented OCSP settings on trusted CA level for the best flexibility. It covers also cases when user needs to setup e.g. two CAs with different OCSP URLs. However, it implied more changes in code. Alternatively we could do it just on tenant level or using Java properties. But this will affect flexibility in cases there will be different CAs with different revocation options used at the same time.
  • Instead of extending TrustAnchor can use new data class, but not sure if this API can be used by someone outside of Hono code.

I'm looking forward to your feedback what would you change. Once you confirm that code changes are ok, I will can also extend tests and documentation. Currently the changes were tested just manually.

closes #3588

@kyberpunk kyberpunk force-pushed the enable_revocation_check_for_trusted_ca branch 2 times, most recently from 4072e09 to 73472a4 Compare December 9, 2023 12:37
@kyberpunk
Copy link
Contributor Author

@sophokles73 I was also thinking about integration tests - we are using OpenSSL OCSP server functionality for testing, so I can imagine using Testcontainers to setup OCSP responder for JUnit tests. Do you think it is good idea to do it this way?

@kyberpunk kyberpunk requested a review from sophokles73 January 9, 2024 13:18
@kyberpunk
Copy link
Contributor Author

Hi @sophokles73 , I've incorporated your remarks and implemented comprehensive unit and integration tests. Can you please check it?

There is currently just one remaining issue related to the decision of using just subject and public key for trust anchor. OCSP request defines issuerNameHash which is created from DER encoding of CA issuer name. We are storing subject just as string and by TrustAnchor it is interpreted internally as X500 name with UTF8String type, but in original certificate it can be (and usually is) PrintableString type. This leads to inconsistent hashes with original certificate. This can lead to incompatibility with some responders (e.g. OpenSSL implementation does not work properly).

Can I add new field in TrustedCertificateAuthority for storing also the binary form of subject (similarly as pub key)? This would ensure correct compatibility according to specification.

@sophokles73
Copy link
Contributor

I hope to find the time to look into this more deeply next week. Sorry for the delay ...

@kyberpunk
Copy link
Contributor Author

I've implemented also storing of DER encoded subject DN as mentioned, so now OCSP should work properly in most scenarios.

@kyberpunk
Copy link
Contributor Author

Hi @sophokles73 , did you please have a chance to check it?

@sophokles73
Copy link
Contributor

not yet, sorry for the delay

@@ -0,0 +1,12 @@
-----BEGIN CERTIFICATE-----
MIIBtTCCATugAwIBAgIBADAKBggqhkjOPQQDBDAaMRgwFgYDVQQDDA9pb3QuZWNs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will any of the tests fail if any of the ceriticates' validity period has expired?

Copy link
Contributor Author

@kyberpunk kyberpunk Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it will, but validity of new certificates is set to 50 years so I hope it is sufficient countermeasure.

@kyberpunk kyberpunk force-pushed the enable_revocation_check_for_trusted_ca branch from 9f49c91 to 44081c7 Compare February 24, 2024 11:06
Signed-off-by: Vit Holasek <[email protected]>
@kyberpunk kyberpunk force-pushed the enable_revocation_check_for_trusted_ca branch from 44081c7 to e16345b Compare February 24, 2024 11:07
Comment on lines +466 to +467
* Gets OCSP responder certificate which is used to verify OCSP response signature. If custom certificate is not
* set then issuing CA of client certificate is used instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this will only work, if the user also includes the trust anchor certificate in its request, because otherwise cert will always be null as we do not store the cert in the DB but only its public key and subject DN.
This means that we can not later enable OCSP using the trust anchor CA for this purpose on an already existing trust anchor, or am I mistaken?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically yes. Since OCSP implementation requires full certificate, user must provide it either in cert or ocsp-responder-cert property. I may test what happens in such case, when you just enable it by PUT, but it should be handled by validation.

X.509 certificate. If the `cert` property is used to provide
an X.509 certificate then the subject DN is determined from
the certificate and this property is ignored.
Otherwise this property is optional, but may be needed to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be needed is very unspecific. Please be clear about when this property is required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improved description

type: string
description: |
Specifies the OCSP responder uri which will be used for OCSP revocation check of this trust
anchor. If URI is not set then certificate AIA extension value is used to obtain the values
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... the AIA extension value of the certificate to check is used ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -0,0 +1,6 @@
-----BEGIN EC PRIVATE KEY-----
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not happy with having these certificates in the code base which seem to have happened to just come out of nowhere.
Can you please include a script for creating them in the demo-certs folder or extend the existing script and then use the keys from the demo-certs artifact as we do in other modules?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, added second device certificate to demo script and now we fetch certificates and information from that package instead of extra static files. It just required small fix, to mark certificates as end entity by CA:FALSE in constrains, otherwise the Java implementations ignores them.

@kyberpunk
Copy link
Contributor Author

@sophokles73 I described the OCSP revocation check experimental feature in the documentation as you requested on open call.

Copy link
Contributor

@sophokles73 sophokles73 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just two small textual changes and we are good to merge :-)

response is then used to verify the client certificate's revocation status. Revocation check can be configured using the
[Tenant](/hono/docs/api/management/#/tenants) resource of Device Registry Management API.

OCSP revocation check is supported for HTTP, MQTT, AMQP and CoAP protocol adapters.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it would be fair to say that it is supported with all protocol adapters, based on the way you have integrated it ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

OCSP revocation check is supported for HTTP, MQTT, AMQP and CoAP protocol adapters.

{{% notice info %}}
This feature is experimental and may be subject to change in future releases. Current implementation checks the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... in future releases without further notice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@kyberpunk kyberpunk requested a review from sophokles73 March 5, 2024 08:44
Copy link
Contributor

@sophokles73 sophokles73 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thanks for contributing and your patience. IMHO this is a great outcome 👍

@sophokles73 sophokles73 added Feature Request A request for adding new functionality to Hono security Issues regarding system/data security/privacy labels Mar 6, 2024
@sophokles73 sophokles73 merged commit 7dcf993 into eclipse-hono:master Mar 6, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request A request for adding new functionality to Hono security Issues regarding system/data security/privacy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable client certificate revocation check with OCSP
2 participants