Skip to content

feat(bark): add optional AES-GCM encryption - #1062

Open
IceCodeNew wants to merge 4 commits into
nikoksr:mainfrom
IceCodeNew:feat/bark-aes-gcm
Open

IceCodeNew wants to merge 4 commits into
nikoksr:mainfrom
IceCodeNew:feat/bark-aes-gcm

Conversation

@IceCodeNew

Copy link
Copy Markdown

Description

Add optional AES-GCM encryption to the Bark service.

Call SetEncryptionKey with the same 16-, 24-, or 32-character ASCII key configured in the Bark app. Subsequent notifications encrypt the complete parameter object and POST device_key, ciphertext, and iv to /push. The IV is a fresh 12-character Bark-compatible nonce for every request. An empty key keeps the existing plaintext path.

This matches the Bark app AES-GCM wire format used by apprise#1684.

Motivation and Context

AES-GCM keeps the notification title and body private. Transit hops and a third-party Bark server only see ciphertext, so callers do not have to run and operate their own Bark server just to keep message content off someone else's disk.

Without a key, the service still sends plaintext, so existing callers are unchanged.

How Has This Been Tested?

  • go test -count=1 -race ./service/bark/
  • golangci-lint run --timeout=5m ./... (v2.12.2, 0 issues)
  • Interoperability vectors from Apprise for AES-128/192/256 with a fixed IV
  • Coverage for invalid keys, IV rotation across servers, fail-closed encryption errors, and plaintext regression

Screenshots / Output (if appropriate):

N/A

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (no code change)
  • Refactor (refactoring production code)
  • Other

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@IceCodeNew

Copy link
Copy Markdown
Author

Follow-up: device_key no longer lives on the encrypted parameter object.

Plaintext /push still uses postData with a required device_key field, including when the key is empty. Encrypted requests marshal notificationParams only, then send device_key, ciphertext, and iv on the outer request.

On the current CI failures:

  • lint is a golangci-lint v2.12.2 typecheck against Go 1.27 crypto/internal/randutil (method must have no type parameters). The official v2.12.2 binary does not understand Go 1.27 generic methods. Local golangci-lint built with go1.27.0 reports 0 issues on this package. build already passed.
  • label is Resource not accessible by integration on actions/labeler for a fork PR. That workflow cannot write labels from this head.

@pull-request-size pull-request-size Bot added size/L and removed size/XL labels Sep 4, 2026
IceCodeNew and others added 3 commits September 7, 2026 00:31
Validate raw ASCII keys before changing configuration and keep plaintext sends unchanged when encryption is disabled.

Encrypt notification parameters with a fresh Bark-compatible IV for each request. Keep device_key outside the ciphertext and stop before network I/O when encryption fails.

Cover key validation, known ciphertext vectors, plaintext compatibility, encrypted envelopes, IV rotation, and fail-closed behavior.

Amp-Thread-ID: https://ampcode.com/threads/T-01a06d8a-3f4a-7438-a100-609db8d61a48
Co-authored-by: Amp <[email protected]>
Add optional encryption to both usage examples and link the setter documentation for key and IV requirements.

Amp-Thread-ID: https://ampcode.com/threads/T-01a06d8a-3f4a-7438-a100-609db8d61a48
Co-authored-by: Amp <[email protected]>
Keep ASCII validation at the configuration boundary and generate the IV where the encrypted request is assembled.

Remove the helper-only IV test; the send test still checks the transmitted IV format and rotation between requests. Preserve ciphertext vectors, envelope assertions, and fail-closed coverage.
Keep postData unchanged and add encryption after the existing message serialization. Serialize the notification fields populated by Send separately from the device key.

Assert the complete decrypted field set without depending on a shared production payload type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant