Package org.microproxy.tls
Class CertificateBuilder
java.lang.Object
org.microproxy.tls.CertificateBuilder
Builds and signs X.509 v3 certificates with nothing but the JDK, which has no public
certificate-generation API. Supports what a TLS-intercepting proxy needs: CA certificates and
server certificates with subject alternative names, signed with ECDSA or RSA (SHA-256).
-
Constructor Summary
ConstructorsConstructorDescriptionStarts a self-signed server certificate with the default subject and validity. -
Method Summary
Modifier and TypeMethodDescriptionaddSubjectAltName(String nameOrIp) Adds a DNS name or IP literal to the subject alternative names.certificateAuthority(boolean ca) Sets whether the certificate may issue other certificates.issuer(X509Certificate issuer) The issuing CA certificate; leave unset for a self-signed certificate.Sets the public key certified by this certificate.sign(PrivateKey signingKey) Signs the certificate withsigningKey(the issuer's key, or the subject's own).Sets the certificate subject.Sets the certificate validity interval.
-
Constructor Details
-
CertificateBuilder
public CertificateBuilder()Starts a self-signed server certificate with the default subject and validity.
-
-
Method Details
-
subject
Sets the certificate subject.- Parameters:
commonName- the certificate subject common nameorganization- the subject organization- Returns:
- this builder
-
issuer
The issuing CA certificate; leave unset for a self-signed certificate.- Parameters:
issuer- the issuing CA certificate- Returns:
- this builder
-
publicKey
Sets the public key certified by this certificate.- Parameters:
publicKey- the public key to certify- Returns:
- this builder
-
validity
Sets the certificate validity interval.- Parameters:
notBefore- the start of the validity intervalnotAfter- the end of the validity interval- Returns:
- this builder
-
certificateAuthority
Sets whether the certificate may issue other certificates.- Parameters:
ca- whether the certificate may sign other certificates- Returns:
- this builder
-
addSubjectAltName
Adds a DNS name or IP literal to the subject alternative names.- Parameters:
nameOrIp- the DNS name or IP literal to add- Returns:
- this builder
-
sign
Signs the certificate withsigningKey(the issuer's key, or the subject's own).- Parameters:
signingKey- the private key used to sign the certificate- Returns:
- the signed certificate
- Throws:
GeneralSecurityException- if the certificate cannot be signed
-