Skip to content

Respect the Qgis SSL configuration on trusted certificates and trusted root CA configured in settings#870

Open
lleirborras wants to merge 4 commits intoMerginMaps:masterfrom
lleirborras:fix/custom-ssl-ca
Open

Respect the Qgis SSL configuration on trusted certificates and trusted root CA configured in settings#870
lleirborras wants to merge 4 commits intoMerginMaps:masterfrom
lleirborras:fix/custom-ssl-ca

Conversation

@lleirborras
Copy link

Also, fixes #820

@MarcelGeo
Copy link
Contributor

Hi @lleirborras thanks for PR, we will take a look at this.

Copy link
Contributor

@wonder-sk wonder-sk left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

Nice idea to use QGIS trusted CA certs - I thought QGIS API provided only the custom ones added by the user, but it actually returns all of them, so we don't need to deal with truststore module...

- Decode QByteArray returned by trustedCaCertsPemText() to str before writing
- Always replace the QGIS CA section in cert.pem instead of append-only,
  so stale certs from previous sessions are refreshed
- Call setup_qgis_ssl_for_mergin_client() in initGui() where the auth manager
  is guaranteed to be ready, and also before each MerginClient creation in
  validate_mergin_url() and mergin_server_deprecated_version()
….pem

Replace the macOS-specific cert.pem file patching with a call to
mergin.client.set_trusted_certificates(cafile), a new API to be added
to python-api-client. The mergin client module stores the extra CA file
path and loads it alongside its default bundle (system CAs on Linux/Windows,
bundled cert.pem on macOS) whenever a MerginClient is instantiated.

This avoids mutating files inside the installed plugin directory and
ensures CAs are always up to date (the PEM file is rewritten on every call).
A hasattr guard keeps the code compatible with older py-client versions
that don't have the new function yet.

Remove the sys import that was only needed for the platform check.
- Remove the module-level setup_qgis_ssl_for_mergin_client() call;
  the auth manager is not guaranteed to be ready at import time
- In initGui(), replace bare except Exception: pass with a logged
  warning so SSL setup failures are visible in the QGIS message log
@lleirborras
Copy link
Author

Ciao @wonder-sk I've went ahead, reimplemented the solution and also rebased the changes on the updated master. Let me know

@lleirborras lleirborras requested a review from wonder-sk March 11, 2026 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use certificates from the operating system

3 participants