Package org.wildfly.security.x500.cert
Class PKCS10CertificateSigningRequest.Builder
- java.lang.Object
-
- org.wildfly.security.x500.cert.PKCS10CertificateSigningRequest.Builder
-
- Enclosing class:
- PKCS10CertificateSigningRequest
public static class PKCS10CertificateSigningRequest.Builder extends Object
ABuilder
to configure and generate aPKCS10CertificateSigningRequest
.
-
-
Field Summary
Fields Modifier and Type Field Description private Certificate
certificate
private Map<String,X509CertificateExtension>
extensionsByOid
private PublicKey
publicKey
private String
signatureAlgorithmName
private String
signatureAlgorithmOid
private PrivateKey
signingKey
private X500Principal
subjectDn
private static int
VERSION
-
Constructor Summary
Constructors Constructor Description Builder()
Construct a new uninitialized instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description PKCS10CertificateSigningRequest.Builder
addExtension(boolean critical, String extensionName, String extensionValue)
Add an X.509 certificate extension that should be included in the certificate signing request using the given extension name and string value.PKCS10CertificateSigningRequest.Builder
addExtension(X509CertificateExtension extension)
Add an X.509 certificate extension that should be included in the certificate signing request.PKCS10CertificateSigningRequest
build()
Attempt to generate a PKCS #10 certificate signing request.private void
encodeAlgorithmIdentifier(DEREncoder encoder)
Encode anAlgorithmIdentifier
using the given DER encoder.private void
encodeAttributes(DEREncoder encoder)
EncodeAttributes
using the given DER encoder.private void
encodeCertificationRequest(DEREncoder encoder)
Encode aCertificationRequest
using the given DER encoder.private void
encodeCertificationRequestInfo(DEREncoder encoder)
Encode aCertificationRequestInfo
using the given DER encoder.private static void
encodeExtension(DEREncoder encoder, X509CertificateExtension extension)
Encode anExtension
using the given DER encoder.private void
encodeExtensionRequest(DEREncoder encoder)
Encode anExtensionRequest
using the given DER encoder.PKCS10CertificateSigningRequest.Builder
setCertificate(Certificate certificate)
Set the certificate.PKCS10CertificateSigningRequest.Builder
setSignatureAlgorithmName(String signatureAlgorithmName)
Set the signature algorithm name.PKCS10CertificateSigningRequest.Builder
setSigningKey(PrivateKey signingKey)
Set the signing key.PKCS10CertificateSigningRequest.Builder
setSubjectDn(X500Principal subjectDn)
Set the subject DN.
-
-
-
Field Detail
-
VERSION
private static final int VERSION
- See Also:
- Constant Field Values
-
certificate
private Certificate certificate
-
publicKey
private PublicKey publicKey
-
signingKey
private PrivateKey signingKey
-
signatureAlgorithmName
private String signatureAlgorithmName
-
signatureAlgorithmOid
private String signatureAlgorithmOid
-
subjectDn
private X500Principal subjectDn
-
extensionsByOid
private final Map<String,X509CertificateExtension> extensionsByOid
-
-
Method Detail
-
setCertificate
public PKCS10CertificateSigningRequest.Builder setCertificate(Certificate certificate)
Set the certificate.- Parameters:
certificate
- the certificate (must not benull
)- Returns:
- this builder instance
-
setSigningKey
public PKCS10CertificateSigningRequest.Builder setSigningKey(PrivateKey signingKey)
Set the signing key.- Parameters:
signingKey
- the signing key (must not benull
)- Returns:
- this builder instance
-
setSubjectDn
public PKCS10CertificateSigningRequest.Builder setSubjectDn(X500Principal subjectDn)
Set the subject DN.- Parameters:
subjectDn
- the subject DN (must not benull
)- Returns:
- this builder instance
-
setSignatureAlgorithmName
public PKCS10CertificateSigningRequest.Builder setSignatureAlgorithmName(String signatureAlgorithmName)
Set the signature algorithm name.- Parameters:
signatureAlgorithmName
- the signature algorithm name (must not benull
)- Returns:
- this builder instance
-
addExtension
public PKCS10CertificateSigningRequest.Builder addExtension(X509CertificateExtension extension) throws IllegalArgumentException
Add an X.509 certificate extension that should be included in the certificate signing request. 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 PKCS10CertificateSigningRequest.Builder addExtension(boolean critical, String extensionName, String extensionValue) throws IllegalArgumentException
Add an X.509 certificate extension that should be included in the certificate signing request 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>]
whereca
indicates whether or not the subject is a CA. Ifca
is true,pathlen
indicates the path length constraint. -
name: KeyUsage
value: usage(,usage)*
wherevalue
is a list of the allowed key usages, where eachusage
value must be one of the following (usage
values are case-sensitive):digitalSignature
nonRepudiation
keyEncipherment
dataEncipherment
keyAgreement
keyCertSign
cRLSign
encipherOnly
decipherOnly
-
name: ExtendedKeyUsage
value: usage(,usage)*
wherevalue
is a list of the allowed key purposes, where eachusage
value must be one of the following (usage
values are case-sensitive):serverAuth
clientAuth
codeSigning
emailProtection
timeStamping
OCSPSigning
- any OID string
-
name SubjectAlternativeName
value: type:val(,type:val)*
wherevalue
is a list oftype:val
pairs, wheretype
can beEMAIL
,URI
,DNS
,IP
, orOID
andval
is a string value for thetype
. -
name: IssuerAlternativeName
value: type:val(,type:val)*
wherevalue
is a list oftype:val
pairs, wheretype
can beEMAIL
,URI
,DNS
,IP
, orOID
andval
is a string value for thetype
. -
name: AuthorityInformationAccess
value: method:location-type:location-value(,method:location-type:location-value)*
wherevalue
is a list ofmethod:location-type:location-value
triples, wheremethod
can beocsp
,caIssuers
, or any OID andlocation-type:location-value
can be anytype:val
pair as defined for theSubjectAlternativeName
extension. -
name: SubjectInformationAccess
value: method:location-type:location-value(,method:location-type:location-value)*
wherevalue
is a list ofmethod:location-type:location-value
triples, wheremethod
can betimeStamping
,caRepository
, or any OID andlocation-type:location-value
can be anytype:val
pair as defined for theSubjectAlternativeName
extension.
- 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
-
-
build
public PKCS10CertificateSigningRequest build() throws IllegalArgumentException
Attempt to generate a PKCS #10 certificate signing request.- Returns:
- the PKCS #10 certificate signing request
- Throws:
IllegalArgumentException
- if a required builder parameter is missing or invalid
-
encodeCertificationRequest
private void encodeCertificationRequest(DEREncoder encoder)
Encode aCertificationRequest
using the given DER encoder. The ASN.1 definition ofCertificationRequest
is:CertificationRequest ::= SEQUENCE { certificationRequestInfo CertificationRequestInfo, signatureAlgorithm AlgorithmIdentifier{{ SignatureAlgorithms }}, signature BIT STRING }
- Parameters:
encoder
- the DER encoder
-
encodeCertificationRequestInfo
private void encodeCertificationRequestInfo(DEREncoder encoder)
Encode aCertificationRequestInfo
using the given DER encoder. The ASN.1 definition ofCertificationRequestInfo
is:CertificationRequestInfo ::= SEQUENCE { version INTEGER { v1(0) } (v1,...), subject Name, subjectPKInfo SubjectPublicKeyInfo{{ PKInfoAlgorithms }}, attributes [0] Attributes{{ CRIAttributes }} }
- Parameters:
encoder
- the DER encoder
-
encodeAlgorithmIdentifier
private void encodeAlgorithmIdentifier(DEREncoder encoder)
Encode anAlgorithmIdentifier
using the given DER encoder. The ASN.1 definition ofAlgorithmIdentifier
is:AlgorithmIdentifier {ALGORITHM:IOSet } ::= SEQUENCE { algorithm ALGORITHM.&id({IOSet}), parameters ALGORITHM.&Type({IOSet}{@algorithm}) OPTIONAL }
- Parameters:
encoder
- the DER encoder
-
encodeAttributes
private void encodeAttributes(DEREncoder encoder)
EncodeAttributes
using the given DER encoder. The ASN.1 definition ofAttributes
is:Attributes ::= SET OF Attribute Attribute :: SEQUENCE { type AttributeType, values SET OF AttributeValue } AttributeType ::= OBJECT IDENTIFIER AttributeValue ::= ANY defined by type
- Parameters:
encoder
- the DER encoder
-
encodeExtensionRequest
private void encodeExtensionRequest(DEREncoder encoder)
Encode anExtensionRequest
using the given DER encoder. The ASN.1 definition ofExtensionRequest
is:ExtensionRequest ::= Extensions Extensions ::= SEQUENCE OF Extension
- Parameters:
encoder
- the DER encoder
-
encodeExtension
private static void encodeExtension(DEREncoder encoder, X509CertificateExtension extension)
Encode anExtension
using the given DER encoder. The ASN.1 definition ofExtension
is:Extension ::= SEQUENCE { extensionId OBJECT IDENTIFIER, critical BOOLEAN DEFAULT FALSE, extensionValue OCTET STRING }
- Parameters:
encoder
- the DER encoderextension
- the X.509 certificate extension
-
-