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

exp/services/recoverysigner: add encrypt and decrypt commands #2746

Merged

Conversation

howardtw
Copy link
Contributor

@howardtw howardtw commented Jun 25, 2020

PR Checklist

PR Structure

  • This PR has reasonably narrow scope (if not, break it down into smaller PRs).
  • This PR avoids mixing refactoring changes with feature changes (split into two PRs
    otherwise).
  • This PR's title starts with name of package that is most changed in the PR, ex.
    services/friendbot, or all or doc if the changes are broad or impact many
    packages.

Thoroughness

  • This PR adds tests for the most critical parts of the new functionality or fixes.
  • I've updated any docs (developer docs, .md
    files, etc... affected by this change). Take a look in the docs folder for a given service,
    like this one.

Release planning

  • I've updated the relevant CHANGELOG (here for Horizon) if
    needed with deprecations, added features, breaking changes, and DB schema changes.
  • I've decided if this PR requires a new major/minor version according to
    semver, or if it's mainly a patch change. The PR is targeted at the next
    release branch if it's not a patch change.

What

This PR adds two sub-commands encrypt and decrypt to encryption-tink-keyset to encrypt a cleartext keyset private or to decrypt an encrypted keyset private.

Why

I was planning on adding a sub-command reencrypt. However, I realized there's no way for someone who started the recovery signer with a cleartext keyset private without configuring encryption-kms-key-uri to encrypt the keyset later on, so I decided to add two sub-commands: encrypt and decrypt.

For someone who wants to make the system more secure by configuring the encryption-kms-key-uri at a later point in time, she can use the encrypt command to do so; for someone who wants to re-encrypt the keyset after rotating the KMS key, she can first use decrypt to get the cleartext keyset if no backup is available, then use encrypt to get a new encrypted keyset.

Known limitations

I could theoretically break this PR into two, one for the encrypt cmd and one for the decrypt cmd. But since they are closely related and are not too big in their own, I decided to put them together and tidy up the messages throughout the file.

@cla-bot cla-bot bot added the cla: yes label Jun 25, 2020
@howardtw howardtw requested a review from leighmcculloch June 25, 2020 09:43
exp/services/recoverysigner/README.md Outdated Show resolved Hide resolved
exp/services/recoverysigner/cmd/keyset.go Outdated Show resolved Hide resolved
exp/services/recoverysigner/cmd/keyset.go Show resolved Hide resolved
exp/services/recoverysigner/cmd/keyset.go Outdated Show resolved Hide resolved
return "", "", errors.Wrap(err, "writing cleartext keyset public")
}

return keysetPublic.String(), keysetPrivateEncrypted.String(), nil
Copy link
Member

Choose a reason for hiding this comment

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

I don't see any tests for this, is that because of the use of the aws integration here? I think we need to figure out tests for these commands, this code is pretty important. Let's think about this separate to this PR though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly. We will have to think about the best way to mock this out. I will create an issue for this.

Speaking of this, I'm curious what you think about having a mock struct in non-test files. i.e. when it is ok to have one and when is not. I remember you mentioned you don't want to have a mock being part of the binary of production code, but we are doing that in the vibrant backend.

Copy link
Member

Choose a reason for hiding this comment

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

I only had an issue with the type being callable via the CLI, i.e. being able to use the mock in real production code, not having the type live there. If we do have types or functions intended only for testing but that need to be importable, let's keep them in their own package. If it's for the crypto package, put them in cryptotest. This pattern is pretty common I think.

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 only had an issue with the type being callable via the CLI, i.e. being able to use the mock in real production code, not having the type live there.

I see. It does look like it is possible to the use the mock in real production with KMS_PROVIDER being set to mock in the vibrant backend. Maybe we need to address that.

If we do have types or functions intended only for testing but that need to be importable, let's keep them in their own package. If it's for the crypto package, put them in cryptotest. This pattern is pretty common I think.

Yeah I usually realize that I have to do this if I have the import cycle issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we need to address that.

Maybe we don't. I think there might be some values to start the service with a KMS mock client in vibrant backend. Looks like this is done on purpose so that people can start the service locally and test the endpoints that use it.

I think the difference lies in the fact that the recovery signer can operate without configuring a KMS client because it is only used to encrypt the tink keyset whereas the vibrant backend cannot operate without configuring a KMS client because it is used to encrypt the data directly.

What do you think? Do you agree?

@howardtw howardtw merged commit d0a3c2c into stellar:recoverysigner-unique-signing-keys Jun 26, 2020
@howardtw howardtw deleted the reencrypt branch June 30, 2020 00:27
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.

2 participants