8000 Embedded key loader by demonsh · Pull Request #82 · iden3/go-iden3-auth · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Embedded key loader #82

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
merged 21 commits into from
Jan 14, 2025
Merged

Embedded key loader #82

merged 21 commits into from
Jan 14, 2025

Conversation

demonsh
Copy link
Contributor
@demonsh demonsh commented Dec 26, 2024
  1. NewEmbeddedKeyLoader with embedded verification keys for:
  • authV2.json
  • credentialAtomicQueryMTPV2.json
  • credentialAtomicQueryMTPV2OnChain.json
  • credentialAtomicQuerySigV2.json
  • credentialAtomicQuerySigV2OnChain.json
  • credentialAtomicQueryV3-beta.1.json
  • credentialAtomicQueryV3OnChain-beta.1.json
  • linkedMultiQuery10-beta.1.json
  1. Updated readme

@demonsh demonsh changed the title Embeded key loader Embedded key loader Dec 26, 2024
olomix
olomix previously approved these changes Jan 2, 2025
vmidyllic
vmidyllic previously approved these changes Jan 8, 2025
olomix
olomix previously approved these changes Jan 9, 2025
README.md Outdated
}

resolvers := map[string]pubsignals.StateResolver{
"polygon:mumbai": resolver,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polygon:mumbai is not supported, could you update to polygon:amoy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

type EmbeddedKeyLoader struct {
keyLoader VerificationKeyLoader
cache map[circuits.CircuitID][]byte
cacheMu sync.RWMutex
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://pkg.go.dev/sync#RWMutex

A RWMutex must not be copied after first use.

Use pointer to sync.RWMutex to prevent copy in methods.

if e.keyLoader != nil {
key, err := e.keyLoader.Load(id)
if err == nil {
if e.useCache {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to deffer to prevent copy-past

Copy link
Contributor
@ilya-korotya ilya-korotya Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can set the deffer after cache check to not perform the deffer if the keys are found in the cache

})
}

func TestDefaultEmbeddedKeys(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loader := NewEmbeddedKeyLoader()
_, err := loader.Load("non-existent-circuit")
assert.Error(t, err)
assert.Contains(t, err.Error(), "failed to load default key")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compare error text is bad practice. Try to use assert.ErrorsIs or assert.ErrorAs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix

type EmbeddedKeyLoader struct {
keyLoader VerificationKeyLoader
cache map[circuits.CircuitID][]byte
cacheMu sync.RWMutex
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider to use https://pkg.go.dev/sync#Map

wg.Add(1)
go func() {
defer wg.Done()
key := loader.getFromCache(testID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, this test is not useful. Since you are testing parallel reads without write operations, there is no concurrency issue.

@@ -19,5 +20,9 @@ type FSKeyLoader struct {

// Load keys from embedded FS
func (m FSKeyLoader) Load(id circuits.CircuitID) ([]byte, error) {
return os.ReadFile(fmt.Sprintf("%s/%v.json", m.Dir, id))
file, err := os.ReadFile(fmt.Sprintf("%s/%v.json", m.Dir, id))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible attack: https://rowin.dev/blog/preventing-path-traversal-attacks-in-go
In your case, the path and filename are constants. It is secure. But make sure that the security issue is not reproduced in your implementation.

@demonsh demonsh dismissed stale reviews from olomix and vmidyllic via 4e4c5fc January 13, 2025 12:01
@demonsh demonsh merged commit 27356eb into main Jan 14, 2025
3 checks passed
@demonsh demonsh deleted the feature/embeded-key-loader branch January 14, 2025 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0