Class PemX509Certificate

  • All Implemented Interfaces:
    ByteBufHolder, PemEncoded, ReferenceCounted, java.io.Serializable, java.security.cert.X509Extension

    public final class PemX509Certificate
    extends java.security.cert.X509Certificate
    implements PemEncoded
    This is a special purpose implementation of a X509Certificate which allows the user to pass PEM/PKCS#8 encoded data straight into OpenSslContext without having to parse and re-encode bytes in Java land. All methods other than what's implemented in PemEncoded's throw UnsupportedOperationExceptions.
    See Also:
    PemEncoded, OpenSslContext, valueOf(byte[]), valueOf(ByteBuf), Serialized Form
    • Field Detail

      • BEGIN_CERT

        private static final byte[] BEGIN_CERT
      • END_CERT

        private static final byte[] END_CERT
      • content

        private final ByteBuf content
    • Constructor Detail

      • PemX509Certificate

        private PemX509Certificate​(ByteBuf content)
    • Method Detail

      • toPEM

        static PemEncoded toPEM​(ByteBufAllocator allocator,
                                boolean useDirect,
                                java.security.cert.X509Certificate... chain)
                         throws java.security.cert.CertificateEncodingException
        Creates a PemEncoded value from the X509Certificates.
        Throws:
        java.security.cert.CertificateEncodingException
      • append

        private static ByteBuf append​(ByteBufAllocator allocator,
                                      boolean useDirect,
                                      java.security.cert.X509Certificate cert,
                                      int count,
                                      ByteBuf pem)
                               throws java.security.cert.CertificateEncodingException
        Appends the X509Certificate value to the ByteBuf (last arg) and returns it. If the ByteBuf didn't exist yet it'll create it using the ByteBufAllocator.
        Throws:
        java.security.cert.CertificateEncodingException
      • newBuffer

        private static ByteBuf newBuffer​(ByteBufAllocator allocator,
                                         boolean useDirect,
                                         int initialCapacity)
      • valueOf

        public static PemX509Certificate valueOf​(byte[] key)
        Creates a PemX509Certificate from raw byte[]. ATTENTION: It's assumed that the given argument is a PEM/PKCS#8 encoded value. No input validation is performed to validate it.
      • valueOf

        public static PemX509Certificate valueOf​(ByteBuf key)
        Creates a PemX509Certificate from raw ByteBuf. ATTENTION: It's assumed that the given argument is a PEM/PKCS#8 encoded value. No input validation is performed to validate it.
      • isSensitive

        public boolean isSensitive()
        Description copied from interface: PemEncoded
        Returns true if the PEM encoded value is considered sensitive information such as a private key.
        Specified by:
        isSensitive in interface PemEncoded
      • refCnt

        public int refCnt()
        Description copied from interface: ReferenceCounted
        Returns the reference count of this object. If 0, it means this object has been deallocated.
        Specified by:
        refCnt in interface ReferenceCounted
      • release

        public boolean release()
        Description copied from interface: ReferenceCounted
        Decreases the reference count by 1 and deallocates this object if the reference count reaches at 0.
        Specified by:
        release in interface ReferenceCounted
        Returns:
        true if and only if the reference count became 0 and this object has been deallocated
      • release

        public boolean release​(int decrement)
        Description copied from interface: ReferenceCounted
        Decreases the reference count by the specified decrement and deallocates this object if the reference count reaches at 0.
        Specified by:
        release in interface ReferenceCounted
        Returns:
        true if and only if the reference count became 0 and this object has been deallocated
      • getEncoded

        public byte[] getEncoded()
        Specified by:
        getEncoded in class java.security.cert.Certificate
      • hasUnsupportedCriticalExtension

        public boolean hasUnsupportedCriticalExtension()
        Specified by:
        hasUnsupportedCriticalExtension in interface java.security.cert.X509Extension
      • getCriticalExtensionOIDs

        public java.util.Set<java.lang.String> getCriticalExtensionOIDs()
        Specified by:
        getCriticalExtensionOIDs in interface java.security.cert.X509Extension
      • getNonCriticalExtensionOIDs

        public java.util.Set<java.lang.String> getNonCriticalExtensionOIDs()
        Specified by:
        getNonCriticalExtensionOIDs in interface java.security.cert.X509Extension
      • getExtensionValue

        public byte[] getExtensionValue​(java.lang.String oid)
        Specified by:
        getExtensionValue in interface java.security.cert.X509Extension
      • checkValidity

        public void checkValidity()
        Specified by:
        checkValidity in class java.security.cert.X509Certificate
      • checkValidity

        public void checkValidity​(java.util.Date date)
        Specified by:
        checkValidity in class java.security.cert.X509Certificate
      • getVersion

        public int getVersion()
        Specified by:
        getVersion in class java.security.cert.X509Certificate
      • getSerialNumber

        public java.math.BigInteger getSerialNumber()
        Specified by:
        getSerialNumber in class java.security.cert.X509Certificate
      • getIssuerDN

        public java.security.Principal getIssuerDN()
        Specified by:
        getIssuerDN in class java.security.cert.X509Certificate
      • getSubjectDN

        public java.security.Principal getSubjectDN()
        Specified by:
        getSubjectDN in class java.security.cert.X509Certificate
      • getNotBefore

        public java.util.Date getNotBefore()
        Specified by:
        getNotBefore in class java.security.cert.X509Certificate
      • getNotAfter

        public java.util.Date getNotAfter()
        Specified by:
        getNotAfter in class java.security.cert.X509Certificate
      • getTBSCertificate

        public byte[] getTBSCertificate()
        Specified by:
        getTBSCertificate in class java.security.cert.X509Certificate
      • getSignature

        public byte[] getSignature()
        Specified by:
        getSignature in class java.security.cert.X509Certificate
      • getSigAlgName

        public java.lang.String getSigAlgName()
        Specified by:
        getSigAlgName in class java.security.cert.X509Certificate
      • getSigAlgOID

        public java.lang.String getSigAlgOID()
        Specified by:
        getSigAlgOID in class java.security.cert.X509Certificate
      • getSigAlgParams

        public byte[] getSigAlgParams()
        Specified by:
        getSigAlgParams in class java.security.cert.X509Certificate
      • getIssuerUniqueID

        public boolean[] getIssuerUniqueID()
        Specified by:
        getIssuerUniqueID in class java.security.cert.X509Certificate
      • getSubjectUniqueID

        public boolean[] getSubjectUniqueID()
        Specified by:
        getSubjectUniqueID in class java.security.cert.X509Certificate
      • getKeyUsage

        public boolean[] getKeyUsage()
        Specified by:
        getKeyUsage in class java.security.cert.X509Certificate
      • getBasicConstraints

        public int getBasicConstraints()
        Specified by:
        getBasicConstraints in class java.security.cert.X509Certificate
      • verify

        public void verify​(java.security.PublicKey key)
        Specified by:
        verify in class java.security.cert.Certificate
      • verify

        public void verify​(java.security.PublicKey key,
                           java.lang.String sigProvider)
        Specified by:
        verify in class java.security.cert.Certificate
      • getPublicKey

        public java.security.PublicKey getPublicKey()
        Specified by:
        getPublicKey in class java.security.cert.Certificate
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.security.cert.Certificate
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.security.cert.Certificate
      • toString

        public java.lang.String toString()
        Specified by:
        toString in class java.security.cert.Certificate