-
-
Notifications
You must be signed in to change notification settings - Fork 110
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
feat: support FIPS endpoints for AWS KMS #245
Open
sbstjn
wants to merge
3
commits into
ebourg:master
Choose a base branch
from
sbstjn:add-support-for-fips-endpoints-kms
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,21 @@ public class AmazonSigningService implements SigningService { | |
algorithmMapping.put("SHA512withRSA/PSS", "RSASSA_PSS_SHA_512"); | ||
} | ||
|
||
/** | ||
* Generates the endpoint URL for the given AWS region. | ||
* | ||
* @param region the AWS region | ||
* @return the endpoint URL | ||
*/ | ||
public static String getEndpointUrl(String region) { | ||
String useFipsEndpoint = getenv("AWS_USE_FIPS_ENDPOINT"); | ||
if (useFipsEndpoint != null && useFipsEndpoint.equalsIgnoreCase("true")) { | ||
return "https://kms-fips." + region + ".amazonaws.com"; | ||
} | ||
|
||
return "https://kms." + region + ".amazonaws.com"; | ||
} | ||
|
||
/** | ||
* Creates a new AWS signing service. | ||
* | ||
|
@@ -90,7 +105,7 @@ public class AmazonSigningService implements SigningService { | |
* @since 6.0 | ||
*/ | ||
public AmazonSigningService(String region, Supplier<AmazonCredentials> credentials, Function<String, Certificate[]> certificateStore) { | ||
this(credentials, certificateStore, "https://kms." + region + ".amazonaws.com"); | ||
this(credentials, certificateStore, getEndpointUrl(region)); | ||
} | ||
|
||
/** | ||
|
@@ -259,7 +274,7 @@ void sign(HttpURLConnection conn, AmazonCredentials credentials, byte[] content, | |
String host = endpoint.getHost(); | ||
Matcher matcher = hostnamePattern.matcher(host); | ||
String regionName = matcher.matches() ? matcher.group(2) : "us-east-1"; | ||
String serviceName = matcher.matches() ? matcher.group(1) : "kms"; | ||
String serviceName = "kms"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather strip the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But that class is only intended to access KMS or are there other services involved that I miss? |
||
|
||
String credentialScope = dateFormat.format(date) + "/" + regionName + "/" + serviceName + "/" + "aws4_request"; | ||
|
||
|
@@ -331,4 +346,8 @@ private String sha256(byte[] data) { | |
digest.update(data); | ||
return Hex.toHexString(digest.digest()).toLowerCase(); | ||
} | ||
|
||
static String getenv(String name) { | ||
return System.getenv(name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to make this method non static and package privarte?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed, if I want to test this individually, it needs to be public. Don't know that much about Java ;) Can give it a try later …
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It remains testable from a test class in the same package if the public keyword is removed, that's the "package private" visibility.