-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use SSM directly instead of storing sensitive info in env vars
- Loading branch information
1 parent
69b6c38
commit c500277
Showing
7 changed files
with
123 additions
and
44 deletions.
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
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
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 |
---|---|---|
@@ -1,13 +1,15 @@ | ||
package gov.nj.innovation.customAwsIdp.keys; | ||
|
||
import gov.nj.innovation.customAwsIdp.util.SsmClientWrapper; | ||
import org.bouncycastle.asn1.x500.X500Name; | ||
import software.amazon.awssdk.services.ssm.SsmClient; | ||
|
||
import java.math.BigInteger; | ||
import java.util.Date; | ||
|
||
/** | ||
* Store the constants needed for generating keys; some which are public, and some which are secrets populated from | ||
* environment variables. | ||
* environment variables and SSM. | ||
* | ||
* @author Case Walker ([email protected]) | ||
*/ | ||
|
@@ -38,27 +40,30 @@ public record KeyConstants( | |
"99768495627357285435626145610679202888676240909221166688413303345247117760811" | ||
); | ||
private static final BigInteger KEY_PUBLIC_EXPONENT = new BigInteger("65537"); | ||
private static final String KEY_PRIVATE_EXPONENT_STR = System.getenv("KEY_PRIVATE_EXPONENT"); | ||
private static final String KEY_PRIME_P_STR = System.getenv("KEY_PRIME_P"); | ||
private static final String KEY_PRIME_Q_STR = System.getenv("KEY_PRIME_Q"); | ||
private static final String KEY_PRIME_EXPONENT_P_STR = System.getenv("KEY_PRIME_EXPONENT_P"); | ||
private static final String KEY_PRIME_EXPONENT_Q_STR = System.getenv("KEY_PRIME_EXPONENT_Q"); | ||
private static final String KEY_CRT_COEFFICIENT_STR = System.getenv("KEY_CRT_COEFFICIENT"); | ||
private static final X500Name CERT_SUBJECT = new X500Name("CN=AwsConnectStandaloneIdP"); | ||
private static final BigInteger CERT_SERIAL = new BigInteger("1696019667843"); | ||
private static final Date CERT_NOT_BEFORE = new Date(1696019567000L); | ||
private static final Date CERT_NOT_AFTER = new Date(2011638867000L); | ||
private static final String JCA_SIGNER_SIGNATURE_ALG = "SHA256WithRSA"; | ||
|
||
public KeyConstants() { | ||
this(KEY_MODULUS, | ||
// Names defined in the environment | ||
private static final String KEY_PRIVATE_EXPONENT_NAME = "KEY_PRIVATE_EXPONENT_NAME"; | ||
private static final String KEY_PRIME_P_NAME = "KEY_PRIME_P_NAME"; | ||
private static final String KEY_PRIME_Q_NAME = "KEY_PRIME_Q_NAME"; | ||
private static final String KEY_PRIME_EXPONENT_P_NAME = "KEY_PRIME_EXPONENT_P_NAME"; | ||
private static final String KEY_PRIME_EXPONENT_Q_NAME = "KEY_PRIME_EXPONENT_Q_NAME"; | ||
private static final String KEY_CRT_COEFFICIENT_NAME = "KEY_CRT_COEFFICIENT_NAME"; | ||
|
||
public KeyConstants(final SsmClient ssmClient) { | ||
this( | ||
KEY_MODULUS, | ||
KEY_PUBLIC_EXPONENT, | ||
new BigInteger(KEY_PRIVATE_EXPONENT_STR), | ||
new BigInteger(KEY_PRIME_P_STR), | ||
new BigInteger(KEY_PRIME_Q_STR), | ||
new BigInteger(KEY_PRIME_EXPONENT_P_STR), | ||
new BigInteger(KEY_PRIME_EXPONENT_Q_STR), | ||
new BigInteger(KEY_CRT_COEFFICIENT_STR), | ||
new BigInteger(SsmClientWrapper.getParameterByName(ssmClient, System.getenv(KEY_PRIVATE_EXPONENT_NAME))), | ||
new BigInteger(SsmClientWrapper.getParameterByName(ssmClient, System.getenv(KEY_PRIME_P_NAME))), | ||
new BigInteger(SsmClientWrapper.getParameterByName(ssmClient, System.getenv(KEY_PRIME_Q_NAME))), | ||
new BigInteger(SsmClientWrapper.getParameterByName(ssmClient, System.getenv(KEY_PRIME_EXPONENT_P_NAME))), | ||
new BigInteger(SsmClientWrapper.getParameterByName(ssmClient, System.getenv(KEY_PRIME_EXPONENT_Q_NAME))), | ||
new BigInteger(SsmClientWrapper.getParameterByName(ssmClient, System.getenv(KEY_CRT_COEFFICIENT_NAME))), | ||
CERT_SUBJECT, | ||
CERT_SERIAL, | ||
CERT_NOT_BEFORE, | ||
|
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
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
29 changes: 29 additions & 0 deletions
29
src/main/java/gov/nj/innovation/customAwsIdp/util/SsmClientWrapper.java
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package gov.nj.innovation.customAwsIdp.util; | ||
|
||
import software.amazon.awssdk.services.ssm.SsmClient; | ||
import software.amazon.awssdk.services.ssm.model.GetParameterRequest; | ||
import software.amazon.awssdk.services.ssm.model.GetParameterResponse; | ||
|
||
/** | ||
* Fetch an SSM parameter by name. | ||
* | ||
* @author Case Walker ([email protected]) | ||
*/ | ||
public class SsmClientWrapper { | ||
|
||
/** | ||
* Encapsulate the Amazon types; consume a String and output its SSM value. | ||
* | ||
* @param parameterName An SSM parameter name | ||
* @return The SSM parameter value. | ||
*/ | ||
public static String getParameterByName(final SsmClient ssmClient, final String parameterName) { | ||
GetParameterRequest request = GetParameterRequest.builder() | ||
.name(parameterName) | ||
.withDecryption(true) | ||
.build(); | ||
GetParameterResponse response = ssmClient.getParameter(request); | ||
|
||
return response.parameter().value(); | ||
} | ||
} |
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