mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
refactor(core): move PEM reading out of ACM's certificate generator (#4878)
* refactor(core): move PEM reading out of ACM's certificate generator parseCertificate, parsePrivateKey and isPair lived on services.acm.CertificateGenerator, so anything needing to read a certificate or key had to depend on ACM to do it. Six files across four packages already did: config's TlsConfigSource, TlsCertificateManager and FlociCertificateAuthority, plus IoT, the RDS proxy and ACM itself. None of them has anything to do with ACM; they just wanted to parse a file. Move the three to core.common.Pem as static methods and migrate every caller. Generation stays on CertificateGenerator, which is genuinely ACM's; only the reading side is shared. Being static also removes the need to instantiate a generator purely to parse, which TlsConfigSource was doing. CertificateGenerationException moves to core.common as CertificateMaterialException, because core cannot throw a type that lives under services.acm without recreating the inversion this removes. Nothing outside ACM caught it, and it stays an unchecked RuntimeException, so the rename is confined to ACM and its tests. Behaviour is unchanged: the method bodies are the same, including the sign-a-probe pair check that works for RSA and EC alike. The reading side had no test of its own, having only ever been exercised through ACM's generator, so PemTest now covers it directly: round trips, a matching and a mismatched pair, EC as well as RSA, and the failure cases. Prompted by IAM server-certificate support, which needs the same parsing for UploadServerCertificate's MalformedCertificate and KeyPairMismatch. It would have been the seventh caller reaching into ACM. * test: drop generators the Pem migration left unused Four test call sites still built a CertificateGenerator after their parse calls moved to Pem: TlsCertificateHostnameTest's parseCertificate helper, the learned-hostnames reissue test, and both RDS proxy trust-anchor tests. None of them generates anything, so the instance goes. Also drops the extra blank line left where IotMqttBrokerDeviceVerificationTest lost its GENERATOR field, and updates the ApiGateway test comment that still pointed at the generator's own parser.
This commit is contained in:
1 parent
a5379cd5d8
commit
0460e51a6e
33 files changed
+314
-169
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package io.github.hectorvent.floci.config;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.Pem;
|
||||
import io.github.hectorvent.floci.services.acm.CertificateGenerator;
|
||||
import io.github.hectorvent.floci.services.acm.model.KeyAlgorithm;
|
||||
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
|
||||
@@ -86,14 +87,14 @@ public final class FlociCertificateAuthority {
|
||||
FlociCertificateAuthority existing = null;
|
||||
try {
|
||||
String pem = Files.readString(certFile);
|
||||
X509Certificate cert = generator.parseCertificate(pem);
|
||||
PrivateKey key = generator.parsePrivateKey(Files.readString(keyFile));
|
||||
X509Certificate cert = Pem.parseCertificate(pem);
|
||||
PrivateKey key = Pem.parsePrivateKey(Files.readString(keyFile));
|
||||
if (cert.getBasicConstraints() < 0) {
|
||||
throw new IllegalStateException("not a CA certificate (BasicConstraints cA=false)");
|
||||
}
|
||||
cert.verify(cert.getPublicKey());
|
||||
cert.checkValidity();
|
||||
if (!CertificateGenerator.isPair(key, cert.getPublicKey())) {
|
||||
if (!Pem.isPair(key, cert.getPublicKey())) {
|
||||
throw new IllegalStateException("private key does not match the certificate");
|
||||
}
|
||||
restrictToOwnerOnly(tlsDir, "rwx------");
|
||||
@@ -116,8 +117,8 @@ public final class FlociCertificateAuthority {
|
||||
Files.writeString(certFile, generated.certificatePem());
|
||||
writePrivateKey(keyFile, generated.privateKeyPem());
|
||||
FlociCertificateAuthority ca = new FlociCertificateAuthority(certFile,
|
||||
generator.parseCertificate(generated.certificatePem()),
|
||||
generator.parsePrivateKey(generated.privateKeyPem()),
|
||||
Pem.parseCertificate(generated.certificatePem()),
|
||||
Pem.parsePrivateKey(generated.privateKeyPem()),
|
||||
generated.certificatePem(), generator);
|
||||
LOG.infov("TLS: generated local CA {0}, SHA256 fingerprint {1}. Trust it once: GET /_floci/ca.pem",
|
||||
certFile, ca.fingerprint());
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.core.common.Pem;
|
||||
import io.github.hectorvent.floci.core.common.Resettable;
|
||||
import io.github.hectorvent.floci.services.acm.CertificateGenerator;
|
||||
import io.github.hectorvent.floci.services.acm.model.KeyAlgorithm;
|
||||
@@ -163,8 +164,8 @@ public class TlsCertificateManager implements Resettable {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
X509Certificate cert = generator.parseCertificate(Files.readString(certFile));
|
||||
keyPair = new KeyPair(cert.getPublicKey(), generator.parsePrivateKey(Files.readString(keyFile)));
|
||||
X509Certificate cert = Pem.parseCertificate(Files.readString(certFile));
|
||||
keyPair = new KeyPair(cert.getPublicKey(), Pem.parsePrivateKey(Files.readString(keyFile)));
|
||||
keyAlgorithm = generator.detectKeyAlgorithm(cert.getPublicKey());
|
||||
Set<String> sans = sansOf(cert);
|
||||
|
||||
@@ -215,7 +216,7 @@ public class TlsCertificateManager implements Resettable {
|
||||
listenerBehindFiles = true;
|
||||
reloadServer();
|
||||
listenerBehindFiles = false;
|
||||
knownHostnames = sansOf(generator.parseCertificate(issued.certificatePem()));
|
||||
knownHostnames = sansOf(Pem.parseCertificate(issued.certificatePem()));
|
||||
}
|
||||
|
||||
/** Re-reads the files into the registry and swaps the listener; throws when either did not happen. */
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.core.common.AwsPartition;
|
||||
import io.github.hectorvent.floci.core.common.AwsPartitions;
|
||||
import io.github.hectorvent.floci.core.common.AwsRegions;
|
||||
import io.github.hectorvent.floci.core.common.Pem;
|
||||
import io.github.hectorvent.floci.services.acm.CertificateGenerator;
|
||||
import io.github.hectorvent.floci.services.acm.model.KeyAlgorithm;
|
||||
import org.bouncycastle.asn1.x509.Extension;
|
||||
@@ -392,7 +393,7 @@ public class TlsConfigSource implements ConfigSource {
|
||||
private static List<String> servedSans(Path certFile) {
|
||||
List<String> sans = new ArrayList<>();
|
||||
try {
|
||||
X509Certificate cert = new CertificateGenerator().parseCertificate(Files.readString(certFile));
|
||||
X509Certificate cert = Pem.parseCertificate(Files.readString(certFile));
|
||||
if (cert.getSubjectAlternativeNames() != null) {
|
||||
for (List<?> entry : cert.getSubjectAlternativeNames()) {
|
||||
sans.add(String.valueOf(entry.get(1)));
|
||||
@@ -432,7 +433,7 @@ public class TlsConfigSource implements ConfigSource {
|
||||
*/
|
||||
private boolean isValidLocalLeaf(FlociCertificateAuthority ca, Path certFile) {
|
||||
try {
|
||||
X509Certificate cert = new CertificateGenerator().parseCertificate(Files.readString(certFile));
|
||||
X509Certificate cert = Pem.parseCertificate(Files.readString(certFile));
|
||||
if (!ca.isIssuedByUs(cert)) {
|
||||
LOG.infov("TLS: existing server certificate was not issued by the local CA; regenerating");
|
||||
return false;
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
/**
|
||||
* Thrown when PEM certificate or private-key material cannot be read, or when certificate
|
||||
* generation fails.
|
||||
*
|
||||
* <p>Lives here rather than beside a single service because the material it describes is read by
|
||||
* {@code config} and by several services, not just by ACM.
|
||||
*/
|
||||
public class CertificateMaterialException extends RuntimeException {
|
||||
|
||||
public CertificateMaterialException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public CertificateMaterialException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
|
||||
import org.bouncycastle.cert.X509CertificateHolder;
|
||||
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
|
||||
import org.bouncycastle.openssl.PEMKeyPair;
|
||||
import org.bouncycastle.openssl.PEMParser;
|
||||
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
import java.security.Signature;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.security.interfaces.ECKey;
|
||||
|
||||
/**
|
||||
* Reading PEM certificate and private-key material, and checking that the two belong together.
|
||||
*
|
||||
* <p>These are stateless and have no connection to any one AWS service: {@code config} reads the
|
||||
* emulator's own TLS material with them, IoT and the RDS proxy read device and endpoint material,
|
||||
* ACM reads what a caller imports, and IAM reads what is uploaded as a server certificate. They
|
||||
* previously lived on {@code services.acm.CertificateGenerator}, which meant unrelated packages
|
||||
* depended on ACM to parse a file. Generation still belongs to that class; only the reading side
|
||||
* is shared.
|
||||
*/
|
||||
public final class Pem {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(Pem.class);
|
||||
|
||||
private Pem() {
|
||||
}
|
||||
|
||||
/** The certificate a PEM block holds. */
|
||||
public static X509Certificate parseCertificate(String certPem) {
|
||||
try (PEMParser parser = new PEMParser(new StringReader(certPem))) {
|
||||
Object parsed = parser.readObject();
|
||||
if (parsed instanceof X509CertificateHolder holder) {
|
||||
return new JcaX509CertificateConverter().getCertificate(holder);
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid certificate PEM format");
|
||||
} catch (Exception e) {
|
||||
LOG.error("Failed to parse certificate", e);
|
||||
throw new CertificateMaterialException("Certificate parsing failed: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/** The private key a PEM block holds, whether it is a key pair or a bare PKCS#8 key. */
|
||||
public static PrivateKey parsePrivateKey(String keyPem) {
|
||||
try (PEMParser parser = new PEMParser(new StringReader(keyPem))) {
|
||||
Object parsed = parser.readObject();
|
||||
JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
|
||||
if (parsed instanceof PEMKeyPair pemKeyPair) {
|
||||
// Only the private half is needed, and a SEC1 key may carry no public half at all.
|
||||
return converter.getPrivateKey(pemKeyPair.getPrivateKeyInfo());
|
||||
} else if (parsed instanceof PrivateKeyInfo keyInfo) {
|
||||
return converter.getPrivateKey(keyInfo);
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid private key PEM format");
|
||||
} catch (Exception e) {
|
||||
LOG.error("Failed to parse private key", e);
|
||||
throw new CertificateMaterialException("Private key parsing failed: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* True when {@code privateKey} signs what {@code publicKey} verifies. Done by signing a probe
|
||||
* rather than comparing key fields, so it holds for RSA and EC alike without either being
|
||||
* special-cased beyond the signature algorithm.
|
||||
*/
|
||||
public static boolean isPair(PrivateKey privateKey, PublicKey publicKey) throws Exception {
|
||||
String algorithm = privateKey instanceof ECKey ? "SHA256withECDSA" : "SHA256withRSA";
|
||||
byte[] probe = "floci".getBytes(StandardCharsets.US_ASCII);
|
||||
Signature signer = Signature.getInstance(algorithm);
|
||||
signer.initSign(privateKey);
|
||||
signer.update(probe);
|
||||
byte[] signature = signer.sign();
|
||||
Signature verifier = Signature.getInstance(algorithm);
|
||||
verifier.initVerify(publicKey);
|
||||
verifier.update(probe);
|
||||
return verifier.verify(signature);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.config.FlociCertificateAuthority;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.Pem;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.resource.ExplorerResource;
|
||||
import io.github.hectorvent.floci.core.resource.ResourceProvider;
|
||||
@@ -394,7 +395,7 @@ public class AcmService implements ResourceProvider {
|
||||
// Parse and validate certificate
|
||||
X509Certificate x509Cert;
|
||||
try {
|
||||
x509Cert = certificateGenerator.parseCertificate(certificatePem);
|
||||
x509Cert = Pem.parseCertificate(certificatePem);
|
||||
certificateGenerator.validateCertificate(x509Cert);
|
||||
} catch (Exception e) {
|
||||
throw new AwsException("ValidationException", "Invalid certificate: " + e.getMessage(), 400);
|
||||
@@ -402,7 +403,7 @@ public class AcmService implements ResourceProvider {
|
||||
|
||||
// Parse and validate private key
|
||||
try {
|
||||
certificateGenerator.parsePrivateKey(privateKeyPem);
|
||||
Pem.parsePrivateKey(privateKeyPem);
|
||||
} catch (Exception e) {
|
||||
throw new AwsException("ValidationException", "Invalid private key: " + e.getMessage(), 400);
|
||||
}
|
||||
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
package io.github.hectorvent.floci.services.acm;
|
||||
|
||||
/**
|
||||
* Exception thrown when certificate generation or parsing fails.
|
||||
*/
|
||||
public class CertificateGenerationException extends RuntimeException {
|
||||
|
||||
public CertificateGenerationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public CertificateGenerationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,13 @@
|
||||
package io.github.hectorvent.floci.services.acm;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.CertificateMaterialException;
|
||||
import io.github.hectorvent.floci.core.common.Pem;
|
||||
import io.github.hectorvent.floci.services.acm.model.KeyAlgorithm;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import org.bouncycastle.asn1.ASN1Primitive;
|
||||
import org.bouncycastle.asn1.DEROctetString;
|
||||
import org.bouncycastle.asn1.pkcs.EncryptedPrivateKeyInfo;
|
||||
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
|
||||
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
|
||||
import org.bouncycastle.asn1.x500.X500Name;
|
||||
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
|
||||
import org.bouncycastle.asn1.x509.BasicConstraints;
|
||||
@@ -24,9 +25,6 @@ import org.bouncycastle.cert.X509v3CertificateBuilder;
|
||||
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
|
||||
import org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils;
|
||||
import org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder;
|
||||
import org.bouncycastle.openssl.PEMKeyPair;
|
||||
import org.bouncycastle.openssl.PEMParser;
|
||||
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;
|
||||
import org.bouncycastle.openssl.jcajce.JcaPEMWriter;
|
||||
import org.bouncycastle.openssl.jcajce.JcePEMEncryptorBuilder;
|
||||
import org.bouncycastle.operator.ContentSigner;
|
||||
@@ -147,7 +145,7 @@ public class CertificateGenerator {
|
||||
return toGenerated(cert, keyPair.getPrivate(), dn.toString(), dn.toString());
|
||||
} catch (Exception e) {
|
||||
LOG.error("Failed to generate CA certificate", e);
|
||||
throw new CertificateGenerationException("CA generation failed: " + e.getMessage(), e);
|
||||
throw new CertificateMaterialException("CA generation failed: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +173,7 @@ public class CertificateGenerator {
|
||||
if (subjectKeyPair != null && !isOfAlgorithm(subjectKeyPair.getPublic(), keyAlgorithm)) {
|
||||
throw new IllegalArgumentException("supplied key pair is not the requested " + keyAlgorithm);
|
||||
}
|
||||
if (subjectKeyPair != null && !isPair(subjectKeyPair.getPrivate(), subjectKeyPair.getPublic())) {
|
||||
if (subjectKeyPair != null && !Pem.isPair(subjectKeyPair.getPrivate(), subjectKeyPair.getPublic())) {
|
||||
throw new IllegalArgumentException("supplied private key does not match its public key");
|
||||
}
|
||||
KeyPair keyPair = subjectKeyPair != null ? subjectKeyPair : generateKeyPair(keyAlgorithm);
|
||||
@@ -189,7 +187,7 @@ public class CertificateGenerator {
|
||||
issuer.certificate().getSubjectX500Principal().getName());
|
||||
} catch (Exception e) {
|
||||
LOG.error("Failed to generate issued certificate", e);
|
||||
throw new CertificateGenerationException("Certificate generation failed: " + e.getMessage(), e);
|
||||
throw new CertificateMaterialException("Certificate generation failed: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,20 +209,7 @@ public class CertificateGenerator {
|
||||
return !(key instanceof ECKey) && detectKeyAlgorithm(key) == keyAlgorithm;
|
||||
}
|
||||
|
||||
/** True when {@code privateKey} signs what {@code publicKey} verifies. */
|
||||
public static boolean isPair(PrivateKey privateKey, PublicKey publicKey) throws Exception {
|
||||
String algorithm = privateKey instanceof ECKey ? "SHA256withECDSA" : "SHA256withRSA";
|
||||
byte[] probe = "floci".getBytes(StandardCharsets.US_ASCII);
|
||||
Signature signer = Signature.getInstance(algorithm);
|
||||
signer.initSign(privateKey);
|
||||
signer.update(probe);
|
||||
byte[] signature = signer.sign();
|
||||
Signature verifier = Signature.getInstance(algorithm);
|
||||
verifier.initVerify(publicKey);
|
||||
verifier.update(probe);
|
||||
return verifier.verify(signature);
|
||||
}
|
||||
|
||||
|
||||
private GeneratedCertificate buildSelfSignedCertificate(String domainName, List<String> sans,
|
||||
KeyAlgorithm keyAlgorithm, KeyPair suppliedKeyPair) {
|
||||
try {
|
||||
@@ -236,7 +221,7 @@ public class CertificateGenerator {
|
||||
return toGenerated(cert, keyPair.getPrivate(), dn, dn);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Failed to generate certificate", e);
|
||||
throw new CertificateGenerationException("Certificate generation failed: " + e.getMessage(), e);
|
||||
throw new CertificateMaterialException("Certificate generation failed: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -443,7 +428,7 @@ public class CertificateGenerator {
|
||||
/**
|
||||
* PEM for a certificate or key. A JDK EC private key goes out as PKCS#8 ({@code PRIVATE KEY}):
|
||||
* {@link JcaPEMWriter} would write it as a bare SEC1 structure without the curve, which neither
|
||||
* OpenSSL nor {@link #parsePrivateKey} can read. RSA keys stay PKCS#1 ({@code RSA PRIVATE KEY}),
|
||||
* OpenSSL nor {@link Pem#parsePrivateKey} can read. RSA keys stay PKCS#1 ({@code RSA PRIVATE KEY}),
|
||||
* the form AWS IoT hands out.
|
||||
*/
|
||||
public String toPem(Object obj) throws Exception {
|
||||
@@ -467,7 +452,7 @@ public class CertificateGenerator {
|
||||
*/
|
||||
public String encryptPrivateKey(String privateKeyPem, String passphrase) {
|
||||
try {
|
||||
PrivateKey privateKey = parsePrivateKey(privateKeyPem);
|
||||
PrivateKey privateKey = Pem.parsePrivateKey(privateKeyPem);
|
||||
|
||||
// PBES2 with AES-256-CBC, run through the JDK so no JCE provider has to be
|
||||
// registered. The algorithm name fixes the PBKDF2 PRF to HMAC-SHA256, and the
|
||||
@@ -496,41 +481,11 @@ public class CertificateGenerator {
|
||||
|
||||
} catch (Exception e) {
|
||||
LOG.error("Failed to encrypt private key", e);
|
||||
throw new CertificateGenerationException("Private key encryption failed: " + e.getMessage(), e);
|
||||
throw new CertificateMaterialException("Private key encryption failed: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public X509Certificate parseCertificate(String certPem) {
|
||||
try (PEMParser parser = new PEMParser(new StringReader(certPem))) {
|
||||
Object obj = parser.readObject();
|
||||
if (obj instanceof X509CertificateHolder holder) {
|
||||
return new JcaX509CertificateConverter()
|
||||
.getCertificate(holder);
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid certificate PEM format");
|
||||
} catch (Exception e) {
|
||||
LOG.error("Failed to parse certificate", e);
|
||||
throw new CertificateGenerationException("Certificate parsing failed: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public PrivateKey parsePrivateKey(String keyPem) {
|
||||
try (PEMParser parser = new PEMParser(new StringReader(keyPem))) {
|
||||
Object obj = parser.readObject();
|
||||
JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
|
||||
|
||||
if (obj instanceof PEMKeyPair pemKeyPair) {
|
||||
// Only the private half is needed, and a SEC1 key may carry no public half at all.
|
||||
return converter.getPrivateKey(pemKeyPair.getPrivateKeyInfo());
|
||||
} else if (obj instanceof PrivateKeyInfo pkInfo) {
|
||||
return converter.getPrivateKey(pkInfo);
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid private key PEM format");
|
||||
} catch (Exception e) {
|
||||
LOG.error("Failed to parse private key", e);
|
||||
throw new CertificateGenerationException("Private key parsing failed: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void validateCertificate(X509Certificate cert) {
|
||||
try {
|
||||
|
||||
@@ -11,6 +11,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.config.FlociCertificateAuthority;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.Pem;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
@@ -370,7 +371,7 @@ public class IotService {
|
||||
private void issueFromLocalCa(IotCertificate certificate) {
|
||||
CertificateGenerator.GeneratedCertificate issued = certificateAuthority.issueClientCertificate("AWS IoT Certificate");
|
||||
try {
|
||||
fill(certificate, new CertificateGenerator().parseCertificate(issued.certificatePem()));
|
||||
fill(certificate, Pem.parseCertificate(issued.certificatePem()));
|
||||
certificate.setPrivateKey(issued.privateKeyPem());
|
||||
} catch (Exception e) {
|
||||
throw new AwsException("InternalFailureException", "Could not issue device certificate: " + e.getMessage(), 500);
|
||||
|
||||
+5
-4
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.rds.proxy;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.config.CertificateMetadata;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.Pem;
|
||||
import io.github.hectorvent.floci.services.acm.CertificateGenerator;
|
||||
import io.github.hectorvent.floci.services.acm.model.KeyAlgorithm;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
@@ -152,8 +153,8 @@ public class RdsProxyTlsCertificates {
|
||||
restrictToOwnerOnly(keyFile, "rw-------");
|
||||
writeMetadata(tlsDir.resolve(METADATA_NAME), sanList);
|
||||
|
||||
X509Certificate certificate = certificateGenerator.parseCertificate(generated.certificatePem());
|
||||
PrivateKey privateKey = certificateGenerator.parsePrivateKey(generated.privateKeyPem());
|
||||
X509Certificate certificate = Pem.parseCertificate(generated.certificatePem());
|
||||
PrivateKey privateKey = Pem.parsePrivateKey(generated.privateKeyPem());
|
||||
this.sslContext = buildSslContext(certificate, privateKey);
|
||||
this.currentSans = Set.copyOf(sans);
|
||||
this.currentKeyPair = new KeyPair(certificate.getPublicKey(), privateKey);
|
||||
@@ -166,8 +167,8 @@ public class RdsProxyTlsCertificates {
|
||||
}
|
||||
|
||||
private void loadExisting(Path certFile, Path keyFile, List<String> sans) throws Exception {
|
||||
X509Certificate certificate = certificateGenerator.parseCertificate(Files.readString(certFile));
|
||||
PrivateKey privateKey = certificateGenerator.parsePrivateKey(Files.readString(keyFile));
|
||||
X509Certificate certificate = Pem.parseCertificate(Files.readString(certFile));
|
||||
PrivateKey privateKey = Pem.parsePrivateKey(Files.readString(keyFile));
|
||||
this.sslContext = buildSslContext(certificate, privateKey);
|
||||
this.currentSans = new LinkedHashSet<>(sans);
|
||||
this.currentKeyPair = new KeyPair(certificate.getPublicKey(), privateKey);
|
||||
|
||||
Reference in new issue
Block a user