Skip to content

Master Key to Keyring API Evolution #150

Closed
@WesleyRosenblum

Description

@WesleyRosenblum

Introduction

The Java version of the AWS Encryption SDK, having been developed prior to all other language variants of the AWS Encryption SDK, contains configuration and API constructs that do not exist in the more recently developed versions. Namely, the Master Key/Master Key Provider (MKP) construct has been replaced by Keyrings in the C, Javascript, and all future versions of the ESDK. To bring the Java ESDK in line with the other ESDKs, Keyring support is currently being added (see #102 ). However, since Master Key Providers are present in both the input and output of the Java ESDK, the process of introducing Keyrings while minimizing disruption to existing customers is complicated. This issue summarizes the current state of Master Key Providers in the Java ESDK and raises the following questions regarding the evolution of the Java ESDK API:

  • Should we provide a Master Key Provider Keyring to ease transitioning to Keyrings?
  • How should the result object of encryption and decryption operations be updated to support Keyrings?
  • Should a new major version be introduced?

Current State

The AwsCrypto class serves as the primary entry-point to the Java ESDK. This class contains 30 public methods interacting with Master Key Providers, which are overloaded variations of the following 4 methods:

  • estimateCiphertextSize, for estimating the output length of encrypting a plaintext
  • encryptData/decryptData, the primary encryption and decryption methods
  • createEncryptingStream/createDecryptingStream, for encrypting/decrypting input streams
  • encryptString/decryptString, deprecated methods for encrypting/decrypting strings

Each of these methods use either a MasterKeyProvider or a CryptoMaterialsManager to perform its encryption/decryption objective. When a MasterKeyProvider is specified, the given MKP is wrapped in the DefaultCryptoMaterialsManager and handed off to the corresponding CryptoMaterialsManager based method. All of these methods (save for estimateCiphertextSize which returns a long) return a CryptoResult or a CryptoInputStream/CryptoOutputStream that wraps a CryptoResult. CryptoResult is a generic type that is parameterized with the MasterKey type that was specified to the method. CryptoResult contains a getMasterKeys method that in the case of encryption returns all the MasterKeys used to encrypt the ciphertext, and in the case of decryption returns the single MasterKey used to decrypt the ciphertext.

Should we provide a Master Key Provider Keyring?

The Master Key Provider Keyring is a Keyring that wraps a MasterKeyProvider that customers have developed so it can be used with the new methods in AwsCrypto that support Keyrings. Supplying this Keyring to customers has benefits, but also some drawbacks, and in particular has implications regarding the long term support plan for Master Key Providers. These benefits and drawbacks are delineated below:

Benefits:

  • Customers with custom Master Key Providers can onboard to the new Keyring methods with minimal effort by constructing a Master Key Provider Keyring with their existing MKP and calling the new methods.
  • Some internal classes (such as DefaultCryptoMaterialsManager) can be updated to work with Keyrings as the Master Key Provider they currently work with can be wrapped with the Master Key Provider Keyring.

Drawbacks

  • Wrapping a custom Master Key Provider in the Master Key Provider Keyring defers any required investment by our customers towards converting their MKPs into Keyrings. This will prolong the usage of Master Keys. Once Master Keys are fully deprecated, customers will need to make a second, more extensive, code change to perform the conversion of their MKPs to Keyrings.
  • If CryptoResult continues to provide access to Master Keys, Master Keys will need to be added to the EncryptionMaterials and DecryptionMaterials that Keyrings work with in order for the Master Key to be populated in the result. This means that deprecated concepts are being introduced into the new Keyring code.

How should the result object be updated to support Keyrings?

Given that the current CryptoResult provides access to Master Keys, this class will need to be updated or augmented to support Keyrings. Possible solutions involve removing Master Keys from the CryptoResult in favor of the Keyring trace, introducing a new result type used exclusively for when a Keyring is being used, or only populating MasterKeys in CryptoResult when a MKP is in use. These options are discussed below:

Option 1: Remove Master Keys from CryptoResult

The getMasterKeys and getMasterKeyIds methods are removed from CryptoResult and the generic MasterKey parameter is removed. A method for accessing the Keyring trace is added.

Benefits:

  • Single result object, reducing complexity and confusion
  • Public methods in AwsCrypto that accept a CryptoMaterialsManager instead of a MasterKeyProvider can be updated to support Keyrings
  • Makes it easier to fully remove Master Keys later on, since customers will have already removed dependencies on getMasterKeys and getMasterKeyIds

Drawbacks:

  • Non-backward compatible, breaking change for all customers that call getMasterKeys on CryptoResult. Removing the generic parameter for Master Key in CryptoResult will require a code change to compile.
  • Customers that use the Master Key from a decryption CryptoResult will have to parse the Keyring trace to determine which Key was used for decryption.

Option 2: New result type for Keyrings

A new result type (KeyringCryptoResult for example) is created that is returned by all the AwsCrypto methods that work with Keyrings. The new type would include a Keyring Trace instead of MasterKeys. Existing methods in AwsCrypto would continue to return CryptoResult.

Benefits:

  • Backwards compatible. Customers using existing MKP based methods would not need to make any code changes.
  • Keyring and MKP code remains segregated for the most part, making it clear what data is expected in the result and easing the removal of MKPs later on.

Drawbacks:

  • Public methods in AwsCrypto that accept a CryptoMaterialsManager instead of a MasterKeyProvider will need to be duplicated with an additional parameter or alternate name indicating they are for Keyrings, since we cannot have an identical method with different output. Overall, 24 new public methods will be required, versus 12 if a new result type is not introduced.
  • CryptoInputStream and CryptoOutputStream will need to have a getKeyringCryptoResult method added. This would return null when Master Key Providers are used, and similarly getCryptoResult would return null when Keyrings are used, which could be confusing.

Option 3: Only populate Master Keys in CryptoResult when a MKP is used

The Master Key methods in CryptoResult remain the same, but only return a result if a Master Key Provider is being used. A method for accessing the Keyring trace is added to CryptoResult, which would only return a result if a Keyring is used.

Benefits:

  • Single result object, reducing complexity and confusion
  • Backwards compatible. Customers using existing MKP based methods would not need to make any code changes.
  • Public methods in AwsCrypto that accept a CryptoMaterialsManager instead of a MasterKeyProvider can be updated to support Keyrings

Drawbacks:

  • Potentially confusing, since the output would contain null or empty data depending on which methods in AwsCrypto were used
  • Support for handling Master Keys must remain in DefaultCryptoMaterialsManager, EncryptionHandler, and DecryptionHandler while additional code for handling Keyring Traces is added, adding complexity.

Should a new major version be introduced?

Another alternative to both the MasterKeyProviderKeyring and updates to the CryptoResult is introducing a new, non-backward compatible major version of the Java ESDK that removes all references to Master Keys and Master Key Providers in favor of Keyrings while marking the old version of the Java ESDK as deprecated. While the introduction of Keyrings is likely not sufficiently beneficial to customers to warrant such an action, the benefits and drawbacks are nonetheless presented below for completeness:

Benefits:

  • Java ESDK will match the design and functionality of the more recent ESDKs
  • The amount of public methods in AwsCrypto does not increase
  • A simpler and more elegant code base

Drawbacks:

  • Non-backward compatible, breaking change for all customers requiring all customers to update their code, sometimes in significant ways, in order to use the new version.
  • Multiple versions of the ESDK must be maintained until the MKP version reaches end of life.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions