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

[network, crypto] Compressed serialization, key conversions and message signing #1129

Merged
merged 10 commits into from Aug 17, 2021

Conversation

huitseeker
Copy link
Contributor

@huitseeker huitseeker commented Aug 12, 2021

This:

  • implements compressed (32/33 bytes instead of 64) (de)serialization for crypto.PublicKey.
    • This is something we want to work on transitioning to more widely next cycle,
    • it's a milestone towards #5739
  • re-activates message signing and verification, closes #5634
  • checks the OriginID contained in a message with respect to the (now cryptographically-verified) libp2p source, closes [Network] Verify originID against libp2p ID #1115

Edit: Splitting this in 2 PRs, to work on the concurrency issues w/ @vishalchangrani : this is the straightwforward crypto PR that will go easier

network/p2p/keyTranslator.go Outdated Show resolved Hide resolved
network/p2p/readSubscription.go Outdated Show resolved Hide resolved
network/test/testUtil.go Outdated Show resolved Hide resolved
network/p2p/readSubscription.go Outdated Show resolved Hide resolved
network/p2p/middleware.go Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Aug 12, 2021

Codecov Report

Merging #1129 (a08b3c7) into master (2d5faf1) will increase coverage by 0.18%.
The diff coverage is 47.05%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1129      +/-   ##
==========================================
+ Coverage   53.11%   53.30%   +0.18%     
==========================================
  Files         323      323              
  Lines       21857    21928      +71     
==========================================
+ Hits        11610    11688      +78     
+ Misses       8667     8648      -19     
- Partials     1580     1592      +12     
Flag Coverage Δ
unittests 53.30% <47.05%> (+0.18%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
network/p2p/libp2pNode.go 62.91% <33.33%> (ø)
network/p2p/keyTranslator.go 63.41% <46.66%> (-10.18%) ⬇️
network/p2p/libp2pUtils.go 53.24% <100.00%> (ø)
fvm/transactionEnv.go 44.94% <0.00%> (-0.38%) ⬇️
engine/consensus/dkg/reactor_engine.go 75.96% <0.00%> (-0.19%) ⬇️
fvm/scriptEnv.go 35.87% <0.00%> (-0.11%) ⬇️
module/signature/signer_store.go 0.00% <0.00%> (ø)
fvm/state/accounts.go 45.27% <0.00%> (+0.60%) ⬆️
...sus/approvals/assignment_collector_statemachine.go 51.92% <0.00%> (+1.92%) ⬆️
module/chunks/chunkVerifier.go 68.90% <0.00%> (+4.14%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2d5faf1...a08b3c7. Read the comment docs.

@huitseeker huitseeker force-pushed the keyTranslator_inverse_ branch 5 times, most recently from abb4a80 to 7fd970e Compare August 13, 2021 16:55
@huitseeker huitseeker changed the title [network, crypto] Various crypto & network synergies [network, crypto] Compressed serialization, key conversions and message signing Aug 16, 2021
@huitseeker huitseeker marked this pull request as ready for review August 16, 2021 19:44
@tarakby tarakby self-assigned this Aug 16, 2021
@huitseeker huitseeker force-pushed the keyTranslator_inverse_ branch 2 times, most recently from fadabd0 to 4907ea0 Compare August 16, 2021 21:21
crypto/bls.go Outdated

// decodePublicKeyCompressed decodes a slice of bytes into a public key.
// This function includes a membership check in G2 and rejects the infinity point.
func (a *blsBLS12381Algo) decodePublicKeyCompressed(publicKeyBytes []byte) (PublicKey, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be a bit misleading because the default choice is made here. This means we can enable an uncompressed setting while function's name is still ..Compressed.
I suggest we just keep decodePublicKey.

We could decide in the future to either:

  • remove the possibility to have uncompressed settings entirely.
  • support both compression formats dynamically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. I inverted the delegation made by the compressed functions in 1dd2bf7 Note that the coherence check on Encode is a bit fugly.

crypto/bls.go Show resolved Hide resolved
crypto/ecdsa.go Outdated Show resolved Hide resolved
crypto/ecdsa.go Outdated Show resolved Hide resolved
crypto/ecdsa.go Outdated Show resolved Hide resolved
crypto/sign.go Show resolved Hide resolved
crypto/ecdsa_test.go Outdated Show resolved Hide resolved
crypto/sign_test_utils.go Show resolved Hide resolved
network/p2p/keyTranslator.go Outdated Show resolved Hide resolved
network/p2p/keyTranslator.go Show resolved Hide resolved
@tarakby
Copy link
Contributor

tarakby commented Aug 17, 2021

In the PR summary, I think we can also remove the line below since it hasn't been addressed yet.

re-activates message signing and verification, closes #5634

crypto/ecdsa.go Outdated Show resolved Hide resolved
crypto/ecdsa.go Outdated Show resolved Hide resolved
crypto/ecdsa.go Outdated Show resolved Hide resolved
crypto/ecdsa.go Outdated Show resolved Hide resolved
crypto/ecdsa.go Outdated Show resolved Hide resolved
crypto/ecdsa.go Outdated Show resolved Hide resolved
crypto/ecdsa_test.go Outdated Show resolved Hide resolved
crypto/ecdsa_test.go Show resolved Hide resolved
case lcrypto_pb.KeyType_ECDSA:
pubB, err := lpk.Raw()
if err != nil {
return nil, lcrypto.ErrBadKeyType
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe making more distinct error types helps to spot the issue upon happening, i.e., this error type is the same as the next 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.

This error and the next will not actually happen: I'm marshalling the key material and then reinterpreting it as bytes using the underlying x509 library manually, because libp2p deprecated its Bytes function. This is just bypassing lack of access to private members.

@huitseeker
Copy link
Contributor Author

huitseeker commented Aug 17, 2021

@tarakby

In the PR summary, I think we can also remove the line below since it hasn't been addressed yet.

Message signing and verification is re-activated in the commit titled "[network] re-activate message signing & verification", included in this PR.

@huitseeker huitseeker force-pushed the keyTranslator_inverse_ branch 4 times, most recently from cc18b84 to cb9aef6 Compare August 17, 2021 17:03
@tarakby
Copy link
Contributor

tarakby commented Aug 17, 2021

Message signing and verification is re-activated in the commit titled "[network] re-activate message signing & verification", included in this PR.

My bad, I missed the change! Thanks

@synzhu
Copy link
Contributor

synzhu commented Aug 17, 2021

Looks good to me, but will leave to @tarakby to more closely review the crypto changes

Copy link
Contributor

@tarakby tarakby left a comment

Choose a reason for hiding this comment

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

Thanks for adding the compressed form to the interface 🏄

crypto/ecdsa.go Show resolved Hide resolved
crypto/ecdsa_test.go Outdated Show resolved Hide resolved
crypto/ecdsa.go Show resolved Hide resolved
crypto/bls.go Outdated Show resolved Hide resolved
crypto/bls.go Outdated Show resolved Hide resolved
@huitseeker huitseeker merged commit 1b33269 into onflow:master Aug 17, 2021
bors bot added a commit that referenced this pull request Aug 19, 2021
1138: skip connecting to invalid identities in the identity table and log error instead of fatal r=vishalchangrani a=vishalchangrani

Found one more place where it was `log.fatal` on a bad identity.


1163: [network] Check the OriginID of a libp2p message corresponds to its authenticated source r=huitseeker a=huitseeker

Contributes to #1115.
Follow-up of #1129.

Edit: there was no problem with the integration tests, 🤦 

However, TestMiddlewareTestSuit/TestUnsubscribe is still flaky based on the delay in the last step (sending the message once a mesh has formed). But it is problematic on master, see [[1]](https://github.com/onflow/flow-go/runs/3357056741) [[2]](https://github.com/onflow/flow-go/runs/3356508175), so this is not relevant to this PR per se.

Co-authored-by: Vishal <1117327+vishalchangrani@users.noreply.github.com>
Co-authored-by: François Garillot <francois.garillot@dapperlabs.com>
bors bot added a commit that referenced this pull request Aug 19, 2021
1028: adding secure-rpc-addr to access node systemd file r=vishalchangrani a=vishalchangrani



1163: [network] Check the OriginID of a libp2p message corresponds to its authenticated source r=huitseeker a=huitseeker

Contributes to #1115.
Follow-up of #1129.

Edit: there was no problem with the integration tests, 🤦 

However, TestMiddlewareTestSuit/TestUnsubscribe is still flaky based on the delay in the last step (sending the message once a mesh has formed). But it is problematic on master, see [[1]](https://github.com/onflow/flow-go/runs/3357056741) [[2]](https://github.com/onflow/flow-go/runs/3356508175), so this is not relevant to this PR per se.

Co-authored-by: vishal <1117327+vishalchangrani@users.noreply.github.com>
Co-authored-by: Simon Zhu <simon.zsiyan@gmail.com>
Co-authored-by: Vishal <1117327+vishalchangrani@users.noreply.github.com>
Co-authored-by: François Garillot <francois.garillot@dapperlabs.com>
bors bot added a commit that referenced this pull request Aug 19, 2021
1028: adding secure-rpc-addr to access node systemd file r=vishalchangrani a=vishalchangrani



1163: [network] Check the OriginID of a libp2p message corresponds to its authenticated source r=huitseeker a=huitseeker

Contributes to #1115.
Follow-up of #1129.

Edit: there was no problem with the integration tests, 🤦 

However, TestMiddlewareTestSuit/TestUnsubscribe is still flaky based on the delay in the last step (sending the message once a mesh has formed). But it is problematic on master, see [[1]](https://github.com/onflow/flow-go/runs/3357056741) [[2]](https://github.com/onflow/flow-go/runs/3356508175), so this is not relevant to this PR per se.

Co-authored-by: vishal <1117327+vishalchangrani@users.noreply.github.com>
Co-authored-by: Simon Zhu <simon.zsiyan@gmail.com>
Co-authored-by: Vishal <1117327+vishalchangrani@users.noreply.github.com>
Co-authored-by: François Garillot <francois.garillot@dapperlabs.com>
bors bot added a commit that referenced this pull request Aug 19, 2021
1163: [network] Check the OriginID of a libp2p message corresponds to its authenticated source r=huitseeker a=huitseeker

Contributes to #1115.
Follow-up of #1129.

Edit: there was no problem with the integration tests, 🤦 

However, TestMiddlewareTestSuit/TestUnsubscribe is still flaky based on the delay in the last step (sending the message once a mesh has formed). But it is problematic on master, see [[1]](https://github.com/onflow/flow-go/runs/3357056741) [[2]](https://github.com/onflow/flow-go/runs/3356508175), so this is not relevant to this PR per se.

Co-authored-by: François Garillot <francois.garillot@dapperlabs.com>
bors bot added a commit that referenced this pull request Aug 19, 2021
1163: [network] Check the OriginID of a libp2p message corresponds to its authenticated source r=huitseeker a=huitseeker

Contributes to #1115.
Follow-up of #1129.

Edit: there was no problem with the integration tests, 🤦 

However, TestMiddlewareTestSuit/TestUnsubscribe is still flaky based on the delay in the last step (sending the message once a mesh has formed). But it is problematic on master, see [[1]](https://github.com/onflow/flow-go/runs/3357056741) [[2]](https://github.com/onflow/flow-go/runs/3356508175), so this is not relevant to this PR per se.

Co-authored-by: François Garillot <francois.garillot@dapperlabs.com>
bors bot added a commit that referenced this pull request Aug 24, 2021
1180: [bootstrap] Key Generation for Unstaked Access Nodes r=huitseeker a=huitseeker

This introduces a generator for the unstaked Access Nodes, which by convention only have positive secp256k1 keys.

The keys in question have a specific format (positive ECDSA Secp256k1 keys) because:
- they are meant to serve ephemeral nodes,
- allow a bijection between flow.NodeID, flow.NetworkPublicKey, libp2p.PeerID, libp2p.PublicKey
- hence allowing us to only retain the minimum amount of information for these nodes.
For this bijection, see #1165 and #1129.

This is to be used in a bootstrap of the unstaked Access Node post #1133. 

For now, having this in master allows the direct bootstrapping of network in tests by creating suitable libp2p peers.

Co-authored-by: François Garillot <francois.garillot@dapperlabs.com>
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.

[Network] Verify originID against libp2p ID
6 participants