-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add recipient-keyed encrypted drops and CLI #1
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
Open
EmmanuelKeifala
wants to merge
7
commits into
abdullah4tech:main
Choose a base branch
from
EmmanuelKeifala:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7303f3d
feat(api): add atomic recipient drop opens
EmmanuelKeifala 37525f5
feat(web): atomically open recipient drops
EmmanuelKeifala 6a95781
feat(cli): add encrypted env sharing
EmmanuelKeifala a5f7c46
docs(cli): explain critical flow invariants
EmmanuelKeifala 80b9afe
docs(cli): lead fixture with its purpose
EmmanuelKeifala 9aff94f
Update config.zig
EmmanuelKeifala ec96b30
fix: address recipient drop review findings
EmmanuelKeifala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "crypto/ecdh" | ||
| "crypto/rand" | ||
| "encoding/base64" | ||
| "encoding/json" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "path/filepath" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
| ) | ||
|
|
||
| func testPublicKey(t *testing.T) string { | ||
| t.Helper() | ||
| private, err := ecdh.P256().GenerateKey(rand.Reader) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| return base64.RawURLEncoding.EncodeToString(private.PublicKey().Bytes()) | ||
| } | ||
|
|
||
| func testStore(t *testing.T) *Store { | ||
| t.Helper() | ||
| store, err := OpenStore(filepath.Join(t.TempDir(), "ashdrop.db")) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| t.Cleanup(func() { | ||
| if err := store.Close(); err != nil { | ||
| t.Error(err) | ||
| } | ||
| }) | ||
| return store | ||
| } | ||
|
|
||
| func TestValidPublicKeyRejectsOffCurvePoint(t *testing.T) { | ||
| if !validPublicKey(testPublicKey(t)) { | ||
| t.Fatal("generated P-256 public key was rejected") | ||
| } | ||
|
|
||
| offCurve := make([]byte, 65) | ||
| offCurve[0] = 0x04 | ||
| if validPublicKey(base64.RawURLEncoding.EncodeToString(offCurve)) { | ||
| t.Fatal("off-curve SEC1 point was accepted") | ||
| } | ||
| } | ||
|
|
||
| func TestCreateRejectsInvalidOrPartialRecipientKeys(t *testing.T) { | ||
| store := testStore(t) | ||
| handler := newHandler(store) | ||
| valid := testPublicKey(t) | ||
| offCurve := make([]byte, 65) | ||
| offCurve[0] = 0x04 | ||
| invalid := base64.RawURLEncoding.EncodeToString(offCurve) | ||
|
|
||
| for name, keys := range map[string]struct{ recipient, ephemeral string }{ | ||
| "off-curve recipient": {recipient: invalid, ephemeral: valid}, | ||
| "missing recipient": {ephemeral: valid}, | ||
| "missing ephemeral": {recipient: valid}, | ||
| } { | ||
| t.Run(name, func(t *testing.T) { | ||
| body, err := json.Marshal(map[string]any{ | ||
| "ciphertext": "ciphertext", | ||
| "iv": "iv", | ||
| "recipientPub": keys.recipient, | ||
| "ephemeralPub": keys.ephemeral, | ||
| }) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| request := httptest.NewRequest(http.MethodPost, "/api/secrets", strings.NewReader(string(body))) | ||
| response := httptest.NewRecorder() | ||
| handler.ServeHTTP(response, request) | ||
| if response.Code != http.StatusBadRequest { | ||
| t.Fatalf("status = %d, want %d", response.Code, http.StatusBadRequest) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestPartialRecipientMaterialIsUnavailable(t *testing.T) { | ||
| store := testStore(t) | ||
| if err := store.Put("legacy", Secret{ | ||
| Ciphertext: "ciphertext", | ||
| IV: "iv", | ||
| ExpiresAt: time.Now().Add(time.Hour).Unix(), | ||
| NotifyTok: "notify", | ||
| EphemeralPub: testPublicKey(t), | ||
| }); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| for name, operation := range map[string]func() (*Secret, error){ | ||
| "metadata": func() (*Secret, error) { return store.Metadata("legacy") }, | ||
| "fetch": func() (*Secret, error) { return store.Fetch("legacy") }, | ||
| "open": func() (*Secret, error) { return store.Open("legacy") }, | ||
| } { | ||
| t.Run(name, func(t *testing.T) { | ||
| secret, err := operation() | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if secret != nil { | ||
| t.Fatal("partial recipient material exposed a drop") | ||
| } | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.