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

Problem: no validate for malformed e2ee key in register #1421

Merged
merged 4 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* (versiondb) [#1387](https://github.com/crypto-org-chain/cronos/pull/1387) Add dedicated config section for versiondb, prepare for sdk 0.50 integration.
* (e2ee)[#1413](https://github.com/crypto-org-chain/cronos/pull/1413) Add custom keyring implementation for e2ee module.
* (e2ee)[#1415](https://github.com/crypto-org-chain/cronos/pull/1415) Add batch keys query for e2ee module.
* (e2ee)[#1421](https://github.com/crypto-org-chain/cronos/pull/1421) Validate e2ee key when register.
mmsqe marked this conversation as resolved.
Show resolved Hide resolved

### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/configs/default.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
e2ee: {
keys: [{
address: 'crc16z0herz998946wr659lr84c8c556da55dc34hh',
key: std.base64('key'),
key: 'age1k3mpspxytgvx6e0jja0xgrtzz7vw2p00c2a3xmq5ygfzhwh4wg0s35z4c8',
}],
},
gov: {
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/cosmoscli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,7 @@ def query_e2ee_key(self, address):
home=self.data_dir,
output="json",
)
)["key"]
).get("key")

def query_e2ee_keys(self, *addresses):
return json.loads(
Expand All @@ -1864,7 +1864,7 @@ def query_e2ee_keys(self, *addresses):
home=self.data_dir,
output="json",
)
)["keys"]
).get("keys")

def register_e2ee_key(self, key, **kwargs):
kwargs.setdefault("gas_prices", DEFAULT_GAS_PRICE)
Expand Down
7 changes: 7 additions & 0 deletions integration_tests/test_e2ee.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
def test_register(cronos):
cli = cronos.cosmos_cli()
pubkey0 = cli.keygen(keyring_name="key0")
cli.register_e2ee_key(pubkey0 + "malformed", _from="validator")
assert not cli.query_e2ee_key(cli.address("validator"))


def test_encrypt_decrypt(cronos):
cli = cronos.cosmos_cli()

Expand Down
3 changes: 3 additions & 0 deletions x/e2ee/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
ctx context.Context,
req *types.MsgRegisterEncryptionKey,
) (*types.MsgRegisterEncryptionKeyResponse, error) {
if err := req.ValidateBasic(); err != nil {
yihuang marked this conversation as resolved.
Show resolved Hide resolved
return nil, err

Check warning on line 36 in x/e2ee/keeper/keeper.go

View check run for this annotation

Codecov / codecov/patch

x/e2ee/keeper/keeper.go#L35-L36

Added lines #L35 - L36 were not covered by tests
}
bz, err := k.addressCodec.StringToBytes(req.Address)
if err != nil {
return nil, err
Expand Down
7 changes: 6 additions & 1 deletion x/e2ee/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import (
fmt "fmt"

"filippo.io/age"
sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand All @@ -11,7 +12,11 @@
return fmt.Errorf("address cannot be empty")
}
if len(m.Key) == 0 {
return fmt.Errorf("key cannot be nil")
return fmt.Errorf("key cannot be empty")

Check warning on line 15 in x/e2ee/types/msg.go

View check run for this annotation

Codecov / codecov/patch

x/e2ee/types/msg.go#L15

Added line #L15 was not covered by tests
}

if _, err := age.ParseX25519Recipient(m.Key); err != nil {
return err

Check warning on line 19 in x/e2ee/types/msg.go

View check run for this annotation

Codecov / codecov/patch

x/e2ee/types/msg.go#L18-L19

Added lines #L18 - L19 were not covered by tests
}
// validate bech32 format of Address
if _, err := sdk.AccAddressFromBech32(m.Address); err != nil {
Expand Down
Loading