mirror of
https://github.com/binwiederhier/ntfy.git
synced 2026-05-09 08:26:00 +02:00
[GH-ISSUE #69] End-to-end encryption (E2E) between clients (Android app, CLI, web app) #55
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#55
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 @binwiederhier on GitHub (Dec 29, 2021).
Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/69
It should be possible to e2e encrypt messages, like this:
Or this
The message should look like this:
It is important to me that the solution is widely supported and can be easily implemented in all languages. Ideally something like
gpgorage, but I doubt such a format exists.@binwiederhier commented on GitHub (Jun 30, 2022):
I looked at this a little today, and sadly had to rule out
gpg, because the library for Go is deprecated, and I don't want to build on deprecated technology. I also looked atagea while ago and even opened an issue here (https://github.com/FiloSottile/age/discussions/404) to ask for support in other languages; and sadly there is not enough support.I also played with
opensslto see if I can encrypt and protect the integrity (~ AEAD-style), but I wasn't successful.I will try and play some more, but I believe I'll have to implement my own format. Something similar to what I have done here (https://syncany.readthedocs.io/en/latest/security.html#encrypting-new-files), though much simpler hopefully.
@binwiederhier commented on GitHub (Jul 1, 2022):
Here's the basic message structure: https://github.com/binwiederhier/ntfy/pull/354. This implements the exact same thing that Pushbullet does (https://docs.pushbullet.com/#encryption) and is even compatible with it. This was super easy. The trickier part is figuring out the UX of this. I'll have to think about that.
@binwiederhier commented on GitHub (Jul 2, 2022):
This can encrypt a message with a key, but a key is not a password. The password we'll still have to derive using pbkdf2.
The question is now:
Relatively easy would be:
@binwiederhier commented on GitHub (Jul 7, 2022):
Even though I have not updated this ticket, I have been working on it in the #354 branch. I've explored JWE as a solution for the crypto format, and implemented PoCs in PHP and Python and Go.
After realizing that that won't work for attachments, I have switched gears after a discussion with a co-worker and with @wunter8.
Proposal
General flow
Key derivation
Encryption file format
"ntfy2586v1" || tag (128 bits) || iv (96 bits) || ciphertext [aes-256-gcm]Publishing (without attachment)
Publishing (with attachment)
@goalieca commented on GitHub (Jul 8, 2022):
Password:
KDF:
@goalieca commented on GitHub (Jul 8, 2022):
It might also be worth adding 'kid' to the JWEs so that can give users a chance to change or rotate their passwords. Changing the passwords has some choices because of historically encrypted messages. Since the user holds the password it would be up to them to have to re-encrypt every message.
Using a key-encryption-key (KEK) to encrypt the JWEs would provide better security. The KEK would be wrapped by the password and the client would store the wrapped KEK somewhere. It could be password wrapped, it could be key-vaulted, who knows. How to transport that KEK between endpoints? iOS has cloud-sync as an example. Or if it was wrapped by the password (pbkdf2) then could nfty itself do it? Rotation the password on the KEK is easier as there's just one. Still hard to rotate the KEK though.
I'll think some more on ergonomics of this.
@binwiederhier commented on GitHub (Jul 14, 2022):
I am still working on this. It's going slow (mostly due to personal commitments), but I have still managed to come up with a design that I think I like. So here it goes:
Proposal 7/13
General flow
Key derivation
sha256(topic)as a salt (e.g.sha256(mytopic))Encryption file format
{"alg":"dir","enc":A256GCM"}) is supportedUse cases
1. Unencrypted message (headers)
Request (HTTP)
Request (via curl)
Response
2. Unencrypted message (JSON)
Request (HTTP)
Request (via curl)
Response
3. Unencrypted message with attachment (headers + attachment)
Request (HTTP)
Request (via curl)
Response
4. Unencrypted message with attachment (multipart: JSON + attachment) [** new]
Request (HTTP)
Request (via curl)
Response
5. Encrypted message (JWE-encrypted JSON) [** new]
Request (HTTP)
Request (via curl)
Response
6. Encrypted with attachment (multipart: JWE-encrypted JSON + JWE-encrypted attachment) [** new]
Request (HTTP)
Request (via curl)
Response
Issues/questions
The salt for PBKDF2 is the topic URL. In some cases, endpoints are different and clients will derive an "incorrect key". Any ideas for a better salt?We'll usesha256(topic)instead@goalieca commented on GitHub (Jul 14, 2022):
@steelman commented on GitHub (Sep 6, 2022):
Friendly reminder: environment variables are only little less bad means to pass secrets than command line. Otherwise +1 (or more).
@aksdb commented on GitHub (Oct 29, 2022):
I want to throw in two considerations regarding the decision against "age" and "openpgp":
golang.org/xtree is no longer maintained, but they even referenced the existing fork from ProtonMail as a successor for people who continue using OpenPGP. We use it in production, for example. (Just as ProtonMail does, I would assume.)agedoes not have existing implementations in a lot of languages, rolling your own scheme doesn't either. If you start implementing a scheme, you might as well use one with a spec. The advantage over a custom / own scheme is obviously that it is already more battle tested and you have reference implementations to test against.@binwiederhier commented on GitHub (Oct 30, 2022):
@aksdb Thanks for the comments.
Re 1: Thanks for the correction. I was not aware that there was another active implementation.
Re 2: The scheme that I picked is not a roll-your-own. It's a subset of JWE. I picked very small subset, so that I could implement it in many different languages easily. I already did it in Python, PHP, Go, and (partially) JS. It is understandable that you think it's roll-your-own, because this ticket discussion is long and old, but this is the one I picked: https://github.com/binwiederhier/ntfy/issues/69#issuecomment-1183839284 -- which is JWE with AES-256-GCM in "dir" mode (
{"alg":"dir","enc":A256GCM"}).Re 2 (age): I did approach the age devs in the GitHub discussions asking for different implementations, and while there is interest, it doesn't seem like it's been done or actively worked on/maintained. Most of the chosen scheme I could implement in 10 lines of code in most languages. It's just AES-256-GCM and a bunch of base64-ing. Simple and I've done that many many times. I'm not new to this :)
@aksdb commented on GitHub (Oct 30, 2022):
Sounds good, thanks for the clarification (and all the effort you put into this project).
@blewsky commented on GitHub (Nov 8, 2022):
Awesome project @binwiederhier! Great work.
Password protection would be a really great feature that would make the tool a lot more powerful.
A small question (I have no crypto background): What would happen if two people used (e.g. by accident) the same topic with a different password? Would that be possible? I guess they wouldn't receive the other person's notification and only their own (because they can only decipher their own message)?! Would they get an error message of an attempted notification/wrong password?
@Fysac commented on GitHub (Apr 10, 2023):
Regarding key derivation: since this is a new design and you have a choice, it doesn't make much sense to use PBKDF2. Instead, a memory-hard hash function like Argon2 or scrypt is far preferable.
If you ultimately stick with PBKDF2, the proposed number of iterations (50,000) is too low to defend against brute-force attacks on modern hardware. 1Password uses 650,000 iterations now, and OWASP recommends at least 600,000 iterations of PBKDF2-HMAC-SHA256: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#pbkdf2
@binwiederhier commented on GitHub (Apr 10, 2023):
I think this is a great recommendation, thank you. I think I picked something "low" for PBKDF2 since there are clients that will have to derive the password every time, which would make sending messages have a delay of 1s or something, or require storing the key somewhere. I'll experiment with the other key derivation functions though.
We now also have access tokens since 2.x, so it may be feasible to ditch the password altogether. I'll look at it when I eventually get to this ticket.
@gardient commented on GitHub (Aug 22, 2023):
@blewsky according to the "General Flow" in https://github.com/binwiederhier/ntfy/issues/69#issuecomment-1183839284 you would get a notification with
(encrypted message)This would only protect content, not the topic itself, you could have a combined encrypted and unencrypted topic even.
also, slightly interesting tidbit, there is nothing really stopping you from creating a custom client and using this with the current setup, the only thing you would miss is the native
Encodingheader support@MzHub commented on GitHub (Sep 3, 2023):
What is the relation here to the Web Push Payload Encryption?
I gave an application server
https://ntfy.sh/mytopicas the Web Pushendpointinstead of the browser's generated endpoint URL. This resulted in receiving encrypted binary blobs in the ntfy Android app.Seems to me like the Android app could act like a browser and have its own keys (per subscription), while the CLI or whatever would act as the application server and have its own keys. Also using Web Push libraries would avoid rolling own crypto.
If I'm on the wrong track here I'm interested in learning more about what the difference is.
@SilverBut commented on GitHub (Sep 22, 2023):
I'm happy to see E2E as a feature to ensure every content being pushed is only visible for the push source and the certain recipients, and not readable for either some vendor's push server (like APNs or Firebase) or temporary push server. Additionally, I think passphrase instead of key is better, because generate a passphrase requires zero knowledge and passphrase can be shared easily. Generate key requires more work, and exchange key content offline is harder.
Thus I think JWE or GPG is good enough. As for Web Push Payload Encryption, it is a pre-HTTPS-everywhere tech, more about preventing insecure push providers using HTTP to send your content, as it stated in the blog:
@Fmstrat commented on GitHub (Sep 22, 2023):
Seems like much of this could be overkill. A simpler way is to treat it like every other method (Signal, Matrix, etc). Provide a way to send a push that tells the client to check a predetermined URL via HTTPS using its bearer token. The user can then determine if they wish to do E2E, but this would be enough to keep Google's eyes out.
This is basically what I do for Matrix API from a shell script for pushes via Element/Matrix.
@MzHub commented on GitHub (Sep 25, 2023):
My reading is that it does not state that Web Push encryption protects from insecure push providers using HTTP.
First they assume everyone uses HTTPS, but "HTTPS can only guarantee that no one can snoop on the message in transit to the push service provider."
Then they go on to explain that HTTPS isn't End-to-End Encryption, and E2EE is needed to prevent Push Providers from snooping on messages, which is why they added E2EE to Web Push.
Part of the reason I'm asking if Web Push Payload Encryption has been considered is because it is an existing solution widely used in production already.
Another reason is that while people claim "Web Push compatibility", there can not be any meaningful Web Push compatibility without clients that can decrypt the messages.
Ntfy is almost Web Push compatible. I've had third party services (application servers I do not own) send push messages into my test endpoint. The only missing piece is decryption.
@CyberShadow commented on GitHub (Sep 25, 2023):
HTTPS can only guarantee that no one can snoop on the message in transit to the TLS terminator. This could be Cloudflare, a corporate security proxy, an evil MITM proxy whose operator has the private key of some TLS certificate trusted by your device, etc. HTTPS is not enough by itself.
@cmj2002 commented on GitHub (Nov 21, 2023):
Any updates for this feature?
@dtinth commented on GitHub (Jul 8, 2024):
I’d like to suggest NaCl for consideration as an encryption/decryption library. In JavaScript TweetNaCl.js can be used, and for Android Lazysodium can be used. They support both symmetric and asymmetric encryption.
@7heo commented on GitHub (Oct 13, 2024):
I would like to suggest a two-folds solution for implementing E2E in ntfy; which I believe would greatly ease its implementation.
Sender side
Instead of going
Or
as suggested, why not using:
Notice the use ofNever mind,-d@withcurlinstead of-T, which results in aPOSTand not aPUT(I don't know ifPUTis currently implemented in ntfy)PUTis clearly implemented, it is even in the repository's summary.Of course, it is necessary to add a recipient flag (
-r) per recipient.This method would literally not require any change to the server code.
Receiver side
On the receiver's end, the message is obtained as usual, but in case the first line is
-----BEGIN PGP MESSAGE-----, the message is processed by an appropriate app (OpenKeychain on Android, and PGPro on iOS), so that the resulting clear-text can be displayed; or, if it failed, either the app displays a warning (or error) or silently ignores it, depending on per-topic configuration.It would be probably good to display an appropriate warning by default, when receiving a PGP encrypted message, if no PGP app is installed on the device.
@bogorad commented on GitHub (Oct 28, 2024):
Why all this complexity - do as Pushbullet does: if you set a secret on one end, all other endpoints won't be able to read messages unless they know the same secret. Doesn't really matter which encryption library is used, nacl is as good as any. Just mandate a lengthy secret.
@7heo commented on GitHub (Nov 15, 2024):
What you advertise as "complexity" (pgp) is only the standard way to do things, supports both asymmetric and symmetric encryption, is already portable because it is standard, is distributed by any stable distribution (Linux or otherwise), and is factually orders of magnitude simpler than your proposal. Just because you will end up "using docker anyway" doesn't mean it's okay to force heaps of dependencies and sometimes barely-reviewed software ripe for supply-chain attacks on everyone. Please, no gaslighting, I'm being thorough, not "complex". And pgp isn't a "library". Ops matter.
Don't roll your own crypto.
From Phil Zimmermann's (PGP creator) Introduction to Cryptography (Page 43, section "Beware of snake oil"):
@bogorad commented on GitHub (Nov 15, 2024):
I have profound respect for Zimmermann, I actually started studying cryptography by reading his paper on PGP, also used to be a paid user of his Silent Circle project.
But PGP is total garbage in respect to useability. It is needlessly complex and convoluted. No one sane uses it in the 21st century (unless they are forced to). That's the reason we have Signal messenger and other projects with great usability and security. Dragging GPG into the new world is just crazy.
@7heo commented on GitHub (Nov 15, 2024):
Good thing OpenKeyChain and PGPro are great apps that are well designed and UX focused.
Also, "Secure, Convenient, Doesn't need hundreds of millions USD to implement; pick any two."
@MzHub commented on GitHub (Nov 16, 2024):
As stated earlier there already is a standard for end-to-end push message encryption, and it is RFC8291.
To me it seems it would be beneficial for both interoperability and security ("don't roll your own crypto") to implement the standard.
@brian6932 commented on GitHub (Nov 16, 2024):
PGP sucks, and I'd hardly consider it standardized, on the other hand, SSH's actually standardized, and broadly used in modern programs. It has replaced PGP in all modern contexts.
@bogorad commented on GitHub (Nov 16, 2024):
or age, X25519 is fairly common.
@dtinth commented on GitHub (Nov 16, 2024):
Speaking about SSH, I recently took a look at age that was earlier suggested by @binwiederhier and found that:
ssh-rsaandssh-ed25519).Personally, I prefer asymmetric encryption (public/private keys) over passwords, so that if there are many senders sending notifications to the same topic, different senders cannot decrypt each other's messages.
@7heo commented on GitHub (Nov 16, 2024):
I was not aware that there was a standard for E2EE of push messages specifically. I am surprised, but also thankful: that is valuable information. However, that would imply specific tooling on the sender, would it not? That was precisely what my proposal aimed to avoid.
Absolutely fair. I'd also recommend SSH instead of PGP, now that you mention it. I don't know what apps can be used to support it on a mobile terminal, though.
Exactly. The same goes for receivers.
@steelman commented on GitHub (Nov 19, 2024):
@brian6932
FYI RFC 9580
@K4LCIFER commented on GitHub (Nov 22, 2024):
I'm a little confused about the existence of this issue. The Unified Push spec explicitly states that notification messages must be encrypted:
Does Ntfy not adhere to the Unified Push spec?
@aksdb commented on GitHub (Nov 22, 2024):
Does it claim anywhere it would? I think the docs are quite clear that it implements its own protocol.
@dtinth commented on GitHub (Nov 22, 2024):
@K4LCIFER There are 3 parties. Sender → Ntfy → Receiver.
So it is encrypted, but not end-to-end from Sender to Receiver. Right now Ntfy as the intermediary has to un-encrypt the message from the Sender, and then re-encrypt it for the Receiver, so it is technically possible for Ntfy service to access to the message contents. E2EE makes it impossible for the intermediary to access the message contents.
@MzHub commented on GitHub (Dec 16, 2024):
I do not know if Ntfy does but UnifiedPush heavily pushes users in the direction of using Ntfy so I can see why someone could mistake it for being compatible with the UnifiedPush spec.
@KizzyCode commented on GitHub (Jun 3, 2025):
A lot of stuff has already been discussed; so I try to keep it short.
First: Complexity kills the cat – it does not only invite bugs and vulnerabilities, but also ensures that users will not set things up correctly, if they try at all. Regardless of whatever finally gets implemented here, I think that it is important that the pairing is as simple as possible – everything that requires complex distribution and maintenance of the correct public keys becomes hairy IMO.
My suggestion for usability and ease-of-pairing: Avoid passwords (at least as first-class secrets), and use an anchor-scheme to setup a topic as encrypted instead; e.g. something like
https://ntfy.example.com/mytopic#mysymmetricencryptionkey– this is well-established in other use-cases, and easy to distribute (can be shared out-of-band, encoded in a QR-code, etc). This ensures that a naive user does not need to know or care that they publish/subscribe to an encrypted topic, and does not have to think about passwords at all.@schklom commented on GitHub (Nov 11, 2025):
Btw, ntfy officially supports UnifiedPush: https://docs.ntfy.sh/publish/#unifiedpush