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

[tls] Add a PEMTrustManager to deal with different PEM files (e.g. self-signed or global CA certificates) #2622

Merged
merged 2 commits into from
Dec 29, 2021

Conversation

cweitkamp
Copy link
Contributor

  • Added a PEMTrustManager to deal with different PEM files (e.g. self-signed or global CA certificates)

Signed-off-by: Christoph Weitkamp github@christophweitkamp.de

@cweitkamp cweitkamp added the enhancement An enhancement or new feature of the Core label Dec 17, 2021
@cweitkamp cweitkamp requested a review from a team as a code owner December 17, 2021 16:38
* @throws CertificateException
*/
public PEMTrustManager(String pemCert) throws CertificateException {
if (!pemCert.isBlank() && pemCert.startsWith(BEGIN_CERT)) {
Copy link
Member

Choose a reason for hiding this comment

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

One of the use-cases (e.g. with the http binding) could be that there is a configuration field in the thing config that allows pinning the certificate permanently (the getInstanceFromServer does only pin until restarting the system).

Using line.separator would require the configuration to be different depending on the operating system that openHAB runs on and could lead to problems if the user configures on a different OS. Maybe the cert string should be normalized to the line.separator line endings before the checks are done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One of the use-cases (e.g. with the http binding) could be that there is a configuration field in the thing config

Yes, exactly. I already though about such an implementation for another binding.

A refresh feature for the downloaded cert would be nice (e.g. on expiration). A future enhancement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you check if the new version handles the line endings even better?

@J-N-K
Copy link
Member

J-N-K commented Dec 18, 2021

This is IMO one of the most useful extensions in the last years, it allows the remove the TrustAllTrustManager and similar implementations in quite a bunch of addons.

Copy link
Contributor Author

@cweitkamp cweitkamp left a comment

Choose a reason for hiding this comment

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

Good to see that someone finds it very useful.

* @throws CertificateException
*/
public PEMTrustManager(String pemCert) throws CertificateException {
if (!pemCert.isBlank() && pemCert.startsWith(BEGIN_CERT)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

One of the use-cases (e.g. with the http binding) could be that there is a configuration field in the thing config

Yes, exactly. I already though about such an implementation for another binding.

A refresh feature for the downloaded cert would be nice (e.g. on expiration). A future enhancement.

* @throws FileNotFoundException
* @throws CertificateInstantiationException
*/
public static PEMTrustManager getInstanceFromFile(String path) throws FileNotFoundException, CertificateException {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am currently not sure if we really need this. There is a mir elegant way to provide a certificate by placing it into the resources folder (see icloud binding).

self-signed or global CA certificates)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/java-connection-to-https-with-self-signed-cert/130593/5

@kaikreuzer kaikreuzer changed the title [tls] Added a PEMTrustManager to deal with different PEM files (e.g. self-signed or global CA certificates) [tls] Add a PEMTrustManager to deal with different PEM files (e.g. self-signed or global CA certificates) Dec 28, 2021
Copy link
Member

@kaikreuzer kaikreuzer left a comment

Choose a reason for hiding this comment

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

lgtm, thank you!
Let's wait for @J-N-K final comments before merging.

@J-N-K
Copy link
Member

J-N-K commented Dec 28, 2021

I'll check today and report back this evening.

Copy link
Member

@J-N-K J-N-K left a comment

Choose a reason for hiding this comment

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

LGTM

@kaikreuzer kaikreuzer merged commit 9609ffb into openhab:main Dec 29, 2021
@kaikreuzer kaikreuzer added this to the 3.3 milestone Dec 29, 2021
@cweitkamp cweitkamp deleted the feature-pem-tls-trust-manager branch December 29, 2021 09:42
splatch pushed a commit to ConnectorIO/copybara-hab-core that referenced this pull request Jul 12, 2023
…lf-signed or global CA certificates) (openhab#2622)

* Added a PEMTrustManager to deal with different PEM files (e.g.
self-signed or global CA certificates)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
GitOrigin-RevId: 9609ffb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature of the Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants