Package org.zeromq

Class ZCert


  • public class ZCert
    extends java.lang.Object
    The ZCert class provides a way to create and work with security certificates for the ZMQ CURVE mechanism. A certificate contains a public + secret key pair, plus metadata. It can be used as a temporary object in memory, or persisted to disk.

    To exchange certificates, send the public file via some secure route. Certificates are not signed but are text files that can be verified by eye.

    Certificates are stored in the ZeroMQ Property Language format.
    They have two sections, "metadata" and "curve".
    The first contains a list of 'name = value' pairs, one per line. Values may be enclosed in quotes.
    The curve section has a 'public-key = key-value' and, for secret certificates, a 'secret-key = key-value' line.
    The key-value is a Z85-encoded CURVE key.

    • Field Detail

      • publicKey

        private final byte[] publicKey
      • secretKey

        private final byte[] secretKey
      • publicTxt

        private final java.lang.String publicTxt
      • secretTxt

        private final java.lang.String secretTxt
    • Constructor Detail

      • ZCert

        public ZCert()
      • ZCert

        public ZCert​(java.lang.String publicKey)
      • ZCert

        public ZCert​(byte[] publicKey,
                     byte[] secretKey)
      • ZCert

        public ZCert​(java.lang.String publicKey,
                     java.lang.String secretKey)
    • Method Detail

      • assertKey

        private void assertKey​(int length,
                               int expected,
                               java.lang.String flavour)
      • getPublicKey

        public byte[] getPublicKey()
      • getSecretKey

        public byte[] getSecretKey()
      • getPublicKeyAsZ85

        public java.lang.String getPublicKeyAsZ85()
      • getSecretKeyAsZ85

        public java.lang.String getSecretKeyAsZ85()
      • apply

        public void apply​(ZMQ.Socket socket)
      • getMetadata

        public ZMetadata getMetadata()
      • setMeta

        public void setMeta​(java.lang.String key,
                            java.lang.String value)
      • unsetMeta

        public void unsetMeta​(java.lang.String key)
      • getMeta

        public java.lang.String getMeta​(java.lang.String key)
      • savePublic

        public java.io.File savePublic​(java.lang.String filename)
                                throws java.io.IOException
        Saves the public key to a file.

        This method will overwrite contents of existing file

        Parameters:
        filename - the path of the file to save the certificate into.
        Returns:
        the saved file or null if dumped to the standard output
        Throws:
        java.io.IOException - if unable to save the file.
      • savePublic

        public void savePublic​(java.io.Writer writer)
                        throws java.io.IOException
        Saves the public key to a writer.
        Parameters:
        writer - the writer to save the certificate into.
        Throws:
        java.io.IOException - if unable to dump the public configuration.
      • publicConfig

        private ZConfig publicConfig()
      • saveSecret

        public java.io.File saveSecret​(java.lang.String filename)
                                throws java.io.IOException
        Saves the public and secret keys to a file.

        This method will overwrite contents of existing file

        Parameters:
        filename - the path of the file to save the certificate into.
        Returns:
        the saved file or null if dumped to the standard output
        Throws:
        java.io.IOException - if unable to save the file.
      • saveSecret

        public void saveSecret​(java.io.Writer writer)
                        throws java.io.IOException
        Saves the public and secret keys to a writer.
        Parameters:
        writer - the writer to save the certificate into.
        Throws:
        java.io.IOException - if unable to dump the configuration.
      • secretConfig

        private ZConfig secretConfig()