Skip to content
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

cluster: verify config signatures #1014

Merged
merged 5 commits into from
Aug 23, 2022
Merged

cluster: verify config signatures #1014

merged 5 commits into from
Aug 23, 2022

Conversation

corverroos
Copy link
Contributor

Adds --no-verify flags to charon run and charon dkg. Verify config otherwise.

Note that charon create cluster requires --no-verify since it doesn't sign the generated lock file.

category: feature
ticket: #589

@codecov
Copy link

codecov bot commented Aug 22, 2022

Codecov Report

Merging #1014 (6ef66ae) into main (9b1b974) will decrease coverage by 0.79%.
The diff coverage is 47.40%.

@@            Coverage Diff             @@
##             main    #1014      +/-   ##
==========================================
- Coverage   54.16%   53.37%   -0.80%     
==========================================
  Files         118      124       +6     
  Lines       13215    13836     +621     
==========================================
+ Hits         7158     7385     +227     
- Misses       5030     5404     +374     
- Partials     1027     1047      +20     
Impacted Files Coverage Δ
cluster/operator.go 73.49% <ø> (+5.40%) ⬆️
cmd/dkg.go 0.00% <0.00%> (ø)
tbls/tblsconv/tblsconv.go 40.44% <0.00%> (-2.93%) ⬇️
cluster/definition.go 53.95% <18.75%> (-1.68%) ⬇️
cluster/lock.go 51.53% <33.33%> (-4.11%) ⬇️
app/app.go 58.76% <37.50%> (+0.49%) ⬆️
dkg/dkg.go 47.81% <40.00%> (-0.53%) ⬇️
cluster/helpers.go 61.47% <46.66%> (-8.66%) ⬇️
cluster/test_cluster.go 85.98% <89.65%> (+85.98%) ⬆️
cmd/run.go 86.11% <100.00%> (+0.60%) ⬆️
... and 20 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Comment on lines +157 to +162
if err := lock.Verify(); err != nil && !conf.NoVerify {
return errors.Wrap(err, "cluster lock signature verification failed. Run with --no-verify to bypass verification at own risk")
} else if err != nil && conf.NoVerify {
log.Warn(ctx, "Ignoring failed cluster lock signature verification due to --no-verify flag", err)
}

Copy link
Contributor

@xenowits xenowits Aug 23, 2022

Choose a reason for hiding this comment

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

Suggested change
if err := lock.Verify(); err != nil && !conf.NoVerify {
return errors.Wrap(err, "cluster lock signature verification failed. Run with --no-verify to bypass verification at own risk")
} else if err != nil && conf.NoVerify {
log.Warn(ctx, "Ignoring failed cluster lock signature verification due to --no-verify flag", err)
}
err := lock.Verify(); err != nil {
if !conf.NoVerify {
return errors.Wrap(err, "cluster lock signature verification failed. Run with --no-verify to bypass verification at your own risk")
}
if conf.NoVerify {
log.Warn(ctx, "Ignoring failed cluster lock signature verification due to --no-verify flag", err)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not of a fan of this verbose style

Copy link
Contributor

Choose a reason for hiding this comment

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

how is this "more" verbose? is there a go guideline that i can read upon?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

More lines and more if statements?

cluster/definition.go Outdated Show resolved Hide resolved
} else if !ok {
return false, errors.Wrap(err, "config signature mismatch")
return errors.New("invalid operator config signature", z.Str("operator_address", o.Address))
Copy link
Contributor

@xenowits xenowits Aug 23, 2022

Choose a reason for hiding this comment

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

nit

Suggested change
return errors.New("invalid operator config signature", z.Str("operator_address", o.Address))
return errors.New("invalid operator config signature", z.Str("operator_address", o.Address), z.Str("config_signature", string(digest[:])))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is the in the definition file, and humans cannot understand hex string in any case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

think about signal to noise, logging more is seldom better. Log only what is actually useful.

} else if !ok {
return false, errors.Wrap(err, "enr signature mismatch")
return errors.New("invalid operator enr signature", z.Str("operator_address", o.Address))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return errors.New("invalid operator enr signature", z.Str("operator_address", o.Address))
return errors.New("invalid operator enr signature", z.Str("operator_address", o.Address), z.Str("enr_signature", string(digest[:])))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same

} else if !ok {
return false, errors.Wrap(err, "config signature mismatch")
return errors.New("invalid operator config signature", z.Str("operator_address", o.Address))
Copy link
Contributor

Choose a reason for hiding this comment

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

discussion: should we also log the invalid and valid sigs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

signal to noise, this would be noise

Co-authored-by: Abhishek Kumar <43061995+xenowits@users.noreply.github.com>
@@ -54,6 +58,69 @@ func verifySig(addr string, digest []byte, sig []byte) (bool, error) {
return actual == expect, nil
}

// signOperator return the operator with config hash and enr EIP712 signatures by the provided k1 private key.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// signOperator return the operator with config hash and enr EIP712 signatures by the provided k1 private key.
// signOperator returns the operator with signed config hash and EIP712 signed ENR using the provided k1 private key.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

did something else

return b, nil
}

// signEIP712 signs the config hash digest and returns the signature.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// signEIP712 signs the config hash digest and returns the signature.
// signEIP712 signs the message and returns the signature.

func signEIP712(secret *ecdsa.PrivateKey, address string, message []byte) ([]byte, error) {
const nonce = 0

digest, err := digestEIP712(address, message, nonce)
Copy link
Contributor

Choose a reason for hiding this comment

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

discussion: is nonce a required field?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

at the moment yes

Comment on lines +183 to +187
if err != nil {
return errors.Wrap(err, "verify lock signature aggregate")
} else if !ok {
return errors.New("invalid lock signature aggregate")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
if err != nil {
return errors.Wrap(err, "verify lock signature aggregate")
} else if !ok {
return errors.New("invalid lock signature aggregate")
}
if err != nil {
return errors.Wrap(err, "verify lock signature aggregate")
}
if !ok {
return errors.New("invalid lock signature aggregate")
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see it as the same check block, so prefer else to indicate that

@@ -86,6 +86,16 @@ func KeyToCore(key *bls_sig.PublicKey) (core.PubKey, error) {
return core.PubKeyFromBytes(b)
}

// SigFromBytes converts a bytes into a kryptology bls signature.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// SigFromBytes converts a bytes into a kryptology bls signature.
// SigFromBytes converts secret bytes into a kryptology bls signature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

did something else

Copy link
Contributor

@xenowits xenowits left a comment

Choose a reason for hiding this comment

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

LGTM!

@corverroos corverroos added the merge when ready Indicates bulldozer bot may merge when all checks pass label Aug 23, 2022
@obol-bulldozer obol-bulldozer bot merged commit d9419e5 into main Aug 23, 2022
@obol-bulldozer obol-bulldozer bot deleted the corver/verify branch August 23, 2022 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge when ready Indicates bulldozer bot may merge when all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants