mirror of
https://github.com/binwiederhier/ntfy.git
synced 2026-05-09 16:35:53 +02:00
[GH-ISSUE #215] Work with not trusted HTTPS certificates #169
Labels
No labels
ai-generated
android-app
android-app
android-app
🪲 bug
build
build
dependencies
docs
enhancement
enhancement
🔥 HOT
in-progress 🏃
ios
prio:low
prio:low
pull-request
question
🔒 security
server
server
unified-push
web-app
website
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/ntfy#169
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @MuratovAS on GitHub (Apr 17, 2022).
Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/215
Good afternoon
Small observations regarding the application.
I use my own server for NTFY. I have no opportunity and desire to make the application public. I prefer even to use HTTPS on the local network.
As part of its network, all services I issue domains and certificates.
In such a scenario there are some difficulties, Android security policy on my phone does not allow working with impervious CA. Your application is no exception.
This problem can be bypass using the corresponding Magisk module. After adding your own CA in the certificate store. But this method is possible only on root devices.
https://github.com/NVISOsecurity/MagiskTrustUserCerts
For example, in the DAVX5-OSE application, this problem is solved elegant. When the connection is first, the application gives a dialog box that allows you to trust / do not trust this HTTPS certificate.
https://github.com/bitfireAT/davx5-ose
Dear developers, I propose to write about it in Wiki or within the application, implement a mechanism for permission to work with not trusted certificates.
P.S. Let's leave it here who can come in handy)
@dcousens commented on GitHub (May 7, 2022):
Preferably, you should be able to provide a custom CA certificate to the application itself, preventing it from accepting connections to anything else.
The equivalent of
--cacertforcurl.I don't mind something like a
--known_hostsoption; presuming the information shown is verifiable to the end user.For example, it could show the sha256 fingerprint of the certificate.
@Kenix3 commented on GitHub (May 12, 2022):
This would be a great feature! At the very least a setting like
curl -kto skip the verification step.@binwiederhier commented on GitHub (May 27, 2022):
So, I am a little bit torn on this one. With Let's Encrypt certs being freely available and the DNS challenge making it possible to issue certs for internal servers, why would I go through the trouble of supporting custom certs. Because if I do that, I have to support ways to manage these certs to (create/update/delete), which is a whole new set of UIs.
Right now I don't see any reason to implement this, because it can be solved differently. I'll leave it open for comment.
@MuratovAS commented on GitHub (May 27, 2022):
I think for starters you just need to add a checkmark "Use untrusted certificates". That is, let the program not check the authenticity of the certificate. Without any authentication.
@Curid commented on GitHub (May 28, 2022):
@MuratovAS Are you sure about that? What do you mean by "impervious CA"? Which Android version?
@binwiederhier commented on GitHub (Sep 24, 2023):
@MuratovAS I was so confused why I couldn't find this ticket anymore. This feature is requested a lot, so I do want to keep it open if you don't mind.
@kevin-king commented on GitHub (Sep 27, 2023):
I'm interested in this as well. I use https with ntfy in the browser. On Android, however, I point it at http and have another server entry in nginx config for port 80 so that changes to IP/port don't require a change to the Android app configuration. I'd say this is good enough of a solution for self hosting except for the fact that file attachments can't be downloaded over http. My workaround is to copy the url and paste it into my mobile browser (which doesn't have the https CA restriction).
@ghost commented on GitHub (Dec 8, 2023):
Can't you just import your own CA certificate into the Android user certificate store? The required setting in the app to utilize user certificates seems to be set: https://github.com/binwiederhier/ntfy-android/blob/main/app/src/main/res/xml/network_security_config.xml. Also make sure that the certificate is valid for your host, see https://github.com/home-assistant/companion.home-assistant/pull/1011/files.
(not an ntfy user, but I stumbled upon this issue when searching for a solution to a similar issue in Android)
@kevin-king commented on GitHub (Dec 10, 2023):
I don't exactly remember this one anymore, but I believe that yes, you can install a user cert as long as that user cert is legitimate. Meaning something from Let's Encrypt or any authority with a matching root cert to your phone's system root certs.
If memory serves, what you cannot do is install a self-signed cert, which is a reasonable thing to do for self-hosted LAN services that will never be exposed to the internet.
That said, this is becoming such a problem across all applications these days that I caved and now use a Let's Encrypt cert for my LAN-only services and do what you mention--install it into my Android system's User certs. It's just annoying to need real SSL certs in a LAN-only context. The more complicated the self-hosted setup gets the harder it is to maintain. I'll add that acme.sh has made this process MUCH better than with certbot.
@ghost commented on GitHub (Dec 10, 2023):
I just installed a self-signed certificate on Android. You just need to make sure you set the correct certificate properties during creation - take a look the the second link from my previous post if you are interested.
@kevin-king commented on GitHub (Dec 10, 2023):
Interesting thanks for testing. Out of curiosity, to which IP does
YOUR_HA_STATIC_IP_HERErefer? In my case, neither ntfy nor my reverse proxy pointing to it (throughntfy.mydomain.com) are public. Are you settingYOUR_HA_STATIC_IP_HEREto be your internal IP like10.x.x.x/192.168.x.x? Or are you setting it to a public static IP? (Please forgive me if this is a dumb question)@ghost commented on GitHub (Dec 10, 2023):
I am using the local IP address of the server which I connect to via LAN,
192.168.x.x.@Pysis868 commented on GitHub (Jul 17, 2024):
Already have my cert. Found this nice, but unfortunate summary, which may mean the dev would still need to add more to support this:
https://stackoverflow.com/a/56295643
@Fmstrat commented on GitHub (Apr 28, 2025):
Unfortunately, this doesn't seem to be the case as it's not working in my testing. Perhaps Ntfy uses a custom HTTP library that the trust store isn't set for?
@Fmstrat commented on GitHub (Apr 28, 2025):
After further investigation, this seems to be the case. Ntfy is using OkHTTP (just realized there is a separate repo there for this): https://github.com/search?q=repo%3Abinwiederhier%2Fntfy-android+okhttp&type=code
I believe OkHTTP requires a Trust Store to be added from the system. Something like the below on every occurrence of the
Builder.Note, there could also be a secondary issue. I set up a proxy using a Let's Encrypt cert, and use my local DNS server to set the valid domain host to point to an internal IP. Ntfy can't seem to connect to that, either. My only guess is that Ntfy is for some reason ignoring the system DNS setting there, but I don't see anything obvious for that.
@Fmstrat commented on GitHub (Apr 28, 2025):
Ok, got it working. This turned out to be a combination of things that led to it looking like a cert issue. If you are running into issues with a self-hosted CA:
ntfyapp. This is important as the cache is holding login credentials, and if you change your default server in the app, these credentials may invalidate if you are swapping a URLNTFY_BASE_URLto the appropriate URL (this turned out to be my issue, as I was switching from an external to an internal domain)After that, all is golden. I'm guessing the Trust Manager I mention above is somewhere else in the code away from the OkHTTP builder.
@binwiederhier commented on GitHub (Jan 4, 2026):
I am working on this in https://github.com/binwiederhier/ntfy-android/pull/149. It's still WIP, but it'll turn out great. The trusted cert part is already working nicely, but I am working on a better user flow. I'll also add a way to add mTLS (which is also working, but a little awkward).
@binwiederhier commented on GitHub (Jan 4, 2026):
Relates to #530
@binwiederhier commented on GitHub (Jan 5, 2026):
📢 ❓ Question: For the "manage certificates" feature, would people be fine to just trust specific certificates, or do people want to add a CA cert and trust anything signed by that?
@binwiederhier commented on GitHub (Jan 5, 2026):
It's looking really good: https://ntfy.sh/file/1znMWy4YkEdf.webm
@binwiederhier commented on GitHub (Jan 6, 2026):
@cyb3rko has offered to test it out a bit. He made some good comments around how the
CertUtilin the PR (https://github.com/binwiederhier/ntfy-android/pull/149). Let me try to summarize them here (please correct me if I'm wrong):Please let me know if this is accurate.
--
I think what this means is this:
(a) In the flow "AddFragment -> TrustedCertFragment" (= unknown certificate, UNKNOWN mode), when we click "Trust", we add a "(baseUrl, cert)" combo to the database, e.g. "https://ntfy.example.com, ". If I connect to https://10.0.0.1 and it presents the same cert, it is not trusted, but TrustedCertFragment dialog is shown again instead, and when I click "Trust", I have a second entry.
This is how Firefox does it too:
(b) In the "CertificateSettingsFragment -> TrustedCertFragment" (= manually add cert, ADD mode), we show a baseUrl field that the user has to fill out.
(c) What about CAs? I honestly don't know how to handle that. Do we have a third section for CAs in the CertificateSettingsFragment, and then we add the CA to the combinedTrustManager, but WITH hostname validation enabled?
@cyb3rko commented on GitHub (Jan 7, 2026):
At least NOT by default. If anybody can deliver valid use-cases of ignoring hostname validation, we could talk about a opt-out option for that.
To be exact not only based on the hostname, but rather the whole endpoint (on transport layer, so without protocol or full URL), so the combination of hostname/IP address and port.
In that case, we should remove the previous certificate for that exact endpoint. Having two trusted certificates for a single endpoint is not really a good solution in my eyes. But to be fair, I don't know how for example Firefox handles that edge-case.
@cyb3rko commented on GitHub (Jan 7, 2026):
I feel like supporting "Trusted certificates" and "Trusted CAs" is a bit over-the-top.
Either you add your own CA and all your self-hosted endpoints are trusted if correctly signed, OR you have to trust your server certificates individually.
If we combine both, it becomes messy real quick.
@binwiederhier commented on GitHub (Jan 8, 2026):
I think I'll try to model it after Firefox's UIs. It has
It shouldn't be difficult to update the code to achieve this, and it'll be more secure. I'm note sure if I will name it the same, because Firefox's naming is weird as hell. Chrome has "Local certificates" and "Your certificates". Local certificates are split into trusted certs, intermediate certs and distrusted certs. That's also a tad weird.
@binwiederhier commented on GitHub (Jan 8, 2026):
I think just doing "Client certs" and "Trusted certs" (per-hostname exceptions) would be best for now. If you have a custom CA, then this will still work, because you can manually click "Trust".
@binwiederhier commented on GitHub (Jan 9, 2026):
I've updated the code and it's much cleaner now. I still have to do a lot of cleanup, but I like the approach more.
@binwiederhier commented on GitHub (Jan 10, 2026):
I like this enough to merge it. I've extensively self-reviewed https://github.com/binwiederhier/ntfy-android/pull/149. Please feel free to still review and/or comment on this design.