Class CertificateUtil
java.lang.Object
org.eclipse.milo.opcua.stack.core.util.CertificateUtil
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic X509CertificatedecodeCertificate(byte[] certificateBytes) Decode a DER-encoded X.509 certificate.static X509CertificatedecodeCertificate(InputStream inputStream) Decode a DER-encoded X.509 certificate.static List<X509Certificate>decodeCertificates(byte[] certificateBytes) Decode either a sequence of DER-encoded X.509 certificates or a PKCS#7 certificate chain.static List<X509Certificate>decodeCertificates(InputStream inputStream) Decode either a sequence of DER-encoded X.509 certificates or a PKCS#7 certificate chain.static org.bouncycastle.pkcs.PKCS10CertificationRequestgenerateCsr(KeyPair keyPair, String subjectName, String sanUri, List<String> sanDnsNames, List<String> sanIpAddresses, String signatureAlgorithm) Generate aPKCS10CertificationRequest.static org.bouncycastle.pkcs.PKCS10CertificationRequestgenerateCsr(KeyPair keyPair, X509Certificate certificate) Generate aPKCS10CertificationRequestfor the providedcertificateandkeyPair.static org.bouncycastle.pkcs.PKCS10CertificationRequestgenerateCsr(KeyPair keyPair, org.bouncycastle.asn1.x500.X500Name subject, String sanUri, List<String> sanDnsNames, List<String> sanIpAddresses, String signatureAlgorithm) Generate aPKCS10CertificationRequest.static ByteStringgetCertificateChainBytes(List<X509Certificate> certificateChain) static StringgetCsrPem(org.bouncycastle.pkcs.PKCS10CertificationRequest csr) Get a PEM-encoded String containing a PKCS #10 certificate signing request.getSanDnsNames(X509Certificate certificate) Get the DNS names from thecertificate's Subject Alternative Name extension, if it's present.getSanIpAddresses(X509Certificate certificate) Get the IP addresses from thecertificate's Subject Alternative Name extension, if it's present.getSanUri(X509Certificate certificate) Get the URI from thecertificate's Subject Alternative Name extension, if it's present.getSubjectAltNameField(X509Certificate certificate, int field) Extract the value of a given SubjectAltName field from aX509Certificate.static ByteStringthumbprint(X509Certificate certificate)
-
Field Details
-
SUBJECT_ALT_NAME_DNS_NAME
public static final int SUBJECT_ALT_NAME_DNS_NAME- See Also:
-
SUBJECT_ALT_NAME_IP_ADDRESS
public static final int SUBJECT_ALT_NAME_IP_ADDRESS- See Also:
-
SUBJECT_ALT_NAME_URI
public static final int SUBJECT_ALT_NAME_URI- See Also:
-
-
Constructor Details
-
CertificateUtil
public CertificateUtil()
-
-
Method Details
-
decodeCertificate
Decode a DER-encoded X.509 certificate.- Parameters:
certificateBytes- DER-encoded certificate bytes.- Returns:
- an
X509Certificate - Throws:
UaException- if decoding the certificate fails.
-
decodeCertificate
Decode a DER-encoded X.509 certificate.- Parameters:
inputStream-InputStreamcontaining DER-encoded certificate bytes.- Returns:
- an
X509Certificate - Throws:
UaException- if decoding the certificate fails.
-
decodeCertificates
Decode either a sequence of DER-encoded X.509 certificates or a PKCS#7 certificate chain.- Parameters:
certificateBytes- the byte[] to decode from.- Returns:
- a
Listof certificates deocded fromcertificateBytes. - Throws:
UaException- if decoding fails.
-
decodeCertificates
Decode either a sequence of DER-encoded X.509 certificates or a PKCS#7 certificate chain.- Parameters:
inputStream- theInputStreamto decode from.- Returns:
- a
Listof certificates decoded frominputStream. - Throws:
UaException- if decoding fails.
-
generateCsr
public static org.bouncycastle.pkcs.PKCS10CertificationRequest generateCsr(KeyPair keyPair, X509Certificate certificate) throws Exception Generate aPKCS10CertificationRequestfor the providedcertificateandkeyPair.- Parameters:
keyPair- theKeyPairforcertificate.certificate- theX509Certificateto request signing for.- Returns:
- a
PKCS10CertificationRequest. - Throws:
Exception- if creating the signing request fails for any reason.
-
generateCsr
public static org.bouncycastle.pkcs.PKCS10CertificationRequest generateCsr(KeyPair keyPair, String subjectName, String sanUri, List<String> sanDnsNames, List<String> sanIpAddresses, String signatureAlgorithm) throws Exception Generate aPKCS10CertificationRequest.- Parameters:
keyPair- theKeyPaircontaining Public and Private keys.subjectName- the subject name, in RFC 4519 style. (CN=foo,O=bar)sanUri- the URI to request in the SAN.sanDnsNames- the DNS names to request in the SAN.sanIpAddresses- the IP addresses to request in the SAN.signatureAlgorithm- the signature algorithm to use when generating the signature to validate the certificate.- Returns:
- a
PKCS10CertificationRequest. - Throws:
Exception- if creating the signing request fails for any reason.
-
generateCsr
public static org.bouncycastle.pkcs.PKCS10CertificationRequest generateCsr(KeyPair keyPair, org.bouncycastle.asn1.x500.X500Name subject, String sanUri, List<String> sanDnsNames, List<String> sanIpAddresses, String signatureAlgorithm) throws Exception Generate aPKCS10CertificationRequest.- Parameters:
keyPair- theKeyPaircontaining Public and Private keys.subject- the subject nameX500Name.sanUri- the URI to request in the SAN.sanDnsNames- the DNS names to request in the SAN.sanIpAddresses- the IP addresses to request in the SAN.signatureAlgorithm- the signature algorithm to use when generating the signature to validate the certificate.- Returns:
- a
PKCS10CertificationRequest. - Throws:
Exception- if creating the signing request fails for any reason.
-
getCsrPem
public static String getCsrPem(org.bouncycastle.pkcs.PKCS10CertificationRequest csr) throws IOException Get a PEM-encoded String containing a PKCS #10 certificate signing request.- Parameters:
csr- theX509Certificateto request signing for.- Returns:
- a PEM-encoded String containing a PKCS #10 CSR.
- Throws:
IOException- if creating the signing request fails for any reason.
-
getSubjectAltNameField
Extract the value of a given SubjectAltName field from aX509Certificate.- Parameters:
certificate- the certificate.field- the field number.- Returns:
- an
Optionalcontaining the value in the field. - See Also:
-
getSanUri
Get the URI from thecertificate's Subject Alternative Name extension, if it's present.- Parameters:
certificate- the certificate to get the URI from.- Returns:
- the value of the SAN URI, if present.
-
getSanDnsNames
Get the DNS names from thecertificate's Subject Alternative Name extension, if it's present.- Parameters:
certificate- the certificate to get the DNS names from.- Returns:
- the values of the SAN DNS names, or empty list if none are present.
-
getSanIpAddresses
Get the IP addresses from thecertificate's Subject Alternative Name extension, if it's present.- Parameters:
certificate- the certificate to get the IP addresses from.- Returns:
- the values of the SAN IP addresses, or empty list if none are present.
-
thumbprint
- Throws:
UaException
-
getCertificateChainBytes
public static ByteString getCertificateChainBytes(List<X509Certificate> certificateChain) throws UaException - Throws:
UaException
-