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

Decouple crypto engine from encryption algorithm #3293

Merged
merged 2 commits into from
May 10, 2024
Merged

Conversation

dmjb
Copy link
Contributor

@dmjb dmjb commented May 9, 2024

Relates to #3292

Previously the crypto engine was coupled to the AES-CFB algorithm. This PR introduces a new EncryptionAlgorithm interface which represents different cryptographic algorithms. The Engine is now instantiated with an instance of this algorithm.

Future PRs will make it possible to support more than one algorithm, and allow the selection of available algorithms to be driven through configuration.

Summary

Provide a brief overview of the changes and the issue being addressed.
Explain the rationale and any background necessary for understanding the changes.
List dependencies required by this change, if any.

Fixes #(related issue)

Change Type

Mark the type of change your PR introduces:

  • Bug fix (resolves an issue without affecting existing features)
  • Feature (adds new functionality without breaking changes)
  • Breaking change (may impact existing functionalities or require documentation updates)
  • Documentation (updates or additions to documentation)
  • Refactoring or test improvements (no bug fixes or new functionality)

Testing

Outline how the changes were tested, including steps to reproduce and any relevant configurations.
Attach screenshots if helpful.

Review Checklist:

  • Reviewed my own code for quality and clarity.
  • Added comments to complex or tricky code sections.
  • Updated any affected documentation.
  • Included tests that validate the fix or feature.
  • Checked that related changes are merged.

@dmjb dmjb requested a review from a team as a code owner May 9, 2024 14:11
Copy link
Contributor

@stacklokbot stacklokbot left a comment

Choose a reason for hiding this comment

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

✅ No Invisible Unicode Characters Detected.

Fixes #3292

Previously the crypto engine was coupled to the AES-CFB algorithm. This
PR introduces a new EncryptionAlgorithm interface which represents
different cryptographic algorithms. The Engine is now instantiated with
an instance of this algorithm.

Future PRs will make it possible to support more than one algorithm, and
allow the selection of available algorithms to be driven through
configuration.
Copy link
Contributor

@stacklokbot stacklokbot left a comment

Choose a reason for hiding this comment

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

✅ No Invisible Unicode Characters Detected.

Copy link
Contributor

@stacklokbot stacklokbot left a comment

Choose a reason for hiding this comment

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

✅ No Mixed Scripts Detected.

@@ -0,0 +1,61 @@
// Copyright 2024 Stacklok, Inc.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code was previously in the same file as the crypto engine. Since it is unrelated, move to its own file.


// Engine provides all functions to encrypt and decrypt data
type Engine interface {
EncryptOAuthToken(token *oauth2.Token) (string, error)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously this method required callers to marshal the token to JSON, and then base64 the result of the encryption method. This logic has been moved inside this method which simplifies its use.


// AlgorithmTypeFromString converts a string to an EncryptionAlgorithmType
// or returns errUnknownAlgorithm.
func AlgorithmTypeFromString(input string) (EncryptionAlgorithmType, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some of this code is not used yet, but will be used in the next PR.

Copy link
Contributor

@stacklokbot stacklokbot left a comment

Choose a reason for hiding this comment

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

✅ No Invisible Unicode Characters Detected.

Copy link
Contributor

@stacklokbot stacklokbot left a comment

Choose a reason for hiding this comment

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

✅ No Mixed Scripts Detected.

@coveralls
Copy link

Coverage Status

coverage: 50.101% (+0.006%) from 50.095%
when pulling f39314d on crypto-api-change
into f6b5176 on main.

@dmjb dmjb merged commit fddc50a into main May 10, 2024
20 checks passed
@dmjb dmjb deleted the crypto-api-change branch May 10, 2024 09:12
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.

5 participants