mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix: handle base64-encoded ACM cert imports (#248)
This commit is contained in:
1 parent
81f1a01c39
commit
13916913e8
22 files changed
+2269
-107
No files matched your search
@@ -135,9 +135,12 @@ public class AcmJsonHandler {
|
||||
}
|
||||
|
||||
private Response handleImportCertificate(JsonNode request, String region) {
|
||||
String certificate = request.path("Certificate").asText();
|
||||
String privateKey = request.path("PrivateKey").asText();
|
||||
String certificate = decodeBlob(request.path("Certificate").asText());
|
||||
String privateKey = decodeBlob(request.path("PrivateKey").asText());
|
||||
String chain = request.path("CertificateChain").asText(null);
|
||||
if (chain != null) {
|
||||
chain = decodeBlob(chain);
|
||||
}
|
||||
String existingArn = request.path("CertificateArn").asText(null);
|
||||
Map<String, String> tags = parseTags(request.path("Tags"));
|
||||
|
||||
@@ -432,6 +435,24 @@ public class AcmJsonHandler {
|
||||
return list.isEmpty() ? null : list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a base64-encoded blob field from the AWS JSON 1.1 wire protocol.
|
||||
* AWS SDKs send binary fields (Certificate, PrivateKey, Passphrase, etc.)
|
||||
* as base64-encoded strings. If the value is already in PEM format (e.g. from
|
||||
* direct HTTP calls), it is returned as-is.
|
||||
*/
|
||||
private String decodeBlob(String value) {
|
||||
if (value == null || value.startsWith("-----")) {
|
||||
return value;
|
||||
}
|
||||
try {
|
||||
return new String(Base64.getDecoder().decode(value));
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Not valid base64 — return as-is
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
private List<KeyAlgorithm> parseKeyTypes(JsonNode node) {
|
||||
if (!node.isArray()) return null;
|
||||
List<KeyAlgorithm> list = new ArrayList<>();
|
||||
|
||||
@@ -256,6 +256,7 @@ public class Certificate {
|
||||
|
||||
public boolean canExport() {
|
||||
return type == CertificateType.PRIVATE ||
|
||||
type == CertificateType.IMPORTED ||
|
||||
(certOptions != null && "ENABLED".equals(certOptions.export()));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user