mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(acm): reject RequestCertificate key algorithms real ACM does not support (#3044)
* fix(acm): reject RequestCertificate key algorithms real ACM does not support Real ACM only issues certificates for RSA_2048, EC_prime256v1, and EC_secp384r1 on RequestCertificate. RSA_1024, RSA_3072, RSA_4096, and EC_secp521r1 are rejected with a ValidationException, and the RSA_4096 message carries the account id where the region goes (an AWS quirk, replicated verbatim). The wider algorithm list remains valid for ImportCertificate. Closes #3027 * style(acm): drop em-dash from RSA_4096 test comment * test(acm): issue leaf certificates only for requestable key algorithms AcmServiceTest.issuesALeafOfTheRequestedAlgorithmSignedByTheLocalCa drove every KeyAlgorithm through RequestCertificate. RSA_1024, RSA_3072, RSA_4096, and EC_secp521r1 are now rejected there, matching real ACM, and their ValidationException is asserted in AcmEdgeCaseTest.
This commit is contained in:
1 parent
631df1dc01
commit
db6c419459
4 files changed
+47
-4
No files matched your search
@@ -32,7 +32,7 @@
|
||||
- **Real Cryptography:** Certificates are generated with real RSA/EC keys and valid X.509 structure
|
||||
- **One Local CA:** Every issued certificate (`AMAZON_ISSUED` and `PRIVATE`) is signed by Floci's local root CA, and `GetCertificate` returns that CA as `CertificateChain`. Trust it once (`GET /_floci/ca.pem`, see [TLS](../configuration/tls.md)) and both Floci's HTTPS endpoint and every ACM certificate validate. `DescribeCertificate` reports `Issuer` as the CA's name, `CN=Floci Local CA`, where AWS reports `Amazon`. `ImportCertificate` keeps the chain you upload.
|
||||
- **CA on First Use:** The CA is created under `{persistent-path}/tls/` the first time a certificate is issued, also with TLS off and in `memory` storage mode, so that directory must be writable. A certificate keeps the chain it was issued with; after a CA regeneration, delete and re-request it.
|
||||
- **Key Algorithms:** Supports `RSA_2048`, `RSA_3072`, `RSA_4096`, `EC_prime256v1`, `EC_secp384r1`, `EC_secp521r1`
|
||||
- **Key Algorithms:** `RequestCertificate` accepts `RSA_2048`, `EC_prime256v1`, and `EC_secp384r1` and rejects the rest with a `ValidationException`, matching real ACM; the wider list (`RSA_1024`, `RSA_3072`, `RSA_4096`, `EC_secp521r1`) remains valid for `ImportCertificate`
|
||||
- **Certificate Types:** `AMAZON_ISSUED` (default) and `PRIVATE` (when `CertificateAuthorityArn` is provided)
|
||||
- **Export:** Only `PRIVATE` type certificates can be exported with their private key
|
||||
- **In use:** `DescribeCertificate` lists under `InUseBy` the CloudFront distribution of each Cognito custom domain that uses the certificate, and `DeleteCertificate` refuses with `ResourceInUseException` while that list is not empty. Other consumers, such as load balancers and API Gateway domain names, are not tracked yet.
|
||||
|
||||
@@ -46,6 +46,9 @@ public class AcmService implements ResourceProvider {
|
||||
private static final int MAX_TAG_VALUE_LENGTH = 256;
|
||||
private static final int MAX_SANS = 100;
|
||||
private static final int MAX_DOMAIN_LENGTH = 253;
|
||||
/** Key algorithms real ACM accepts for RequestCertificate; the wider enum stays valid for ImportCertificate. */
|
||||
private static final Set<KeyAlgorithm> REQUESTABLE_KEY_ALGORITHMS =
|
||||
EnumSet.of(KeyAlgorithm.RSA_2048, KeyAlgorithm.EC_prime256v1, KeyAlgorithm.EC_secp384r1);
|
||||
private final StorageBackend<String, Certificate> store;
|
||||
private final CertificateGenerator certificateGenerator;
|
||||
private final FlociCertificateAuthority certificateAuthority;
|
||||
@@ -113,6 +116,7 @@ public class AcmService implements ResourceProvider {
|
||||
}
|
||||
|
||||
KeyAlgorithm alg = keyAlgorithm != null ? keyAlgorithm : KeyAlgorithm.RSA_2048;
|
||||
validateRequestableKeyAlgorithm(alg, region);
|
||||
|
||||
// Check idempotency with parameter validation
|
||||
if (idempotencyToken != null && !idempotencyToken.isEmpty()) {
|
||||
@@ -670,6 +674,16 @@ public class AcmService implements ResourceProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private void validateRequestableKeyAlgorithm(KeyAlgorithm alg, String region) {
|
||||
if (REQUESTABLE_KEY_ALGORITHMS.contains(alg)) {
|
||||
return;
|
||||
}
|
||||
// Real ACM quirk: the RSA_4096 message carries the account id where the region goes.
|
||||
String location = alg == KeyAlgorithm.RSA_4096 ? regionResolver.getAccountId() : region;
|
||||
throw new AwsException("ValidationException",
|
||||
"Encryption Algorithm " + alg.name() + " is not supported in " + location + " region", 400);
|
||||
}
|
||||
|
||||
private void validateSans(List<String> sans) {
|
||||
if (sans != null && sans.size() > MAX_SANS) {
|
||||
throw new AwsException("ValidationException",
|
||||
|
||||
@@ -398,8 +398,8 @@ class AcmEdgeCaseTest {
|
||||
// ==================== Key Algorithm Tests ====================
|
||||
|
||||
@Test
|
||||
void allKeyAlgorithmsSupported() {
|
||||
String[] algorithms = {"RSA_2048", "RSA_3072", "RSA_4096", "EC_prime256v1", "EC_secp384r1", "EC_secp521r1"};
|
||||
void requestableKeyAlgorithmsAccepted() {
|
||||
String[] algorithms = {"RSA_2048", "EC_prime256v1", "EC_secp384r1"};
|
||||
|
||||
for (String algo : algorithms) {
|
||||
given()
|
||||
@@ -418,4 +418,33 @@ class AcmEdgeCaseTest {
|
||||
.body("CertificateArn", startsWith("arn:aws:acm:"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void unsupportedKeyAlgorithmsRejected() {
|
||||
// Real ACM rejects these on RequestCertificate. The RSA_4096 message carries the
|
||||
// account id where the region goes, an AWS quirk replicated verbatim.
|
||||
Map<String, String> expected = Map.of(
|
||||
"RSA_1024", "Encryption Algorithm RSA_1024 is not supported in us-east-1 region",
|
||||
"RSA_3072", "Encryption Algorithm RSA_3072 is not supported in us-east-1 region",
|
||||
"RSA_4096", "Encryption Algorithm RSA_4096 is not supported in 000000000000 region",
|
||||
"EC_secp521r1", "Encryption Algorithm EC_secp521r1 is not supported in us-east-1 region");
|
||||
|
||||
for (Map.Entry<String, String> entry : expected.entrySet()) {
|
||||
given()
|
||||
.header("X-Amz-Target", "CertificateManager.RequestCertificate")
|
||||
.contentType(ACM_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"DomainName": "%s.example.com",
|
||||
"KeyAlgorithm": "%s"
|
||||
}
|
||||
""".formatted(entry.getKey().toLowerCase().replace("_", "-"), entry.getKey()))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"))
|
||||
.body("message", equalTo(entry.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ class AcmServiceTest {
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(KeyAlgorithm.class)
|
||||
@EnumSource(value = KeyAlgorithm.class, names = {"RSA_2048", "EC_prime256v1", "EC_secp384r1"})
|
||||
void issuesALeafOfTheRequestedAlgorithmSignedByTheLocalCa(KeyAlgorithm algorithm) throws Exception {
|
||||
Certificate cert = service.requestCertificate("api.example.test", List.of("*.example.test"),
|
||||
ValidationMethod.DNS, null, algorithm, null, null, Map.of(), REGION);
|
||||
|
||||
Reference in new issue
Block a user