feat: introduce AWS KMS types.MessageTypeRaw for AWS KMS signing operations #573
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi
smallstep/crypto
reviewers! 👋This is my first contributing PR, please feel free to provide any feedback! I'm happy to change things up where required!
Name of feature:
Implement a means for callers to specify
types.MessageTypeRaw
in AWS KMS Sign operations.Pain or issue this feature alleviates:
Currently, the
awskms.Sign
operation exclusively supports the signing of messages, where the message is expected to be atypes.MessageTypeDigest
.This limitation prevents callers from being able to specify that their message is un-hashed, and thus unable to inform the AWS KMS API that the Sign operation should have a
types.MessageType
oftypes.MessageTypeRaw
(RAW
).Limitations
The objective of this package, (and the other Signing packages) is to provide an implementation of the
crypto.Signer
interface that performs the relevant cloud based signing operations.As a part of the
crypto.Signer
interface, thecrypto.SignerOpts
interface is include as the third and final argument to theSign()
method.A perk of the
crypto.SignerOpts
interface is the promise that:However, within the
awskms
implementation of thecrypto.Signer
interface, this promise cannot be fulfilled, as the AWS KMSSign
operation requires atypes.SigningAlgorithmSpec
must be provided when performing an AWS KMS Signing operation.AWS KMS Go SDK v2 Documentation:
The only exclusion to this limitation is when signing with ECDSA keys. As AWS does not enable the user to specify arbirtary signing algorithms, but rather the specified signing algorithm for that ECDSA key type. See The ECDSA AWS Key Spec
As such, when calling the
awskms
Sign()
we must always provide a non-zerocrypto.Hash
as ourcrypto.SignerOpts
argument.Mitigation
To mitigate this limitation, a new
AWSOptions
type is introduced to theawskms
package.This
AWSOptions
type implements thecrypto.SignerOpts
interface, and allows callers to specify whether or not the message isRAW
.Additionally, it posses a
crypto.SignerOpts
fieldOptions
where callers can provide the underlyingcrypto.Hash
that can be matched with the appropriatetypes.SigningAlgorithmSpec
that is expected by the AWS KMS Sign API.Approach
I have opted to use a more generic
AWSOptions
struct with theRaw
field as a boolean to indicate if thetypes.MessageType
istypes.MessageTypeRaw
or not. I did consider using a struct such asAWSRawMessageOptions
and removing the field (since the only logical difference is the truthy value of theRaw
field.) However I decided against it such that we open ourselves up to adding or removing additional options in the future.Why is this important to the project (if not answered above):
Allow callers to have the additional flexibility of using both
types.MessageTypeRaw
andtypes.MessageTypeDigest
when using theawskms
Signer.Is there documentation on how to use this feature? If so, where?
GoDoc comments on the
awskms.AWSOptions
struct has been introduced.In what environments or workflows is this feature supported?
AWS Environments that leverage AWS KMS Sign operations.
In what environments or workflows is this feature explicitly NOT supported (if any)?
Non-AWS Environments.
Supporting links/other PRs/issues:
N/a