-
Notifications
You must be signed in to change notification settings - Fork 48
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
Change the app link signature encoding to hex #636
Comments
@RiccardoM However, I think it is better to remain UTF-8 encoded. Is it able to force to convert the plain text to UTF-8 string before signing? |
You're right, I just checked here and it assumes the plain text is UTF-8 encoded
Unfortunately this issue is not about encoding only, but also about the signature verification process. To better understand this, let's assume we keep the UTF-8 encoding as it is right now, and that we want to create an app/chain link using the Ledger as a signer. As per design, the Ledger can sign only Cosmos transactions. You give to it a transaction as a byte array and it signs it. It doesn't allow the signature of arbitrary data. So to build an app/chain link we need to provide it with a Cosmos transaction as a byte array. What would happen is:
To be honest, I don't think that encoding the transaction to a UTF-8 string would always work. We might have some problems here due to the fact that UTF-8 does not support all characters. Reading here we get that:
Which means that if the transaction contains a particular memo field with ISO Latin-1 characters, it will not get converted to a UTF-8 byte array properly. For this reason, I think we should convert both app and chain links to require HEX-encoded plain texts instead in order to support even Ledger signers |
@RiccardoM |
@RiccardoM @dadamu From what I've read, this problem extend also to chain-link plain-text right? |
@bragaz I think a single ADR for both of them is great instead of having two different ADRs. Whoever wishes can go on |
@RiccardoM I can draft it later. |
@RiccardoM Yes I meant one 👍 |
@RiccardoM @bragaz Deeply re-thinking about it when writing the ADR. If we change the plain text of the old links which is UTF-8 encoded to hex before verifying the signature, the old links are all invalid since their signatures are simply signed with UTF-8 string bytes. So, all of old links must be re-created to sign the signature in hex bytes. How about we force the plain text to be hex-encoded string to the new link, then remain the old links used the old proof since they have already passed the verification. // generateChainLinkJSON returns build a new ChainLinkJSON intance using the provided mnemonic and chain configuration
func generateChainLinkJSON(mnemonic string, chain chainlinktypes.Chain) (profilescliutils.ChainLinkJSON, error) {
...
// force to change the value to hex-encoded string as plain text automatically
plainText := hex.EncodeToString([]byte(value))
sig, pubkey, err := keyBase.Sign(keyName, []byte(plainText))
if err != nil {
return profilescliutils.ChainLinkJSON{}, err
}
return profilescliutils.NewChainLinkJSON(
profilestypes.NewBech32Address(addr, chain.Prefix),
profilestypes.NewProof(pubkey, hex.EncodeToString(sig), plainText),
profilestypes.NewChainConfig(chain.Name),
), nil
} What do you think @RiccardoM, @bragaz |
@dadamu Changing from UTF-8 to HEX for new links shouldn't be a problem to old links. Once a link is created, the signature is checked only during the creation process and never after that. If we want to keep things consistent on-chain, then we can write a migration script that takes all the currently stored links and transforms them into HEX-encoded values. This can be done as follow:
This will make all the links backward compatible as well. |
) ## Description <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> This PR introduces the draft of the 8th ADR related to Change the plain text encoding of links to hex in #636. --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://docs.cosmos.network/v0.44/building-modules/intro.html) - [ ] included the necessary unit and integration [tests](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
## Description This PR implements what's described inside [ADR-008](#642). Closes: #636 <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://docs.cosmos.network/v0.44/building-modules/intro.html) - [ ] included the necessary unit and integration [tests](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
Feature description
Currently when we verify an application link result, we assume that the plain text value has been encoded using UTF-8 (see here). Unfortunately, this currently makes it impossible to sign something using the Ledger or any common wallet due to the fact that they do not allow to sign arbitrary strings.
Implementation proposal
In order to fix this issue, I think we should adopt the same strategy that we currently use for the chain links: require that the plain text is encoded using the hex format (see here). This would make it easier for developers to use any arbitrary value as the plain text, even a full transaction that is then signed using the Ledger.
Note that this change requires a change to all data sources as well to make sure they decode the plain text as a HEX instead of UTF-8 before verifying the signature.
Please @bragaz @dadamu let me know what you think about this before we can make an ADR.
The text was updated successfully, but these errors were encountered: