forked from LeSuisse/vault-gpg-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Switch to protonmail/crypto for key/sig expiry #9
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
Merged
trishankatdatadog
merged 6 commits into
master
from
trishankatdatadog/protonmail-crypto
Oct 20, 2020
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8137e3c
switch to protonmail/crypto fork
trishankatdatadog 06e76b0
use protonmail/crypto fork for key/sig expiry
trishankatdatadog 17bef07
update to latest protonmail/crypto
trishankatdatadog 11d6f66
fix nondeterminism in tests
trishankatdatadog 03ab017
remove build script we do not use
trishankatdatadog bc3ad7b
functions to read keyring vs entity
trishankatdatadog 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,21 +14,21 @@ jobs: | |
| runs-on: ${{ matrix.os }} | ||
| name: Tests (${{ matrix.os }}) | ||
| steps: | ||
| - uses: actions/checkout@v2.3.3 | ||
| - uses: actions/setup-go@v2.1.2 | ||
| - uses: actions/checkout@v2 | ||
| - uses: actions/setup-go@v2 | ||
| with: | ||
| go-version: '^1.15.0' | ||
| - name: Tests | ||
| run: "go test -race -coverprofile='coverage.txt' -covermode=atomic -v ./gpg/" | ||
| - uses: codecov/codecov-action@v1.0.13 | ||
| - uses: codecov/codecov-action@v1 | ||
| with: | ||
| token: ${{ secrets.CODECOV_TOKEN }} | ||
| static_analysis: | ||
| runs-on: ubuntu-20.04 | ||
| name: Run static analysis and linting | ||
| steps: | ||
| - uses: actions/checkout@v2.3.3 | ||
| - uses: actions/setup-go@v2.1.2 | ||
| - uses: actions/checkout@v2 | ||
| - uses: actions/setup-go@v2 | ||
| with: | ||
| go-version: '^1.15.0' | ||
| - name: Go fmt | ||
|
|
@@ -39,15 +39,3 @@ jobs: | |
| run: go run honnef.co/go/tools/cmd/staticcheck -checks 'all,-ST1000' ./... | ||
| - name: Gosec | ||
| run: go run github.com/securego/gosec/cmd/gosec -exclude=G104 ./... | ||
| build_script: | ||
| runs-on: ubuntu-20.04 | ||
| name: Build across all supported architectures | ||
| steps: | ||
| - uses: actions/[email protected] | ||
| - uses: actions/[email protected] | ||
| with: | ||
| go-version: '^1.15.0' | ||
| - name: Build | ||
| run: ./scripts/build.sh | ||
| - name: Display checksum | ||
| run: find ./pkg/ -name '*.sha256sum' -exec cat {} \; | ||
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
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 |
|---|---|---|
|
|
@@ -53,19 +53,24 @@ func TestBackend_Signing(t *testing.T) { | |
| b, storage := getTestBackend(t) | ||
|
|
||
| keyData := map[string]interface{}{ | ||
| "real_name": "Vault", | ||
| "email": "[email protected]", | ||
| "comment": "Comment", | ||
| "key_bits": 4096, | ||
| "exportable": true, | ||
| "real_name": "Vault", | ||
| "email": "[email protected]", | ||
| "comment": "Comment", | ||
| "key_bits": 2048, | ||
| } | ||
| base64InputData := "bXkgc2VjcmV0IGRhdGEK" | ||
| otherBase64InputData := "c29tZSBvdGhlciBkYXRhCg==" | ||
| masterName := "test" | ||
| testAccStepCreateKey(t, b, storage, masterName, keyData, false) | ||
| // NOTE: choose expiration time long enough that the key does not expire by the time we are done creating it. | ||
| sigExpiresAfterSeconds := 6 | ||
| keyExpiresAfterSeconds := 2 * sigExpiresAfterSeconds | ||
|
|
||
| // NOTE: every test uses a separate master key so that parallel tests do not affect each other. | ||
| t.Run("signing with master key", func(t *testing.T) { | ||
| signature := testAccStepSign(t, b, storage, masterName, base64InputData) | ||
| masterName := "master1" | ||
| testAccStepCreateKey(t, b, storage, masterName, keyData, false) | ||
| signature := testAccStepSign(t, b, storage, masterName, map[string]interface{}{ | ||
| "input": base64InputData, | ||
| }) | ||
| testAccStepVerify(t, b, storage, masterName, map[string]interface{}{ | ||
| "input": base64InputData, | ||
| "signature": signature, | ||
|
|
@@ -77,10 +82,12 @@ func TestBackend_Signing(t *testing.T) { | |
| }) | ||
|
|
||
| t.Run("signing with subkey", func(t *testing.T) { | ||
| masterName := "master2" | ||
| testAccStepCreateKey(t, b, storage, masterName, keyData, false) | ||
| subkeyRespData := testAccStepCreateSubkey(t, b, storage, masterName, map[string]interface{}{}) | ||
| subkeyID := subkeyRespData["key_id"].(string) | ||
| testAccStepReadSubkey(t, b, storage, masterName, subkeyID) | ||
| signature := testAccStepSignWithSubkey(t, b, storage, masterName, subkeyID, map[string]interface{}{ | ||
| signature := testAccStepSign(t, b, storage, masterName, map[string]interface{}{ | ||
| "input": base64InputData, | ||
| }) | ||
| testAccStepVerify(t, b, storage, masterName, map[string]interface{}{ | ||
|
|
@@ -93,24 +100,44 @@ func TestBackend_Signing(t *testing.T) { | |
| }, false) | ||
| }) | ||
|
|
||
| t.Run("signing after expiration", func(t *testing.T) { | ||
| expireAfterSeconds := 1 | ||
| subkeyRespData := testAccStepCreateSubkey(t, b, storage, masterName, map[string]interface{}{ | ||
| "expires": expireAfterSeconds, // 1 second | ||
| t.Run("verification after key expiration", func(t *testing.T) { | ||
| masterName := "master3" | ||
| testAccStepCreateKey(t, b, storage, masterName, keyData, false) | ||
| testAccStepCreateSubkey(t, b, storage, masterName, map[string]interface{}{ | ||
| "expires": keyExpiresAfterSeconds, | ||
| }) | ||
| subkeyID := subkeyRespData["key_id"].(string) | ||
| testAccStepReadSubkey(t, b, storage, masterName, subkeyID) | ||
| signature := testAccStepSignWithSubkey(t, b, storage, masterName, subkeyID, map[string]interface{}{ | ||
| signature := testAccStepSign(t, b, storage, masterName, map[string]interface{}{ | ||
| "input": base64InputData, | ||
| "expires": expireAfterSeconds, | ||
| "expires": 0, // signature does not expire | ||
| }) | ||
| testAccStepVerify(t, b, storage, masterName, map[string]interface{}{ | ||
| "input": base64InputData, | ||
| "signature": signature, | ||
| }, true) | ||
| // Sleep for long enough that the subkey *should have* expired | ||
| time.Sleep(time.Duration(keyExpiresAfterSeconds) * time.Second) | ||
| testAccStepVerify(t, b, storage, masterName, map[string]interface{}{ | ||
| "input": base64InputData, | ||
| "signature": signature, | ||
| }, false) | ||
| }) | ||
|
|
||
| // TODO | ||
| t.Skipf("re-enable this test once keys and/or signatures expire") | ||
|
|
||
| t.Run("verification after sig expiration", func(t *testing.T) { | ||
| masterName := "master4" | ||
| testAccStepCreateKey(t, b, storage, masterName, keyData, false) | ||
| testAccStepCreateSubkey(t, b, storage, masterName, map[string]interface{}{ | ||
| "expires": 0, // subkey does not expire | ||
| }) | ||
| signature := testAccStepSign(t, b, storage, masterName, map[string]interface{}{ | ||
| "input": base64InputData, | ||
| "expires": sigExpiresAfterSeconds, | ||
| }) | ||
| testAccStepVerify(t, b, storage, masterName, map[string]interface{}{ | ||
| "input": base64InputData, | ||
| "signature": signature, | ||
| }, true) | ||
| // Sleep for long enough that the subkey and the signature *should have* expired | ||
| time.Sleep(time.Duration(3*expireAfterSeconds) * time.Second) | ||
|
|
||
| time.Sleep(time.Duration(sigExpiresAfterSeconds) * time.Second) | ||
| testAccStepVerify(t, b, storage, masterName, map[string]interface{}{ | ||
| "input": base64InputData, | ||
| "signature": signature, | ||
|
|
@@ -298,10 +325,10 @@ func testAccStepCreateSubkey(t *testing.T, b logical.Backend, s logical.Storage, | |
| return resp.Data | ||
| } | ||
|
|
||
| func testAccStepReadSubkey(t *testing.T, b logical.Backend, s logical.Storage, masterName string, subkeyName string) { | ||
| func testAccStepReadSubkey(t *testing.T, b logical.Backend, s logical.Storage, masterName string, subkeyID string) { | ||
| resp, err := b.HandleRequest(context.Background(), &logical.Request{ | ||
| Operation: logical.ReadOperation, | ||
| Path: "keys/" + masterName + "/subkeys/" + subkeyName, | ||
| Path: "keys/" + masterName + "/subkeys/" + subkeyID, | ||
| Storage: s, | ||
| }) | ||
| if err != nil { | ||
|
|
@@ -320,25 +347,10 @@ func testAccStepReadSubkey(t *testing.T, b logical.Backend, s logical.Storage, m | |
| } | ||
| } | ||
|
|
||
| func testAccStepSign(t *testing.T, b logical.Backend, s logical.Storage, masterName string, base64Input string) string { | ||
| func testAccStepSign(t *testing.T, b logical.Backend, s logical.Storage, masterName string, signData map[string]interface{}) string { | ||
| resp, err := b.HandleRequest(context.Background(), &logical.Request{ | ||
| Operation: logical.UpdateOperation, | ||
| Path: "sign/" + masterName, | ||
| Data: map[string]interface{}{ | ||
| "input": base64Input, | ||
| }, | ||
| Storage: s, | ||
| }) | ||
| if err != nil { | ||
| t.Error(err) | ||
| } | ||
| return resp.Data["signature"].(string) | ||
| } | ||
|
|
||
| func testAccStepSignWithSubkey(t *testing.T, b logical.Backend, s logical.Storage, masterName string, subkeyName string, signData map[string]interface{}) string { | ||
| resp, err := b.HandleRequest(context.Background(), &logical.Request{ | ||
| Operation: logical.UpdateOperation, | ||
| Path: "sign/" + masterName + "/subkeys/" + subkeyName, | ||
| Data: signData, | ||
| Storage: s, | ||
| }) | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you decide building on all architectures was slow or unreliable? Or not supported by the library?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too slow, and we don't release the built binaries anyway, so...