java.lang.Object
org.shredzone.acme4j.util.CertificateUtils
Utility class offering convenience methods for certificates.
Requires Bouncy Castle. This class is part of the acme4j-utils module.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.bouncycastle.asn1.ASN1ObjectIdentifierTheacmeValidationobject identifier. -
Method Summary
Modifier and TypeMethodDescriptionstatic X509CertificatecreateTestCertificate(org.bouncycastle.pkcs.PKCS10CertificationRequest csr, Instant notBefore, Instant notAfter, X509Certificate issuer, PrivateKey issuerPrivateKey) Creates a signed end entity certificate from the given CSR.static X509CertificatecreateTestIntermediateCertificate(String subject, Instant notBefore, Instant notAfter, PublicKey intermediatePublicKey, X509Certificate issuer, PrivateKey issuerPrivateKey) Creates an intermediate certificate that is signed by an issuer.static X509CertificatecreateTestRootCertificate(String subject, Instant notBefore, Instant notAfter, KeyPair keypair) Creates a self-signed root certificate.static X509CertificatecreateTlsAlpn01Certificate(KeyPair keypair, Identifier id, byte[] acmeValidation) Creates a self-signedX509Certificatethat can be used for theTlsAlpn01Challenge.static org.bouncycastle.pkcs.PKCS10CertificationRequestreadCSR(InputStream in) Reads a CSR PEM file.
-
Field Details
-
ACME_VALIDATION
TheacmeValidationobject identifier.- Since:
- 2.1
-
-
Method Details
-
readCSR
public static org.bouncycastle.pkcs.PKCS10CertificationRequest readCSR(InputStream in) throws IOException Reads a CSR PEM file.- Parameters:
in-InputStreamto read the CSR from. TheInputStreamis closed after use.- Returns:
- CSR that was read
- Throws:
IOException
-
createTlsAlpn01Certificate
public static X509Certificate createTlsAlpn01Certificate(KeyPair keypair, Identifier id, byte[] acmeValidation) throws IOException Creates a self-signedX509Certificatethat can be used for theTlsAlpn01Challenge. The certificate is valid for 7 days.- Parameters:
keypair- A domainKeyPairto be used for the challengeid- TheIdentifierthat is to be validatedacmeValidation- The value that is returned byTlsAlpn01Challenge.getAcmeValidation()- Returns:
- Created certificate
- Throws:
IOException- Since:
- 2.6
-
createTestRootCertificate
public static X509Certificate createTestRootCertificate(String subject, Instant notBefore, Instant notAfter, KeyPair keypair) Creates a self-signed root certificate.The generated certificate is only meant for testing purposes!
- Parameters:
subject- This certificate's subject X.500 name.notBefore-Instantbefore which the certificate is not valid.notAfter-Instantafter which the certificate is not valid.keypair-KeyPairthat is to be used for this certificate.- Returns:
- Generated
X509Certificate - Since:
- 2.8
-
createTestIntermediateCertificate
public static X509Certificate createTestIntermediateCertificate(String subject, Instant notBefore, Instant notAfter, PublicKey intermediatePublicKey, X509Certificate issuer, PrivateKey issuerPrivateKey) Creates an intermediate certificate that is signed by an issuer.The generated certificate is only meant for testing purposes!
- Parameters:
subject- This certificate's subject X.500 name.notBefore-Instantbefore which the certificate is not valid.notAfter-Instantafter which the certificate is not valid.intermediatePublicKey-PublicKeyof this certificateissuer- The issuer'sX509Certificate.issuerPrivateKey-PrivateKeyof the issuer. This is not the private key of this intermediate certificate.- Returns:
- Generated
X509Certificate - Since:
- 2.8
-
createTestCertificate
public static X509Certificate createTestCertificate(org.bouncycastle.pkcs.PKCS10CertificationRequest csr, Instant notBefore, Instant notAfter, X509Certificate issuer, PrivateKey issuerPrivateKey) Creates a signed end entity certificate from the given CSR.This method is only meant for testing purposes! Do not use it in a real-world CA implementation.
Do not assume that real-world certificates have a similar structure. It's up to the discretion of the CA which distinguished names, validity dates, extensions and other parameters are transferred from the CSR to the generated certificate.
- Parameters:
csr- CSR to create the certificate fromnotBefore-Instantbefore which the certificate is not valid.notAfter-Instantafter which the certificate is not valid.issuer- The issuer'sX509Certificate.issuerPrivateKey-PrivateKeyof the issuer. This is not the private key the CSR was signed with.- Returns:
- Generated
X509Certificate - Since:
- 2.8
-