Package org.wildfly.security.x500.cert
Class SelfSignedX509CertificateAndSigningKey.Builder
- java.lang.Object
-
- org.wildfly.security.x500.cert.SelfSignedX509CertificateAndSigningKey.Builder
-
- Enclosing class:
- SelfSignedX509CertificateAndSigningKey
public static class SelfSignedX509CertificateAndSigningKey.Builder extends Object
ABuilderto configure and generate aSelfSignedX509CertificateAndSigningKey. ThisBuildergenerates a key pair and then wraps the resulting public key into a self-signed X.509 certificate.
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_EC_KEY_SIZEThe default key size that will be used if the key algorithm name is EC.static StringDEFAULT_KEY_ALGORITHM_NAMEThe default key algorithm name.static intDEFAULT_KEY_SIZEThe default key size that will be used if the key algorithm name is not EC.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SelfSignedX509CertificateAndSigningKey.BuilderaddExtension(boolean critical, String extensionName, String extensionValue)Add an X.509 certificate extension using the given extension name and string value.SelfSignedX509CertificateAndSigningKey.BuilderaddExtension(X509CertificateExtension extension)Add an X.509 certificate extension.X509CertificateExtensionaddOrReplaceExtension(boolean critical, String extensionName, String extensionValue)Add or replace an X.509 certificate extension.X509CertificateExtensionaddOrReplaceExtension(X509CertificateExtension extension)Add or replace an X.509 certificate extension.SelfSignedX509CertificateAndSigningKeybuild()Attempt to generate a key pair and wrap the resulting public key into a self-signed X.509 certificate.X509CertificateExtensionremoveExtension(String oid)Remove the X.509 extension with the given OID, if it is registered.SelfSignedX509CertificateAndSigningKey.BuildersetDn(X500Principal dn)Set the DN.SelfSignedX509CertificateAndSigningKey.BuildersetKeyAlgorithmName(String keyAlgorithmName)Set the key algorithm name to use when generating the key pair.SelfSignedX509CertificateAndSigningKey.BuildersetKeySize(int keySize)Set the key size to use when generating the key pair.SelfSignedX509CertificateAndSigningKey.BuildersetNotValidAfter(ZonedDateTime notValidAfter)Set the not-valid-after date.SelfSignedX509CertificateAndSigningKey.BuildersetNotValidBefore(ZonedDateTime notValidBefore)Set the not-valid-before date.SelfSignedX509CertificateAndSigningKey.BuildersetSignatureAlgorithmName(String signatureAlgorithmName)Set the signature algorithm name to use when signing the self-signed certificate.
-
-
-
Field Detail
-
DEFAULT_KEY_ALGORITHM_NAME
public static final String DEFAULT_KEY_ALGORITHM_NAME
The default key algorithm name.- See Also:
- Constant Field Values
-
DEFAULT_EC_KEY_SIZE
public static final int DEFAULT_EC_KEY_SIZE
The default key size that will be used if the key algorithm name is EC.- See Also:
- Constant Field Values
-
DEFAULT_KEY_SIZE
public static final int DEFAULT_KEY_SIZE
The default key size that will be used if the key algorithm name is not EC.- See Also:
- Constant Field Values
-
-
Method Detail
-
setKeyAlgorithmName
public SelfSignedX509CertificateAndSigningKey.Builder setKeyAlgorithmName(String keyAlgorithmName)
Set the key algorithm name to use when generating the key pair.- Parameters:
keyAlgorithmName- the key algorithm name to use when generating the key pair (must not benull)- Returns:
- this builder instance
-
setKeySize
public SelfSignedX509CertificateAndSigningKey.Builder setKeySize(int keySize)
Set the key size to use when generating the key pair.- Parameters:
keySize- the key size to use when generating the key pair- Returns:
- this builder instance
-
setSignatureAlgorithmName
public SelfSignedX509CertificateAndSigningKey.Builder setSignatureAlgorithmName(String signatureAlgorithmName)
Set the signature algorithm name to use when signing the self-signed certificate.- Parameters:
signatureAlgorithmName- the signature algorithm to use when signing the self-signed certificate (must not benull)- Returns:
- this builder instance
-
setDn
public SelfSignedX509CertificateAndSigningKey.Builder setDn(X500Principal dn)
Set the DN.- Parameters:
dn- the DN to use as both the subject DN and the issuer DN (must not benull)- Returns:
- this builder instance
-
addExtension
public SelfSignedX509CertificateAndSigningKey.Builder addExtension(X509CertificateExtension extension) throws IllegalArgumentException
Add an X.509 certificate extension. If an extension with the same OID already exists, an exception is thrown.- Parameters:
extension- the extension to add (must not benull)- Returns:
- this builder instance
- Throws:
IllegalArgumentException- if an extension with the same OID has already been added
-
addExtension
public SelfSignedX509CertificateAndSigningKey.Builder addExtension(boolean critical, String extensionName, String extensionValue) throws IllegalArgumentException
Add an X.509 certificate extension using the given extension name and string value. If an extension with the same name already exists, an exception is thrown. The following extension names and values are supported:-
name: BasicConstraints
value: ca:{true|false}[,pathlen:<len>]wherecaindicates whether or not the subject is a CA. Ifcais true,pathlenindicates the path length constraint. -
name: KeyUsage
value: usage(,usage)*wherevalueis a list of the allowed key usages, where eachusagevalue must be one of the following (usagevalues are case-sensitive):digitalSignaturenonRepudiationkeyEnciphermentdataEnciphermentkeyAgreementkeyCertSigncRLSignencipherOnlydecipherOnly
-
name: ExtendedKeyUsage
value: usage(,usage)*wherevalueis a list of the allowed key purposes, where eachusagevalue must be one of the following (usagevalues are case-sensitive):serverAuthclientAuthcodeSigningemailProtectiontimeStampingOCSPSigning- any OID string
-
name SubjectAlternativeName
value: type:val(,type:val)*wherevalueis a list oftype:valpairs, wheretypecan beEMAIL,URI,DNS,IP, orOIDandvalis a string value for thetype. -
name: IssuerAlternativeName
value: type:val(,type:val)*wherevalueis a list oftype:valpairs, wheretypecan beEMAIL,URI,DNS,IP, orOIDandvalis a string value for thetype. -
name: AuthorityInformationAccess
value: method:location-type:location-value(,method:location-type:location-value)*wherevalueis a list ofmethod:location-type:location-valuetriples, wheremethodcan beocsp,caIssuers, or any OID andlocation-type:location-valuecan be anytype:valpair as defined for theSubjectAlternativeNameextension. -
name: SubjectInformationAccess
value: method:location-type:location-value(,method:location-type:location-value)*wherevalueis a list ofmethod:location-type:location-valuetriples, wheremethodcan betimeStamping,caRepository, or any OID andlocation-type:location-valuecan be anytype:valpair as defined for theSubjectAlternativeNameextension.
- Parameters:
critical- whether the extension should be marked as criticalextensionName- the extension name (must not benull)extensionValue- the extension value, as a string (must not benull)- Returns:
- this builder instance
- Throws:
IllegalArgumentException- if an extension with the same name has already been added or if an error occurs while attempting to add the extension
-
-
addOrReplaceExtension
public X509CertificateExtension addOrReplaceExtension(X509CertificateExtension extension)
Add or replace an X.509 certificate extension. If an extension with the same OID already exists, it is replaced and returned.- Parameters:
extension- the extension to add (must not benull)- Returns:
- the existing extension or
nullif no other extension with the same OID existed
-
addOrReplaceExtension
public X509CertificateExtension addOrReplaceExtension(boolean critical, String extensionName, String extensionValue)
Add or replace an X.509 certificate extension. If an extension with the same name already exists, it is replaced and returned. SeeaddExtension(boolean, String, String)for the supported extension names and values.- Parameters:
critical- whether the extension should be marked as criticalextensionName- the extension name (must not benull)extensionValue- the extension value, as a string (must not benull)- Returns:
- the existing extension or
nullif no other extension with the same OID existed or if an error occurs while attempting to add the extension
-
removeExtension
public X509CertificateExtension removeExtension(String oid)
Remove the X.509 extension with the given OID, if it is registered.- Parameters:
oid- the OID of the extension to remove (must not benull)- Returns:
- the extension or
nullif no extension with the same OID existed
-
setNotValidBefore
public SelfSignedX509CertificateAndSigningKey.Builder setNotValidBefore(ZonedDateTime notValidBefore)
Set the not-valid-before date.- Parameters:
notValidBefore- the not-valid-before date (must not benull)- Returns:
- this builder instance
-
setNotValidAfter
public SelfSignedX509CertificateAndSigningKey.Builder setNotValidAfter(ZonedDateTime notValidAfter)
Set the not-valid-after date.- Parameters:
notValidAfter- the not-valid-after date (must not benull)- Returns:
- this builder instance
-
build
public SelfSignedX509CertificateAndSigningKey build() throws IllegalArgumentException
Attempt to generate a key pair and wrap the resulting public key into a self-signed X.509 certificate.- Returns:
- the self-signed X.509 certificate and signing key
- Throws:
IllegalArgumentException- if a required builder parameter is missing or invalid or if an error occurs while attempting to generate the self-signed X.509 certificate
-
-